This branch predates CI on `main`. `cargo fmt --all` only; no behaviour. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
73 lines
2.6 KiB
Rust
73 lines
2.6 KiB
Rust
//! Is T8aD `+0x08` a per-sprite MODE, or a texture FORMAT word?
|
|
//!
|
|
//! On the main menu the two frames share `+0x08 = 0x8050` and no other sprite has
|
|
//! it — a candidate for the blend/alpha mode `sylpheed-port` asked for. Before
|
|
//! offering it, refute it: if 0x8050 is common disc-wide on ordinary sprites, it
|
|
//! is not frame-specific and not a mode.
|
|
//!
|
|
//! cargo run -p sylpheed-formats --example t8ad_word8_census
|
|
use std::collections::BTreeMap;
|
|
use std::path::PathBuf;
|
|
use sylpheed_formats::{pak::PakArchive, ui_layout};
|
|
|
|
fn main() {
|
|
let root = PathBuf::from(std::env::var("SYLPHEED_DISC").expect("SYLPHEED_DISC"));
|
|
let mut paks: Vec<_> = std::fs::read_dir(root.join("dat"))
|
|
.expect("dat")
|
|
.filter_map(|e| e.ok().map(|e| e.path()))
|
|
.filter(|p| p.extension().map(|x| x == "pak").unwrap_or(false))
|
|
.collect();
|
|
paks.sort();
|
|
let mut hist: BTreeMap<u32, usize> = BTreeMap::new();
|
|
let mut frames_like: BTreeMap<u32, usize> = BTreeMap::new();
|
|
let mut examples: BTreeMap<u32, Vec<String>> = BTreeMap::new();
|
|
for p in &paks {
|
|
let Ok(ar) = PakArchive::open(p) else {
|
|
continue;
|
|
};
|
|
for e in ar.entries() {
|
|
let Ok(by) = ar.read(e) else { continue };
|
|
let Some(b) = ui_layout::parse_build(&by) else {
|
|
continue;
|
|
};
|
|
for (n, (off, size)) in &b.sprites {
|
|
let s = &by[*off..(*off + *size).min(by.len())];
|
|
if s.len() < 48 {
|
|
continue;
|
|
}
|
|
let w = u32::from_be_bytes([s[8], s[9], s[10], s[11]]);
|
|
*hist.entry(w).or_default() += 1;
|
|
if n.contains("frame") {
|
|
*frames_like.entry(w).or_default() += 1
|
|
}
|
|
let ex = examples.entry(w).or_default();
|
|
if ex.len() < 3 && !ex.contains(n) {
|
|
ex.push(n.clone())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
let total: usize = hist.values().sum();
|
|
println!(
|
|
"{total} sprites disc-wide; distinct +0x08 values: {}\n",
|
|
hist.len()
|
|
);
|
|
println!(
|
|
"{:>10} {:>8} {:>10} examples",
|
|
"value", "count", "of which 'frame'"
|
|
);
|
|
for (v, c) in hist.iter().filter(|(_, c)| **c >= 20) {
|
|
println!(
|
|
"{:>#10x} {c:>8} {:>10} {}",
|
|
v,
|
|
frames_like.get(v).copied().unwrap_or(0),
|
|
examples[v].join(", ")
|
|
);
|
|
}
|
|
println!(
|
|
"\n0x8050 specifically: {} sprites, {} of them named *frame*",
|
|
hist.get(&0x8050).copied().unwrap_or(0),
|
|
frames_like.get(&0x8050).copied().unwrap_or(0)
|
|
);
|
|
}
|