Skip to content

Commit

Permalink
Create rpng_process_t
Browse files Browse the repository at this point in the history
  • Loading branch information
inactive123 committed Feb 25, 2015
1 parent c07bab4 commit 4c7325c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
12 changes: 6 additions & 6 deletions libretro-common/formats/png/rpng_decode_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static void deinterlace_pass(uint32_t *data, const struct png_ihdr *ihdr,
}

static bool png_reverse_filter(uint32_t *data, const struct png_ihdr *ihdr,
const uint8_t *inflate_buf, size_t inflate_buf_size,
const uint8_t *inflate_buf, struct rpng_process_t *pngp,
const uint32_t *palette)
{
unsigned i, h;
Expand All @@ -103,7 +103,7 @@ static bool png_reverse_filter(uint32_t *data, const struct png_ihdr *ihdr,

png_pass_geom(ihdr, ihdr->width, ihdr->height, &bpp, &pitch, &pass_size);

if (inflate_buf_size < pass_size)
if (pngp->total_out < pass_size)
return false;

prev_scanline = (uint8_t*)calloc(1, pitch);
Expand Down Expand Up @@ -184,7 +184,7 @@ static bool png_reverse_filter(uint32_t *data, const struct png_ihdr *ihdr,

static bool png_reverse_filter_adam7(uint32_t *data,
const struct png_ihdr *ihdr,
const uint8_t *inflate_buf, size_t inflate_buf_size,
const uint8_t *inflate_buf, struct rpng_process_t *pngp,
const uint32_t *palette)
{
unsigned pass;
Expand Down Expand Up @@ -227,21 +227,21 @@ static bool png_reverse_filter_adam7(uint32_t *data,
png_pass_geom(&tmp_ihdr, pass_width,
pass_height, NULL, NULL, &pass_size);

if (pass_size > inflate_buf_size)
if (pass_size > pngp->total_out)
{
free(tmp_data);
return false;
}

if (!png_reverse_filter(tmp_data,
&tmp_ihdr, inflate_buf, pass_size, palette))
&tmp_ihdr, inflate_buf, pngp, palette))
{
free(tmp_data);
return false;
}

inflate_buf += pass_size;
inflate_buf_size -= pass_size;
pngp->total_out -= pass_size;

deinterlace_pass(data,
ihdr, tmp_data, pass_width, pass_height, &passes[pass]);
Expand Down
7 changes: 5 additions & 2 deletions libretro-common/formats/png/rpng_decode_fbio.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ bool rpng_load_image_argb(const char *path, uint32_t **data,
char header[8];
z_stream stream = {0};
struct rpng_t rpng = {0};
struct rpng_process_t process = {0};
bool ret = true;

*data = NULL;
Expand Down Expand Up @@ -337,14 +338,16 @@ bool rpng_load_image_argb(const char *path, uint32_t **data,
if (!*data)
GOTO_END_ERROR();

process.total_out = stream.total_out;

if (rpng.ihdr.interlace == 1)
{
if (!png_reverse_filter_adam7(*data,
&rpng.ihdr, rpng.inflate_buf, stream.total_out, rpng.palette))
&rpng.ihdr, rpng.inflate_buf, &process, rpng.palette))
GOTO_END_ERROR();
}
else if (!png_reverse_filter(*data,
&rpng.ihdr, rpng.inflate_buf, stream.total_out, rpng.palette))
&rpng.ihdr, rpng.inflate_buf, &process, rpng.palette))
GOTO_END_ERROR();

end:
Expand Down
7 changes: 5 additions & 2 deletions libretro-common/formats/png/rpng_decode_fnbio.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ 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};
z_stream stream = {0};

if (inflateInit(&stream) != Z_OK)
Expand Down Expand Up @@ -296,14 +297,16 @@ bool rpng_nbio_load_image_argb_process(struct rpng_t *rpng,
if (!*data)
return false;

process.total_out = stream.total_out;

if (rpng->ihdr.interlace == 1)
{
if (!png_reverse_filter_adam7(*data,
&rpng->ihdr, rpng->inflate_buf, stream.total_out, rpng->palette))
&rpng->ihdr, rpng->inflate_buf, &process, rpng->palette))
return false;
}
else if (!png_reverse_filter(*data,
&rpng->ihdr, rpng->inflate_buf, stream.total_out, rpng->palette))
&rpng->ihdr, rpng->inflate_buf, &process, rpng->palette))
return false;

return true;
Expand Down
5 changes: 5 additions & 0 deletions libretro-common/include/formats/rpng.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ struct png_ihdr
uint8_t interlace;
};

struct rpng_process_t
{
size_t total_out;
};

struct rpng_t
{
bool has_ihdr;
Expand Down

0 comments on commit 4c7325c

Please sign in to comment.