// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rax
movl (%rdi), %edi
movl %edi, %ebx
shrl $0xa, %ebx
andl $0x7ff, %ebx            # imm = 0x7FF
cmpl %esi, %ebx
jle 0x383fa
xorl %r14d, %r14d
testw %si, %si
cmovgl %esi, %r14d
jmp 0x383fe
leal -0x1(%rbx), %r14d
movswl %dx, %esi
movl %edi, %ebp
shrl $0x15, %ebp
cmpl %esi, %ebp
jle 0x38414
xorl %ebp, %ebp
testw %dx, %dx
cmovgl %edx, %ebp
jmp 0x38416
decl %ebp
andl $0x1f, %edi
leal -0x4(%rdi), %edx
cmpl $0xa, %edx
ja 0x38467
movq 0x8(%rax), %r15
leaq 0x6e9c(%rip), %rax      # 0x3f2c8
movslq (%rax,%rdx,4), %rdx
addq %rax, %rdx
jmpq *%rdx
testq %rcx, %rcx
je 0x38467
movzwl 0x38(%rcx), %eax
jmp 0x38509
callq 0x38514
shrb $0x3, %al
movswl %bp, %ecx
imull %ecx, %ebx
movzbl %al, %eax
movswl %r14w, %ecx
addl %ebx, %ecx
imull %eax, %ecx
movzwl (%r15,%rcx), %eax
jmp 0x38509
xorl %eax, %eax
jmp 0x38509
leal (,%r14,4), %ecx
movswl %r14w, %eax
incl %ebx
shrl %ebx
movswl %bp, %edx
imull %ebx, %edx
sarl %eax
addl %edx, %eax
movzbl 0x40(%r15,%rax), %eax
notb %cl
andb $0x4, %cl
shrl %cl, %eax
andl $0xf, %eax
jmp 0x38509
movswl %bp, %eax
imull %eax, %ebx
movswl %r14w, %eax
addl %ebx, %eax
movzbl 0x400(%r15,%rax), %eax
jmp 0x38509
leal (%r14,%r14), %ecx
movswl %r14w, %eax
addl $0x3, %ebx
shrl $0x2, %ebx
movswl %bp, %edx
imull %ebx, %edx
sarl $0x2, %eax
addl %edx, %eax
movzbl 0x10(%r15,%rax), %eax
notb %cl
andb $0x6, %cl
shrl %cl, %eax
andl $0x3, %eax
jmp 0x38509
movswl %r14w, %eax
addl $0x7, %ebx
shrl $0x3, %ebx
movswl %bp, %ecx
imull %ebx, %ecx
sarl $0x3, %eax
addl %ecx, %eax
notb %r14b
movzbl 0x8(%r15,%rax), %ecx
movzbl %r14b, %edx
andl $0x7, %edx
xorl %eax, %eax
btl %edx, %ecx
setb %al
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq