Adding nullpointer checks to GDISP image functions
This commit is contained in:
parent
82047b1ac6
commit
ea158a836d
@ -60,6 +60,7 @@ FEATURE: Added AHTML2COLOR() and ARGB2COLOR() to support alpha. This is currentl
|
||||
FEATURE: Added the new color GFXTRANSPARENT - only available for RGB888 pixel format on alpha capable displays.
|
||||
NOTE: Alpha support in RGB888 requies an alpha capable display (STM32LTDC 2nd display only currently)
|
||||
NOTE: Alpha support in RGB888 is NOT the standard ARGB8888 format. Only use AHTML2COLOR() and ARGB2COLOR() to create alpha colors.
|
||||
FEATURE: Added nullpointer checks to GDISP image functions (with new error code GDISP_IMAGE_ERR_NULLPOINTER)
|
||||
|
||||
|
||||
*** Release 2.7 ***
|
||||
|
@ -110,6 +110,8 @@ void gdispImageInit(gdispImage *img) {
|
||||
gdispImageError gdispImageOpenGFile(gdispImage *img, GFILE *f) {
|
||||
gdispImageError err;
|
||||
|
||||
if (!img)
|
||||
return GDISP_IMAGE_ERR_NULLPOINTER;
|
||||
if (!f)
|
||||
return GDISP_IMAGE_ERR_NOSUCHFILE;
|
||||
img->f = f;
|
||||
@ -141,6 +143,8 @@ unrecoverable:
|
||||
}
|
||||
|
||||
void gdispImageClose(gdispImage *img) {
|
||||
if (!img)
|
||||
return;
|
||||
if (img->fns)
|
||||
img->fns->close(img);
|
||||
gfileClose(img->f);
|
||||
@ -151,19 +155,25 @@ void gdispImageClose(gdispImage *img) {
|
||||
}
|
||||
|
||||
bool_t gdispImageIsOpen(gdispImage *img) {
|
||||
if (!img)
|
||||
return FALSE;
|
||||
return img->type != GDISP_IMAGE_TYPE_UNKNOWN && img->fns != 0;
|
||||
}
|
||||
|
||||
void gdispImageSetBgColor(gdispImage *img, color_t bgcolor) {
|
||||
if (!img)
|
||||
return;
|
||||
img->bgcolor = bgcolor;
|
||||
}
|
||||
|
||||
gdispImageError gdispImageCache(gdispImage *img) {
|
||||
if (!img) return GDISP_IMAGE_ERR_NULLPOINTER;
|
||||
if (!img->fns) return GDISP_IMAGE_ERR_BADFORMAT;
|
||||
return img->fns->cache(img);
|
||||
}
|
||||
|
||||
gdispImageError gdispGImageDraw(GDisplay *g, gdispImage *img, coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t sx, coord_t sy) {
|
||||
if (!img) return GDISP_IMAGE_ERR_NULLPOINTER;
|
||||
if (!img->fns) return GDISP_IMAGE_ERR_BADFORMAT;
|
||||
|
||||
// Check on window
|
||||
@ -179,24 +189,25 @@ gdispImageError gdispGImageDraw(GDisplay *g, gdispImage *img, coord_t x, coord_t
|
||||
}
|
||||
|
||||
delaytime_t gdispImageNext(gdispImage *img) {
|
||||
if (!img) return GDISP_IMAGE_ERR_NULLPOINTER;
|
||||
if (!img->fns) return GDISP_IMAGE_ERR_BADFORMAT;
|
||||
return img->fns->next(img);
|
||||
}
|
||||
|
||||
uint16_t gdispImageGetPaletteSize(gdispImage *img) {
|
||||
if (!img->fns) return 0;
|
||||
if (!img || !img->fns) return 0;
|
||||
if (!img->fns->getPaletteSize) return 0;
|
||||
return img->fns->getPaletteSize(img);
|
||||
}
|
||||
|
||||
color_t gdispImageGetPalette(gdispImage *img, uint16_t index) {
|
||||
if (!img->fns) return 0;
|
||||
if (!img || !img->fns) return 0;
|
||||
if (!img->fns->getPalette) return 0;
|
||||
return img->fns->getPalette(img, index);
|
||||
}
|
||||
|
||||
bool_t gdispImageAdjustPalette(gdispImage *img, uint16_t index, color_t newColor) {
|
||||
if (!img->fns) return FALSE;
|
||||
if (!img || !img->fns) return FALSE;
|
||||
if (!img->fns->adjustPalette) return FALSE;
|
||||
return img->fns->adjustPalette(img, index, newColor);
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ typedef uint16_t gdispImageError;
|
||||
#define GDISP_IMAGE_ERR_UNSUPPORTED_OK 3
|
||||
#define GDISP_IMAGE_ERR_NOMEMORY (GDISP_IMAGE_ERR_UNRECOVERABLE+4)
|
||||
#define GDISP_IMAGE_ERR_NOSUCHFILE (GDISP_IMAGE_ERR_UNRECOVERABLE+5)
|
||||
#define GDISP_IMAGE_ERR_NULLPOINTER (GDISP_IMAGE_ERR_UNRECOVERABLE+6)
|
||||
|
||||
/**
|
||||
* @brief Image flags
|
||||
|
Loading…
Reference in New Issue
Block a user