qoi icon indicating copy to clipboard operation
qoi copied to clipboard

Does QOI support grayscale?

Open dmikushin opened this issue 2 years ago • 5 comments

Hi, I wonder if the QOI format also covers grayscale? As I understood it is designed mainly for 3 and 4 channels.

dmikushin avatar Dec 28 '23 12:12 dmikushin

Support: yes, good at it: no. Of course you can encode grayscale images with qoi, but it will always use 3 channels for it. The resulting file size will be closer to uncompressed than PNG.

A "qoi-like" file format focusing on 1 channel sounds like a fun experiment though. Could probably get good results with storing small chunks as 4bit nibbles.

May I ask: what's your use-case?

phoboslab avatar Dec 28 '23 21:12 phoboslab

Hi @phoboslab , thanks ! My usecase is 5 GBytes of grayscale images from a high-speed industrial camera.

dmikushin avatar Dec 28 '23 23:12 dmikushin

same use-case here. Images from industrial cameras or artificial sources. 8-bit greyscale images of varying dimensions (~1k x 1k up to ~16k x 80k)

schoebey avatar Aug 08 '24 10:08 schoebey

I was exploring general data compression similar to QOI for small arbitrary data and I wanted something super simple, fast, and with reasonable compression.

I came up with this general-purpose (untested) compression format idea:

  • 00xxxxxx: Emit most recent byte plus 6-bit signed X delta.
  • 01xxxxxx nnnnnnnn: Emit X+2-th most recent distinct byte N+1 times
  • 10xxxxxx nnnnnnnn: Emit specified byte X+1 times
  • 11xxxxxx nnnnnnnn: Emit most recent byte plus 6-bit signed X delta N+3 times

Internal state: last 65 unique bytes emit, initially set to 0 for the first byte and the sequence 64 to 127 for the remaining bytes (to optimize for small ASCII strings).

There's no implicit end token like QOI has, but you can infer the end from your input, or you could modify one of the above to provide an "end" byte. If you shoved a QOI-like header plus this into a QOI image format, it may do the trick.

Keep in mind, I've not done any experiments, so this is just all words on a page. But I am curious what you all might see with compression ratios using this.

dead-claudia avatar Aug 15 '24 00:08 dead-claudia