From e1ff181b3f3183066c0275965ecd122ca81450da Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 21 Feb 2015 01:40:21 +0100 Subject: [PATCH] (RPNG) Start creating struct rpng_t --- libretro-common/formats/png/rpng.c | 23 +++++++--------- libretro-common/formats/png/rpng_nbio.c | 35 +++++++++++-------------- libretro-common/include/formats/rpng.h | 8 ++++++ 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/libretro-common/formats/png/rpng.c b/libretro-common/formats/png/rpng.c index e36f3dd17b..19f122836e 100644 --- a/libretro-common/formats/png/rpng.c +++ b/libretro-common/formats/png/rpng.c @@ -219,10 +219,7 @@ bool rpng_load_image_argb(const char *path, uint32_t **data, struct idat_buffer idat_buf = {0}; struct png_ihdr ihdr = {0}; uint32_t palette[256] = {0}; - bool has_ihdr = false; - bool has_idat = false; - bool has_iend = false; - bool has_plte = false; + struct rpng_t rpng = {0}; bool ret = true; *data = NULL; @@ -264,17 +261,17 @@ bool rpng_load_image_argb(const char *path, uint32_t **data, GOTO_END_ERROR(); case PNG_CHUNK_IHDR: - if (has_ihdr || has_idat || has_iend) + if (rpng.has_ihdr || rpng.has_idat || rpng.has_iend) GOTO_END_ERROR(); if (!png_parse_ihdr_fio(file, &chunk, &ihdr)) GOTO_END_ERROR(); - has_ihdr = true; + rpng.has_ihdr = true; break; case PNG_CHUNK_PLTE: - if (!has_ihdr || has_plte || has_iend || has_idat) + if (!rpng.has_ihdr || rpng.has_plte || rpng.has_iend || rpng.has_idat) GOTO_END_ERROR(); if (chunk.size % 3) @@ -283,32 +280,32 @@ bool rpng_load_image_argb(const char *path, uint32_t **data, if (!png_read_plte_fio(file, palette, chunk.size / 3)) GOTO_END_ERROR(); - has_plte = true; + rpng.has_plte = true; break; case PNG_CHUNK_IDAT: - if (!has_ihdr || has_iend || (ihdr.color_type == 3 && !has_plte)) + if (!rpng.has_ihdr || rpng.has_iend || (ihdr.color_type == 3 && !rpng.has_plte)) GOTO_END_ERROR(); if (!png_append_idat_fio(file, &chunk, &idat_buf)) GOTO_END_ERROR(); - has_idat = true; + rpng.has_idat = true; break; case PNG_CHUNK_IEND: - if (!has_ihdr || !has_idat) + if (!rpng.has_ihdr || !rpng.has_idat) GOTO_END_ERROR(); if (fseek(file, sizeof(uint32_t), SEEK_CUR) < 0) GOTO_END_ERROR(); - has_iend = true; + rpng.has_iend = true; break; } } - if (!has_ihdr || !has_idat || !has_iend) + if (!rpng.has_ihdr || !rpng.has_idat || !rpng.has_iend) GOTO_END_ERROR(); if (inflateInit(&stream) != Z_OK) diff --git a/libretro-common/formats/png/rpng_nbio.c b/libretro-common/formats/png/rpng_nbio.c index ce2b727e1e..4bf324e6db 100644 --- a/libretro-common/formats/png/rpng_nbio.c +++ b/libretro-common/formats/png/rpng_nbio.c @@ -171,8 +171,7 @@ bool rpng_nbio_load_image_argb_iterate(uint8_t *buf, struct png_chunk *chunk, uint32_t *palette, struct png_ihdr *ihdr, struct idat_buffer *idat_buf, - bool *has_ihdr, bool *has_idat, - bool *has_iend, bool *has_plte, size_t *increment_size) + struct rpng_t *rpng, size_t *increment_size) { unsigned i; @@ -193,7 +192,7 @@ bool rpng_nbio_load_image_argb_iterate(uint8_t *buf, return false; case PNG_CHUNK_IHDR: - if (*has_ihdr || *has_idat || *has_iend) + if (rpng->has_ihdr || rpng->has_idat || rpng->has_iend) return false; if (chunk->size != 13) @@ -202,14 +201,14 @@ bool rpng_nbio_load_image_argb_iterate(uint8_t *buf, if (!png_parse_ihdr(buf, ihdr)) return false; - *has_ihdr = true; + rpng->has_ihdr = true; break; case PNG_CHUNK_PLTE: { unsigned entries = chunk->size / 3; - if (!*has_ihdr || *has_plte || *has_iend || *has_idat) + if (!rpng->has_ihdr || rpng->has_plte || rpng->has_iend || rpng->has_idat) return false; if (chunk->size % 3) @@ -226,12 +225,12 @@ bool rpng_nbio_load_image_argb_iterate(uint8_t *buf, if (!png_read_plte_into_buf(palette, entries)) return false; - *has_plte = true; + rpng->has_plte = true; } break; case PNG_CHUNK_IDAT: - if (!(*has_ihdr) || *has_iend || (ihdr->color_type == 3 && !(*has_plte))) + if (!(rpng->has_ihdr) || rpng->has_iend || (ihdr->color_type == 3 && !(rpng->has_plte))) return false; if (!png_realloc_idat(chunk, idat_buf)) @@ -244,14 +243,14 @@ bool rpng_nbio_load_image_argb_iterate(uint8_t *buf, idat_buf->size += chunk->size; - *has_idat = true; + rpng->has_idat = true; break; case PNG_CHUNK_IEND: - if (!(*has_ihdr) || !(*has_idat)) + if (!(rpng->has_ihdr) || !(rpng->has_idat)) return false; - *has_iend = true; + rpng->has_iend = true; return false; } @@ -325,10 +324,7 @@ bool rpng_nbio_load_image_argb(const char *path, uint32_t **data, struct idat_buffer idat_buf = {0}; struct png_ihdr ihdr = {0}; uint32_t palette[256] = {0}; - bool has_ihdr = false; - bool has_idat = false; - bool has_iend = false; - bool has_plte = false; + struct rpng_t rpng = {0}; bool ret = true; void* ptr = NULL; size_t increment = 0; @@ -369,20 +365,19 @@ bool rpng_nbio_load_image_argb(const char *path, uint32_t **data, if (!rpng_nbio_load_image_argb_iterate( buff_data, &chunk, palette, &ihdr, &idat_buf, - &has_ihdr, &has_idat, &has_iend, &has_plte, - &increment)) + &rpng, &increment)) break; buff_data += 4 + 4 + chunk.size + 4; } #if 0 - fprintf(stderr, "has_ihdr: %d\n", has_ihdr); - fprintf(stderr, "has_idat: %d\n", has_idat); - fprintf(stderr, "has_iend: %d\n", has_iend); + fprintf(stderr, "has_ihdr: %d\n", rpng.has_ihdr); + fprintf(stderr, "has_idat: %d\n", rpng.has_idat); + fprintf(stderr, "has_iend: %d\n", rpng.has_iend); #endif - if (!has_ihdr || !has_idat || !has_iend) + if (!rpng.has_ihdr || !rpng.has_idat || !rpng.has_iend) GOTO_END_ERROR(); rpng_nbio_load_image_argb_process(inflate_buf, diff --git a/libretro-common/include/formats/rpng.h b/libretro-common/include/formats/rpng.h index 2cc75b04f5..80708fc4d6 100644 --- a/libretro-common/include/formats/rpng.h +++ b/libretro-common/include/formats/rpng.h @@ -35,6 +35,14 @@ extern "C" { #endif +struct rpng_t +{ + bool has_ihdr; + bool has_idat; + bool has_iend; + bool has_plte; +}; + bool rpng_load_image_argb(const char *path, uint32_t **data, unsigned *width, unsigned *height);