Skip to main content

Module tpc

Module tpc 

Source
Expand description

TPC binary texture-container support. TPC binary reader and writer.

TPC (texture pack container) is KotOR’s native texture container format. This module currently focuses on container-level parity: header fields, payload boundaries, and optional trailing TXI footer bytes.

§KotOR Notes

  • Canonical K1 pixel-type mappings are explicit and enforced.
  • Unknown pixel-type combinations are rejected by default.
  • Mip payload sizing follows K1 native shift semantics (>> 1 per level without clamping), so extra mip levels after dimensions collapse to zero contribute zero additional bytes.

§Shape of the container

A fixed 128-byte header, the payload immediately after it at 0x80, and optionally TXI text on the end. Nothing points anywhere. There is also no magic signature, so a .tpc is recognised by extension and by its header parsing plausibly.

The mip shift semantics noted above are the part worth being careful with: reproducing the engine’s unclamped >> 1 is not pedantry, since a writer that clamps at one produces a payload the engine reads at the wrong offsets from the first collapsed level onward.

Byte-level field map in docs/src/formats/textures/tpc.md, with the engine’s own header read and the reason only DXT1 and DXT5 exist here.

Structs§

Tpc
In-memory TPC container.
TpcHeader
TPC header fields.
TpcPixelFormatCode
Raw TPC pixel encoding code derived from pixel_type + compression state.

Enums§

TpcBinaryError
Errors produced while parsing or serializing TPC binary data.
TpcHeaderPixelFormat
Header-derived TPC texture payload format classification.

Functions§

read_tpc
Reads TPC data from a reader.
read_tpc_from_bytes
Reads TPC data from bytes.
write_tpc
Writes TPC data to a writer.
write_tpc_to_vec
Serializes TPC data to a byte vector.