diff options
Diffstat (limited to 'src/gdisp')
-rw-r--r-- | src/gdisp/gdisp_image_bmp.c | 40 | ||||
-rw-r--r-- | src/gdisp/gdisp_image_gif.c | 290 | ||||
-rw-r--r-- | src/gdisp/gdisp_image_native.c | 16 |
3 files changed, 173 insertions, 173 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<<MAX_CODE_BITS)-1) // Maximum legal code value -#define CODE_FLUSH (CODE_MAX+1) // Illegal code to signal flush -#define CODE_FIRST (CODE_MAX+2) // Illegal code to signal first -#define CODE_NONE (CODE_MAX+3) // Illegal code to signal empty +#define GIF_MAX_CODE_BITS 12 +#define GIF_CODE_MAX ((1<<GIF_MAX_CODE_BITS)-1) // Maximum legal code value +#define GIF_CODE_FLUSH (GIF_CODE_MAX+1) // Illegal code to signal flush +#define GIF_CODE_FIRST (GIF_CODE_MAX+2) // Illegal code to signal first +#define GIF_CODE_NONE (GIF_CODE_MAX+3) // Illegal code to signal empty // Convert bits to masks for that number of bits -static const uint16_t BitMask[] = { +static const uint16_t GifBitMask[] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff, 0x01ff, 0x03ff, 0x07ff, @@ -36,7 +36,7 @@ static const uint16_t BitMask[] = { }; // 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 maxpixel; // The maximum allowed pixel value uint8_t bitsperpixel; @@ -50,14 +50,14 @@ typedef struct imgdecode { uint16_t code_last; uint32_t shiftdata; color_t * palette; - uint8_t buf[BLIT_BUFFER_SIZE]; // Buffer for decoded pixels - uint16_t prefix[1<<MAX_CODE_BITS]; // The LZW table - uint8_t suffix[1<<MAX_CODE_BITS]; // So we can trace the codes - uint8_t stack[1<<MAX_CODE_BITS]; // Decoded pixels might be stacked here -} imgdecode; + uint8_t buf[BLIT_BUFFER_SIZE_GIF]; // Buffer for decoded pixels + uint16_t prefix[1<<GIF_MAX_CODE_BITS]; // The LZW table + uint8_t suffix[1<<GIF_MAX_CODE_BITS]; // So we can trace the codes + uint8_t stack[1<<GIF_MAX_CODE_BITS]; // Decoded pixels might be stacked here +} gifimgdecode; // The data on a single frame -typedef struct imgframe { +typedef struct gifimgframe { coord_t x, y; // position relative to full image coord_t width, height; // size of frame uint16_t delay; // delay after processing @@ -72,55 +72,55 @@ typedef struct imgframe { size_t pospal; // The file position of the palette size_t posimg; // The file position of the image bits size_t posend; // The file position of the end of the frame -} imgframe; +} gifimgframe; // The data for a cache -typedef struct imgcache { - imgframe frame; +typedef struct gifimgcache { + gifimgframe frame; color_t * palette; // Local palette uint8_t * imagebits; // Image bits - only saved when caching - struct imgcache * next; // Next cached frame -} imgcache; + struct gifimgcache *next; // Next cached frame +} gifimgcache; // The data for a dispose area -typedef struct imgdispose { +typedef struct gifimgdispose { uint8_t flags; // Frame flags uint8_t paltrans; // Transparency coord_t x, y; // position relative to full image coord_t width, height; // size of dispose area -} imgdispose; - -typedef struct gdispImagePrivate { - uint8_t flags; // Flags (global) - #define GIF_LOOP 0x01 // Loop back to first frame - #define GIF_LOOPFOREVER 0x02 // Looping is forever - uint8_t bgcolor; // Background Color (global) - uint16_t loops; // Remaining frame loops (if animated) - uint16_t palsize; // Global palette size (global) - pixel_t *palette; // Global palette (global) - size_t frame0pos; // The position of the first frame - imgcache * cache; // The list of cached frames - imgcache * curcache; // The cache of the current frame (if created) - imgdecode * decode; // The decode data for the decode in progress - imgframe frame; - imgdispose dispose; - pixel_t buf[BLIT_BUFFER_SIZE]; // Buffer for reading and blitting - } gdispImagePrivate; +} gifimgdispose; + +typedef struct gdispImagePrivate_GIF { + uint8_t flags; // Flags (global) + #define GIF_LOOP 0x01 // Loop back to first frame + #define GIF_LOOPFOREVER 0x02 // Looping is forever + uint8_t bgcolor; // Background Color (global) + uint16_t loops; // Remaining frame loops (if animated) + uint16_t palsize; // Global palette size (global) + pixel_t *palette; // Global palette (global) + size_t frame0pos; // The position of the first frame + gifimgcache * cache; // The list of cached frames + gifimgcache * curcache; // The cache of the current frame (if created) + gifimgdecode * decode; // The decode data for the decode in progress + gifimgframe frame; + gifimgdispose dispose; + pixel_t buf[BLIT_BUFFER_SIZE_GIF]; // Buffer for reading and blitting + } gdispImagePrivate_GIF; /** * Get ready for decoding a frame. * * Pre: Frame info has been read. */ -static gdispImageError startDecode(gdispImage *img) { - gdispImagePrivate * priv; - imgdecode * decode; - uint16_t cnt; +static gdispImageError startDecodeGif(gdispImage *img) { + gdispImagePrivate_GIF * priv; + gifimgdecode * decode; + uint16_t cnt; priv = img->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; |