// File: /workspace/github_c_makefile_star2_O0/OnionIoT[P]lv_example/lvgl/src/lv_draw/lv_img_decoder.c
// Function: lv_img_decoder_built_in_line_alpha
static lv_res_t lv_img_decoder_built_in_line_alpha(lv_img_decoder_dsc_t * dsc, lv_coord_t x, lv_coord_t y,
                                                   lv_coord_t len, uint8_t * buf)
{

#if LV_IMG_CF_ALPHA
    const lv_opa_t alpha1_opa_table[2]  = {0, 255};          /*Opacity mapping with bpp = 1 (Just for compatibility)*/
    const lv_opa_t alpha2_opa_table[4]  = {0, 85, 170, 255}; /*Opacity mapping with bpp = 2*/
    const lv_opa_t alpha4_opa_table[16] = {0,  17, 34,  51,  /*Opacity mapping with bpp = 4*/
                                           68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255};

    /*Simply fill the buffer with the color. Later only the alpha value will be modified.*/
    lv_color_t bg_color = dsc->style->image.color;
    lv_coord_t i;
    for(i = 0; i < len; i++) {
#if LV_COLOR_DEPTH == 8 || LV_COLOR_DEPTH == 1
        buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE] = bg_color.full;
#elif LV_COLOR_DEPTH == 16
        /*Because of Alpha byte 16 bit color can start on odd address which can cause crash*/
        buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE] = bg_color.full & 0xFF;
        buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE + 1] = (bg_color.full >> 8) & 0xFF;
#elif LV_COLOR_DEPTH == 32
        *((uint32_t *)&buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE]) = bg_color.full;
#else
#error "Invalid LV_COLOR_DEPTH. Check it in lv_conf.h"
#endif
    }

    const lv_opa_t * opa_table = NULL;
    uint8_t px_size            = lv_img_color_format_get_px_size(dsc->header.cf);
    uint16_t mask              = (1 << px_size) - 1; /*E.g. px_size = 2; mask = 0x03*/

    lv_coord_t w = 0;
    uint32_t ofs = 0;
    int8_t pos   = 0;
    switch(dsc->header.cf) {
        case LV_IMG_CF_ALPHA_1BIT:
            w = (dsc->header.w >> 3); /*E.g. w = 20 -> w = 2 + 1*/
            if(dsc->header.w & 0x7) w++;
            ofs += w * y + (x >> 3); /*First pixel*/
            pos       = 7 - (x & 0x7);
            opa_table = alpha1_opa_table;
            break;
        case LV_IMG_CF_ALPHA_2BIT:
            w = (dsc->header.w >> 2); /*E.g. w = 13 -> w = 3 + 1 (bytes)*/
            if(dsc->header.w & 0x3) w++;
            ofs += w * y + (x >> 2); /*First pixel*/
            pos       = 6 - ((x & 0x3) * 2);
            opa_table = alpha2_opa_table;
            break;
        case LV_IMG_CF_ALPHA_4BIT:
            w = (dsc->header.w >> 1); /*E.g. w = 13 -> w = 6 + 1 (bytes)*/
            if(dsc->header.w & 0x1) w++;
            ofs += w * y + (x >> 1); /*First pixel*/
            pos       = 4 - ((x & 0x1) * 4);
            opa_table = alpha4_opa_table;
            break;
        case LV_IMG_CF_ALPHA_8BIT:
            w = dsc->header.w; /*E.g. x = 7 -> w = 7 (bytes)*/
            ofs += w * y + x;  /*First pixel*/
            pos = 0;
            break;
    }

#if LV_USE_FILESYSTEM
    lv_img_decoder_built_in_data_t * user_data = dsc->user_data;
    uint8_t fs_buf[LV_HOR_RES_MAX];
