img_tga#
TGA -- crate root lib/img_tga/lib.rs
img_tga -- Truevision TGA reader / writer [src/img/tga.s]
probe(data, meta) -> recognised tga_probe
decode(data, sf, dec, meta) -> 0 / ERR_* tga_decode
encode(sf, opt, out) -> 0 / ERR_* tga_encode
CODEC tga_codec
TGA has no magic number, so the format detection only reports TGA when the caller's hint
(file extension) says so or probe accepts the header. probe is deliberately strict: colour
map type 0 / 1, image type 1 / 2 / 3 / 9 / 10 / 11, a colour map exactly when the type needs
one (entry size 15 / 16 / 24 / 32, length > 0; without one all colour map fields 0), width and
height > 0, a pixel depth that fits the type (colour mapped 8; true colour 15 / 16 / 24 / 32;
grey 8 / 16), descriptor bits 6..7 zero, alpha bits 0 / 1 (16 bit), 0 / 8 (32 bit, 16-bit
grey), 0 otherwise, at least one byte of pixel data after the ID and the colour map, and for
uncompressed types all pixels present.
Decoder (more lenient than the probe): image types 1 / 2 / 3 and RLE 9 / 10 / 11 (types 32 /
33 and 0: ERR_UNSUPPORTED); colour mapped with 8- or 16-bit indices and 15 / 16 / 24 / 32-bit
entries starting at the first-entry index (indices outside the map: opaque black); true colour
15 / 16 / 24 / 32 bit; grey 8 bit and 16 bit (grey + alpha byte); a colour map of a
true-colour image is skipped; the ID field is skipped; all four origins (descriptor bit 4
right-to-left, bit 5 top-to-bottom); RLE packets may cross rows; interleaved images
(descriptor bits 6..7) ERR_UNSUPPORTED. 5-bit channels expand by bit replication.
Alpha: with a v2 footer ("TRUEVISION-XFILE.") and an extension area (size >= 495) the
attributes type decides: 3 = straight alpha, 4 = premultiplied (FMT_PARGB result, colours
clamped to alpha, IMF_SRC_PREMUL), anything else = opaque. Without one the storage decides:
32-bit pixels / entries and 16-bit grey carry alpha, 16-bit pixels / entries when the
descriptor has alpha bits; then an alpha channel that is zero everywhere counts as opaque.
Missing or truncated pixel data: ERR_TRUNC (the minimum size -- RLE: one packet per 128
pixels -- is checked before the surface is allocated). Result: FMT_ARGB (straight).
Encoder: 32-bit BGRA with straight alpha (descriptor alpha bits 8) or 24-bit BGR (bitdepth
24; transparent pixels are composited over white), bitdepth 0 / 32 = 32 bit, others
ERR_UNSUPPORTED; IOF_RLE -> type 10 with packets that never cross a row (runs of >= 2 equal
pixels become run packets); rows bottom-up (origin lower left); a v2 extension area
(attributes type 3 for 32 bit, 0 for 24 bit) and footer. Width / height above 65535:
ERR_DIMS. Codec iom: IOM_RLE | IOM_BITDEPTH.
img_tga API#
static CODEC: Codectga_codecfn probe(d: &[u8], m: &mut ImgMeta) -> booltga_probe: the strict header check described in the module header; meta: size, depth, model, alpha (w = h = 0 when not recognised)fn decode(d: &[u8], sf: &mut Surface, dec: &ImgDec, m: &mut ImgMeta) -> i32tga_decode: decode (see the module header); meta is filled from the header; sf holds the (partial) surface also when a later error is returnedfn encode(sf: &Surface, opt: &ImgOpt, out: &mut Vec<u8>) -> i32tga_encode: TGA file (see the module header) -> 0 / ERR_DIMS / ERR_UNSUPPORTED / ERR_CANCEL; out is empty on error