PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Compose: a clipped adjustment with no base inside a pass-through group reaches everything (#6535)
David Mann8534f0c93526
diff --git a/crates/compose/src/lib.rs b/crates/compose/src/lib.rsindex 6ee2b6a2c..f2733d157 100644--- a/crates/compose/src/lib.rs+++ b/crates/compose/src/lib.rs@@ -1156,9 +1156,14 @@ pub fn composite_bounds(layer: &Layer, canvas: Rect) -> Option<Rect> {pub fn change_bounds(layer: &Layer, canvas: Rect) -> Option<Rect> {fn reaches_below(l: &Layer) -> bool {match &l.content {- // Clipped, it changes only its base's pixels.LayerContent::Adjustment(_) => !l.clipped,- LayerContent::Group(g) if l.blend == BlendMode::PassThrough => g.children.iter().any(reaches_below),+ // Clipped to a base, an adjustment changes only the base's pixels; one with no base+ // beneath it in its list composites as an ordinary adjustment (#6535).+ LayerContent::Group(g) if l.blend == BlendMode::PassThrough => g.children.iter().enumerate().any(|(k, c)| {+ let orphan =+ c.clipped && matches!(c.content, LayerContent::Adjustment(_)) && g.children.get(..k).is_none_or(|below| below.iter().all(|b| b.clipped));+ orphan || reaches_below(c)+ }),_ => false,}}diff --git a/crates/compose/src/tests.rs b/crates/compose/src/tests.rsindex 42bbea272..9bbbaaf2a 100644--- a/crates/compose/src/tests.rs+++ b/crates/compose/src/tests.rs@@ -500,6 +500,32 @@ fn clipped_adjustment_changes_only_its_base() {assert_eq!(change_bounds_in(&on_group, 2, canvas), None);}+/// #6535: a clipped adjustment with no base beneath it, inside a pass-through group, composites+/// as an ordinary adjustment, so hiding the group or the layer clipped to it (which ends its+/// isolation) changes the whole canvas, not just the group's pixels.+#[test]+fn orphan_clipped_adjustment_in_pass_through_base_reaches_everything() {+ let canvas = Rect::new(0, 0, 8, 6);+ let mut d = doc_white(8, 6);+ let mut orphan = Layer::new("A", LayerContent::Adjustment(Adjustment::Invert));+ orphan.clipped = true;+ let mut g = Layer::group("G", vec![orphan, solid_layer("P", Rect::new(2, 1, 4, 3), [0.2, 0.4, 0.6, 1.0])]);+ g.blend = BlendMode::PassThrough;+ d.layers.push(g);+ let mut x = Layer::new("X", LayerContent::Adjustment(Adjustment::Invert));+ x.clipped = true;+ d.layers.push(x);+ let shown = px(&d, 0, 0);+ d.layers[2].visible = false;+ assert!(!close4(shown, px(&d, 0, 0)), "the toggle changes pixels outside the group");+ assert_eq!(change_bounds_in(&d.layers, 2, canvas), None);+ assert_eq!(change_bounds(&d.layers[1], canvas), None);+ // With a base beneath it the clipped adjustment stays inside the group.+ let LayerContent::Group(g) = &mut d.layers[1].content else { panic!("group") };+ g.children.swap(0, 1);+ assert_eq!(change_bounds_in(&d.layers, 2, canvas), Some(Rect::new(2, 1, 4, 3)));+}+#[test]fn threshold_posterize_levels_curves() {let mut buf = Buffer::filled(Rect::new(0, 0, 1, 1), [0.3, 0.3, 0.3, 1.0]);