From a27c0714cb4c51dc476ee7cd300dd436632d1b67 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 10 Apr 2015 23:45:56 +0200 Subject: [PATCH] Take chunk_type out of struct --- libretro-common/formats/png/rpng_nbio.c | 50 +++++++++++++------------ libretro-common/formats/png/rpng_test.c | 5 ++- libretro-common/include/formats/rpng.h | 3 +- runloop_data.c | 6 +-- 4 files changed, 34 insertions(+), 30 deletions(-) diff --git a/libretro-common/formats/png/rpng_nbio.c b/libretro-common/formats/png/rpng_nbio.c index 07d727efb0..6ad2fd4475 100644 --- a/libretro-common/formats/png/rpng_nbio.c +++ b/libretro-common/formats/png/rpng_nbio.c @@ -98,14 +98,13 @@ static bool png_read_plte_into_buf(uint8_t *buf, return true; } -bool rpng_nbio_load_image_argb_iterate(uint8_t *buf, struct rpng_t *rpng) +bool rpng_nbio_load_image_argb_iterate(uint8_t *buf, struct rpng_t *rpng, unsigned *ret) { unsigned i; - rpng->chunk.size = 0; - rpng->chunk.type[0] = '\0'; + struct png_chunk chunk = {0}; - if (!read_chunk_header(buf, &rpng->chunk)) + if (!read_chunk_header(buf, &chunk)) return false; #if 0 @@ -115,43 +114,43 @@ bool rpng_nbio_load_image_argb_iterate(uint8_t *buf, struct rpng_t *rpng) } #endif - switch (png_chunk_type(&rpng->chunk)) + switch (png_chunk_type(&chunk)) { case PNG_CHUNK_NOOP: default: break; case PNG_CHUNK_ERROR: - return false; + goto error; case PNG_CHUNK_IHDR: if (rpng->has_ihdr || rpng->has_idat || rpng->has_iend) - return false; + goto error; - if (rpng->chunk.size != 13) - return false; + if (chunk.size != 13) + goto error; if (!png_parse_ihdr(buf, &rpng->ihdr)) - return false; + goto error; if (!png_process_ihdr(&rpng->ihdr)) - return false; + goto error; rpng->has_ihdr = true; break; case PNG_CHUNK_PLTE: { - unsigned entries = rpng->chunk.size / 3; + unsigned entries = chunk.size / 3; if (!rpng->has_ihdr || rpng->has_plte || rpng->has_iend || rpng->has_idat) - return false; + goto error; - if (rpng->chunk.size % 3) - return false; + if (chunk.size % 3) + goto error; if (!png_read_plte_into_buf(buf, rpng->palette, entries)) - return false; + goto error; rpng->has_plte = true; } @@ -159,30 +158,35 @@ bool rpng_nbio_load_image_argb_iterate(uint8_t *buf, struct rpng_t *rpng) case PNG_CHUNK_IDAT: if (!(rpng->has_ihdr) || rpng->has_iend || (rpng->ihdr.color_type == PNG_IHDR_COLOR_PLT && !(rpng->has_plte))) - return false; + goto error; - if (!png_realloc_idat(&rpng->chunk, &rpng->idat_buf)) - return false; + if (!png_realloc_idat(&chunk, &rpng->idat_buf)) + goto error; buf += 8; - for (i = 0; i < rpng->chunk.size; i++) + for (i = 0; i < chunk.size; i++) rpng->idat_buf.data[i + rpng->idat_buf.size] = buf[i]; - rpng->idat_buf.size += rpng->chunk.size; + rpng->idat_buf.size += chunk.size; rpng->has_idat = true; break; case PNG_CHUNK_IEND: if (!(rpng->has_ihdr) || !(rpng->has_idat)) - return false; + goto error; rpng->has_iend = true; - return false; + goto error; } + *ret = 4 + 4 + chunk.size + 4; + return true; + +error: + return false; } int rpng_nbio_load_image_argb_process(struct rpng_t *rpng, diff --git a/libretro-common/formats/png/rpng_test.c b/libretro-common/formats/png/rpng_test.c index b1939bb0d4..da8fbd6bc3 100644 --- a/libretro-common/formats/png/rpng_test.c +++ b/libretro-common/formats/png/rpng_test.c @@ -46,6 +46,7 @@ static bool rpng_nbio_load_image_argb(const char *path, uint32_t **data, bool ret = true; struct rpng_t *rpng = NULL; void *ptr = NULL; + unsigned val = 0; struct nbio_t* handle = (void*)nbio_open(path, NBIO_READ); if (!handle) @@ -88,9 +89,9 @@ static bool rpng_nbio_load_image_argb(const char *path, uint32_t **data, } while (rpng_nbio_load_image_argb_iterate( - rpng->buff_data, rpng)) + rpng->buff_data, rpng, &val)) { - rpng->buff_data += 4 + 4 + rpng->chunk.size + 4; + rpng->buff_data += val; } #if 0 diff --git a/libretro-common/include/formats/rpng.h b/libretro-common/include/formats/rpng.h index 4b1ef983e8..fdd3ca2032 100644 --- a/libretro-common/include/formats/rpng.h +++ b/libretro-common/include/formats/rpng.h @@ -98,7 +98,6 @@ struct rpng_t struct png_ihdr ihdr; uint8_t *buff_data; uint32_t palette[256]; - struct png_chunk chunk; }; bool rpng_load_image_argb(const char *path, uint32_t **data, @@ -109,7 +108,7 @@ struct rpng_t *rpng_nbio_load_image_argb_init(const char *path); void rpng_nbio_load_image_free(struct rpng_t *rpng); bool rpng_nbio_load_image_argb_iterate(uint8_t *buf, - struct rpng_t *rpng); + struct rpng_t *rpng, unsigned *ret); int rpng_nbio_load_image_argb_process(struct rpng_t *rpng, uint32_t **data, unsigned *width, unsigned *height); diff --git a/runloop_data.c b/runloop_data.c index e7593dd6a6..73328e5f28 100644 --- a/runloop_data.c +++ b/runloop_data.c @@ -441,13 +441,13 @@ static int rarch_main_data_image_iterate_transfer(nbio_handle_t *nbio) for (i = 0; i < nbio->image.pos_increment; i++) { + unsigned ret; if (!rpng_nbio_load_image_argb_iterate( nbio->image.handle->buff_data, - nbio->image.handle)) + nbio->image.handle, &ret)) goto error; - nbio->image.handle->buff_data += - 4 + 4 + nbio->image.handle->chunk.size + 4; + nbio->image.handle->buff_data += ret; } nbio->image.frame_count++;