// 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_alpha
void lv_img_buf_set_px_alpha(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_opa_t opa)
{
    uint8_t * buf_u8 = (uint8_t *)dsc->data;

    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;
        buf_u8[px + px_size - 1] = opa;
    } else if(dsc->header.cf == LV_IMG_CF_ALPHA_1BIT) {
        opa         = opa >> 7; /*opa -> [0,1]*/
        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] | ((opa & 0x1) << (7 - bit));
    } else if(dsc->header.cf == LV_IMG_CF_ALPHA_2BIT) {
        opa         = opa >> 6; /*opa -> [0,3]*/
        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;
        buf_u8[px]  = buf_u8[px] & ~(3 << (6 - bit));
        buf_u8[px]  = buf_u8[px] | ((opa & 0x3) << (6 - bit));
    } else if(dsc->header.cf == LV_IMG_CF_ALPHA_4BIT) {
        opa         = opa >> 4; /*opa -> [0,15]*/
        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;
        buf_u8[px]  = buf_u8[px] & ~(0xF << (4 - bit));
        buf_u8[px]  = buf_u8[px] | ((opa & 0xF) << (4 - bit));
    } else if(dsc->header.cf == LV_IMG_CF_ALPHA_8BIT) {
        uint32_t px = dsc->header.w * y + x;
        buf_u8[px]  = opa;
    }
}

// Assembly:
movl %ecx, %eax
movl (%rdi), %r8d
movl %r8d, %ecx
andl $0x1f, %ecx
addl $-0x5, %ecx
cmpl $0x9, %ecx
ja 0x38913
movq 0x8(%rdi), %rdi
leaq 0x6b29(%rip), %r9       # 0x3f338
movslq (%r9,%rcx,4), %rcx
addq %r9, %rcx
jmpq *%rcx
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
addl $0x2, %ecx
movb %al, (%rdi,%rcx)
retq
shrb $0x6, %al
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
pushq $0x3
popq %rsi
shll %cl, %esi
sarl $0x2, %r9d
jmp 0x388e2
shrb $0x7, %al
movswl %si, %r9d
shrl $0xa, %r8d
andl $0x7ff, %r8d            # imm = 0x7FF
addl $0x7, %r8d
shrl $0x3, %r8d
movswl %dx, %ecx
imull %r8d, %ecx
sarl $0x3, %r9d
addl %ecx, %r9d
notb %sil
andb $0x7, %sil
pushq $0x1
popq %rdx
movl %esi, %ecx
shll %cl, %edx
notb %dl
shlb %cl, %al
andb (%rdi,%r9), %dl
orb %dl, %al
jmp 0x388f4
shrb $0x4, %al
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
pushq $0xf
popq %rsi
shll %cl, %esi
sarl %r9d
addl %edx, %r9d
notb %sil
movzbl %al, %eax
shll %cl, %eax
andb (%rdi,%r9), %sil
orb %sil, %al
movb %al, (%rdi,%r9)
retq
shrl $0xa, %r8d
andl $0x7ff, %r8d            # imm = 0x7FF
movswl %dx, %ecx
imull %r8d, %ecx
movswl %si, %edx
addl %ecx, %edx
movb %al, (%rdi,%rdx)
retq