phoboslab / qoi

The “Quite OK Image Format” for fast, lossless image compression
MIT License
6.94k stars 330 forks source link

Some potential optimisations #242

Closed HughPH closed 2 years ago

HughPH commented 2 years ago

Where we know the image has no alpha or a constant alpha, we can re-purpose QOI_OP_RGBA for 6-bit single channel delta: 111111111 + 2 bits per channel + 6 bits of delta 00 = R, 01 = G, 10 = B, 11 = All

I think it would need to be run on a large selection of example images to determine if it's a worthwhile change.

This works great on monochrome images (in my limited test) but with colour images the size reduction is insignificant in most cases. But qoi isn't designed for monochrome images. This could only be useful where qoi is used very generally.

More generally, we can amend QOI_OP_RUN so that a run length of 0 implies the next byte contains 8 bits of length. This has a benefit anywhere where there are runs of 125-255 (i.e. where we would otherwise need 3-5 QOI_OP_RUN chunks), and there is no additional storage for images where the feature isn't useful. I missed that length is offset by 1...