From 386e49480d449596b6f878c572241470a1cf9577 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Thu, 10 Nov 2016 23:00:31 +0100 Subject: [PATCH 1/5] Adding ability to modify the color palette of BMP images (untested) --- src/gdisp/gdisp_image.c | 25 ++++++++++---- src/gdisp/gdisp_image.h | 4 +++ src/gdisp/gdisp_image_bmp.c | 69 +++++++++++++++++++++++++++++++++++++ 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 */ From ebfe1e95a240cdd29d295522f002325c65df622b Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Fri, 11 Nov 2016 18:28:48 +0100 Subject: [PATCH 2/5] Minor changes & improvements on image color palletization handling --- src/gdisp/gdisp_image.c | 31 +++++++++++++++++++++++++------ src/gdisp/gdisp_image.h | 8 ++++---- src/gdisp/gdisp_image_bmp.c | 34 +++++++++++++--------------------- 3 files changed, 42 insertions(+), 31 deletions(-) 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; From 73a110eed634e757389c647ad988fe750e9be0ee Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Fri, 11 Nov 2016 18:35:09 +0100 Subject: [PATCH 3/5] Adding API documentation for new image color palette functions --- src/gdisp/gdisp_image.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/gdisp/gdisp_image.h b/src/gdisp/gdisp_image.h index 41ed7531..76773887 100644 --- a/src/gdisp/gdisp_image.h +++ b/src/gdisp/gdisp_image.h @@ -248,8 +248,40 @@ extern "C" { */ 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 From 1c5bfeef64f7eb84c5d04e3e11daaebeeef651e1 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Fri, 11 Nov 2016 19:07:55 +0100 Subject: [PATCH 4/5] Adding demo to demonstrate image color palette modification --- demos/modules/gdisp/images_palettes/demo.mk | 3 + .../gdisp/images_palettes/expected_result.png | Bin 0 -> 5421 bytes demos/modules/gdisp/images_palettes/gfxconf.h | 60 ++++++++++ .../gdisp/images_palettes/icon_home.bmp | Bin 0 -> 530 bytes demos/modules/gdisp/images_palettes/main.c | 104 ++++++++++++++++++ .../gdisp/images_palettes/romfs_files.h | 7 ++ .../gdisp/images_palettes/romfs_icon_home.h | 48 ++++++++ 7 files changed, 222 insertions(+) create mode 100644 demos/modules/gdisp/images_palettes/demo.mk create mode 100644 demos/modules/gdisp/images_palettes/expected_result.png create mode 100644 demos/modules/gdisp/images_palettes/gfxconf.h create mode 100644 demos/modules/gdisp/images_palettes/icon_home.bmp create mode 100644 demos/modules/gdisp/images_palettes/main.c create mode 100644 demos/modules/gdisp/images_palettes/romfs_files.h create mode 100644 demos/modules/gdisp/images_palettes/romfs_icon_home.h 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 0000000000000000000000000000000000000000..fb0ef0aae26c5a67405143b30ade8c84033faaca GIT binary patch literal 5421 zcmeI0X*iqdyTBjhPwY~v2Bo6P3}dNMOH0R6wUxHEwg@%$62#inUL8xw(N@cZE;G|s zscl+Y?PDE9RIOD@#a2X05k%s=p`(ZMzvi6t?R=OI@0;topXYhs>w50r{kxwx36^J# zc)3Km006wkXAI5*z#0Pp3k}W=MeNiV(a;a4- z1$er91cK-MZCX&2Zz~$$>dc&aDA3c#6{u19IiV3w=Ew!KTVRNDfGcqD+hk7X-g>wv z#^tIrG&KN}*1p6;VK_5v>m1FW+^#U_7(VjSD+g92P!!SZJ8>|fLL(LO$|zJXw+ z?QRVeV`omY@(jG{3bNB@u3akAPl44~1^42uor{%lzhjm(i zH>*A6aj2*R@SmAG1!K)V+VzZ-)_gh(eD56O)pF}&Hy8Zj5v{}iMI3|xeWW355YDM_ zR$T6`OZpwTb3%;-p%Bx9jYAcKLjzgpm2e5?N2IyAxr!nFk&ZSS6zz@D3;>6+CgS6% zj$tKaO#sq=eTt&FDioiD0YDajGG)y91Bm+V#vyR({A<+vPfDBXq)B6FYCWO9A88`a3)8!UmMx85VIkOyyD1d#Qf+gMx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>R$`ZvicsH8>cRR6@8IrOZ^2G-ZRt}5!HvraFLkGGp$O>~O% z$s;2`)W5ziw$hZcqXtVjP`%JoEWontsGc7h1Z%Qyw7NsOJ$XY#B@m?(}=V(T_ z;Yi1uaU;1^@fiIQ{5#z%OHixg^$yvqFe~hCg*^=3r7$5k#x8|%9Ua-Fu()*8E`_nS z$?hmDx=m+GVX1CnTMDy#v8}L|1KSF7{Jfoq2f{Z;1lQNgwqcGgZ zJqkNZII%}zQ)a?@6eifjzei!cp?ef&m@%}auw(y4Vb7~_hd+@YXK8DAbui{PiOHeW zFF#XGx0kCErJy2k-AVYKW+zI?`EYT%HLZo?BXk3x;(sfzjQ=h#_TBQLGu|=f#dvp# z*#p1GYj;=v%IM#k@}Fs2N5DOO=YKv<{ + * 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 0000000000000000000000000000000000000000..9a9cff6dbb54839f93f59ed0123e137884f68694 GIT binary patch literal 530 zcmbu5u?oUK42DxH7F`O8Yu%)y*jWlLE;{J!+!t^aS_kKXTi?X7_!6$&U0ehQ>G>zQ zK~O|6H22-5$$!T`U342HalpDoj%+&QNIe7QHn~;X4UvA_W2Up!CO_T6Ar zQ7=i7A+l8zMSIdYyWu(?i=bVauLrv~#t@S6#s_&7#YF!Tmx<1AMAz5I_%Hk^nJ!Vq z^oXuZpXkmU@VgPXw`QhdpL&>K++bT;R+bQuIs}9e5JEtRnH|rW%u$xEvhtKyUwI!W PAF=vcr=R>~*SY=#kr + * 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 From 477aa8e87872ae79e568e1a1d5468c614fc1c457 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Fri, 11 Nov 2016 19:08:51 +0100 Subject: [PATCH 5/5] Updating changelog --- docs/releases.txt | 1 + 1 file changed, 1 insertion(+) 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 ***