//! 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 { let mut idx: Vec = (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}"); } } }