mirror of
https://github.com/nothings/stb
synced 2024-12-15 12:22:55 +03:00
stb_image: Fix PNG initial size guess for 1/2/4 bpc.
This commit is contained in:
parent
fb109abeaf
commit
d92ab86c65
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user