// File: /workspace/github_c_makefile_star2_O1/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 %rbx
pushq %rax
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 0x7b0a5
cmpl $0x52474238, %eax       # imm = 0x52474238
jne 0x7b0ec
movb $0x1, 0x61(%r14)
cmpl $0x52474238, %eax       # imm = 0x52474238
je 0x7b0c6
cmpl $0x5247424e, %eax       # imm = 0x5247424E
jne 0x7b0e0
cmpq $0xd, 0x60(%r15)
je 0x7b0cd
cmpl $0x52474238, %eax       # imm = 0x52474238
jne 0x7b0e0
cmpq $0x19, 0x60(%r15)
jne 0x7b0e0
movb 0x68(%r15), %cl
addb $-0x3, %cl
cmpb $0x1, %cl
ja 0x7b0e0
cmpb $0x0, 0x69(%r15)
je 0x7b0ec
leaq 0xadbbc(%rip), %rsi     # 0x128ca3
jmp 0x7b1c1
xorl %ecx, %ecx
testl %ebp, %ebp
setne %cl
shll $0x6, %ecx
movq 0x50(%rcx,%r15), %rdx
movq %rdx, (%r14)
movq 0x58(%rcx,%r15), %rcx
movq %rcx, 0x8(%r14)
cmpb $0x0, 0xd6(%rbx)
je 0x7b141
testl %ebp, %ebp
jne 0x7b141
movq 0x50(%r15), %rcx
andl $0xf, %ecx
je 0x7b141
cmpl $0x494c424d, %eax       # imm = 0x494C424D
jne 0x7b141
cmpl $0x0, (%r15)
jne 0x7b141
cmpb $0x0, 0x38(%r15)
jne 0x7b141
movq (%r14), %rdi
movl $0x10, %esi
callq 0xea80b
movq %rax, (%r14)
movb 0x68(%r15), %al
movb %al, 0x20(%r14)
movb 0x69(%r15), %al
xorl %edx, %edx
cmpb $0x1, %al
movzbl %al, %eax
cmovnel %eax, %edx
testl %ebp, %ebp
cmovel %eax, %edx
movb %dl, 0x21(%r14)
movq 0x60(%r15), %rcx
xorl %eax, %eax
cmpq $0x18, %rcx
sete %al
movl %eax, 0x58(%r14)
movb 0x60(%r14), %al
testb %al, %al
jne 0x7b184
cmpb $0x0, 0x61(%r14)
je 0x7b271
movl $0x1, %edx
movq %rdx, 0x10(%r14)
movq %rdx, 0x18(%r14)
movl 0x6c(%r15), %edx
movl %edx, 0x24(%r14)
movq 0x70(%r15), %rdx
movq %rdx, 0x28(%r14)
movq 0x78(%r15), %rdx
movq %rdx, 0x30(%r14)
testb %al, %al
je 0x7b1f3
cmpq $0x8, %rcx
jne 0x7b1ba
cmpb $0x1, 0x69(%r15)
jne 0x7b1da
leaq 0xadaff(%rip), %rsi     # 0x128cc0
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
testb %al, %al
je 0x7b1f3
movq (%r14), %rax
movl %eax, %ecx
andl $0x1, %ecx
addq %rax, %rcx
movq %rcx, 0x40(%r14)
shlq $0x3, %rcx
jmp 0x7b20d
cmpb $0x0, 0x61(%r14)
movq (%r14), %rdi
je 0x7b214
leaq (%rdi,%rdi,2), %rax
movq %rax, 0x40(%r14)
shlq $0x3, %rdi
leaq (%rdi,%rdi,2), %rcx
movl $0x38, %eax
jmp 0x7b236
movl $0x10, %esi
callq 0xea80b
movq %rax, 0x38(%r14)
leaq 0x7(%rax), %rcx
testq %rax, %rax
cmovnsq %rax, %rcx
sarq $0x3, %rcx
movl $0x40, %eax
movq %rcx, (%r14,%rax)
movq 0x18(%r14), %rax
imulq 0x40(%r14), %rax
movq %rax, 0x48(%r14)
imulq 0x8(%r14), %rax
movq %rax, 0x50(%r14)
movzbl 0x21(%r14), %eax
cmpl $0x2, %eax
jb 0x7b29c
jne 0x7b28b
cmpq $0x8, 0x10(%r14)
jg 0x7b29c
cmpb $0x0, 0x38(%r15)
jne 0x7b29c
movb $0x1, 0x22(%r14)
jmp 0x7b29c
movq %rcx, 0x10(%r14)
movq %rcx, 0x18(%r14)
cmpb $0x1, %dl
jne 0x7b191
leaq 0x1(%rcx), %rdx
jmp 0x7b18d
leaq 0xada49(%rip), %rsi     # 0x128cdb
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9b27
cmpb $0x0, 0x22(%r14)
je 0x7b2b8
movl 0x24(%r14), %eax
cmpq $0xff, %rax
ja 0x7b2b8
movb $0x0, 0x4d7(%r15,%rax,4)
movl $0x1, %ebp
cmpl $0x1, 0x58(%r14)
je 0x7b1cd
movq 0x10(%r14), %rdx
leaq -0x9(%rdx), %rax
cmpq $-0x9, %rax
ja 0x7b1cd
leaq 0xada25(%rip), %rsi     # 0x128d06
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0x7b1cd