I know png images have their zlib compression scheme, which caused me some headaches in the past in C#. because there seems to be a tiny difference in definitions of zlib.
Is the std version (zlib.zig) the one which is usable for compressing png images?
I am unsure, though so long as the DEFLATE algorithm is compatible, it should be trivial to workaround. If memory serves me correct, Zlib is just a header, DEFLATE compressed data, and then a checksum. It has been a long time, but I seem to remember that there was something different with .NETās implementation than what is commonly seen in the wild, and I had to implement a basic ZlibStream class when doing some Minecraft NBT project years ago.
zigimg uses a pure Zig reader/writer implementation, so it might be worth a peek to see how they did it. If they donāt use std.zlib, it may be an indicator that it suffers from the same issue.
They use I think this. If I remember correctly the only difference was a checksum thingy.
I believe so, and TIL Zig has an adler32 implementation in std, which makes it even easier if you opt for a custom implementation. This does make me curious what the incompatibility issue is with Zlib implementations, as I assume zigimg didnāt implement this for fun.
Most programs open / show āunofficalā pngās without a problem. That is why I was so confused a few years ago. It is indeed a tiny difference. Yes it was this adler thing.
Telegram for example requires a fully qualified png.
Thanks ![]()
Oh I didnāt know the std lib provided those functions.
Over the last few weeks I wrote my own PNG encoder/decoder over at
I will see if I can remove some stuff in favor of the std lib. But Iām worried it might break. Right now itās pretty self contained.
I would keep it, if youāre confident of its correctness. Thereās nothing wrong with reimplementing certain functions that exist in the std lib for your own purposes.
I see in deflate.zig
// Compression algorithm explained in rfc-1951 (slightly edited for this case)
I guess I can now confidently say that the answer to the original question is yes.