80 findings, not the 14 the first run showed -- clippy stops at the first failing compilation unit, so `--keep-going` is what makes the list complete. 60 were machine-applicable (`cargo clippy --fix`). The rest by hand: * five descending `sort_by` -> `sort_by_key(Reverse(..))` * `chunks_exact(4)` on both sides of four zips, so the compared items stay `[u8; 4]` rather than one array against one slice * three `type` aliases for the census maps and the captured-quad tuple * `&PathBuf` -> `&Path` in two disc tests * two range loops; one of them keeps `#[allow(needless_range_loop)]` with the reason -- the index is into a map's value, which changes each iteration * the module doc list in `invert_capture` re-indented to markdown's rules * `blit`'s eight arguments get `#[allow(too_many_arguments)]`, not a struct One dead `let off = b.len();` in a `ratc` test is dropped rather than renamed. The sibling test at :162 is the one that asserts an offset; if this one was meant to as well, that is a test change and not a lint fix. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
100 lines
3.7 KiB
Rust
100 lines
3.7 KiB
Rust
//! Reconcile two ink counts for one screen that were never counting the same pixels.
|
|
//!
|
|
//! The port agent double-witnessed the pixel-cost claim in Godot — a renderer
|
|
//! sharing no code with `compose` — and got `GP_TITLE` entry 12 at **59 530 px**
|
|
//! ink above threshold 0 and **48 368** above 1. This crate reported **49 771**.
|
|
//! Neither is wrong; the question is which convention each was using, and on a
|
|
//! mostly-dark frame the answer moves thousands of pixels.
|
|
//!
|
|
//! So: count the same composite every way, and print the family. Whichever row
|
|
//! the port's numbers land in is the convention, and then the two renderers can be
|
|
//! compared on purpose rather than by coincidence.
|
|
//!
|
|
//! cargo run -p sylpheed-formats --example forced_backdrop_ink_thresholds
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use sylpheed_formats::{pak::PakArchive, ui_layout};
|
|
use ui_layout::ComposeOptions;
|
|
|
|
fn order_without_rule(build: &ui_layout::UiBuild, bundle: &[u8]) -> Vec<usize> {
|
|
let mut idx: Vec<usize> = (0..build.elements.len()).collect();
|
|
idx.sort_by_key(|&i| {
|
|
let el = &build.elements[i];
|
|
(
|
|
ui_layout::sprite_layer_key(build, bundle, el)
|
|
.or_else(|| ui_layout::implied_layer_key(&el.name))
|
|
.unwrap_or(u32::MAX),
|
|
i,
|
|
)
|
|
});
|
|
idx
|
|
}
|
|
|
|
fn counts(rgba: &[u8], t: u8) -> (usize, usize) {
|
|
let rgb = rgba
|
|
.as_chunks::<4>()
|
|
.0
|
|
.iter()
|
|
.filter(|p| p[0] > t || p[1] > t || p[2] > t)
|
|
.count();
|
|
let alpha = rgba.as_chunks::<4>().0.iter().filter(|p| p[3] > t).count();
|
|
(rgb, alpha)
|
|
}
|
|
|
|
fn main() {
|
|
let root = PathBuf::from(std::env::var("SYLPHEED_DISC").expect("SYLPHEED_DISC"));
|
|
let ar = PakArchive::open(root.join("dat/GP_TITLE.pak")).expect("GP_TITLE.pak");
|
|
|
|
for entry in [12usize, 15] {
|
|
let by = ar.read(&ar.entries()[entry]).expect("entry");
|
|
let b = ui_layout::parse_build(&by).expect("parse");
|
|
for (label, opts) in [
|
|
(
|
|
"primitives on (what the cost run used)",
|
|
ComposeOptions {
|
|
include_primitives: true,
|
|
backdrop: [0, 0, 0, 255],
|
|
..Default::default()
|
|
},
|
|
),
|
|
(
|
|
"primitives+focus+animated",
|
|
ComposeOptions {
|
|
include_primitives: true,
|
|
include_focus: true,
|
|
include_animated: true,
|
|
backdrop: [0, 0, 0, 255],
|
|
..Default::default()
|
|
},
|
|
),
|
|
] {
|
|
let with = ui_layout::derived_paint_order(&b, &by);
|
|
let without = order_without_rule(&b, &by);
|
|
let a = ui_layout::compose_with_order(&b, &by, opts, None, Some(&with));
|
|
let c = ui_layout::compose_with_order(&b, &by, opts, None, Some(&without));
|
|
println!(
|
|
"\n== GP_TITLE entry {entry} — {label} ({}x{})",
|
|
a.width, a.height
|
|
);
|
|
println!(
|
|
" threshold | RGB>t with rule | A>t with rule | RGB>t WITHOUT | A>t WITHOUT"
|
|
);
|
|
for t in [0u8, 1, 2, 4, 8, 16] {
|
|
let (r1, a1) = counts(&a.rgba, t);
|
|
let (r0, a0) = counts(&c.rgba, t);
|
|
println!(" >{t:<8} | {r1:>16} | {a1:>14} | {r0:>13} | {a0:>11}");
|
|
}
|
|
let changed = a
|
|
.rgba
|
|
.as_chunks::<4>()
|
|
.0
|
|
.iter()
|
|
.zip(c.rgba.as_chunks::<4>().0.iter())
|
|
.filter(|(x, y)| x != y)
|
|
.count();
|
|
println!(" exact-RGBA changed pixels between the two orders: {changed}");
|
|
}
|
|
}
|
|
}
|