From a48343c1305c1592fbf64135fa85a5a1e855d618 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 21 Feb 2015 03:28:00 +0100 Subject: [PATCH] Move png_chunk to rpng_t --- libretro-common/formats/png/rpng_common.h | 7 ------ .../formats/png/rpng_decode_fnbio.c | 22 +++++++++---------- libretro-common/formats/png/rpng_test.c | 2 ++ libretro-common/include/formats/rpng.h | 8 +++++++ 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/libretro-common/formats/png/rpng_common.h b/libretro-common/formats/png/rpng_common.h index e831cc4202..d96ed66ac1 100644 --- a/libretro-common/formats/png/rpng_common.h +++ b/libretro-common/formats/png/rpng_common.h @@ -40,13 +40,6 @@ static const uint8_t png_magic[8] = { 0x89, 'P', 'N', 'G', 0x0d, 0x0a, 0x1a, 0x0a, }; -struct png_chunk -{ - uint32_t size; - char type[4]; - uint8_t *data; -}; - enum png_chunk_type { PNG_CHUNK_NOOP = 0, diff --git a/libretro-common/formats/png/rpng_decode_fnbio.c b/libretro-common/formats/png/rpng_decode_fnbio.c index 549329b4c4..6161b457a5 100644 --- a/libretro-common/formats/png/rpng_decode_fnbio.c +++ b/libretro-common/formats/png/rpng_decode_fnbio.c @@ -170,9 +170,11 @@ static bool png_read_plte_into_buf(uint32_t *buffer, unsigned entries) bool rpng_nbio_load_image_argb_iterate(uint8_t *buf, struct rpng_t *rpng) { unsigned i; - struct png_chunk chunk = {0}; - if (!read_chunk_header(rpng->buff_data, &chunk)) + rpng->chunk.size = 0; + rpng->chunk.type[0] = '\0'; + + if (!read_chunk_header(buf, &rpng->chunk)) return false; #if 0 @@ -182,7 +184,7 @@ bool rpng_nbio_load_image_argb_iterate(uint8_t *buf, struct rpng_t *rpng) } #endif - switch (png_chunk_type(&chunk)) + switch (png_chunk_type(&rpng->chunk)) { case PNG_CHUNK_NOOP: default: @@ -195,7 +197,7 @@ bool rpng_nbio_load_image_argb_iterate(uint8_t *buf, struct rpng_t *rpng) if (rpng->has_ihdr || rpng->has_idat || rpng->has_iend) return false; - if (chunk.size != 13) + if (rpng->chunk.size != 13) return false; if (!png_parse_ihdr(buf, &rpng->ihdr)) @@ -206,12 +208,12 @@ bool rpng_nbio_load_image_argb_iterate(uint8_t *buf, struct rpng_t *rpng) case PNG_CHUNK_PLTE: { - unsigned entries = chunk.size / 3; + unsigned entries = rpng->chunk.size / 3; if (!rpng->has_ihdr || rpng->has_plte || rpng->has_iend || rpng->has_idat) return false; - if (chunk.size % 3) + if (rpng->chunk.size % 3) return false; if (entries > 256) @@ -233,15 +235,15 @@ bool rpng_nbio_load_image_argb_iterate(uint8_t *buf, struct rpng_t *rpng) if (!(rpng->has_ihdr) || rpng->has_iend || (rpng->ihdr.color_type == 3 && !(rpng->has_plte))) return false; - if (!png_realloc_idat(&chunk, &rpng->idat_buf)) + if (!png_realloc_idat(&rpng->chunk, &rpng->idat_buf)) return false; buf += 8; - for (i = 0; i < chunk.size; i++) + for (i = 0; i < rpng->chunk.size; i++) rpng->idat_buf.data[i + rpng->idat_buf.size] = buf[i]; - rpng->idat_buf.size += chunk.size; + rpng->idat_buf.size += rpng->chunk.size; rpng->has_idat = true; break; @@ -254,8 +256,6 @@ bool rpng_nbio_load_image_argb_iterate(uint8_t *buf, struct rpng_t *rpng) return false; } - rpng->buff_data += 4 + 4 + chunk.size + 4; - return true; } diff --git a/libretro-common/formats/png/rpng_test.c b/libretro-common/formats/png/rpng_test.c index c1bc579d3a..add6c4b343 100644 --- a/libretro-common/formats/png/rpng_test.c +++ b/libretro-common/formats/png/rpng_test.c @@ -47,6 +47,8 @@ static bool rpng_nbio_load_image_argb(const char *path, uint32_t **data, if (!rpng_nbio_load_image_argb_iterate( rpng->buff_data, rpng)) break; + + rpng->buff_data += 4 + 4 + rpng->chunk.size + 4; } #if 0 diff --git a/libretro-common/include/formats/rpng.h b/libretro-common/include/formats/rpng.h index f339ed4fe9..e5d77561f6 100644 --- a/libretro-common/include/formats/rpng.h +++ b/libretro-common/include/formats/rpng.h @@ -42,6 +42,13 @@ struct idat_buffer size_t size; }; +struct png_chunk +{ + uint32_t size; + char type[4]; + uint8_t *data; +}; + struct png_ihdr { uint32_t width; @@ -65,6 +72,7 @@ struct rpng_t size_t inflate_buf_size; uint8_t *buff_data; uint32_t palette[256]; + struct png_chunk chunk; void *userdata; void *ptr; };