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:

  1. signature , basic metadata (image size , type)
  2. palette (only if image indexed)
  3. raw pixel data
  4. optional metadata (ancillary chunks)
  5. 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

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -