aboutsummaryrefslogtreecommitdiffstats
path: root/src/gdisp
diff options
context:
space:
mode:
authorJoel Bodenmann <joel@embedded.pro>2016-11-10 23:00:31 +0100
committerJoel Bodenmann <joel@embedded.pro>2016-11-10 23:00:31 +0100
commit386e49480d449596b6f878c572241470a1cf9577 (patch)
tree7e029b66778875833bc2a9fd2ee5e947b6f73486 /src/gdisp
parent2cf23ca69b188a89105fe7e06b655020409cee12 (diff)
downloaduGFX-386e49480d449596b6f878c572241470a1cf9577.tar.gz
uGFX-386e49480d449596b6f878c572241470a1cf9577.tar.bz2
uGFX-386e49480d449596b6f878c572241470a1cf9577.zip
Adding ability to modify the color palette of BMP images (untested)
Diffstat (limited to 'src/gdisp')
-rw-r--r--src/gdisp/gdisp_image.c25
-rw-r--r--src/gdisp/gdisp_image.h4
-rw-r--r--src/gdisp/gdisp_image_bmp.c69
3 files changed, 91 insertions, 7 deletions
diff --git a/src/gdisp/gdisp_image.c b/src/gdisp/gdisp_image.c
index 356ba64f..13001d5c 100644
--- a/src/gdisp/gdisp_image.c
+++ b/src/gdisp/gdisp_image.c
@@ -33,6 +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);
#endif
#if GDISP_NEED_IMAGE_JPG
@@ -53,41 +56,49 @@
/* The structure defining the routines for image drawing */
typedef struct gdispImageHandlers {
- gdispImageError (*open)(gdispImage *img); /* The open function */
- void (*close)(gdispImage *img); /* The close function */
- gdispImageError (*cache)(gdispImage *img); /* The cache function */
+ gdispImageError (*open)(gdispImage *img); /* The open function */
+ void (*close)(gdispImage *img); /* The close function */
+ gdispImageError (*cache)(gdispImage *img); /* The cache function */
gdispImageError (*draw)(GDisplay *g,
gdispImage *img,
coord_t x, coord_t y,
coord_t cx, coord_t cy,
- coord_t sx, coord_t sy); /* The draw function */
- delaytime_t (*next)(gdispImage *img); /* The next frame function */
+ 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 */
} gdispImageHandlers;
static gdispImageHandlers ImageHandlers[] = {
#if GDISP_NEED_IMAGE_NATIVE
{ gdispImageOpen_NATIVE, gdispImageClose_NATIVE,
gdispImageCache_NATIVE, gdispGImageDraw_NATIVE, gdispImageNext_NATIVE,
+ 0, 0, 0
},
#endif
#if GDISP_NEED_IMAGE_GIF
{ gdispImageOpen_GIF, gdispImageClose_GIF,
gdispImageCache_GIF, gdispGImageDraw_GIF, gdispImageNext_GIF,
+ 0, 0, 0
},
#endif
#if GDISP_NEED_IMAGE_BMP
- { gdispImageOpen_BMP, gdispImageClose_BMP,
- gdispImageCache_BMP, gdispGImageDraw_BMP, gdispImageNext_BMP,
+ { gdispImageOpen_BMP, gdispImageClose_BMP,
+ gdispImageCache_BMP, gdispGImageDraw_BMP, gdispImageNext_BMP,
+ gdispImageGetPaletteSize_BMP, gdispImageGetPalette_BMP, gdispImageAdjustPalette_BMP
},
#endif
#if GDISP_NEED_IMAGE_JPG
{ gdispImageOpen_JPG, gdispImageClose_JPG,
gdispImageCache_JPG, gdispGImageDraw_JPG, gdispImageNext_JPG,
+ 0, 0, 0
},
#endif
#if GDISP_NEED_IMAGE_PNG
{ gdispImageOpen_PNG, gdispImageClose_PNG,
gdispImageCache_PNG, gdispGImageDraw_PNG, gdispImageNext_PNG,
+ 0, 0, 0
},
#endif
};
diff --git a/src/gdisp/gdisp_image.h b/src/gdisp/gdisp_image.h
index 2b6fdf19..a07a633d 100644
--- a/src/gdisp/gdisp_image.h
+++ b/src/gdisp/gdisp_image.h
@@ -248,6 +248,10 @@ extern "C" {
*/
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);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/gdisp/gdisp_image_bmp.c b/src/gdisp/gdisp_image_bmp.c
index 371fdf2d..f8ac07ab 100644
--- a/src/gdisp/gdisp_image_bmp.c
+++ b/src/gdisp/gdisp_image_bmp.c
@@ -829,4 +829,73 @@ delaytime_t gdispImageNext_BMP(gdispImage *img) {
return TIME_INFINITE;
}
+int 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) {
+ return 0;
+ }
+
+ if (!(priv->bmpflags & BMP_PALETTE)) {
+ return 0;
+ }
+
+ return priv->palsize;
+ #else
+ return 0;
+ #endif
+}
+
+color_t gdispImageGetPalette_BMP(gdispImage *img, int 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) {
+ return 0;
+ }
+
+ if (!(priv->bmpflags & BMP_PALETTE)) {
+ return 0;
+ }
+
+ if (index < 0 || index >= priv->palsize) {
+ return 0;
+ }
+
+ return priv->palette[index];
+
+ #else
+ return 0;
+ #endif
+}
+
+bool_t gdispImageAdjustPalette_BMP(gdispImage *img, int 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) {
+ return FALSE;
+ }
+
+ if (!(priv->bmpflags & BMP_PALETTE)) {
+ return FALSE;
+ }
+
+ if (index < 0 || index >= priv->palsize) {
+ return FALSE;
+ }
+
+ priv->palette[index] = newColor;
+
+ return TRUE;
+
+ #else
+ return 0;
+ #endif
+}
+
#endif /* GFX_USE_GDISP && GDISP_NEED_IMAGE && GDISP_NEED_IMAGE_BMP */