Make process a part of rpng_t

This commit is contained in:
twinaphex 2015-02-26 03:49:35 +01:00
parent 05e33f1ac4
commit 0006f0a429
4 changed files with 42 additions and 39 deletions

View File

@ -211,8 +211,7 @@ bool rpng_load_image_argb(const char *path, uint32_t **data,
long pos, file_len;
FILE *file;
char header[8];
struct rpng_t rpng = {0};
struct rpng_process_t process = {{0}};
struct rpng_t rpng = {{0}};
bool ret = true;
*data = NULL;
@ -301,28 +300,28 @@ 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 (inflateInit(&process.stream) != Z_OK)
if (inflateInit(&rpng.process.stream) != Z_OK)
GOTO_END_ERROR();
png_pass_geom(&rpng.ihdr, rpng.ihdr.width, rpng.ihdr.height, NULL, NULL, &rpng.inflate_buf_size);
png_pass_geom(&rpng.ihdr, rpng.ihdr.width, rpng.ihdr.height, NULL, NULL, &rpng.process.inflate_buf_size);
if (rpng.ihdr.interlace == 1) /* To be sure. */
rpng.inflate_buf_size *= 2;
rpng.process.inflate_buf_size *= 2;
rpng.inflate_buf = (uint8_t*)malloc(rpng.inflate_buf_size);
if (!rpng.inflate_buf)
rpng.process.inflate_buf = (uint8_t*)malloc(rpng.process.inflate_buf_size);
if (!rpng.process.inflate_buf)
GOTO_END_ERROR();
process.stream.next_in = rpng.idat_buf.data;
process.stream.avail_in = rpng.idat_buf.size;
process.stream.avail_out = rpng.inflate_buf_size;
process.stream.next_out = rpng.inflate_buf;
rpng.process.stream.next_in = rpng.idat_buf.data;
rpng.process.stream.avail_in = rpng.idat_buf.size;
rpng.process.stream.avail_out = rpng.process.inflate_buf_size;
rpng.process.stream.next_out = rpng.process.inflate_buf;
if (inflate(&process.stream, Z_FINISH) != Z_STREAM_END)
if (inflate(&rpng.process.stream, Z_FINISH) != Z_STREAM_END)
{
inflateEnd(&process.stream);
inflateEnd(&rpng.process.stream);
GOTO_END_ERROR();
}
inflateEnd(&process.stream);
inflateEnd(&rpng.process.stream);
*width = rpng.ihdr.width;
*height = rpng.ihdr.height;
@ -338,11 +337,11 @@ bool rpng_load_image_argb(const char *path, uint32_t **data,
if (rpng.ihdr.interlace == 1)
{
if (!png_reverse_filter_adam7(*data,
&rpng.ihdr, rpng.inflate_buf, &process, rpng.palette))
&rpng.ihdr, rpng.process.inflate_buf, &rpng.process, rpng.palette))
GOTO_END_ERROR();
}
else if (!png_reverse_filter(*data,
&rpng.ihdr, rpng.inflate_buf, &process, rpng.palette))
&rpng.ihdr, rpng.process.inflate_buf, &rpng.process, rpng.palette))
GOTO_END_ERROR();
end:
@ -351,6 +350,6 @@ end:
if (!ret)
free(*data);
free(rpng.idat_buf.data);
free(rpng.inflate_buf);
free(rpng.process.inflate_buf);
return ret;
}

View File

@ -255,31 +255,37 @@ 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)
{
struct rpng_process_t process = {{0}};
if (!rpng)
return false;
if (inflateInit(&process.stream) != Z_OK)
struct rpng_process_t *process = &rpng->process;
process->inflate_buf_size = 0;
process->inflate_buf = NULL;
if (inflateInit(&process->stream) != Z_OK)
return false;
png_pass_geom(&rpng->ihdr, rpng->ihdr.width,
rpng->ihdr.height, NULL, NULL, &rpng->inflate_buf_size);
rpng->ihdr.height, NULL, NULL, &process->inflate_buf_size);
if (rpng->ihdr.interlace == 1) /* To be sure. */
rpng->inflate_buf_size *= 2;
process->inflate_buf_size *= 2;
rpng->inflate_buf = (uint8_t*)malloc(rpng->inflate_buf_size);
if (!rpng->inflate_buf)
process->inflate_buf = (uint8_t*)malloc(process->inflate_buf_size);
if (!process->inflate_buf)
return false;
process.stream.next_in = rpng->idat_buf.data;
process.stream.avail_in = rpng->idat_buf.size;
process.stream.avail_out = rpng->inflate_buf_size;
process.stream.next_out = rpng->inflate_buf;
process->stream.next_in = rpng->idat_buf.data;
process->stream.avail_in = rpng->idat_buf.size;
process->stream.avail_out = process->inflate_buf_size;
process->stream.next_out = process->inflate_buf;
if (inflate(&process.stream, Z_FINISH) != Z_STREAM_END)
if (inflate(&process->stream, Z_FINISH) != Z_STREAM_END)
{
inflateEnd(&process.stream);
inflateEnd(&process->stream);
return false;
}
inflateEnd(&process.stream);
inflateEnd(&process->stream);
*width = rpng->ihdr.width;
*height = rpng->ihdr.height;
@ -297,11 +303,11 @@ bool rpng_nbio_load_image_argb_process(struct rpng_t *rpng,
if (rpng->ihdr.interlace == 1)
{
if (!png_reverse_filter_adam7(*data,
&rpng->ihdr, rpng->inflate_buf, &process, rpng->palette))
&rpng->ihdr, process->inflate_buf, process, rpng->palette))
return false;
}
else if (!png_reverse_filter(*data,
&rpng->ihdr, rpng->inflate_buf, &process, rpng->palette))
&rpng->ihdr, process->inflate_buf, process, rpng->palette))
return false;
return true;
@ -314,8 +320,8 @@ void rpng_nbio_load_image_free(struct rpng_t *rpng)
if (rpng->idat_buf.data)
free(rpng->idat_buf.data);
if (rpng->inflate_buf)
free(rpng->inflate_buf);
if (rpng->process.inflate_buf)
free(rpng->process.inflate_buf);
if (rpng)
free(rpng);

View File

@ -63,19 +63,20 @@ struct png_ihdr
struct rpng_process_t
{
uint8_t *inflate_buf;
size_t inflate_buf_size;
z_stream stream;
};
struct rpng_t
{
struct rpng_process_t process;
bool has_ihdr;
bool has_idat;
bool has_iend;
bool has_plte;
struct idat_buffer idat_buf;
struct png_ihdr ihdr;
uint8_t *inflate_buf;
size_t inflate_buf_size;
uint8_t *buff_data;
uint32_t palette[256];
struct png_chunk chunk;

View File

@ -1,8 +1,5 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2015 - Daniel De Matteis
* Copyright (C) 2012-2015 - Michael Lelli
* Copyright (C) 2014-2015 - Jay McCarthy
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-