// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/colorix.c
// Function: do_colorix_old_SCR
static void do_colorix_old_SCR(deark *c, struct colorix_ctx *d)
{
	de_bitmap *img = NULL;
	i64 planespan;
	dbuf *unc_pixels = NULL;
	dbuf *tmpbuf = NULL;
	dbuf *final_pixels_dbuf; // copy of pointer; do not free
	i64 final_pixels_pos;
	de_finfo *fi = NULL;

	d->imgtype = 1;
	d->width = 640;
	d->height = 350;
	d->unc_image_size = (d->width*d->height)/2;
	planespan = d->unc_image_size/4;
	d->known_segment_size = planespan;
	d->rowspan = d->width/8;
	declare_colorix_fmt(c, d);

	acquire_palette_ega64idx(c, d, 0);

	if(d->is_compressed) {
		unc_pixels = dbuf_create_membuf(c, d->unc_image_size+256, 0);
		if(!do_colorix_decompress(c, d, 16, unc_pixels)) goto done;
		final_pixels_dbuf = unc_pixels;
		final_pixels_pos = 0;
	}
	else {
		final_pixels_dbuf = c->infile;
		final_pixels_pos = 16;
	}

	// TODO?: Improve de_convert_image_paletted_planar to support this plane order.
	tmpbuf = dbuf_create_membuf(c, d->unc_image_size, 0);
	dbuf_copy(final_pixels_dbuf, final_pixels_pos+planespan*0, planespan, tmpbuf);
	dbuf_copy(final_pixels_dbuf, final_pixels_pos+planespan*2, planespan, tmpbuf);
	dbuf_copy(final_pixels_dbuf, final_pixels_pos+planespan*1, planespan, tmpbuf);
	dbuf_copy(final_pixels_dbuf, final_pixels_pos+planespan*3, planespan, tmpbuf);

	img = de_bitmap_create(c, d->width, d->height, 3);
	de_convert_image_paletted_planar(tmpbuf, 0, 4,
		d->rowspan, planespan, d->pal, img, 2);

	fi = de_finfo_create(c);
	fi->density.code = DE_DENSITY_UNK_UNITS;
	fi->density.xdens = 480.0;
	fi->density.ydens = (double)d->height;
	de_bitmap_write_to_file_finfo(img, fi, DE_CREATEFLAG_OPT_IMAGE);

done:
	de_bitmap_destroy(img);
	dbuf_close(unc_pixels);
	dbuf_close(tmpbuf);
	de_finfo_destroy(c, fi);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x10(%rbp), %rax
movb $0x1, 0x6(%rax)
movq -0x10(%rbp), %rax
movq $0x280, 0x10(%rax)      # imm = 0x280
movq -0x10(%rbp), %rax
movq $0x15e, 0x18(%rax)      # imm = 0x15E
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
imulq 0x18(%rcx), %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movl $0x4, %ecx
cqto
idivq %rcx
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl $0x8, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x68510
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x693d0
movq -0x10(%rbp), %rax
cmpb $0x0, 0x7(%rax)
je 0x6820d
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rsi
addq $0x100, %rsi            # imm = 0x100
xorl %edx, %edx
callq 0x168020
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rcx
movl $0x10, %edx
callq 0x68880
cmpl $0x0, %eax
jne 0x681fb
jmp 0x6835d
movq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
jmp 0x68221
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x38(%rbp)
movq $0x10, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rsi
xorl %edx, %edx
callq 0x168020
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
imulq $0x0, -0x20(%rbp), %rax
addq %rax, %rsi
movq -0x20(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0x166070
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x20(%rbp), %rax
shlq %rax
addq %rax, %rsi
movq -0x20(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0x166070
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x20(%rbp), %rax
shlq $0x0, %rax
addq %rax, %rsi
movq -0x20(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0x166070
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
imulq $0x3, -0x20(%rbp), %rax
addq %rax, %rsi
movq -0x20(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0x166070
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdx
movl $0x3, %ecx
callq 0x16b750
movq %rax, -0x18(%rbp)
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x20(%rbp), %r8
movq -0x10(%rbp), %r9
addq $0x40, %r9
movq -0x18(%rbp), %rax
xorl %edx, %edx
movl %edx, %esi
movl $0x4, %edx
movq %rax, (%rsp)
movl $0x2, 0x8(%rsp)
callq 0x16c690
movq -0x8(%rbp), %rdi
callq 0x15d230
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movl $0x1, 0x78(%rax)
movq -0x48(%rbp), %rax
movsd 0x13dfab(%rip), %xmm0   # 0x1a62d8
movsd %xmm0, 0x80(%rax)
movq -0x10(%rbp), %rax
cvtsi2sdq 0x18(%rax), %xmm0
movq -0x48(%rbp), %rax
movsd %xmm0, 0x88(%rax)
movq -0x18(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl $0x2, %edx
callq 0x16afa0
movq -0x18(%rbp), %rdi
callq 0x16af60
movq -0x28(%rbp), %rdi
callq 0x1676a0
movq -0x30(%rbp), %rdi
callq 0x1676a0
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x15d260
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)