feat(png): add support for files without extension (#7289)
Signed-off-by: pengyiqiang <pengyiqiang@xiaomi.com> Co-authored-by: pengyiqiang <pengyiqiang@xiaomi.com>
@ -271,10 +271,6 @@ static lv_draw_buf_t * decode_png(lv_image_decoder_dsc_t * dsc)
|
||||
image.version = PNG_IMAGE_VERSION;
|
||||
|
||||
if(dsc->src_type == LV_IMAGE_SRC_FILE) {
|
||||
if(lv_strcmp(lv_fs_get_ext(dsc->src), "png") != 0) { /*Check the extension*/
|
||||
return NULL;
|
||||
}
|
||||
|
||||
png_data = alloc_file(dsc->src, &png_data_size);
|
||||
if(png_data == NULL) {
|
||||
LV_LOG_WARN("can't load file: %s", (const char *)dsc->src);
|
||||
|
@ -145,17 +145,16 @@ static lv_result_t decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_d
|
||||
size_t png_data_size = 0;
|
||||
if(dsc->src_type == LV_IMAGE_SRC_FILE) {
|
||||
const char * fn = dsc->src;
|
||||
if(lv_strcmp(lv_fs_get_ext(fn), "png") == 0) { /*Check the extension*/
|
||||
unsigned error;
|
||||
error = lodepng_load_file((void *)&png_data, &png_data_size, fn); /*Load the file*/
|
||||
if(error) {
|
||||
if(png_data != NULL) {
|
||||
lv_free((void *)png_data);
|
||||
}
|
||||
LV_LOG_WARN("error %u: %s\n", error, lodepng_error_text(error));
|
||||
LV_PROFILER_DECODER_END_TAG("lv_lodepng_decoder_open");
|
||||
return LV_RESULT_INVALID;
|
||||
|
||||
/*Load the file*/
|
||||
unsigned error = lodepng_load_file((void *)&png_data, &png_data_size, fn);
|
||||
if(error) {
|
||||
if(png_data != NULL) {
|
||||
lv_free((void *)png_data);
|
||||
}
|
||||
LV_LOG_WARN("error %u: %s\n", error, lodepng_error_text(error));
|
||||
LV_PROFILER_DECODER_END_TAG("lv_lodepng_decoder_open");
|
||||
return LV_RESULT_INVALID;
|
||||
}
|
||||
}
|
||||
else if(dsc->src_type == LV_IMAGE_SRC_VARIABLE) {
|
||||
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 13 KiB |
BIN
tests/src/test_assets/test_img_lvgl_logo_png_no_ext
Normal file
After Width: | Height: | Size: 6.7 KiB |
@ -15,40 +15,40 @@ void tearDown(void)
|
||||
/* Function run after every test */
|
||||
}
|
||||
|
||||
static void create_image_item(lv_obj_t * parent, const void * src, const char * text)
|
||||
{
|
||||
lv_obj_t * cont = lv_obj_create(parent);
|
||||
lv_obj_remove_style_all(cont);
|
||||
lv_obj_set_size(cont, 300, 200);
|
||||
lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_flex_align(cont, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||
|
||||
lv_obj_t * img = lv_image_create(cont);
|
||||
lv_image_set_src(img, src);
|
||||
|
||||
lv_obj_t * label = lv_label_create(cont);
|
||||
lv_label_set_text(label, text);
|
||||
}
|
||||
|
||||
static void create_images(void)
|
||||
{
|
||||
lv_obj_clean(lv_screen_active());
|
||||
|
||||
lv_obj_t * img;
|
||||
lv_obj_t * label;
|
||||
lv_obj_t * screen = lv_screen_active();
|
||||
lv_obj_clean(screen);
|
||||
lv_obj_set_flex_flow(screen, LV_FLEX_FLOW_ROW_WRAP);
|
||||
lv_obj_set_flex_align(screen, LV_FLEX_ALIGN_SPACE_AROUND, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||
|
||||
/* PNG array */
|
||||
LV_IMAGE_DECLARE(test_img_lvgl_logo_png);
|
||||
img = lv_image_create(lv_screen_active());
|
||||
lv_image_set_src(img, &test_img_lvgl_logo_png);
|
||||
lv_obj_align(img, LV_ALIGN_CENTER, -100, -20);
|
||||
|
||||
label = lv_label_create(lv_screen_active());
|
||||
lv_label_set_text(label, "Array");
|
||||
lv_obj_align(label, LV_ALIGN_CENTER, -100, 20);
|
||||
create_image_item(screen, &test_img_lvgl_logo_png, "Array");
|
||||
|
||||
/* 32 bit PNG file */
|
||||
img = lv_image_create(lv_screen_active());
|
||||
lv_image_set_src(img, "A:src/test_assets/test_img_lvgl_logo.png");
|
||||
lv_obj_align(img, LV_ALIGN_CENTER, 100, -100);
|
||||
create_image_item(screen, "A:src/test_assets/test_img_lvgl_logo.png", "File (32 bit)");
|
||||
|
||||
label = lv_label_create(lv_screen_active());
|
||||
lv_label_set_text(label, "File (32 bit)");
|
||||
lv_obj_align(label, LV_ALIGN_CENTER, 100, -60);
|
||||
/* No extension PNG file */
|
||||
create_image_item(screen, "A:src/test_assets/test_img_lvgl_logo_png_no_ext", "File (32 bit) No Extension");
|
||||
|
||||
/* 8 bit palette PNG file */
|
||||
img = lv_image_create(lv_screen_active());
|
||||
lv_image_set_src(img, "A:src/test_assets/test_img_lvgl_logo_8bit_palette.png");
|
||||
lv_obj_align(img, LV_ALIGN_CENTER, 100, 60);
|
||||
|
||||
label = lv_label_create(lv_screen_active());
|
||||
lv_label_set_text(label, "File (8 bit palette)");
|
||||
lv_obj_align(label, LV_ALIGN_CENTER, 100, 100);
|
||||
create_image_item(screen, "A:src/test_assets/test_img_lvgl_logo_8bit_palette.png", "File (8 bit palette)");
|
||||
}
|
||||
|
||||
void test_libpng_1(void)
|
||||
@ -58,7 +58,7 @@ void test_libpng_1(void)
|
||||
|
||||
create_images();
|
||||
|
||||
TEST_ASSERT_EQUAL_SCREENSHOT("libs/png_2.png");
|
||||
TEST_ASSERT_EQUAL_SCREENSHOT("libs/png_1.png");
|
||||
|
||||
size_t mem_before = lv_test_get_free_mem();
|
||||
for(uint32_t i = 0; i < 20; i++) {
|
||||
@ -68,7 +68,7 @@ void test_libpng_1(void)
|
||||
lv_refr_now(NULL);
|
||||
}
|
||||
|
||||
TEST_ASSERT_EQUAL_SCREENSHOT("libs/png_2.png");
|
||||
TEST_ASSERT_EQUAL_SCREENSHOT("libs/png_1.png");
|
||||
|
||||
TEST_ASSERT_MEM_LEAK_LESS_THAN(mem_before, 32);
|
||||
|
||||
|
@ -15,40 +15,40 @@ void tearDown(void)
|
||||
/* Function run after every test */
|
||||
}
|
||||
|
||||
static void create_image_item(lv_obj_t * parent, const void * src, const char * text)
|
||||
{
|
||||
lv_obj_t * cont = lv_obj_create(parent);
|
||||
lv_obj_remove_style_all(cont);
|
||||
lv_obj_set_size(cont, 300, 200);
|
||||
lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_flex_align(cont, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||
|
||||
lv_obj_t * img = lv_image_create(cont);
|
||||
lv_image_set_src(img, src);
|
||||
|
||||
lv_obj_t * label = lv_label_create(cont);
|
||||
lv_label_set_text(label, text);
|
||||
}
|
||||
|
||||
static void create_images(void)
|
||||
{
|
||||
lv_obj_clean(lv_screen_active());
|
||||
|
||||
lv_obj_t * img;
|
||||
lv_obj_t * label;
|
||||
lv_obj_t * screen = lv_screen_active();
|
||||
lv_obj_clean(screen);
|
||||
lv_obj_set_flex_flow(screen, LV_FLEX_FLOW_ROW_WRAP);
|
||||
lv_obj_set_flex_align(screen, LV_FLEX_ALIGN_SPACE_AROUND, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||
|
||||
/* PNG array */
|
||||
LV_IMAGE_DECLARE(test_img_lvgl_logo_png);
|
||||
img = lv_image_create(lv_screen_active());
|
||||
lv_image_set_src(img, &test_img_lvgl_logo_png);
|
||||
lv_obj_align(img, LV_ALIGN_CENTER, -100, -20);
|
||||
|
||||
label = lv_label_create(lv_screen_active());
|
||||
lv_label_set_text(label, "Array");
|
||||
lv_obj_align(label, LV_ALIGN_CENTER, -100, 20);
|
||||
create_image_item(screen, &test_img_lvgl_logo_png, "Array");
|
||||
|
||||
/* 32 bit PNG file */
|
||||
img = lv_image_create(lv_screen_active());
|
||||
lv_image_set_src(img, "A:src/test_assets/test_img_lvgl_logo.png");
|
||||
lv_obj_align(img, LV_ALIGN_CENTER, 100, -100);
|
||||
create_image_item(screen, "A:src/test_assets/test_img_lvgl_logo.png", "File (32 bit)");
|
||||
|
||||
label = lv_label_create(lv_screen_active());
|
||||
lv_label_set_text(label, "File (32 bit)");
|
||||
lv_obj_align(label, LV_ALIGN_CENTER, 100, -60);
|
||||
/* No extension PNG file */
|
||||
create_image_item(screen, "A:src/test_assets/test_img_lvgl_logo_png_no_ext", "File (32 bit) No Extension");
|
||||
|
||||
/* 8 bit palette PNG file */
|
||||
img = lv_image_create(lv_screen_active());
|
||||
lv_image_set_src(img, "A:src/test_assets/test_img_lvgl_logo_8bit_palette.png");
|
||||
lv_obj_align(img, LV_ALIGN_CENTER, 100, 60);
|
||||
|
||||
label = lv_label_create(lv_screen_active());
|
||||
lv_label_set_text(label, "File (8 bit palette)");
|
||||
lv_obj_align(label, LV_ALIGN_CENTER, 100, 100);
|
||||
create_image_item(screen, "A:src/test_assets/test_img_lvgl_logo_8bit_palette.png", "File (8 bit palette)");
|
||||
}
|
||||
|
||||
void test_lodepng_1(void)
|
||||
|