From b8356ebe6cfcb5e1b0818101b5174b83cd220e9b Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Fri, 1 Sep 2023 11:13:21 +0200 Subject: [PATCH] fix(draw): stride handling for RGB565A8 images --- src/draw/lv_img_decoder.c | 20 ++++++++++++++------ src/draw/sw/lv_draw_sw_letter.c | 4 +++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/draw/lv_img_decoder.c b/src/draw/lv_img_decoder.c index a7c294ba5..fc69d3cc5 100644 --- a/src/draw/lv_img_decoder.c +++ b/src/draw/lv_img_decoder.c @@ -34,6 +34,7 @@ typedef struct { static lv_res_t decode_indexed_line(lv_color_format_t color_format, const lv_color32_t * palette, lv_coord_t y, lv_coord_t w_px, const uint8_t * in, lv_color32_t * out); +static uint32_t img_width_to_stride(lv_img_header_t * header); /********************** * STATIC VARIABLES **********************/ @@ -93,9 +94,7 @@ lv_res_t lv_img_decoder_get_info(const void * src, lv_img_header_t * header) if(d->info_cb) { res = d->info_cb(d, src, header); if(res == LV_RES_OK) { - if(header->stride == 0) { - header->stride = header->w * lv_color_format_get_size(header->cf); - } + if(header->stride == 0) header->stride = img_width_to_stride(header); break; } } @@ -143,9 +142,7 @@ lv_res_t lv_img_decoder_open(lv_img_decoder_dsc_t * dsc, const void * src, lv_co res = decoder->info_cb(decoder, src, &dsc->header); if(res != LV_RES_OK) continue; - if(dsc->header.stride == 0) { - dsc->header.stride = dsc->header.w * lv_color_format_get_size(dsc->header.cf); - } + if(dsc->header.stride == 0) dsc->header.stride = img_width_to_stride(&dsc->header); dsc->decoder = decoder; res = decoder->open_cb(decoder, dsc); @@ -483,3 +480,14 @@ static lv_res_t decode_indexed_line(lv_color_format_t color_format, const lv_col } return LV_RES_OK; } + + +static uint32_t img_width_to_stride(lv_img_header_t * header) +{ + if(header->cf == LV_COLOR_FORMAT_RGB565A8) { + return header->w * 2; + } + else { + return header->w * lv_color_format_get_size(header->cf); + } +} diff --git a/src/draw/sw/lv_draw_sw_letter.c b/src/draw/sw/lv_draw_sw_letter.c index c987e26a4..5f4a19f46 100644 --- a/src/draw/sw/lv_draw_sw_letter.c +++ b/src/draw/sw/lv_draw_sw_letter.c @@ -76,12 +76,14 @@ LV_ATTRIBUTE_FAST_MEM static void draw_letter_cb(lv_draw_unit_t * draw_unit, lv_ #endif } else if(glyph_draw_dsc->format == LV_DRAW_LETTER_BITMAP_FORMAT_A8) { + lv_area_t mask_area = *glyph_draw_dsc->letter_coords; + mask_area.x2 = mask_area.x1 + lv_draw_buf_width_to_stride(lv_area_get_width(&mask_area), LV_COLOR_FORMAT_A8) - 1; lv_draw_sw_blend_dsc_t blend_dsc; lv_memzero(&blend_dsc, sizeof(blend_dsc)); blend_dsc.color = glyph_draw_dsc->color; blend_dsc.opa = glyph_draw_dsc->opa; blend_dsc.mask_buf = glyph_draw_dsc->bitmap; - blend_dsc.mask_area = glyph_draw_dsc->letter_coords; + blend_dsc.mask_area = &mask_area; blend_dsc.blend_area = glyph_draw_dsc->letter_coords; blend_dsc.mask_res = LV_DRAW_SW_MASK_RES_CHANGED;