Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added palette callback function #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/GifDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,28 @@
#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);
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 <int maxGifWidth, int maxGifHeight, int lzwMaxBits, bool useMalloc=false> class GifDecoder {
public:
Expand All @@ -64,6 +68,8 @@ template <int maxGifWidth, int maxGifHeight, int lzwMaxBits, bool useMalloc=fals
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 setPaletteCallback(palette_callback);

void setFileSeekCallback(file_seek_callback f);
void setFilePositionCallback(file_position_callback f);
void setFileReadCallback(file_read_callback f);
Expand Down Expand Up @@ -98,6 +104,7 @@ template <int maxGifWidth, int maxGifHeight, int lzwMaxBits, bool useMalloc=fals
static file_read_callback fileReadCallback;
static file_read_block_callback fileReadBlockCallback;
static file_size_callback fileSizeCallback;
static palette_callback paletteCallback;

static void GIFDraw(GIFDRAW *pDraw);
static void * GIFOpenFile(const char *fname, int32_t *pSize);
Expand Down
11 changes: 11 additions & 0 deletions src/GifDecoder_Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ template <int maxGifWidth, int maxGifHeight, int lzwMaxBits, bool useMalloc>
file_read_block_callback GifDecoder<maxGifWidth, maxGifHeight, lzwMaxBits, useMalloc>::fileReadBlockCallback;
template <int maxGifWidth, int maxGifHeight, int lzwMaxBits, bool useMalloc>
file_size_callback GifDecoder<maxGifWidth, maxGifHeight, lzwMaxBits, useMalloc>::fileSizeCallback;
template <int maxGifWidth, int maxGifHeight, int lzwMaxBits, bool useMalloc>
palette_callback GifDecoder<maxGifWidth, maxGifHeight, lzwMaxBits, useMalloc>::paletteCallback;


template <int maxGifWidth, int maxGifHeight, int lzwMaxBits, bool useMalloc>
Expand Down Expand Up @@ -122,6 +124,12 @@ void GifDecoder<maxGifWidth, maxGifHeight, lzwMaxBits, useMalloc>::setFileReadBl
fileReadBlockCallback = f;
}

template <int maxGifWidth, int maxGifHeight, int lzwMaxBits, bool useMalloc>
void GifDecoder<maxGifWidth, maxGifHeight, lzwMaxBits, useMalloc>::setPaletteCallback(palette_callback f) {
paletteCallback = f;
}


template <int maxGifWidth, int maxGifHeight, int lzwMaxBits, bool useMalloc>
void GifDecoder<maxGifWidth, maxGifHeight, lzwMaxBits, useMalloc>::DrawPixelRow(int startX, int y, int numPixels, rgb_24 * data) {
for(int i=0; i<numPixels; i++)
Expand All @@ -147,6 +155,9 @@ void GifDecoder<maxGifWidth, maxGifHeight, lzwMaxBits, useMalloc>::GIFDraw(GIFDR
iWidth = DISPLAY_WIDTH;
usPalette = (rgb_24*)pDraw->pPalette;

if(paletteCallback)
paletteCallback(usPalette,pDraw->ucIsGlobalPalette==1);

y = pDraw->iY + pDraw->y; // current line

s = pDraw->pPixels;
Expand Down