From 484483b691b34ed670f01d4e849bbaf4cd250e53 Mon Sep 17 00:00:00 2001 From: David Mann Date: Tue, 17 Nov 2026 02:03:03 +0100 Subject: [PATCH] test: build the CMYK test profile once, run large raw-develop sizes at one depth - cmyk_flatten_profile: synthesise the test profile once per process and share one Arc, so CmykSpace's per-allocation cache builds the transforms once; exact() reads both rows from one run (4 documents, not 8). - camera_raw GPU tests: the 858x572 and 1600x900 comparisons run at one depth each. The depth only changes the input quantization (8 and 16 bits both develop with float = false) and every depth runs at 171x113 above. - cols_timing is a benchmark without assertions: ignore it like its siblings. - compose: delete clipped_dissolve_is_binary_and_preserves_the_base_shape, a byte-identical copy of clipped_dissolve_opacity_fill_is_binary_and_ preserves_base_shape (whose doc comment names both issues). Part of #15376. Co-Authored-By: Claude Opus 5.5 --- crates/algo/src/fxutil.rs | 3 +- crates/compose/src/tests.rs | 29 ---------------- crates/engine/tests/cmyk_flatten_profile.rs | 37 ++++++++++++++------- crates/gpu/tests/it/camera_raw.rs | 21 ++++++------ 4 files changed, 37 insertions(+), 53 deletions(-) diff --git a/crates/algo/src/fxutil.rs b/crates/algo/src/fxutil.rs index 1f5faa4254..a1ca795388 100644 --- a/crates/algo/src/fxutil.rs +++ b/crates/algo/src/fxutil.rs @@ -447,8 +447,9 @@ mod tests { } } - /// `cargo test -p photocraft-algo --release --lib -- --nocapture cols_timing` + /// `cargo test -p photocraft-algo --release --lib -- --ignored --nocapture cols_timing` #[test] + #[ignore = "timing"] fn cols_timing() { for (w, h, n, r) in [(324, 324, 2, 9), (1122, 1122, 2, 79), (1122, 786, 2, 79)] { // Each pass gets its own copy of the same input: a pass run after the other would diff --git a/crates/compose/src/tests.rs b/crates/compose/src/tests.rs index 0018d22093..e281204b00 100644 --- a/crates/compose/src/tests.rs +++ b/crates/compose/src/tests.rs @@ -617,35 +617,6 @@ fn clipped_dissolve_matches_whole_render_at_offset_regions_and_depths() { } } -/// #4921: Dissolve coverage must survive clipping and use Opacity × Fill. -#[test] -fn clipped_dissolve_is_binary_and_preserves_the_base_shape() { - let mut d = doc_white(40, 12); - d.layers.push(solid_layer("base", Rect::new(0, 0, 20, 12), [0.0, 0.0, 1.0, 1.0])); - let mut clip = solid_layer("clip", d.bounds(), [1.0, 0.0, 0.0, 1.0]); - clip.clipped = true; - clip.blend = BlendMode::Dissolve; - clip.opacity = 0.6; - clip.fill_opacity = 0.5; - d.layers.push(clip); - let mut red = 0; - let mut blue = 0; - for y in 0..12 { - for x in 0..20 { - let p = px(&d, x, y); - if close4(p, [1.0, 0.0, 0.0, 1.0]) { - red += 1; - } else { - assert!(close4(p, [0.0, 0.0, 1.0, 1.0]), "Dissolve must not interpolate: {p:?} at ({x},{y})"); - blue += 1; - } - } - assert!(close4(px(&d, 30, y), [1.0; 4]), "outside the base the clip is invisible"); - } - assert!(red > 0 && blue > 0, "Dissolve must expose both source and base: {red}/{blue}"); - assert!((red as f32 / (red + blue) as f32 - 0.3).abs() < 0.1, "coverage should follow 60% opacity × 50% fill: {red}/{blue}"); -} - #[test] fn hidden_base_hides_clipping_group() { let mut d = doc_white(4, 4); diff --git a/crates/engine/tests/cmyk_flatten_profile.rs b/crates/engine/tests/cmyk_flatten_profile.rs index c7f47e9ef8..bb088ec1a6 100644 --- a/crates/engine/tests/cmyk_flatten_profile.rs +++ b/crates/engine/tests/cmyk_flatten_profile.rs @@ -33,10 +33,22 @@ const INKS: [[f32; 4]; 8] = [ [0.1, 0.0, 0.6, 0.3], ]; +/// The test profile, synthesised once per process. Synthesis samples and inverts whole LUTs, and +/// `CmykSpace::for_profile` caches by allocation, so one shared `Arc` also builds the transforms +/// once instead of for every document. fn profile() -> Arc> { - craft_cms::synth::cmyk_profile(&craft_cms::synth::CmykParams { description: "Test Uncoated".into(), tvi: [0.26, 0.26, 0.26, 0.3], ..Default::default() }) - .unwrap() - .to_bytes() + static PROFILE: std::sync::OnceLock>> = std::sync::OnceLock::new(); + PROFILE + .get_or_init(|| { + craft_cms::synth::cmyk_profile(&craft_cms::synth::CmykParams { + description: "Test Uncoated".into(), + tvi: [0.26, 0.26, 0.26, 0.3], + ..Default::default() + }) + .unwrap() + .to_bytes() + }) + .clone() } /// A one-layer (Background) CMYK document, tagged with `profile()` when `tag`: the first row is @@ -85,22 +97,23 @@ fn max_diff(a: &[[f32; 4]], b: &[[f32; 4]]) -> f32 { a.iter().zip(b).flat_map(|(p, q)| (0..4).map(move |c| (p[c] - q[c]).abs())).fold(0.0, f32::max) } -/// Runs `run` on a document and returns how far the inks of `row` (0 = separations, 1 = any +/// Runs `run` on a document and returns how far the inks of each row (0 = separations, 1 = any /// inks) moved. -fn drift(depth: u32, tag: bool, row: usize, run: impl FnOnce(&mut Session)) -> f32 { +fn drift(depth: u32, tag: bool, run: impl FnOnce(&mut Session)) -> [f32; 2] { let mut s = document(depth, tag); let before = inks(&s); run(&mut s); let after = inks(&s); - let r = row * W as usize..(row + 1) * W as usize; - max_diff(&before[r.clone()], &after[r]) + [0, 1].map(|row| { + let r = row * W as usize..(row + 1) * W as usize; + max_diff(&before[r.clone()], &after[r]) + }) } fn exact(what: &str, run: impl Fn(&mut Session)) { for depth in [8, 16] { for tag in [true, false] { - for row in [0, 1] { - let d = drift(depth, tag, row, &run); + for (row, d) in drift(depth, tag, &run).into_iter().enumerate() { assert!(d == 0.0, "{depth}-bit {what} (tagged: {tag}, row {row}): inks moved by {d}"); } } @@ -153,7 +166,7 @@ const ROUND_TRIP: f32 = 10.0 / 255.0; #[test] fn merge_down_separates_through_the_document_profile() { for depth in [8, 16] { - let d = drift(depth, true, 0, |s| { + let [d, _] = drift(depth, true, |s| { s.execute("layer.new.layer", json!({})).unwrap(); s.execute("layer.mergeDown", json!({})).unwrap(); }); @@ -164,7 +177,7 @@ fn merge_down_separates_through_the_document_profile() { #[test] fn merge_visible_separates_through_the_document_profile() { for depth in [8, 16] { - let d = drift(depth, true, 0, |s| { + let [d, _] = drift(depth, true, |s| { s.execute("layer.new.layer", json!({})).unwrap(); s.execute("layer.mergeVisible", json!({})).unwrap(); }); @@ -179,7 +192,7 @@ fn merge_visible_separates_through_the_document_profile() { #[test] fn rasterize_layer_style_separates_through_the_document_profile() { for depth in [8, 16] { - let d = drift(depth, true, 0, |s| { + let [d, _] = drift(depth, true, |s| { s.execute("layer.new.layerFromBackground", json!({})).unwrap(); s.execute("layer.layerStyle.dropShadow", json!({"distance": 40, "size": 0})).unwrap(); s.execute("layer.rasterize.layerStyle", json!({})).unwrap(); diff --git a/crates/gpu/tests/it/camera_raw.rs b/crates/gpu/tests/it/camera_raw.rs index 5ef4c6e7c0..905a9ad929 100644 --- a/crates/gpu/tests/it/camera_raw.rs +++ b/crates/gpu/tests/it/camera_raw.rs @@ -465,12 +465,12 @@ fn shadows_and_highlights_with_per_pixel_stages() { CameraRaw { shadows: 30.0, highlights: -30.0, whites: 40.0, blacks: -30.0, encoding_gamma: 1.8, ..Default::default() }, ], ); - // At the dialog's proxy size. + // At the dialog's proxy size, at one depth: the depth only changes how the input is + // quantized (8 and 16 bits both develop with `float = false`), and every depth already ran + // above at 171×113. The size is what matters here (subsampled pyramid levels). let Some(mut g) = gpu() else { return }; - for depth in DEPTHS { - let d = compare_at(&mut g, &all, depth, (858, 572)); - eprintln!("shadows/highlights + per pixel 858x572 {depth:?}: max |GPU - CPU| = {d:.2e}"); - } + let d = compare_at(&mut g, &all, Depth::Sixteen, (858, 572)); + eprintln!("shadows/highlights + per pixel 858x572: max |GPU - CPU| = {d:.2e}"); } /// Asserts that each of `sets` moves some pixel of the test image by over 2 %, so a comparison @@ -546,12 +546,11 @@ fn clarity_texture_and_dehaze_with_shadows_highlights_and_per_pixel_stages() { check("clarity/texture/dehaze + shadows/highlights + per pixel", &sets); let Some(mut g) = gpu() else { return }; // At the dialog's proxy size (Dehaze and Clarity on a copy subsampled twice), and wider (three - // times). - for size in [(858, 572), (1600, 900)] { - for depth in DEPTHS { - let d = compare_at(&mut g, &all, depth, size); - eprintln!("everything {size:?} {depth:?}: max |GPU - CPU| = {d:.2e}"); - } + // times). One depth per size: the depth only changes how the input is quantized (8 and 16 + // bits both develop with `float = false`), and every depth already ran above at 171×113. + for (size, depth) in [((858, 572), Depth::Eight), ((1600, 900), Depth::Float)] { + let d = compare_at(&mut g, &all, depth, size); + eprintln!("everything {size:?} {depth:?}: max |GPU - CPU| = {d:.2e}"); } }