Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does QOI support grayscale? #293

Open
dmikushin opened this issue Dec 28, 2023 · 4 comments
Open

Does QOI support grayscale? #293

dmikushin opened this issue Dec 28, 2023 · 4 comments

Comments

@dmikushin
Copy link

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

@phoboslab
Copy link
Owner

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?

@dmikushin
Copy link
Author

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

@schoebey
Copy link

schoebey commented Aug 8, 2024

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)

@dead-claudia
Copy link

dead-claudia commented Aug 15, 2024

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:

It's a sequence of the following 16-bit aligned words, all N little-endian:

  • 00nnnnnn nnnnnnnn: Emit most recent byte N+1 times
  • 00111111 nnnnnnnn nnnnnnnn nnnnnnnn: Emit most recent byte N+1 times
  • 01xxxxxx nnnnnnnn: Emit X+2-th most recent distinct byte N+1 times
  • 10nnnnnn xxxxxxxx: Emit specified byte N+1 times
  • 11xxxxxx nnnnnnnn: Emit most recent byte plus 6-bit signed X delta N+1 times
  • Max compression ratio: ~2^24 to 1
  • Min compression ratio: 0.5 to 1

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.

Edit: improve max compression, simplify loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants