mirror of
https://github.com/libretro/RetroArch
synced 2025-02-20 15:40:44 +00:00
(NBIO) Make all nbio functions nonblocking
This commit is contained in:
parent
c328462c9c
commit
6c54e8119e
@ -331,10 +331,7 @@ void rpng_nbio_load_image_free(struct rpng_t *rpng)
|
||||
|
||||
struct rpng_t *rpng_nbio_load_image_argb_init(const char *path)
|
||||
{
|
||||
unsigned i;
|
||||
char header[8];
|
||||
size_t file_len;
|
||||
bool looped = false;
|
||||
struct nbio_t* nbread = NULL;
|
||||
struct rpng_t *rpng = (struct rpng_t*)calloc(1, sizeof(struct rpng_t));
|
||||
|
||||
@ -352,22 +349,6 @@ struct rpng_t *rpng_nbio_load_image_argb_init(const char *path)
|
||||
|
||||
nbio_begin_read(nbread);
|
||||
|
||||
while (!nbio_iterate(nbread))
|
||||
looped = true;
|
||||
|
||||
rpng->ptr = nbio_get_ptr(nbread, &file_len);
|
||||
(void)looped;
|
||||
|
||||
rpng->buff_data = (uint8_t*)rpng->ptr;
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
header[i] = rpng->buff_data[i];
|
||||
|
||||
if (memcmp(header, png_magic, sizeof(png_magic)) != 0)
|
||||
goto error;
|
||||
|
||||
rpng->buff_data += 8;
|
||||
|
||||
return rpng;
|
||||
|
||||
error:
|
||||
@ -377,3 +358,39 @@ error:
|
||||
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 *nbread = NULL;
|
||||
|
||||
if (!rpng)
|
||||
return false;
|
||||
|
||||
nbread = (struct nbio_t*)rpng->userdata;
|
||||
|
||||
if (!nbread)
|
||||
return false;
|
||||
|
||||
rpng->ptr = nbio_get_ptr(nbread, &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];
|
||||
|
||||
if (memcmp(header, png_magic, sizeof(png_magic)) != 0)
|
||||
return false;
|
||||
|
||||
rpng->buff_data += 8;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
#include <formats/rpng.h>
|
||||
#include <file/nbio.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
@ -42,12 +43,17 @@ static bool rpng_nbio_load_image_argb(const char *path, uint32_t **data,
|
||||
goto end;
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (!rpng_nbio_load_image_argb_iterate(
|
||||
rpng->buff_data, rpng))
|
||||
break;
|
||||
while (!nbio_iterate((struct nbio_t*)rpng->userdata));
|
||||
|
||||
if (!rpng_nbio_load_image_argb_start(rpng))
|
||||
{
|
||||
ret = false;
|
||||
goto end;
|
||||
}
|
||||
|
||||
while (rpng_nbio_load_image_argb_iterate(
|
||||
rpng->buff_data, rpng))
|
||||
{
|
||||
rpng->buff_data += 4 + 4 + rpng->chunk.size + 4;
|
||||
}
|
||||
|
||||
|
@ -90,6 +90,8 @@ bool rpng_nbio_load_image_argb_iterate(uint8_t *buf,
|
||||
bool rpng_nbio_load_image_argb_process(struct rpng_t *rpng,
|
||||
uint32_t **data, unsigned *width, unsigned *height);
|
||||
|
||||
bool rpng_nbio_load_image_argb_start(struct rpng_t *rpng);
|
||||
|
||||
#ifdef HAVE_ZLIB_DEFLATE
|
||||
bool rpng_save_image_argb(const char *path, const uint32_t *data,
|
||||
unsigned width, unsigned height, unsigned pitch);
|
||||
|
Loading…
x
Reference in New Issue
Block a user