mirror of
https://github.com/libretro/RetroArch
synced 2025-03-29 22:20:21 +00:00
Move png_ihdr to rpng_t struct
This commit is contained in:
parent
538b3f3231
commit
193fef41cc
@ -215,7 +215,6 @@ bool rpng_load_image_argb(const char *path, uint32_t **data,
|
||||
char header[8];
|
||||
size_t inflate_buf_size = 0;
|
||||
z_stream stream = {0};
|
||||
struct png_ihdr ihdr = {0};
|
||||
uint32_t palette[256] = {0};
|
||||
struct rpng_t rpng = {0};
|
||||
bool ret = true;
|
||||
@ -262,7 +261,7 @@ bool rpng_load_image_argb(const char *path, uint32_t **data,
|
||||
if (rpng.has_ihdr || rpng.has_idat || rpng.has_iend)
|
||||
GOTO_END_ERROR();
|
||||
|
||||
if (!png_parse_ihdr_fio(file, &chunk, &ihdr))
|
||||
if (!png_parse_ihdr_fio(file, &chunk, &rpng.ihdr))
|
||||
GOTO_END_ERROR();
|
||||
|
||||
rpng.has_ihdr = true;
|
||||
@ -282,7 +281,7 @@ bool rpng_load_image_argb(const char *path, uint32_t **data,
|
||||
break;
|
||||
|
||||
case PNG_CHUNK_IDAT:
|
||||
if (!rpng.has_ihdr || rpng.has_iend || (ihdr.color_type == 3 && !rpng.has_plte))
|
||||
if (!rpng.has_ihdr || rpng.has_iend || (rpng.ihdr.color_type == 3 && !rpng.has_plte))
|
||||
GOTO_END_ERROR();
|
||||
|
||||
if (!png_append_idat_fio(file, &chunk, &rpng.idat_buf))
|
||||
@ -309,8 +308,8 @@ bool rpng_load_image_argb(const char *path, uint32_t **data,
|
||||
if (inflateInit(&stream) != Z_OK)
|
||||
GOTO_END_ERROR();
|
||||
|
||||
png_pass_geom(&ihdr, ihdr.width, ihdr.height, NULL, NULL, &inflate_buf_size);
|
||||
if (ihdr.interlace == 1) /* To be sure. */
|
||||
png_pass_geom(&rpng.ihdr, rpng.ihdr.width, rpng.ihdr.height, NULL, NULL, &inflate_buf_size);
|
||||
if (rpng.ihdr.interlace == 1) /* To be sure. */
|
||||
inflate_buf_size *= 2;
|
||||
|
||||
rpng.inflate_buf = (uint8_t*)malloc(inflate_buf_size);
|
||||
@ -329,25 +328,25 @@ bool rpng_load_image_argb(const char *path, uint32_t **data,
|
||||
}
|
||||
inflateEnd(&stream);
|
||||
|
||||
*width = ihdr.width;
|
||||
*height = ihdr.height;
|
||||
*width = rpng.ihdr.width;
|
||||
*height = rpng.ihdr.height;
|
||||
#ifdef GEKKO
|
||||
/* we often use these in textures, make sure they're 32-byte aligned */
|
||||
*data = (uint32_t*)memalign(32, ihdr.width * ihdr.height * sizeof(uint32_t));
|
||||
*data = (uint32_t*)memalign(32, rpng.ihdr.width * rpng.ihdr.height * sizeof(uint32_t));
|
||||
#else
|
||||
*data = (uint32_t*)malloc(ihdr.width * ihdr.height * sizeof(uint32_t));
|
||||
*data = (uint32_t*)malloc(rpng.ihdr.width * rpng.ihdr.height * sizeof(uint32_t));
|
||||
#endif
|
||||
if (!*data)
|
||||
GOTO_END_ERROR();
|
||||
|
||||
if (ihdr.interlace == 1)
|
||||
if (rpng.ihdr.interlace == 1)
|
||||
{
|
||||
if (!png_reverse_filter_adam7(*data,
|
||||
&ihdr, rpng.inflate_buf, stream.total_out, palette))
|
||||
&rpng.ihdr, rpng.inflate_buf, stream.total_out, palette))
|
||||
GOTO_END_ERROR();
|
||||
}
|
||||
else if (!png_reverse_filter(*data,
|
||||
&ihdr, rpng.inflate_buf, stream.total_out, palette))
|
||||
&rpng.ihdr, rpng.inflate_buf, stream.total_out, palette))
|
||||
GOTO_END_ERROR();
|
||||
|
||||
end:
|
||||
|
@ -47,17 +47,6 @@ struct png_chunk
|
||||
uint8_t *data;
|
||||
};
|
||||
|
||||
struct png_ihdr
|
||||
{
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint8_t depth;
|
||||
uint8_t color_type;
|
||||
uint8_t compression;
|
||||
uint8_t filter;
|
||||
uint8_t interlace;
|
||||
};
|
||||
|
||||
enum png_chunk_type
|
||||
{
|
||||
PNG_CHUNK_NOOP = 0,
|
||||
|
@ -319,7 +319,6 @@ bool rpng_nbio_load_image_argb(const char *path, uint32_t **data,
|
||||
{
|
||||
size_t file_len;
|
||||
struct nbio_t* nbread = NULL;
|
||||
struct png_ihdr ihdr = {0};
|
||||
uint32_t palette[256] = {0};
|
||||
struct rpng_t rpng = {0};
|
||||
bool ret = true;
|
||||
@ -360,7 +359,7 @@ bool rpng_nbio_load_image_argb(const char *path, uint32_t **data,
|
||||
GOTO_END_ERROR();
|
||||
|
||||
if (!rpng_nbio_load_image_argb_iterate(
|
||||
rpng.buff_data, &chunk, palette, &ihdr,
|
||||
rpng.buff_data, &chunk, palette, &rpng.ihdr,
|
||||
&rpng))
|
||||
break;
|
||||
|
||||
@ -377,7 +376,7 @@ bool rpng_nbio_load_image_argb(const char *path, uint32_t **data,
|
||||
GOTO_END_ERROR();
|
||||
|
||||
rpng_nbio_load_image_argb_process(&rpng,
|
||||
&ihdr, data, palette,
|
||||
&rpng.ihdr, data, palette,
|
||||
width, height);
|
||||
|
||||
end:
|
||||
|
@ -42,6 +42,17 @@ struct idat_buffer
|
||||
size_t size;
|
||||
};
|
||||
|
||||
struct png_ihdr
|
||||
{
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint8_t depth;
|
||||
uint8_t color_type;
|
||||
uint8_t compression;
|
||||
uint8_t filter;
|
||||
uint8_t interlace;
|
||||
};
|
||||
|
||||
struct rpng_t
|
||||
{
|
||||
bool has_ihdr;
|
||||
@ -49,6 +60,7 @@ struct rpng_t
|
||||
bool has_iend;
|
||||
bool has_plte;
|
||||
struct idat_buffer idat_buf;
|
||||
struct png_ihdr ihdr;
|
||||
uint8_t *inflate_buf;
|
||||
uint8_t *buff_data;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user