diff --git a/demos/modules/gdisp/images_palettes/demo.mk b/demos/modules/gdisp/images_palettes/demo.mk new file mode 100644 index 00000000..6dab7aa7 --- /dev/null +++ b/demos/modules/gdisp/images_palettes/demo.mk @@ -0,0 +1,3 @@ +DEMODIR = $(GFXLIB)/demos/modules/gdisp/images_palettes +GFXINC += $(DEMODIR) +GFXSRC += $(DEMODIR)/main.c diff --git a/demos/modules/gdisp/images_palettes/expected_result.png b/demos/modules/gdisp/images_palettes/expected_result.png new file mode 100644 index 00000000..fb0ef0aa Binary files /dev/null and b/demos/modules/gdisp/images_palettes/expected_result.png differ diff --git a/demos/modules/gdisp/images_palettes/gfxconf.h b/demos/modules/gdisp/images_palettes/gfxconf.h new file mode 100644 index 00000000..a98776f5 --- /dev/null +++ b/demos/modules/gdisp/images_palettes/gfxconf.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2012, 2013, Joel Bodenmann aka Tectu + * Copyright (c) 2012, 2013, Andrew Hannam aka inmarket + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _GFXCONF_H +#define _GFXCONF_H + +/* The operating system to use. One of these must be defined - preferably in your Makefile */ +//#define GFX_USE_OS_CHIBIOS FALSE +//#define GFX_USE_OS_WIN32 FALSE +//#define GFX_USE_OS_LINUX FALSE +//#define GFX_USE_OS_OSX FALSE + +/* GFX sub-systems to turn on */ +#define GFX_USE_GDISP TRUE + +/* Features for the GDISP sub-system. */ +#define GDISP_NEED_VALIDATION TRUE +#define GDISP_NEED_CLIP TRUE +#define GDISP_NEED_IMAGE TRUE +#define GDISP_STARTUP_COLOR HTML2COLOR(0xC0C0C0) + +/* GDISP image decoders */ +//#define GDISP_NEED_IMAGE_NATIVE TRUE +//#define GDISP_NEED_IMAGE_GIF TRUE +#define GDISP_NEED_IMAGE_BMP TRUE +//#define GDISP_NEED_IMAGE_JPG TRUE +//#define GDISP_NEED_IMAGE_PNG TRUE + +#define GFX_USE_GFILE TRUE +#define GFILE_NEED_ROMFS TRUE +//#define GFILE_NEED_NATIVEFS TRUE + +#endif /* _GFXCONF_H */ + diff --git a/demos/modules/gdisp/images_palettes/icon_home.bmp b/demos/modules/gdisp/images_palettes/icon_home.bmp new file mode 100644 index 00000000..9a9cff6d Binary files /dev/null and b/demos/modules/gdisp/images_palettes/icon_home.bmp differ diff --git a/demos/modules/gdisp/images_palettes/main.c b/demos/modules/gdisp/images_palettes/main.c new file mode 100644 index 00000000..7d63088b --- /dev/null +++ b/demos/modules/gdisp/images_palettes/main.c @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2016, Joel Bodenmann aka Tectu + * Copyright (c) 2016, Andrew Hannam aka inmarket + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * This example demonstrates how the color palette of an image can be modified + * during run-time of the program to exchange colors. + * This example uses a BMP1 image (one-bit BMP) and which only has a palette + * size of two. + * Note that although the demo shows multiple images with different colors at + * the same time there's still just one copy of the image in memory at all times. + */ + +#define USE_PRINTF TRUE + +#include "gfx.h" + +static gdispImage _imgHome; + +int main(void) +{ + int paletteSize = 0; + + // Initialize everything + gfxInit(); + gdispClear(Silver); + + // Open the image file + gdispImageOpenFile(&_imgHome, "icon_home.bmp"); + + // Retrieve the color palette size and dump it - just for fun. + paletteSize = gdispImageGetPaletteSize(&_imgHome); + if (paletteSize != 2) { // With this image we expect the palette to have only two entries! + gdispClear(Red); + while (1); + } + + // Draw the image w/o modifying the palette + gdispImageDraw(&_imgHome, 10, 10, gdispGetWidth(), gdispGetHeight(), 0, 0); + + // Modify the palette & redraw at a different location + gdispImageAdjustPalette(&_imgHome, 0, Blue); + gdispImageAdjustPalette(&_imgHome, 1, Red); + gdispImageDraw(&_imgHome, 10, 60, gdispGetWidth(), gdispGetHeight(), 0, 0); + + // Modify the palette & redraw at a different location + gdispImageAdjustPalette(&_imgHome, 0, White); + gdispImageAdjustPalette(&_imgHome, 1, Black); + gdispImageDraw(&_imgHome, 10, 110, gdispGetWidth(), gdispGetHeight(), 0, 0); + + // Modify the palette & redraw at a different location + gdispImageAdjustPalette(&_imgHome, 0, Lime); + gdispImageAdjustPalette(&_imgHome, 1, Navy); + gdispImageDraw(&_imgHome, 10, 160, gdispGetWidth(), gdispGetHeight(), 0, 0); + + // Modify the palette & redraw at a different location + gdispImageAdjustPalette(&_imgHome, 0, Gray); + gdispImageAdjustPalette(&_imgHome, 1, Yellow); + gdispImageDraw(&_imgHome, 60, 60, gdispGetWidth(), gdispGetHeight(), 0, 0); + + // Modify the palette & redraw at a different location + gdispImageAdjustPalette(&_imgHome, 0, Green); + gdispImageAdjustPalette(&_imgHome, 1, Black); + gdispImageDraw(&_imgHome, 60, 110, gdispGetWidth(), gdispGetHeight(), 0, 0); + + // Modify the palette & redraw at a different location + gdispImageAdjustPalette(&_imgHome, 0, Lime); + gdispImageAdjustPalette(&_imgHome, 1, Teal); + gdispImageDraw(&_imgHome, 60, 160, gdispGetWidth(), gdispGetHeight(), 0, 0); + + // We're done. Clean up. + gdispImageClose(&_imgHome); + + while(1) { + gfxSleepMilliseconds(500); + } + + return 0; +} diff --git a/demos/modules/gdisp/images_palettes/romfs_files.h b/demos/modules/gdisp/images_palettes/romfs_files.h new file mode 100644 index 00000000..356f6d39 --- /dev/null +++ b/demos/modules/gdisp/images_palettes/romfs_files.h @@ -0,0 +1,7 @@ +/** + * This file contains the list of files for the ROMFS. + * + * The files have been converted using... + * file2c -dbcs infile outfile + */ +#include "romfs_icon_home.h" diff --git a/demos/modules/gdisp/images_palettes/romfs_icon_home.h b/demos/modules/gdisp/images_palettes/romfs_icon_home.h new file mode 100644 index 00000000..0ec6b8f6 --- /dev/null +++ b/demos/modules/gdisp/images_palettes/romfs_icon_home.h @@ -0,0 +1,48 @@ +/** + * This file was generated from "icon_home.bmp" using... + * + * file2c -dcs icon_home.bmp romfs_icon_home.bmp + * + */ +static const char icon_home[] = { + 0x42, 0x4D, 0x12, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x92, 0x00, 0x00, 0x00, 0x7C, 0x00, + 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x4C, 0x01, 0x00, 0x00, 0x4C, 0x01, 0x00, 0x00, 0x02, 0x00, + 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x42, 0x47, 0x52, 0x73, 0x8F, 0xC2, 0xF5, 0x28, 0x51, 0xB8, + 0x1E, 0x15, 0x1E, 0x85, 0xEB, 0x01, 0x33, 0x33, 0x33, 0x13, 0x66, 0x66, 0x66, 0x26, 0x66, 0x66, + 0x66, 0x06, 0x99, 0x99, 0x99, 0x09, 0x3D, 0x0A, 0xD7, 0x03, 0x28, 0x5C, 0x8F, 0x32, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, + 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFC, 0x00, 0x07, 0xE0, 0x00, 0x3F, + 0x00, 0x00, 0xFC, 0x00, 0x07, 0xE0, 0x00, 0x3F, 0x00, 0x00, 0xFC, 0x00, 0x07, 0xE0, 0x00, 0x3F, + 0x00, 0x00, 0xFC, 0x00, 0x07, 0xE0, 0x00, 0x3F, 0x00, 0x00, 0xFC, 0x00, 0x07, 0xE0, 0x00, 0x3F, + 0x00, 0x00, 0xFC, 0x00, 0x07, 0xE0, 0x00, 0x3F, 0x00, 0x00, 0xFC, 0x00, 0x07, 0xE0, 0x00, 0x3F, + 0x00, 0x00, 0xFC, 0x00, 0x07, 0xE0, 0x00, 0x3F, 0x00, 0x00, 0xFC, 0x00, 0x07, 0xE0, 0x00, 0x3F, + 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x3F, + 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x3F, + 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x3F, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x03, + 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x0F, + 0x00, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x3F, + 0x00, 0x00, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, + 0x00, 0x00, 0xFF, 0x80, 0x00, 0x00, 0x01, 0xFF, 0x00, 0x00, 0xFF, 0xC0, 0x00, 0x00, 0x01, 0xFF, + 0x00, 0x00, 0xFF, 0xE0, 0x00, 0x00, 0x01, 0xFF, 0x00, 0x00, 0xFF, 0xF0, 0x00, 0x00, 0x01, 0xFF, + 0x00, 0x00, 0xFF, 0xF8, 0x00, 0x00, 0x01, 0xFF, 0x00, 0x00, 0xFF, 0xFC, 0x00, 0x00, 0x01, 0xFF, + 0x00, 0x00, 0xFF, 0xFE, 0x00, 0x00, 0x01, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x81, 0xFF, + 0x00, 0x00, 0xFF, 0xFF, 0x80, 0x01, 0x81, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xC0, 0x03, 0x81, 0xFF, + 0x00, 0x00, 0xFF, 0xFF, 0xE0, 0x07, 0x81, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xF0, 0x0F, 0x81, 0xFF, + 0x00, 0x00, 0xFF, 0xFF, 0xF8, 0x1F, 0x81, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFC, 0x3F, 0xFF, 0xFF, + 0x00, 0x00, 0xFF, 0xFF, 0xFE, 0x7F, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0x00, +}; + +#ifdef ROMFS_DIRENTRY_HEAD + static const ROMFS_DIRENTRY icon_home_dir = { 0, 0, ROMFS_DIRENTRY_HEAD, "icon_home.bmp", 530, icon_home }; + #undef ROMFS_DIRENTRY_HEAD + #define ROMFS_DIRENTRY_HEAD &icon_home_dir +#endif diff --git a/docs/releases.txt b/docs/releases.txt index 0fb164b7..a0ee7246 100644 --- a/docs/releases.txt +++ b/docs/releases.txt @@ -19,6 +19,7 @@ FIX: Updating Windows binaries of the font encoder to improve compatibility FIX: Fixed progressbar bounds checking and decrementing FEATURE: Added a dual circle with the same center drawing routine to GDISP FIX: Fixed an issue in the filled polygon drawing function which caused irregularities +FEATURE: Added high-level functions to modify image color palettes *** Release 2.6 *** diff --git a/src/gdisp/gdisp_image.c b/src/gdisp/gdisp_image.c index 356ba64f..347ed6aa 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 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 @@ -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 */ + 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[] = { #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 }; @@ -172,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 2b6fdf19..76773887 100644 --- a/src/gdisp/gdisp_image.h +++ b/src/gdisp/gdisp_image.h @@ -247,6 +247,42 @@ extern "C" { * frame/page. */ delaytime_t gdispImageNext(gdispImage *img); + + /** + * @brief Get the number of entries in the color palette. + * @return The number of entries in the color palette or 0 if the image doesn't use a color palette. + * + * @param[in] img The image structure + * + * @pre gdispImageOpen() must have returned successfully. + */ + uint16_t gdispImageGetPaletteSize(gdispImage *img); + + /** + * @brief Get an entry in the color palette. + * @return The color value at a given position in the color palette. + * + * @param[in] img The image structure + * @param[in] index The index of the color palette entry + * + * @pre gdispImageOpen() must have returned successfully. + * + * @note This function will return 0 if the index is out of bounds or if the image doesn't use a color palette. + */ + color_t gdispImageGetPalette(gdispImage *img, uint16_t index); + + /** + * @brief Modify an entry in the color palette. + * @return @p TRUE on success, @p FALSE otherwise. + * + * @param[in] img The image structure + * @param[in] index The index of the color palette entry + * @param[in] newColor The new color value of the specified entry + * + * @pre gdispImageOpen() must have returned successfully. + * @note This function will return @p FALSE if the index is out of bounds or if the image doesn't use a color palette. + */ + 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 371fdf2d..2ea4e95f 100644 --- a/src/gdisp/gdisp_image_bmp.c +++ b/src/gdisp/gdisp_image_bmp.c @@ -829,4 +829,65 @@ delaytime_t gdispImageNext_BMP(gdispImage *img) { return TIME_INFINITE; } +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) + return 0; + + if (!(priv->bmpflags & BMP_PALETTE)) + return 0; + + return priv->palsize; + #else + return 0; + #endif +} + +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) + return 0; + + if (!(priv->bmpflags & BMP_PALETTE)) + return 0; + + if (index >= priv->palsize) + return 0; + + return priv->palette[(uint8_t)index]; + + #else + return 0; + #endif +} + +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) + return FALSE; + + if (!(priv->bmpflags & BMP_PALETTE)) + return FALSE; + + if (index >= priv->palsize) + return FALSE; + + priv->palette[(uint8_t)index] = newColor; + + return TRUE; + + #else + return 0; + #endif +} + #endif /* GFX_USE_GDISP && GDISP_NEED_IMAGE && GDISP_NEED_IMAGE_BMP */