From c7d5a8d4835d4685127d575cb2b1d50b48f016de Mon Sep 17 00:00:00 2001 From: Sergey Yadryshnikov Date: Tue, 27 Oct 2026 16:57:28 +0700 Subject: [PATCH 1/7] fix(layers): Merge Down keeps the lower layer's layer style live Photoshop, observed with reproducible fixtures (PR #8750), keeps the lower layer's style live on the merged layer, where it re-composes over the union of both layers' content. pixels::merge_down replaced the lower layer with a fresh Layer::new, whose effects are empty, so a shadow or glow on the layer below was lost. Bake the pair without the lower layer's style (std::mem::take) and restore it on the merged layer, and render through a Document clone so the bake keeps the document's own Global Light, patterns and ICC profile. --- .../src/cmd/layer_multi_cmds/tests.rs | 74 +++++++++++++++++++ crates/engine-core/src/pixels.rs | 16 ++-- 2 files changed, 85 insertions(+), 5 deletions(-) diff --git a/crates/engine-core/src/cmd/layer_multi_cmds/tests.rs b/crates/engine-core/src/cmd/layer_multi_cmds/tests.rs index c690b0d0aeb..3c27b6eaa69 100644 --- a/crates/engine-core/src/cmd/layer_multi_cmds/tests.rs +++ b/crates/engine-core/src/cmd/layer_multi_cmds/tests.rs @@ -967,6 +967,80 @@ fn merging_keeps_layer_effects_outside_the_pixels() { } } +#[test] +fn merging_down_keeps_the_lower_layers_style_live_on_the_union() { + // Merge Down over a styled layer keeps its style live, as in Photoshop, where it + // re-composes over the merged pixels: the glow that only surrounded the lower layer now + // surrounds the union of both layers' content. + let probe = |s: &Session| { + let d = doc(s); + photocraft_compose::render(d, d.bounds()).get(75, 26) + }; + for depth in [8, 16, 32] { + let mut s = session(depth); + let lower = rect_layer(&mut s, Rect::new(10, 10, 30, 30)); + let upper = rect_layer(&mut s, Rect::new(60, 20, 72, 32)); + s.execute("layer.layerStyle.outerGlow", json!({"layer": lower.0, "blend": "normal", "size": 6, "color": "#000000", "add": true})).unwrap(); + let before = probe(&s); + assert!(before.iter().all(|v| *v > 0.9), "depth {depth}: the glow never reaches the probe before the merge: {before:?}"); + s.execute("layer.mergeDown", json!({"layer": upper.0})).unwrap(); + let merged = doc(&s).layer(lower).unwrap().clone(); + assert!(doc(&s).layer(upper).is_none()); + assert_eq!(merged.effects.items.len(), 1); + assert!(merged.effects.items.iter().all(photocraft_doc::Effect::enabled), "the style stays live on the merged layer"); + let after = probe(&s); + assert!( + after.iter().take(3).zip(&before).all(|(a, b)| *a < *b - 0.03), + "depth {depth}: the glow re-applies to the merged union: {before:?} -> {after:?}" + ); + } +} + +#[test] +fn merging_selected_layers_bakes_the_bottom_layers_style_to_pixels() { + // Observed in Photoshop (fixtures in PR #8750): ⌘E over a selection merges the selected + // layers preserving the visible composite — the bottommost layer's style is baked into + // the merged pixels and no longer carried as a live effect, so it keeps drawing only + // around its own shape and never wraps the upper layers' content. + for depth in [8, 16, 32] { + let mut s = session(depth); + let lower = rect_layer(&mut s, Rect::new(10, 10, 30, 30)); + let upper = rect_layer(&mut s, Rect::new(60, 20, 72, 32)); + s.execute("layer.layerStyle.outerGlow", json!({"layer": lower.0, "blend": "normal", "size": 6, "color": "#000000", "add": true})).unwrap(); + let before = photocraft_compose::render(doc(&s), doc(&s).bounds()); + select_all(&mut s, &[lower, upper]); + let m = LayerId(s.execute("layer.mergeLayers", json!({})).unwrap()["layer"].as_u64().unwrap()); + assert!(doc(&s).layer(m).unwrap().effects.items.is_empty(), "depth {depth}: Merge Layers drops the style"); + let after = photocraft_compose::render(doc(&s), doc(&s).bounds()); + let worst = before.px.iter().zip(&after.px).map(|(a, b)| a.iter().zip(b).map(|(x, y)| (x - y).abs()).fold(0.0f32, f32::max)).fold(0.0f32, f32::max); + assert!(worst <= 1.5 / 255.0, "depth {depth}: Merge Layers preserves the visible composite (off by {worst})"); + } +} + +#[test] +fn merging_down_inside_the_shaped_layer_is_a_pixel_match() { + // With the upper layer fully inside the lower one's shape, the union is the same shape, so + // a correct merge is a pixel-for-pixel match: the style is neither lost, nor applied + // twice, and Global Light follows the document instead of `Document::new` defaults. + for depth in [8, 16, 32] { + let mut s = session(depth); + let lower = rect_layer(&mut s, Rect::new(10, 10, 60, 60)); + let upper = rect_layer(&mut s, Rect::new(25, 25, 45, 45)); + s.edit("light", |doc, _| { + doc.global_light = photocraft_doc::GlobalLight { angle: 20.0, altitude: 40.0 }; + Ok(()) + }) + .unwrap(); + s.execute("layer.layerStyle.dropShadow", json!({"layer": lower.0, "blend": "normal", "useGlobalLight": true, "angle": 120, "distance": 5, "spread": 0, "size": 0, "opacity": 100, "color": "#000000"})).unwrap(); + let before = photocraft_compose::render(doc(&s), doc(&s).bounds()); + s.execute("layer.mergeDown", json!({"layer": upper.0})).unwrap(); + assert!(!doc(&s).layer(lower).unwrap().effects.items.is_empty()); + let after = photocraft_compose::render(doc(&s), doc(&s).bounds()); + let worst = before.px.iter().zip(&after.px).map(|(a, b)| a.iter().zip(b).map(|(x, y)| (x - y).abs()).fold(0.0f32, f32::max)).fold(0.0f32, f32::max); + assert!(worst <= 1.5 / 255.0, "depth {depth}: merge down changed the composite (off by {worst})"); + } +} + #[test] fn merging_a_group_down_preserves_the_composite() { for depth in [8, 16, 32] { diff --git a/crates/engine-core/src/pixels.rs b/crates/engine-core/src/pixels.rs index 0e5572d0d9d..d86b510d688 100644 --- a/crates/engine-core/src/pixels.rs +++ b/crates/engine-core/src/pixels.rs @@ -557,11 +557,14 @@ pub fn remap_surface(s: &Surface, map: impl Fn(i32, i32) -> (i32, i32)) -> Surfa /// Merge `upper` onto `lower` producing a raster layer (Layer → Merge Down). pub fn merge_down(doc: &Document, lower: &Layer, upper: &Layer) -> Layer { let format = doc.pixel_format(); - let stack = vec![lower.clone(), upper.clone()]; - let mut tmp = Document::new("merge", doc.size, format.mode, format.sample); - // The pair is read (and a CMYK one separated again) through the document's own profile. - tmp.icc_profile = doc.icc_profile.clone(); - tmp.layers = stack.into(); + // Photoshop keeps the lower layer's layer style live on the merged layer, where it + // re-applies to the merged pixels: bake the pair without it so it is not applied twice. + let mut bare_lower = lower.clone(); + let style = std::mem::take(&mut bare_lower.effects); + // The pair is rendered with the document's own Global Light, patterns and colour profile, + // and read (and a CMYK one separated again) through that profile. + let mut tmp = doc.clone(); + tmp.layers = vec![bare_lower, upper.clone()].into(); // A Background stays canvas-sized; any other layer keeps the pixels outside the canvas (#5067). let s = if doc.is_background(lower.id) { composite_layers(&tmp, format, None) } else { composite_layers_uncropped(&tmp, format) }; let mut merged = Layer::new(lower.name.clone(), LayerContent::Raster(s)); @@ -576,5 +579,8 @@ pub fn merge_down(doc: &Document, lower: &Layer, upper: &Layer) -> Layer { merged.clipped = lower.clipped && upper.clipped; merged.label = lower.label; merged.link_group = lower.link_group; + // The fill opacity and the masks are in the pixels now; the layer style is kept, live, and + // recomposes over the union of both layers' content. + merged.effects = style; merged } From ab052d12d92b2ff023fb42bcd71b4330e590eb9f Mon Sep 17 00:00:00 2001 From: Sergey Yadryshnikov Date: Tue, 27 Oct 2026 16:57:28 +0700 Subject: [PATCH 2/7] contributors: add yadser (Sergey Yadryshnikov) --- contributors/people.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/contributors/people.toml b/contributors/people.toml index e86ee8a01a1..7cc9c1efece 100644 --- a/contributors/people.toml +++ b/contributors/people.toml @@ -306,6 +306,9 @@ sync_github_name = false real_name = "Jason DeBoever" sync_github_name = true +[people.yadser] +real_name = "Sergey Yadryshnikov" + [people.dylanmtaylor] sync_github_name = true From 40987811397c0549a73399e52f9406e372edf310 Mon Sep 17 00:00:00 2001 From: Sergey Yadryshnikov Date: Tue, 27 Oct 2026 21:10:43 +0700 Subject: [PATCH 3/7] fix(layers): Merge Down drops a zero-fill layer's style with its fill Photoshop, observed with fixtures (thread in PR #8750), drops a zero-fill lower layer's whole contribution at Merge Down: the glow that outlined its invisible shape disappears with the fill and nothing re-appears on the union. Our merge_down kept the style live, so the glow re-planted around the merged union. Keep the style live only when the lower layer's fill opacity is non-zero, with a regression test at 8/16/32-bit. --- .../src/cmd/layer_multi_cmds/tests.rs | 30 +++++++++++++++++++ crates/engine-core/src/pixels.rs | 8 +++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/crates/engine-core/src/cmd/layer_multi_cmds/tests.rs b/crates/engine-core/src/cmd/layer_multi_cmds/tests.rs index 3c27b6eaa69..9131c02abea 100644 --- a/crates/engine-core/src/cmd/layer_multi_cmds/tests.rs +++ b/crates/engine-core/src/cmd/layer_multi_cmds/tests.rs @@ -1017,6 +1017,36 @@ fn merging_selected_layers_bakes_the_bottom_layers_style_to_pixels() { } } +#[test] +fn merging_down_drops_the_style_of_a_zero_fill_lower_layer() { + // Photoshop drops a zero-fill lower layer's whole contribution at Merge Down: the fill + // already shows nothing and the style goes with it, so the glow that outlined its shape + // before the merge is gone after it and nothing re-appears on the union (fixtures in + // PR #8750, a Fill-0% layer with Outer Glow and a disjoint upper layer). + let probe = |s: &Session| { + let d = doc(s); + photocraft_compose::render(d, d.bounds()).get(32, 20) + }; + for depth in [8, 16, 32] { + let mut s = session(depth); + let lower = rect_layer(&mut s, Rect::new(10, 10, 30, 30)); + let upper = rect_layer(&mut s, Rect::new(60, 20, 72, 32)); + s.execute("layer.layerStyle.outerGlow", json!({"layer": lower.0, "blend": "normal", "size": 6, "color": "#000000", "add": true})).unwrap(); + s.edit("zero fill", |doc, _| { + doc.layer_mut(lower).unwrap().fill_opacity = 0.0; + Ok(()) + }) + .unwrap(); + let before = probe(&s); + assert!(before.iter().take(3).all(|v| *v < 0.97), "depth {depth}: the glow outlines the invisible shape before the merge: {before:?}"); + s.execute("layer.mergeDown", json!({"layer": upper.0})).unwrap(); + let merged = doc(&s).layer(lower).unwrap().clone(); + assert!(merged.effects.items.is_empty(), "depth {depth}: the zero-fill style is dropped with the fill"); + let after = probe(&s); + assert!(after.iter().take(3).zip(&before).all(|(a, b)| *a > *b + 0.03), "depth {depth}: the glow went with the zero fill: {before:?} -> {after:?}"); + } +} + #[test] fn merging_down_inside_the_shaped_layer_is_a_pixel_match() { // With the upper layer fully inside the lower one's shape, the union is the same shape, so diff --git a/crates/engine-core/src/pixels.rs b/crates/engine-core/src/pixels.rs index d86b510d688..8c1aac39464 100644 --- a/crates/engine-core/src/pixels.rs +++ b/crates/engine-core/src/pixels.rs @@ -580,7 +580,11 @@ pub fn merge_down(doc: &Document, lower: &Layer, upper: &Layer) -> Layer { merged.label = lower.label; merged.link_group = lower.link_group; // The fill opacity and the masks are in the pixels now; the layer style is kept, live, and - // recomposes over the union of both layers' content. - merged.effects = style; + // recomposes over the union of both layers' content. A zero-fill lower layer is the one + // exception: Photoshop drops its whole contribution at Merge Down — the fill shows nothing + // and the style goes with it, so nothing re-appears on the union (fixtures in the PR). + if lower.fill_opacity != 0.0 { + merged.effects = style; + } merged } From 7421674b1b173eeee925f0ab05ada6b846cf78ee Mon Sep 17 00:00:00 2001 From: Sergey Yadryshnikov Date: Tue, 27 Oct 2026 22:01:01 +0700 Subject: [PATCH 4/7] Revert "fix(layers): Merge Down drops a zero-fill layer's style with its fill" This reverts commit cb2c8951bb485742a1c49727c2c51df24d779034. --- .../src/cmd/layer_multi_cmds/tests.rs | 30 ------------------- crates/engine-core/src/pixels.rs | 8 ++--- 2 files changed, 2 insertions(+), 36 deletions(-) diff --git a/crates/engine-core/src/cmd/layer_multi_cmds/tests.rs b/crates/engine-core/src/cmd/layer_multi_cmds/tests.rs index 9131c02abea..3c27b6eaa69 100644 --- a/crates/engine-core/src/cmd/layer_multi_cmds/tests.rs +++ b/crates/engine-core/src/cmd/layer_multi_cmds/tests.rs @@ -1017,36 +1017,6 @@ fn merging_selected_layers_bakes_the_bottom_layers_style_to_pixels() { } } -#[test] -fn merging_down_drops_the_style_of_a_zero_fill_lower_layer() { - // Photoshop drops a zero-fill lower layer's whole contribution at Merge Down: the fill - // already shows nothing and the style goes with it, so the glow that outlined its shape - // before the merge is gone after it and nothing re-appears on the union (fixtures in - // PR #8750, a Fill-0% layer with Outer Glow and a disjoint upper layer). - let probe = |s: &Session| { - let d = doc(s); - photocraft_compose::render(d, d.bounds()).get(32, 20) - }; - for depth in [8, 16, 32] { - let mut s = session(depth); - let lower = rect_layer(&mut s, Rect::new(10, 10, 30, 30)); - let upper = rect_layer(&mut s, Rect::new(60, 20, 72, 32)); - s.execute("layer.layerStyle.outerGlow", json!({"layer": lower.0, "blend": "normal", "size": 6, "color": "#000000", "add": true})).unwrap(); - s.edit("zero fill", |doc, _| { - doc.layer_mut(lower).unwrap().fill_opacity = 0.0; - Ok(()) - }) - .unwrap(); - let before = probe(&s); - assert!(before.iter().take(3).all(|v| *v < 0.97), "depth {depth}: the glow outlines the invisible shape before the merge: {before:?}"); - s.execute("layer.mergeDown", json!({"layer": upper.0})).unwrap(); - let merged = doc(&s).layer(lower).unwrap().clone(); - assert!(merged.effects.items.is_empty(), "depth {depth}: the zero-fill style is dropped with the fill"); - let after = probe(&s); - assert!(after.iter().take(3).zip(&before).all(|(a, b)| *a > *b + 0.03), "depth {depth}: the glow went with the zero fill: {before:?} -> {after:?}"); - } -} - #[test] fn merging_down_inside_the_shaped_layer_is_a_pixel_match() { // With the upper layer fully inside the lower one's shape, the union is the same shape, so diff --git a/crates/engine-core/src/pixels.rs b/crates/engine-core/src/pixels.rs index 8c1aac39464..d86b510d688 100644 --- a/crates/engine-core/src/pixels.rs +++ b/crates/engine-core/src/pixels.rs @@ -580,11 +580,7 @@ pub fn merge_down(doc: &Document, lower: &Layer, upper: &Layer) -> Layer { merged.label = lower.label; merged.link_group = lower.link_group; // The fill opacity and the masks are in the pixels now; the layer style is kept, live, and - // recomposes over the union of both layers' content. A zero-fill lower layer is the one - // exception: Photoshop drops its whole contribution at Merge Down — the fill shows nothing - // and the style goes with it, so nothing re-appears on the union (fixtures in the PR). - if lower.fill_opacity != 0.0 { - merged.effects = style; - } + // recomposes over the union of both layers' content. + merged.effects = style; merged } From 6d340d67c0ed28123d2e614830607052060c86d2 Mon Sep 17 00:00:00 2001 From: Sergey Yadryshnikov Date: Tue, 27 Oct 2026 22:33:59 +0700 Subject: [PATCH 5/7] fix(layers): Merge Down inherits the lower layer's fill opacity MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Photoshop, observed with fixtures (thread in PR #8750), inherits the lower layer's fill opacity onto the merged layer instead of resetting the property: a Fill-0% lower layer merges keeping the union ink in the pixels but invisible, with only its live style — re-rendered around the union — showing. PhotoCraft reset the property to opaque, so the merged raster showed its ink with the glow around the wrong shape. At fill 1.0 inheritance is a no-op, and the existing pixel-match tests cover that path; a new regression test asserts the inherited property, the hidden union ink and the relocated glow at 8/16/32-bit. --- .../src/cmd/layer_multi_cmds/tests.rs | 39 +++++++++++++++++++ crates/engine-core/src/pixels.rs | 4 ++ 2 files changed, 43 insertions(+) diff --git a/crates/engine-core/src/cmd/layer_multi_cmds/tests.rs b/crates/engine-core/src/cmd/layer_multi_cmds/tests.rs index 3c27b6eaa69..5e4b653a871 100644 --- a/crates/engine-core/src/cmd/layer_multi_cmds/tests.rs +++ b/crates/engine-core/src/cmd/layer_multi_cmds/tests.rs @@ -996,6 +996,45 @@ fn merging_down_keeps_the_lower_layers_style_live_on_the_union() { } } +#[test] +fn merging_down_inherits_the_lower_layers_fill_opacity() { + // Photoshop inherits the fill onto the merged layer (fixtures in PR #8750): merging onto a + // Fill-0% lower layer keeps the union ink in the pixels but invisible, and only the live + // style — re-rendered around the union — shows. The property is not reset to opaque. + let ink = |s: &Session| { + let d = doc(s); + photocraft_compose::render(d, d.bounds()).get(66, 26) + }; + let glow = |s: &Session| { + let d = doc(s); + photocraft_compose::render(d, d.bounds()).get(75, 26) + }; + for depth in [8, 16, 32] { + let mut s = session(depth); + let lower = rect_layer(&mut s, Rect::new(10, 10, 30, 30)); + let upper = rect_layer(&mut s, Rect::new(60, 20, 72, 32)); + s.execute("layer.layerStyle.outerGlow", json!({"layer": lower.0, "blend": "normal", "size": 6, "color": "#000000", "add": true})).unwrap(); + s.edit("zero fill", |doc, _| { + doc.layer_mut(lower).unwrap().fill_opacity = 0.0; + Ok(()) + }) + .unwrap(); + let before_ink = ink(&s); + let before_glow = glow(&s); + s.execute("layer.mergeDown", json!({"layer": upper.0})).unwrap(); + let merged = doc(&s).layer(lower).unwrap().clone(); + assert_eq!(merged.fill_opacity, 0.0, "depth {depth}: the fill inherits onto the merged layer"); + assert_eq!(merged.effects.items.len(), 1, "depth {depth}: the style stays live"); + let after_ink = ink(&s); + assert!(after_ink.iter().take(3).all(|v| *v > 0.9), "depth {depth}: the inherited zero fill hides the union ink: {before_ink:?} -> {after_ink:?}"); + let after_glow = glow(&s); + assert!( + after_glow.iter().take(3).zip(&before_glow).all(|(a, b)| *a < *b - 0.03), + "depth {depth}: the glow re-renders around the invisible union: {before_glow:?} -> {after_glow:?}" + ); + } +} + #[test] fn merging_selected_layers_bakes_the_bottom_layers_style_to_pixels() { // Observed in Photoshop (fixtures in PR #8750): ⌘E over a selection merges the selected diff --git a/crates/engine-core/src/pixels.rs b/crates/engine-core/src/pixels.rs index d86b510d688..878da574d22 100644 --- a/crates/engine-core/src/pixels.rs +++ b/crates/engine-core/src/pixels.rs @@ -571,6 +571,10 @@ pub fn merge_down(doc: &Document, lower: &Layer, upper: &Layer) -> Layer { merged.id = lower.id; merged.blend = lower.blend; merged.opacity = 1.0; + // And the fill: Photoshop inherits the lower layer's fill opacity onto the merged layer, + // so a zero-fill layer keeps its ink in the pixels but invisible, with only its style + // visible — instead of resetting the property (observed in the PR fixtures). + merged.fill_opacity = lower.fill_opacity; // Merge Down replaces the lower layer, so keep its editing restrictions. // In particular, a merged Background must remain opaque and position-locked. merged.locks = lower.locks; From 4575d6e1729e4aad188f568302fccba037370820 Mon Sep 17 00:00:00 2001 From: Sergey Yadryshnikov Date: Wed, 18 Nov 2026 21:23:48 +0700 Subject: [PATCH 6/7] test(layers): cover Merge Down fill inheritance at 0, 50 and 100% Photoshop, observed with fixtures (thread in PR #8750), holds one opaque circle and one painted at 50% brush opacity per layer. At Fill 50% the merge bakes the lower circles with the fill already applied, then the inherited fill applies again, so they land on a quarter and an eighth while the upper circles stay at half and a quarter. At Fill 0% the lower ink is empty before the bake and nothing is left in the composite; at Fill 100% the merge changes nothing visible. Painted alpha, not just the layer fill, is what the previous zero-fill test could not see: it probed only the upper shape. The test also checks undo restores both layers, the fill and the composite, at 8/16/32-bit. --- .../src/cmd/layer_multi_cmds/tests.rs | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/crates/engine-core/src/cmd/layer_multi_cmds/tests.rs b/crates/engine-core/src/cmd/layer_multi_cmds/tests.rs index 5e4b653a871..334698b5409 100644 --- a/crates/engine-core/src/cmd/layer_multi_cmds/tests.rs +++ b/crates/engine-core/src/cmd/layer_multi_cmds/tests.rs @@ -1035,6 +1035,69 @@ fn merging_down_inherits_the_lower_layers_fill_opacity() { } } +#[test] +fn merging_down_applies_the_inherited_fill_to_the_baked_ink() { + // Observed in Photoshop (fixtures in PR #8750: each layer holds one opaque circle and one + // painted at 50% brush opacity). Merge Down bakes the visible pixels — with the lower + // layer's Fill already applied — onto the merged layer, and the merged layer inherits that + // same Fill, so the lower content is attenuated twice: at Fill 50% the opaque circle lands + // on a quarter (0.5 × 0.5) and the half-transparent one on an eighth, while the upper + // circles stay at half and a quarter. At Fill 0% the lower ink is already empty when baked + // and the rest leaves the composite through the inherited fill — as in the fixtures, where + // the lower shape and its glow vanish; at Fill 100% the merge changes nothing visible. + let alpha_at = |s: &Session, x: i32, y: i32| { + let d = doc(s); + photocraft_compose::render(d, d.bounds()).get(x, y)[3] + }; + let alphas = |s: &Session| [alpha_at(s, 30, 30), alpha_at(s, 30, 80), alpha_at(s, 130, 30), alpha_at(s, 130, 80)]; + let close = |got: &[f32; 4], want: [f32; 4]| got.iter().zip(&want).all(|(g, w)| (g - w).abs() < 0.01); + let (all, top_only) = (Rect::new(10, 10, 150, 100), Rect::new(110, 10, 150, 100)); + // (Fill, alpha of [lower opaque, lower half, upper opaque, upper half] after the merge, + // the ink baked into the merged layer) + let cases = [(1.0f32, [1.0, 0.5, 1.0, 0.5], all), (0.5, [0.25, 0.125, 0.5, 0.25], all), (0.0, [0.0; 4], top_only)]; + for (fill, after, baked) in cases { + for depth in [8, 16, 32] { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 160, "height": 120, "depth": depth, "background": "transparent"})).unwrap(); + let lower = rect_layer(&mut s, Rect::new(10, 10, 50, 50)); + let upper = rect_layer(&mut s, Rect::new(110, 10, 150, 50)); + let half = |s: &mut Session, id: LayerId, r: Rect| { + s.edit("half", |doc, _| { + doc.layer_mut(id).unwrap().surface_mut().unwrap().fill_rect(r, &[0.0, 0.0, 1.0, 0.5]); + Ok(()) + }) + .unwrap(); + }; + half(&mut s, lower, Rect::new(10, 60, 50, 100)); + half(&mut s, upper, Rect::new(110, 60, 150, 100)); + s.edit("fill", |doc, _| { + doc.layer_mut(lower).unwrap().fill_opacity = fill; + Ok(()) + }) + .unwrap(); + let before = alphas(&s); + assert!( + close(&before, [fill, fill * 0.5, 1.0, 0.5]), + "depth {depth}, fill {fill}: the lower layer's own fill attenuates it once before the merge: {before:?}" + ); + let layers_before = doc(&s).layer_count(); + s.execute("layer.mergeDown", json!({"layer": upper.0})).unwrap(); + let merged = doc(&s).layer(lower).unwrap().clone(); + assert!(doc(&s).layer(upper).is_none(), "depth {depth}, fill {fill}: the upper layer merged down"); + assert_eq!(doc(&s).layer_count(), layers_before - 1, "depth {depth}, fill {fill}: the merge took one layer"); + assert_eq!(merged.fill_opacity, fill, "depth {depth}, fill {fill}: the fill inherits onto the merged layer"); + assert_eq!(layer_bounds(&merged).unwrap(), baked, "depth {depth}, fill {fill}: the merge bakes the visible pixels of both layers"); + let got = alphas(&s); + assert!(close(&got, after), "depth {depth}, fill {fill}: the inherited fill applies to the baked ink again: {got:?}, want {after:?}"); + s.undo(); + assert_eq!(doc(&s).layer_count(), layers_before, "depth {depth}, fill {fill}: undo brings both layers back"); + assert!(doc(&s).layer(upper).is_some(), "depth {depth}, fill {fill}: undo restores the upper layer"); + assert_eq!(doc(&s).layer(lower).unwrap().fill_opacity, fill, "depth {depth}, fill {fill}: undo restores the fill"); + assert!(close(&alphas(&s), before), "depth {depth}, fill {fill}: undo restores the composite"); + } + } +} + #[test] fn merging_selected_layers_bakes_the_bottom_layers_style_to_pixels() { // Observed in Photoshop (fixtures in PR #8750): ⌘E over a selection merges the selected From ac299ac5c0fa10cc361fec875dd2410c80a2e287 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Wed, 2 Dec 2026 13:40:46 +0700 Subject: [PATCH 7/7] Use crate::session() in the Merge Down fill test On main Session::new() fails with NotInstalled in engine-core tests; the other tests in this module build their session with crate::session(). --- crates/engine-core/src/cmd/layer_multi_cmds/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/engine-core/src/cmd/layer_multi_cmds/tests.rs b/crates/engine-core/src/cmd/layer_multi_cmds/tests.rs index 857c4f9c188..f8f519d0ff6 100644 --- a/crates/engine-core/src/cmd/layer_multi_cmds/tests.rs +++ b/crates/engine-core/src/cmd/layer_multi_cmds/tests.rs @@ -1057,7 +1057,7 @@ fn merging_down_applies_the_inherited_fill_to_the_baked_ink() { let cases = [(1.0f32, [1.0, 0.5, 1.0, 0.5], all), (0.5, [0.25, 0.125, 0.5, 0.25], all), (0.0, [0.0; 4], top_only)]; for (fill, after, baked) in cases { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 160, "height": 120, "depth": depth, "background": "transparent"})).unwrap(); let lower = rect_layer(&mut s, Rect::new(10, 10, 50, 50)); let upper = rect_layer(&mut s, Rect::new(110, 10, 150, 50));