stb_image: Fix PNG initial size guess for 1/2/4 bpc.

This commit is contained in:
Fabian Giesen 2014-12-24 10:15:28 +01:00
parent fb109abeaf
commit d92ab86c65

View File

@ -4275,12 +4275,13 @@ static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp)
}
case STBI__PNG_TYPE('I','E','N','D'): {
stbi__uint32 raw_len;
stbi__uint32 raw_len, bpl;
if (first) return stbi__err("first not IHDR", "Corrupt PNG");
if (scan != STBI__SCAN_load) return 1;
if (z->idata == NULL) return stbi__err("no IDAT","Corrupt PNG");
// initial guess for decoded data size to avoid unnecessary reallocs
raw_len = s->img_x * s->img_y * s->img_n /* pixels */ + s->img_y /* filter mode per row */;
bpl = (s->img_x * depth + 7) / 8; // bytes per line, per component
raw_len = bpl * s->img_y * s->img_n /* pixels */ + s->img_y /* filter mode per row */;
z->expanded = (stbi_uc *) stbi_zlib_decode_malloc_guesssize_headerflag((char *) z->idata, ioff, raw_len, (int *) &raw_len, !is_iphone);
if (z->expanded == NULL) return 0; // zlib should set error
STBI_FREE(z->idata); z->idata = NULL;