Minor changes & improvements on image color palletization handling

spinbox_widget
Joel Bodenmann 2016-11-11 18:28:48 +01:00
parent 386e49480d
commit ebfe1e95a2
3 changed files with 42 additions and 31 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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;