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