// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/modules/ilbm.c
// Function: init_imgbody_info
static int init_imgbody_info(deark *c, lctx *d, struct imgbody_info *ibi, int is_thumb)
{
	int retval = 0;

	ibi->is_thumb = is_thumb;

	// Unlike ACBM, it would be messy and slow to convert PBM to the standard ILBM
	// frame buffer format (and back). So we support a special frame buffer format
	// just for PBM.
	ibi->is_pbm = (d->formtype==CODE_PBM);
	// We also have a special nonplanar RGB24 format (is_rgb24).

	if(d->formtype==CODE_RGBN || d->formtype==CODE_RGB8) {
		ibi->is_rgb24 = 1;
		if(((d->formtype==CODE_RGBN && d->planes_raw==13) ||
			(d->formtype==CODE_RGB8 && d->planes_raw==25)) &&
			(d->compression==3 || d->compression==4) &&
			d->masking_code==MASKINGTYPE_NONE)
		{
			;
		}
		else {
			de_err(c, "Unsupported RGBN/RGB8 format");
			goto done;
		}
	}

	if(is_thumb) {
		ibi->width = d->thumb_width;
		ibi->height = d->thumb_height;
	}
	else {
		ibi->width = d->width;
		ibi->height = d->height;
	}

	// Quick & dirty support for -padpix.
	// TODO: Some of these conditions could be removed, with care.
	if(c->padpix && (d->width%16) && !is_thumb && !d->is_anim && d->formtype==CODE_ILBM &&
		!d->ham_flag)
	{
		ibi->width = de_pad_to_n(ibi->width, 16);
	}

	ibi->compression = d->compression;

	ibi->masking_code = d->masking_code;
	// Based on what little data I have, it seems that TINY images do not have
	// a transparency mask, even if the main image does.
	if(is_thumb && ibi->masking_code==MASKINGTYPE_1BITMASK) {
		ibi->masking_code = MASKINGTYPE_NONE;
	}

	if(d->planes_raw==24) {
		ibi->colortype = COLORTYPE_RGB24;
	}
	else {
		ibi->colortype = COLORTYPE_DEFAULT;
	}

	if(ibi->is_pbm || ibi->is_rgb24) {
		ibi->planes_fg = 1;
		ibi->planes_total = 1;
	}
	else {
		ibi->planes_fg = d->planes_raw;
		ibi->planes_total = d->planes_raw;
		if(ibi->masking_code==MASKINGTYPE_1BITMASK) {
			ibi->planes_total++;
		}
	}
	ibi->transparent_color = d->transparent_color;
	ibi->x_aspect = d->x_aspect;
	ibi->y_aspect = d->y_aspect;

	if(ibi->is_pbm) {
		if(d->planes_raw!=8 || d->masking_code==MASKINGTYPE_1BITMASK) {
			de_err(c, "Not a supported PBM format");
			goto done;
		}
	}

	if(ibi->is_pbm) {
		ibi->bytes_per_row_per_plane = ibi->width;
		if(ibi->bytes_per_row_per_plane%2) {
			ibi->bytes_per_row_per_plane++;
		}
		ibi->bits_per_row_per_plane = ibi->bytes_per_row_per_plane * 8;
		// Note: The PBM row size might be adjusted later, after decompression.
	}
	else if(ibi->is_rgb24) {
		ibi->bytes_per_row_per_plane = ibi->width*3;
		ibi->bits_per_row_per_plane = ibi->bytes_per_row_per_plane * 8;
	}
	else {
		ibi->bits_per_row_per_plane = de_pad_to_n(ibi->width, 16);
		ibi->bytes_per_row_per_plane = ibi->bits_per_row_per_plane/8;
	}
	ibi->frame_buffer_rowspan = ibi->bytes_per_row_per_plane * ibi->planes_total;
	ibi->frame_buffer_size = ibi->frame_buffer_rowspan * ibi->height;

	if(ibi->masking_code==MASKINGTYPE_NONE) {
		;
	}
	else if(ibi->masking_code==MASKINGTYPE_COLORKEY) {
		if(ibi->planes_fg<=8 && !d->ham_flag) {
			ibi->use_colorkey_transparency = 1;
		}
	}
	else if(ibi->masking_code==MASKINGTYPE_1BITMASK) {
		;
	}
	else {
		de_warn(c, "This type of transparency is not supported");
	}

	if(ibi->use_colorkey_transparency && ibi->transparent_color<=255) {
		d->pal[ibi->transparent_color] = DE_SET_ALPHA(d->pal[ibi->transparent_color], 0);
	}

	if(ibi->colortype==COLORTYPE_RGB24) {
		;
	}
	else if(ibi->planes_fg<1 || ibi->planes_fg>8) {
		de_err(c, "Bad or unsupported number of planes: %d", (int)ibi->planes_fg);
		goto done;
	}
	retval = 1;

done:
	return retval;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %ecx, %ebp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movl %ecx, 0x5c(%rdx)
movl 0x4(%rsi), %eax
cmpl $0x50424d20, %eax       # imm = 0x50424D20
sete 0x60(%rdx)
cmpl $0x5247424e, %eax       # imm = 0x5247424E
je 0x7ad3a
cmpl $0x52474238, %eax       # imm = 0x52474238
jne 0x7ad8e
movb $0x1, 0x61(%r14)
cmpl $0x52474238, %eax       # imm = 0x52474238
je 0x7ad56
cmpl $0x5247424e, %eax       # imm = 0x5247424E
jne 0x7ad70
cmpq $0xd, 0x60(%r15)
je 0x7ad5d
jmp 0x7ad70
cmpq $0x19, 0x60(%r15)
jne 0x7ad70
movb 0x68(%r15), %cl
addb $-0x3, %cl
cmpb $0x1, %cl
ja 0x7ad70
cmpb $0x0, 0x69(%r15)
je 0x7ad8e
leaq 0xae15c(%rip), %rsi     # 0x128ed3
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movl %ebp, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
xorl %ecx, %ecx
testl %ebp, %ebp
setne %cl
shll $0x6, %ecx
movq 0x50(%rcx,%r15), %rdi
movq 0x58(%rcx,%r15), %rcx
movq %rdi, (%r14)
movq %rcx, 0x8(%r14)
cmpb $0x0, 0xd6(%rbx)
je 0x7ade3
testl %ebp, %ebp
jne 0x7ade3
movq 0x50(%r15), %rcx
andl $0xf, %ecx
je 0x7ade3
cmpl $0x494c424d, %eax       # imm = 0x494C424D
jne 0x7ade3
cmpl $0x0, (%r15)
jne 0x7ade3
cmpb $0x0, 0x38(%r15)
jne 0x7ade3
movl $0x10, %esi
callq 0xe9cb4
movq %rax, %rdi
movq %rax, (%r14)
movb 0x68(%r15), %al
movb %al, 0x20(%r14)
movb 0x69(%r15), %cl
xorl %eax, %eax
cmpb $0x1, %cl
movzbl %cl, %ecx
cmovnel %ecx, %eax
testl %ebp, %ebp
cmovel %ecx, %eax
movb %al, 0x21(%r14)
movq 0x60(%r15), %rcx
xorl %edx, %edx
cmpq $0x18, %rcx
sete %dl
movl %edx, 0x58(%r14)
movb 0x60(%r14), %dl
testb %dl, %dl
jne 0x7ae23
cmpb $0x0, 0x61(%r14)
je 0x7ae7c
movl $0x1, %esi
movq %rsi, 0x10(%r14)
movq %rsi, 0x18(%r14)
movl 0x6c(%r15), %esi
movl %esi, 0x24(%r14)
leaq 0x24(%r14), %r12
movups 0x70(%r15), %xmm0
movups %xmm0, 0x28(%r14)
testb %dl, %dl
je 0x7ae63
cmpq $0x8, %rcx
jne 0x7ae57
cmpb $0x1, 0x69(%r15)
jne 0x7aecf
leaq 0xae092(%rip), %rsi     # 0x128ef0
jmp 0x7ad77
cmpb $0x0, 0x61(%r14)
je 0x7aea4
leaq (%rdi,%rdi,2), %rcx
movq %rcx, 0x40(%r14)
shlq $0x3, %rdi
leaq (%rdi,%rdi,2), %rdx
jmp 0x7aee3
movq %rcx, 0x10(%r14)
xorl %edx, %edx
cmpb $0x1, %al
sete %dl
addq %rcx, %rdx
movq %rdx, 0x18(%r14)
movl 0x6c(%r15), %eax
leaq 0x24(%r14), %r12
movl %eax, 0x24(%r14)
movups 0x70(%r15), %xmm0
movups %xmm0, 0x28(%r14)
movl $0x10, %esi
callq 0xe9cb4
movq %rax, 0x38(%r14)
leaq 0x7(%rax), %rcx
testq %rax, %rax
cmovnsq %rax, %rcx
sarq $0x3, %rcx
movq %rcx, 0x40(%r14)
movq 0x18(%r14), %rdx
movb 0x21(%r14), %al
jmp 0x7aeec
movl %edi, %ecx
andl $0x1, %ecx
addq %rdi, %rcx
movq %rcx, 0x40(%r14)
leaq (,%rcx,8), %rdx
movq %rdx, 0x38(%r14)
movl $0x1, %edx
imulq %rcx, %rdx
movq %rdx, 0x48(%r14)
imulq 0x8(%r14), %rdx
movq %rdx, 0x50(%r14)
cmpb $0x2, %al
jb 0x7af2f
movzbl %al, %eax
cmpl $0x2, %eax
jne 0x7af1e
cmpq $0x8, 0x10(%r14)
jg 0x7af2f
cmpb $0x0, 0x38(%r15)
jne 0x7af2f
movb $0x1, 0x22(%r14)
jmp 0x7af2f
leaq 0xadfe6(%rip), %rsi     # 0x128f0b
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8faa
cmpb $0x0, 0x22(%r14)
je 0x7af4b
movl (%r12), %eax
cmpq $0xff, %rax
ja 0x7af4b
movb $0x0, 0x4d7(%r15,%rax,4)
movl $0x1, %ebp
cmpl $0x1, 0x58(%r14)
je 0x7ad83
movq 0x10(%r14), %rdx
leaq -0x9(%rdx), %rax
cmpq $-0x9, %rax
ja 0x7ad83
leaq 0xadfc2(%rip), %rsi     # 0x128f36
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
jmp 0x7ad83