3 ms·
It's effective, but it's not /very/ effective. A 1D byte-level compression like deflate is an inappropriate tool for images. As an experiment I just opened a s
by astrange 11y ago
It's effective, but it's not /very/ effective. A 1D byte-level compression like deflate is an inappropriate tool for images.
As an experiment I just opened a screenshot in Preview.app and exported to PNG with and without an alpha channel - adding alpha makes it 335KB vs 300KB. Since the alpha contains no information, there's no excuse for it to be 30KB compressed!
ffv1 or your favorite video codec with a lossless mode will produce much smaller files and decode much faster than png.
- derefr 11y ago> 1D byte-level compression Now you've got me curious what the compression ratio would be if you just re-ordered an image's pixels using a Hilbert curve (so that in e.g. a 100x100 image, the first 100px scanline contains the first 100px of the Hilbert path through the original image) before passing it to PNG for compression.
- derefr 11y agoReplying to myself because I just tested it. • Lenna.png (http://i.imgur.com/pPNbiyG.png http://i.imgur.com/pPNbiyG.png): 475KB. • Lenna.Hilbertized.png (http://i.imgur.com/kU8C3yG.png http://i.imgur.com/kU8C3yG.png): 709KB. Clearly, not a good idea, at least for photographic sources.
- astrange 11y agoThat idea isn't too bad, it probably works most places but fails very badly in a few spots. So it might be good for lossy compression - I actually tried this once, but lost the code a while back... In this case, PNG's filtering makes it kind of 2D-aware, so that probably works better on the original. But if you tried splitting it into 8x8 blocks, then predicting each one from the left-upperleft-upper neighbors, well, you'd have the basics to modern DCT codecs.
- poizan42 11y agoIt interferes with the filtering. You should try to first filter, then "Hilbertize" and then deflate
- maxst 11y agoPaeth filter helps. This PNG is only 251 bytes: https://upload.wikimedia.org/wikipedia/commons/8/89/PNG-Gradient.png https://upload.wikimedia.org/wikipedia/commons/8/89/PNG-Grad...
- versteegen 11y agoIn my own experiments compressing pixel art, I found that gzipped .bmp files were smaller than the output of pngcrush just as often as they were larger. On average the pngs were slightly smaller, but you can tar together a whole bunch of similar bmps and gzip the lot, and then gzip really blows png out of the water. For a compressed file format specialised for images, I found png's performance very disappointing and decided not to use it.