""" TGA reader for uncompressed true-colour images (Type 2). Stores pixels as RGBA8888: (R<<24 | G<<16 | B<<8 | A). Matches the convention in TerrarumSansBitmap.kt where .and(255) checks the alpha channel (lowest byte). """ import struct from typing import List class TgaImage: __slots__ = ('width', 'height', 'pixels') def __init__(self, width: int, height: int, pixels: List[int]): self.width = width self.height = height self.pixels = pixels # flat array, row-major def get_pixel(self, x: int, y: int) -> int: """Get pixel at (x, y) as RGBA8888 (R in bits 31-24, A in bits 7-0).""" if x < 0 or x >= self.width or y < 0 or y >= self.height: return 0 return self.pixels[y * self.width + x] def read_tga(path: str) -> TgaImage: """Read an uncompressed true-colour TGA file.""" with open(path, 'rb') as f: data = f.read() pos = 0 def u8(): nonlocal pos val = data[pos] pos += 1 return val def u16(): nonlocal pos val = struct.unpack_from('