diff --git a/src/gdisp/gdisp_image.c b/src/gdisp/gdisp_image.c index 13001d5c..347ed6aa 100644 --- a/src/gdisp/gdisp_image.c +++ b/src/gdisp/gdisp_image.c @@ -33,9 +33,9 @@ extern gdispImageError gdispImageCache_BMP(gdispImage *img); extern gdispImageError gdispGImageDraw_BMP(GDisplay *g, gdispImage *img, coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t sx, coord_t sy); extern delaytime_t gdispImageNext_BMP(gdispImage *img); - extern int gdispImageGetPaletteSize_BMP(gdispImage *img); - extern color_t gdispImageGetPalette_BMP(gdispImage *img, int index); - extern bool_t gdispImageAdjustPalette_BMP(gdispImage *img, int index, color_t newColor); + extern uint16_t gdispImageGetPaletteSize_BMP(gdispImage *img); + extern color_t gdispImageGetPalette_BMP(gdispImage *img, uint16_t index); + extern bool_t gdispImageAdjustPalette_BMP(gdispImage *img, uint16_t index, color_t newColor); #endif #if GDISP_NEED_IMAGE_JPG @@ -65,9 +65,9 @@ typedef struct gdispImageHandlers { coord_t cx, coord_t cy, coord_t sx, coord_t sy); /* The draw function */ delaytime_t (*next)(gdispImage *img); /* The next frame function */ - int (*getPaletteSize)(gdispImage *img); /* Retrieve the size of the palette (number of entries) */ - color_t (*getPalette)(gdispImage *img, int index); /* Retrieve a specific color value of the palette */ - bool_t (*adjustPalette)(gdispImage *img, int index, color_t newColor); /* Replace a color value in the palette */ + uint16_t (*getPaletteSize)(gdispImage *img); /* Retrieve the size of the palette (number of entries) */ + color_t (*getPalette)(gdispImage *img, uint16_t index); /* Retrieve a specific color value of the palette */ + bool_t (*adjustPalette)(gdispImage *img, uint16_t index, color_t newColor); /* Replace a color value in the palette */ } gdispImageHandlers; static gdispImageHandlers ImageHandlers[] = { @@ -183,6 +183,25 @@ delaytime_t gdispImageNext(gdispImage *img) { return img->fns->next(img); } +uint16_t gdispImageGetPaletteSize(gdispImage *img) { + if (!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->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->fns->adjustPalette) return FALSE; + return img->fns->adjustPalette(img, index, newColor); +} + + // Helper Routines void *gdispImageAlloc(gdispImage *img, size_t sz) { #if GDISP_NEED_IMAGE_ACCOUNTING diff --git a/src/gdisp/gdisp_image.h b/src/gdisp/gdisp_image.h index a07a633d..41ed7531 100644 --- a/src/gdisp/gdisp_image.h +++ b/src/gdisp/gdisp_image.h @@ -247,10 +247,10 @@ extern "C" { * frame/page. */ delaytime_t gdispImageNext(gdispImage *img); - - int gdispImageGetPaletteSize(gdispImage *img); - color_t gdispImageGetPalette(gdispImage *img, int index); - bool_t gdispImageAdjustPalette(gdispImage *img, int index, color_t newColor); + + uint16_t gdispImageGetPaletteSize(gdispImage *img); + color_t gdispImageGetPalette(gdispImage *img, uint16_t index); + bool_t gdispImageAdjustPalette(gdispImage *img, uint16_t index, color_t newColor); #ifdef __cplusplus } diff --git a/src/gdisp/gdisp_image_bmp.c b/src/gdisp/gdisp_image_bmp.c index f8ac07ab..2ea4e95f 100644 --- a/src/gdisp/gdisp_image_bmp.c +++ b/src/gdisp/gdisp_image_bmp.c @@ -829,18 +829,16 @@ delaytime_t gdispImageNext_BMP(gdispImage *img) { return TIME_INFINITE; } -int gdispImageGetPaletteSize_BMP(gdispImage *img) { +uint16_t gdispImageGetPaletteSize_BMP(gdispImage *img) { #if GDISP_NEED_IMAGE_BMP_1 || GDISP_NEED_IMAGE_BMP_4 || GDISP_NEED_IMAGE_BMP_8 gdispImagePrivate_BMP *priv; priv = (gdispImagePrivate_BMP *)img->priv; - if (!priv) { + if (!priv) return 0; - } - if (!(priv->bmpflags & BMP_PALETTE)) { + if (!(priv->bmpflags & BMP_PALETTE)) return 0; - } return priv->palsize; #else @@ -848,48 +846,42 @@ int gdispImageGetPaletteSize_BMP(gdispImage *img) { #endif } -color_t gdispImageGetPalette_BMP(gdispImage *img, int index) { +color_t gdispImageGetPalette_BMP(gdispImage *img, uint16_t index) { #if GDISP_NEED_IMAGE_BMP_1 || GDISP_NEED_IMAGE_BMP_4 || GDISP_NEED_IMAGE_BMP_8 gdispImagePrivate_BMP *priv; priv = (gdispImagePrivate_BMP *)img->priv; - if (!priv) { + if (!priv) return 0; - } - if (!(priv->bmpflags & BMP_PALETTE)) { + if (!(priv->bmpflags & BMP_PALETTE)) return 0; - } - if (index < 0 || index >= priv->palsize) { + if (index >= priv->palsize) return 0; - } - return priv->palette[index]; + return priv->palette[(uint8_t)index]; #else return 0; #endif } -bool_t gdispImageAdjustPalette_BMP(gdispImage *img, int index, color_t newColor) { +bool_t gdispImageAdjustPalette_BMP(gdispImage *img, uint16_t index, color_t newColor) { #if GDISP_NEED_IMAGE_BMP_1 || GDISP_NEED_IMAGE_BMP_4 || GDISP_NEED_IMAGE_BMP_8 gdispImagePrivate_BMP *priv; priv = (gdispImagePrivate_BMP *)img->priv; - if (!priv) { + if (!priv) return FALSE; - } - if (!(priv->bmpflags & BMP_PALETTE)) { + if (!(priv->bmpflags & BMP_PALETTE)) return FALSE; - } - if (index < 0 || index >= priv->palsize) { + if (index >= priv->palsize) return FALSE; - } - priv->palette[index] = newColor; + priv->palette[(uint8_t)index] = newColor; return TRUE;