ImageGear for C and C++ on Linux v18.10 - Updated
TGA
User Guide > File Formats and Compressions > File Formats > File Formats Reference > TGA

Full Name TGA (Truevision Targa)
Format ID IG_FORMAT_TGA = 39
File Extension(s) *.tga, *.tpic
Data Type Raster Image
Data Encoding Binary
Color Profile Support No
Multi-Page Support No
Alpha Channel Support Single alpha channel for read/write
ImageGear Platforms Support WIN32, WIN64, Unix, Unix64, .NET, .NET64, MAC

ImageGear Supported Versions:

ImageGear Supported Features:

ImageGear Read Support:

ImageGear Write Support:

ImageGear Filter Control Parameters:

Filter Control Parameter Type Default Value Available Values Description
AUTHOR_COMMENT STRING " " Author's comments.
AUTHOR_NAME STRING " " Name of author.
IMAGE_ID STRING " " Image ID.
SOFTWARE_ID STRING " " Software ID.
STAMP_DAY WORD 0 Day stamp.
STAMP_HOUR WORD 0 Hour stamp.
STAMP_MINUTE WORD 0 Minute stamp.
STAMP_MONTH WORD 0 Month stamp.
STAMP_SECOND WORD 0 Second stamp.
STAMP_YEAR WORD 0 Year stamp.
KEEP_ALPHA BOOL FALSE TRUE, FALSE FALSE means to ignore Alpha bits. Non-zero (TRUE) means to pass alpha bits back through callback.
PROMOTE16 BOOL FALSE TRUE, FALSE FALSE means to create 16 bit DIB without promoting to 24 bits. Non-zero (TRUE) means promoting.
HEADER_TYPE INT 0 1 or 2 1 or 2 for revision level of header.
STORES_TAMP BOOL FALSE TRUE, FALSE FALSE for no stamp, TRUE to save a stamp with image. HEADER_TYPE must be 2.
STAMP_WIDTH UINT 0 0-64 Stamps width must not be larger than 64 pixels.
STAMP_HEIGHT UINT 0 0-64 Stamps height must not be larger than 64 pixels.
PALETTE BOOL FALSE TRUE, FALSE TRUE indicates that color map should be created.
CONV_TO_16 BOOL FALSE TRUE, FALSE If TRUE, convert to 16 bpp when saving.
THUMB_FLAG UINT 0 TRUE, FALSE TRUE if save should include a thumbnail.
THUMB_WIDTH UINT 0 Width of thumbnail.
THUMB_HEIGHT UINT 0 Height of thumbnail - Thumbnails are 24 bit.

Comments:

This file format was originally developed by AT&T for use with its image capture boards. The format was taken over by Truevision when it acquired the product line from AT&T. It is now commonly used for digitized images and also for high-quality images produced by ray tracers and other graphics applications.

It became a popular file format mainly because it was the first 24-bit truecolor format to come to the PC market. There are several varieties of Targa files; the most commonly used are the Targa 16, Targa 24, and Targa 32. The names are derived from the type of hardware used to create them.

The fixed-sized header information of the Targa format includes: the existence (or not) and colormap, location, size, pixel depth, image location, colormap (if it exists), and finally the image data itself.

Version 2.0 introduced a file footer that identifies it as the newest version and contains pointers to additional fields in two main structures: the "extension area" and the "developer directory". The extension area contains the addresses of many optional fields, one of the most popular being the "postage stamp image" (miniature of the main image).

The developer directory can be used to store proprietary information. Developers can register their own private fields with Truevision. A null-terminated ASCII string containing "TRUEVISION-XFILE.", and positioned at the end of the file, indicates that the footer is valid.

Targa defines 3 color methods: pseudo color, direct color, and truecolor. Pseudo color uses an index to a color palette. Direct color is like pseudo color except that the RGB components are looked up separately. In truecolor files, the color information is stored directly in the image data. The palettes used by Targa files are variable in size; they do not necessarily correlate to the bit depth of the image. The presence of a palette does not always mean that it is used to display the image.

Alpha channel handling

KEEP_ALPHA control parameter must be set to TRUE to enable loading and saving of Alpha/Extra channels from TGA images.

If bits 0..3 of Image Descriptor field are set to non-zero (additional channel is present), ImageGear treats additional bits as follows, depending on the Attributes Type field:

Attributes Type value Attributes type value meaning Additional bits are loaded as:
0 No Alpha Data included Non-premultiplied Alpha (for incompliant images where Image Descriptor tells there is an additional channel but Attributes Type field is not set.)
1 Undefined data, can be ignored Extra channel
2 Undefined data, should be retained Extra channel
3 Non-premultiplied Alpha Non-premultiplied Alpha
4 Premultiplied Alpha Premultiplied Alpha
Other Reserved or unassigned Non-premultiplied Alpha

If bits 0..3 of Image Descriptor field are set to zero (no additional channel is present), ImageGear treats additional bits as Extra channel. This allows reading additional channel from images that have incorrect Image Descriptor field, but does not spoil image display if there is no meaningful data in the additional channel.

References Used

Brown, C. Wayne, and Barry J. Shepherd. Graphics File Formats: Reference and Guide. Greenwich, CT.: Manning Publications, 1992.

Kay, David C. and John R. Levine. Graphics File Formats. Windcrest Books, 1992.

Murray, James D. and William vanRyper. Encyclopedia of Graphics File Formats. Sebastopol, CA: O'Reilly & Associates, Inc., 1994.