Format:TIM2 (PlayStation 2 texture)
| On this wiki | Facts · Code · Notes · Topics |
|---|
Sony's PlayStation 2 texture container (.tm2/.tim2): a 16-byte file header with the magic "TIM2", a format version and alignment id and a picture count, followed by pictures that each have a 48-byte header (sizes, CLUT colour count, image type, width, height and the GS TEX0/TEX1 register images), the pixel data and an optional CLUT.
Overview
TIM2 is the PS2 successor of Format:TIM (PlayStation texture), but the layout differs: a TIM2 file holds several pictures, every picture keeps the register values the Graphics Synthesizer needs (TEX0, TEX1, and a CLUT/miptbp word) so that the data can be uploaded as it is. Games often bundle many TIM2 files inside archives, so scan for the magic 54 49 4D 32 ("TIM2") rather than trusting an extension.
File header (0x10 bytes)
All values are little-endian. Magic "TIM2" (u32 0x324D4954), format version u8 (4 is written by chihuahua's writer; Unverified: Sony's tools write 4 as well; values below 0x80 reserved, 0x80-0xBF private incompatible, 0xC0-0xFF private compatible), format id u8 (0 = 16-byte alignment of the pictures; a 128-byte alignment variant exists, but chihuahua names its id 0x81 in one place and 0x01 in another, see Pitfalls), picture count u16, then 8 reserved bytes.
Picture header (0x30 bytes)
Total size u32 (header + CLUT + image), CLUT size u32, image size u32, header size u16 (0x30 or larger when user data or the mipmap header follows), CLUT colour count u16, picture format u8, mipmap count u8, CLUT type u8, image type u8, width u16, height u16, GsTex0 u64, GsTex1 u64, GsRegs u32, GsTexClut u32. The image type is 1 = 16-bit colour, 2 = 24-bit, 3 = 32-bit, 4 = 4-bit indexed, 5 = 8-bit indexed. The CLUT type: bits 0-4 colour format (1 = 16-bit, 2 = 24-bit, 3 = 32-bit), bit 6 storage mode (CSM1/CSM2), bit 7 compound mode.
Pixels and palette
In the layout used by the ImHex pattern shipped with chihuahua the picture header is followed directly by the image data and then the palette entries (4 bytes each: red, green, blue, alpha). 4-bit pixels store the low nibble first. 8-bit CLUTs in CSM1 order are "twiddled": within each group of 32 entries, entries 8-15 and 16-23 swap places; a reader that shows scrambled colours has missed this. Unverified: a mipmap count above 1 inserts a mipmap header (miptbp registers and per-level sizes) after the picture header; the pattern file only has it as a comment. Unverified: with count 0 some tools still read one level.
Code & repositories
- https://github.com/anasrar/chihuahua @
83bb54e34991030ff224639159dd1c62568e9a98· license: MIT
Go tools for a PS2 game (MIT): pkg/tim2 holds a TIM2 reader/writer and an ImHex pattern (tim2.hexpat).
Tested on: source read, not run: source read, not run or built · checked 2026-10-19; last activity 2026-08-30
Pitfalls
- chihuahua's constants name the 128-byte alignment id as 0x81 in one place and 0x01 in its String method; check a real file before trusting either.
- Alpha in 32-bit data is 0-0x80 (0x80 opaque) on the PS2, not 0-0xFF. Unverified: not read in the chihuahua source, known from GS documentation.