From 5c617230094923224924c330aa247ae26a0ad2c0 Mon Sep 17 00:00:00 2001 From: yoriswind Date: Sat, 31 Oct 2026 09:56:57 -0700 Subject: [PATCH 1/4] Choose Stamp ink or paper without intermediate colors --- crates/algo/src/artistic_fx.rs | 3 +- crates/engine/tests/it/gallery_colours.rs | 40 +++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/crates/algo/src/artistic_fx.rs b/crates/algo/src/artistic_fx.rs index 6ef9dad13a..905b753ec6 100644 --- a/crates/algo/src/artistic_fx.rs +++ b/crates/algo/src/artistic_fx.rs @@ -1157,7 +1157,8 @@ fn apply_sketch(e: &GalleryEffect, win: &mut Win, ctx: &Ctx) -> bool { let mut l = win.lum(); blur1(&mut l, w, h, 0.3 + g("smoothness") * 0.3); for i in 0..win.c.len() { - win.c[i] = mix(bg, fg, smoothstep(bal + 0.02, bal - 0.02, l[i])); + // Smooth the shapes without introducing colors between the ink and paper. + win.c[i] = if l[i] < bal { fg } else { bg }; } } F::TornEdges => { diff --git a/crates/engine/tests/it/gallery_colours.rs b/crates/engine/tests/it/gallery_colours.rs index d1561e8aad..7973e861b2 100644 --- a/crates/engine/tests/it/gallery_colours.rs +++ b/crates/engine/tests/it/gallery_colours.rs @@ -31,3 +31,43 @@ fn colored_pencil_honours_session_background() { fn neon_glow_honours_session_background() { assert_ne!(one("neonGlow", "#ffffff"), one("neonGlow", "#0000ff"), "filter.gallery.neonGlow must honour the session background"); } + +/// Stamp uses the selected ink and paper without adding intermediate colors (#9912). +#[test] +fn stamp_uses_only_the_selected_colors() { + for depth in [8, 16, 32] { + for (fg, bg, ink, paper) in [("#000000", "#ffffff", [0.0, 0.0, 0.0], [1.0, 1.0, 1.0]), ("#ff0000", "#0000ff", [1.0, 0.0, 0.0], [0.0, 0.0, 1.0])] { + for smoothness in [1, 5, 50] { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 16, "height": 16, "depth": depth, "background": "#808080"})).unwrap(); + s.execute("tools.setColors", json!({"foreground": fg, "background": bg})).unwrap(); + s.execute("filter.gallery.stamp", json!({"lightDarkBalance": 25, "smoothness": smoothness})).unwrap(); + for p in image(&mut s).chunks_exact(4) { + assert!(p[..3] == ink || p[..3] == paper, "{depth}-bit, smoothness {smoothness}: Stamp added an intermediate color: {p:?}"); + assert_eq!(p[3], 1.0); + } + } + } + } +} + +/// Balance still selects dark or light, with the selection boundary and one-step Undo intact. +#[test] +fn stamp_balance_selection_and_undo() { + for depth in [8, 16, 32] { + for (balance, expected) in [(0, 1.0), (50, 0.0)] { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 16, "height": 16, "depth": depth, "background": "#808080"})).unwrap(); + s.execute("select.rect", json!({"x": 4, "y": 4, "width": 8, "height": 8, "antiAlias": false})).unwrap(); + let before = s.active().unwrap().doc.clone(); + let history = s.active().unwrap().history.past_len(); + let outside = px(&mut s, 2, 2); + s.execute("filter.gallery.stamp", json!({"lightDarkBalance": balance, "smoothness": 1})).unwrap(); + assert_eq!(px(&mut s, 8, 8), [expected, expected, expected, 1.0]); + assert_eq!(px(&mut s, 2, 2), outside); + assert_eq!(s.active().unwrap().history.past_len(), history + 1); + s.undo(); + assert_eq!(*s.active().unwrap().doc, *before); + } + } +} From 18b43023b03ae5fd406cd70b9408fa8c9bce7e79 Mon Sep 17 00:00:00 2001 From: yoriswind Date: Sat, 31 Oct 2026 10:12:34 -0700 Subject: [PATCH 2/4] Exercise Stamp smoothing detail and an intermediate balance --- crates/engine/tests/it/gallery_colours.rs | 26 +++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/crates/engine/tests/it/gallery_colours.rs b/crates/engine/tests/it/gallery_colours.rs index 7973e861b2..96b0305303 100644 --- a/crates/engine/tests/it/gallery_colours.rs +++ b/crates/engine/tests/it/gallery_colours.rs @@ -51,11 +51,11 @@ fn stamp_uses_only_the_selected_colors() { } } -/// Balance still selects dark or light, with the selection boundary and one-step Undo intact. +/// Balance controls the chosen color, with the selection boundary and one-step Undo intact. #[test] fn stamp_balance_selection_and_undo() { for depth in [8, 16, 32] { - for (balance, expected) in [(0, 1.0), (50, 0.0)] { + for (balance, expected) in [(0, 1.0), (40, 0.0), (50, 0.0)] { let mut s = Session::new(); s.execute("file.new", json!({"width": 16, "height": 16, "depth": depth, "background": "#808080"})).unwrap(); s.execute("select.rect", json!({"x": 4, "y": 4, "width": 8, "height": 8, "antiAlias": false})).unwrap(); @@ -71,3 +71,25 @@ fn stamp_balance_selection_and_undo() { } } } + +/// Smoothness changes spatial detail without adding intermediate colors. +#[test] +fn stamp_smoothness_changes_spatial_detail() { + for depth in [8, 16, 32] { + let render = |smoothness| { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 16, "height": 16, "depth": depth, "background": "#ffffff"})).unwrap(); + s.execute("select.rect", json!({"x": 6, "y": 6, "width": 4, "height": 4, "antiAlias": false})).unwrap(); + s.execute("edit.fill", json!({"contents": "color", "color": "#000000"})).unwrap(); + s.execute("select.deselect", json!({})).unwrap(); + s.execute("filter.gallery.stamp", json!({"lightDarkBalance": 25, "smoothness": smoothness})).unwrap(); + image(&mut s) + }; + let fine = render(1); + let smooth = render(50); + assert_ne!(fine, smooth, "{depth}-bit: Smoothness must change the spatial result"); + for p in fine.chunks_exact(4).chain(smooth.chunks_exact(4)) { + assert!(p[..3] == [0.0; 3] || p[..3] == [1.0; 3]); + } + } +} From 9ad4bccb761fba6b6a821805903fc32624c2b400 Mon Sep 17 00:00:00 2001 From: yoriswind <164435053+yoriswind@users.noreply.github.com> Date: Mon, 2 Nov 2026 22:48:16 -0800 Subject: [PATCH 3/4] ci: retrigger checks after contributor approval From 80b54d28971972a7586cabd69f0a12d62b9342d5 Mon Sep 17 00:00:00 2001 From: yoriswind Date: Mon, 2 Nov 2026 23:37:53 -0800 Subject: [PATCH 4/4] test(engine): use typed pixel chunks in Stamp gallery checks --- crates/engine/tests/it/gallery_colours.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/engine/tests/it/gallery_colours.rs b/crates/engine/tests/it/gallery_colours.rs index 96b0305303..e8ae544832 100644 --- a/crates/engine/tests/it/gallery_colours.rs +++ b/crates/engine/tests/it/gallery_colours.rs @@ -42,7 +42,7 @@ fn stamp_uses_only_the_selected_colors() { s.execute("file.new", json!({"width": 16, "height": 16, "depth": depth, "background": "#808080"})).unwrap(); s.execute("tools.setColors", json!({"foreground": fg, "background": bg})).unwrap(); s.execute("filter.gallery.stamp", json!({"lightDarkBalance": 25, "smoothness": smoothness})).unwrap(); - for p in image(&mut s).chunks_exact(4) { + for p in image(&mut s).as_chunks::<4>().0 { assert!(p[..3] == ink || p[..3] == paper, "{depth}-bit, smoothness {smoothness}: Stamp added an intermediate color: {p:?}"); assert_eq!(p[3], 1.0); } @@ -88,7 +88,7 @@ fn stamp_smoothness_changes_spatial_detail() { let fine = render(1); let smooth = render(50); assert_ne!(fine, smooth, "{depth}-bit: Smoothness must change the spatial result"); - for p in fine.chunks_exact(4).chain(smooth.chunks_exact(4)) { + for p in fine.as_chunks::<4>().0.iter().chain(smooth.as_chunks::<4>().0.iter()) { assert!(p[..3] == [0.0; 3] || p[..3] == [1.0; 3]); } }