// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/rosprite.c
// Function: do_image
static void do_image(deark *c, lctx *d, struct page_ctx *pg, de_finfo *fi)
{
	int is_grayscale;
	int bypp;

	if(pg->fgbpp<=8) {
		is_grayscale = de_is_grayscale_palette(pg->pal, ((i64)1)<<pg->fgbpp);
	}
	else {
		is_grayscale = 0;
	}

	bypp = is_grayscale?1:3;
	if(pg->has_mask) bypp++;

	if(pg->mask_type==MASK_TYPE_OLD) {
		pg->mask_width_1 = pg->width_1;
	}
	else if(pg->mask_type==MASK_TYPE_NEW_1 || pg->mask_type==MASK_TYPE_NEW_8) {
		pg->mask_width_1 = pg->npwidth;
	}

	pg->img = de_bitmap_create(c, pg->width_1, pg->height, bypp);

	if(pg->xdpi>0) {
		fi->density.code = DE_DENSITY_DPI;
		fi->density.xdens = (double)pg->xdpi;
		fi->density.ydens = (double)pg->ydpi;
	}

	de_dbg(c, "image data at %"I64_FMT, pg->image_offset);

	if(pg->fgbpp==32) {
		de_convert_image_rgb(c->infile, pg->image_offset, 4*pg->width_in_words, 4, pg->img, 0);
	}
	else if(pg->fgbpp==16) {
		convert_image_16bit(c, d, pg, pg->img);
	}
	else {
		de_convert_image_paletted(c->infile, pg->image_offset, pg->fgbpp, 4*pg->width_in_words,
			pg->pal, pg->img, 0x1);
	}

	if(pg->has_mask && pg->use_mask) {
		de_dbg(c, "transparency mask at %"I64_FMT, pg->mask_offset);

		if(pg->maskbpp<1 || pg->maskbpp>8) {
			de_warn(c, "This type of transparency mask is not supported");
			goto after_mask;
		}

		pg->mask = de_bitmap_create(c, pg->mask_width_1, pg->height, 1);

		// Make a palette to use with de_convert_image_paletted().
		if(pg->mask_type==MASK_TYPE_NEW_8) {
			de_make_grayscale_palette(pg->maskpal, 256, 0);
		}
		else {
			// Supposedly, anything nonzero is opaque.
			de_memset(pg->maskpal, 0xff, sizeof(pg->maskpal));
			pg->maskpal[0] = DE_STOCKCOLOR_BLACK;
		}

		// Start with an opaque mask.
		de_bitmap_rect(pg->mask, 0, 0, pg->mask->width, pg->mask->height, DE_STOCKCOLOR_WHITE, 0);

		de_convert_image_paletted(c->infile, pg->mask_offset, pg->maskbpp, pg->mask_rowspan,
			pg->maskpal, pg->mask, 0x1);

		de_bitmap_apply_mask(pg->img, pg->mask, 0);
		de_bitmap_destroy(pg->mask);
		pg->mask = NULL;
	}
after_mask:

	if(pg->num_padding_pixels_at_start_of_row>0 && !c->padpix) {
		remove_left_padding(c, pg);
	}

	de_bitmap_write_to_file_finfo(pg->img, fi, DE_CREATEFLAG_OPT_IMAGE);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x8, (%rax)
jg 0x121936
movq -0x18(%rbp), %rdi
addq $0xc0, %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movl $0x1, %esi
shlq %cl, %rsi
callq 0x16aa20
movl %eax, -0x24(%rbp)
jmp 0x12193d
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %edx
movl $0x3, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rax
cmpb $0x0, 0x78(%rax)
je 0x121966
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x1, 0x7c(%rax)
jne 0x121982
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x48(%rax)
jmp 0x1219a8
movq -0x18(%rbp), %rax
cmpl $0x2, 0x7c(%rax)
je 0x121996
movq -0x18(%rbp), %rax
cmpl $0x3, 0x7c(%rax)
jne 0x1219a6
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x48(%rax)
jmp 0x1219a8
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rdx
movl -0x28(%rbp), %ecx
callq 0x16b750
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x98(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x60(%rax)
jle 0x121a14
movq -0x20(%rbp), %rax
movl $0x2, 0x78(%rax)
movq -0x18(%rbp), %rax
cvtsi2sdq 0x60(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x80(%rax)
movq -0x18(%rbp), %rax
cvtsi2sdq 0x68(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x88(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x88(%rax), %rdx
leaq 0xa503b(%rip), %rsi     # 0x1c6a65
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
cmpq $0x20, (%rax)
jne 0x121a74
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x88(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdx
shlq $0x2, %rdx
movq -0x18(%rbp), %rax
movq 0x98(%rax), %r8
movl $0x4, %ecx
xorl %r9d, %r9d
callq 0x16c8b0
jmp 0x121ae6
movq -0x18(%rbp), %rax
cmpq $0x10, (%rax)
jne 0x121a9c
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x18(%rbp), %rax
movq 0x98(%rax), %rcx
callq 0x121f40
jmp 0x121ae4
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x88(%rax), %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rcx
shlq $0x2, %rcx
movq -0x18(%rbp), %r8
addq $0xc0, %r8
movq -0x18(%rbp), %rax
movq 0x98(%rax), %r9
movl $0x1, (%rsp)
callq 0x16c520
jmp 0x121ae6
movq -0x18(%rbp), %rax
movzbl 0x78(%rax), %eax
cmpl $0x0, %eax
je 0x121c91
movq -0x18(%rbp), %rax
movzbl 0x79(%rax), %eax
cmpl $0x0, %eax
je 0x121c91
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x90(%rax), %rdx
leaq 0xa469c(%rip), %rsi     # 0x1c61ba
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
cmpq $0x1, 0x8(%rax)
jl 0x121b3b
movq -0x18(%rbp), %rax
cmpq $0x8, 0x8(%rax)
jle 0x121b52
movq -0x8(%rbp), %rdi
leaq 0xa468d(%rip), %rsi     # 0x1c61d3
movb $0x0, %al
callq 0x15bc10
jmp 0x121c93
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rdx
movl $0x1, %ecx
callq 0x16b750
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0xa0(%rax)
movq -0x18(%rbp), %rax
cmpl $0x3, 0x7c(%rax)
jne 0x121ba1
movq -0x18(%rbp), %rdi
addq $0x4c0, %rdi            # imm = 0x4C0
movl $0x100, %esi            # imm = 0x100
xorl %edx, %edx
callq 0x16d580
jmp 0x121bc9
movq -0x18(%rbp), %rdi
addq $0x4c0, %rdi            # imm = 0x4C0
movl $0xff, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x19140
movq -0x18(%rbp), %rax
movl $0xff000000, 0x4c0(%rax) # imm = 0xFF000000
movq -0x18(%rbp), %rax
movq 0xa0(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0xa0(%rax), %rax
movq 0x8(%rax), %rcx
movq -0x18(%rbp), %rax
movq 0xa0(%rax), %rax
movq 0x10(%rax), %r8
xorl %eax, %eax
movl %eax, %edx
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
xorl %eax, %eax
movq %rdx, %rsi
movl $0x0, (%rsp)
callq 0x16cdc0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x90(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x18(%rbp), %rax
movq 0x80(%rax), %rcx
movq -0x18(%rbp), %r8
addq $0x4c0, %r8             # imm = 0x4C0
movq -0x18(%rbp), %rax
movq 0xa0(%rax), %r9
movl $0x1, (%rsp)
callq 0x16c520
movq -0x18(%rbp), %rax
movq 0x98(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0xa0(%rax), %rsi
xorl %edx, %edx
callq 0x16cf60
movq -0x18(%rbp), %rax
movq 0xa0(%rax), %rdi
callq 0x16af60
movq -0x18(%rbp), %rax
movq $0x0, 0xa0(%rax)
jmp 0x121c93
movq -0x18(%rbp), %rax
cmpq $0x0, 0x50(%rax)
jle 0x121cb8
movq -0x8(%rbp), %rax
cmpb $0x0, 0xd5(%rax)
jne 0x121cb8
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x122010
movq -0x18(%rbp), %rax
movq 0x98(%rax), %rdi
movq -0x20(%rbp), %rsi
movl $0x2, %edx
callq 0x16afa0
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)