From 870901880b30a7f81b2d95a815e89542746d62ab Mon Sep 17 00:00:00 2001 From: inmarket Date: Tue, 24 Nov 2015 09:19:58 +1000 Subject: [PATCH] Prevent naming conflicts when compiling multiple image formats with GFXSINGLEMAKE --- src/gdisp/gdisp_image_bmp.c | 40 ++--- src/gdisp/gdisp_image_gif.c | 288 ++++++++++++++++----------------- src/gdisp/gdisp_image_native.c | 16 +- 3 files changed, 172 insertions(+), 172 deletions(-) diff --git a/src/gdisp/gdisp_image_bmp.c b/src/gdisp/gdisp_image_bmp.c index cc3235c0..73549ae3 100644 --- a/src/gdisp/gdisp_image_bmp.c +++ b/src/gdisp/gdisp_image_bmp.c @@ -16,9 +16,9 @@ * 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 */ -#define BLIT_BUFFER_SIZE 32 +#define BLIT_BUFFER_SIZE_BMP 32 -typedef struct gdispImagePrivate { +typedef struct gdispImagePrivate_BMP { uint8_t bmpflags; #define BMP_V2 0x01 // Version 2 (old) header format #define BMP_V4 0x02 // Version 4 (alpha support) header format @@ -49,8 +49,8 @@ typedef struct gdispImagePrivate { #endif size_t frame0pos; pixel_t *frame0cache; - pixel_t buf[BLIT_BUFFER_SIZE]; - } gdispImagePrivate; + pixel_t buf[BLIT_BUFFER_SIZE_BMP]; + } gdispImagePrivate_BMP; void gdispImageClose_BMP(gdispImage *img) { if (img->priv) { @@ -60,13 +60,13 @@ void gdispImageClose_BMP(gdispImage *img) { #endif if (img->priv->frame0cache) 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; } } gdispImageError gdispImageOpen_BMP(gdispImage *img) { - gdispImagePrivate *priv; + gdispImagePrivate_BMP *priv; uint8_t hdr[2]; uint16_t aword; uint32_t adword; @@ -89,7 +89,7 @@ gdispImageError gdispImageOpen_BMP(gdispImage *img) { img->flags = 0; /* 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; /* Initialise the essential bits in the private area */ @@ -357,7 +357,7 @@ unsupportedcleanup: } static coord_t getPixels(gdispImage *img, coord_t x) { - gdispImagePrivate * priv; + gdispImagePrivate_BMP * priv; color_t * pc; coord_t len; @@ -376,7 +376,7 @@ static coord_t getPixels(gdispImage *img, coord_t x) { pc = priv->buf; 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) return 0; @@ -406,7 +406,7 @@ static coord_t getPixels(gdispImage *img, coord_t x) { while(x < img->width) { 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]; priv->rlerun--; 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 return len; } 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) return 0; *pc++ = priv->palette[b[0] >> 4]; @@ -481,7 +481,7 @@ static coord_t getPixels(gdispImage *img, coord_t x) { { 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) return 0; @@ -512,7 +512,7 @@ static coord_t getPixels(gdispImage *img, coord_t x) { while(x < img->width) { 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]; priv->rlerun--; 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 return len; } 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) return 0; *pc++ = priv->palette[b[0]]; @@ -575,7 +575,7 @@ static coord_t getPixels(gdispImage *img, coord_t x) { { 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) return 0; @@ -597,7 +597,7 @@ static coord_t getPixels(gdispImage *img, coord_t x) { uint16_t w[2]; 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) return 0; gdispImageMakeLE16(w[0]); @@ -642,7 +642,7 @@ static coord_t getPixels(gdispImage *img, coord_t x) { { 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) return 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; 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) return 0; gdispImageMakeLE32(dw); @@ -696,7 +696,7 @@ static coord_t getPixels(gdispImage *img, coord_t x) { } gdispImageError gdispImageCache_BMP(gdispImage *img) { - gdispImagePrivate * priv; + gdispImagePrivate_BMP * priv; color_t * pcs; color_t * pcd; 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) { - gdispImagePrivate * priv; + gdispImagePrivate_BMP * priv; coord_t mx, my; coord_t pos, len, st; diff --git a/src/gdisp/gdisp_image_gif.c b/src/gdisp/gdisp_image_gif.c index 0c1ba2c1..f3e9d8dd 100644 --- a/src/gdisp/gdisp_image_gif.c +++ b/src/gdisp/gdisp_image_gif.c @@ -15,20 +15,20 @@ * How big an array to allocate for blitting (in pixels) * 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) -#define GDISP_IMAGE_EOF ((gdispImageError)-1) -#define GDISP_IMAGE_LOOP ((gdispImageError)-2) +#define GDISP_IMAGE_GIF_EOF ((gdispImageError)-1) +#define GDISP_IMAGE_GIF_LOOP ((gdispImageError)-2) -#define MAX_CODE_BITS 12 -#define CODE_MAX ((1<priv; // 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; // 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 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; decode->code_clear = 1 << decode->bitsperpixel; decode->code_eof = decode->code_clear + 1; decode->code_max = decode->code_clear + 2; - decode->code_last = CODE_NONE; + decode->code_last = GIF_CODE_NONE; decode->bitspercode = decode->bitsperpixel+1; decode->maxcodesz = 1 << decode->bitspercode; decode->shiftbits = 0; decode->shiftdata = 0; decode->stackcnt = 0; - for(cnt = 0; cnt <= CODE_MAX; cnt++) - decode->prefix[cnt] = CODE_NONE; + for(cnt = 0; cnt <= GIF_CODE_MAX; cnt++) + decode->prefix[cnt] = GIF_CODE_NONE; // All ready to go priv->decode = decode; return GDISP_IMAGE_ERR_OK; 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; } @@ -176,24 +176,24 @@ baddatacleanup: * * Pre: Frame info has been read. */ -static void stopDecode(gdispImage *img) { - gdispImagePrivate * priv; +static void stopDecodeGif(gdispImage *img) { + gdispImagePrivate_GIF * priv; priv = img->priv; // Free the decode data 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; } } -static uint16_t getPrefix(imgdecode *decode, uint16_t code) { +static uint16_t getPrefixGif(gifimgdecode *decode, uint16_t code) { uint16_t i; - for(i=0; code > decode->code_clear && i <= CODE_MAX; i++, code = decode->prefix[code]) { - if (code > CODE_MAX) - return CODE_NONE; + for(i=0; code > decode->code_clear && i <= GIF_CODE_MAX; i++, code = decode->prefix[code]) { + if (code > GIF_CODE_MAX) + return GIF_CODE_NONE; } return code; } @@ -203,16 +203,16 @@ static uint16_t getPrefix(imgdecode *decode, uint16_t code) { * * 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 */ -static uint16_t getbytes(gdispImage *img) { - gdispImagePrivate * priv; - imgdecode * decode; - uint16_t cnt; - uint16_t code, prefix; - uint8_t bdata; +static uint16_t getBytesGif(gdispImage *img) { + gdispImagePrivate_GIF * priv; + gifimgdecode * decode; + uint16_t cnt; + uint16_t code, prefix; + uint8_t bdata; priv = img->priv; decode = priv->decode; @@ -243,16 +243,16 @@ static uint16_t getbytes(gdispImage *img) { decode->shiftdata |= ((unsigned long)bdata) << decode->shiftbits; decode->shiftbits += 8; } - code = decode->shiftdata & BitMask[decode->bitspercode]; + code = decode->shiftdata & GifBitMask[decode->bitspercode]; decode->shiftdata >>= decode->bitspercode; decode->shiftbits -= decode->bitspercode; /** * If code cannot fit into bitspercode bits we must raise its size. - * Note that codes above CODE_MAX are used for special signaling. - * If we're using MAX_CODE_BITS bits already and we're at the max code, just + * Note that codes above GIF_CODE_MAX are used for special signaling. + * 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. */ - 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->bitspercode++; } @@ -271,12 +271,12 @@ static uint16_t getbytes(gdispImage *img) { if (code == decode->code_clear) { // Start again - for(prefix = 0; prefix <= CODE_MAX; prefix++) - decode->prefix[prefix] = CODE_NONE; + for(prefix = 0; prefix <= GIF_CODE_MAX; prefix++) + decode->prefix[prefix] = GIF_CODE_NONE; decode->code_max = decode->code_eof + 1; decode->bitspercode = decode->bitsperpixel + 1; decode->maxcodesz = 1 << decode->bitspercode; - decode->code_last = CODE_NONE; + decode->code_last = GIF_CODE_NONE; continue; } @@ -290,7 +290,7 @@ static uint16_t getbytes(gdispImage *img) { * valid pixel while pushing the suffix pixels on the stack. * 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; /** @@ -301,34 +301,34 @@ static uint16_t getbytes(gdispImage *img) { */ else if (code == decode->code_max - 2 && decode->stackcnt < sizeof(decode->stack)) { 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 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 * 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]; 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; /* Push the last character on stack: */ 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; /* Only allowed if code is exactly the running code: * In that case code = XXXCode, CrntCode or the * prefix code is last code and the suffix char is * 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; } @@ -340,11 +340,11 @@ static uint16_t getbytes(gdispImage *img) { * * Pre: The file position is at the start of the frame. */ -static gdispImageError initFrame(gdispImage *img) { - gdispImagePrivate * priv; - imgcache * cache; - uint8_t blocktype; - uint8_t blocksz; +static gdispImageError initFrameGif(gdispImage *img) { + gdispImagePrivate_GIF * priv; + gifimgcache * cache; + uint8_t blocktype; + uint8_t blocksz; priv = img->priv; @@ -482,16 +482,16 @@ static gdispImageError initFrame(gdispImage *img) { case 0x3B: //';' - TERMINATE_RECORD_TYPE; // Are we an looping animation if (!(priv->flags & GIF_LOOP)) - return GDISP_IMAGE_EOF; + return GDISP_IMAGE_GIF_EOF; if (!(priv->flags & GIF_LOOPFOREVER)) { if (!priv->loops) - return GDISP_IMAGE_EOF; + return GDISP_IMAGE_GIF_EOF; priv->loops--; } // Seek back to frame0 gfileSetPos(img->f, priv->frame0pos); - return GDISP_IMAGE_LOOP; + return GDISP_IMAGE_GIF_LOOP; default: // UNDEFINED_RECORD_TYPE; return GDISP_IMAGE_ERR_UNSUPPORTED; @@ -500,9 +500,9 @@ static gdispImageError initFrame(gdispImage *img) { } void gdispImageClose_GIF(gdispImage *img) { - gdispImagePrivate * priv; - imgcache * cache; - imgcache * ncache; + gdispImagePrivate_GIF * priv; + gifimgcache * cache; + gifimgcache * ncache; priv = img->priv; if (priv) { @@ -510,18 +510,18 @@ void gdispImageClose_GIF(gdispImage *img) { cache = priv->cache; while(cache) { 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; } if (priv->palette) 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; } } gdispImageError gdispImageOpen_GIF(gdispImage *img) { - gdispImagePrivate *priv; + gdispImagePrivate_GIF *priv; uint8_t hdr[6]; uint16_t aword; @@ -539,7 +539,7 @@ gdispImageError gdispImageOpen_GIF(gdispImage *img) { img->flags = 0; /* 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; /* Initialise the essential bits in the private area */ @@ -579,7 +579,7 @@ gdispImageError gdispImageOpen_GIF(gdispImage *img) { priv->frame0pos = gfileGetPos(img->f); // Read the first frame descriptor - switch(initFrame(img)) { + switch(initFrameGif(img)) { case GDISP_IMAGE_ERR_OK: // Everything OK img->type = GDISP_IMAGE_TYPE_GIF; return GDISP_IMAGE_ERR_OK; @@ -590,8 +590,8 @@ gdispImageError gdispImageOpen_GIF(gdispImage *img) { nomemcleanup: gdispImageClose_GIF(img); // Clean up the private data area return GDISP_IMAGE_ERR_NOMEMORY; - case GDISP_IMAGE_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_EOF: // 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 default: baddatacleanup: @@ -601,13 +601,13 @@ gdispImageError gdispImageOpen_GIF(gdispImage *img) { } gdispImageError gdispImageCache_GIF(gdispImage *img) { - gdispImagePrivate * priv; - imgcache * cache; - imgdecode * decode; - uint8_t * p; - uint8_t * q; - coord_t mx, my; - uint16_t cnt; + gdispImagePrivate_GIF * priv; + gifimgcache * cache; + gifimgdecode * decode; + uint8_t * p; + uint8_t * q; + coord_t mx, my; + uint16_t cnt; /* If we are already cached - just return OK */ priv = img->priv; @@ -615,7 +615,7 @@ gdispImageError gdispImageCache_GIF(gdispImage *img) { return GDISP_IMAGE_ERR_OK; /* 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; /* Initialise the cache */ @@ -625,7 +625,7 @@ gdispImageError gdispImageCache_GIF(gdispImage *img) { cache->next = 0; /* Start the decode */ - switch(startDecode(img)) { + switch(startDecodeGif(img)) { case GDISP_IMAGE_ERR_OK: break; case GDISP_IMAGE_ERR_NOMEMORY: goto nomemcleanup; 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(mx=0; mx < cache->frame.width; mx++) { if (!cnt) { - if (!(cnt = getbytes(img))) { + if (!(cnt = getBytesGif(img))) { // Sometimes the image EOF is a bit early - treat the rest as transparent if (decode->code_last != decode->code_eof) 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(mx=0; mx < cache->frame.width; mx++) { if (!cnt) { - if (!(cnt = getbytes(img))) { + if (!(cnt = getBytesGif(img))) { // Sometimes the image EOF is a bit early - treat the rest as transparent if (decode->code_last != decode->code_eof) 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(mx=0; mx < cache->frame.width; mx++) { if (!cnt) { - if (!(cnt = getbytes(img))) { + if (!(cnt = getBytesGif(img))) { // Sometimes the image EOF is a bit early - treat the rest as transparent if (decode->code_last != decode->code_eof) 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(mx=0; mx < cache->frame.width; mx++) { if (!cnt) { - if (!(cnt = getbytes(img))) { + if (!(cnt = getBytesGif(img))) { // Sometimes the image EOF is a bit early - treat the rest as transparent if (decode->code_last != decode->code_eof) goto baddatacleanup; @@ -721,7 +721,7 @@ gdispImageError gdispImageCache_GIF(gdispImage *img) { for(my=0; my < cache->frame.height; my++) { for(mx=0; mx < cache->frame.width; mx++) { if (!cnt) { - if (!(cnt = getbytes(img))) { + if (!(cnt = getBytesGif(img))) { // Sometimes the image EOF is a bit early - treat the rest as transparent if (decode->code_last != decode->code_eof) goto baddatacleanup; @@ -736,7 +736,7 @@ gdispImageError gdispImageCache_GIF(gdispImage *img) { } } // 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); // Save everything @@ -747,7 +747,7 @@ gdispImageError gdispImageCache_GIF(gdispImage *img) { cache->next = priv->cache; priv->cache = cache; } else { - imgcache *pc; + gifimgcache *pc; for(pc = priv->cache; pc; pc = pc->next) { 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; nomemcleanup: - stopDecode(img); - gdispImageFree(img, cache, sizeof(imgcache) + priv->frame.palsize*sizeof(color_t) + priv->frame.width*priv->frame.height); + stopDecodeGif(img); + gdispImageFree(img, cache, sizeof(gifimgcache) + priv->frame.palsize*sizeof(color_t) + priv->frame.width*priv->frame.height); return GDISP_IMAGE_ERR_NOMEMORY; baddatacleanup: - stopDecode(img); - gdispImageFree(img, cache, sizeof(imgcache) + priv->frame.palsize*sizeof(color_t) + priv->frame.width*priv->frame.height); + stopDecodeGif(img); + gdispImageFree(img, cache, sizeof(gifimgcache) + priv->frame.palsize*sizeof(color_t) + priv->frame.width*priv->frame.height); 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) { - gdispImagePrivate * priv; - imgdecode * decode; - uint8_t * q = 0; - coord_t mx, my, fx, fy; - uint16_t cnt, gcnt; - uint8_t col; + gdispImagePrivate_GIF * priv; + gifimgdecode * decode; + uint8_t * q = 0; + coord_t mx, my, fx, fy; + uint16_t cnt, gcnt; + uint8_t col; 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 */ if (priv->curcache) { - imgcache * cache; + gifimgcache * cache; cache = priv->curcache; q = cache->imagebits+priv->frame.width*sy+sx; @@ -838,7 +838,7 @@ gdispImageError gdispGImageDraw_GIF(GDisplay *g, gdispImage *img, coord_t x, coo continue; } 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 gdispGBlitArea(g, x+mx-sx-gcnt+1, y+my-sy, gcnt, 1, 0, 0, gcnt, priv->buf); gcnt = 0; @@ -856,7 +856,7 @@ gdispImageError gdispGImageDraw_GIF(GDisplay *g, gdispImage *img, coord_t x, coo } /* Start the decode */ - switch(startDecode(img)) { + switch(startDecodeGif(img)) { case GDISP_IMAGE_ERR_OK: break; case GDISP_IMAGE_ERR_NOMEMORY: return GDISP_IMAGE_ERR_NOMEMORY; 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(gcnt=0, mx=0; mx < priv->frame.width; mx++, q++, cnt--) { if (!cnt) { - if (!(cnt = getbytes(img))) { + if (!(cnt = getBytesGif(img))) { // Sometimes the image EOF is a bit early - treat the rest as transparent if (decode->code_last != decode->code_eof) goto baddatacleanup; @@ -892,7 +892,7 @@ gdispImageError gdispGImageDraw_GIF(GDisplay *g, gdispImage *img, coord_t x, coo continue; } 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 gdispGBlitArea(g, x+mx-sx-gcnt+1, y+my-sy, gcnt, 1, 0, 0, gcnt, priv->buf); 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(gcnt=0, mx=0; mx < priv->frame.width; mx++, q++, cnt--) { if (!cnt) { - if (!(cnt = getbytes(img))) { + if (!(cnt = getBytesGif(img))) { // Sometimes the image EOF is a bit early - treat the rest as transparent if (decode->code_last != decode->code_eof) goto baddatacleanup; @@ -938,7 +938,7 @@ gdispImageError gdispGImageDraw_GIF(GDisplay *g, gdispImage *img, coord_t x, coo continue; } 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 gdispGBlitArea(g, x+mx-sx-gcnt+1, y+my-sy, gcnt, 1, 0, 0, gcnt, priv->buf); 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(gcnt=0, mx=0; mx < priv->frame.width; mx++, q++, cnt--) { if (!cnt) { - if (!(cnt = getbytes(img))) { + if (!(cnt = getBytesGif(img))) { // Sometimes the image EOF is a bit early - treat the rest as transparent if (decode->code_last != decode->code_eof) goto baddatacleanup; @@ -984,7 +984,7 @@ gdispImageError gdispGImageDraw_GIF(GDisplay *g, gdispImage *img, coord_t x, coo continue; } 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 gdispGBlitArea(g, x+mx-sx-gcnt+1, y+my-sy, gcnt, 1, 0, 0, gcnt, priv->buf); 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(gcnt=0, mx=0; mx < priv->frame.width; mx++, q++, cnt--) { if (!cnt) { - if (!(cnt = getbytes(img))) { + if (!(cnt = getBytesGif(img))) { // Sometimes the image EOF is a bit early - treat the rest as transparent if (decode->code_last != decode->code_eof) goto baddatacleanup; @@ -1030,7 +1030,7 @@ gdispImageError gdispGImageDraw_GIF(GDisplay *g, gdispImage *img, coord_t x, coo continue; } 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 gdispGBlitArea(g, x+mx-sx-gcnt+1, y+my-sy, gcnt, 1, 0, 0, gcnt, priv->buf); 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(gcnt=0, mx=0; mx < priv->frame.width; mx++, q++, cnt--) { if (!cnt) { - if (!(cnt = getbytes(img))) { + if (!(cnt = getBytesGif(img))) { // Sometimes the image EOF is a bit early - treat the rest as transparent if (decode->code_last != decode->code_eof) goto baddatacleanup; @@ -1077,7 +1077,7 @@ gdispImageError gdispGImageDraw_GIF(GDisplay *g, gdispImage *img, coord_t x, coo continue; } 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 gdispGBlitArea(g, x+mx-sx-gcnt+1, y+my-sy, gcnt, 1, 0, 0, gcnt, priv->buf); 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 - while (getbytes(img)); + while (getBytesGif(img)); priv->frame.posend = gfileGetPos(img->f); - stopDecode(img); + stopDecodeGif(img); return GDISP_IMAGE_ERR_OK; baddatacleanup: - stopDecode(img); + stopDecodeGif(img); return GDISP_IMAGE_ERR_BADDATA; } delaytime_t gdispImageNext_GIF(gdispImage *img) { - gdispImagePrivate * priv; - delaytime_t delay; - uint8_t blocksz; + gdispImagePrivate_GIF * priv; + delaytime_t delay; + uint8_t blocksz; priv = img->priv; @@ -1140,12 +1140,12 @@ delaytime_t gdispImageNext_GIF(gdispImage *img) { // Read the next frame descriptor 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 return delay; - case GDISP_IMAGE_LOOP: // Back to the beginning + case GDISP_IMAGE_GIF_LOOP: // Back to the beginning 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_NOMEMORY: // Out of Memory case GDISP_IMAGE_ERR_UNSUPPORTED: // Unsupported diff --git a/src/gdisp/gdisp_image_native.c b/src/gdisp/gdisp_image_native.c index 9ed0f664..df7c9f72 100644 --- a/src/gdisp/gdisp_image_native.c +++ b/src/gdisp/gdisp_image_native.c @@ -15,10 +15,10 @@ * How big a pixel array to allocate for blitting * Bigger is faster but uses more RAM. */ -#define BLIT_BUFFER_SIZE 32 +#define BLIT_BUFFER_SIZE_NATIVE 32 -#define HEADER_SIZE 8 -#define FRAME0POS (HEADER_SIZE) +#define HEADER_SIZE_NATIVE 8 +#define FRAME0POS_NATIVE (HEADER_SIZE_NATIVE) /** * Helper Routines Needed @@ -28,7 +28,7 @@ void gdispImageFree(gdispImage *img, void *ptr, size_t sz); typedef struct gdispImagePrivate { pixel_t *frame0cache; - pixel_t buf[BLIT_BUFFER_SIZE]; + pixel_t buf[BLIT_BUFFER_SIZE_NATIVE]; } gdispImagePrivate; void gdispImageClose_NATIVE(gdispImage *img) { @@ -41,7 +41,7 @@ void gdispImageClose_NATIVE(gdispImage *img) { } gdispImageError gdispImageOpen_NATIVE(gdispImage *img) { - uint8_t hdr[HEADER_SIZE]; + uint8_t hdr[HEADER_SIZE_NATIVE]; /* Read the 8 byte header */ if (gfileRead(img->f, hdr, 8) != 8) @@ -81,7 +81,7 @@ gdispImageError gdispImageCache_NATIVE(gdispImage *img) { return GDISP_IMAGE_ERR_NOMEMORY; /* Read the entire bitmap into cache */ - gfileSetPos(img->f, FRAME0POS); + gfileSetPos(img->f, FRAME0POS_NATIVE); if (gfileRead(img->f, img->priv->frame0cache, len) != len) 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 */ - pos = FRAME0POS + (img->width * sy + sx) * sizeof(pixel_t); + pos = FRAME0POS_NATIVE + (img->width * sy + sx) * sizeof(pixel_t); /* Cycle through the lines */ for(;cy;cy--, y++) { @@ -116,7 +116,7 @@ gdispImageError gdispGImageDraw_NATIVE(GDisplay *g, gdispImage *img, coord_t x, // Read the data len = gfileRead(img->f, 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); if (!len) return GDISP_IMAGE_ERR_BADDATA;