From 5db053b506f785b215563925185d5a7fe5072b3b Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 17 Feb 2015 03:45:32 +0100 Subject: [PATCH] (MPNG) Build fixes --- libretro-sdk/formats/mpng/mpng_decode.c | 129 ++++++++++++++---------- 1 file changed, 73 insertions(+), 56 deletions(-) diff --git a/libretro-sdk/formats/mpng/mpng_decode.c b/libretro-sdk/formats/mpng/mpng_decode.c index 5599fcc869..495e8c191c 100644 --- a/libretro-sdk/formats/mpng/mpng_decode.c +++ b/libretro-sdk/formats/mpng/mpng_decode.c @@ -1,6 +1,7 @@ #include #include #include +#include #ifdef WANT_MINIZ #define MINIZ_HEADER_FILE_ONLY @@ -31,10 +32,10 @@ enum mpng_chunk_type MPNG_CHUNK_IDAT = 0x49444154, MPNG_CHUNK_PLTE = 0x504c5445, MPNG_CHUNK_IEND = 0x49454e44, -} +}; bool png_decode(const void *userdata, size_t len, - struct image *img, videoformat format) + struct mpng_image *img, enum video_format format) { /* chop off some warnings... these are all initialized in IHDR */ unsigned int depth; @@ -56,12 +57,12 @@ bool png_decode(const void *userdata, size_t len, if (!data) return false; - memset(img, 0, sizeof(struct image)); + memset(img, 0, sizeof(struct mpng_image)); /* Only works for RGB888, XRGB8888, and ARGB8888 */ - if (format != fmt_rgb888 - && format != fmt_xrgb8888 - && format != fmt_argb8888) + if (format != FMT_RGB888 + && format != FMT_XRGB8888 + && format != FMT_ARGB8888) return false; if (len < 8) @@ -147,7 +148,7 @@ bool png_decode(const void *userdata, size_t len, if (color_type == 6 && depth != 8) goto error; /* truecolor with alpha */ - if (color_type == 6 && format != fmt_argb8888) + if (color_type == 6 && format != FMT_ARGB8888) goto error; /* can only decode alpha on ARGB formats */ if (compression != 0) @@ -199,7 +200,7 @@ bool png_decode(const void *userdata, size_t len, break; case MPNG_CHUNK_TRNS: { - if (format != fmt_argb8888 || !pixels || pixels != pixelsat) + if (format != FMT_ARGB8888 || !pixels || pixels != pixelsat) goto error; if (color_type == 2) @@ -218,6 +219,9 @@ bool png_decode(const void *userdata, size_t len, { size_t byteshere; size_t chunklen_copy; +#ifdef WANT_MINIZ + tinfl_status status; +#endif if (!pixels || (color_type == 3 && palette_len == 0)) goto error; @@ -226,7 +230,7 @@ bool png_decode(const void *userdata, size_t len, byteshere = (pixelsend - pixelsat)+1; #ifdef WANT_MINIZ - tinfl_status status = tinfl_decompress(&inflator, + status = tinfl_decompress(&inflator, (const mz_uint8 *)chunkdata, &chunklen_copy, pixels, pixelsat, @@ -238,12 +242,15 @@ bool png_decode(const void *userdata, size_t len, pixelsat += byteshere; +#ifdef WANT_MINIZ if (status < TINFL_STATUS_DONE) goto error; +#endif } break; case MPNG_CHUNK_IEND: { + unsigned b, x, y; #ifdef WANT_MINIZ tinfl_status status; #endif @@ -266,11 +273,13 @@ bool png_decode(const void *userdata, size_t len, pixelsat += finalbytes; +#ifdef WANT_MINIZ if (status < TINFL_STATUS_DONE) goto error; if (status > TINFL_STATUS_DONE) goto error; +#endif if (pixelsat != pixelsend) goto error; /* too little data (can't be too much because we didn't give it that buffer size) */ @@ -282,6 +291,7 @@ bool png_decode(const void *userdata, size_t len, //run filters unsigned int bpppacked = ((color_type == 2) ? 3 : (color_type == 6) ? 4 : 1); uint8_t * prevout = out + (4 * width * 1); + if (height==1) { /* This will blow up if a 1px high image is filtered with Paeth, but highly unlikely. */ @@ -293,7 +303,7 @@ bool png_decode(const void *userdata, size_t len, filteredline = pixels; - for (unsigned int y = 0; y < height; y++) + for (y = 0; y < height; y++) { uint8_t * thisout=out+(bpl*y); @@ -305,21 +315,21 @@ bool png_decode(const void *userdata, size_t len, case 1: memcpy(thisout, filteredline, bpppacked); - for (unsigned int x=bpppacked;x>b)&1]; - *(--outp)=rgb32>>0; - *(--outp)=rgb32>>8; - *(--outp)=rgb32>>16; + int rgb32 = palette[((*inp)>>b)&1]; + *(--outp) = rgb32 >> 0; + *(--outp) = rgb32 >> 8; + *(--outp) = rgb32 >> 16; } } while(x); y--; @@ -422,10 +439,10 @@ bool png_decode(const void *userdata, size_t len, inp--; for (b = 0;b < 8; b += 2) { - int rgb32=palette[((*inp)>>b)&3]; - *(--outp)=rgb32>>0; - *(--outp)=rgb32>>8; - *(--outp)=rgb32>>16; + int rgb32 = palette[((*inp)>>b)&3]; + *(--outp) = rgb32 >> 0; + *(--outp) = rgb32 >> 8; + *(--outp) = rgb32 >> 16; } } while(x); y--; @@ -470,8 +487,8 @@ bool png_decode(const void *userdata, size_t len, { int rgb32; i--; - inp-=1; - rgb32 = palette[*inp]; + inp -= 1; + rgb32 = palette[*inp]; *(--outp) = rgb32 >> 0; *(--outp) = rgb32 >> 8; @@ -483,7 +500,7 @@ bool png_decode(const void *userdata, size_t len, } /* unpack to 32bpp if requested */ - if (format != fmt_rgb888 && color_type == 2) + if (format != FMT_RGB888 && color_type == 2) { uint8_t *inp = out + width * height * 3; uint32_t *outp = ((uint32_t*)out) + width * height; @@ -516,6 +533,6 @@ bool png_decode(const void *userdata, size_t len, error: free(pixels); - memset(img, 0, sizeof(struct image)); + memset(img, 0, sizeof(struct mpng_image)); return false; }