mirror of
https://github.com/libretro/RetroArch
synced 2025-03-23 01:21:47 +00:00
Take chunk_type out of struct
This commit is contained in:
parent
642a5ddb40
commit
a27c0714cb
@ -98,14 +98,13 @@ static bool png_read_plte_into_buf(uint8_t *buf,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool rpng_nbio_load_image_argb_iterate(uint8_t *buf, struct rpng_t *rpng)
|
||||
bool rpng_nbio_load_image_argb_iterate(uint8_t *buf, struct rpng_t *rpng, unsigned *ret)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
rpng->chunk.size = 0;
|
||||
rpng->chunk.type[0] = '\0';
|
||||
struct png_chunk chunk = {0};
|
||||
|
||||
if (!read_chunk_header(buf, &rpng->chunk))
|
||||
if (!read_chunk_header(buf, &chunk))
|
||||
return false;
|
||||
|
||||
#if 0
|
||||
@ -115,43 +114,43 @@ bool rpng_nbio_load_image_argb_iterate(uint8_t *buf, struct rpng_t *rpng)
|
||||
}
|
||||
#endif
|
||||
|
||||
switch (png_chunk_type(&rpng->chunk))
|
||||
switch (png_chunk_type(&chunk))
|
||||
{
|
||||
case PNG_CHUNK_NOOP:
|
||||
default:
|
||||
break;
|
||||
|
||||
case PNG_CHUNK_ERROR:
|
||||
return false;
|
||||
goto error;
|
||||
|
||||
case PNG_CHUNK_IHDR:
|
||||
if (rpng->has_ihdr || rpng->has_idat || rpng->has_iend)
|
||||
return false;
|
||||
goto error;
|
||||
|
||||
if (rpng->chunk.size != 13)
|
||||
return false;
|
||||
if (chunk.size != 13)
|
||||
goto error;
|
||||
|
||||
if (!png_parse_ihdr(buf, &rpng->ihdr))
|
||||
return false;
|
||||
goto error;
|
||||
|
||||
if (!png_process_ihdr(&rpng->ihdr))
|
||||
return false;
|
||||
goto error;
|
||||
|
||||
rpng->has_ihdr = true;
|
||||
break;
|
||||
|
||||
case PNG_CHUNK_PLTE:
|
||||
{
|
||||
unsigned entries = rpng->chunk.size / 3;
|
||||
unsigned entries = chunk.size / 3;
|
||||
|
||||
if (!rpng->has_ihdr || rpng->has_plte || rpng->has_iend || rpng->has_idat)
|
||||
return false;
|
||||
goto error;
|
||||
|
||||
if (rpng->chunk.size % 3)
|
||||
return false;
|
||||
if (chunk.size % 3)
|
||||
goto error;
|
||||
|
||||
if (!png_read_plte_into_buf(buf, rpng->palette, entries))
|
||||
return false;
|
||||
goto error;
|
||||
|
||||
rpng->has_plte = true;
|
||||
}
|
||||
@ -159,30 +158,35 @@ bool rpng_nbio_load_image_argb_iterate(uint8_t *buf, struct rpng_t *rpng)
|
||||
|
||||
case PNG_CHUNK_IDAT:
|
||||
if (!(rpng->has_ihdr) || rpng->has_iend || (rpng->ihdr.color_type == PNG_IHDR_COLOR_PLT && !(rpng->has_plte)))
|
||||
return false;
|
||||
goto error;
|
||||
|
||||
if (!png_realloc_idat(&rpng->chunk, &rpng->idat_buf))
|
||||
return false;
|
||||
if (!png_realloc_idat(&chunk, &rpng->idat_buf))
|
||||
goto error;
|
||||
|
||||
buf += 8;
|
||||
|
||||
for (i = 0; i < rpng->chunk.size; i++)
|
||||
for (i = 0; i < chunk.size; i++)
|
||||
rpng->idat_buf.data[i + rpng->idat_buf.size] = buf[i];
|
||||
|
||||
rpng->idat_buf.size += rpng->chunk.size;
|
||||
rpng->idat_buf.size += chunk.size;
|
||||
|
||||
rpng->has_idat = true;
|
||||
break;
|
||||
|
||||
case PNG_CHUNK_IEND:
|
||||
if (!(rpng->has_ihdr) || !(rpng->has_idat))
|
||||
return false;
|
||||
goto error;
|
||||
|
||||
rpng->has_iend = true;
|
||||
return false;
|
||||
goto error;
|
||||
}
|
||||
|
||||
*ret = 4 + 4 + chunk.size + 4;
|
||||
|
||||
return true;
|
||||
|
||||
error:
|
||||
return false;
|
||||
}
|
||||
|
||||
int rpng_nbio_load_image_argb_process(struct rpng_t *rpng,
|
||||
|
@ -46,6 +46,7 @@ static bool rpng_nbio_load_image_argb(const char *path, uint32_t **data,
|
||||
bool ret = true;
|
||||
struct rpng_t *rpng = NULL;
|
||||
void *ptr = NULL;
|
||||
unsigned val = 0;
|
||||
struct nbio_t* handle = (void*)nbio_open(path, NBIO_READ);
|
||||
|
||||
if (!handle)
|
||||
@ -88,9 +89,9 @@ static bool rpng_nbio_load_image_argb(const char *path, uint32_t **data,
|
||||
}
|
||||
|
||||
while (rpng_nbio_load_image_argb_iterate(
|
||||
rpng->buff_data, rpng))
|
||||
rpng->buff_data, rpng, &val))
|
||||
{
|
||||
rpng->buff_data += 4 + 4 + rpng->chunk.size + 4;
|
||||
rpng->buff_data += val;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
@ -98,7 +98,6 @@ struct rpng_t
|
||||
struct png_ihdr ihdr;
|
||||
uint8_t *buff_data;
|
||||
uint32_t palette[256];
|
||||
struct png_chunk chunk;
|
||||
};
|
||||
|
||||
bool rpng_load_image_argb(const char *path, uint32_t **data,
|
||||
@ -109,7 +108,7 @@ 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);
|
||||
struct rpng_t *rpng, unsigned *ret);
|
||||
|
||||
int rpng_nbio_load_image_argb_process(struct rpng_t *rpng,
|
||||
uint32_t **data, unsigned *width, unsigned *height);
|
||||
|
@ -441,13 +441,13 @@ static int rarch_main_data_image_iterate_transfer(nbio_handle_t *nbio)
|
||||
|
||||
for (i = 0; i < nbio->image.pos_increment; i++)
|
||||
{
|
||||
unsigned ret;
|
||||
if (!rpng_nbio_load_image_argb_iterate(
|
||||
nbio->image.handle->buff_data,
|
||||
nbio->image.handle))
|
||||
nbio->image.handle, &ret))
|
||||
goto error;
|
||||
|
||||
nbio->image.handle->buff_data +=
|
||||
4 + 4 + nbio->image.handle->chunk.size + 4;
|
||||
nbio->image.handle->buff_data += ret;
|
||||
}
|
||||
|
||||
nbio->image.frame_count++;
|
||||
|
Loading…
x
Reference in New Issue
Block a user