How to create PNG files optimized for being compression-friendly? I.e. would it help if image is created (mostly) from 8x8 unicolor blocks?
-
$\begingroup$ It depends how much control you have over the image. e.g. making all your images 1 pixel large would have a huge benefit, but that probably isn't useful to you. $\endgroup$– Dan HulmeOct 12, 2016 at 10:33
-
$\begingroup$ @DanHulme I'm thinking about quality-loss optimization of existing PNG images. The questions is: how to process such images. First idea - pixelize with unicolor blocks. Second idea - decrease palette to have possibly big unicolor shapes. Or maybe something else. I don't know how PNG compression works and what change will result with best effect. $\endgroup$– tomashOct 12, 2016 at 10:50
-
$\begingroup$ PNG is not stored in blocks, so no that is useful but not optimal $\endgroup$– joojaaOct 12, 2016 at 10:52
1 Answer
PNG format is lossless format where for compression the image is first "filtered" and this filtered image is then passed to DEFLATE lossless compression algorithm. The purpose of filtering stage is to make the image more compressible by DEFLATE and current method uses delta-compression from previously decoded pixels.
So if your plan is to pre-process the image in some lossy way, then if you can reduce the deltas so that the following entropy encoding can benefit from it, then you get better compression ratio. For example "blockifying" the image as you suggested would only require more storage for the top-left pixel in the block while the deltas for the remaining pixels would be zero, which DEFLATE can compress very efficiently. This same would apply to any continuous constant color regions.