// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/fnt.c
// Function: do_make_image
static void do_make_image(deark *c, lctx *d)
{
	struct de_bitmap_font *font = NULL;
	i64 i;
	de_encoding encoding_to_use;
	struct de_encconv_state es_main;
	struct de_encconv_state es_dec_special_gr;

	de_dbg(c, "reading bitmaps");
	de_dbg_indent(c, 1);

	font = de_create_bitmap_font(c);

	font->has_nonunicode_codepoints = 1;

	if(d->input_encoding_req!=DE_ENCODING_UNKNOWN) {
		encoding_to_use = d->input_encoding_req;
		font->has_unicode_codepoints = 1;
		font->prefer_unicode = 1;
	}
	else if(d->encoding!=DE_ENCODING_UNKNOWN) {
		encoding_to_use = d->encoding;
		font->has_unicode_codepoints = 1;
		font->prefer_unicode = 0;
	}
	else {
		encoding_to_use = DE_ENCODING_LATIN1;
		font->has_unicode_codepoints = 0;
		font->prefer_unicode = 0;
	}

	font->nominal_width = d->nominal_char_width;
	font->nominal_height = (int)d->char_height;
	font->num_chars = d->num_chars_stored;
	font->char_array = de_mallocarray(c, font->num_chars, sizeof(struct de_bitmap_font_char));
	de_encconv_init(&es_main, encoding_to_use);
	de_encconv_init(&es_dec_special_gr, DE_ENCODING_DEC_SPECIAL_GRAPHICS);

	for(i=0; i<d->num_chars_stored; i++) {
		i32 char_index;
		struct char_table_entry *cte = &d->char_table[i];
		struct de_bitmap_font_char *ch = &font->char_array[i];

		if(cte->is_abs_space) {
			// Arbitrarily put the "absolute space" char at codepoint 256,
			// and U+2002 EN SPACE (best I can do).
			ch->codepoint_nonunicode = 256;
			ch->codepoint_unicode = 0x2002;
		}
		else {
			char_index = (i32)d->first_char + (i32)i;

			ch->codepoint_nonunicode = char_index;

			if(font->has_unicode_codepoints) {
				if(char_index<32 && d->dfCharSet==0) {
					// This kind of font usually doesn't have glyphs below 32.
					// If it does, assume that they are VT100 line drawing characters.
					ch->codepoint_unicode =
						de_char_to_unicode_ex(95+char_index, &es_dec_special_gr);
				}
				else {
					ch->codepoint_unicode = de_char_to_unicode_ex(char_index, &es_main);
				}
			}
		}

		ch->width = cte->pixel_width;
		ch->height = (int)d->char_height;

		if(d->fnt_version==0x100) {
			get_char_bitmap_v1(c, d, cte, ch);
		}
		else {
			get_char_bitmap_v23(c, d, cte, ch);
		}
	}

	de_font_bitmap_font_to_image(c, font, d->fi, 0);

	if(font) {
		if(font->char_array) {
			for(i=0; i<font->num_chars; i++) {
				de_free(c, font->char_array[i].bitmap);
			}
			de_free(c, font->char_array);
		}
		de_destroy_bitmap_font(c, font);
	}

	de_dbg_indent(c, -1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x13bcba(%rip), %rsi    # 0x1aabd0
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
callq 0x16f6f0
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movb $0x1, 0x10(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x88(%rax)
je 0x6ef6c
movq -0x10(%rbp), %rax
movl 0x88(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x18(%rbp), %rax
movb $0x1, 0x11(%rax)
movq -0x18(%rbp), %rax
movb $0x1, 0x12(%rax)
jmp 0x6efb1
movq -0x10(%rbp), %rax
cmpl $0x0, 0x84(%rax)
je 0x6ef98
movq -0x10(%rbp), %rax
movl 0x84(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x18(%rbp), %rax
movb $0x1, 0x11(%rax)
movq -0x18(%rbp), %rax
movb $0x0, 0x12(%rax)
jmp 0x6efaf
movl $0x5, -0x24(%rbp)
movq -0x18(%rbp), %rax
movb $0x0, 0x11(%rax)
movq -0x18(%rbp), %rax
movb $0x0, 0x12(%rax)
jmp 0x6efb1
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rsi
movl $0x28, %edx
callq 0x15c450
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movl -0x24(%rbp), %esi
leaq -0x48(%rbp), %rdi
callq 0x160150
leaq -0x68(%rbp), %rdi
movl $0x17, %esi
callq 0x160150
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x48(%rcx), %rax
jge 0x6f150
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
imulq $0x18, -0x20(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
imulq $0x28, -0x20(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rax
cmpb $0x0, 0x4(%rax)
je 0x6f07d
movq -0x80(%rbp), %rax
movl $0x100, (%rax)          # imm = 0x100
movq -0x80(%rbp), %rax
movl $0x2002, 0x4(%rax)      # imm = 0x2002
jmp 0x6f0e7
movq -0x10(%rbp), %rax
movzbl 0x40(%rax), %eax
movq -0x20(%rbp), %rcx
addl %ecx, %eax
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %ecx
movq -0x80(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
cmpb $0x0, 0x11(%rax)
je 0x6f0e5
cmpl $0x20, -0x6c(%rbp)
jge 0x6f0ce
movq -0x10(%rbp), %rax
movzbl 0x78(%rax), %eax
cmpl $0x0, %eax
jne 0x6f0ce
movl -0x6c(%rbp), %edi
addl $0x5f, %edi
leaq -0x68(%rbp), %rsi
callq 0x160a30
movl %eax, %ecx
movq -0x80(%rbp), %rax
movl %ecx, 0x4(%rax)
jmp 0x6f0e3
movl -0x6c(%rbp), %edi
leaq -0x48(%rbp), %rsi
callq 0x160a30
movl %eax, %ecx
movq -0x80(%rbp), %rax
movl %ecx, 0x4(%rax)
jmp 0x6f0e5
jmp 0x6f0e7
movq -0x78(%rbp), %rax
movl (%rax), %ecx
movq -0x80(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl %eax, %ecx
movq -0x80(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x10(%rbp), %rax
cmpl $0x100, (%rax)          # imm = 0x100
jne 0x6f128
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x78(%rbp), %rdx
movq -0x80(%rbp), %rcx
callq 0x6f630
jmp 0x6f13d
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x78(%rbp), %rdx
movq -0x80(%rbp), %rcx
callq 0x6f7b0
jmp 0x6f13f
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x6f022
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rdx
xorl %ecx, %ecx
callq 0x16fe80
cmpq $0x0, -0x18(%rbp)
je 0x6f1db
movq -0x18(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x6f1ce
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jge 0x6f1bd
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
imulq $0x28, -0x20(%rbp), %rcx
addq %rcx, %rax
movq 0x20(%rax), %rsi
callq 0x15b820
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x6f184
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x16f730
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)