Sign in to follow this  

C code - Simple .PNG loader

This topic is 3577 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 3577 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this