diff options
author | inmarket <andrewh@inmarket.com.au> | 2015-11-25 12:25:04 +1000 |
---|---|---|
committer | inmarket <andrewh@inmarket.com.au> | 2015-11-25 12:25:04 +1000 |
commit | fb7e7c6ea7a8bd8501805a24d76e58ee617cdbe3 (patch) | |
tree | 9fb8e947794351597fa31b9af43fb197544917b0 /src/gdisp/gdisp_image_native.c | |
parent | 205160aec0bace67836ee70e5bdaa85f4d7f10d5 (diff) | |
download | uGFX-fb7e7c6ea7a8bd8501805a24d76e58ee617cdbe3.tar.gz uGFX-fb7e7c6ea7a8bd8501805a24d76e58ee617cdbe3.tar.bz2 uGFX-fb7e7c6ea7a8bd8501805a24d76e58ee617cdbe3.zip |
Fix compiler errors and warnings on image handling with multiple image formats turned on.
Diffstat (limited to 'src/gdisp/gdisp_image_native.c')
-rw-r--r-- | src/gdisp/gdisp_image_native.c | 40 |
1 files changed, 24 insertions, 16 deletions
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 */ |