#endif

    const uint8_t * data_tmp = NULL;
    if(dsc->src_type == LV_IMG_SRC_VARIABLE) {
        const lv_img_dsc_t * img_dsc = dsc->src;

        data_tmp = img_dsc->data + ofs;
    } else {
#if LV_USE_FILESYSTEM
        lv_fs_seek(user_data->f, ofs + 4); /*+4 to skip the header*/
        lv_fs_read(user_data->f, fs_buf, w, NULL);
        data_tmp = fs_buf;
#else
        LV_LOG_WARN("Image built-in alpha line reader can't read file because LV_USE_FILESYSTEM = 0");
        data_tmp = NULL; /*To avoid warnings*/
        return LV_RES_INV;
#endif
    }

    uint8_t byte_act = 0;
    uint8_t val_act;
    for(i = 0; i < len; i++) {
        val_act = (data_tmp[byte_act] & (mask << pos)) >> pos;

        buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE + LV_IMG_PX_SIZE_ALPHA_BYTE - 1] =
            dsc->header.cf == LV_IMG_CF_ALPHA_8BIT ? val_act : opa_table[val_act];

        pos -= px_size;
        if(pos < 0) {
            pos = 8 - px_size;
            data_tmp++;
        }
    }

    return LV_RES_OK;

#else
    LV_LOG_WARN("Image built-in alpha line reader failed because LV_IMG_CF_ALPHA is 0 in lv_conf.h");
    return LV_RES_INV;
