Table of Contents

TGA

Egami reads Truevision TGA files: color-mapped, true-color and gray, raw and RLE, 8 to 32 bits, every origin, and the TGA 2.0 footer and extension area. It writes 8-bit gray, 16-bit 5-5-5 with or without a 1-bit alpha, 24 and 32-bit, and 8-bit palettes, raw or RLE, with a TGA 2.0 footer.

A TGA loads as Bgr8, Bgra8, Gray8 or GrayAlpha8. TGA has no signature, so detection takes a file as TGA only when its whole 18-byte header is consistent; see Detection.

// Run-length encoded by default, bottom-left origin, with a TGA 2.0 footer that states the alpha type.
image.Save("duck.tga");
image.Save("duck-raw.tga", new TgaWriterOptions { Rle = false });

The descriptor's attribute bits say whether the extra bits are alpha, and a TGA 2.0 alpha type of "none" overrides them; premultiplied alpha is divided out on load. The extension area's author and comments become Author and Comment text entries, and the writer stores them back. TgaPixelFormat.Bgr24 and Bgr555 drop alpha rather than blending it onto a background. 15 and 16-bit files load straight into Bgr555 and Bgra5551.

The writer's pixel format and run-length coding, and the origin and alpha type a file states, read back through TgaDetails:

image.Save("duck-gray.tga", new TgaWriterOptions { PixelFormat = TgaPixelFormat.Gray8, Rle = false });
using Raster back = Raster.Load("duck-gray.tga");
TgaDetails details = (TgaDetails)back.Metadata.FormatDetails!;
bool upsideDown = details.Origin is TgaOrigin.BottomLeft or TgaOrigin.BottomRight;
bool hasAlpha = details.AlphaType is TgaAlphaType.Straight or TgaAlphaType.Premultiplied;