compression - Is there some way to predict png size? -
i implementing clipboard, , want allocate memory png image 1 time. there way predict maximum size of png file?
a png image includes several things:
- signature , basic metadata (image size , type)
- palette (only if image indexed)
- raw pixel data
- optional metadata (ancillary chunks)
- end of image chunk
size of item 1 fixed: 8 + 12 + 11 = 31 bytes
size of item 2 (if required) @ 12 + 3 * 256 = 780 bytes
size of item 5 fixed: 12 bytes
item 3, raw pixels data, important one. filtered-uncompressed data amounts
fud=(w*c*8/bpc+1)*h bytes
where w=width in pixels, h=height in pixels, c=channels (3 if rgb, 1 if palette or grayscale, 4 if rgba, 2 if ga), bpc=bits per channel (normally 8)
that compressed zlib. it's practically impossible bound precisely worst case compression rate. in practice, 1 might assume in worst case compressed stream have few bytes more original. item 3 size approximately bound (again assuming small idat chunk size of 8192 bytes) by
(fud + 6)(1 + 12/8192) ~ fud
item 4 (ancillary chunk data) practically impossible bound.
Comments
Post a Comment