Skip to content

Commit

Permalink
Move inflate_buf to rpng_process_t
Browse files Browse the repository at this point in the history
  • Loading branch information
inactive123 committed Feb 25, 2015
1 parent 4c7325c commit c970962
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
30 changes: 15 additions & 15 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, struct rpng_process_t *pngp,
struct rpng_process_t *pngp,
const uint32_t *palette)
{
unsigned i, h;
Expand All @@ -113,47 +113,47 @@ static bool png_reverse_filter(uint32_t *data, const struct png_ihdr *ihdr,
GOTO_END_ERROR();

for (h = 0; h < ihdr->height;
h++, inflate_buf += pitch, data += ihdr->width)
h++, pngp->inflate_buf += pitch, data += ihdr->width)
{
unsigned filter = *inflate_buf++;
unsigned filter = *pngp->inflate_buf++;

switch (filter)
{
case 0: /* None */
memcpy(decoded_scanline, inflate_buf, pitch);
memcpy(decoded_scanline, pngp->inflate_buf, pitch);
break;

case 1: /* Sub */
for (i = 0; i < bpp; i++)
decoded_scanline[i] = inflate_buf[i];
decoded_scanline[i] = pngp->inflate_buf[i];
for (i = bpp; i < pitch; i++)
decoded_scanline[i] = decoded_scanline[i - bpp] + inflate_buf[i];
decoded_scanline[i] = decoded_scanline[i - bpp] + pngp->inflate_buf[i];
break;

case 2: /* Up */
for (i = 0; i < pitch; i++)
decoded_scanline[i] = prev_scanline[i] + inflate_buf[i];
decoded_scanline[i] = prev_scanline[i] + pngp->inflate_buf[i];
break;

case 3: /* Average */
for (i = 0; i < bpp; i++)
{
uint8_t avg = prev_scanline[i] >> 1;
decoded_scanline[i] = avg + inflate_buf[i];
decoded_scanline[i] = avg + pngp->inflate_buf[i];
}
for (i = bpp; i < pitch; i++)
{
uint8_t avg = (decoded_scanline[i - bpp] + prev_scanline[i]) >> 1;
decoded_scanline[i] = avg + inflate_buf[i];
decoded_scanline[i] = avg + pngp->inflate_buf[i];
}
break;

case 4: /* Paeth */
for (i = 0; i < bpp; i++)
decoded_scanline[i] = paeth(0, prev_scanline[i], 0) + inflate_buf[i];
decoded_scanline[i] = paeth(0, prev_scanline[i], 0) + pngp->inflate_buf[i];
for (i = bpp; i < pitch; i++)
decoded_scanline[i] = paeth(decoded_scanline[i - bpp],
prev_scanline[i], prev_scanline[i - bpp]) + inflate_buf[i];
prev_scanline[i], prev_scanline[i - bpp]) + pngp->inflate_buf[i];
break;

default:
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, struct rpng_process_t *pngp,
struct rpng_process_t *pngp,
const uint32_t *palette)
{
unsigned pass;
Expand Down Expand Up @@ -234,14 +234,14 @@ static bool png_reverse_filter_adam7(uint32_t *data,
}

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

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

deinterlace_pass(data,
ihdr, tmp_data, pass_width, pass_height, &passes[pass]);
Expand Down
7 changes: 4 additions & 3 deletions libretro-common/formats/png/rpng_decode_fbio.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,16 +338,17 @@ bool rpng_load_image_argb(const char *path, uint32_t **data,
if (!*data)
GOTO_END_ERROR();

process.total_out = stream.total_out;
process.total_out = stream.total_out;
process.inflate_buf = rpng.inflate_buf;

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

end:
Expand Down
7 changes: 4 additions & 3 deletions libretro-common/formats/png/rpng_decode_fnbio.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,16 +297,17 @@ bool rpng_nbio_load_image_argb_process(struct rpng_t *rpng,
if (!*data)
return false;

process.total_out = stream.total_out;
process.total_out = stream.total_out;
process.inflate_buf = rpng->inflate_buf;

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

return true;
Expand Down
1 change: 1 addition & 0 deletions libretro-common/include/formats/rpng.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct png_ihdr

struct rpng_process_t
{
const uint8_t *inflate_buf;
size_t total_out;
};

Expand Down

0 comments on commit c970962

Please sign in to comment.