Expand description
TGA texture-image support. TGA (Targa) reader and writer.
This module provides a Rust-centric TGA API for KotOR texture workflows:
- parse many TGA source variants into a normalized top-left RGBA8 buffer,
- write lossless-passthrough or canonical output.
Parsing is backed by tinytga for robust header/color-map/RLE handling.
§KotOR Notes
- Reader defaults target canonical vanilla KotOR (K1) image types
(
1,2,3,9,10) and reject non-canonical variants such as grayscale RLE (type 11) unless compatibility mode is explicitly enabled. - Writer default: lossless passthrough when pixels are unmodified (the 18-byte
header and raw image sections are re-emitted verbatim). For new files or
edited pixels, output is canonical uncompressed true-color (type
2, 32-bit, top-left origin). K1 ignoresimage_typeandimage_descriptorentirely (confirmed Ghidra evidence – seedocs/src/formats/textures/tga.md).
§Shape of the file
The standard Truevision structure: an 18-byte header, then optional image ID and colour map regions, the pixel data, and an optional footer KotOR never emits.
What matters here is how little of the header the engine reads. It takes the
dimensions and pixel_depth, validates only that the depth is 8, 24 or 32,
and disregards every other field including image_type and the origin bit in
image_descriptor. Orientation therefore cannot be expressed in the file:
the engine’s own writer hardcodes the descriptor to zero and flips the raster
on the way out. Field map in docs/src/formats/textures/tga.md.
Structs§
- Tga
- In-memory TGA image.
- TgaHeader
- Source TGA header metadata captured during parsing.
- TgaRead
Options - TGA reader option set.
Enums§
- TgaBinary
Error - Errors produced while parsing or serializing TGA data.
- TgaBits
PerPixel - Source TGA bit depth.
- TgaCompression
- Source TGA compression mode.
- TgaData
Type - Parsed TGA data category from the source header.
- TgaOrigin
- Source TGA image origin.
- TgaRead
Mode - TGA reader input policy.
Functions§
- read_
tga - Reads TGA data from a reader.
- read_
tga_ from_ bytes - Reads TGA data from bytes.
- read_
tga_ from_ bytes_ with_ options - Reads TGA data from bytes with explicit options.
- read_
tga_ with_ options - Reads TGA data from a reader with explicit options.
- write_
tga - Writes TGA data to a writer.
- write_
tga_ to_ vec - Serializes TGA data into a byte vector.