Hacker News new | ask | show | jobs
by ivoras 1247 days ago
Does anyone know why filtering is mandatory?

It seems like operations with the format would be a bit faster if the pre-compression data would just be a framebuffer dump, instead of prefixing each row with a 1-byte "filter ID", possibly breaking data alignment.

4 comments

I suspect even if you weren't using heuristics you would be best to pick a different static filter than "None". For example I would expect that "Up" does much better on average as you are essentially bringing in context that the compressor would struggle to line up. I think most encoders would probably only use "None" in cases where heuristics show that nothing else helps.

So it is probably mandatory because only a tiny minority of images wouldn't use a filter. So it is better to just require it to avoid one more condition in the decoder.

Adding 1 Byte to each line of raw pixel data is not that much. You can set it to zeros to avoid filtering. But it gives you a chance to improve the compression.
The assumption was that it improves compression of gradients and photographic data. In order for compressors to be able to use it, it has to be mandatory for decompressors. Anything that is optional becomes unusable (e.g. arithmetic coding in JPEG).

Filtering as a separate preprocessing step allowed PNG to use off-the-shelf zlib for compression without needing to modify it.

Can’t answer as to why it is mandatory but it is known to improve compression.