Decode level textures: 8-bit indices through a CSM1 palette
Adds texture.rs and makes the pipeline write gs_ram.bin, which it had been skipping. Nothing could be decoded before this: the CLUTs live there. A level texture is not pixels, it is palette indices -- width*height bytes at core_data[textures_base + data_offset], with colour coming from a 256-entry CLUT at gs_ram[palette * 0x100]. gs_ram is a byte range in the level's data extent header at offset 0x10, 518,656 bytes on level 0. Two PS2 conventions have to be honoured and neither is a design choice: within each 32-entry CLUT group the two middle 8-entry blocks are swapped (bits 3 and 4 of the index are exchanged, an involution), and alpha runs 0..=0x80 rather than 0..=255 with 0x80 fully opaque. The mip chain splits across two buffers: levels 0 and 1 are in the texture block with level 1 immediately after level 0, and levels 2 and 3 are resident in gs_ram at mipmap*0x100 and pad*0x100. Tfrag textures are square so every level halves evenly. Verification is two-layered, because every step here is a table lookup and a wrong CLUT remap still produces a well-formed image of the wrong thing. All 1,595 tfrag textures across all 27 levels decode; 96.8% are fully opaque and 96.3% use more than eight colours. On top of that, `gc-extract dump-texture` writes any texture or mip level as a PPM. Level 0 texture 0 comes back as a clean bevelled metal panel with rivets and specular highlights, and texture 74 as a vent grille whose punched windows are fully transparent. That tool is worth keeping: it is the cheapest way to tell a decode that is merely well-formed from one that is right. The hash table is regenerated for the 27 new gs_ram.bin files, now 5,186 files and 5,685,541,143 bytes.
This commit is contained in:
@@ -158,6 +158,19 @@ pub fn unpack(iso_path: &Path, out_dir: &Path) -> Result<Vec<Extracted>, String>
|
||||
);
|
||||
parts += 1;
|
||||
}
|
||||
// Graphics Synthesizer RAM holds the CLUTs the tfrag
|
||||
// texture table's palette indices point into, so it
|
||||
// is needed to decode any level texture.
|
||||
let gs = data_header.part(LevelDataPart::GsRam);
|
||||
if let Ok(bytes) = gs.slice(data_extent, data_extent.len()) {
|
||||
write_file(
|
||||
out_dir,
|
||||
&format!("{stem}/gs_ram.bin"),
|
||||
bytes,
|
||||
&mut written,
|
||||
);
|
||||
parts += 1;
|
||||
}
|
||||
}
|
||||
Err(e) => eprintln!(" {stem}: data extent header did not parse: {e}"),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user