C code - Simple .PNG loader

Started by
4 comments, last by Captain P 16 years, 1 month ago
Hi guys. Can anyone point me in the direction of a .png file loader for C. All I want is to load the image into a 2D array (intensity or RGB value stored in the array) and then save the array back to a PNG. I've had a quick look but I can only seem to find big expansive libraries with 100's and 1000's of functions. I just want the very basics because time is of the essence! Thanks.
Advertisement
LibPNG can actually be quite well stripped from function you don't need by using a set of #defines.

Futhermore, if you say 'time is of the essence', do you mean it has to be fast? Since, even if a library contains thousands of functions, those functions that you don't use will not cost you any time. If you're on an embedded platform, and therefore low an memory, that's a whole different story.

If you really think libpng is unfit for your needs, you could consider this PNGLoader by Lode VandeVenne, a member of this board.
Nvidia texture tools, contains png loader:
http://code.google.com/p/nvidia-texture-tools/

However, it pretty much just makes use of libpng I believe:
http://www.libpng.org/pub/png/libpng.html

I haven't used libpng directly, I'm personally using the nvidia texture tools.

If you're using DirectX, you can always just load a png texture file (D3DXCreateTextureFromFile), lock the top mip rect, and copy the bits.
Thanks for the suggestions guys, i will look into them.

And sorry I meant that I dont have long to get this loader working, not time of loading must be fast. I just wanted something simple that i can get up and running quickly.
You should take a look at stb_image. It works perfectly for me, was easy to start using, and is tiny and fast.

Best of all, the author (Sean Barrett, a really cool and friendly guy) has released it into the public domain, so you can do whatever you like with it (commercial use etc.).

It's on Sean's page: http://www.nothings.org
Quote:Original post by mpledge52
And sorry I meant that I dont have long to get this loader working, not time of loading must be fast. I just wanted something simple that i can get up and running quickly.

Unless you really need to use C, Python + PIL would be an excellent choice. I've written various tools with it, ranging from unique tile extractors to batch color replacement scripts, where each script took me roughly 15-30 minutes to write and test.
Create-ivity - a game development blog Mouseover for more information.

This topic is closed to new replies.

Advertisement