diff --git a/src/libs/libpng/lv_libpng.c b/src/libs/libpng/lv_libpng.c index 89340dea6..15578f7ab 100644 --- a/src/libs/libpng/lv_libpng.c +++ b/src/libs/libpng/lv_libpng.c @@ -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); diff --git a/src/libs/lodepng/lv_lodepng.c b/src/libs/lodepng/lv_lodepng.c index cef4cbc2f..d9db17dd1 100644 --- a/src/libs/lodepng/lv_lodepng.c +++ b/src/libs/lodepng/lv_lodepng.c @@ -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) { diff --git a/tests/ref_imgs/libs/png_1.png b/tests/ref_imgs/libs/png_1.png index b45e030f6..4d968feb2 100644 Binary files a/tests/ref_imgs/libs/png_1.png and b/tests/ref_imgs/libs/png_1.png differ diff --git a/tests/ref_imgs/libs/png_2.png b/tests/ref_imgs/libs/png_2.png deleted file mode 100644 index b45e030f6..000000000 Binary files a/tests/ref_imgs/libs/png_2.png and /dev/null differ diff --git a/tests/ref_imgs_vg_lite/libs/png_1.png b/tests/ref_imgs_vg_lite/libs/png_1.png index 13d0cb00e..28a7f5170 100644 Binary files a/tests/ref_imgs_vg_lite/libs/png_1.png and b/tests/ref_imgs_vg_lite/libs/png_1.png differ diff --git a/tests/ref_imgs_vg_lite/libs/png_2.png b/tests/ref_imgs_vg_lite/libs/png_2.png deleted file mode 100644 index 13d0cb00e..000000000 Binary files a/tests/ref_imgs_vg_lite/libs/png_2.png and /dev/null differ diff --git a/tests/src/test_assets/test_img_lvgl_logo_png_no_ext b/tests/src/test_assets/test_img_lvgl_logo_png_no_ext new file mode 100644 index 000000000..aaaa7b05f Binary files /dev/null and b/tests/src/test_assets/test_img_lvgl_logo_png_no_ext differ diff --git a/tests/src/test_cases/libs/test_libpng.c b/tests/src/test_cases/libs/test_libpng.c index 714eab355..4db9b80c5 100644 --- a/tests/src/test_cases/libs/test_libpng.c +++ b/tests/src/test_cases/libs/test_libpng.c @@ -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); diff --git a/tests/src/test_cases/libs/test_lodepng.c b/tests/src/test_cases/libs/test_lodepng.c index 5f3f1cf78..aae78f309 100644 --- a/tests/src/test_cases/libs/test_lodepng.c +++ b/tests/src/test_cases/libs/test_lodepng.c @@ -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)