# PlayStation TIM fixtures (tools/fixtures.py): TIM files written here (4-bit with two CLUTs, 8-bit, 15-bit direct # with STP bits and 0x0000 transparency, 24-bit with an odd width, VRAM positions) decoded by ImageMagick's TIM # reader (nix imagemagick, RGB: it ignores alpha) -> CRC-32 of the RGB bytes per CLUT row, plus the transparent # pixel count (colour 0x0000) computed here. # ImageMagick cannot read several CLUT rows: the 2-row file's reference is a copy with row 0 only. # tests/gen/tim.luau { { name, data, width, height, bpp, rgb = { crc of CLUT row 0 }, transparent, cluts } } import os, shutil, struct, tempfile, zlib def tim(rng, bpp, w, h, cluts=1): flags = {4: 0, 8: 1, 16: 2, 24: 3}[bpp] out = b"" colours = [] if bpp <= 8: n = 16 if bpp == 4 else 256 flags |= 8 for _ in range(cluts): row = [rng.randrange(65536) for _ in range(n)] row[0] = 0 row[1] = 0x8000 colours.append(row) out += struct.pack(" 1: n = 16 if bpp == 4 else 256 ref = struct.pack("