Split up deinit code from png_reverse_filter

This commit is contained in:
twinaphex 2015-02-25 20:43:12 +01:00
parent ef09b9a855
commit 3fc262ecac
3 changed files with 24 additions and 14 deletions

View File

@ -124,7 +124,6 @@ static bool png_reverse_filter(uint32_t *data, const struct png_ihdr *ihdr,
struct rpng_process_t *pngp) struct rpng_process_t *pngp)
{ {
unsigned i; unsigned i;
bool ret = true;
for (; pngp->h < ihdr->height; for (; pngp->h < ihdr->height;
pngp->h++, pngp->inflate_buf += pngp->pitch, data += ihdr->width) pngp->h++, pngp->inflate_buf += pngp->pitch, data += ihdr->width)
@ -173,7 +172,7 @@ static bool png_reverse_filter(uint32_t *data, const struct png_ihdr *ihdr,
break; break;
default: default:
GOTO_END_ERROR(); return false;
} }
if (ihdr->color_type == 0) if (ihdr->color_type == 0)
@ -192,9 +191,7 @@ static bool png_reverse_filter(uint32_t *data, const struct png_ihdr *ihdr,
memcpy(pngp->prev_scanline, pngp->decoded_scanline, pngp->pitch); memcpy(pngp->prev_scanline, pngp->decoded_scanline, pngp->pitch);
} }
end: return true;
png_reverse_filter_deinit(pngp);
return ret;
} }
static bool png_reverse_filter_adam7(uint32_t *data, static bool png_reverse_filter_adam7(uint32_t *data,
@ -213,6 +210,7 @@ static bool png_reverse_filter_adam7(uint32_t *data,
for (; pngp->pass < ARRAY_SIZE(passes); pngp->pass++) for (; pngp->pass < ARRAY_SIZE(passes); pngp->pass++)
{ {
bool ret = true;
unsigned pass_width, pass_height; unsigned pass_width, pass_height;
struct png_ihdr tmp_ihdr; struct png_ihdr tmp_ihdr;
uint32_t *tmp_data = NULL; uint32_t *tmp_data = NULL;
@ -245,8 +243,12 @@ static bool png_reverse_filter_adam7(uint32_t *data,
return false; return false;
} }
if (!png_reverse_filter(tmp_data, ret = png_reverse_filter(tmp_data,
&tmp_ihdr, pngp)) &tmp_ihdr, pngp);
png_reverse_filter_deinit(pngp);
if (ret)
{ {
free(tmp_data); free(tmp_data);
return false; return false;

View File

@ -353,8 +353,13 @@ bool rpng_load_image_argb(const char *path, uint32_t **data,
&rpng.ihdr, &pngp)) &rpng.ihdr, &pngp))
GOTO_END_ERROR(); GOTO_END_ERROR();
} }
else if (!png_reverse_filter(*data, else
&rpng.ihdr, &pngp)) ret = png_reverse_filter(*data,
&rpng.ihdr, &pngp);
png_reverse_filter_deinit(&pngp);
if (!ret)
GOTO_END_ERROR(); GOTO_END_ERROR();
end: end:

View File

@ -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, bool rpng_nbio_load_image_argb_process(struct rpng_t *rpng,
uint32_t **data, unsigned *width, unsigned *height) uint32_t **data, unsigned *width, unsigned *height)
{ {
bool ret = true;
struct rpng_process_t pngp = {0}; struct rpng_process_t pngp = {0};
z_stream stream = {0}; z_stream stream = {0};
@ -313,11 +314,13 @@ bool rpng_nbio_load_image_argb_process(struct rpng_t *rpng,
return false; return false;
} }
else else
{ ret = png_reverse_filter(*data,
if (!png_reverse_filter(*data, &rpng->ihdr, &pngp);
&rpng->ihdr, &pngp))
png_reverse_filter_deinit(&pngp);
if (!ret)
return false; return false;
}
return true; return true;
} }