// File: /workspace/github_c_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %ecx, %eax
movl %edx, %ebp
movq %rdi, %rcx
movw %ax, 0x6(%rsp)
movl (%rdi), %r15d
movl %r15d, %edi
andl $0x1f, %edi
leal -0x4(%rdi), %edx
cmpl $0x6, %edx
ja 0x387e2
movl %esi, %r14d
movq 0x8(%rcx), %rbx
leaq 0x6c9a(%rip), %rcx      # 0x3f31c
movslq (%rcx,%rdx,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
callq 0x38514
shrb $0x3, %al
shrl $0xa, %r15d
andl $0x7ff, %r15d           # imm = 0x7FF
movswl %bp, %ecx
imull %r15d, %ecx
movzbl %al, %edx
movswl %r14w, %eax
addl %ecx, %eax
imull %edx, %eax
addq %rax, %rbx
leaq 0x6(%rsp), %rsi
movq %rbx, %rdi
callq 0x20f0
jmp 0x387e2
movswl %r14w, %edx
shrl $0xa, %r15d
andl $0x7ff, %r15d           # imm = 0x7FF
addl $0x7, %r15d
shrl $0x3, %r15d
movswl %bp, %esi
imull %r15d, %esi
notb %r14b
andb $0x7, %r14b
pushq $0x1
popq %rdi
movl %r14d, %ecx
shll %cl, %edi
sarl $0x3, %edx
addl %esi, %edx
notb %dil
andb $0x1, %al
shlb %cl, %al
andb 0x8(%rbx,%rdx), %dil
orb %dil, %al
movb %al, 0x8(%rbx,%rdx)
jmp 0x387e2
shrl $0xa, %r15d
andl $0x7ff, %r15d           # imm = 0x7FF
movswl %bp, %ecx
imull %r15d, %ecx
movswl %r14w, %edx
addl %ecx, %edx
leal (%rdx,%rdx,2), %ecx
movw %ax, (%rbx,%rcx)
jmp 0x387e2
movswl %r14w, %edx
leal (,%r14,4), %ecx
shrl $0xa, %r15d
andl $0x7ff, %r15d           # imm = 0x7FF
incl %r15d
shrl %r15d
movswl %bp, %esi
imull %r15d, %esi
notb %cl
andb $0x4, %cl
pushq $0xf
popq %rdi
shll %cl, %edi
sarl %edx
addl %esi, %edx
notb %dil
andl $0xf, %eax
shll %cl, %eax
andb 0x40(%rbx,%rdx), %dil
orb %dil, %al
movb %al, 0x40(%rbx,%rdx)
jmp 0x387e2
shrl $0xa, %r15d
andl $0x7ff, %r15d           # imm = 0x7FF
movswl %bp, %ecx
imull %r15d, %ecx
movswl %r14w, %edx
addl %ecx, %edx
movb %al, 0x400(%rbx,%rdx)
jmp 0x387e2
movswl %r14w, %edx
leal (%r14,%r14), %ecx
shrl $0xa, %r15d
andl $0x7ff, %r15d           # imm = 0x7FF
addl $0x3, %r15d
shrl $0x2, %r15d
movswl %bp, %esi
imull %r15d, %esi
notb %cl
andb $0x6, %cl
pushq $0x3
popq %rdi
shll %cl, %edi
sarl $0x2, %edx
addl %esi, %edx
notb %dil
andl $0x3, %eax
shll %cl, %eax
andb 0x10(%rbx,%rdx), %dil
orb %dil, %al
movb %al, 0x10(%rbx,%rdx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq