Move png_chunk to rpng_t

This commit is contained in:
twinaphex 2015-02-21 03:28:00 +01:00
parent 82432ca5d5
commit a48343c130
4 changed files with 21 additions and 18 deletions
libretro-common

@ -40,13 +40,6 @@ static const uint8_t png_magic[8] = {
0x89, 'P', 'N', 'G', 0x0d, 0x0a, 0x1a, 0x0a,
};
struct png_chunk
{
uint32_t size;
char type[4];
uint8_t *data;
};
enum png_chunk_type
{
PNG_CHUNK_NOOP = 0,

@ -170,9 +170,11 @@ static bool png_read_plte_into_buf(uint32_t *buffer, unsigned entries)
bool rpng_nbio_load_image_argb_iterate(uint8_t *buf, struct rpng_t *rpng)
{
unsigned i;
struct png_chunk chunk = {0};
if (!read_chunk_header(rpng->buff_data, &chunk))
rpng->chunk.size = 0;
rpng->chunk.type[0] = '\0';
if (!read_chunk_header(buf, &rpng->chunk))
return false;
#if 0
@ -182,7 +184,7 @@ bool rpng_nbio_load_image_argb_iterate(uint8_t *buf, struct rpng_t *rpng)
}
#endif
switch (png_chunk_type(&chunk))
switch (png_chunk_type(&rpng->chunk))
{
case PNG_CHUNK_NOOP:
default:
@ -195,7 +197,7 @@ bool rpng_nbio_load_image_argb_iterate(uint8_t *buf, struct rpng_t *rpng)
if (rpng->has_ihdr || rpng->has_idat || rpng->has_iend)
return false;
if (chunk.size != 13)
if (rpng->chunk.size != 13)
return false;
if (!png_parse_ihdr(buf, &rpng->ihdr))
@ -206,12 +208,12 @@ bool rpng_nbio_load_image_argb_iterate(uint8_t *buf, struct rpng_t *rpng)
case PNG_CHUNK_PLTE:
{
unsigned entries = chunk.size / 3;
unsigned entries = rpng->chunk.size / 3;
if (!rpng->has_ihdr || rpng->has_plte || rpng->has_iend || rpng->has_idat)
return false;
if (chunk.size % 3)
if (rpng->chunk.size % 3)
return false;
if (entries > 256)
@ -233,15 +235,15 @@ bool rpng_nbio_load_image_argb_iterate(uint8_t *buf, struct rpng_t *rpng)
if (!(rpng->has_ihdr) || rpng->has_iend || (rpng->ihdr.color_type == 3 && !(rpng->has_plte)))
return false;
if (!png_realloc_idat(&chunk, &rpng->idat_buf))
if (!png_realloc_idat(&rpng->chunk, &rpng->idat_buf))
return false;
buf += 8;
for (i = 0; i < chunk.size; i++)
for (i = 0; i < rpng->chunk.size; i++)
rpng->idat_buf.data[i + rpng->idat_buf.size] = buf[i];
rpng->idat_buf.size += chunk.size;
rpng->idat_buf.size += rpng->chunk.size;
rpng->has_idat = true;
break;
@ -254,8 +256,6 @@ bool rpng_nbio_load_image_argb_iterate(uint8_t *buf, struct rpng_t *rpng)
return false;
}
rpng->buff_data += 4 + 4 + chunk.size + 4;
return true;
}

@ -47,6 +47,8 @@ static bool rpng_nbio_load_image_argb(const char *path, uint32_t **data,
if (!rpng_nbio_load_image_argb_iterate(
rpng->buff_data, rpng))
break;
rpng->buff_data += 4 + 4 + rpng->chunk.size + 4;
}
#if 0

@ -42,6 +42,13 @@ struct idat_buffer
size_t size;
};
struct png_chunk
{
uint32_t size;
char type[4];
uint8_t *data;
};
struct png_ihdr
{
uint32_t width;
@ -65,6 +72,7 @@ struct rpng_t
size_t inflate_buf_size;
uint8_t *buff_data;
uint32_t palette[256];
struct png_chunk chunk;
void *userdata;
void *ptr;
};