// File: /workspace/github_c_makefile_star2_O3/OnionIoT[P]lv_example/lvgl/src/lv_draw/lv_draw_img.c
// Function: lv_img_buf_get_px_color
lv_color_t lv_img_buf_get_px_color(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, const lv_style_t * style)
{
    lv_color_t p_color = LV_COLOR_BLACK;
    if(x >= (lv_coord_t)dsc->header.w) {
        x = dsc->header.w - 1;
        LV_LOG_WARN("lv_canvas_get_px: x is too large (out of canvas)");
    } else if(x < 0) {
        x = 0;
        LV_LOG_WARN("lv_canvas_get_px: x is < 0 (out of canvas)");
    }

    if(y >= (lv_coord_t)dsc->header.h) {
        y = dsc->header.h - 1;
        LV_LOG_WARN("lv_canvas_get_px: y is too large (out of canvas)");
    } else if(y < 0) {
        y = 0;
        LV_LOG_WARN("lv_canvas_get_px: y is < 0 (out of canvas)");
    }

    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 ||
       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(&p_color, &buf_u8[px], sizeof(lv_color_t));
#if LV_COLOR_SIZE == 32
        p_color.ch.alpha = 0xFF; /*Only the color should be get so use a deafult alpha value*/
#endif
    } else if(dsc->header.cf == LV_IMG_CF_INDEXED_1BIT) {
        buf_u8 += 4 * 2;
        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;
        p_color.full = (buf_u8[px] & (1 << (7 - bit))) >> (7 - bit);
    } else if(dsc->header.cf == LV_IMG_CF_INDEXED_2BIT) {
        buf_u8 += 4 * 4;
        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;
        p_color.full = (buf_u8[px] & (3 << (6 - bit))) >> (6 - bit);
    } else if(dsc->header.cf == LV_IMG_CF_INDEXED_4BIT) {
        buf_u8 += 4 * 16;
        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;
        p_color.full = (buf_u8[px] & (0xF << (4 - bit))) >> (4 - bit);
    } else if(dsc->header.cf == LV_IMG_CF_INDEXED_8BIT) {
        buf_u8 += 4 * 256;
        uint32_t px  = dsc->header.w * y + x;
        p_color.full = buf_u8[px];
    } else if(dsc->header.cf == LV_IMG_CF_ALPHA_1BIT || dsc->header.cf == LV_IMG_CF_ALPHA_2BIT ||
              dsc->header.cf == LV_IMG_CF_ALPHA_4BIT || dsc->header.cf == LV_IMG_CF_ALPHA_8BIT) {
        if(style)
            p_color = style->image.color;
        else
            p_color = LV_COLOR_BLACK;
    }
    return p_color;
}

// Assembly:
movl (%rdi), %r9d
movl %r9d, %eax
shrl $0xa, %eax
andl $0x7ff, %eax            # imm = 0x7FF
cmpl %esi, %eax
jle 0x3c2b1
xorl %r8d, %r8d
testw %si, %si
cmovgl %esi, %r8d
jmp 0x3c2b5
leal -0x1(%rax), %r8d
movswl %dx, %r10d
movl %r9d, %esi
shrl $0x15, %esi
cmpl %r10d, %esi
jle 0x3c2ce
xorl %esi, %esi
testw %dx, %dx
cmovgl %edx, %esi
jmp 0x3c2d0
decl %esi
movl %r9d, %r10d
andl $0x1f, %r10d
addl $-0x4, %r10d
cmpl $0xa, %r10d
ja 0x3c332
movq 0x8(%rdi), %rdx
leaq 0x711c(%rip), %rdi      # 0x43408
movslq (%rdi,%r10,4), %r10
addq %rdi, %r10
jmpq *%r10
testq %rcx, %rcx
je 0x3c332
movzwl 0x38(%rcx), %eax
retq
andb $0x1f, %r9b
addb $-0x4, %r9b
xorl %ecx, %ecx
cmpb $0xa, %r9b
ja 0x3c31e
movzbl %r9b, %ecx
leaq 0x71b1(%rip), %rdi      # 0x434cc
movl (%rdi,%rcx,4), %ecx
movswl %si, %esi
imull %esi, %eax
movswl %r8w, %esi
addl %eax, %esi
imull %ecx, %esi
movzwl (%rdx,%rsi), %eax
retq
xorl %eax, %eax
retq
leal (,%r8,4), %ecx
movswl %r8w, %edi
incl %eax
shrl %eax
movswl %si, %esi
imull %eax, %esi
sarl %edi
addl %esi, %edi
movzbl 0x40(%rdx,%rdi), %eax
notb %cl
andb $0x4, %cl
shrl %cl, %eax
andl $0xf, %eax
retq
movswl %si, %ecx
imull %ecx, %eax
movswl %r8w, %ecx
addl %eax, %ecx
movzbl 0x400(%rdx,%rcx), %eax
retq
leal (%r8,%r8), %ecx
movswl %r8w, %edi
addl $0x3, %eax
shrl $0x2, %eax
movswl %si, %esi
imull %eax, %esi
sarl $0x2, %edi
addl %esi, %edi
movzbl 0x10(%rdx,%rdi), %eax
notb %cl
andb $0x6, %cl
shrl %cl, %eax
andl $0x3, %eax
retq
movswl %r8w, %ecx
addl $0x7, %eax
shrl $0x3, %eax
movswl %si, %esi
imull %eax, %esi
sarl $0x3, %ecx
addl %esi, %ecx
notb %r8b
movzbl 0x8(%rdx,%rcx), %ecx
movzbl %r8b, %edx
andl $0x7, %edx
xorl %eax, %eax
btl %edx, %ecx
setb %al
retq