PNG loading made simple

I need to load some images from disk, and use them as OpenGL textures. This is something I’ve reimplemented many times on different systems, and it’s always seemed more complicated than it should be.

The first choice is whether to use the native OS’s image loading libraries, or a cross-platform framework. Native libraries are a lot easier to start using, but make the code harder to port to other systems. Using an open-source framework makes your code much more portable, but it’s often a pain to find or build against the right version of the code, and you also have to deploy it to the end-users’ systems. I lost several hours wrestling with libpng a few weeks ago, since it refused to build on OS X, and I ended up yak-shaving my way down a dependency chain of other libraries it needed.

This seems overkill for most of the tasks I’m trying to accomplish, since I’m usually just trying to load a small, fixed set of images, which I’ve created and so can control their properties. This only uses a tiny part of most image loading libraries, since they’re designed to cope with reading and writing dozens of different formats, and hundreds of combinations of bit-depth, compression and other flags within each of those, along with lots of platform-specific optimizations to improve performance.

Happily, I recently came across the LodePNG project, which offers a simple, dependency-free way of loading PNGs. The PicoPNG module is a standalone C++ file that will load 8 bit, 4 channel PNGs, and is only 500 lines of code. This is perfect for my needs, there’s no extra installation hassles or dependencies, and it’s cross-platform. I also appreciate the elegant way that Lode Vandevenne packed his solution into such a small amount of code. It’s compact, but not obsfucated, very classy work.

Funhouse Photo User Count: 1,933 total, 78 active. Still getting quite a few users from the profile box add link, according to my statistics.

Event Connector User Count: 87 total, 4 active. Very quiet, I haven’t been actively chasing up any leads for a few days.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: