mirror of
https://github.com/libretro/RetroArch
synced 2025-03-03 04:14:00 +00:00
Decouple nbio_t from rpng_decode_fnbio.c
This commit is contained in:
parent
f233ccb141
commit
07c7a0df99
@ -28,8 +28,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <file/nbio.h>
|
||||
|
||||
#ifdef GEKKO
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
@ -319,7 +317,6 @@ void rpng_nbio_load_image_free(struct rpng_t *rpng)
|
||||
if (!rpng)
|
||||
return;
|
||||
|
||||
nbio_free((struct nbio_t*)rpng->userdata);
|
||||
if (rpng->idat_buf.data)
|
||||
free(rpng->idat_buf.data);
|
||||
if (rpng->inflate_buf)
|
||||
@ -329,61 +326,14 @@ void rpng_nbio_load_image_free(struct rpng_t *rpng)
|
||||
free(rpng);
|
||||
}
|
||||
|
||||
struct rpng_t *rpng_nbio_load_image_argb_init(const char *path)
|
||||
{
|
||||
size_t file_len;
|
||||
struct nbio_t* handle = NULL;
|
||||
struct rpng_t *rpng = (struct rpng_t*)calloc(1, sizeof(struct rpng_t));
|
||||
|
||||
if (!rpng)
|
||||
goto error;
|
||||
|
||||
rpng->userdata = (void*)nbio_open(path, NBIO_READ);
|
||||
|
||||
handle = (struct nbio_t*)rpng->userdata;
|
||||
|
||||
if (!handle)
|
||||
goto error;
|
||||
|
||||
rpng->ptr = nbio_get_ptr(handle, &file_len);
|
||||
|
||||
nbio_begin_read(handle);
|
||||
|
||||
return rpng;
|
||||
|
||||
error:
|
||||
if (rpng->userdata)
|
||||
nbio_free((struct nbio_t*)rpng->userdata);
|
||||
if (rpng)
|
||||
free(rpng);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool rpng_nbio_load_image_argb_start(struct rpng_t *rpng)
|
||||
{
|
||||
unsigned i;
|
||||
size_t file_len;
|
||||
char header[8];
|
||||
struct nbio_t *handle = NULL;
|
||||
|
||||
if (!rpng)
|
||||
return false;
|
||||
|
||||
handle = (struct nbio_t*)rpng->userdata;
|
||||
|
||||
if (!handle)
|
||||
return false;
|
||||
|
||||
rpng->ptr = nbio_get_ptr(handle, &file_len);
|
||||
|
||||
if (!rpng->ptr)
|
||||
return false;
|
||||
|
||||
rpng->buff_data = (uint8_t*)rpng->ptr;
|
||||
|
||||
if (!rpng->buff_data)
|
||||
return false;
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
header[i] = rpng->buff_data[i];
|
||||
|
||||
|
@ -33,9 +33,24 @@
|
||||
static bool rpng_nbio_load_image_argb(const char *path, uint32_t **data,
|
||||
unsigned *width, unsigned *height)
|
||||
{
|
||||
bool ret = true;
|
||||
size_t file_len;
|
||||
bool ret = true;
|
||||
struct nbio_t* handle = NULL;
|
||||
struct rpng_t *rpng = (struct rpng_t*)calloc(1, sizeof(struct rpng_t));
|
||||
|
||||
struct rpng_t *rpng = rpng_nbio_load_image_argb_init(path);
|
||||
if (!rpng)
|
||||
return false;
|
||||
|
||||
rpng->userdata = (void*)nbio_open(path, NBIO_READ);
|
||||
|
||||
handle = (struct nbio_t*)rpng->userdata;
|
||||
|
||||
if (!handle)
|
||||
goto end;
|
||||
|
||||
rpng->ptr = nbio_get_ptr(handle, &file_len);
|
||||
|
||||
nbio_begin_read(handle);
|
||||
|
||||
if (!rpng)
|
||||
{
|
||||
@ -43,7 +58,23 @@ static bool rpng_nbio_load_image_argb(const char *path, uint32_t **data,
|
||||
goto end;
|
||||
}
|
||||
|
||||
while (!nbio_iterate((struct nbio_t*)rpng->userdata));
|
||||
while (!nbio_iterate(handle));
|
||||
|
||||
rpng->ptr = nbio_get_ptr(handle, &file_len);
|
||||
|
||||
if (!rpng->ptr)
|
||||
{
|
||||
ret = false;
|
||||
goto end;
|
||||
}
|
||||
|
||||
rpng->buff_data = (uint8_t*)rpng->ptr;
|
||||
|
||||
if (!rpng->buff_data)
|
||||
{
|
||||
ret = false;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!rpng_nbio_load_image_argb_start(rpng))
|
||||
{
|
||||
@ -72,11 +103,15 @@ static bool rpng_nbio_load_image_argb(const char *path, uint32_t **data,
|
||||
rpng_nbio_load_image_argb_process(rpng, data, width, height);
|
||||
|
||||
end:
|
||||
rpng_nbio_load_image_free(rpng);
|
||||
rpng = NULL;
|
||||
if (rpng->userdata)
|
||||
nbio_free((struct nbio_t*)rpng->userdata);
|
||||
if (rpng)
|
||||
{
|
||||
rpng_nbio_load_image_free(rpng);
|
||||
}
|
||||
if (!ret)
|
||||
free(*data);
|
||||
|
||||
rpng = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user