TGA Decoder

Hi all,

I’ve been using the TWL PNGDecoder quite regularly but couldn’t find a comparable decoder for TGA images which I use sometimes, so I thought I’d have a go at writing one. I’ve written it to work in the same way as the PNGDecoder (create a new decoder object with an input stream, then call decode and supply a bytebuffer). You can find it here:

It supports 24-bit (RGB) and 32-bit (RGBA) formats, and uncompressed or RLE Compressed formats. On my 2.7ghz i7 it took 180ms to decode a 40mb compressed 2988×5312x24 photo and around 80ms to decode a 15mb compressed 2048x2048x32 image. Uncompressed images take around half that time.

Hope someone finds this helpful!

Great! These things are sorely lacking from Java and interfacing with native libraries is a pain.

yes, thanks for sharing :slight_smile:

You’re welcome, guys! If there is enough demand for it then I’ll look at adding support for 16-bit and colour-mapped images, but since I don’t use them myself I haven’t bothered yet.

What license is it under?

I’d love to include it in Spade. We’ve had this issue open for a while now.

Oops, forgot to modify the header. I’ve put it under the MIT license, so feel free to integrate it any way you like, or extend/modify (fix?) parts.

If you’re looking to implement it as part of an image editing program, you’ll probably want to include support for at least 16-bit and colour-mapped file formats as well. I will take a look since I’m going to use this as part of my 3D game engine. I only restricted the file formats because right at the moment I’m just using it to import some textures to test my FBX binary parser (turns out the UVs are a bit dodgy :(), but eventually I’ll want to include as wide a media support as possible.

PS: Took a look at your Spade project, I like the idea :slight_smile: Do you have a custom JPEG importer at all? I did some research and it looks pretty horrendous (at least compared to the relatively-straightforward TGA format). Then again, the compression on JPEGs is far more aggressive than on TGAs so I guess it’s not unexpected that it would be more complicated to uncompress.

For the moment, I used this technique as a quick fix to decode JPEG images:

Eventually I’ll write my own and package it up with the TGA decoder.

@HeroesGraveDev I noticed you were using ImageIO in Spade, this library here https://github.com/haraldk/TwelveMonkeys (not me but I have used it) has some good image plugins for ImageIO and is actively developed. You might find it useful.