// File: /workspace/github_c_makefile_star2_O1/OnionIoT[P]lv_example/lvgl/src/lv_draw/lv_draw_img.c
// Function: lv_img_buf_get_px_alpha
lv_opa_t lv_img_buf_get_px_alpha(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y)
{
    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_ALPHA) {
        uint32_t px = dsc->header.w * y * LV_IMG_PX_SIZE_ALPHA_BYTE + x * LV_IMG_PX_SIZE_ALPHA_BYTE;
        return buf_u8[px + LV_IMG_PX_SIZE_ALPHA_BYTE - 1];
    } else if(dsc->header.cf == LV_IMG_CF_ALPHA_1BIT) {
        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;
        uint8_t px_opa = (buf_u8[px] & (1 << (7 - bit))) >> (7 - bit);
        return px_opa ? LV_OPA_TRANSP : LV_OPA_COVER;
    } else if(dsc->header.cf == LV_IMG_CF_ALPHA_2BIT) {
        const uint8_t opa_table[4] = {0, 85, 170, 255}; /*Opacity mapping with bpp = 2*/

        uint8_t bit = (x & 0x3) * 2;
        x           = x >> 2;

        /* Get the current pixel.
         * dsc->header.w + 4 means rounding up to 8 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;
        uint8_t px_opa = (buf_u8[px] & (3 << (6 - bit))) >> (6 - bit);
        return opa_table[px_opa];
    } else if(dsc->header.cf == LV_IMG_CF_ALPHA_4BIT) {
        const uint8_t opa_table[16] = {0,  17, 34,  51, /*Opacity mapping with bpp = 4*/
                                       68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255};

        uint8_t bit = (x & 0x1) * 4;
        x           = x >> 1;

        /* Get the current pixel.
         * dsc->header.w + 1 means rounding up to 8 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;
        uint8_t px_opa = (buf_u8[px] & (0xF << (4 - bit))) >> (4 - bit);
        return opa_table[px_opa];
    } else if(dsc->header.cf == LV_IMG_CF_ALPHA_8BIT) {
        uint32_t px = dsc->header.w * y + x;
        return buf_u8[px];
    }

    return LV_OPA_COVER;
}

// Assembly:
movl (%rdi), %r9d
movl %r9d, %r8d
shrl $0xa, %r8d
andl $0x7ff, %r8d            # imm = 0x7FF
cmpl %esi, %r8d
jle 0x3c00a
xorl %ecx, %ecx
testw %si, %si
cmovgl %esi, %ecx
jmp 0x3c00e
leal -0x1(%r8), %ecx
movswl %dx, %eax
movl %r9d, %esi
shrl $0x15, %esi
cmpl %eax, %esi
jle 0x3c025
xorl %esi, %esi
testw %dx, %dx
cmovgl %edx, %esi
jmp 0x3c027
decl %esi
andl $0x1f, %r9d
movb $-0x1, %al
addl $-0x5, %r9d
cmpl $0x9, %r9d
ja 0x3c0c3
movq 0x8(%rdi), %rdx
leaq 0x71fe(%rip), %rdi      # 0x43244
movslq (%rdi,%r9,4), %r9
addq %rdi, %r9
jmpq *%r9
movswl %si, %eax
imull %eax, %r8d
movswl %cx, %eax
addl %r8d, %eax
leal (%rax,%rax,2), %eax
addl $0x2, %eax
jmp 0x3c102
movswl %cx, %eax
notl %ecx
addl %ecx, %ecx
addl $0x3, %r8d
shrl $0x2, %r8d
movswl %si, %esi
imull %r8d, %esi
sarl $0x2, %eax
addl %esi, %eax
movzbl (%rdx,%rax), %eax
andb $0x6, %cl
shrq %cl, %rax
andl $0x3, %eax
leaq 0x710d(%rip), %rcx      # 0x431a4
jmp 0x3c0f1
movswl %cx, %eax
addl $0x7, %r8d
shrl $0x3, %r8d
movswl %si, %esi
imull %r8d, %esi
sarl $0x3, %eax
addl %esi, %eax
notb %cl
movzbl (%rdx,%rax), %edx
movzbl %cl, %ecx
andl $0x7, %ecx
xorl %eax, %eax
btl %ecx, %edx
adcb $-0x1, %al
retq
movswl %cx, %eax
notl %ecx
shll $0x2, %ecx
incl %r8d
shrl %r8d
movswl %si, %esi
imull %r8d, %esi
sarl %eax
addl %esi, %eax
movzbl (%rdx,%rax), %eax
andb $0x4, %cl
shrq %cl, %rax
andl $0xf, %eax
leaq 0x70bf(%rip), %rcx      # 0x431b0
movb (%rax,%rcx), %al
retq
movswl %si, %eax
imull %eax, %r8d
movswl %cx, %eax
addl %r8d, %eax
movb (%rdx,%rax), %al
retq