Introduction
TGA, also called TARGA, is a raster image format made by Truevision in the 1980s for its TARGA and VISTA graphics cards. It stores palette, truecolour or greyscale images, either raw or with simple run-length compression.
Its simple layout and support for an alpha channel made it a long-standing choice for textures in games and 3D software, where it is still common.
Structure
A TGA file has no signature at the start. It opens with an 18-byte little-endian header: the length of an optional image ID, whether there is a colour map, the image type, the colour map's layout, then the image's origin, width, height, bits per pixel and a descriptor byte. The descriptor gives the number of alpha bits and whether rows run from the bottom up or the top down.
The image type is 1 for colour-mapped, 2 for truecolour and 3 for greyscale, with 8
added for the run-length encoded versions (9, 10 and 11); types 32 and 33, for colour-mapped
images compressed with Huffman and delta coding, are named in old descriptions but never
documented. A file written before September 1989 is an original (version 1) TGA with
nothing after the pixels. Version 2.0 of the format
adds an extension area, a developer area and a 26-byte footer that ends with the text
TRUEVISION-XFILE. and a zero byte.
0Header ID length, colour map type, image type, colour map spec, image spec18 bytes18Image ID optional free text0 to 255 bytes…Colour map the palette, when there is onevaries…Image data the pixels, raw or run-length encodedvaries…Footer version 2.0 only, endsTRUEVISION-XFILE.26 bytes
The extensions .icb, .vda and .vst were used for
the same format by Truevision’s image capture board, video display adapter and Vista
boards. A file of any of these extensions dropped on any page of this site opens in
the explorer, which shows the picture and every field, and lists each run-length
packet.
In this reference
- Header – the 18-byte header, the image ID and the colour map
- Image data – pixels at every depth and run-length packets
- Version 2.0 areas – the footer, extension area, developer directory, postage stamp and tables
Not described
Everything in Truevision’s 2.2 specification (January 1991) is described and shown. What is left is what that document does not say, and what no other source gives.
Unknown
- Reference and viewer: image types 32 and 33 (colour-mapped, compressed with Huffman, delta and run-length coding, type 33 with a four-pass quadtree-type process; see Header). Their layout is not in the 2.2 specification, the Truevision Technical Guide table of contents, Wikipedia, Paul Bourke’s, FileFormat.info’s or Kaitai’s descriptions (which only list the names), the source of stb_image, Pillow, FFmpeg, FreeImage (which calls them obsolete), GIMP or the Go and Rust readers found (which list them as unsupported), and no sample file is in the Pillow, OpenImageIO, OpenImageIO-images, ImageMagick or SDL_image collections or among the more than 3,000 TGA files on this Mac. The viewer names the type, decodes the header and colour map, and shows the compressed bytes with no picture.
- Reference and viewer: the interleaving codes in descriptor bits 7-6 (1 two-way, 2 four-way) of the original specification. The row order described on Header is the one FFmpeg’s decoder uses; Truevision’s own text for it (the first Technical Guide) was not found, version 2.0 only says the bits must be zero, stb_image and Pillow ignore them, and no sample file sets them, so it is unconfirmed. The viewer draws such images that way and does not link their bytes to pixels.
- Reference: what the developer directory tags mean. The specification says Truevision kept a list of tag numbers it assigned to companies and published none; the viewer shows each tag’s number, offset and bytes.
- Viewer: the colour correction table is decoded entry by entry but not applied to the picture: the specification gives the table’s layout and range, not a remapping procedure, and none of the readers checked applies it.
Links
Software
- GIMP – free image editor that opens and saves TGA (Windows, macOS, Linux)
- Adobe Photoshop – Adobe’s image editor, which opens and saves TGA (Windows, macOS)
- Krita – free painting program that opens and saves TGA (Windows, macOS, Linux)
- IrfanView – image viewer and converter (Windows)
- XnView MP – image viewer and batch converter (Windows, macOS, Linux)
- ImageMagick – command-line tools that convert to and from TGA (Windows, macOS, Linux)
- Blender – free 3D suite that uses TGA for textures and renders (Windows, macOS, Linux)