Move rpng_nbio wrapper function to rpng_test.c

This commit is contained in:
twinaphex 2015-02-21 02:42:33 +01:00
parent e912d3c49c
commit 1b0c9d7776
3 changed files with 52 additions and 39 deletions

View File

@ -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;
}

View File

@ -29,6 +29,49 @@
#include <Imlib2.h>
#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

View File

@ -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,