diff --git a/crates/engine/src/cmd/background_eraser_transparency_lock_tests.rs b/crates/engine/src/cmd/background_eraser_transparency_lock_tests.rs index ea83a7bd5c..66f7727e58 100644 --- a/crates/engine/src/cmd/background_eraser_transparency_lock_tests.rs +++ b/crates/engine/src/cmd/background_eraser_transparency_lock_tests.rs @@ -71,6 +71,31 @@ fn a_drag_and_the_live_preview_erase_a_transparency_locked_layer_too() { assert!(target(&s).locks.transparency); } +#[test] +fn with_a_colour_channel_target_the_preview_matches_the_commit_on_a_locked_layer() { + // A channel target erases colour channels only (towards the background colour) and never + // changes alpha, so the lock the preview keeps there gives the commit's pixels exactly. The + // stroke crosses the band's edge, so transparent pixels are under the tip too. + let mut s = session(8); + s.execute("layer.setProps", json!({"locks": {"transparency": true}})).unwrap(); + let opts = |pts: &[[f64; 2]]| json!({"points": pts, "size": 16, "hardness": 0.5, "target": {"colors": [1]}}); + let all = [[8.0, 12.0], [32.0, 12.0], [56.0, 12.0]]; + let mut live = live_background_eraser(&s, &opts(&all[..1])).unwrap(); + for q in &all[1..] { + live.push(&[photocraft_paint::StrokePoint::new(q[0], q[1], 1.0)]).unwrap(); + } + let id = s.active().unwrap().active_layer.unwrap(); + let shown = live.doc.layer(id).unwrap().surface().unwrap().clone(); + let before = alphas(&s); + s.execute("paint.backgroundEraser", opts(&all)).unwrap(); + let surf = target(&s).surface().unwrap(); + assert!(surf.rgba(32, 12)[1] > 0.0, "the green channel moved towards the white background"); + for (x, y) in (0..40).flat_map(|y| (0..64).map(move |x| (x, y))) { + assert_eq!(shown.rgba(x, y), surf.rgba(x, y), "({x}, {y}): preview = commit"); + } + assert_eq!(alphas(&s), before, "alpha untouched"); +} + #[test] fn locked_pixels_and_lock_all_still_refuse() { for locks in [json!({"pixels": true}), json!({"all": true})] { diff --git a/crates/engine/src/cmd/retouch_cmds/dab.rs b/crates/engine/src/cmd/retouch_cmds/dab.rs index 70ba5683ed..a950ad5992 100644 --- a/crates/engine/src/cmd/retouch_cmds/dab.rs +++ b/crates/engine/src/cmd/retouch_cmds/dab.rs @@ -538,7 +538,9 @@ impl LiveDab { } /// Mix the dabs back without the layer's transparency lock, for a tool that erases a locked - /// layer anyway (the Background Eraser). Points shown before this keep the lock. + /// layer anyway (the Background Eraser). Call it before pushing any points: build the dab with + /// the stroke's points taken out, then [`Self::push`] them (as `live_background_eraser` does), + /// because points pushed before it were already mixed back with the lock. pub(crate) fn unlocked(mut self) -> Self { self.lock = false; self