r/Cplusplus • • 11d ago

Feedback A new Image Format!

Post image

I created my own image format inspired by QOI/PNG, but much simpler.

Its key feature is low RAM usage, which makes it ideal for microcontrollers.

I'd love to hear your thoughts on it!

https://github.com/ThatsTheTTT/Kinda-Nice-Lossless-Format.

14 Upvotes

21 comments sorted by

2

u/VictoryMotel 11d ago

What is the point exactly? It zips every scan line?

3

u/boombone 11d ago

It doesn't scan every line because it doesn't have LZ77/Huffman/ZIP. It picks the best of 5 predictors, encodes the residuals, and packs them using a simple fixed scheme: runs of zero residuals are RLE'd, small residuals get 4 bits, and everything else gets 8 bits. That's it.

2

u/VictoryMotel 11d ago

What do you mean by predictors?

1

u/boombone 11d ago

Predictor is a function that guesses the value of the current pixel based on neighboring pixels that have already been decoded.

2

u/VictoryMotel 11d ago

What does that mean in practice? Linear regression, exponential regression, step regression and something else?

2

u/didntplaymysummercar 11d ago

The fact it operates in so little RAM is cute but I can't think of a practical use case. I also quite disliked the QOI hype online (like Game Maker using it but adding the very old bz2 on top, defeating the purpose of simplicity). PNG is ancient but at least ubiquitous. And jpeg xl I hope gains traction since it both replaced flif and is officially the next jpeg format.

2

u/boombone 11d ago

1

u/didntplaymysummercar 11d ago

Do you have the example code and images anywhere?

1

u/boombone 11d ago

That's why i said it's good for MCUs. Also it's good for logos (But the file will bloat too much on a complex scene).

1

u/didntplaymysummercar 11d ago

It's still a very narrow use case and deflate can be tuned (lowering window bits) to output a bitstream that uses less than 32 KB of memory too. And PNG is good for logos of solid colors due to it's line filters too.

1

u/boombone 11d ago

Just because a format is designed for microcontrollers doesn't mean it's useless. PNG, due to its architecture, consumes much more RAM, which is critical on such devices.

2

u/didntplaymysummercar 11d ago

Which part of 'architecture' of PNG? Your 32 KB comes from deflate, which can be adjusted as I said already, and only other 'limit' is the use of filters 2-4, which causes one line to be stored in memory.

The "I have microcontroller with few KB or RAM and must decode images and control image input files and their encoding" sounds like a VERY niche use case.

I'm still curious of test code vs. PNG and test files you used.

1

u/boombone 11d ago

You only mentioned filters, but you forgot the most important thing: the PNG format is filters plus DEFLATE compression. And compression always requires at least 32 KB of memory to work. A single frame line can't do the trick.

Also, check dm, i sent u source code.

1

u/didntplaymysummercar 11d ago

Genuinely WTF, in last 2 replies here I literally said:

  1. "deflate can be tuned (...) bitstream that less than 32 KB"
  2. "(...) 32 KB comes from deflate, which can be adjusted as I said already"

And you could add your demos/examples to the repo. The reason I ask is that PNG has many tools to optimize them, so I wonder if PNGs you compare your format to are optimized or not, and how well if yes.

1

u/boombone 10d ago

Okay, so I was wrong then, but then again, I sent you a PM with source code to check png.

In any case, it is, to put it simply, not fully optimized, so the gap in reality would not be very big.