Version 2.0 of the format adds areas after the image data. They are found through a
26-byte footer at the very end of the file, and the rest can sit in any order. A file
without the footer is an original-format TGA, and reading stops at the image data for
those. To tell which, a reader looks at the last 26 bytes: if bytes 8 to 23 are
TRUEVISION-XFILE, byte 24 is a full stop and byte 25 is zero, the file is a
2.0 file; otherwise those 26 bytes are just the end of the pixels. Writers are advised to add the
footer even when both offsets are 0. All numbers are little-endian, and all offsets count
from the start of the file.
0Header18 bytes…Image ID, colour map and image datavaries…Developer area tags, optionalvaries…Extension area optional495 bytes…Scan-line table, postage stamp, colour correction optionalvariessize − 26Footer26 bytes
Extension area
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 2 | u16 | size | 495 in version 2.0; any other value means another version, and only the 495 bytes of 2.0 are read. Autodesk 3D Studio and 3ds max write 494 although their area is the usual 495 bytes (it ends exactly at the footer); readers should not trust the field alone. |
| 2 | 41 | text | author name | Up to 40 characters, then a zero byte; nulls or spaces if unused. |
| 43 | 324 | text | comments | Four lines of 80 characters, each followed by a zero byte (81 bytes a line). |
| 367 | 12 | 6 × u16 | date and time | Month (1 to 12), day (1 to 31), year (four digits), hour (0 to 23), minute (0 to 59) and second (0 to 59) the image was saved; all zero if unused. The file system’s time can change when a file is copied, so this one is kept. |
| 379 | 41 | text | job name | Up to 40 characters. |
| 420 | 6 | 3 × u16 | job time | Hours (0 to 65,535), minutes and seconds (0 to 59) of work spent on the image so far, for billing and estimating; all zero if unused. |
| 426 | 41 | text | software ID | The program that made the file. |
| 467 | 2 | u16 | software version | The version × 100, so 417 for 4.17. |
| 469 | 1 | ASCII | version letter | A letter following the version, or a space. |
| 470 | 4 | u32 | key colour | A:R:G:B, alpha in the top byte: the background or transparent colour in effect when the image was saved; 0 (black) if unused. |
| 474 | 2 | u16 | pixel ratio numerator | A pixel’s width as a fraction of its height (numerator over denominator). The same non-zero value in both means square pixels; a denominator of 0 means no ratio is given. |
| 476 | 2 | u16 | pixel ratio denominator | 0 if not given. |
| 478 | 2 | u16 | gamma numerator | Gamma as a fraction, 0.0 to 10.0 with one decimal place needed; 1/1 means an uncorrected image. A denominator of 0 means the field is not used. |
| 480 | 2 | u16 | gamma denominator | 0 if not given. |
| 482 | 4 | u32 | colour correction offset | Where the colour correction table is; 0 for none. |
| 486 | 4 | u32 | postage stamp offset | Where the postage stamp is; 0 for none. |
| 490 | 4 | u32 | scan-line offset | Where the scan-line table is; 0 for none. |
| 494 | 1 | u8 | attributes type | What the alpha bits hold: 0 none, 1 undefined and can be ignored, 2 undefined and should be kept, 3 useful alpha, 4 pre-multiplied alpha. 5 to 127 are reserved; 128 to 255 are unassigned. |
Developer directory
A 16-bit count, then ten bytes for each tag. It lets a program store data of its own
and find it again. The format does not say what any tag means; a reader that does not
know a tag skips it (and a writer should copy it unchanged). The directory is found
through the footer; a directory offset of 0 means there is none. Its size is
tags × 10 + 2 bytes, and the tags need not be sorted. Each tag’s data is
complete in itself, with any variable-length parts inside the size given. Truevision keeps
the list of tag numbers it has assigned to companies; no such list has been published,
so the explorer shows each tag’s number, offset and bytes.
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 2 | u16 | tag number | 0 to 32,767 are for developers; 32,768 to 65,535 are reserved for Truevision. |
| 2 | 4 | u32 | offset | Where the tag’s data is in the file. |
| 6 | 4 | u32 | size | The size of the tag’s data. |
Postage stamp
A small copy of the image, at most 64 × 64 pixels, in the same pixel format as the
main image: one byte of width, one of height, then its pixels. It is never compressed, even
when the image is run-length encoded, and a colour-mapped image’s stamp uses the image’s own
colour map and is not averaged. Truevision does not recommend stamps larger than 64 × 64
and suggests larger ones be clipped. It lies after the scan-line table and before the
footer. The explorer shows it as a second picture. Corel’s writer stores the width and
height as two 16-bit numbers, a 4-byte header instead of the 2 bytes above (seen in a
Corel file, round_grill.tga of the OpenImageIO test images, where 4 + 64 × 64 × 4
bytes fill the space up to the footer exactly); when the one-byte reading gives a stamp of no
pixels or one that does not fit, and the 16-bit reading fits, the explorer uses that and says so.
Colour correction table
A table of 256 entries of four 16-bit values, alpha, red, green and blue: 2,048 bytes in all; each group of four is the A:R:G:B correction for that entry. Values run from 0 to 65,535, so black is 0, 0, 0, 0 and white 65,535 in every field. It is for remapping an image or loading a hardware look-up table, may sit anywhere between the image data and the footer, and is left out (offset 0) when the gamma value is enough. The explorer decodes every entry in the tree. It does not apply the table to the picture: the specification says what the table holds, not how a viewer must remap with it, so the picture shows the stored pixels, as every other reader does.
Scan-line table
One 32-bit file offset for each row of the image, in the order the rows are stored. It lets a reader of a run-length encoded file jump straight to a row, and a reader open a very large image in pieces. A 768-row image has 768 offsets, 3,072 bytes. It is the reason packets should not cross rows. The explorer compares each offset with where the row really starts and reports the ones that differ.