chore(color): improve TRACE error messages for image file handling (#6939)
This commit is contained in:
@@ -111,7 +111,7 @@ BitmapBuffer *BitmapBuffer::loadBitmap(const char *filename, BitmapFormats fmt)
|
|||||||
f_close(&imgFile);
|
f_close(&imgFile);
|
||||||
|
|
||||||
if (!img) {
|
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;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ BitmapBuffer *BitmapBuffer::loadBitmap(const char *filename, BitmapFormats fmt)
|
|||||||
|
|
||||||
BitmapBuffer *bmp = new BitmapBuffer(dst_fmt, w, h);
|
BitmapBuffer *bmp = new BitmapBuffer(dst_fmt, w, h);
|
||||||
if (bmp == nullptr) {
|
if (bmp == nullptr) {
|
||||||
TRACE_ERROR("loadBitmap: malloc failed");
|
TRACE_ERROR("loadBitmap: malloc failed\n");
|
||||||
return nullptr;
|
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);
|
FRESULT result = f_open(&imgFile, fn, FA_OPEN_EXISTING | FA_READ);
|
||||||
if (result == FR_OK) {
|
if (result == FR_OK) {
|
||||||
int x, y, nn;
|
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);
|
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->always_zero = 0;
|
||||||
header->cf =
|
header->cf =
|
||||||
(nn == 4) ? LV_IMG_CF_TRUE_COLOR_ALPHA : LV_IMG_CF_TRUE_COLOR;
|
(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;
|
header->h = y;
|
||||||
|
|
||||||
return LV_RES_OK;
|
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...*/
|
/*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);
|
uint8_t *bmp = (uint8_t *)lv_mem_alloc(((n == 4) ? 3 : 2) * w * h);
|
||||||
if (bmp == nullptr) {
|
if (bmp == nullptr) {
|
||||||
TRACE_ERROR("convert_bitmap: lv_mem_alloc failed");
|
TRACE_ERROR("convert_bitmap: lv_mem_alloc failed\n");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,7 +247,7 @@ static lv_res_t decoder_open(lv_img_decoder_t *decoder,
|
|||||||
f_close(&imgFile);
|
f_close(&imgFile);
|
||||||
|
|
||||||
if (!img) {
|
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;
|
return LV_RES_INV;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,6 +255,8 @@ static lv_res_t decoder_open(lv_img_decoder_t *decoder,
|
|||||||
stbi_image_free(img);
|
stbi_image_free(img);
|
||||||
|
|
||||||
return dsc->img_data ? LV_RES_OK : LV_RES_INV;
|
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...*/
|
/*If it's a file in a C array...*/
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "lz4/lz4.h"
|
#include "lz4/lz4.h"
|
||||||
#include "sdcard.h"
|
#include "sdcard.h"
|
||||||
#include "etx_lv_theme.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());
|
lv_img_set_src(image, fullpath.c_str());
|
||||||
if (!hasImage()) {
|
if (!hasImage()) {
|
||||||
// Failed to load
|
// 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();
|
clearSource();
|
||||||
}
|
}
|
||||||
setZoom();
|
setZoom();
|
||||||
|
|||||||
Reference in New Issue
Block a user