display_gif_sd: load GIF from SD into PSRAM once, play from memory (9.8 -> 15.4 fps)
Also enable a 16 KB LVGL stdio read cache (no measurable effect for the GIF). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
55e27b6572
commit
71d4bf7b58
2 files changed
+19
-7
No files matched your search
@@ -22,14 +22,26 @@ void display_animation() {
|
||||
lv_mem_monitor(&mem_mon);
|
||||
printf("Free memory: %d bytes\n", mem_mon.free_size);
|
||||
|
||||
lv_fs_file_t file;
|
||||
if (lv_fs_open(&file, "A:wallpaper.gif", LV_FS_MODE_RD) == LV_FS_RES_OK) {
|
||||
lv_fs_close(&file); // File exists, proceed with loading
|
||||
lv_gif_set_src(img, "A:wallpaper.gif");
|
||||
Serial.println("GIF Loaded Successfully");
|
||||
// Load the whole GIF from the SD card into PSRAM once and play it from memory:
|
||||
// no SD access while playing (faster, and kinder to flaky cards)
|
||||
static lv_image_dsc_t gif_dsc;
|
||||
File f = SD_MMC.open("/wallpaper.gif");
|
||||
size_t size = f ? f.size() : 0;
|
||||
uint8_t* data = size ? (uint8_t*)ps_malloc(size) : NULL;
|
||||
if (data && f.read(data, size) == size) {
|
||||
gif_dsc.header.magic = LV_IMAGE_HEADER_MAGIC;
|
||||
gif_dsc.header.cf = LV_COLOR_FORMAT_RAW;
|
||||
gif_dsc.header.w = data[6] | (data[7] << 8); // GIF logical screen size
|
||||
gif_dsc.header.h = data[8] | (data[9] << 8);
|
||||
gif_dsc.data_size = size;
|
||||
gif_dsc.data = data;
|
||||
lv_gif_set_src(img, &gif_dsc);
|
||||
Serial.printf("GIF loaded into PSRAM: %u bytes, %u x %u\n", size, gif_dsc.header.w, gif_dsc.header.h);
|
||||
} else {
|
||||
Serial.println("Failed to Load GIF: File not found or inaccessible");
|
||||
Serial.println("Failed to load /wallpaper.gif from the SD card");
|
||||
free(data);
|
||||
}
|
||||
if (f) f.close();
|
||||
|
||||
Serial.print("Available Heap after: ");
|
||||
Serial.println(esp_get_free_heap_size());
|
||||
|
||||
@@ -1967,7 +1967,7 @@
|
||||
#define LV_FS_STDIO_PATH "/sdcard/"
|
||||
|
||||
/** Read cache size in bytes for stdio (0 = disabled) */
|
||||
#define LV_FS_STDIO_CACHE_SIZE 0
|
||||
#define LV_FS_STDIO_CACHE_SIZE 16384 /* JC3636W518: fewer small SD reads (GIF decoding) */
|
||||
|
||||
#endif /*LV_USE_FS_STDIO*/
|
||||
|
||||
|
||||
Reference in new issue
Block a user