TinyImageLoader 1.7.0

by admin

It has been a long time since I’ve released a new version. This is mostly because TinyImageLoader went on the backburner. I’m still supporting it though.

What is TinyImageLoader?

TinyImageLoader (TIL) is a very small C++ library that can load PNG, BMP, TGA, GIF, ICO and DDS images. It does so without fluff or safety guarantees.

Here’s an example on how to load an image as an OpenGL texture:

	g_Load = til::TIL_Load("media\\PNG\\avatar.png", TIL_FILE_ADDWORKINGDIR | TIL_DEPTH_A8B8G8R8);
	glBindTexture(GL_TEXTURE_2D, g_Texture);
		g_Load->GetPitchX(), g_Load->GetPitchY(),
		GL_RGBA, GL_UNSIGNED_BYTE, g_Load->GetPixels()

Before loading, you specify the target pixel format. That way you immediately have your data the way you need it.

For a full list of supported formats, please refer to the “Supported formats” page in the supplied documentation.

TinyImageLoader is licensed under the MIT license.

What’s new?

1.7.0 introduces flexible pitch. Pitch refers to the width plus padding of an image. In TIL’s case, I talk about both horizontal and vertical pitch. Why is that handy?

Well, suppose you need to load images on a platform that doesn’t support non-power of two textures. How would you ensure that the image is always a power of two when you load it? You can’t with 1.6.3. In fact, you’d have to load the image and then pad the data manually. Not fun.

In 1.7.0, you can write a function like this:

	void CustomPitchFunc(til::uint32 a_Width, til::uint32 a_Height, til::uint8 a_BPP, til::uint32& a_PitchX, til::uint32& a_PitchY)
		til::uint32 high = (a_Width > a_Height) ? a_Width : a_Height;

		til::uint32 closest = 0;
		til::uint32 move = high;
		while (move >>= 1) { closest++; }
		if (high - (1 << closest) > 0) { closest++; }

		a_PitchX = 1 << closest;
		a_PitchY = a_PitchX;

This function takes the width and height of an image and sets the horizontal and vertical pitch.

Then you can attach the function to the pipeline, after initializing TinyImageLoader.


And now your images will always be padded until they are the nearest power of two.

You will most likely not have to use this functionality in your projects. In fact, you're more likely to walk over to your artists and smack them on the head for not sticking to powers of two. But it's nice to have and it has other uses too.

DDS support

1.7.0 comes with improved DDS support. DDS has many forms of compression, but only uncompressed, DXT1 and DXT5 are supported, as these are by far the most common types of DDS textures.

New is support for cube textures and the ability to load mipmaps.

Google Code

You can download TinyImageLoader from Google Code: