From 586a567b0b4bffef47b091510b5d053be5255cc9 Mon Sep 17 00:00:00 2001 From: philmoz Date: Sun, 4 Jan 2026 12:18:05 +1100 Subject: [PATCH] chore(color): improve TRACE error messages for image file handling (#6939) --- .../colorlcd/libui/bitmapbuffer_fileio.cpp | 19 ++++++++++++++----- radio/src/gui/colorlcd/libui/static.cpp | 3 ++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/radio/src/gui/colorlcd/libui/bitmapbuffer_fileio.cpp b/radio/src/gui/colorlcd/libui/bitmapbuffer_fileio.cpp index c397bdf9a..dddf7a1bf 100644 --- a/radio/src/gui/colorlcd/libui/bitmapbuffer_fileio.cpp +++ b/radio/src/gui/colorlcd/libui/bitmapbuffer_fileio.cpp @@ -111,7 +111,7 @@ BitmapBuffer *BitmapBuffer::loadBitmap(const char *filename, BitmapFormats fmt) f_close(&imgFile); if (!img) { - TRACE_ERROR("loadBitmap(%s) failed: %s", filename, stbi_failure_reason()); + TRACE_ERROR("loadBitmap(%s) failed: %s\n", filename, stbi_failure_reason()); return nullptr; } @@ -123,7 +123,7 @@ BitmapBuffer *BitmapBuffer::loadBitmap(const char *filename, BitmapFormats fmt) BitmapBuffer *bmp = new BitmapBuffer(dst_fmt, w, h); if (bmp == nullptr) { - TRACE_ERROR("loadBitmap: malloc failed"); + TRACE_ERROR("loadBitmap: malloc failed\n"); return nullptr; } @@ -168,9 +168,14 @@ static lv_res_t decoder_info(struct _lv_img_decoder_t *decoder, const void *src, FRESULT result = f_open(&imgFile, fn, FA_OPEN_EXISTING | FA_READ); if (result == FR_OK) { int x, y, nn; - stbi_info_from_callbacks(&stbCallbacks, &imgFile, &x, &y, &nn); + int res = stbi_info_from_callbacks(&stbCallbacks, &imgFile, &x, &y, &nn); f_close(&imgFile); + if (res == LV_RES_INV) { + TRACE_ERROR("decoder_info(%s) failed: %s\n", fn, stbi_failure_reason()); + return LV_RES_INV; + } + header->always_zero = 0; header->cf = (nn == 4) ? LV_IMG_CF_TRUE_COLOR_ALPHA : LV_IMG_CF_TRUE_COLOR; @@ -178,6 +183,8 @@ static lv_res_t decoder_info(struct _lv_img_decoder_t *decoder, const void *src, header->h = y; return LV_RES_OK; + } else { + TRACE_ERROR("decoder_info(%s) failed to open image file\n", fn); } } /*If it's a file in a C array...*/ @@ -192,7 +199,7 @@ static uint8_t *convert_bitmap(uint8_t *img, int w, int h, int n) { uint8_t *bmp = (uint8_t *)lv_mem_alloc(((n == 4) ? 3 : 2) * w * h); if (bmp == nullptr) { - TRACE_ERROR("convert_bitmap: lv_mem_alloc failed"); + TRACE_ERROR("convert_bitmap: lv_mem_alloc failed\n"); return nullptr; } @@ -240,7 +247,7 @@ static lv_res_t decoder_open(lv_img_decoder_t *decoder, f_close(&imgFile); if (!img) { - TRACE_ERROR("decoder_open(%s) failed: %s", fn, stbi_failure_reason()); + TRACE_ERROR("decoder_open(%s) failed: %s\n", fn, stbi_failure_reason()); return LV_RES_INV; } @@ -248,6 +255,8 @@ static lv_res_t decoder_open(lv_img_decoder_t *decoder, stbi_image_free(img); return dsc->img_data ? LV_RES_OK : LV_RES_INV; + } else { + TRACE_ERROR("decoder_open(%s) failed to open image file\n", fn); } } /*If it's a file in a C array...*/ diff --git a/radio/src/gui/colorlcd/libui/static.cpp b/radio/src/gui/colorlcd/libui/static.cpp index 532e70889..6a67adc91 100644 --- a/radio/src/gui/colorlcd/libui/static.cpp +++ b/radio/src/gui/colorlcd/libui/static.cpp @@ -22,6 +22,7 @@ #include "lz4/lz4.h" #include "sdcard.h" #include "etx_lv_theme.h" +#include "stb/stb_image.h" //----------------------------------------------------------------------------- @@ -238,7 +239,7 @@ void StaticImage::setSource(std::string filename) lv_img_set_src(image, fullpath.c_str()); if (!hasImage()) { // Failed to load - TRACE_ERROR("could not load image '%s'", filename.c_str()); + TRACE_ERROR("could not load image '%s' - %s\n", filename.c_str(), stbi_failure_reason()); clearSource(); } setZoom();