// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/rsc.c
// Function: do_color_icon
static void do_color_icon(deark *c, lctx *d, struct iconinfo *ii, i64 fg_pos,
	i64 mask_pos, const char *token, int is_sel)
{
	de_bitmap *img = NULL;
	de_bitmap *mask = NULL;
	de_finfo *fi = NULL;
	i64 planespan;
	const de_color *pal_to_use;

	// TODO: Images with 5, 6, or 7 planes exist, but I don't know what palettes
	// they use.

	if(ii->nplanes!=1 && ii->nplanes!=4 && ii->nplanes!=8) {
		// The non-selected and selected images have the same # of planes, so
		// suppress the duplicate warning message.
		if(!is_sel) {
			de_warn(c, "%d-plane icons not supported", (int)ii->nplanes);
		}
		goto done;
	}

	if(d->pal16[0]==0) {
		construct_palettes(c, d);
	}

	switch(ii->nplanes) {
	case 1: pal_to_use = d->pal2; break;
	case 4: pal_to_use = d->pal16; break;
	default: pal_to_use = d->pal256;
	}

	img = de_bitmap_create(c, ii->width, ii->height, 4);
	mask = de_bitmap_create(c, ii->width, ii->height, 1);

	planespan = ii->mono_rowspan * ii->height;
	de_convert_image_paletted_planar(c->infile, fg_pos, ii->nplanes,
		ii->mono_rowspan, planespan, pal_to_use, img, 0x2);

	do_decode_bilevel_image(c, d, mask, mask_pos, ii->mono_rowspan);
	de_bitmap_apply_mask(img, mask, DE_BITMAPFLAG_WHITEISTRNS);

	fi = de_finfo_create(c);
	set_icon_finfo(c, d, fi, ii, token);
	de_bitmap_write_to_file_finfo(img, fi, DE_CREATEFLAG_OPT_IMAGE);

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x1, 0x18(%rax)
je 0x124bf3
movq -0x18(%rbp), %rax
cmpq $0x4, 0x18(%rax)
je 0x124bf3
movq -0x18(%rbp), %rax
cmpq $0x8, 0x18(%rax)
je 0x124bf3
cmpl $0x0, 0x10(%rbp)
jne 0x124bee
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movl %eax, %edx
leaq 0xa1ef0(%rip), %rsi     # 0x1c6ad7
movb $0x0, %al
callq 0x15bc10
jmp 0x124d52
movq -0x10(%rbp), %rax
cmpl $0x0, 0x98(%rax)
jne 0x124c0d
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x124d80
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x60(%rbp)
subq $0x1, %rax
je 0x124c2d
jmp 0x124c21
movq -0x60(%rbp), %rax
subq $0x4, %rax
je 0x124c3d
jmp 0x124c4d
movq -0x10(%rbp), %rax
addq $0x90, %rax
movq %rax, -0x58(%rbp)
jmp 0x124c5b
movq -0x10(%rbp), %rax
addq $0x98, %rax
movq %rax, -0x58(%rbp)
jmp 0x124c5b
movq -0x10(%rbp), %rax
addq $0xd8, %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdx
movl $0x4, %ecx
callq 0x16b750
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdx
movl $0x1, %ecx
callq 0x16b750
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
imulq 0x8(%rcx), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x50(%rbp), %r8
movq -0x58(%rbp), %r9
movq -0x38(%rbp), %rax
movq %rax, (%rsp)
movl $0x2, 0x8(%rsp)
callq 0x16c690
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %r8
callq 0x123e80
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl $0x1, %edx
callq 0x16cf60
movq -0x8(%rbp), %rdi
callq 0x15d230
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x18(%rbp), %rcx
movq -0x30(%rbp), %r8
callq 0x1243b0
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl $0x2, %edx
callq 0x16afa0
movq -0x38(%rbp), %rdi
callq 0x16af60
movq -0x40(%rbp), %rdi
callq 0x16af60
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x15d260
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)