From 3ccb4380f1f7b2a9aa3cb548abc26febdb88b753 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 1 Sep 2015 13:27:36 +0200 Subject: [PATCH] (RPNG) Move more common code outside --- libretro-common/formats/png/rpng_common.h | 10 +++++++++ libretro-common/formats/png/rpng_fbio.c | 27 +++++++---------------- libretro-common/formats/png/rpng_nbio.c | 12 ---------- 3 files changed, 18 insertions(+), 31 deletions(-) diff --git a/libretro-common/formats/png/rpng_common.h b/libretro-common/formats/png/rpng_common.h index 2e678e0382..e84e97f9c5 100644 --- a/libretro-common/formats/png/rpng_common.h +++ b/libretro-common/formats/png/rpng_common.h @@ -181,5 +181,15 @@ static INLINE bool png_read_plte(uint8_t *buf, return true; } +static INLINE bool png_realloc_idat(const struct png_chunk *chunk, struct idat_buffer *buf) +{ + uint8_t *new_buffer = (uint8_t*)realloc(buf->data, buf->size + chunk->size); + + if (!new_buffer) + return false; + + buf->data = new_buffer; + return true; +} #endif diff --git a/libretro-common/formats/png/rpng_fbio.c b/libretro-common/formats/png/rpng_fbio.c index 66f05e46ef..4d73186f32 100644 --- a/libretro-common/formats/png/rpng_fbio.c +++ b/libretro-common/formats/png/rpng_fbio.c @@ -96,24 +96,6 @@ static bool png_parse_ihdr_fio(FILE **fd, return true; } -static bool png_append_idat_fio(FILE **fd, - const struct png_chunk *chunk, struct idat_buffer *buf) -{ - FILE *file = *fd; - uint8_t *new_buffer = (uint8_t*)realloc(buf->data, buf->size + chunk->size); - - if (!new_buffer) - return false; - - buf->data = new_buffer; - if (fread(buf->data + buf->size, 1, chunk->size, file) != chunk->size) - return false; - if (fseek(file, sizeof(uint32_t), SEEK_CUR) < 0) - return false; - buf->size += chunk->size; - return true; -} - bool rpng_load_image_argb_iterate(FILE **fd, struct rpng_t *rpng) { struct png_chunk chunk = {0}; @@ -184,9 +166,16 @@ bool rpng_load_image_argb_iterate(FILE **fd, struct rpng_t *rpng) if (!rpng->has_ihdr || rpng->has_iend || (rpng->ihdr.color_type == PNG_IHDR_COLOR_PLT && !rpng->has_plte)) return false; - if (!png_append_idat_fio(fd, &chunk, &rpng->idat_buf)) + if (!png_realloc_idat(&chunk, &rpng->idat_buf)) return false; + if (fread(rpng->idat_buf.data + rpng->idat_buf.size, 1, chunk.size, file) != chunk.size) + return false; + if (fseek(file, sizeof(uint32_t), SEEK_CUR) < 0) + return false; + + rpng->idat_buf.size += chunk.size; + rpng->has_idat = true; break; diff --git a/libretro-common/formats/png/rpng_nbio.c b/libretro-common/formats/png/rpng_nbio.c index f62e3aa9a2..1b4ca54133 100644 --- a/libretro-common/formats/png/rpng_nbio.c +++ b/libretro-common/formats/png/rpng_nbio.c @@ -66,18 +66,6 @@ static bool png_parse_ihdr(uint8_t *buf, return true; } -static bool png_realloc_idat(const struct png_chunk *chunk, struct idat_buffer *buf) -{ - uint8_t *new_buffer = (uint8_t*)realloc(buf->data, buf->size + chunk->size); - - if (!new_buffer) - return false; - - buf->data = new_buffer; - return true; -} - - bool rpng_nbio_load_image_argb_iterate(struct rpng_t *rpng) { unsigned i;