From 6ff19516db08dc78619f4f9ea57b40aefe202819 Mon Sep 17 00:00:00 2001 From: alwyn Date: Wed, 10 Aug 2022 19:38:06 +0100 Subject: [PATCH 1/3] Added palette callback function --- src/GifDecoder.h | 17 ++++++++++++----- src/GifDecoder_Impl.h | 11 +++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/GifDecoder.h b/src/GifDecoder.h index ca84528..321180a 100644 --- a/src/GifDecoder.h +++ b/src/GifDecoder.h @@ -23,6 +23,13 @@ #define ERROR_GIF_DECODE_ERROR -10 #define ERROR_MISSING_CALLBACK_FUNCTION -11 + +typedef struct rgb_24 { + uint8_t red; + uint8_t green; + uint8_t blue; +} rgb_24; + typedef void (*callback)(void); typedef void (*pixel_callback)(int16_t x, int16_t y, uint8_t red, uint8_t green, uint8_t blue); @@ -30,17 +37,14 @@ typedef void (*line_callback)(int16_t x, int16_t y, uint8_t *buf, int16_t wid, uint16_t *palette565, int16_t skip); typedef void *(*get_buffer_callback)(void); +typedef void (*palette_callback)(rgb_24 *palette888, bool isGlobalPalette); + typedef bool (*file_seek_callback)(unsigned long position); typedef unsigned long (*file_position_callback)(void); typedef int (*file_read_callback)(void); typedef int (*file_read_block_callback)(void *buffer, int numberOfBytes); typedef int (*file_size_callback)(void); -typedef struct rgb_24 { - uint8_t red; - uint8_t green; - uint8_t blue; -} rgb_24; template class GifDecoder { public: @@ -64,6 +68,8 @@ template file_read_block_callback GifDecoder::fileReadBlockCallback; template file_size_callback GifDecoder::fileSizeCallback; +template +palette_callback GifDecoder::paletteCallback; template @@ -122,6 +124,12 @@ void GifDecoder::setFileReadBl fileReadBlockCallback = f; } +template +void GifDecoder::setPaletteCallback(palette_callback f) { + paletteCallback = f; +} + + template void GifDecoder::DrawPixelRow(int startX, int y, int numPixels, rgb_24 * data) { for(int i=0; i::GIFDraw(GIFDR iWidth = DISPLAY_WIDTH; usPalette = (rgb_24*)pDraw->pPalette; + if(paletteCallback) + paletteCallback(usPalette,pDraw->bIsGlobalPalette); + y = pDraw->iY + pDraw->y; // current line s = pDraw->pPixels; From d8b50b7e185a7e99f5ed5272bfa17bef8a16e8b4 Mon Sep 17 00:00:00 2001 From: alwyn Date: Thu, 11 Aug 2022 19:03:28 +0100 Subject: [PATCH 2/3] Global Palette flag changed to uint8_t type --- src/GifDecoder_Impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GifDecoder_Impl.h b/src/GifDecoder_Impl.h index 5fca516..c818026 100644 --- a/src/GifDecoder_Impl.h +++ b/src/GifDecoder_Impl.h @@ -156,7 +156,7 @@ void GifDecoder::GIFDraw(GIFDR usPalette = (rgb_24*)pDraw->pPalette; if(paletteCallback) - paletteCallback(usPalette,pDraw->bIsGlobalPalette); + paletteCallback(usPalette,pDraw->ucIsGlobalPalette==1); y = pDraw->iY + pDraw->y; // current line From a67a33e91accd8d2d2f07f2a5d6cfe41b6ee38dd Mon Sep 17 00:00:00 2001 From: welshcoder Date: Wed, 14 May 2025 21:17:42 +0100 Subject: [PATCH 3/3] Small correction for c++17 --- src/GifDecoder.h | 17 +++++++++-------- src/GifDecoder_Impl.h | 20 ++++++++++++-------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/GifDecoder.h b/src/GifDecoder.h index 321180a..324b64c 100644 --- a/src/GifDecoder.h +++ b/src/GifDecoder.h @@ -30,7 +30,7 @@ typedef struct rgb_24 { uint8_t blue; } rgb_24; -typedef void (*callback)(void); +typedef void (*gd_callback)(void); typedef void (*pixel_callback)(int16_t x, int16_t y, uint8_t red, uint8_t green, uint8_t blue); typedef void (*line_callback)(int16_t x, int16_t y, uint8_t *buf, int16_t wid, @@ -46,7 +46,8 @@ typedef int (*file_read_block_callback)(void *buffer, int numberOfBytes); typedef int (*file_size_callback)(void); -template class GifDecoder { +template +class GifDecoder { public: GifDecoder(void); int startDecoding(void); @@ -62,11 +63,11 @@ template getCanvasHeight(); } - void setScreenClearCallback(callback f); - void setUpdateScreenCallback(callback f); + void setScreenClearCallback(gd_callback f); + void setUpdateScreenCallback(gd_callback f); void setDrawPixelCallback(pixel_callback f); void setDrawLineCallback(line_callback f); // note this callback is not currently used, but may be used in the future - void setStartDrawingCallback(callback f); // note this callback is not currently used + void setStartDrawingCallback(gd_callback f); // note this callback is not currently used void setPaletteCallback(palette_callback); @@ -94,11 +95,11 @@ template - +#undef abs #include "GifDecoder.h" + template -callback GifDecoder::screenClearCallback; +gd_callback GifDecoder::screenClearCallback; template -callback GifDecoder::updateScreenCallback; +gd_callback GifDecoder::updateScreenCallback; template pixel_callback GifDecoder::drawPixelCallback; template line_callback GifDecoder::drawLineCallback; template -callback GifDecoder::startDrawingCallback; +gd_callback GifDecoder::startDrawingCallback; template file_seek_callback GifDecoder::fileSeekCallback; template @@ -67,13 +68,13 @@ GifDecoder::GifDecoder(void) { template void GifDecoder::setStartDrawingCallback( - callback f) { + gd_callback f) { startDrawingCallback = f; } template void GifDecoder::setUpdateScreenCallback( - callback f) { + gd_callback f) { updateScreenCallback = f; } @@ -91,7 +92,7 @@ void GifDecoder::setDrawLineCa template void GifDecoder::setScreenClearCallback( - callback f) { + gd_callback f) { screenClearCallback = f; } @@ -223,8 +224,11 @@ void GifDecoder::GIFDraw(GIFDR s = pDraw->pPixels; // Translate the 8-bit pixels through the RGB565 palette (already byte reversed) for (x=0; xiX+x_offset, y+y_offset, iWidth, (rgb_24 *)usTemp); + } + + DrawPixelRow(pDraw->iX+x_offset, y+y_offset, iWidth, (rgb_24 *)usTemp); } }