1
0
mirror of https://github.com/libretro/RetroArch synced 2025-04-02 16:20:39 +00:00

Improve image_nbio.c

This commit is contained in:
twinaphex 2015-02-23 02:36:18 +01:00
parent 80072c72c2
commit 635d75a5ea

@ -18,7 +18,7 @@
#include "../../config.h" #include "../../config.h"
#endif #endif
#include "image.h" #include <formats/image.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -28,12 +28,33 @@
#include <file/nbio.h> #include <file/nbio.h>
#ifdef HAVE_ZLIB #ifdef HAVE_ZLIB
static bool rpng_load_image_argb_nonblocking( static bool rpng_nbio_load_image_argb_nonblocking(const char *path, uint32_t **data,
const char *path, uint32_t **data,
unsigned *width, unsigned *height) unsigned *width, unsigned *height)
{ {
bool ret = true; size_t file_len;
struct rpng_t *rpng = rpng_nbio_load_image_argb_init(path); bool ret = true;
struct rpng_t *rpng = NULL;
void *ptr = NULL;
struct nbio_t* handle = (void*)nbio_open(path, NBIO_READ);
if (!handle)
goto end;
ptr = nbio_get_ptr(handle, &file_len);
nbio_begin_read(handle);
while (!nbio_iterate(handle));
ptr = nbio_get_ptr(handle, &file_len);
if (!ptr)
{
ret = false;
goto end;
}
rpng = (struct rpng_t*)calloc(1, sizeof(struct rpng_t));
if (!rpng) if (!rpng)
{ {
@ -41,7 +62,13 @@ static bool rpng_load_image_argb_nonblocking(
goto end; goto end;
} }
while (!nbio_iterate((struct nbio_t*)rpng->userdata)); rpng->buff_data = (uint8_t*)ptr;
if (!rpng->buff_data)
{
ret = false;
goto end;
}
if (!rpng_nbio_load_image_argb_start(rpng)) if (!rpng_nbio_load_image_argb_start(rpng))
{ {
@ -66,15 +93,17 @@ static bool rpng_load_image_argb_nonblocking(
ret = false; ret = false;
goto end; goto end;
} }
rpng_nbio_load_image_argb_process(rpng, data, width, height); rpng_nbio_load_image_argb_process(rpng, data, width, height);
end: end:
rpng_nbio_load_image_free(rpng); if (handle)
nbio_free(handle);
if (rpng)
rpng_nbio_load_image_free(rpng);
rpng = NULL; rpng = NULL;
if (!ret) if (!ret)
free(*data); free(*data);
return ret; return ret;
} }
@ -83,7 +112,7 @@ static bool rpng_image_load_argb_shift(const char *path,
unsigned a_shift, unsigned r_shift, unsigned a_shift, unsigned r_shift,
unsigned g_shift, unsigned b_shift) unsigned g_shift, unsigned b_shift)
{ {
bool ret = rpng_load_image_argb_nonblocking(path, bool ret = rpng_nbio_load_image_argb_nonblocking(path,
&out_img->pixels, &out_img->width, &out_img->height); &out_img->pixels, &out_img->width, &out_img->height);
if (!ret) if (!ret)