diff --git a/libretro-common/formats/png/rpng_nbio.c b/libretro-common/formats/png/rpng_nbio.c index 7a31448ac4..549329b4c4 100644 --- a/libretro-common/formats/png/rpng_nbio.c +++ b/libretro-common/formats/png/rpng_nbio.c @@ -377,40 +377,3 @@ error: free(rpng); return NULL; } - -bool rpng_nbio_load_image_argb(const char *path, uint32_t **data, - unsigned *width, unsigned *height) -{ - bool ret = true; - - struct rpng_t *rpng = rpng_nbio_load_image_argb_init(path); - - if (!rpng) - GOTO_END_ERROR(); - - while (1) - { - if (!rpng_nbio_load_image_argb_iterate( - rpng->buff_data, rpng)) - break; - } - -#if 0 - 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 (!rpng->has_ihdr || !rpng->has_idat || !rpng->has_iend) - GOTO_END_ERROR(); - - rpng_nbio_load_image_argb_process(rpng, data, width, height); - -end: - rpng_nbio_load_image_free(rpng); - rpng = NULL; - if (!ret) - free(*data); - - return ret; -} diff --git a/libretro-common/formats/png/rpng_test.c b/libretro-common/formats/png/rpng_test.c index c2c7353156..c1bc579d3a 100644 --- a/libretro-common/formats/png/rpng_test.c +++ b/libretro-common/formats/png/rpng_test.c @@ -29,6 +29,49 @@ #include #endif +static bool rpng_nbio_load_image_argb(const char *path, uint32_t **data, + unsigned *width, unsigned *height) +{ + bool ret = true; + + struct rpng_t *rpng = rpng_nbio_load_image_argb_init(path); + + if (!rpng) + { + ret = false; + goto end; + } + + while (1) + { + if (!rpng_nbio_load_image_argb_iterate( + rpng->buff_data, rpng)) + break; + } + +#if 0 + 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 (!rpng->has_ihdr || !rpng->has_idat || !rpng->has_iend) + { + ret = false; + goto end; + } + + rpng_nbio_load_image_argb_process(rpng, data, width, height); + +end: + rpng_nbio_load_image_free(rpng); + rpng = NULL; + if (!ret) + free(*data); + + return ret; +} + static int test_nonblocking_rpng(const char *in_path) { #ifdef HAVE_IMLIB2 diff --git a/libretro-common/include/formats/rpng.h b/libretro-common/include/formats/rpng.h index 1f702d085b..f339ed4fe9 100644 --- a/libretro-common/include/formats/rpng.h +++ b/libretro-common/include/formats/rpng.h @@ -72,8 +72,15 @@ struct rpng_t bool rpng_load_image_argb(const char *path, uint32_t **data, unsigned *width, unsigned *height); -bool rpng_nbio_load_image_argb(const char *path, uint32_t **data, - unsigned *width, unsigned *height); +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); + +bool rpng_nbio_load_image_argb_process(struct rpng_t *rpng, + uint32_t **data, unsigned *width, unsigned *height); #ifdef HAVE_ZLIB_DEFLATE bool rpng_save_image_argb(const char *path, const uint32_t *data,