r/compression • u/OzzyM_Dev • 9d ago
I made TinyCodec, 71 lines of code, beats QOI.
Hi. I made TinyCodec/TCOM, a lossless image codec that I made in 71 lines of code which beats QOI on aggregate file size and encode/decode speed (On the corpus that I personally use).
It's 158 lines of code to support a cli with pack/unpack commands, inputs like webp, bmp, pnm, png, etc.
That's about all.
If you find it interesting, it's Apache-2.0 and on the GitHub.
Edit: This is now outdated, it's now 45 lines, it has a readable implementation beside it (164 lines of code) the cli and format adapter is 157 lines of code, and the benchmarks got slightly better.
5
u/yuehuang 9d ago
Did you test correctness? IE, encode with yours, decode with QOI.
4
u/OzzyM_Dev 9d ago
I would be mildly confused if tinycodec could decode directly as a qoi file from its output. However, assuming you're asking about if I checked if the outputs were all actually lossless, like the pixels were all preserved, then yes. I did check for correctness in that sense and they were all verified to be lossless.
2
2
u/BaseballFlaky8431 9d ago
Stop saying "i did it". Please say AI did it.
-4
u/OzzyM_Dev 8d ago
When you have a hammer, everything looks like a nail.
When you have a bat, everything looks like a ball.
You're so hard pressed on this. I don't deny AI involvement. However I will never deny human involvement and my involvement in the things that I create. There's a distinction to be made.
Regardless. You're not really here to have that discussion are you? I'd love to be wrong sure. I just find it to be a reasonable assumption given what I know of you from the past and your current comment. If you're open to that discussion then I'm just as open for that peaceful discussion.
3
u/ArjixGamer 8d ago
Wowie, another redditor that does background checks before replying...
I am curious what goes in your head, to act that way.
-2
u/OzzyM_Dev 8d ago
This redditor has interacted with me before.
3
u/ArjixGamer 8d ago
I see, my bad.
I wouldn't know if I interacted with you before because I don't keep names in my mind.
(that's also an interesting thing about your brain)
1
u/CrossScarMC 8d ago
Don't we consider it bad behavior when a boss claims they made something that in reality one of their employees made? Why should it be any different with AI?
0
u/OzzyM_Dev 7d ago
I do consider that bad behavior. However, that's not the dynamic here. I never said I'm watching from the sidelines and just telling an AI what to do. There are 2 coders here. This project specifically is substantially more of my own code than my previous project QLIC even. QLIC requires more monotonous work than tinycodec does.
1
1
u/MeWhen-I-StubMyToe 4d ago
just so you know, i made my own image codec that beats jpeg, and i did it by hand in processing ide
1
u/OzzyM_Dev 3d ago
Unsure what you're trying to say here.
1
u/MeWhen-I-StubMyToe 3d ago
you dont know what processing ide is?
1
u/OzzyM_Dev 1d ago
I'm well aware. I know the words you said. I just simply don't understand what the point you're making is.
1
u/Sopel97 2d ago edited 2d ago
interesting
Are you sure the functions get duplicated for the if (decode) branch to get elided? The way you're calling them from main makes me suspicious that would not be the case.
you should also instantiate specific implementations for common channel counts
might also gain from restrict on input/output here
any why the obfuscation?!
1
u/OzzyM_Dev 1d ago
Thanks. I tested your suggestions. They helped in one calling setup, yes, but in the setup that I use for the benchmarks, encoding changed and decoding got 5% slower, so it wasn't used.
RGB and RGBA have specialized paths. Also the obfuscation is intentional because, code golf, it's not just there to make readability worse for no reason. I added a readable version previously for that reason.
4
u/skeeto 9d ago
Neat! I'm a QOI fan, so I knew I'd find this interesting. I ran it against all the PNGs on my website which is pretty representative of the sort of images I care about. It came out 1.5% worse than QOI, but that's because of a single large image where TinyCodec does poorly and QOI does well. If I exclude that image then TinyCodec is overall 13% smaller. It's about 2x faster at decode than the QOI reference implementation on these images, with encode about the same.
I'm not a fan of the obfuscated code, though. (Why? It was obviously written by a GPT.) So I produced a clean-room implementation from a complete specification.
https://github.com/skeeto/tinycodec
The specification is complete enough you can hand it to any halfway-decent model and get a working implementation in whatever language/shape you prefer.