// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/qtif.c
// Function: do_decode_raw
static void do_decode_raw(deark *c, lctx *d)
{
	de_bitmap *img = NULL;
	de_finfo *fi = NULL;
	i64 i, j;
	i64 rowspan;
	u32 clr;

	if(d->bitdepth != 32) {
		if(!d->fail_gracefully_mode)
			de_err(c, "Unsupported bit depth for raw image (%d)", (int)d->bitdepth);
		goto done;
	}

	if(d->fail_gracefully_mode) {
		if(!de_good_image_dimensions_noerr(c, d->width, d->height)) goto done;
	}
	else {
		if(!de_good_image_dimensions(c, d->width, d->height)) goto done;
	}

	img = de_bitmap_create(c, d->width, d->height, 3);

	fi = de_finfo_create(c);
	fi->density.code = DE_DENSITY_DPI;
	fi->density.xdens = d->hres;
	fi->density.ydens = d->vres;

	// Warning: This code is based on reverse engineering, and may not be correct.
	// TODO: Is the first sample for transparency?

	// I don't know how to figure out the bytes per row. This logic works for the
	// few example files I have.
	rowspan = d->width * 4;
	if(d->idat_data_size/d->height > rowspan) {
		rowspan = d->idat_data_size/d->height;
	}

	for(j=0; j<d->height; j++) {
		for(i=0; i<d->width; i++) {
			clr = dbuf_getRGB(c->infile, d->idat_pos + j*rowspan + i*4+1, 0);
			de_bitmap_setpixel_rgb(img, i, j, clr);
		}
	}

	de_bitmap_write_to_file_finfo(img, fi, 0);
	d->decoded_ok = 1;

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x20, 0x70(%rax)
je 0x11e875
movq -0x10(%rbp), %rax
cmpb $0x0, (%rax)
jne 0x11e870
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rax
movl %eax, %edx
leaq 0xa73b1(%rip), %rsi     # 0x1c5c1a
movb $0x0, %al
callq 0x15bfb0
jmp 0x11ea21
movq -0x10(%rbp), %rax
cmpb $0x0, (%rax)
je 0x11e8a3
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rdx
callq 0x16a7f0
cmpl $0x0, %eax
jne 0x11e8a1
jmp 0x11ea21
jmp 0x11e8c8
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rdx
callq 0x16a850
cmpl $0x0, %eax
jne 0x11e8c6
jmp 0x11ea21
jmp 0x11e8c8
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rdx
movl $0x3, %ecx
callq 0x16b750
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
callq 0x15d230
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movl $0x2, 0x78(%rax)
movq -0x10(%rbp), %rax
movsd 0x80(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x80(%rax)
movq -0x10(%rbp), %rax
movsd 0x88(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x88(%rax)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
shlq $0x2, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
cqto
idivq 0x68(%rcx)
cmpq -0x38(%rbp), %rax
jle 0x11e970
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
cqto
idivq 0x68(%rcx)
movq %rax, -0x38(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x68(%rcx), %rax
jge 0x11ea0a
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x60(%rcx), %rax
jge 0x11e9f7
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x30(%rbp), %rax
imulq -0x38(%rbp), %rax
addq %rax, %rsi
movq -0x28(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rsi
addq $0x1, %rsi
xorl %edx, %edx
callq 0x165ff0
movl %eax, -0x3c(%rbp)
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
movl -0x3c(%rbp), %ecx
callq 0x16b310
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x11e992
jmp 0x11e9f9
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x11e978
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
xorl %edx, %edx
callq 0x16afa0
movq -0x10(%rbp), %rax
movb $0x1, 0x1(%rax)
movq -0x18(%rbp), %rdi
callq 0x16af60
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x15d260
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)