PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Groups: a pass-through clipping base with an adjustment renders isolated (passthrough_clipping_mask_adjustment passes) (#5272)
Timothy Daly3feebb9b131a
diff --git a/crates/compose/src/lib.rs b/crates/compose/src/lib.rsindex c53a224d6..ad09375ed 100644--- a/crates/compose/src/lib.rs+++ b/crates/compose/src/lib.rs@@ -1346,11 +1346,17 @@ fn composite_layer_plain(layer: &Layer, clipped: &[Layer], backdrop: &mut Buffer// Pass-through groups composite their children straight into the backdrop. Below 100% fill// Photoshop renders the group isolated, like Normal (psd-tools passthrough_fill_*: an- // adjustment inside no longer reaches the layers beneath).+ // adjustment inside no longer reaches the layers beneath), and so it does for a group that+ // is the base of a clipping group and holds an adjustment layer (psd-tools+ // passthrough_clipping_mask_adjustment: an Exposure inside leaves the layers beneath alone),+ // while such a group's blend modes still reach the backdrop (passthrough_clipping_mask_blendmode).+ let clip_base_adjusts = clipped.iter().any(|c| c.visible)+ && matches!(&layer.content, LayerContent::Group(g) if g.children.iter().any(|c| c.visible && matches!(c.content, LayerContent::Adjustment(_))));if let LayerContent::Group(g) = &layer.content&& layer.blend == BlendMode::PassThrough&& layer.fill_opacity >= 1.0&& !effects::has_effects(layer)+ && !clip_base_adjusts{let needs_mix = opacity < 1.0 || layer.mask.is_some() || layer.vector_mask.is_some();let has_clipped = clipped.iter().any(|c| c.visible);diff --git a/crates/compose/src/tests.rs b/crates/compose/src/tests.rsindex df6c01850..1a64aa7f7 100644--- a/crates/compose/src/tests.rs+++ b/crates/compose/src/tests.rs@@ -2737,3 +2737,24 @@ fn shape_layer_bounds_includes_vector_bounds_clipped_to_canvas_and_preserves_effassert!(!b_fx.is_empty());assert!(b_fx.contains_rect(&b));}++// A pass-through group with an adjustment layer reaches the layers beneath, unless the group is+// the base of a clipping group: then Photoshop renders it isolated, and an adjustment with no+// content of its own in the group changes nothing (psd-tools passthrough_clipping_mask_adjustment).+#[test]+fn a_pass_through_clipping_base_keeps_its_adjustments_inside() {+ let base = || {+ let mut d = doc_white(4, 4);+ let group = Layer::group("group", vec![Layer::new("invert", LayerContent::Adjustment(Adjustment::Invert))]);+ d.layers.push(group);+ d+ };+ // Unclipped: the invert reaches the white background.+ assert!(close4(px(&base(), 1, 1), [0.0, 0.0, 0.0, 1.0]), "{:?}", px(&base(), 1, 1));+ // With a layer clipped to the group: the background stays white.+ let mut d = base();+ let mut clip = Layer::raster("clipped", PixelFormat::RGBA8);+ clip.clipped = true;+ d.layers.push(clip);+ assert!(close4(px(&d, 1, 1), [1.0, 1.0, 1.0, 1.0]), "{:?}", px(&d, 1, 1));+}diff --git a/crates/gpu/src/plan.rs b/crates/gpu/src/plan.rsindex d94d2c1de..636467fc5 100644--- a/crates/gpu/src/plan.rs+++ b/crates/gpu/src/plan.rs@@ -652,11 +652,15 @@ impl<'a> Planner<'a> {let opacity = layer.opacity * layer.fill_opacity;let visible_clipped: Vec<&'a Layer> = clipped.iter().filter(|c| c.visible).collect();- // Below 100% fill a pass-through group renders isolated (as the CPU compositor does).+ // Below 100% fill a pass-through group renders isolated (as the CPU compositor does), and+ // so does one that is the base of a clipping group and holds an adjustment layer.+ let clip_base_adjusts = !visible_clipped.is_empty()+ && matches!(&layer.content, LayerContent::Group(g) if g.children.iter().any(|c| c.visible && matches!(c.content, LayerContent::Adjustment(_))));if let LayerContent::Group(g) = &layer.content&& layer.blend == BlendMode::PassThrough&& layer.fill_opacity >= 1.0&& !has_effects(layer)+ && !clip_base_adjusts{let before = self.retain(backdrop);let mut after = self.stack(&g.children, backdrop)?;diff --git a/crates/gpu/tests/parity.rs b/crates/gpu/tests/parity.rsindex de2a97200..7b2dfaf7c 100644--- a/crates/gpu/tests/parity.rs+++ b/crates/gpu/tests/parity.rs@@ -2588,3 +2588,22 @@ fn the_focused_view_stays_resident_after_a_full_refresh() {assert!(worst_diff(&cpu.px, &out).0 <= TOL);}}++// A pass-through group holding an adjustment renders isolated when layers clip to it, on the GPU+// as on the CPU (psd-tools passthrough_clipping_mask_adjustment).+#[test]+fn pass_through_clipping_base_with_an_adjustment() {+ let Some(mut g) = gpu() else { return };+ let mut d = base_doc(32, 24);+ d.layers.push(noise_layer("mid", PixelFormat::RGBA8, Rect::new(0, 0, 32, 24), 41, 1.0));+ let mut grp = Layer::group(+ "g",+ vec![noise_layer("in", PixelFormat::RGBA8, Rect::new(4, 4, 20, 20), 42, 0.5), Layer::new("inv", LayerContent::Adjustment(Adjustment::Invert))],+ );+ grp.blend = BlendMode::PassThrough;+ d.layers.push(grp);+ let mut clip = noise_layer("clip", PixelFormat::RGBA8, Rect::new(8, 0, 28, 16), 43, 0.3);+ clip.clipped = true;+ d.layers.push(clip);+ check(&mut g, &d, "pass-through clipping base with an adjustment");+}diff --git a/docs/file-format-parity.md b/docs/file-format-parity.mdindex 6793091b8..12f7c53d1 100644--- a/docs/file-format-parity.md+++ b/docs/file-format-parity.md@@ -1,6 +1,6 @@# File-format parity-> **Last reviewed:** 2026-10-12 · **Last updated:** 2026-10-13 · **Change:** minor (16-bit Posterize as Photoshop bins it; psd-tools oracle floor 241/309; Gradient Map luminosity; Photoshop-oracle floor 147/258; PSD: `Mt16`/`Mt32` merged transparency read; palette PNGs open in Indexed Color mode, #4804; earlier: CMYK Invert, Posterize and Threshold on the inks; 16-bit Lab Invert; Photoshop-oracle floor 145/258; `.atn` import maps 112 events; DDS textures open, #1327; DPX read and write, #1049; #2465 fixed: CS2 placed layers with only a `PlLd` block open their contents; Photoshop Actions `.atn` read and write; `.shc` contour files read and write; earlier the same day: indexed BMP palette mode; Save keeps a JPEG's quality and a WebP's encoding) · **Target:** Adobe Photoshop 2026+> **Last reviewed:** 2026-10-12 · **Last updated:** 2026-10-13 · **Change:** minor (a pass-through clipping base with an adjustment renders isolated; psd-tools oracle floor 240/309; 16-bit Posterize as Photoshop bins it; psd-tools oracle floor 241/309; Gradient Map luminosity; Photoshop-oracle floor 147/258; PSD: `Mt16`/`Mt32` merged transparency read; palette PNGs open in Indexed Color mode, #4804; earlier: CMYK Invert, Posterize and Threshold on the inks; 16-bit Lab Invert; Photoshop-oracle floor 145/258; `.atn` import maps 112 events; DDS textures open, #1327; DPX read and write, #1049; #2465 fixed: CS2 placed layers with only a `PlLd` block open their contents; Photoshop Actions `.atn` read and write; `.shc` contour files read and write; earlier the same day: indexed BMP palette mode; Save keeps a JPEG's quality and a WebP's encoding) · **Target:** Adobe Photoshop 2026Every format Photoshop 2026 (27.11.0) reads or writes, with PhotoCraft's support, fidelity andtests. Photoshop's list comes from its `Info.plist` `CFBundleDocumentTypes`, the PiPL read/write@@ -142,6 +142,7 @@ remaining gaps in #1606 stay tracked with per-sample corpus ceilings.| Date | Change | Summary ||---|---|---|+| 2026-10-13 | minor | A pass-through group that is the base of a clipping group and holds an adjustment layer renders isolated, as Photoshop does (its blend modes still reach the backdrop): psd-tools passthrough_clipping_mask_adjustment passes (was 50 % of pixels off); psd-tools floor → 240 of 309 (main 239) || 2026-10-13 | minor | 16-bit Posterize bins the 16-bit sample and lands on 8-bit levels through a 16-bit step, as Photoshop does (RGB, Grayscale and the CMYK/Lab channel path): psd-tools posterize_16bits_rgb and posterize_16bits_grayscale pass; psd-tools floor → 241 of 309 (main 239) || 2026-10-13 | minor | Gradient Map adjustment layers are driven by the W3C luminosity (0.3, 0.59, 0.11), not the Rec. 601 grey: rgb8 and rgb16 gradient-map.psd pass; Photoshop-oracle floor 145 → 147 of 258 || 2026-10-13 | minor | PSD: a "Saving Merged Transparency" global block (`Mtrn`, `Mt16`, `Mt32`; Photoshop's 32-bit documents keep a positive layer count) marks the merged image's first extra channel as its transparency: opening such a file no longer adds a "Transparency" alpha channel, and the oracle compares psd-tools transparentbg.psd's alpha (83.7 % → 0.9 % of pixels off; its shape edges remain) |diff --git a/docs/gaps.md b/docs/gaps.mdindex 70925deb8..d858c67be 100644--- a/docs/gaps.md+++ b/docs/gaps.md@@ -1,6 +1,6 @@# Where PhotoCraft falls short of Photoshop-> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-13 · **Change:** minor (G1: 16-bit Posterize as Photoshop bins it, psd-tools oracle floor 241/309; G1: Gradient Map driven by the W3C luminosity, Photoshop-oracle floor 147/258; G7: Field Blur's on-canvas pins, #3373; G4: Hue Jitter amount track, #3825 partial; G4: minimum field interaction, #3825 partial; G1: CMYK Invert, Posterize and Threshold on the inks, 16-bit Lab Invert; Photoshop-oracle floor 145/258; G11: `.atn` import maps 112 events: Select and Mask, Filter Gallery Spatter, Ripple, Crystallize, Pattern Fill layers, mask targeting, Step Backward, nudges in points, Bitmap mode; G5: Free Transform H/V skew fields; G9: toolbar tool shortcut editing; refreshed against main: G2, G5, G7, G9, G10, G13, G14, G17 items that landed; G10: DPX read and write, #1049; G4: checkbox-only Brush Settings rows; G11: Load/Save Actions `.atn` landed, AUTO-219-2 partial; G5: hold-a-key spring-loaded tools landed, #2672; G1: #2465 fixed; stale missing-tool rows corrected: Color Replacement, Red Eye and Add/Delete Anchor Point are live tools, so only Art History Brush is missing; no estimate changed) · **Target:** Adobe Photoshop 2026+> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-13 · **Change:** minor (G1: pass-through clipping base with an adjustment renders isolated, psd-tools oracle floor 240/309; G1: 16-bit Posterize as Photoshop bins it, psd-tools oracle floor 241/309; G1: Gradient Map driven by the W3C luminosity, Photoshop-oracle floor 147/258; G7: Field Blur's on-canvas pins, #3373; G4: Hue Jitter amount track, #3825 partial; G4: minimum field interaction, #3825 partial; G1: CMYK Invert, Posterize and Threshold on the inks, 16-bit Lab Invert; Photoshop-oracle floor 145/258; G11: `.atn` import maps 112 events: Select and Mask, Filter Gallery Spatter, Ripple, Crystallize, Pattern Fill layers, mask targeting, Step Backward, nudges in points, Bitmap mode; G5: Free Transform H/V skew fields; G9: toolbar tool shortcut editing; refreshed against main: G2, G5, G7, G9, G10, G13, G14, G17 items that landed; G10: DPX read and write, #1049; G4: checkbox-only Brush Settings rows; G11: Load/Save Actions `.atn` landed, AUTO-219-2 partial; G5: hold-a-key spring-loaded tools landed, #2672; G1: #2465 fixed; stale missing-tool rows corrected: Color Replacement, Red Eye and Add/Delete Anchor Point are live tools, so only Art History Brush is missing; no estimate changed) · **Target:** Adobe Photoshop 2026Every known shortfall against Photoshop 2026 (27.11.0), one entry each, ranked by user impacton the way to beta. This is the work list agents pick from: take the highest-ranked entry that@@ -262,6 +262,7 @@ what an agent can't finish alone.| Date | Change | Summary ||---|---|---|+| 2026-10-13 | minor | G1: a pass-through group that is a clipping base and holds an adjustment layer renders isolated; psd-tools passthrough_clipping_mask_adjustment passes; psd-tools floor → 240 of 309 || 2026-10-13 | minor | G1: 16-bit Posterize bins the 16-bit sample, as Photoshop does (exact on two oracles); psd-tools floor → 241 of 309 || 2026-10-13 | minor | G1: Gradient Map driven by the W3C luminosity (0.3, 0.59, 0.11), as Photoshop is; rgb8/rgb16 gradient-map pass; Photoshop-oracle floor 145 → 147 of 258 || 2026-10-13 | minor | G6: stale "missing tool" list corrected against `main` — Color Replacement (`paint.colorReplacement`), Red Eye (`paint.redEye`) and Add/Delete Anchor Point (P flyout, #4144) are live tools, so the toolbox is 67 of 68 and Art History Brush is the only one missing; no percentage or estimate changed |