Skip to content

Commit

Permalink
feat(decoder): use draw buf to describe decoded image
Browse files Browse the repository at this point in the history
Signed-off-by: Xu Xingliang <xuxingliang@xiaomi.com>
  • Loading branch information
XuNeo committed Dec 11, 2023
1 parent 7119b74 commit 74273ac
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 85 deletions.
1 change: 1 addition & 0 deletions src/draw/lv_image_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ lv_result_t lv_image_decoder_open(lv_image_decoder_dsc_t * dsc, const void * src

dsc->error_msg = NULL;
dsc->img_data = NULL;
dsc->decoded = NULL;
dsc->cache_entry = NULL;
dsc->user_data = NULL;
dsc->time_to_open = 0;
Expand Down
12 changes: 11 additions & 1 deletion src/draw/lv_image_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extern "C" {
#include "../lv_conf_internal.h"

#include <stdint.h>
#include "lv_image_buf.h"
#include "lv_draw_buf.h"
#include "../misc/lv_fs.h"
#include "../misc/lv_types.h"
#include "../misc/lv_area.h"
Expand Down Expand Up @@ -136,6 +136,8 @@ typedef struct _lv_image_decoder_dsc_t {
* MUST be set in `open` function*/
const uint8_t * img_data;

const lv_draw_buf_t * decoded; /*A draw buffer to described decoded image.*/

const lv_color32_t * palette;
uint32_t palette_size;

Expand All @@ -158,6 +160,14 @@ typedef struct _lv_image_decoder_dsc_t {
* GLOBAL PROTOTYPES
**********************/

/**
* @todo remove it when all decoder migrates to new draw buf interface.
*/
static inline const void * _lv_image_decoder_get_data(const lv_image_decoder_dsc_t * dsc)
{
return dsc->decoded ? dsc->decoded->data : dsc->img_data;
}

/**
* Initialize the image decoder module
*/
Expand Down
2 changes: 1 addition & 1 deletion src/draw/sw/lv_draw_sw_arc.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void lv_draw_sw_arc(lv_draw_unit_t * draw_unit, const lv_draw_arc_dsc_t * dsc, c
int32_t ofs = decoder_dsc.header.w / 2;
lv_area_move(&img_area, dsc->center.x - ofs, dsc->center.y - ofs);
blend_dsc.src_area = &img_area;
blend_dsc.src_buf = decoder_dsc.img_data;
blend_dsc.src_buf = _lv_image_decoder_get_data(&decoder_dsc);
blend_dsc.src_color_format = decoder_dsc.header.cf;
blend_dsc.src_stride = decoder_dsc.header.stride;
}
Expand Down
10 changes: 8 additions & 2 deletions src/draw/sw/lv_draw_sw_img.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ static void img_decode_and_draw(lv_draw_unit_t * draw_unit, const lv_draw_image_
sup.palette_size = decoder_dsc->palette_size;

/*The whole image is available, just draw it*/
if(decoder_dsc->img_data) {
if(decoder_dsc->decoded || decoder_dsc->img_data) {
img_draw_core(draw_unit, draw_dsc, decoder_dsc, &sup, img_area, clipped_img_area);
}
/*Draw in smaller pieces*/
Expand Down Expand Up @@ -298,7 +298,13 @@ static void img_draw_core(lv_draw_unit_t * draw_unit, const lv_draw_image_dsc_t
uint32_t img_stride = header->stride;
lv_color_format_t cf = header->cf;

cf = LV_COLOR_FORMAT_IS_INDEXED(cf) ? LV_COLOR_FORMAT_ARGB8888 : cf,
cf = LV_COLOR_FORMAT_IS_INDEXED(cf) ? LV_COLOR_FORMAT_ARGB8888 : cf;

if(decoder_dsc->decoded) {
src_buf = decoder_dsc->decoded->data;
img_stride = decoder_dsc->decoded->header.stride;
cf = decoder_dsc->decoded->header.cf;
}

lv_memzero(&blend_dsc, sizeof(lv_draw_sw_blend_dsc_t));
blend_dsc.opa = draw_dsc->opa;
Expand Down
4 changes: 2 additions & 2 deletions src/draw/sw/lv_draw_sw_vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,13 @@ static void _set_paint_fill_pattern(Tvg_Paint * obj, Tvg_Canvas * canvas, const
return;
}

if(!decoder_dsc.img_data) {
if(!decoder_dsc.decoded && !decoder_dsc.img_data) {
lv_image_decoder_close(&decoder_dsc);
LV_LOG_ERROR("Image not ready");
return;
}

const uint8_t * src_buf = decoder_dsc.img_data;
const uint8_t * src_buf = _lv_image_decoder_get_data(&decoder_dsc);
const lv_image_header_t * header = &decoder_dsc.header;
lv_color_format_t cf = header->cf;

Expand Down
Loading

0 comments on commit 74273ac

Please sign in to comment.