Module tga

Module tga 

Source
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 ignores image_type and image_descriptor entirely (confirmed Ghidra evidence – see docs/notes/texture_formats.md).

§Format Layout

+------------------------------+ 0x0000
| Header (18 bytes)            |
+------------------------------+
| Image ID (id_len bytes)      |
+------------------------------+
| Optional color map           |
+------------------------------+
| Pixel data                   |
+------------------------------+
| Optional footer/extensions   |
+------------------------------+

Structs§

Tga
In-memory TGA image.
TgaHeader
Source TGA header metadata captured during parsing.
TgaReadOptions
TGA reader option set.

Enums§

TgaBinaryError
Errors produced while parsing or serializing TGA data.
TgaBitsPerPixel
Source TGA bit depth.
TgaCompression
Source TGA compression mode.
TgaDataType
Parsed TGA data category from the source header.
TgaOrigin
Source TGA image origin.
TgaReadMode
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.