The table below illustrates a common arrangement of data in a TGA file.
Field # |
Size |
Data |
General File Area |
1 |
byte |
ID length (offset=0) |
|
2 |
byte |
Color Map Type (offset=1) |
|
3 |
byte |
Image Type (offset=2) |
TGA File Header |
4 |
5 bytes |
Color Map Specification (offset=3) |
|
5 |
10 bytes |
Image Specification (offset=8) |
|
6 |
variable |
Image ID |
|
7 |
variable |
Color Map Data |
Image/Color Map Data |
8 |
variable |
Image Data |
|
9 |
variable |
Developer Fields |
|
10 |
variable |
Developer Directory |
|
11 |
short |
Extension Size (offset=0) |
|
12 |
41 ASCII |
Author Name (offset=2) |
|
13 |
324 ASCII |
Author Comments (offset=43) |
|
14 |
6 shorts |
Date/Time Stamp (offset=367) |
|
15 |
41 ASCII |
Job Name/ID (offset=379) |
|
16 |
3 shorts |
Job Time (offset=420) |
|
17 |
41 ASCII |
Software ID (offset=426) |
|
18 |
3 bytes |
Software Version (offset=467) |
|
19 |
long |
Key Color (offset=470) |
|
20 |
2 shorts |
Pixel Aspect Ratio (offset=474) |
Extension Area |
21 |
2 shorts |
Gamma Value (offset=478) |
|
22 |
long |
Color Correction Offset (offset=482) |
|
23 |
long |
Postage Stamp Offset (offset=486) |
|
24 |
long |
Scan Line Offset (offset=490) |
|
25 |
byte |
Attributes Type (offset=494) |
|
26 |
variable |
Scan Line Table |
|
27 |
variable |
Postage Stamp Image |
|
28 |
1K shorts |
Color Correction Table |
|
29 |
long |
Extension Area Offset (offset=0) |
|
30 |
long |
Developer Directory Offset (offset=4) |
TGA File Footer |
31 |
ASCII |
Signature (offset=8) |
|
While the figure above demonstrates one possible arrangement for the various data blocks within a TGA file, other arrangements are possible since many of the data blocks are referenced by an offset position from the beginning of the file. In particular, developers may find it easier to create the file if the Scan Line Table, the Postage Stamp Image and the Color Correction Table are located before the Extension Size field (Field 10). The Truevision TGA file format comprises of five areas, each of which contains one or more fields of fixed or variable length. The five file areas are: 1) TGA File Header, 2) Image/Color Map Data, 3) Developer Area, 4) Extension Area, and 5) TGA File Footer.
The last three areas, the Developer Area, Extension Area and the TGA File Footer are new to the file specification as of September, 1989. For this reason, images created with software written before September 1989 will probably not contain these three fields. In this document, the TGA file format prior to September 1989 will be referred to as the original TGA format, while the current TGA file format will be referred to as the new TGA format.
Note: A TGA file reader should begin by determining whether the selected file is in original or new format. This is accomplished by examining the last 26 bytes of the file (most operating systems support some type of SEEK function). Reading the last 26 bytes from the file will either retrieve the last 26 bytes of image data (if the file is in original format), or it will retrieve the TGA File Footer (is the file is in new format). To determine whether the acquired data constitutes a legal TGA File Footer, scan bytes 8-23 of the footer as ASCII characters and determine whether they match the following signature string:
This string is exactly 16 bytes long and is formatted exactly as shown above with uppercase letters, with a hyphen between the words “TRUEVISION” and “XFILE.” If the signature is found, the file can be assumed to be in the new TGA format and may contain the additional Developer Area and Extension Area fields. If the signature is not found, then the file is assumed to be in the original TGA format and should only contain areas 1 and 2. The byte format for the TGA File Footer is the following: Bytes 0-3, Extension Area Offset; Bytes 4-7, Developer Directory Offset; Bytes 8-23, Signature; Byte 24, ASCII character “.”; Byte 25, binary zero string terminator (0x00).