diff --git a/Makefile.common b/Makefile.common index 2c70757c9a..58646cea28 100644 --- a/Makefile.common +++ b/Makefile.common @@ -594,8 +594,9 @@ endif ifeq ($(HAVE_ZLIB), 1) ZLIB_OBJS = decompress/zip_support.o - OBJ += libretro-common/formats/png/rpng_decode_fnbio.o \ - libretro-common/formats/png/rpng_decode_fbio.o \ + OBJ += libretro-common/formats/png/rpng_nbio.o \ + libretro-common/formats/png/rpng_fbio.o \ + libretro-common/formats/png/rpng_decode.o \ libretro-common/formats/png/rpng_encode.o \ file_extract.o OBJ += $(ZLIB_OBJS) diff --git a/griffin/griffin.c b/griffin/griffin.c index 4ba20edb0f..dbf7fb8056 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -171,8 +171,9 @@ VIDEO IMAGE #include "../gfx/image/image.c" #include "../libretro-common/formats/tga/tga_decode.c" -#include "../libretro-common/formats/png/rpng_decode_fbio.c" -#include "../libretro-common/formats/png/rpng_decode_fnbio.c" +#include "../libretro-common/formats/png/rpng_fbio.c" +#include "../libretro-common/formats/png/rpng_nbio.c" +#include "../libretro-common/formats/png/rpng_decode.c" #include "../libretro-common/formats/png/rpng_encode.c" /*============================================================ diff --git a/libretro-common/formats/png/Makefile b/libretro-common/formats/png/Makefile index 01ca70c167..36fdeaefc0 100644 --- a/libretro-common/formats/png/Makefile +++ b/libretro-common/formats/png/Makefile @@ -8,7 +8,7 @@ CFLAGS += -DHAVE_IMLIB2 LDFLAGS += -lImlib2 endif -SOURCES := rpng_decode_fbio.c rpng_decode_fnbio.c rpng_encode.c rpng_test.c ../../file/nbio/nbio_stdio.c +SOURCES := rpng_fbio.c rpng_nbio.c rpng_encode.c rpng_decode.c rpng_test.c ../../file/nbio/nbio_stdio.c OBJS := $(SOURCES:.c=.o) CFLAGS += -Wall -pedantic -std=gnu99 -O0 -g -DHAVE_ZLIB -DHAVE_ZLIB_DEFLATE -DRPNG_TEST -I../../include diff --git a/libretro-common/formats/png/rpng_decode_common.h b/libretro-common/formats/png/rpng_decode.c similarity index 96% rename from libretro-common/formats/png/rpng_decode_common.h rename to libretro-common/formats/png/rpng_decode.c index 2b55a8467c..c1f0ced0ff 100644 --- a/libretro-common/formats/png/rpng_decode_common.h +++ b/libretro-common/formats/png/rpng_decode.c @@ -20,10 +20,16 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef _RPNG_DECODE_COMMON_H -#define _RPNG_DECODE_COMMON_H +#include -static enum png_chunk_type png_chunk_type(const struct png_chunk *chunk) +#include +#include +#include + +#include "rpng_common.h" +#include "rpng_decode.h" + +enum png_chunk_type png_chunk_type(const struct png_chunk *chunk) { unsigned i; struct @@ -46,7 +52,7 @@ static enum png_chunk_type png_chunk_type(const struct png_chunk *chunk) return PNG_CHUNK_NOOP; } -static bool png_process_ihdr(struct png_ihdr *ihdr) +bool png_process_ihdr(struct png_ihdr *ihdr) { unsigned i; bool ret = true; @@ -230,7 +236,7 @@ static void png_reverse_filter_copy_line_plt(uint32_t *data, } } -static void png_pass_geom(const struct png_ihdr *ihdr, +void png_pass_geom(const struct png_ihdr *ihdr, unsigned width, unsigned height, unsigned *bpp_out, unsigned *pitch_out, size_t *pass_size) { @@ -323,7 +329,7 @@ enum png_process_code PNG_PROCESS_END = 1, }; -static int png_reverse_filter_init(const struct png_ihdr *ihdr, +int png_reverse_filter_init(const struct png_ihdr *ihdr, struct rpng_process_t *pngp) { size_t pass_size; @@ -389,8 +395,6 @@ error: return -1; } - - static int png_reverse_filter_copy_line(uint32_t *data, const struct png_ihdr *ihdr, struct rpng_process_t *pngp, unsigned filter) { @@ -461,7 +465,6 @@ static int png_reverse_filter_copy_line(uint32_t *data, const struct png_ihdr *i return PNG_PROCESS_NEXT; } - static int png_reverse_filter_iterate(uint32_t *data, const struct png_ihdr *ihdr, struct rpng_process_t *pngp) { @@ -488,11 +491,10 @@ static int png_reverse_filter_iterate(uint32_t *data, const struct png_ihdr *ihd return PNG_PROCESS_NEXT; } - -static int png_reverse_filter_regular_loop(uint32_t **data_, const struct png_ihdr *ihdr, +int png_reverse_filter_regular_loop(uint32_t **data, const struct png_ihdr *ihdr, struct rpng_process_t *pngp) { - int ret = png_reverse_filter_iterate(*data_, ihdr, pngp); + int ret = png_reverse_filter_iterate(*data, ihdr, pngp); switch (ret) { @@ -501,19 +503,18 @@ static int png_reverse_filter_regular_loop(uint32_t **data_, const struct png_ih case PNG_PROCESS_END: break; case PNG_PROCESS_NEXT: - *data_ += ihdr->width; + *data += ihdr->width; pngp->data_restore_buf_size += ihdr->width; return PNG_PROCESS_NEXT; } pngp->inflate_buf -= pngp->restore_buf_size; - *data_ -= pngp->data_restore_buf_size; + *data -= pngp->data_restore_buf_size; pngp->data_restore_buf_size = 0; return ret; } - static int png_reverse_filter_adam7_iterate(uint32_t **data_, const struct png_ihdr *ihdr, struct rpng_process_t *pngp) @@ -560,7 +561,7 @@ static int png_reverse_filter_adam7_iterate(uint32_t **data_, return PNG_PROCESS_NEXT; } -static int png_reverse_filter_adam7(uint32_t **data_, +int png_reverse_filter_adam7(uint32_t **data_, const struct png_ihdr *ihdr, struct rpng_process_t *pngp) { @@ -588,7 +589,7 @@ static int png_reverse_filter_adam7(uint32_t **data_, return ret; } -static bool png_reverse_filter_loop(struct rpng_t *rpng, +bool png_reverse_filter_loop(struct rpng_t *rpng, uint32_t **data) { int ret = 0; @@ -625,5 +626,3 @@ static bool png_reverse_filter_loop(struct rpng_t *rpng, return true; } - -#endif diff --git a/libretro-common/formats/png/rpng_decode.h b/libretro-common/formats/png/rpng_decode.h new file mode 100644 index 0000000000..78786a9727 --- /dev/null +++ b/libretro-common/formats/png/rpng_decode.h @@ -0,0 +1,48 @@ +/* Copyright (C) 2010-2015 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (rpng.c). + * --------------------------------------------------------------------------------------- + * + * Permission is hereby granted, free of charge, + * to any person obtaining a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef _RPNG_DECODE_H +#define _RPNG_DECODE_H + +enum png_chunk_type png_chunk_type(const struct png_chunk *chunk); + +void png_pass_geom(const struct png_ihdr *ihdr, + unsigned width, unsigned height, + unsigned *bpp_out, unsigned *pitch_out, size_t *pass_size); + +bool png_process_ihdr(struct png_ihdr *ihdr); + +int png_reverse_filter_init(const struct png_ihdr *ihdr, + struct rpng_process_t *pngp); + +int png_reverse_filter_adam7(uint32_t **data, + const struct png_ihdr *ihdr, + struct rpng_process_t *pngp); + +int png_reverse_filter_regular_loop(uint32_t **data, + const struct png_ihdr *ihdr, + struct rpng_process_t *pngp); + +bool png_reverse_filter_loop(struct rpng_t *rpng, + uint32_t **data); + +#endif diff --git a/libretro-common/formats/png/rpng_decode_fbio.c b/libretro-common/formats/png/rpng_fbio.c similarity index 99% rename from libretro-common/formats/png/rpng_decode_fbio.c rename to libretro-common/formats/png/rpng_fbio.c index c311260cf2..4e6d7a642a 100644 --- a/libretro-common/formats/png/rpng_decode_fbio.c +++ b/libretro-common/formats/png/rpng_fbio.c @@ -31,7 +31,7 @@ #endif #include "rpng_common.h" -#include "rpng_decode_common.h" +#include "rpng_decode.h" static bool read_chunk_header_fio(FILE *file, struct png_chunk *chunk) { @@ -78,9 +78,6 @@ static void png_free_chunk(struct png_chunk *chunk) static bool png_parse_ihdr_fio(FILE *file, struct png_chunk *chunk, struct png_ihdr *ihdr) { - unsigned i; - bool ret = true; - if (!png_read_chunk(file, chunk)) return false; diff --git a/libretro-common/formats/png/rpng_decode_fnbio.c b/libretro-common/formats/png/rpng_nbio.c similarity index 99% rename from libretro-common/formats/png/rpng_decode_fnbio.c rename to libretro-common/formats/png/rpng_nbio.c index b4d90a86ff..1aecb03ce4 100644 --- a/libretro-common/formats/png/rpng_decode_fnbio.c +++ b/libretro-common/formats/png/rpng_nbio.c @@ -31,7 +31,7 @@ #endif #include "rpng_common.h" -#include "rpng_decode_common.h" +#include "rpng_decode.h" static bool read_chunk_header(uint8_t *buf, struct png_chunk *chunk) { @@ -56,8 +56,6 @@ static bool read_chunk_header(uint8_t *buf, struct png_chunk *chunk) static bool png_parse_ihdr(uint8_t *buf, struct png_ihdr *ihdr) { - bool ret = true; - buf += 4 + 4; ihdr->width = dword_be(buf + 0);