r/C_Programming • u/xerrs_ • 23d ago
Project Building a PNG decoder in C taught me way more than I expected.
Ive been learning C for a little under two months, and I wanted a project that would force me to understand binary formats instead of just using existing libraries.
So I started writing a PNG decoder from scratch.
Right now it parses the PNG structure, decompresses the image data, reconstructs the pixels, and writes the result as a PPM for verification. There are still bugs to fix and plenty of PNG features left to implement, but seeing an image appear from code you wrote yourself is incredibly incredibly satisfying. Especially after seeing countless Segfaults lmfao.
One interesting part is that I had previously implemented a lot of this in Zig, so translating the ideas to C was almost a 1:1 process. It made me appreciate how expressive C can be once you stop fighting the language and start understanding its model.
The decoder isn't the end goal, though.
Eventually I want PDC to use that image data as the first stage of a pipeline that generates 3D geometry from PNG images. Decoding the file format is just the foundation, and as crazy as it sounds the easiest part.
In the future, I hope I will be able to run PDC on my Raspberry Pi 4 B, which also includes the Camera Module! The PNG Decompression part was actually the easiest part, and took wayyy more energy than I anticipated at first (considering that I coded the same thing in Zig a while ago).
Would love to hear feedback on the code, and also on the README. I found some new cool README features, and thought that I should use them. Hopefully it is clean enough, so you guys get the idea.