A TGA file has no signature at the start. It begins with an 18-byte header, followed by an optional image ID, an optional colour map, and then the image data. Numbers of two bytes are little-endian, low byte first.
Layout
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 1 | u8 | ID length | The length of the image ID, 0 to 255. |
| 1 | 1 | u8 | colour map type | 0 none, 1 a colour map follows. 2 to 127 are reserved; 128 to 255 are for developers. |
| 2 | 1 | u8 | image type | How the image is stored. |
| 3 | 2 | u16 | first entry | The index of the first colour map entry stored. |
| 5 | 2 | u16 | colour map length | The number of entries stored. |
| 7 | 1 | u8 | colour map entry size | The bits in each entry: 15, 16, 24 or 32. |
| 8 | 2 | u16 | X origin | The image’s lower-left corner on the screen, horizontally. |
| 10 | 2 | u16 | Y origin | The image’s lower-left corner on the screen, vertically. |
| 12 | 2 | u16 | width | The width of the image in pixels. |
| 14 | 2 | u16 | height | The height of the image in pixels. |
| 16 | 1 | u8 | pixel depth | The bits a pixel takes: 8, 15, 16, 24 or 32. |
| 17 | 1 | u8 | image descriptor | Alpha bits and the direction of the rows. |
Image type
| Value | Meaning |
|---|---|
| 0 | No image data |
| 1 | Colour-mapped, uncompressed |
| 2 | True-colour, uncompressed |
| 3 | Greyscale, uncompressed |
| 9 | Colour-mapped, run-length encoded |
| 10 | True-colour, run-length encoded |
| 11 | Greyscale, run-length encoded |
Bit 3 of the value (the 8) marks run-length encoding, so types 9, 10 and 11 are types 1, 2 and 3 encoded. Values 32 and 33, which use Huffman and delta coding, appear in older documents; their layout is not given and the explorer does not read them.
Colour map fields
The three fields at offsets 3 to 7 describe the colour map. The first entry is the colour number of the first colour stored, so pixels point to colours from that number on. The entry size can differ from the pixel depth: a common layout is 24-bit entries for an 8-bit image.
Image descriptor
| Bits | Name | Meaning |
|---|---|---|
| 3–0 | alpha bits | The alpha or attribute bits in each pixel. |
| 4 | right to left | 1 if pixels in a row run from right to left. |
| 5 | top to bottom | 1 if the first row in the file is the top one; otherwise it is the bottom one. |
| 7–6 | interleaving | Should be 0. The first specification used them for interleaved rows. |
Most TGA files are stored bottom-up, with the bottom row first and bit 5 zero, the default of the format.
Image ID
Straight after the header, the number of bytes given by the ID length field, up to 255. The format does not say what it holds; programs use it for a name or a comment.
Colour map
After the image ID, when the colour map type is 1. Each entry takes as many whole bytes as its entry size needs:
| Entry size | Bytes | Layout |
|---|---|---|
| 15 or 16 | 2 | Bits as A R R R R R G G G G G B B B B B, least significant byte first |
| 24 | 3 | Blue, green, red |
| 32 | 4 | Blue, green, red, alpha |