feat(img_decoder) add frame_id parameter to the image decoder

Related to #2090
This commit is contained in:
Gabor Kiss-Vamosi
2021-04-14 17:04:24 +02:00
parent e4345bd7f5
commit ff330b0f42
6 changed files with 25 additions and 29 deletions

View File

@@ -236,7 +236,7 @@ LV_ATTRIBUTE_FAST_MEM static lv_res_t lv_img_draw_core(const lv_area_t * coords,
{ {
if(draw_dsc->opa <= LV_OPA_MIN) return LV_RES_OK; if(draw_dsc->opa <= LV_OPA_MIN) return LV_RES_OK;
lv_img_cache_entry_t * cdsc = _lv_img_cache_open(src, draw_dsc->recolor); lv_img_cache_entry_t * cdsc = _lv_img_cache_open(src, draw_dsc->recolor, draw_dsc->frame_id);
if(cdsc == NULL) return LV_RES_INV; if(cdsc == NULL) return LV_RES_INV;

View File

@@ -30,17 +30,18 @@ extern "C" {
**********************/ **********************/
typedef struct { typedef struct {
lv_opa_t opa;
uint16_t angle; uint16_t angle;
lv_point_t pivot;
uint16_t zoom; uint16_t zoom;
lv_point_t pivot;
lv_opa_t recolor_opa;
lv_color_t recolor; lv_color_t recolor;
lv_opa_t recolor_opa;
lv_blend_mode_t blend_mode; lv_opa_t opa;
lv_blend_mode_t blend_mode : 4;
int32_t frame_id;
uint8_t antialias : 1; uint8_t antialias : 1;
} lv_draw_img_dsc_t; } lv_draw_img_dsc_t;

View File

@@ -60,7 +60,7 @@
* @param color color The color of the image with `LV_IMG_CF_ALPHA_...` * @param color color The color of the image with `LV_IMG_CF_ALPHA_...`
* @return pointer to the cache entry or NULL if can open the image * @return pointer to the cache entry or NULL if can open the image
*/ */
lv_img_cache_entry_t * _lv_img_cache_open(const void * src, lv_color_t color) lv_img_cache_entry_t * _lv_img_cache_open(const void * src, lv_color_t color, int32_t frame_id)
{ {
/*Is the image cached?*/ /*Is the image cached?*/
lv_img_cache_entry_t * cached_src = NULL; lv_img_cache_entry_t * cached_src = NULL;
@@ -83,6 +83,7 @@ lv_img_cache_entry_t * _lv_img_cache_open(const void * src, lv_color_t color)
for(i = 0; i < entry_cnt; i++) { for(i = 0; i < entry_cnt; i++) {
if(color.full == cache[i].dec_dsc.color.full && if(color.full == cache[i].dec_dsc.color.full &&
frame_id == cache[i].dec_dsc.frame_id &&
lv_img_cache_match(src, cache[i].dec_dsc.src)) { lv_img_cache_match(src, cache[i].dec_dsc.src)) {
/*If opened increment its life. /*If opened increment its life.
*Image difficult to open should live longer to keep avoid frequent their recaching. *Image difficult to open should live longer to keep avoid frequent their recaching.
@@ -119,7 +120,7 @@ lv_img_cache_entry_t * _lv_img_cache_open(const void * src, lv_color_t color)
#endif #endif
/*Open the image and measure the time to open*/ /*Open the image and measure the time to open*/
uint32_t t_start = lv_tick_get(); uint32_t t_start = lv_tick_get();
lv_res_t open_res = lv_img_decoder_open(&cached_src->dec_dsc, src, color); lv_res_t open_res = lv_img_decoder_open(&cached_src->dec_dsc, src, color, frame_id);
if(open_res == LV_RES_INV) { if(open_res == LV_RES_INV) {
LV_LOG_WARN("Image draw cannot open the image resource"); LV_LOG_WARN("Image draw cannot open the image resource");
lv_memset_00(cached_src, sizeof(lv_img_cache_entry_t)); lv_memset_00(cached_src, sizeof(lv_img_cache_entry_t));

View File

@@ -47,9 +47,10 @@ typedef struct {
* The image is closed if a new image is opened and the new image takes its place in the cache. * The image is closed if a new image is opened and the new image takes its place in the cache.
* @param src source of the image. Path to file or pointer to an `lv_img_dsc_t` variable * @param src source of the image. Path to file or pointer to an `lv_img_dsc_t` variable
* @param color The color of the image with `LV_IMG_CF_ALPHA_...` * @param color The color of the image with `LV_IMG_CF_ALPHA_...`
* @param frame_id the index of the frame. Used only with animated images, set 0 for normal images
* @return pointer to the cache entry or NULL if can open the image * @return pointer to the cache entry or NULL if can open the image
*/ */
lv_img_cache_entry_t * _lv_img_cache_open(const void * src, lv_color_t color); lv_img_cache_entry_t * _lv_img_cache_open(const void * src, lv_color_t color, int32_t frame_id);
/** /**
* Set the number of images to be cached. * Set the number of images to be cached.

View File

@@ -95,24 +95,13 @@ lv_res_t lv_img_decoder_get_info(const void * src, lv_img_header_t * header)
return res; return res;
} }
/** lv_res_t lv_img_decoder_open(lv_img_decoder_dsc_t * dsc, const void * src, lv_color_t color, int32_t frame_id)
* Open an image.
* Try the created image decoder one by one. Once one is able to open the image that decoder is save in `dsc`
* @param dsc describe a decoding session. Simply a pointer to an `lv_img_decoder_dsc_t` variable.
* @param src the image source. Can be
* 1) File name: E.g. "S:folder/img1.png" (The drivers needs to registered via `lv_fs_add_drv()`)
* 2) Variable: Pointer to an `lv_img_dsc_t` variable
* 3) Symbol: E.g. `LV_SYMBOL_OK`
* @param color The color of the image with `LV_IMG_CF_ALPHA_...`
* @return LV_RES_OK: opened the image. `dsc->img_data` and `dsc->header` are set.
* LV_RES_INV: none of the registered image decoders were able to open the image.
*/
lv_res_t lv_img_decoder_open(lv_img_decoder_dsc_t * dsc, const void * src, lv_color_t color)
{ {
lv_memset_00(dsc, sizeof(lv_img_decoder_dsc_t)); lv_memset_00(dsc, sizeof(lv_img_decoder_dsc_t));
dsc->color = color; dsc->color = color;
dsc->src_type = lv_img_src_get_type(src); dsc->src_type = lv_img_src_get_type(src);
dsc->frame_id = frame_id;
if(dsc->src_type == LV_IMG_SRC_FILE) { if(dsc->src_type == LV_IMG_SRC_FILE) {
size_t fnlen = strlen(src); size_t fnlen = strlen(src);
@@ -130,16 +119,16 @@ lv_res_t lv_img_decoder_open(lv_img_decoder_dsc_t * dsc, const void * src, lv_co
lv_res_t res = LV_RES_INV; lv_res_t res = LV_RES_INV;
lv_img_decoder_t * d; lv_img_decoder_t * decoder;
_LV_LL_READ(&LV_GC_ROOT(_lv_img_decoder_ll), d) { _LV_LL_READ(&LV_GC_ROOT(_lv_img_decoder_ll), decoder) {
/*Info and Open callbacks are required*/ /*Info and Open callbacks are required*/
if(d->info_cb == NULL || d->open_cb == NULL) continue; if(decoder->info_cb == NULL || decoder->open_cb == NULL) continue;
res = d->info_cb(d, src, &dsc->header); res = decoder->info_cb(decoder, src, &dsc->header);
if(res != LV_RES_OK) continue; if(res != LV_RES_OK) continue;
dsc->decoder = d; dsc->decoder = decoder;
res = d->open_cb(d, dsc); res = decoder->open_cb(decoder, dsc);
/*Opened successfully. It is a good decoder to for this image source*/ /*Opened successfully. It is a good decoder to for this image source*/
if(res == LV_RES_OK) return res; if(res == LV_RES_OK) return res;

View File

@@ -102,9 +102,12 @@ typedef struct _lv_img_decoder_dsc {
/**The image source. A file path like "S:my_img.png" or pointer to an `lv_img_dsc_t` variable*/ /**The image source. A file path like "S:my_img.png" or pointer to an `lv_img_dsc_t` variable*/
const void * src; const void * src;
/**Style to draw the image.*/ /**Color to draw the image. USed when the image has alpha channel only*/
lv_color_t color; lv_color_t color;
/**Frame of the image, using with animated images*/
int32_t frame_id;
/**Type of the source: file or variable. Can be set in `open` function if required*/ /**Type of the source: file or variable. Can be set in `open` function if required*/
lv_img_src_t src_type; lv_img_src_t src_type;
@@ -157,10 +160,11 @@ lv_res_t lv_img_decoder_get_info(const void * src, lv_img_header_t * header);
* 2) Variable: Pointer to an `lv_img_dsc_t` variable * 2) Variable: Pointer to an `lv_img_dsc_t` variable
* 3) Symbol: E.g. `LV_SYMBOL_OK` * 3) Symbol: E.g. `LV_SYMBOL_OK`
* @param color The color of the image with `LV_IMG_CF_ALPHA_...` * @param color The color of the image with `LV_IMG_CF_ALPHA_...`
* @param frame_id the index of the frame. Used only with animated images, set 0 for normal images
* @return LV_RES_OK: opened the image. `dsc->img_data` and `dsc->header` are set. * @return LV_RES_OK: opened the image. `dsc->img_data` and `dsc->header` are set.
* LV_RES_INV: none of the registered image decoders were able to open the image. * LV_RES_INV: none of the registered image decoders were able to open the image.
*/ */
lv_res_t lv_img_decoder_open(lv_img_decoder_dsc_t * dsc, const void * src, lv_color_t color); lv_res_t lv_img_decoder_open(lv_img_decoder_dsc_t * dsc, const void * src, lv_color_t color, int32_t frame_id);
/** /**
* Read a line from an opened image * Read a line from an opened image