Lv_image_set_src: failed to get image info

What do you want to achieve?

Display JPG images from SD card.

What have you tried so far?

I wrote a code using the documentation and examples. I think I set everything up correctly, but the images doesn’t dsiplay, I get the error message mentioned in the title. I don’t think this is a file system problem, as I can read the directory, and the file with lv_fs_open and lv_fs_read. Here is the log I get. I dump the first 16 bytes from the JPG file, just to make sure the file system is working and I can read the data from the file.
(13:10:32.234) I (2642) SDMCC: Open dir
(13:10:32.234) /SYSTEM~1
(13:10:32.234) FRAME_~1.JPG
(13:10:32.234) FRAME_~2.JPG
(13:10:32.234) FRAME_~3.JPG
(13:10:32.234) FRAME_~1.PNG
(13:10:32.234) IMG_LV~1.JPG
(13:10:32.234) ESP360.JPG
(13:10:32.235) ESP720.JPG
(13:10:32.235) ESP1080.JPG
(13:10:32.269) FLOWER.JPG
(13:10:32.269) I (2663) SDMCC: File opened A:ESP720
(13:10:32.269) I (2664) SDMCC: ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 01
(13:10:32.269) I (2664) SDMCC: 00 01 00 00 ff db 00 43 00 08 06 06 07 06 05 08
(13:10:32.269) [Info] (1.535, +1235) lv_button_create: begin lv_button.c:51
(13:10:32.269) [Info] (1.540, +5) lv_label_create: begin lv_label.c:131
(13:10:32.269) I (2680) SDMCC: Opening jpg from sd card
(13:10:32.269) [Info] (1.545, +5) lv_image_create: begin lv_image.c:149
(13:10:32.281) [Info] (1.555, +10) image_decoder_get_info: Can’t open image with decoder TJPGD. Trying next decoder. lv_image_decoder.c:390
(13:10:32.318) [Info] (1.565, +10) image_decoder_get_info: Can’t open image with decoder BIN. Trying next decoder. lv_image_decoder.c:390
(13:10:32.318) [Info] (1.575, +10) image_decoder_get_info: No decoder found lv_image_decoder.c:395
(13:10:32.318) [Warn] (1.580, +5) lv_image_set_src: failed to get image info: A:ESP720.JPG lv_image.c:195

Code to reproduce

void lv_fs_test(void) //read and display some data from the file
{
lv_fs_file_t f;
lv_fs_res_t res;
uint8_t read_buf[256];
uint32_t read_bytes;

res = lv_fs_open(&f, "A:ESP720.JPG", LV_FS_MODE_RD);
if(res != LV_FS_RES_OK) 
{
	ESP_LOGE(TAG, "Failed to open file");
}
else
{
	ESP_LOGI(TAG, "File opened A:ESP720");

	lv_fs_read(&f, read_buf,32,&read_bytes);
	
	ESP_LOG_BUFFER_HEX(TAG, read_buf, read_bytes);
	
	lv_fs_close(&f);	
}

}

void lv_example_image_1(void)
{
ESP_LOGI(TAG, “Opening jpg from sd card”);
lv_obj_t * img1 = lv_image_create(lv_screen_active());
lv_image_set_src(img1, “A:ESP720.JPG”);
lv_obj_align(img1, LV_ALIGN_CENTER, 0, 0);
}

void app_main(void)
{
esp_err_t ret;

ret=bsp_sdcard_mount();

if (ret != ESP_OK) {
	ESP_LOGE(TAG, "Failed to mount sd card");
} else {
	ESP_LOGI(TAG, "SD card mounted");	
}
lv_fs_init();

bsp_display_cfg_t cfg = {
    .lvgl_port_cfg = ESP_LVGL_PORT_INIT_CONFIG(),
    .buffer_size = BSP_LCD_DRAW_BUFF_SIZE,
    .double_buffer = BSP_LCD_DRAW_BUFF_DOUBLE,
    .flags = {
        .buff_dma = true,
        .buff_spiram = true,
        .sw_rotate = false,
    }
};
bsp_display_start_with_config(&cfg);
bsp_display_backlight_on();

bsp_display_lock(0);

lv_fs_dir_t dir;
lv_fs_res_t res;
res = lv_fs_dir_open(&dir, "A:/");

if(res != LV_FS_RES_OK) {
	ESP_LOGE(TAG, "Failed to open dir");
} else {
	ESP_LOGI(TAG, "Open dir");
	char fn[256];
	
	while(1) {
	    res = lv_fs_dir_read(&dir, fn, sizeof(fn));
	    if(res != LV_FS_RES_OK) {
	        break;
	    }

	    /*fn is empty, if not more files to read*/
	    if(strlen(fn) == 0) {
	        break;
    	}

    	printf("%s\n", fn);
	}
}
lv_fs_dir_close(&dir);

bsp_display_unlock();

lv_fs_test();

lv_example_image_1();

}

Screenshot and/or video

Environment

  • MCU/MPU/Board: ESP32P4, Guiton jc8012p4a1
  • LVGL version: 9.4

Hi!

A few things I see with the code.

  • Can you try adding a slash “/” here like “A:/ESP720.JPG”
  • Can you check if LV_USE_TJPGD is enabled in lv_conf?

Also this two functions seem to be outside lock/unlock

lv_fs_test();
lv_example_image_1();

But that depends on how exactly you are running the LVGL thread.