// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/deark-font.c
// Function: de_font_paint_character_idx
void de_font_paint_character_idx(deark *c, de_bitmap *img,
	struct de_bitmap_font *font, i64 char_idx,
	i64 xpos, i64 ypos, de_color fgcol, de_color bgcol,
	unsigned int flags)
{
	struct de_bitmap_font_char *ch;

	if(char_idx<0 || char_idx>=font->num_chars) return;
	ch = &font->char_array[char_idx];
	if(!is_valid_char(ch)) return;
	if(ch->width > font->nominal_width) return;
	if(ch->height > font->nominal_height) return;

	// Paint a "canvas" for the char, if needed.

	// If the "extraspace" feature is used, paint an additional canvas of
	// a different color.
	if(!(flags&DE_PAINTFLAG_TRNSBKGD) && (ch->extraspace_l || ch->extraspace_r)) {
		i64 canvas_x, canvas_y;
		i64 canvas_w, canvas_h;

		canvas_x = xpos;
		canvas_y = ypos+ch->v_offset;
		canvas_w = (i64)ch->extraspace_l + (i64)ch->width + (i64)ch->extraspace_r;
		canvas_h = ch->height;
		// (We don't need to support both the "extraspace" and the VGA9COL
		// feature at the same time.)

		if(ch->width==0 || ch->height==0) {
			// Bit of a hack. If we have a zero-size (spacer-only) character,
			// paint the extraspace as the full height the cell.
			// (In principle, maybe it should be painted this way for *all*
			// characters, but I'm not sure how to make that look good.)
			canvas_y = ypos;
			canvas_h = font->nominal_height;
		}

		if(canvas_y + canvas_h > ypos + font->nominal_height) {
			goto after_extraspace;
		}

		de_bitmap_rect(img, canvas_x, canvas_y,
			canvas_w, canvas_h, DE_MAKE_RGB(192,255,192), 0);
	}

after_extraspace:

	if(ch->width<=0 || ch->height<=0) goto after_foreground; // Nothing to do

	// Paint the canvas for the main part of the character.
	if(!(flags&DE_PAINTFLAG_TRNSBKGD)) {
		i64 canvas_x, canvas_y;
		i64 canvas_w, canvas_h;

		canvas_x = xpos + ch->extraspace_l;
		canvas_y = ypos+ch->v_offset;
		canvas_w = ch->width;
		if((flags&DE_PAINTFLAG_VGA9COL) && ch->width==8) {
			canvas_w++;
		}
		canvas_h = ch->height;

		if(canvas_y + canvas_h > ypos + font->nominal_height) {
			goto after_foreground;
		}
		de_bitmap_rect(img, canvas_x, canvas_y,
			canvas_w, canvas_h, bgcol, 0);
	}

	// Paint the character foreground.
	paint_character_internal(c, img, ch,
		ch->extraspace_l + xpos, ch->v_offset + ypos, fgcol, flags);

after_foreground:
	;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
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)
cmpq $0x0, -0x20(%rbp)
jl 0x16f7a1
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jl 0x16f7a6
jmp 0x16f9de
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
imulq $0x28, -0x20(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0x16f9f0
cmpl $0x0, %eax
jne 0x16f7cd
jmp 0x16f9de
movq -0x38(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jle 0x16f7e1
jmp 0x16f9de
movq -0x38(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jle 0x16f7f6
jmp 0x16f9de
movl 0x20(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x16f8dc
movq -0x38(%rbp), %rax
movswl 0x14(%rax), %eax
cmpl $0x0, %eax
jne 0x16f823
movq -0x38(%rbp), %rax
movswl 0x16(%rax), %eax
cmpl $0x0, %eax
je 0x16f8dc
movq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movslq 0x10(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
movswq 0x14(%rax), %rax
movq -0x38(%rbp), %rcx
movslq 0x8(%rcx), %rcx
addq %rcx, %rax
movq -0x38(%rbp), %rcx
movswq 0x16(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rax
movslq 0xc(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rax
cmpl $0x0, 0x8(%rax)
je 0x16f882
movq -0x38(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0x16f896
movq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movslq 0x4(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rax
addq -0x58(%rbp), %rax
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rdx
movslq 0x4(%rdx), %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jle 0x16f8b4
jmp 0x16f8de
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq -0x58(%rbp), %r8
movl $0xffc0ffc0, %r9d       # imm = 0xFFC0FFC0
xorl %eax, %eax
movl $0x0, (%rsp)
callq 0x16cdc0
jmp 0x16f8de
movq -0x38(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jle 0x16f8f2
movq -0x38(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jg 0x16f8f7
jmp 0x16f9de
movl 0x20(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x16f9aa
movq -0x28(%rbp), %rax
movq -0x38(%rbp), %rcx
movswq 0x14(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movslq 0x10(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x38(%rbp), %rax
movslq 0x8(%rax), %rax
movq %rax, -0x70(%rbp)
movl 0x20(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x16f95a
movq -0x38(%rbp), %rax
cmpl $0x8, 0x8(%rax)
jne 0x16f95a
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
movq -0x38(%rbp), %rax
movslq 0xc(%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x68(%rbp), %rax
addq -0x78(%rbp), %rax
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rdx
movslq 0x4(%rdx), %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jle 0x16f984
jmp 0x16f9de
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x68(%rbp), %rdx
movq -0x70(%rbp), %rcx
movq -0x78(%rbp), %r8
movl 0x18(%rbp), %r9d
xorl %eax, %eax
movl $0x0, (%rsp)
callq 0x16cdc0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x38(%rbp), %rax
movswq 0x14(%rax), %rcx
addq -0x28(%rbp), %rcx
movq -0x38(%rbp), %rax
movslq 0x10(%rax), %r8
addq -0x30(%rbp), %r8
movl 0x10(%rbp), %r9d
movl 0x20(%rbp), %eax
movl %eax, (%rsp)
callq 0x16fac0
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)