-
Notifications
You must be signed in to change notification settings - Fork 21
Description
This issue is to potentially resurrect an idea I had about filtering 16 bit per component images back at the dawn of PNG, but didn't investigate (and dropped, because an MVP of PNG that actually got implemented was more important). At the time, working in a computer graphics lab, we were making a bunch of 16 bit/component images, which were stored as TIFF, and we wanted to use PNG to migrate away from no-longer-free LZW compressed TIFF. We got that, but the sub-optimal filtering bugged me
The existing filter methods in PNG are all oriented towards 8bit/component greyscale and truecolor images. They are defined on bytes, and the spec says to use filter 0 (None) for images with less than 8bits/component.
For images of color type 3 (indexed-color), filter type 0 (None) is usually the most effective. Color images with 256 or fewer colors should almost always be stored in indexed-color format; truecolor format is likely to be much larger.
Filter type 0 is also recommended for images of bit depths less than 8. For low-bit-depth greyscale images, in rare cases, better compression may be obtained by first expanding the image to 8-bit representation and then applying filtering.
For truecolor and greyscale images, any of the five filters may prove the most effective. If an encoder uses a fixed filter, the Paeth filter type is most likely to be the best.
12.7 Filter selection
So they work, but not very well, on 16bit/component data; typically filter type 0 (None) is the most effective even though they are truecolor. This is because 16bit/component data is stored as interleaved MSB, LSB which kills compression efficiency.
I wondered at the time about another filter method, with one or more filter types, which firstly, de-interleaves the image data: on each scanline to be filtered, you get an 8-bit MSB scanline and an 8-bit LSB scanline. The existing filters, or new ones, are then used on the de-interleaved data before it is compressed.
Decompression works the same way, and undoing the filtering re-interleaves the image data.
Adding a new filter method is not backwards compatible with existing decoders. Adding a new filter type for the existing filter method 0 is also not allowed
So the filesize benefits would need to be significant, compared to:
- using a different image format with better lossless compression
- using unfiltered 16bit data
- using unfiltered 16bit data and relying on
sBITto say the depth is 10, or 12 - using a backwards-compatible but hacky way to redefine existing data, like pretending 10-10-10-2 is actually 8-8-8-8
So this might not work; or might work but not well enough to justify doing. At least worth exploring, though.