Own lv_img_dsc_t with dynamic .data

Hello folk,

I want to build an background based on binary images, which changes every 10 sec.
I created my own lv_img_dsc_t:

const lv_img_dsc_t bg1 = {
.header.always_zero = 0,
.header.w = 320,
.header.h = 240,
.data_size = 38464,
.header.cf = LV_IMG_CF_INDEXED_4BIT, /Set the color format/
.data = my_img_data+4,
};

lv_obj_t * scr1 = lv_scr_act();
lv_obj_t *img_bg = lv_img_create(scr1, NULL);
lv_img_set_src(img_bg, &bg1);

the pointer my_img_data will be filled by reading binary file from SPIFFS in function
set_bg_img(0, my_img_data);

in a loop i just set:

while(1) {

set_bg_img(screen, my_img_data); // uint8 screen number

}

it works fine for first image, all next images have wrong color, seems to be they are blended with first image colors.

I tried also to delete the object and create it new in the loop, nothing helps :frowning:

any hints,

Cheers,
Mike

V7.9, ESP32, M5STACK

first img, correct color

second img, wrong color, it should be green

when I set img 2 at first, then it is correct green, and the second is green as well

Hello, I suspect the issue is that you use a color index. I assume LVGL bases the colors for this index on a certain range of colors used by the first image.

Perhaps try using another color format instead of LV_IMG_CF_INDEXED_4BIT.

Hello,
Thanks for reply,
problem is solved, migrated to V8 and add
lv_obj_invalidate(img_bg); in loop

while(1) {

set_bg_img(screen, my_img_data); // uint8 screen number
lv_obj_invalidate(img_bg);

}
means LV_IMG_CF_INDEXED_4BIT contains all data for a whole screen,
which is good, the files are pretty small, I’m limited at my SPIFFS

Cheers,
Mike