// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/deark-char.c
// Function: de_char_output_screen_to_image_file
static void de_char_output_screen_to_image_file(deark *c, struct de_char_context *charctx,
	struct charextractx *ectx, struct de_char_screen *screen)
{
	i64 screen_width_in_pixels, screen_height_in_pixels;
	de_bitmap *img = NULL;
	de_finfo *fi = NULL;
	int i, j;
	const struct de_char_cell *cell;
	unsigned int flags;

	screen_width_in_pixels = screen->width * ectx->char_width_in_pixels;
	screen_height_in_pixels = screen->height * ectx->char_height_in_pixels;

	if(!de_good_image_dimensions(c, screen_width_in_pixels, screen_height_in_pixels)) goto done;

	img = de_bitmap_create(c, screen_width_in_pixels, screen_height_in_pixels, 3);

	fi = de_finfo_create(c);
	set_density(c, charctx, ectx, fi);

	if(charctx->creation_date.is_valid) {
		// The ->creation_date field is most likely from a SAUCE record, for which the
		// only date field is documented as "The date the file was created".
		// We intentionally treat it as a last-modified timestamp.
		fi->internal_mod_time = charctx->creation_date;
	}

	for(j=0; j<screen->height; j++) {
		for(i=0; i<screen->width; i++) {
			if(!screen->cell_rows[j]) continue;
			cell = &screen->cell_rows[j][i];
			if(!cell) continue;

			flags = cell->size_flags;

			do_render_character(c, charctx, ectx, img, i, j,
				ectx->uses_custom_font ? cell->codepoint : cell->codepoint_unicode,
				ectx->uses_custom_font ? 0 : 1,
				cell->fgcol, cell->bgcol, flags);

			// TODO: It might be better to draw our own underline and/or
			// strikethru marks, rather than relying on font glyphs that
			// might be customized or otherwise sub-optimal.
			if(cell->underline) {
				do_render_character(c, charctx, ectx, img, i, j,
					0x5f, 1, cell->fgcol, cell->bgcol, flags|DE_PAINTFLAG_TRNSBKGD);
			}
			if(cell->strikethru) {
				do_render_character(c, charctx, ectx, img, i, j,
					0x2d, 1, cell->fgcol, cell->bgcol, flags|DE_PAINTFLAG_TRNSBKGD);
			}
		}
	}

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0xc0, %rsp
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rcx
imulq 0x38(%rcx), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x28(%rbp), %rcx
imulq 0x40(%rcx), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x16a850
cmpl $0x0, %eax
jne 0x16e2e2
jmp 0x16e579
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
movl $0x3, %ecx
callq 0x16b750
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rdi
callq 0x15d230
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x50(%rbp), %rcx
callq 0x16e5a0
movq -0x20(%rbp), %rax
cmpb $0x0, 0x80(%rax)
je 0x16e349
movq -0x50(%rbp), %rax
movq -0x20(%rbp), %rcx
movq 0x80(%rcx), %rdx
movq %rdx, 0x68(%rax)
movq 0x88(%rcx), %rcx
movq %rcx, 0x70(%rax)
movl $0x0, -0x58(%rbp)
movslq -0x58(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jge 0x16e56a
movl $0x0, -0x54(%rbp)
movslq -0x54(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq (%rcx), %rax
jge 0x16e55a
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x58(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x16e392
jmp 0x16e54c
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x54(%rbp), %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x16e3bd
jmp 0x16e54c
movq -0x60(%rbp), %rax
movzbl 0x13(%rax), %eax
movl %eax, -0x64(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x80(%rbp)
movslq -0x54(%rbp), %rax
movq %rax, -0x78(%rbp)
movslq -0x58(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x28(%rbp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x0, %eax
je 0x16e41c
movq -0x60(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x9c(%rbp)
jmp 0x16e429
movq -0x60(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x9c(%rbp)
movq -0x70(%rbp), %r9
movq -0x78(%rbp), %r8
movq -0x80(%rbp), %rcx
movq -0x88(%rbp), %rdx
movq -0x90(%rbp), %rsi
movq -0x98(%rbp), %rdi
movl -0x9c(%rbp), %r14d
movq -0x28(%rbp), %rax
movzbl 0x1(%rax), %r10d
movl $0x1, %ebx
xorl %eax, %eax
cmpl $0x0, %r10d
cmovnel %eax, %ebx
movq -0x60(%rbp), %rax
movl 0x8(%rax), %r11d
movq -0x60(%rbp), %rax
movl 0xc(%rax), %r10d
movl -0x64(%rbp), %eax
movl %r14d, (%rsp)
movl %ebx, 0x8(%rsp)
movl %r11d, 0x10(%rsp)
movl %r10d, 0x18(%rsp)
movl %eax, 0x20(%rsp)
callq 0x16e660
movq -0x60(%rbp), %rax
cmpb $0x0, 0x10(%rax)
je 0x16e4f0
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x48(%rbp), %rcx
movslq -0x54(%rbp), %r8
movslq -0x58(%rbp), %r9
movq -0x60(%rbp), %rax
movl 0x8(%rax), %r11d
movq -0x60(%rbp), %rax
movl 0xc(%rax), %r10d
movl -0x64(%rbp), %eax
orl $0x1, %eax
movl $0x5f, (%rsp)
movl $0x1, 0x8(%rsp)
movl %r11d, 0x10(%rsp)
movl %r10d, 0x18(%rsp)
movl %eax, 0x20(%rsp)
callq 0x16e660
movq -0x60(%rbp), %rax
cmpb $0x0, 0x11(%rax)
je 0x16e54a
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x48(%rbp), %rcx
movslq -0x54(%rbp), %r8
movslq -0x58(%rbp), %r9
movq -0x60(%rbp), %rax
movl 0x8(%rax), %r11d
movq -0x60(%rbp), %rax
movl 0xc(%rax), %r10d
movl -0x64(%rbp), %eax
orl $0x1, %eax
movl $0x2d, (%rsp)
movl $0x1, 0x8(%rsp)
movl %r11d, 0x10(%rsp)
movl %r10d, 0x18(%rsp)
movl %eax, 0x20(%rsp)
callq 0x16e660
jmp 0x16e54c
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x16e369
jmp 0x16e55c
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x16e350
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rsi
xorl %edx, %edx
callq 0x16afa0
movq -0x48(%rbp), %rdi
callq 0x16af60
movq -0x18(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x15d260
addq $0xc0, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nopl (%rax,%rax)