Prevent naming conflicts when compiling multiple image formats with GFXSINGLEMAKE

ugfx_release_2.6
inmarket 2015-11-24 09:19:58 +10:00
parent 0ec1a5e4da
commit 870901880b
3 changed files with 172 additions and 172 deletions

View File

@ -16,9 +16,9 @@
* Bigger is faster but uses more RAM. * Bigger is faster but uses more RAM.
* This must be greater than 40 bytes and 32 pixels as we read our headers into this space as well * This must be greater than 40 bytes and 32 pixels as we read our headers into this space as well
*/ */
#define BLIT_BUFFER_SIZE 32 #define BLIT_BUFFER_SIZE_BMP 32
typedef struct gdispImagePrivate { typedef struct gdispImagePrivate_BMP {
uint8_t bmpflags; uint8_t bmpflags;
#define BMP_V2 0x01 // Version 2 (old) header format #define BMP_V2 0x01 // Version 2 (old) header format
#define BMP_V4 0x02 // Version 4 (alpha support) header format #define BMP_V4 0x02 // Version 4 (alpha support) header format
@ -49,8 +49,8 @@ typedef struct gdispImagePrivate {
#endif #endif
size_t frame0pos; size_t frame0pos;
pixel_t *frame0cache; pixel_t *frame0cache;
pixel_t buf[BLIT_BUFFER_SIZE]; pixel_t buf[BLIT_BUFFER_SIZE_BMP];
} gdispImagePrivate; } gdispImagePrivate_BMP;
void gdispImageClose_BMP(gdispImage *img) { void gdispImageClose_BMP(gdispImage *img) {
if (img->priv) { if (img->priv) {
@ -60,13 +60,13 @@ void gdispImageClose_BMP(gdispImage *img) {
#endif #endif
if (img->priv->frame0cache) if (img->priv->frame0cache)
gdispImageFree(img, (void *)img->priv->frame0cache, img->width*img->height*sizeof(pixel_t)); gdispImageFree(img, (void *)img->priv->frame0cache, img->width*img->height*sizeof(pixel_t));
gdispImageFree(img, (void *)img->priv, sizeof(gdispImagePrivate)); gdispImageFree(img, (void *)img->priv, sizeof(gdispImagePrivate_BMP));
img->priv = 0; img->priv = 0;
} }
} }
gdispImageError gdispImageOpen_BMP(gdispImage *img) { gdispImageError gdispImageOpen_BMP(gdispImage *img) {
gdispImagePrivate *priv; gdispImagePrivate_BMP *priv;
uint8_t hdr[2]; uint8_t hdr[2];
uint16_t aword; uint16_t aword;
uint32_t adword; uint32_t adword;
@ -89,7 +89,7 @@ gdispImageError gdispImageOpen_BMP(gdispImage *img) {
img->flags = 0; img->flags = 0;
/* Allocate our private area */ /* Allocate our private area */
if (!(img->priv = (gdispImagePrivate *)gdispImageAlloc(img, sizeof(gdispImagePrivate)))) if (!(img->priv = (gdispImagePrivate_BMP *)gdispImageAlloc(img, sizeof(gdispImagePrivate_BMP))))
return GDISP_IMAGE_ERR_NOMEMORY; return GDISP_IMAGE_ERR_NOMEMORY;
/* Initialise the essential bits in the private area */ /* Initialise the essential bits in the private area */
@ -357,7 +357,7 @@ unsupportedcleanup:
} }
static coord_t getPixels(gdispImage *img, coord_t x) { static coord_t getPixels(gdispImage *img, coord_t x) {
gdispImagePrivate * priv; gdispImagePrivate_BMP * priv;
color_t * pc; color_t * pc;
coord_t len; coord_t len;
@ -376,7 +376,7 @@ static coord_t getPixels(gdispImage *img, coord_t x) {
pc = priv->buf; pc = priv->buf;
len = 0; len = 0;
while(x < img->width && len <= BLIT_BUFFER_SIZE-32) { while(x < img->width && len <= BLIT_BUFFER_SIZE_BMP-32) {
if (gfileRead(img->f, &b, 4) != 4) if (gfileRead(img->f, &b, 4) != 4)
return 0; return 0;
@ -406,7 +406,7 @@ static coord_t getPixels(gdispImage *img, coord_t x) {
while(x < img->width) { while(x < img->width) {
if (priv->bmpflags & BMP_RLE_ENC) { if (priv->bmpflags & BMP_RLE_ENC) {
while (priv->rlerun && len <= BLIT_BUFFER_SIZE-2 && x < img->width) { while (priv->rlerun && len <= BLIT_BUFFER_SIZE_BMP-2 && x < img->width) {
*pc++ = priv->palette[priv->rlecode >> 4]; *pc++ = priv->palette[priv->rlecode >> 4];
priv->rlerun--; priv->rlerun--;
len++; len++;
@ -421,7 +421,7 @@ static coord_t getPixels(gdispImage *img, coord_t x) {
if (priv->rlerun) // Return if we have more run to do if (priv->rlerun) // Return if we have more run to do
return len; return len;
} else if (priv->bmpflags & BMP_RLE_ABS) { } else if (priv->bmpflags & BMP_RLE_ABS) {
while (priv->rlerun && len <= BLIT_BUFFER_SIZE-2 && x < img->width) { while (priv->rlerun && len <= BLIT_BUFFER_SIZE_BMP-2 && x < img->width) {
if (gfileRead(img->f, &b, 1) != 1) if (gfileRead(img->f, &b, 1) != 1)
return 0; return 0;
*pc++ = priv->palette[b[0] >> 4]; *pc++ = priv->palette[b[0] >> 4];
@ -481,7 +481,7 @@ static coord_t getPixels(gdispImage *img, coord_t x) {
{ {
uint8_t b[4]; uint8_t b[4];
while(x < img->width && len <= BLIT_BUFFER_SIZE-8) { while(x < img->width && len <= BLIT_BUFFER_SIZE_BMP-8) {
if (gfileRead(img->f, &b, 4) != 4) if (gfileRead(img->f, &b, 4) != 4)
return 0; return 0;
@ -512,7 +512,7 @@ static coord_t getPixels(gdispImage *img, coord_t x) {
while(x < img->width) { while(x < img->width) {
if (priv->bmpflags & BMP_RLE_ENC) { if (priv->bmpflags & BMP_RLE_ENC) {
while (priv->rlerun && len < BLIT_BUFFER_SIZE && x < img->width) { while (priv->rlerun && len < BLIT_BUFFER_SIZE_BMP && x < img->width) {
*pc++ = priv->palette[priv->rlecode]; *pc++ = priv->palette[priv->rlecode];
priv->rlerun--; priv->rlerun--;
len++; len++;
@ -521,7 +521,7 @@ static coord_t getPixels(gdispImage *img, coord_t x) {
if (priv->rlerun) // Return if we have more run to do if (priv->rlerun) // Return if we have more run to do
return len; return len;
} else if (priv->bmpflags & BMP_RLE_ABS) { } else if (priv->bmpflags & BMP_RLE_ABS) {
while (priv->rlerun && len < BLIT_BUFFER_SIZE && x < img->width) { while (priv->rlerun && len < BLIT_BUFFER_SIZE_BMP && x < img->width) {
if (gfileRead(img->f, &b, 1) != 1) if (gfileRead(img->f, &b, 1) != 1)
return 0; return 0;
*pc++ = priv->palette[b[0]]; *pc++ = priv->palette[b[0]];
@ -575,7 +575,7 @@ static coord_t getPixels(gdispImage *img, coord_t x) {
{ {
uint8_t b[4]; uint8_t b[4];
while(x < img->width && len <= BLIT_BUFFER_SIZE-4) { while(x < img->width && len <= BLIT_BUFFER_SIZE_BMP-4) {
if (gfileRead(img->f, &b, 4) != 4) if (gfileRead(img->f, &b, 4) != 4)
return 0; return 0;
@ -597,7 +597,7 @@ static coord_t getPixels(gdispImage *img, coord_t x) {
uint16_t w[2]; uint16_t w[2];
color_t r, g, b; color_t r, g, b;
while(x < img->width && len <= BLIT_BUFFER_SIZE-2) { while(x < img->width && len <= BLIT_BUFFER_SIZE_BMP-2) {
if (gfileRead(img->f, &w, 4) != 4) if (gfileRead(img->f, &w, 4) != 4)
return 0; return 0;
gdispImageMakeLE16(w[0]); gdispImageMakeLE16(w[0]);
@ -642,7 +642,7 @@ static coord_t getPixels(gdispImage *img, coord_t x) {
{ {
uint8_t b[3]; uint8_t b[3];
while(x < img->width && len < BLIT_BUFFER_SIZE) { while(x < img->width && len < BLIT_BUFFER_SIZE_BMP) {
if (gfileRead(img->f, &b, 3) != 3) if (gfileRead(img->f, &b, 3) != 3)
return 0; return 0;
*pc++ = RGB2COLOR(b[2], b[1], b[0]); *pc++ = RGB2COLOR(b[2], b[1], b[0]);
@ -665,7 +665,7 @@ static coord_t getPixels(gdispImage *img, coord_t x) {
uint32_t dw; uint32_t dw;
color_t r, g, b; color_t r, g, b;
while(x < img->width && len < BLIT_BUFFER_SIZE) { while(x < img->width && len < BLIT_BUFFER_SIZE_BMP) {
if (gfileRead(img->f, &dw, 4) != 4) if (gfileRead(img->f, &dw, 4) != 4)
return 0; return 0;
gdispImageMakeLE32(dw); gdispImageMakeLE32(dw);
@ -696,7 +696,7 @@ static coord_t getPixels(gdispImage *img, coord_t x) {
} }
gdispImageError gdispImageCache_BMP(gdispImage *img) { gdispImageError gdispImageCache_BMP(gdispImage *img) {
gdispImagePrivate * priv; gdispImagePrivate_BMP * priv;
color_t * pcs; color_t * pcs;
color_t * pcd; color_t * pcd;
coord_t pos, x, y; coord_t pos, x, y;
@ -752,7 +752,7 @@ gdispImageError gdispImageCache_BMP(gdispImage *img) {
} }
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) { 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) {
gdispImagePrivate * priv; gdispImagePrivate_BMP * priv;
coord_t mx, my; coord_t mx, my;
coord_t pos, len, st; coord_t pos, len, st;

View File

@ -15,20 +15,20 @@
* How big an array to allocate for blitting (in pixels) * How big an array to allocate for blitting (in pixels)
* Bigger is faster but uses more RAM. * Bigger is faster but uses more RAM.
*/ */
#define BLIT_BUFFER_SIZE 32 #define BLIT_BUFFER_SIZE_GIF 32
// We need a special error to indicate the end of file (which may not actually be an error) // We need a special error to indicate the end of file (which may not actually be an error)
#define GDISP_IMAGE_EOF ((gdispImageError)-1) #define GDISP_IMAGE_GIF_EOF ((gdispImageError)-1)
#define GDISP_IMAGE_LOOP ((gdispImageError)-2) #define GDISP_IMAGE_GIF_LOOP ((gdispImageError)-2)
#define MAX_CODE_BITS 12 #define GIF_MAX_CODE_BITS 12
#define CODE_MAX ((1<<MAX_CODE_BITS)-1) // Maximum legal code value #define GIF_CODE_MAX ((1<<GIF_MAX_CODE_BITS)-1) // Maximum legal code value
#define CODE_FLUSH (CODE_MAX+1) // Illegal code to signal flush #define GIF_CODE_FLUSH (GIF_CODE_MAX+1) // Illegal code to signal flush
#define CODE_FIRST (CODE_MAX+2) // Illegal code to signal first #define GIF_CODE_FIRST (GIF_CODE_MAX+2) // Illegal code to signal first
#define CODE_NONE (CODE_MAX+3) // Illegal code to signal empty #define GIF_CODE_NONE (GIF_CODE_MAX+3) // Illegal code to signal empty
// Convert bits to masks for that number of bits // Convert bits to masks for that number of bits
static const uint16_t BitMask[] = { static const uint16_t GifBitMask[] = {
0x0000, 0x0001, 0x0003, 0x0007, 0x0000, 0x0001, 0x0003, 0x0007,
0x000f, 0x001f, 0x003f, 0x007f, 0x000f, 0x001f, 0x003f, 0x007f,
0x00ff, 0x01ff, 0x03ff, 0x07ff, 0x00ff, 0x01ff, 0x03ff, 0x07ff,
@ -36,7 +36,7 @@ static const uint16_t BitMask[] = {
}; };
// Structure for decoding a single frame // Structure for decoding a single frame
typedef struct imgdecode { typedef struct gifimgdecode {
uint8_t blocksz; // The size of the block currently being processed uint8_t blocksz; // The size of the block currently being processed
uint8_t maxpixel; // The maximum allowed pixel value uint8_t maxpixel; // The maximum allowed pixel value
uint8_t bitsperpixel; uint8_t bitsperpixel;
@ -50,14 +50,14 @@ typedef struct imgdecode {
uint16_t code_last; uint16_t code_last;
uint32_t shiftdata; uint32_t shiftdata;
color_t * palette; color_t * palette;
uint8_t buf[BLIT_BUFFER_SIZE]; // Buffer for decoded pixels uint8_t buf[BLIT_BUFFER_SIZE_GIF]; // Buffer for decoded pixels
uint16_t prefix[1<<MAX_CODE_BITS]; // The LZW table uint16_t prefix[1<<GIF_MAX_CODE_BITS]; // The LZW table
uint8_t suffix[1<<MAX_CODE_BITS]; // So we can trace the codes uint8_t suffix[1<<GIF_MAX_CODE_BITS]; // So we can trace the codes
uint8_t stack[1<<MAX_CODE_BITS]; // Decoded pixels might be stacked here uint8_t stack[1<<GIF_MAX_CODE_BITS]; // Decoded pixels might be stacked here
} imgdecode; } gifimgdecode;
// The data on a single frame // The data on a single frame
typedef struct imgframe { typedef struct gifimgframe {
coord_t x, y; // position relative to full image coord_t x, y; // position relative to full image
coord_t width, height; // size of frame coord_t width, height; // size of frame
uint16_t delay; // delay after processing uint16_t delay; // delay after processing
@ -72,55 +72,55 @@ typedef struct imgframe {
size_t pospal; // The file position of the palette size_t pospal; // The file position of the palette
size_t posimg; // The file position of the image bits size_t posimg; // The file position of the image bits
size_t posend; // The file position of the end of the frame size_t posend; // The file position of the end of the frame
} imgframe; } gifimgframe;
// The data for a cache // The data for a cache
typedef struct imgcache { typedef struct gifimgcache {
imgframe frame; gifimgframe frame;
color_t * palette; // Local palette color_t * palette; // Local palette
uint8_t * imagebits; // Image bits - only saved when caching uint8_t * imagebits; // Image bits - only saved when caching
struct imgcache * next; // Next cached frame struct gifimgcache *next; // Next cached frame
} imgcache; } gifimgcache;
// The data for a dispose area // The data for a dispose area
typedef struct imgdispose { typedef struct gifimgdispose {
uint8_t flags; // Frame flags uint8_t flags; // Frame flags
uint8_t paltrans; // Transparency uint8_t paltrans; // Transparency
coord_t x, y; // position relative to full image coord_t x, y; // position relative to full image
coord_t width, height; // size of dispose area coord_t width, height; // size of dispose area
} imgdispose; } gifimgdispose;
typedef struct gdispImagePrivate { typedef struct gdispImagePrivate_GIF {
uint8_t flags; // Flags (global) uint8_t flags; // Flags (global)
#define GIF_LOOP 0x01 // Loop back to first frame #define GIF_LOOP 0x01 // Loop back to first frame
#define GIF_LOOPFOREVER 0x02 // Looping is forever #define GIF_LOOPFOREVER 0x02 // Looping is forever
uint8_t bgcolor; // Background Color (global) uint8_t bgcolor; // Background Color (global)
uint16_t loops; // Remaining frame loops (if animated) uint16_t loops; // Remaining frame loops (if animated)
uint16_t palsize; // Global palette size (global) uint16_t palsize; // Global palette size (global)
pixel_t *palette; // Global palette (global) pixel_t *palette; // Global palette (global)
size_t frame0pos; // The position of the first frame size_t frame0pos; // The position of the first frame
imgcache * cache; // The list of cached frames gifimgcache * cache; // The list of cached frames
imgcache * curcache; // The cache of the current frame (if created) gifimgcache * curcache; // The cache of the current frame (if created)
imgdecode * decode; // The decode data for the decode in progress gifimgdecode * decode; // The decode data for the decode in progress
imgframe frame; gifimgframe frame;
imgdispose dispose; gifimgdispose dispose;
pixel_t buf[BLIT_BUFFER_SIZE]; // Buffer for reading and blitting pixel_t buf[BLIT_BUFFER_SIZE_GIF]; // Buffer for reading and blitting
} gdispImagePrivate; } gdispImagePrivate_GIF;
/** /**
* Get ready for decoding a frame. * Get ready for decoding a frame.
* *
* Pre: Frame info has been read. * Pre: Frame info has been read.
*/ */
static gdispImageError startDecode(gdispImage *img) { static gdispImageError startDecodeGif(gdispImage *img) {
gdispImagePrivate * priv; gdispImagePrivate_GIF * priv;
imgdecode * decode; gifimgdecode * decode;
uint16_t cnt; uint16_t cnt;
priv = img->priv; priv = img->priv;
// We need the decode ram, and possibly a palette // We need the decode ram, and possibly a palette
if (!(decode = (imgdecode *)gdispImageAlloc(img, sizeof(imgdecode)+priv->frame.palsize*sizeof(color_t)))) if (!(decode = (gifimgdecode *)gdispImageAlloc(img, sizeof(gifimgdecode)+priv->frame.palsize*sizeof(color_t))))
return GDISP_IMAGE_ERR_NOMEMORY; return GDISP_IMAGE_ERR_NOMEMORY;
// We currently have not read any image data block // We currently have not read any image data block
@ -148,26 +148,26 @@ static gdispImageError startDecode(gdispImage *img) {
// Get the initial lzw code size and values // Get the initial lzw code size and values
gfileSetPos(img->f, priv->frame.posimg); gfileSetPos(img->f, priv->frame.posimg);
if (gfileRead(img->f, &decode->bitsperpixel, 1) != 1 || decode->bitsperpixel >= MAX_CODE_BITS) if (gfileRead(img->f, &decode->bitsperpixel, 1) != 1 || decode->bitsperpixel >= GIF_MAX_CODE_BITS)
goto baddatacleanup; goto baddatacleanup;
decode->code_clear = 1 << decode->bitsperpixel; decode->code_clear = 1 << decode->bitsperpixel;
decode->code_eof = decode->code_clear + 1; decode->code_eof = decode->code_clear + 1;
decode->code_max = decode->code_clear + 2; decode->code_max = decode->code_clear + 2;
decode->code_last = CODE_NONE; decode->code_last = GIF_CODE_NONE;
decode->bitspercode = decode->bitsperpixel+1; decode->bitspercode = decode->bitsperpixel+1;
decode->maxcodesz = 1 << decode->bitspercode; decode->maxcodesz = 1 << decode->bitspercode;
decode->shiftbits = 0; decode->shiftbits = 0;
decode->shiftdata = 0; decode->shiftdata = 0;
decode->stackcnt = 0; decode->stackcnt = 0;
for(cnt = 0; cnt <= CODE_MAX; cnt++) for(cnt = 0; cnt <= GIF_CODE_MAX; cnt++)
decode->prefix[cnt] = CODE_NONE; decode->prefix[cnt] = GIF_CODE_NONE;
// All ready to go // All ready to go
priv->decode = decode; priv->decode = decode;
return GDISP_IMAGE_ERR_OK; return GDISP_IMAGE_ERR_OK;
baddatacleanup: baddatacleanup:
gdispImageFree(img, decode, sizeof(imgdecode)+priv->frame.palsize*sizeof(color_t)); gdispImageFree(img, decode, sizeof(gifimgdecode)+priv->frame.palsize*sizeof(color_t));
return GDISP_IMAGE_ERR_BADDATA; return GDISP_IMAGE_ERR_BADDATA;
} }
@ -176,24 +176,24 @@ baddatacleanup:
* *
* Pre: Frame info has been read. * Pre: Frame info has been read.
*/ */
static void stopDecode(gdispImage *img) { static void stopDecodeGif(gdispImage *img) {
gdispImagePrivate * priv; gdispImagePrivate_GIF * priv;
priv = img->priv; priv = img->priv;
// Free the decode data // Free the decode data
if (priv->decode) { if (priv->decode) {
gdispImageFree(img, (void *)priv->decode, sizeof(imgdecode)+priv->frame.palsize*sizeof(color_t)); gdispImageFree(img, (void *)priv->decode, sizeof(gifimgdecode)+priv->frame.palsize*sizeof(color_t));
priv->decode = 0; priv->decode = 0;
} }
} }
static uint16_t getPrefix(imgdecode *decode, uint16_t code) { static uint16_t getPrefixGif(gifimgdecode *decode, uint16_t code) {
uint16_t i; uint16_t i;
for(i=0; code > decode->code_clear && i <= CODE_MAX; i++, code = decode->prefix[code]) { for(i=0; code > decode->code_clear && i <= GIF_CODE_MAX; i++, code = decode->prefix[code]) {
if (code > CODE_MAX) if (code > GIF_CODE_MAX)
return CODE_NONE; return GIF_CODE_NONE;
} }
return code; return code;
} }
@ -203,16 +203,16 @@ static uint16_t getPrefix(imgdecode *decode, uint16_t code) {
* *
* Pre: We are ready for decoding. * Pre: We are ready for decoding.
* *
* Return: The number of pixels decoded 0 .. BLIT_BUFFER_SIZE-1. 0 means EOF * Return: The number of pixels decoded 0 .. BLIT_BUFFER_SIZE_GIF-1. 0 means EOF
* *
* Note: The resulting pixels are stored in decode->buf * Note: The resulting pixels are stored in decode->buf
*/ */
static uint16_t getbytes(gdispImage *img) { static uint16_t getBytesGif(gdispImage *img) {
gdispImagePrivate * priv; gdispImagePrivate_GIF * priv;
imgdecode * decode; gifimgdecode * decode;
uint16_t cnt; uint16_t cnt;
uint16_t code, prefix; uint16_t code, prefix;
uint8_t bdata; uint8_t bdata;
priv = img->priv; priv = img->priv;
decode = priv->decode; decode = priv->decode;
@ -243,16 +243,16 @@ static uint16_t getbytes(gdispImage *img) {
decode->shiftdata |= ((unsigned long)bdata) << decode->shiftbits; decode->shiftdata |= ((unsigned long)bdata) << decode->shiftbits;
decode->shiftbits += 8; decode->shiftbits += 8;
} }
code = decode->shiftdata & BitMask[decode->bitspercode]; code = decode->shiftdata & GifBitMask[decode->bitspercode];
decode->shiftdata >>= decode->bitspercode; decode->shiftdata >>= decode->bitspercode;
decode->shiftbits -= decode->bitspercode; decode->shiftbits -= decode->bitspercode;
/** /**
* If code cannot fit into bitspercode bits we must raise its size. * If code cannot fit into bitspercode bits we must raise its size.
* Note that codes above CODE_MAX are used for special signaling. * Note that codes above GIF_CODE_MAX are used for special signaling.
* If we're using MAX_CODE_BITS bits already and we're at the max code, just * If we're using GIF_MAX_CODE_BITS bits already and we're at the max code, just
* keep using the table as it is, don't increment decode->bitspercode. * keep using the table as it is, don't increment decode->bitspercode.
*/ */
if (decode->code_max < CODE_MAX + 2 && ++decode->code_max > decode->maxcodesz && decode->bitspercode < MAX_CODE_BITS) { if (decode->code_max < GIF_CODE_MAX + 2 && ++decode->code_max > decode->maxcodesz && decode->bitspercode < GIF_MAX_CODE_BITS) {
decode->maxcodesz <<= 1; decode->maxcodesz <<= 1;
decode->bitspercode++; decode->bitspercode++;
} }
@ -271,12 +271,12 @@ static uint16_t getbytes(gdispImage *img) {
if (code == decode->code_clear) { if (code == decode->code_clear) {
// Start again // Start again
for(prefix = 0; prefix <= CODE_MAX; prefix++) for(prefix = 0; prefix <= GIF_CODE_MAX; prefix++)
decode->prefix[prefix] = CODE_NONE; decode->prefix[prefix] = GIF_CODE_NONE;
decode->code_max = decode->code_eof + 1; decode->code_max = decode->code_eof + 1;
decode->bitspercode = decode->bitsperpixel + 1; decode->bitspercode = decode->bitsperpixel + 1;
decode->maxcodesz = 1 << decode->bitspercode; decode->maxcodesz = 1 << decode->bitspercode;
decode->code_last = CODE_NONE; decode->code_last = GIF_CODE_NONE;
continue; continue;
} }
@ -290,7 +290,7 @@ static uint16_t getbytes(gdispImage *img) {
* valid pixel while pushing the suffix pixels on the stack. * valid pixel while pushing the suffix pixels on the stack.
* If done, pop the stack in reverse order adding the pixels * If done, pop the stack in reverse order adding the pixels
*/ */
if (decode->prefix[code] != CODE_NONE) if (decode->prefix[code] != GIF_CODE_NONE)
prefix = code; prefix = code;
/** /**
@ -301,34 +301,34 @@ static uint16_t getbytes(gdispImage *img) {
*/ */
else if (code == decode->code_max - 2 && decode->stackcnt < sizeof(decode->stack)) { else if (code == decode->code_max - 2 && decode->stackcnt < sizeof(decode->stack)) {
prefix = decode->code_last; prefix = decode->code_last;
decode->suffix[decode->code_max - 2] = decode->stack[decode->stackcnt++] = getPrefix(decode, decode->code_last); decode->suffix[decode->code_max - 2] = decode->stack[decode->stackcnt++] = getPrefixGif(decode, decode->code_last);
} else } else
return 0; return 0;
/** /**
* If the image is OK we should not get a CODE_NONE while tracing. * If the image is OK we should not get a GIF_CODE_NONE while tracing.
* To prevent looping with a bad image we use StackPtr as loop counter * To prevent looping with a bad image we use StackPtr as loop counter
* and stop before overflowing Stack[]. * and stop before overflowing Stack[].
*/ */
while (decode->stackcnt < sizeof(decode->stack) && prefix > decode->code_clear && prefix <= CODE_MAX) { while (decode->stackcnt < sizeof(decode->stack) && prefix > decode->code_clear && prefix <= GIF_CODE_MAX) {
decode->stack[decode->stackcnt++] = decode->suffix[prefix]; decode->stack[decode->stackcnt++] = decode->suffix[prefix];
prefix = decode->prefix[prefix]; prefix = decode->prefix[prefix];
} }
if (decode->stackcnt >= sizeof(decode->stack) || prefix > CODE_MAX) if (decode->stackcnt >= sizeof(decode->stack) || prefix > GIF_CODE_MAX)
return 0; return 0;
/* Push the last character on stack: */ /* Push the last character on stack: */
decode->stack[decode->stackcnt++] = prefix; decode->stack[decode->stackcnt++] = prefix;
} }
if (decode->code_last != CODE_NONE && decode->prefix[decode->code_max - 2] == CODE_NONE) { if (decode->code_last != GIF_CODE_NONE && decode->prefix[decode->code_max - 2] == GIF_CODE_NONE) {
decode->prefix[decode->code_max - 2] = decode->code_last; decode->prefix[decode->code_max - 2] = decode->code_last;
/* Only allowed if code is exactly the running code: /* Only allowed if code is exactly the running code:
* In that case code = XXXCode, CrntCode or the * In that case code = XXXCode, CrntCode or the
* prefix code is last code and the suffix char is * prefix code is last code and the suffix char is
* exactly the prefix of last code! */ * exactly the prefix of last code! */
decode->suffix[decode->code_max - 2] = getPrefix(decode, code == decode->code_max - 2 ? decode->code_last : code); decode->suffix[decode->code_max - 2] = getPrefixGif(decode, code == decode->code_max - 2 ? decode->code_last : code);
} }
decode->code_last = code; decode->code_last = code;
} }
@ -340,11 +340,11 @@ static uint16_t getbytes(gdispImage *img) {
* *
* Pre: The file position is at the start of the frame. * Pre: The file position is at the start of the frame.
*/ */
static gdispImageError initFrame(gdispImage *img) { static gdispImageError initFrameGif(gdispImage *img) {
gdispImagePrivate * priv; gdispImagePrivate_GIF * priv;
imgcache * cache; gifimgcache * cache;
uint8_t blocktype; uint8_t blocktype;
uint8_t blocksz; uint8_t blocksz;
priv = img->priv; priv = img->priv;
@ -482,16 +482,16 @@ static gdispImageError initFrame(gdispImage *img) {
case 0x3B: //';' - TERMINATE_RECORD_TYPE; case 0x3B: //';' - TERMINATE_RECORD_TYPE;
// Are we an looping animation // Are we an looping animation
if (!(priv->flags & GIF_LOOP)) if (!(priv->flags & GIF_LOOP))
return GDISP_IMAGE_EOF; return GDISP_IMAGE_GIF_EOF;
if (!(priv->flags & GIF_LOOPFOREVER)) { if (!(priv->flags & GIF_LOOPFOREVER)) {
if (!priv->loops) if (!priv->loops)
return GDISP_IMAGE_EOF; return GDISP_IMAGE_GIF_EOF;
priv->loops--; priv->loops--;
} }
// Seek back to frame0 // Seek back to frame0
gfileSetPos(img->f, priv->frame0pos); gfileSetPos(img->f, priv->frame0pos);
return GDISP_IMAGE_LOOP; return GDISP_IMAGE_GIF_LOOP;
default: // UNDEFINED_RECORD_TYPE; default: // UNDEFINED_RECORD_TYPE;
return GDISP_IMAGE_ERR_UNSUPPORTED; return GDISP_IMAGE_ERR_UNSUPPORTED;
@ -500,9 +500,9 @@ static gdispImageError initFrame(gdispImage *img) {
} }
void gdispImageClose_GIF(gdispImage *img) { void gdispImageClose_GIF(gdispImage *img) {
gdispImagePrivate * priv; gdispImagePrivate_GIF * priv;
imgcache * cache; gifimgcache * cache;
imgcache * ncache; gifimgcache * ncache;
priv = img->priv; priv = img->priv;
if (priv) { if (priv) {
@ -510,18 +510,18 @@ void gdispImageClose_GIF(gdispImage *img) {
cache = priv->cache; cache = priv->cache;
while(cache) { while(cache) {
ncache = cache->next; ncache = cache->next;
gdispImageFree(img, (void *)cache, sizeof(imgcache)+cache->frame.width*cache->frame.height+cache->frame.palsize*sizeof(color_t)); gdispImageFree(img, (void *)cache, sizeof(gifimgcache)+cache->frame.width*cache->frame.height+cache->frame.palsize*sizeof(color_t));
cache = ncache; cache = ncache;
} }
if (priv->palette) if (priv->palette)
gdispImageFree(img, (void *)priv->palette, priv->palsize*sizeof(color_t)); gdispImageFree(img, (void *)priv->palette, priv->palsize*sizeof(color_t));
gdispImageFree(img, (void *)img->priv, sizeof(gdispImagePrivate)); gdispImageFree(img, (void *)img->priv, sizeof(gdispImagePrivate_GIF));
img->priv = 0; img->priv = 0;
} }
} }
gdispImageError gdispImageOpen_GIF(gdispImage *img) { gdispImageError gdispImageOpen_GIF(gdispImage *img) {
gdispImagePrivate *priv; gdispImagePrivate_GIF *priv;
uint8_t hdr[6]; uint8_t hdr[6];
uint16_t aword; uint16_t aword;
@ -539,7 +539,7 @@ gdispImageError gdispImageOpen_GIF(gdispImage *img) {
img->flags = 0; img->flags = 0;
/* Allocate our private area */ /* Allocate our private area */
if (!(img->priv = (gdispImagePrivate *)gdispImageAlloc(img, sizeof(gdispImagePrivate)))) if (!(img->priv = (gdispImagePrivate_GIF *)gdispImageAlloc(img, sizeof(gdispImagePrivate_GIF))))
return GDISP_IMAGE_ERR_NOMEMORY; return GDISP_IMAGE_ERR_NOMEMORY;
/* Initialise the essential bits in the private area */ /* Initialise the essential bits in the private area */
@ -579,7 +579,7 @@ gdispImageError gdispImageOpen_GIF(gdispImage *img) {
priv->frame0pos = gfileGetPos(img->f); priv->frame0pos = gfileGetPos(img->f);
// Read the first frame descriptor // Read the first frame descriptor
switch(initFrame(img)) { switch(initFrameGif(img)) {
case GDISP_IMAGE_ERR_OK: // Everything OK case GDISP_IMAGE_ERR_OK: // Everything OK
img->type = GDISP_IMAGE_TYPE_GIF; img->type = GDISP_IMAGE_TYPE_GIF;
return GDISP_IMAGE_ERR_OK; return GDISP_IMAGE_ERR_OK;
@ -590,8 +590,8 @@ gdispImageError gdispImageOpen_GIF(gdispImage *img) {
nomemcleanup: nomemcleanup:
gdispImageClose_GIF(img); // Clean up the private data area gdispImageClose_GIF(img); // Clean up the private data area
return GDISP_IMAGE_ERR_NOMEMORY; return GDISP_IMAGE_ERR_NOMEMORY;
case GDISP_IMAGE_EOF: // We should have a frame but we don't seem to case GDISP_IMAGE_GIF_EOF: // We should have a frame but we don't seem to
case GDISP_IMAGE_LOOP: // We should have a frame but we don't seem to case GDISP_IMAGE_GIF_LOOP: // We should have a frame but we don't seem to
case GDISP_IMAGE_ERR_BADDATA: // Oops - something wrong with the data case GDISP_IMAGE_ERR_BADDATA: // Oops - something wrong with the data
default: default:
baddatacleanup: baddatacleanup:
@ -601,13 +601,13 @@ gdispImageError gdispImageOpen_GIF(gdispImage *img) {
} }
gdispImageError gdispImageCache_GIF(gdispImage *img) { gdispImageError gdispImageCache_GIF(gdispImage *img) {
gdispImagePrivate * priv; gdispImagePrivate_GIF * priv;
imgcache * cache; gifimgcache * cache;
imgdecode * decode; gifimgdecode * decode;
uint8_t * p; uint8_t * p;
uint8_t * q; uint8_t * q;
coord_t mx, my; coord_t mx, my;
uint16_t cnt; uint16_t cnt;
/* If we are already cached - just return OK */ /* If we are already cached - just return OK */
priv = img->priv; priv = img->priv;
@ -615,7 +615,7 @@ gdispImageError gdispImageCache_GIF(gdispImage *img) {
return GDISP_IMAGE_ERR_OK; return GDISP_IMAGE_ERR_OK;
/* We need to allocate the frame, the palette and bits for the image */ /* We need to allocate the frame, the palette and bits for the image */
if (!(cache = (imgcache *)gdispImageAlloc(img, sizeof(imgcache) + priv->frame.palsize*sizeof(color_t) + priv->frame.width*priv->frame.height))) if (!(cache = (gifimgcache *)gdispImageAlloc(img, sizeof(gifimgcache) + priv->frame.palsize*sizeof(color_t) + priv->frame.width*priv->frame.height)))
return GDISP_IMAGE_ERR_NOMEMORY; return GDISP_IMAGE_ERR_NOMEMORY;
/* Initialise the cache */ /* Initialise the cache */
@ -625,7 +625,7 @@ gdispImageError gdispImageCache_GIF(gdispImage *img) {
cache->next = 0; cache->next = 0;
/* Start the decode */ /* Start the decode */
switch(startDecode(img)) { switch(startDecodeGif(img)) {
case GDISP_IMAGE_ERR_OK: break; case GDISP_IMAGE_ERR_OK: break;
case GDISP_IMAGE_ERR_NOMEMORY: goto nomemcleanup; case GDISP_IMAGE_ERR_NOMEMORY: goto nomemcleanup;
case GDISP_IMAGE_ERR_BADDATA: case GDISP_IMAGE_ERR_BADDATA:
@ -651,7 +651,7 @@ gdispImageError gdispImageCache_GIF(gdispImage *img) {
for(p=cache->imagebits, my=0; my < cache->frame.height; my+=8, p += cache->frame.width*7) { for(p=cache->imagebits, my=0; my < cache->frame.height; my+=8, p += cache->frame.width*7) {
for(mx=0; mx < cache->frame.width; mx++) { for(mx=0; mx < cache->frame.width; mx++) {
if (!cnt) { if (!cnt) {
if (!(cnt = getbytes(img))) { if (!(cnt = getBytesGif(img))) {
// Sometimes the image EOF is a bit early - treat the rest as transparent // Sometimes the image EOF is a bit early - treat the rest as transparent
if (decode->code_last != decode->code_eof) if (decode->code_last != decode->code_eof)
goto baddatacleanup; goto baddatacleanup;
@ -668,7 +668,7 @@ gdispImageError gdispImageCache_GIF(gdispImage *img) {
for(p=cache->imagebits+cache->frame.width*4, my=4; my < cache->frame.height; my+=8, p += cache->frame.width*7) { for(p=cache->imagebits+cache->frame.width*4, my=4; my < cache->frame.height; my+=8, p += cache->frame.width*7) {
for(mx=0; mx < cache->frame.width; mx++) { for(mx=0; mx < cache->frame.width; mx++) {
if (!cnt) { if (!cnt) {
if (!(cnt = getbytes(img))) { if (!(cnt = getBytesGif(img))) {
// Sometimes the image EOF is a bit early - treat the rest as transparent // Sometimes the image EOF is a bit early - treat the rest as transparent
if (decode->code_last != decode->code_eof) if (decode->code_last != decode->code_eof)
goto baddatacleanup; goto baddatacleanup;
@ -685,7 +685,7 @@ gdispImageError gdispImageCache_GIF(gdispImage *img) {
for(p=cache->imagebits+cache->frame.width*2, my=2; my < cache->frame.height; my+=4, p += cache->frame.width*3) { for(p=cache->imagebits+cache->frame.width*2, my=2; my < cache->frame.height; my+=4, p += cache->frame.width*3) {
for(mx=0; mx < cache->frame.width; mx++) { for(mx=0; mx < cache->frame.width; mx++) {
if (!cnt) { if (!cnt) {
if (!(cnt = getbytes(img))) { if (!(cnt = getBytesGif(img))) {
// Sometimes the image EOF is a bit early - treat the rest as transparent // Sometimes the image EOF is a bit early - treat the rest as transparent
if (decode->code_last != decode->code_eof) if (decode->code_last != decode->code_eof)
goto baddatacleanup; goto baddatacleanup;
@ -702,7 +702,7 @@ gdispImageError gdispImageCache_GIF(gdispImage *img) {
for(p=cache->imagebits+cache->frame.width, my=1; my < cache->frame.height; my+=2, p += cache->frame.width) { for(p=cache->imagebits+cache->frame.width, my=1; my < cache->frame.height; my+=2, p += cache->frame.width) {
for(mx=0; mx < cache->frame.width; mx++) { for(mx=0; mx < cache->frame.width; mx++) {
if (!cnt) { if (!cnt) {
if (!(cnt = getbytes(img))) { if (!(cnt = getBytesGif(img))) {
// Sometimes the image EOF is a bit early - treat the rest as transparent // Sometimes the image EOF is a bit early - treat the rest as transparent
if (decode->code_last != decode->code_eof) if (decode->code_last != decode->code_eof)
goto baddatacleanup; goto baddatacleanup;
@ -721,7 +721,7 @@ gdispImageError gdispImageCache_GIF(gdispImage *img) {
for(my=0; my < cache->frame.height; my++) { for(my=0; my < cache->frame.height; my++) {
for(mx=0; mx < cache->frame.width; mx++) { for(mx=0; mx < cache->frame.width; mx++) {
if (!cnt) { if (!cnt) {
if (!(cnt = getbytes(img))) { if (!(cnt = getBytesGif(img))) {
// Sometimes the image EOF is a bit early - treat the rest as transparent // Sometimes the image EOF is a bit early - treat the rest as transparent
if (decode->code_last != decode->code_eof) if (decode->code_last != decode->code_eof)
goto baddatacleanup; goto baddatacleanup;
@ -736,7 +736,7 @@ gdispImageError gdispImageCache_GIF(gdispImage *img) {
} }
} }
// We could be pedantic here but extra bytes won't hurt us // We could be pedantic here but extra bytes won't hurt us
while(getbytes(img)); while(getBytesGif(img));
priv->frame.posend = cache->frame.posend = gfileGetPos(img->f); priv->frame.posend = cache->frame.posend = gfileGetPos(img->f);
// Save everything // Save everything
@ -747,7 +747,7 @@ gdispImageError gdispImageCache_GIF(gdispImage *img) {
cache->next = priv->cache; cache->next = priv->cache;
priv->cache = cache; priv->cache = cache;
} else { } else {
imgcache *pc; gifimgcache *pc;
for(pc = priv->cache; pc; pc = pc->next) { for(pc = priv->cache; pc; pc = pc->next) {
if (!pc->next || pc->next->frame.posstart > cache->frame.posstart) { if (!pc->next || pc->next->frame.posstart > cache->frame.posstart) {
@ -757,27 +757,27 @@ gdispImageError gdispImageCache_GIF(gdispImage *img) {
} }
} }
} }
stopDecode(img); stopDecodeGif(img);
return GDISP_IMAGE_ERR_OK; return GDISP_IMAGE_ERR_OK;
nomemcleanup: nomemcleanup:
stopDecode(img); stopDecodeGif(img);
gdispImageFree(img, cache, sizeof(imgcache) + priv->frame.palsize*sizeof(color_t) + priv->frame.width*priv->frame.height); gdispImageFree(img, cache, sizeof(gifimgcache) + priv->frame.palsize*sizeof(color_t) + priv->frame.width*priv->frame.height);
return GDISP_IMAGE_ERR_NOMEMORY; return GDISP_IMAGE_ERR_NOMEMORY;
baddatacleanup: baddatacleanup:
stopDecode(img); stopDecodeGif(img);
gdispImageFree(img, cache, sizeof(imgcache) + priv->frame.palsize*sizeof(color_t) + priv->frame.width*priv->frame.height); gdispImageFree(img, cache, sizeof(gifimgcache) + priv->frame.palsize*sizeof(color_t) + priv->frame.width*priv->frame.height);
return GDISP_IMAGE_ERR_BADDATA; return GDISP_IMAGE_ERR_BADDATA;
} }
gdispImageError gdispGImageDraw_GIF(GDisplay *g, gdispImage *img, coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t sx, coord_t sy) { gdispImageError gdispGImageDraw_GIF(GDisplay *g, gdispImage *img, coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t sx, coord_t sy) {
gdispImagePrivate * priv; gdispImagePrivate_GIF * priv;
imgdecode * decode; gifimgdecode * decode;
uint8_t * q = 0; uint8_t * q = 0;
coord_t mx, my, fx, fy; coord_t mx, my, fx, fy;
uint16_t cnt, gcnt; uint16_t cnt, gcnt;
uint8_t col; uint8_t col;
priv = img->priv; priv = img->priv;
@ -820,7 +820,7 @@ gdispImageError gdispGImageDraw_GIF(GDisplay *g, gdispImage *img, coord_t x, coo
/* Draw from the image cache - if it exists */ /* Draw from the image cache - if it exists */
if (priv->curcache) { if (priv->curcache) {
imgcache * cache; gifimgcache * cache;
cache = priv->curcache; cache = priv->curcache;
q = cache->imagebits+priv->frame.width*sy+sx; q = cache->imagebits+priv->frame.width*sy+sx;
@ -838,7 +838,7 @@ gdispImageError gdispGImageDraw_GIF(GDisplay *g, gdispImage *img, coord_t x, coo
continue; continue;
} }
priv->buf[gcnt++] = cache->palette[col]; priv->buf[gcnt++] = cache->palette[col];
if (gcnt >= BLIT_BUFFER_SIZE) { if (gcnt >= BLIT_BUFFER_SIZE_GIF) {
// We have run out of buffer - dump it to the display // We have run out of buffer - dump it to the display
gdispGBlitArea(g, x+mx-sx-gcnt+1, y+my-sy, gcnt, 1, 0, 0, gcnt, priv->buf); gdispGBlitArea(g, x+mx-sx-gcnt+1, y+my-sy, gcnt, 1, 0, 0, gcnt, priv->buf);
gcnt = 0; gcnt = 0;
@ -856,7 +856,7 @@ gdispImageError gdispGImageDraw_GIF(GDisplay *g, gdispImage *img, coord_t x, coo
} }
/* Start the decode */ /* Start the decode */
switch(startDecode(img)) { switch(startDecodeGif(img)) {
case GDISP_IMAGE_ERR_OK: break; case GDISP_IMAGE_ERR_OK: break;
case GDISP_IMAGE_ERR_NOMEMORY: return GDISP_IMAGE_ERR_NOMEMORY; case GDISP_IMAGE_ERR_NOMEMORY: return GDISP_IMAGE_ERR_NOMEMORY;
case GDISP_IMAGE_ERR_BADDATA: case GDISP_IMAGE_ERR_BADDATA:
@ -871,7 +871,7 @@ gdispImageError gdispGImageDraw_GIF(GDisplay *g, gdispImage *img, coord_t x, coo
for(my=0; my < priv->frame.height; my+=8) { for(my=0; my < priv->frame.height; my+=8) {
for(gcnt=0, mx=0; mx < priv->frame.width; mx++, q++, cnt--) { for(gcnt=0, mx=0; mx < priv->frame.width; mx++, q++, cnt--) {
if (!cnt) { if (!cnt) {
if (!(cnt = getbytes(img))) { if (!(cnt = getBytesGif(img))) {
// Sometimes the image EOF is a bit early - treat the rest as transparent // Sometimes the image EOF is a bit early - treat the rest as transparent
if (decode->code_last != decode->code_eof) if (decode->code_last != decode->code_eof)
goto baddatacleanup; goto baddatacleanup;
@ -892,7 +892,7 @@ gdispImageError gdispGImageDraw_GIF(GDisplay *g, gdispImage *img, coord_t x, coo
continue; continue;
} }
priv->buf[gcnt++] = decode->palette[col]; priv->buf[gcnt++] = decode->palette[col];
if (gcnt >= BLIT_BUFFER_SIZE) { if (gcnt >= BLIT_BUFFER_SIZE_GIF) {
// We have run out of buffer - dump it to the display // We have run out of buffer - dump it to the display
gdispGBlitArea(g, x+mx-sx-gcnt+1, y+my-sy, gcnt, 1, 0, 0, gcnt, priv->buf); gdispGBlitArea(g, x+mx-sx-gcnt+1, y+my-sy, gcnt, 1, 0, 0, gcnt, priv->buf);
gcnt = 0; gcnt = 0;
@ -917,7 +917,7 @@ gdispImageError gdispGImageDraw_GIF(GDisplay *g, gdispImage *img, coord_t x, coo
for(my=4; my < priv->frame.height; my+=8) { for(my=4; my < priv->frame.height; my+=8) {
for(gcnt=0, mx=0; mx < priv->frame.width; mx++, q++, cnt--) { for(gcnt=0, mx=0; mx < priv->frame.width; mx++, q++, cnt--) {
if (!cnt) { if (!cnt) {
if (!(cnt = getbytes(img))) { if (!(cnt = getBytesGif(img))) {
// Sometimes the image EOF is a bit early - treat the rest as transparent // Sometimes the image EOF is a bit early - treat the rest as transparent
if (decode->code_last != decode->code_eof) if (decode->code_last != decode->code_eof)
goto baddatacleanup; goto baddatacleanup;
@ -938,7 +938,7 @@ gdispImageError gdispGImageDraw_GIF(GDisplay *g, gdispImage *img, coord_t x, coo
continue; continue;
} }
priv->buf[gcnt++] = decode->palette[col]; priv->buf[gcnt++] = decode->palette[col];
if (gcnt >= BLIT_BUFFER_SIZE) { if (gcnt >= BLIT_BUFFER_SIZE_GIF) {
// We have run out of buffer - dump it to the display // We have run out of buffer - dump it to the display
gdispGBlitArea(g, x+mx-sx-gcnt+1, y+my-sy, gcnt, 1, 0, 0, gcnt, priv->buf); gdispGBlitArea(g, x+mx-sx-gcnt+1, y+my-sy, gcnt, 1, 0, 0, gcnt, priv->buf);
gcnt = 0; gcnt = 0;
@ -963,7 +963,7 @@ gdispImageError gdispGImageDraw_GIF(GDisplay *g, gdispImage *img, coord_t x, coo
for(my=2; my < priv->frame.height; my+=4) { for(my=2; my < priv->frame.height; my+=4) {
for(gcnt=0, mx=0; mx < priv->frame.width; mx++, q++, cnt--) { for(gcnt=0, mx=0; mx < priv->frame.width; mx++, q++, cnt--) {
if (!cnt) { if (!cnt) {
if (!(cnt = getbytes(img))) { if (!(cnt = getBytesGif(img))) {
// Sometimes the image EOF is a bit early - treat the rest as transparent // Sometimes the image EOF is a bit early - treat the rest as transparent
if (decode->code_last != decode->code_eof) if (decode->code_last != decode->code_eof)
goto baddatacleanup; goto baddatacleanup;
@ -984,7 +984,7 @@ gdispImageError gdispGImageDraw_GIF(GDisplay *g, gdispImage *img, coord_t x, coo
continue; continue;
} }
priv->buf[gcnt++] = decode->palette[col]; priv->buf[gcnt++] = decode->palette[col];
if (gcnt >= BLIT_BUFFER_SIZE) { if (gcnt >= BLIT_BUFFER_SIZE_GIF) {
// We have run out of buffer - dump it to the display // We have run out of buffer - dump it to the display
gdispGBlitArea(g, x+mx-sx-gcnt+1, y+my-sy, gcnt, 1, 0, 0, gcnt, priv->buf); gdispGBlitArea(g, x+mx-sx-gcnt+1, y+my-sy, gcnt, 1, 0, 0, gcnt, priv->buf);
gcnt = 0; gcnt = 0;
@ -1009,7 +1009,7 @@ gdispImageError gdispGImageDraw_GIF(GDisplay *g, gdispImage *img, coord_t x, coo
for(my=1; my < priv->frame.height; my+=2) { for(my=1; my < priv->frame.height; my+=2) {
for(gcnt=0, mx=0; mx < priv->frame.width; mx++, q++, cnt--) { for(gcnt=0, mx=0; mx < priv->frame.width; mx++, q++, cnt--) {
if (!cnt) { if (!cnt) {
if (!(cnt = getbytes(img))) { if (!(cnt = getBytesGif(img))) {
// Sometimes the image EOF is a bit early - treat the rest as transparent // Sometimes the image EOF is a bit early - treat the rest as transparent
if (decode->code_last != decode->code_eof) if (decode->code_last != decode->code_eof)
goto baddatacleanup; goto baddatacleanup;
@ -1030,7 +1030,7 @@ gdispImageError gdispGImageDraw_GIF(GDisplay *g, gdispImage *img, coord_t x, coo
continue; continue;
} }
priv->buf[gcnt++] = decode->palette[col]; priv->buf[gcnt++] = decode->palette[col];
if (gcnt >= BLIT_BUFFER_SIZE) { if (gcnt >= BLIT_BUFFER_SIZE_GIF) {
// We have run out of buffer - dump it to the display // We have run out of buffer - dump it to the display
gdispGBlitArea(g, x+mx-sx-gcnt+1, y+my-sy, gcnt, 1, 0, 0, gcnt, priv->buf); gdispGBlitArea(g, x+mx-sx-gcnt+1, y+my-sy, gcnt, 1, 0, 0, gcnt, priv->buf);
gcnt = 0; gcnt = 0;
@ -1056,7 +1056,7 @@ gdispImageError gdispGImageDraw_GIF(GDisplay *g, gdispImage *img, coord_t x, coo
for(my=0; my < priv->frame.height; my++) { for(my=0; my < priv->frame.height; my++) {
for(gcnt=0, mx=0; mx < priv->frame.width; mx++, q++, cnt--) { for(gcnt=0, mx=0; mx < priv->frame.width; mx++, q++, cnt--) {
if (!cnt) { if (!cnt) {
if (!(cnt = getbytes(img))) { if (!(cnt = getBytesGif(img))) {
// Sometimes the image EOF is a bit early - treat the rest as transparent // Sometimes the image EOF is a bit early - treat the rest as transparent
if (decode->code_last != decode->code_eof) if (decode->code_last != decode->code_eof)
goto baddatacleanup; goto baddatacleanup;
@ -1077,7 +1077,7 @@ gdispImageError gdispGImageDraw_GIF(GDisplay *g, gdispImage *img, coord_t x, coo
continue; continue;
} }
priv->buf[gcnt++] = decode->palette[col]; priv->buf[gcnt++] = decode->palette[col];
if (gcnt >= BLIT_BUFFER_SIZE) { if (gcnt >= BLIT_BUFFER_SIZE_GIF) {
// We have run out of buffer - dump it to the display // We have run out of buffer - dump it to the display
gdispGBlitArea(g, x+mx-sx-gcnt+1, y+my-sy, gcnt, 1, 0, 0, gcnt, priv->buf); gdispGBlitArea(g, x+mx-sx-gcnt+1, y+my-sy, gcnt, 1, 0, 0, gcnt, priv->buf);
gcnt = 0; gcnt = 0;
@ -1100,21 +1100,21 @@ gdispImageError gdispGImageDraw_GIF(GDisplay *g, gdispImage *img, coord_t x, coo
} }
} }
// We could be pedantic here but extra bytes won't hurt us // We could be pedantic here but extra bytes won't hurt us
while (getbytes(img)); while (getBytesGif(img));
priv->frame.posend = gfileGetPos(img->f); priv->frame.posend = gfileGetPos(img->f);
stopDecode(img); stopDecodeGif(img);
return GDISP_IMAGE_ERR_OK; return GDISP_IMAGE_ERR_OK;
baddatacleanup: baddatacleanup:
stopDecode(img); stopDecodeGif(img);
return GDISP_IMAGE_ERR_BADDATA; return GDISP_IMAGE_ERR_BADDATA;
} }
delaytime_t gdispImageNext_GIF(gdispImage *img) { delaytime_t gdispImageNext_GIF(gdispImage *img) {
gdispImagePrivate * priv; gdispImagePrivate_GIF * priv;
delaytime_t delay; delaytime_t delay;
uint8_t blocksz; uint8_t blocksz;
priv = img->priv; priv = img->priv;
@ -1140,12 +1140,12 @@ delaytime_t gdispImageNext_GIF(gdispImage *img) {
// Read the next frame descriptor // Read the next frame descriptor
for(blocksz=0; blocksz < 2; blocksz++) { // 2 loops max to prevent cycling forever with a bad file for(blocksz=0; blocksz < 2; blocksz++) { // 2 loops max to prevent cycling forever with a bad file
switch(initFrame(img)) { switch(initFrameGif(img)) {
case GDISP_IMAGE_ERR_OK: // Everything OK case GDISP_IMAGE_ERR_OK: // Everything OK
return delay; return delay;
case GDISP_IMAGE_LOOP: // Back to the beginning case GDISP_IMAGE_GIF_LOOP: // Back to the beginning
break; break;
case GDISP_IMAGE_EOF: // The real End-Of-File case GDISP_IMAGE_GIF_EOF: // The real End-Of-File
case GDISP_IMAGE_ERR_BADDATA: // Oops - something wrong with the data case GDISP_IMAGE_ERR_BADDATA: // Oops - something wrong with the data
case GDISP_IMAGE_ERR_NOMEMORY: // Out of Memory case GDISP_IMAGE_ERR_NOMEMORY: // Out of Memory
case GDISP_IMAGE_ERR_UNSUPPORTED: // Unsupported case GDISP_IMAGE_ERR_UNSUPPORTED: // Unsupported

View File

@ -15,10 +15,10 @@
* How big a pixel array to allocate for blitting * How big a pixel array to allocate for blitting
* Bigger is faster but uses more RAM. * Bigger is faster but uses more RAM.
*/ */
#define BLIT_BUFFER_SIZE 32 #define BLIT_BUFFER_SIZE_NATIVE 32
#define HEADER_SIZE 8 #define HEADER_SIZE_NATIVE 8
#define FRAME0POS (HEADER_SIZE) #define FRAME0POS_NATIVE (HEADER_SIZE_NATIVE)
/** /**
* Helper Routines Needed * Helper Routines Needed
@ -28,7 +28,7 @@ void gdispImageFree(gdispImage *img, void *ptr, size_t sz);
typedef struct gdispImagePrivate { typedef struct gdispImagePrivate {
pixel_t *frame0cache; pixel_t *frame0cache;
pixel_t buf[BLIT_BUFFER_SIZE]; pixel_t buf[BLIT_BUFFER_SIZE_NATIVE];
} gdispImagePrivate; } gdispImagePrivate;
void gdispImageClose_NATIVE(gdispImage *img) { void gdispImageClose_NATIVE(gdispImage *img) {
@ -41,7 +41,7 @@ void gdispImageClose_NATIVE(gdispImage *img) {
} }
gdispImageError gdispImageOpen_NATIVE(gdispImage *img) { gdispImageError gdispImageOpen_NATIVE(gdispImage *img) {
uint8_t hdr[HEADER_SIZE]; uint8_t hdr[HEADER_SIZE_NATIVE];
/* Read the 8 byte header */ /* Read the 8 byte header */
if (gfileRead(img->f, hdr, 8) != 8) if (gfileRead(img->f, hdr, 8) != 8)
@ -81,7 +81,7 @@ gdispImageError gdispImageCache_NATIVE(gdispImage *img) {
return GDISP_IMAGE_ERR_NOMEMORY; return GDISP_IMAGE_ERR_NOMEMORY;
/* Read the entire bitmap into cache */ /* Read the entire bitmap into cache */
gfileSetPos(img->f, FRAME0POS); gfileSetPos(img->f, FRAME0POS_NATIVE);
if (gfileRead(img->f, img->priv->frame0cache, len) != len) if (gfileRead(img->f, img->priv->frame0cache, len) != len)
return GDISP_IMAGE_ERR_BADDATA; return GDISP_IMAGE_ERR_BADDATA;
@ -104,7 +104,7 @@ gdispImageError gdispGImageDraw_NATIVE(GDisplay *g, gdispImage *img, coord_t x,
} }
/* For this image decoder we cheat and just seek straight to the region we want to display */ /* For this image decoder we cheat and just seek straight to the region we want to display */
pos = FRAME0POS + (img->width * sy + sx) * sizeof(pixel_t); pos = FRAME0POS_NATIVE + (img->width * sy + sx) * sizeof(pixel_t);
/* Cycle through the lines */ /* Cycle through the lines */
for(;cy;cy--, y++) { for(;cy;cy--, y++) {
@ -116,7 +116,7 @@ gdispImageError gdispGImageDraw_NATIVE(GDisplay *g, gdispImage *img, coord_t x,
// Read the data // Read the data
len = gfileRead(img->f, len = gfileRead(img->f,
img->priv->buf, img->priv->buf,
mcx > BLIT_BUFFER_SIZE ? (BLIT_BUFFER_SIZE*sizeof(pixel_t)) : (mcx * sizeof(pixel_t))) mcx > BLIT_BUFFER_SIZE_NATIVE ? (BLIT_BUFFER_SIZE_NATIVE*sizeof(pixel_t)) : (mcx * sizeof(pixel_t)))
/ sizeof(pixel_t); / sizeof(pixel_t);
if (!len) if (!len)
return GDISP_IMAGE_ERR_BADDATA; return GDISP_IMAGE_ERR_BADDATA;