#endif
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movw %cx, %ax
movw %dx, %cx
movw %si, %dx
movq %rdi, -0x8(%rbp)
movw %dx, -0xa(%rbp)
movw %cx, -0xc(%rbp)
movw %ax, -0xe(%rbp)
movq %r8, -0x18(%rbp)
movw 0x6211(%rip), %ax       # 0x6c0b0
movw %ax, -0x1a(%rbp)
movl 0x610d(%rip), %eax      # 0x6bfb6
movl %eax, -0x1e(%rbp)
movq 0x610d(%rip), %rax      # 0x6bfc0
movq %rax, -0x30(%rbp)
movq 0x610a(%rip), %rax      # 0x6bfc8
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movw 0x38(%rax), %ax
movw %ax, -0x32(%rbp)
movw $0x0, -0x34(%rbp)
movswl -0x34(%rbp), %eax
movswl -0xe(%rbp), %ecx
cmpl %ecx, %eax
jge 0x65f30
movzwl -0x32(%rbp), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x18(%rbp), %rax
movswl -0x34(%rbp), %ecx
imull $0x3, %ecx, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movzwl -0x32(%rbp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x18(%rbp), %rax
movswl -0x34(%rbp), %ecx
imull $0x3, %ecx, %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movw -0x34(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x34(%rbp)
jmp 0x65ed8
movq $0x0, -0x40(%rbp)
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %edi
andl $0x1f, %edi
callq 0x62530
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %cl
movl $0x1, %eax
shll %cl, %eax
decl %eax
movw %ax, -0x44(%rbp)
movw $0x0, -0x46(%rbp)
movl $0x0, -0x4c(%rbp)
movb $0x0, -0x4d(%rbp)
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %eax
andl $0x1f, %eax
addl $-0xb, %eax
movl %eax, %ecx
movq %rcx, -0x1c0(%rbp)
subl $0x3, %eax
ja 0x66122
movq -0x1c0(%rbp), %rax
leaq 0x60f8(%rip), %rcx      # 0x6c090
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %eax
shrl $0xa, %eax
andl $0x7ff, %eax            # imm = 0x7FF
sarl $0x3, %eax
movw %ax, -0x46(%rbp)
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %eax
shrl $0xa, %eax
andl $0x7ff, %eax            # imm = 0x7FF
andl $0x7, %eax
cmpl $0x0, %eax
je 0x65fda
movw -0x46(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x46(%rbp)
movswl -0x46(%rbp), %eax
movswl -0xc(%rbp), %ecx
imull %ecx, %eax
movswl -0xa(%rbp), %ecx
sarl $0x3, %ecx
addl %ecx, %eax
addl -0x4c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movswl -0xa(%rbp), %ecx
andl $0x7, %ecx
movl $0x7, %eax
subl %ecx, %eax
movb %al, -0x4d(%rbp)
leaq -0x1a(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x66122
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %eax
shrl $0xa, %eax
andl $0x7ff, %eax            # imm = 0x7FF
sarl $0x2, %eax
movw %ax, -0x46(%rbp)
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %eax
shrl $0xa, %eax
andl $0x7ff, %eax            # imm = 0x7FF
andl $0x3, %eax
cmpl $0x0, %eax
je 0x6604b
movw -0x46(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x46(%rbp)
movswl -0x46(%rbp), %eax
movswl -0xc(%rbp), %ecx
imull %ecx, %eax
movswl -0xa(%rbp), %ecx
sarl $0x2, %ecx
addl %ecx, %eax
addl -0x4c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movswl -0xa(%rbp), %ecx
andl $0x3, %ecx
shll %ecx
movl $0x6, %eax
subl %ecx, %eax
movb %al, -0x4d(%rbp)
leaq -0x1e(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x66122
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %eax
shrl $0xa, %eax
andl $0x7ff, %eax            # imm = 0x7FF
sarl %eax
movw %ax, -0x46(%rbp)
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %eax
shrl $0xa, %eax
andl $0x7ff, %eax            # imm = 0x7FF
andl $0x1, %eax
cmpl $0x0, %eax
je 0x660bd
movw -0x46(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x46(%rbp)
movswl -0x46(%rbp), %eax
movswl -0xc(%rbp), %ecx
imull %ecx, %eax
movswl -0xa(%rbp), %ecx
sarl %ecx
addl %ecx, %eax
addl -0x4c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movswl -0xa(%rbp), %ecx
andl $0x1, %ecx
shll $0x2, %ecx
movl $0x4, %eax
subl %ecx, %eax
movb %al, -0x4d(%rbp)
leaq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x66122
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %eax
shrl $0xa, %eax
andl $0x7ff, %eax            # imm = 0x7FF
movw %ax, -0x46(%rbp)
movswl -0x46(%rbp), %eax
movswl -0xc(%rbp), %ecx
imull %ecx, %eax
movswl -0xa(%rbp), %ecx
addl %ecx, %eax
addl -0x4c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movb $0x0, -0x4d(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x58(%rbp)
movq $0x0, -0x1a8(%rbp)
movq -0x8(%rbp), %rax
movzbl 0x18(%rax), %eax
cmpl $0x0, %eax
jne 0x6616f
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x1b0(%rbp)
movq -0x1b0(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x4c(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x1a8(%rbp)
jmp 0x661aa
movq -0x58(%rbp), %rax
movq (%rax), %rdi
movl -0x4c(%rbp), %esi
addl $0x4, %esi
callq 0x438e0
movq -0x58(%rbp), %rax
movq (%rax), %rdi
leaq -0x1a0(%rbp), %rsi
movswl -0x46(%rbp), %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x437a0
leaq -0x1a0(%rbp), %rax
movq %rax, -0x1a8(%rbp)
movb $0x0, -0x1b1(%rbp)
movw $0x0, -0x34(%rbp)
movswl -0x34(%rbp), %eax
movswl -0xe(%rbp), %ecx
cmpl %ecx, %eax
jge 0x6628e
movq -0x1a8(%rbp), %rax
movzbl -0x1b1(%rbp), %ecx
movzbl (%rax,%rcx), %eax
movzwl -0x44(%rbp), %edx
movsbl -0x4d(%rbp), %ecx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
movsbl -0x4d(%rbp), %ecx
sarl %cl, %eax
movb %al, -0x1b2(%rbp)
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %eax
andl $0x1f, %eax
cmpl $0xe, %eax
jne 0x66211
movzbl -0x1b2(%rbp), %eax
movl %eax, -0x1c4(%rbp)
jmp 0x66226
movq -0x40(%rbp), %rax
movzbl -0x1b2(%rbp), %ecx
movzbl (%rax,%rcx), %eax
movl %eax, -0x1c4(%rbp)
movl -0x1c4(%rbp), %eax
movb %al, %dl
movq -0x18(%rbp), %rax
movswl -0x34(%rbp), %ecx
imull $0x3, %ecx, %ecx
addl $0x3, %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movzbl -0x41(%rbp), %ecx
movsbl -0x4d(%rbp), %eax
subl %ecx, %eax
movb %al, -0x4d(%rbp)
movsbl -0x4d(%rbp), %eax
cmpl $0x0, %eax
jge 0x6627b
movzbl -0x41(%rbp), %ecx
movl $0x8, %eax
subl %ecx, %eax
movb %al, -0x4d(%rbp)
movq -0x1a8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1a8(%rbp)
jmp 0x6627d
movw -0x34(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x34(%rbp)
jmp 0x661b7
movb $0x1, %al
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
nopl (%rax)