// File: /workspace/github_c_makefile_star2_O3/OnionIoT[P]lv_example/lvgl/src/lv_draw/lv_draw_img.c
// Function: lv_img_buf_set_px_color
void lv_img_buf_set_px_color(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_color_t c)
{
    uint8_t * buf_u8 = (uint8_t *)dsc->data;

    if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR || dsc->header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED) {
        uint8_t px_size = lv_img_color_format_get_px_size(dsc->header.cf) >> 3;
        uint32_t px     = dsc->header.w * y * px_size + x * px_size;
        memcpy(&buf_u8[px], &c, px_size);
    } else if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_ALPHA) {
        uint8_t px_size = lv_img_color_format_get_px_size(dsc->header.cf) >> 3;
        uint32_t px     = dsc->header.w * y * px_size + x * px_size;
        memcpy(&buf_u8[px], &c, px_size - 1); /*-1 to not overwrite the alpha value*/
    } else if(dsc->header.cf == LV_IMG_CF_INDEXED_1BIT) {
        buf_u8 += sizeof(lv_color32_t) * 2; /*Skip the palette*/

        uint8_t bit = x & 0x7;
        x           = x >> 3;

        /* Get the current pixel.
         * dsc->header.w + 7 means rounding up to 8 because the lines are byte aligned
         * so the possible real width are 8 ,16, 24 ...*/
        uint32_t px = ((dsc->header.w + 7) >> 3) * y + x;
        buf_u8[px]  = buf_u8[px] & ~(1 << (7 - bit));
        buf_u8[px]  = buf_u8[px] | ((c.full & 0x1) << (7 - bit));
    } else if(dsc->header.cf == LV_IMG_CF_INDEXED_2BIT) {
        buf_u8 += sizeof(lv_color32_t) * 4; /*Skip the palette*/
        uint8_t bit = (x & 0x3) * 2;
        x           = x >> 2;

        /* Get the current pixel.
         * dsc->header.w + 3 means rounding up to 4 because the lines are byte aligned
         * so the possible real width are 4, 8 ,12 ...*/
        uint32_t px = ((dsc->header.w + 3) >> 2) * y + x;

        buf_u8[px] = buf_u8[px] & ~(3 << (6 - bit));
        buf_u8[px] = buf_u8[px] | ((c.full & 0x3) << (6 - bit));
    } else if(dsc->header.cf == LV_IMG_CF_INDEXED_4BIT) {
        buf_u8 += sizeof(lv_color32_t) * 16; /*Skip the palette*/
        uint8_t bit = (x & 0x1) * 4;
        x           = x >> 1;

        /* Get the current pixel.
         * dsc->header.w + 1 means rounding up to 2 because the lines are byte aligned
         * so the possible real width are 2 ,4, 6 ...*/
        uint32_t px = ((dsc->header.w + 1) >> 1) * y + x;
        buf_u8[px]  = buf_u8[px] & ~(0xF << (4 - bit));
        buf_u8[px]  = buf_u8[px] | ((c.full & 0xF) << (4 - bit));
    } else if(dsc->header.cf == LV_IMG_CF_INDEXED_8BIT) {
        buf_u8 += sizeof(lv_color32_t) * 256; /*Skip the palette*/
        uint32_t px = dsc->header.w * y + x;
        buf_u8[px]  = c.full;
    }
}

// Assembly:
pushq %rax
movl %ecx, %eax
movw %ax, 0x6(%rsp)
movl (%rdi), %r8d
movl %r8d, %ecx
andl $0x1f, %ecx
addl $-0x4, %ecx
cmpl $0x6, %ecx
ja 0x3c6a6
movq 0x8(%rdi), %rdi
leaq 0x6f32(%rip), %r9       # 0x4345c
movslq (%r9,%rcx,4), %rcx
addq %r9, %rcx
jmpq *%rcx
movl %r8d, %eax
andb $0x1f, %al
addb $-0x4, %al
cmpb $0xa, %al
ja 0x3c54d
movzbl %al, %eax
leaq 0x6fbb(%rip), %rcx      # 0x43503
movb (%rax,%rcx), %al
jmp 0x3c54f
xorl %eax, %eax
shrl $0xa, %r8d
andl $0x7ff, %r8d            # imm = 0x7FF
movswl %dx, %ecx
imull %r8d, %ecx
movzbl %al, %edx
movswl %si, %eax
addl %ecx, %eax
imull %edx, %eax
addq %rax, %rdi
leaq 0x6(%rsp), %rsi
callq 0x20f0
jmp 0x3c6a6
movswl %si, %r9d
shrl $0xa, %r8d
andl $0x7ff, %r8d            # imm = 0x7FF
addl $0x7, %r8d
shrl $0x3, %r8d
movswl %dx, %edx
imull %r8d, %edx
notb %sil
andb $0x7, %sil
movl $0x1, %r8d
movl %esi, %ecx
shll %cl, %r8d
sarl $0x3, %r9d
addl %edx, %r9d
notb %r8b
andb $0x1, %al
shlb %cl, %al
andb 0x8(%rdi,%r9), %r8b
orb %r8b, %al
movb %al, 0x8(%rdi,%r9)
jmp 0x3c6a6
shrl $0xa, %r8d
andl $0x7ff, %r8d            # imm = 0x7FF
movswl %dx, %ecx
imull %r8d, %ecx
movswl %si, %edx
addl %ecx, %edx
leal (%rdx,%rdx,2), %ecx
movw %ax, (%rdi,%rcx)
jmp 0x3c6a6
movswl %si, %r9d
leal (,%rsi,4), %ecx
shrl $0xa, %r8d
andl $0x7ff, %r8d            # imm = 0x7FF
incl %r8d
shrl %r8d
movswl %dx, %edx
imull %r8d, %edx
notb %cl
andb $0x4, %cl
movl $0xf, %esi
shll %cl, %esi
sarl %r9d
addl %edx, %r9d
notb %sil
andl $0xf, %eax
shll %cl, %eax
andb 0x40(%rdi,%r9), %sil
orb %sil, %al
movb %al, 0x40(%rdi,%r9)
jmp 0x3c6a6
shrl $0xa, %r8d
andl $0x7ff, %r8d            # imm = 0x7FF
movswl %dx, %ecx
imull %r8d, %ecx
movswl %si, %edx
addl %ecx, %edx
movb %al, 0x400(%rdi,%rdx)
jmp 0x3c6a6
movswl %si, %r9d
leal (%rsi,%rsi), %ecx
shrl $0xa, %r8d
andl $0x7ff, %r8d            # imm = 0x7FF
addl $0x3, %r8d
shrl $0x2, %r8d
movswl %dx, %edx
imull %r8d, %edx
notb %cl
andb $0x6, %cl
movl $0x3, %esi
shll %cl, %esi
sarl $0x2, %r9d
addl %edx, %r9d
notb %sil
andl $0x3, %eax
shll %cl, %eax
andb 0x10(%rdi,%r9), %sil
orb %sil, %al
movb %al, 0x10(%rdi,%r9)
popq %rax
retq