diff options
author | Joel Bodenmann <joel@seriouslyembedded.com> | 2015-11-27 20:39:28 +0100 |
---|---|---|
committer | Joel Bodenmann <joel@seriouslyembedded.com> | 2015-11-27 20:39:28 +0100 |
commit | 5a99092b794373966e444296c57991631e712c70 (patch) | |
tree | 3e2853ab9730ece7398f508238ac2707e485b346 /src/gdisp | |
parent | eaf0b19fb8428b9e2e47798294d6ba83a56d186e (diff) | |
parent | f16ee702727a811288749a0722ddb138dd559fa8 (diff) | |
download | uGFX-5a99092b794373966e444296c57991631e712c70.tar.gz uGFX-5a99092b794373966e444296c57991631e712c70.tar.bz2 uGFX-5a99092b794373966e444296c57991631e712c70.zip |
Merge branch 'master' of https://bitbucket.org/Tectu/ugfx
Diffstat (limited to 'src/gdisp')
-rw-r--r-- | src/gdisp/gdisp_image.h | 2 | ||||
-rw-r--r-- | src/gdisp/gdisp_image_bmp.c | 33 | ||||
-rw-r--r-- | src/gdisp/gdisp_image_gif.c | 22 | ||||
-rw-r--r-- | src/gdisp/gdisp_image_native.c | 40 |
4 files changed, 55 insertions, 42 deletions
diff --git a/src/gdisp/gdisp_image.h b/src/gdisp/gdisp_image.h index 4613bea7..2b6fdf19 100644 --- a/src/gdisp/gdisp_image.h +++ b/src/gdisp/gdisp_image.h @@ -66,7 +66,7 @@ typedef struct gdispImage { uint32_t maxmemused; /* @< How much RAM has been allocated (maximum) */ #endif const struct gdispImageHandlers * fns; /* @< Don't mess with this! */ - struct gdispImagePrivate * priv; /* @< Don't mess with this! */ + void * priv; /* @< Don't mess with this! */ } gdispImage; #ifdef __cplusplus diff --git a/src/gdisp/gdisp_image_bmp.c b/src/gdisp/gdisp_image_bmp.c index 73549ae3..371fdf2d 100644 --- a/src/gdisp/gdisp_image_bmp.c +++ b/src/gdisp/gdisp_image_bmp.c @@ -53,14 +53,17 @@ typedef struct gdispImagePrivate_BMP { } gdispImagePrivate_BMP; void gdispImageClose_BMP(gdispImage *img) { - if (img->priv) { + gdispImagePrivate_BMP *priv; + + priv = (gdispImagePrivate_BMP *)img->priv; + if (priv) { #if GDISP_NEED_IMAGE_BMP_1 || GDISP_NEED_IMAGE_BMP_4 || GDISP_NEED_IMAGE_BMP_4_RLE || GDISP_NEED_IMAGE_BMP_8 || GDISP_NEED_IMAGE_BMP_8_RLE - if (img->priv->palette) - gdispImageFree(img, (void *)img->priv->palette, img->priv->palsize*sizeof(color_t)); + if (priv->palette) + gdispImageFree(img, (void *)priv->palette, priv->palsize*sizeof(color_t)); #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_BMP)); + if (priv->frame0cache) + gdispImageFree(img, (void *)priv->frame0cache, img->width*img->height*sizeof(pixel_t)); + gdispImageFree(img, (void *)priv, sizeof(gdispImagePrivate_BMP)); img->priv = 0; } } @@ -89,11 +92,11 @@ gdispImageError gdispImageOpen_BMP(gdispImage *img) { img->flags = 0; /* Allocate our private area */ - if (!(img->priv = (gdispImagePrivate_BMP *)gdispImageAlloc(img, sizeof(gdispImagePrivate_BMP)))) + if (!(img->priv = gdispImageAlloc(img, sizeof(gdispImagePrivate_BMP)))) return GDISP_IMAGE_ERR_NOMEMORY; /* Initialise the essential bits in the private area */ - priv = img->priv; + priv = (gdispImagePrivate_BMP *)img->priv; priv->frame0cache = 0; priv->bmpflags = 0; #if GDISP_NEED_IMAGE_BMP_1 || GDISP_NEED_IMAGE_BMP_4 || GDISP_NEED_IMAGE_BMP_4_RLE || GDISP_NEED_IMAGE_BMP_8 || GDISP_NEED_IMAGE_BMP_8_RLE @@ -119,7 +122,7 @@ gdispImageError gdispImageOpen_BMP(gdispImage *img) { // Detect our bitmap version if (offsetColorTable == 12+14) { - img->priv->bmpflags |= BMP_V2; + priv->bmpflags |= BMP_V2; // Read the header if (gfileRead(img->f, priv->buf, 12-4) != 12-4) @@ -129,7 +132,7 @@ gdispImageError gdispImageOpen_BMP(gdispImage *img) { // Get the height img->height = gdispImageGetAlignedLE16(priv->buf, 2); if (img->height < 0) { - img->priv->bmpflags |= BMP_TOP_TO_BOTTOM; + priv->bmpflags |= BMP_TOP_TO_BOTTOM; img->height = -img->height; } // Get the planes @@ -361,7 +364,7 @@ static coord_t getPixels(gdispImage *img, coord_t x) { color_t * pc; coord_t len; - priv = img->priv; + priv = (gdispImagePrivate_BMP *)img->priv; pc = priv->buf; len = 0; @@ -372,7 +375,7 @@ static coord_t getPixels(gdispImage *img, coord_t x) { uint8_t b[4]; uint8_t m; - priv = img->priv; + priv = (gdispImagePrivate_BMP *)img->priv; pc = priv->buf; len = 0; @@ -703,7 +706,7 @@ gdispImageError gdispImageCache_BMP(gdispImage *img) { size_t len; /* If we are already cached - just return OK */ - priv = img->priv; + priv = (gdispImagePrivate_BMP *)img->priv; if (priv->frame0cache) return GDISP_IMAGE_ERR_OK; @@ -720,6 +723,8 @@ gdispImageError gdispImageCache_BMP(gdispImage *img) { priv->rlecode = 0; #endif + pcs = priv->buf; // This line is just to prevent a compiler warning. + if (priv->bmpflags & BMP_TOP_TO_BOTTOM) { for(y = 0, pcd = priv->frame0cache; y < img->height; y++) { x = 0; pos = 0; @@ -756,7 +761,7 @@ gdispImageError gdispGImageDraw_BMP(GDisplay *g, gdispImage *img, coord_t x, coo coord_t mx, my; coord_t pos, len, st; - priv = img->priv; + priv = (gdispImagePrivate_BMP *)img->priv; /* Check some reasonableness */ if (sx >= img->width || sy >= img->height) return GDISP_IMAGE_ERR_OK; diff --git a/src/gdisp/gdisp_image_gif.c b/src/gdisp/gdisp_image_gif.c index f3e9d8dd..5a3f68c6 100644 --- a/src/gdisp/gdisp_image_gif.c +++ b/src/gdisp/gdisp_image_gif.c @@ -117,7 +117,7 @@ static gdispImageError startDecodeGif(gdispImage *img) { gifimgdecode * decode; uint16_t cnt; - priv = img->priv; + priv = (gdispImagePrivate_GIF *)img->priv; // We need the decode ram, and possibly a palette if (!(decode = (gifimgdecode *)gdispImageAlloc(img, sizeof(gifimgdecode)+priv->frame.palsize*sizeof(color_t)))) @@ -179,7 +179,7 @@ baddatacleanup: static void stopDecodeGif(gdispImage *img) { gdispImagePrivate_GIF * priv; - priv = img->priv; + priv = (gdispImagePrivate_GIF *)img->priv; // Free the decode data if (priv->decode) { @@ -214,7 +214,7 @@ static uint16_t getBytesGif(gdispImage *img) { uint16_t code, prefix; uint8_t bdata; - priv = img->priv; + priv = (gdispImagePrivate_GIF *)img->priv; decode = priv->decode; cnt = 0; @@ -346,7 +346,7 @@ static gdispImageError initFrameGif(gdispImage *img) { uint8_t blocktype; uint8_t blocksz; - priv = img->priv; + priv = (gdispImagePrivate_GIF *)img->priv; // Save the dispose info from the existing frame priv->dispose.flags = priv->frame.flags; @@ -504,7 +504,7 @@ void gdispImageClose_GIF(gdispImage *img) { gifimgcache * cache; gifimgcache * ncache; - priv = img->priv; + priv = (gdispImagePrivate_GIF *)img->priv; if (priv) { // Free any stored frames cache = priv->cache; @@ -515,7 +515,7 @@ void gdispImageClose_GIF(gdispImage *img) { } if (priv->palette) gdispImageFree(img, (void *)priv->palette, priv->palsize*sizeof(color_t)); - gdispImageFree(img, (void *)img->priv, sizeof(gdispImagePrivate_GIF)); + gdispImageFree(img, (void *)priv, sizeof(gdispImagePrivate_GIF)); img->priv = 0; } } @@ -539,11 +539,11 @@ gdispImageError gdispImageOpen_GIF(gdispImage *img) { img->flags = 0; /* Allocate our private area */ - if (!(img->priv = (gdispImagePrivate_GIF *)gdispImageAlloc(img, sizeof(gdispImagePrivate_GIF)))) + if (!(img->priv = gdispImageAlloc(img, sizeof(gdispImagePrivate_GIF)))) return GDISP_IMAGE_ERR_NOMEMORY; /* Initialise the essential bits in the private area */ - priv = img->priv; + priv = (gdispImagePrivate_GIF *)img->priv; priv->flags = 0; priv->palsize = 0; priv->palette = 0; @@ -610,7 +610,7 @@ gdispImageError gdispImageCache_GIF(gdispImage *img) { uint16_t cnt; /* If we are already cached - just return OK */ - priv = img->priv; + priv = (gdispImagePrivate_GIF *)img->priv; if (priv->curcache) return GDISP_IMAGE_ERR_OK; @@ -779,7 +779,7 @@ gdispImageError gdispGImageDraw_GIF(GDisplay *g, gdispImage *img, coord_t x, coo uint16_t cnt, gcnt; uint8_t col; - priv = img->priv; + priv = (gdispImagePrivate_GIF *)img->priv; /* Handle previous frame disposing */ if (priv->dispose.flags & (GIFL_DISPOSECLEAR|GIFL_DISPOSEREST)) { @@ -1116,7 +1116,7 @@ delaytime_t gdispImageNext_GIF(gdispImage *img) { delaytime_t delay; uint8_t blocksz; - priv = img->priv; + priv = (gdispImagePrivate_GIF *)img->priv; // Save the delay and convert to millisecs delay = (delaytime_t)priv->frame.delay * 10; diff --git a/src/gdisp/gdisp_image_native.c b/src/gdisp/gdisp_image_native.c index df7c9f72..28706564 100644 --- a/src/gdisp/gdisp_image_native.c +++ b/src/gdisp/gdisp_image_native.c @@ -26,16 +26,19 @@ void *gdispImageAlloc(gdispImage *img, size_t sz); void gdispImageFree(gdispImage *img, void *ptr, size_t sz); -typedef struct gdispImagePrivate { +typedef struct gdispImagePrivate_NATIVE { pixel_t *frame0cache; pixel_t buf[BLIT_BUFFER_SIZE_NATIVE]; - } gdispImagePrivate; + } gdispImagePrivate_NATIVE; void gdispImageClose_NATIVE(gdispImage *img) { - if (img->priv) { - if (img->priv->frame0cache) - gdispImageFree(img, (void *)img->priv->frame0cache, img->width * img->height * sizeof(pixel_t)); - gdispImageFree(img, (void *)img->priv, sizeof(gdispImagePrivate)); + gdispImagePrivate_NATIVE * priv; + + priv = (gdispImagePrivate_NATIVE *)img->priv; + if (priv) { + if (priv->frame0cache) + gdispImageFree(img, (void *)priv->frame0cache, img->width * img->height * sizeof(pixel_t)); + gdispImageFree(img, (void *)priv, sizeof(gdispImagePrivate_NATIVE)); img->priv = 0; } } @@ -59,9 +62,9 @@ gdispImageError gdispImageOpen_NATIVE(gdispImage *img) { img->height = (((uint16_t)hdr[4])<<8) | (hdr[5]); if (img->width < 1 || img->height < 1) return GDISP_IMAGE_ERR_BADDATA; - if (!(img->priv = (gdispImagePrivate *)gdispImageAlloc(img, sizeof(gdispImagePrivate)))) + if (!(img->priv = gdispImageAlloc(img, sizeof(gdispImagePrivate_NATIVE)))) return GDISP_IMAGE_ERR_NOMEMORY; - img->priv->frame0cache = 0; + ((gdispImagePrivate_NATIVE *)(img->priv))->frame0cache = 0; img->type = GDISP_IMAGE_TYPE_NATIVE; return GDISP_IMAGE_ERR_OK; @@ -69,20 +72,22 @@ gdispImageError gdispImageOpen_NATIVE(gdispImage *img) { gdispImageError gdispImageCache_NATIVE(gdispImage *img) { size_t len; + gdispImagePrivate_NATIVE * priv; /* If we are already cached - just return OK */ - if (img->priv->frame0cache) + priv = (gdispImagePrivate_NATIVE *)img->priv; + if (priv->frame0cache) return GDISP_IMAGE_ERR_OK; /* We need to allocate the cache */ len = img->width * img->height * sizeof(pixel_t); - img->priv->frame0cache = (pixel_t *)gdispImageAlloc(img, len); - if (!img->priv->frame0cache) + priv->frame0cache = (pixel_t *)gdispImageAlloc(img, len); + if (!priv->frame0cache) return GDISP_IMAGE_ERR_NOMEMORY; /* Read the entire bitmap into cache */ gfileSetPos(img->f, FRAME0POS_NATIVE); - if (gfileRead(img->f, img->priv->frame0cache, len) != len) + if (gfileRead(img->f, priv->frame0cache, len) != len) return GDISP_IMAGE_ERR_BADDATA; return GDISP_IMAGE_ERR_OK; @@ -91,6 +96,9 @@ gdispImageError gdispImageCache_NATIVE(gdispImage *img) { gdispImageError gdispGImageDraw_NATIVE(GDisplay *g, gdispImage *img, coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t sx, coord_t sy) { coord_t mx, mcx; size_t pos, len; + gdispImagePrivate_NATIVE * priv; + + priv = (gdispImagePrivate_NATIVE *)img->priv; /* Check some reasonableness */ if (sx >= img->width || sy >= img->height) return GDISP_IMAGE_ERR_OK; @@ -98,8 +106,8 @@ gdispImageError gdispGImageDraw_NATIVE(GDisplay *g, gdispImage *img, coord_t x, if (sy + cy > img->height) cy = img->height - sy; /* Draw from the image cache - if it exists */ - if (img->priv->frame0cache) { - gdispGBlitArea(g, x, y, cx, cy, sx, sy, img->width, img->priv->frame0cache); + if (priv->frame0cache) { + gdispGBlitArea(g, x, y, cx, cy, sx, sy, img->width, priv->frame0cache); return GDISP_IMAGE_ERR_OK; } @@ -115,14 +123,14 @@ gdispImageError gdispGImageDraw_NATIVE(GDisplay *g, gdispImage *img, coord_t x, for(mx = x, mcx = cx; mcx > 0; mcx -= len, mx += len) { // Read the data len = gfileRead(img->f, - img->priv->buf, + priv->buf, 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; /* Blit the chunk of data */ - gdispGBlitArea(g, mx, y, len, 1, 0, 0, len, img->priv->buf); + gdispGBlitArea(g, mx, y, len, 1, 0, 0, len, priv->buf); } /* Get the position for the start of the next line */ |