PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Fix compound layer property exports for Photoshop actions
bommertsd1c30954aacd
diff --git a/crates/engine/src/atn_cmds.rs b/crates/engine/src/atn_cmds.rsindex 343a5920a..1b41a64e3 100644--- a/crates/engine/src/atn_cmds.rs+++ b/crates/engine/src/atn_cmds.rs@@ -3201,6 +3201,29 @@ fn export_item(id: &str, params: &Value, set: &str) -> Option<AtnItem> {Some(AtnItem { event, dictionary: e.label.to_string(), descriptor: Some(descriptor), ..Default::default() })}+/// Photoshop applies only the rename when a Set mixes it with opacity or blend mode (#8304).+/// Write each layer property separately, renaming last so named references still resolve.+fn export_items(id: &str, params: &Value, set: &str) -> Option<Vec<AtnItem>> {+ let item = export_item(id, params, set)?;+ if id != "layer.setProps" {+ return Some(vec![item]);+ }+ let descriptor = item.descriptor.as_ref()?;+ let properties = get_obj(descriptor, "T ")?;+ if properties.items.len() <= 1 {+ return Some(vec![item]);+ }+ let target = descriptor.get("null")?;+ let mut items = Vec::with_capacity(properties.items.len());+ for (key, value) in properties.items.iter().filter(|(k, _)| !k.is("Nm ")).chain(properties.items.iter().filter(|(k, _)| k.is("Nm "))) {+ let mut property = properties.clone();+ property.items = vec![(key.clone(), value.clone())];+ let descriptor = desc("null").with("null", target.clone()).with("T ", D::Descriptor(property));+ items.push(AtnItem { descriptor: Some(descriptor), ..item.clone() });+ }+ Some(items)+}+/// An action's key as a shortcut string: `F5`, with Photoshop's Shift and Command options/// `Shift+F5`, `Cmd+F5` or `Cmd+Shift+F5` (#7646).pub fn function_key_name(key: u16, shift: bool, command: bool) -> String {@@ -3241,17 +3264,19 @@ pub fn export((out.function_key, out.shift, out.command) = (n, shift, command);}for (i, (id, params)) in a.steps.iter().enumerate() {- let Some(mut item) = export_item(id, params, set) else {+ let Some(items) = export_items(id, params, set) else {if skip_unsupported {skipped.push(Skipped { action: a.name.clone(), step: i, id: id.clone() });continue;}return Err(format!("step {} of `{}` (`{id}`) has no Photoshop equivalent; pass \"skipUnsupported\": true to leave it out", i + 1, a.name));};- item.enabled = a.step_enabled(i);- item.with_dialog = a.dialogs.contains(&i);- item.dialog_options = if item.with_dialog { 2 } else { 0 };- out.items.push(item);+ for mut item in items {+ item.enabled = a.step_enabled(i);+ item.with_dialog = a.dialogs.contains(&i);+ item.dialog_options = if item.with_dialog { 2 } else { 0 };+ out.items.push(item);+ }}file.actions.push(out);}@@ -3470,3 +3495,6 @@ pub fn specs() -> Vec<CommandSpec> {#[cfg(test)]mod tests;++#[cfg(test)]+mod layer_props_tests;diff --git a/crates/engine/src/atn_cmds/layer_props_tests.rs b/crates/engine/src/atn_cmds/layer_props_tests.rsnew file mode 100644index 000000000..424af7bd5--- /dev/null+++ b/crates/engine/src/atn_cmds/layer_props_tests.rs@@ -0,0 +1,151 @@+use super::*;++/// PhotoCraft's own roundtrip accepts a combined Set, but Photoshop applies only its rename.+#[test]+fn compound_properties_export_as_separate_sets_with_rename_last() {+ for target in [None, Some("Original")] {+ let mut params = json!({"name": "Renamed", "opacity": 0.37, "blend": "Multiply"});+ if let Some(name) = target {+ params["layer"] = json!(name);+ }+ let action = Action::new("Properties", vec![("layer.setProps".into(), params.clone())]);+ let (bytes, skipped) = export("Set", &[&action], &[], false).unwrap();+ assert!(skipped.is_empty());+ let file = atn::parse(&bytes).unwrap();+ let items = &file.actions[0].items;+ assert_eq!(items.len(), 3);+ let expected = [("Opct", pct(37.0)), ("Md ", enm("BlnM", "Mltp")), ("Nm ", text("Renamed"))];+ for (item, (key, value)) in items.iter().zip(expected) {+ assert_eq!(item.event.id(), "setd");+ let descriptor = item.descriptor.as_ref().unwrap();+ assert_eq!(descriptor.get("null"), Some(&layer_ref(¶ms)));+ let properties = get_obj(descriptor, "T ").unwrap();+ assert!(properties.class_id.is("Lyr "));+ assert_eq!(properties.items.len(), 1, "Photoshop must receive each property independently");+ assert_eq!(properties.get(key), Some(&value));+ }+ }+}++#[test]+fn expanded_properties_keep_flags_and_original_skip_indices() {+ let mut action = Action::new(+ "Flags",+ vec![+ ("layer.setProps".into(), json!({"name": "Renamed", "opacity": 0.37, "blend": "Multiply"})),+ ("filter.blur.gaussianBlur".into(), json!({"radius": 2})),+ ("filter.render.clouds".into(), json!({})),+ ],+ );+ action.disabled.insert(0);+ action.dialogs.insert(0);+ let (bytes, skipped) = export("Set", &[&action], &[], true).unwrap();+ assert_eq!(skipped, [Skipped { action: "Flags".into(), step: 2, id: "filter.render.clouds".into() }]);+ let file = atn::parse(&bytes).unwrap();+ let items = &file.actions[0].items;+ assert_eq!(items.len(), 4);+ for item in &items[..3] {+ assert!(!item.enabled);+ assert!(item.with_dialog);+ assert_eq!(item.dialog_options, 2);+ }+ assert_eq!(items[3].event.id(), "GsnB");+ assert!(items[3].enabled);+ assert!(!items[3].with_dialog);+ assert_eq!(items[3].dialog_options, 0);+ let back = import(&bytes).unwrap();+ assert_eq!(back.actions[0].disabled.iter().copied().collect::<Vec<_>>(), [0, 1, 2]);+ assert_eq!(back.actions[0].dialogs.iter().copied().collect::<Vec<_>>(), [0, 1, 2]);+}++#[test]+fn invalid_compound_properties_fail_or_skip_the_whole_source_step() {+ let action = Action::new(+ "Atomic",+ vec![+ ("filter.blur.gaussianBlur".into(), json!({"radius": 2})),+ ("layer.setProps".into(), json!({"name": "Renamed", "opacity": 0.37, "blend": "invalid blend"})),+ ("select.inverse".into(), json!({})),+ ],+ );+ let error = export("Set", &[&action], &[], false).unwrap_err();+ assert!(error.contains("step 2"), "{error}");+ let (bytes, skipped) = export("Set", &[&action], &[], true).unwrap();+ assert_eq!(skipped, [Skipped { action: "Atomic".into(), step: 1, id: "layer.setProps".into() }]);+ let file = atn::parse(&bytes).unwrap();+ let events: Vec<_> = file.actions[0].items.iter().map(|item| item.event.id()).collect();+ assert_eq!(events, ["GsnB", "Invs"]);+}++#[test]+fn single_layer_properties_keep_their_existing_descriptor() {+ for params in [json!({"name": "Renamed"}), json!({"opacity": 0.37}), json!({"blend": "Multiply"}), json!({"fill": 0.5}), json!({"visible": false})] {+ let action = Action::new("Single", vec![("layer.setProps".into(), params.clone())]);+ let expected = export_item("layer.setProps", ¶ms, "Set").unwrap();+ let (bytes, skipped) = export("Set", &[&action], &[], false).unwrap();+ assert!(skipped.is_empty());+ let file = atn::parse(&bytes).unwrap();+ assert_eq!(file.actions[0].items.len(), 1);+ assert_eq!(file.actions[0].items[0].event, expected.event);+ assert_eq!(file.actions[0].items[0].descriptor, expected.descriptor);+ }+}++#[test]+fn fill_and_visibility_also_export_separately_before_rename() {+ let action = Action::new("Other properties", vec![("layer.setProps".into(), json!({"name": "Renamed", "fill": 0.5, "visible": false}))]);+ let (bytes, _) = export("Set", &[&action], &[], false).unwrap();+ let file = atn::parse(&bytes).unwrap();+ let keys: Vec<_> = file.actions[0]+ .items+ .iter()+ .map(|item| {+ let properties = get_obj(item.descriptor.as_ref().unwrap(), "T ").unwrap();+ assert_eq!(properties.items.len(), 1);+ trimmed(&properties.items[0].0)+ })+ .collect();+ assert_eq!(keys, ["fillOpacity", "Vsbl", "Nm"]);+}++#[test]+fn expanded_properties_replay_like_direct_edits_at_every_depth() {+ for depth in [8, 16, 32] {+ for named in [false, true] {+ let prepare = || {+ let mut session = Session::new();+ session.execute("file.new", json!({"width": 2, "height": 2, "depth": depth})).unwrap();+ session.execute("layer.new.layer", json!({"name": "Original"})).unwrap();+ session.execute("layer.new.layer", json!({"name": "Other"})).unwrap();+ if !named {+ session.execute("layer.select", json!({"layer": "Original"})).unwrap();+ }+ session+ };+ let mut params = json!({"name": "Renamed", "opacity": 0.37, "blend": "Multiply"});+ if named {+ params["layer"] = json!("Original");+ }+ let mut direct = prepare();+ direct.execute("layer.setProps", params.clone()).unwrap();+ let action = Action::new("Properties", vec![("layer.setProps".into(), params)]);+ let (bytes, _) = export("Set", &[&action], &[], false).unwrap();+ let mut replay = prepare();+ replay.actions.list = import(&bytes).unwrap().actions;+ let result = replay.execute("actions.play", json!({"action": "Properties"})).unwrap();+ assert!(result["failed"].is_null(), "{result}");+ assert_eq!(result["ran"], 3);+ let state = |session: &Session| {+ session+ .active()+ .unwrap()+ .doc+ .walk()+ .iter()+ .map(|(_, _, layer)| (layer.name.clone(), layer.opacity, layer.blend, layer.visible))+ .collect::<Vec<_>>()+ };+ assert_eq!(state(&direct), state(&replay), "depth={depth}, named={named}");+ }+ }+}diff --git a/docs/gaps.md b/docs/gaps.mdindex 3c56d6d35..dcc88878c 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-18 · **Change:** minor (G9: Preferences › File Handling › Save in Background takes effect, #6207, 24 of 169 preferences do nothing; G7: Content-Aware Move previews every selection the command takes, coarse then exact, TOOL-213-4 done, #6680; G4: Pattern Stamp and Background Eraser draw live, TOOL-213-7; G9: Animated Zoom pref read: holding the Zoom tool zooms continuously, #6210, prefs that do nothing 25 of 166; G2: a cancelled 24 MP Gaussian Blur job stops in at most 44 ms, P25 under its 200 ms budget, #6205; G1: generated large-file fixtures, a 4.38 GB PSB opens on Windows through io, FILE-216-2 done, #5107; G9: fill and adjustment layers copy and paste whole, #2344; G1: smart filter masks show on PSD open, Photoshop-oracle floor 188/258; G10: DPX read and write, #1049, Cineon read; G1: CMYK Hue/Saturation and Color Balance keep the black ink; G1: CMYK Posterize on the stored values, psd-tools oracle floor 242/309; G1: CMYK adjustment layers composite on the document's inks, Photoshop-oracle floor 165/258; G1: CMYK Brightness/Contrast on the inks, CMYK Threshold's luma; G1: modern Brightness/Contrast's brightness curve matches Photoshop, Photoshop-oracle floor 151/258; G1: Lab documents composite on their stored L, a, b, Photoshop-oracle floor 152/258; G1: Levels on whole levels at every step, Photoshop-oracle floor 146/258, psd-tools 238/309; G1: 32-bit Brightness/Contrast legacy, Channel Mixer, Photo Filter and Black & White tint unclipped as in Photoshop, Photoshop-oracle floor 149/258; G1: mask feathers blur with their exact variance, psd-tools oracle floor 240/309; G1: Threshold splits on Photoshop's luminosity, psd-tools oracle floor 241/309; 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 2026+> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-21 · **Change:** minor (G11: compound layer properties export as separate Photoshop Set events, rename last, #8304; G9: Preferences › File Handling › Save in Background takes effect, #6207, 24 of 169 preferences do nothing; G7: Content-Aware Move previews every selection the command takes, coarse then exact, TOOL-213-4 done, #6680; G4: Pattern Stamp and Background Eraser draw live, TOOL-213-7; G9: Animated Zoom pref read: holding the Zoom tool zooms continuously, #6210, prefs that do nothing 25 of 166; G2: a cancelled 24 MP Gaussian Blur job stops in at most 44 ms, P25 under its 200 ms budget, #6205; G1: generated large-file fixtures, a 4.38 GB PSB opens on Windows through io, FILE-216-2 done, #5107; G9: fill and adjustment layers copy and paste whole, #2344; G1: smart filter masks show on PSD open, Photoshop-oracle floor 188/258; G10: DPX read and write, #1049, Cineon read; G1: CMYK Hue/Saturation and Color Balance keep the black ink; G1: CMYK Posterize on the stored values, psd-tools oracle floor 242/309; G1: CMYK adjustment layers composite on the document's inks, Photoshop-oracle floor 165/258; G1: CMYK Brightness/Contrast on the inks, CMYK Threshold's luma; G1: modern Brightness/Contrast's brightness curve matches Photoshop, Photoshop-oracle floor 151/258; G1: Lab documents composite on their stored L, a, b, Photoshop-oracle floor 152/258; G1: Levels on whole levels at every step, Photoshop-oracle floor 146/258, psd-tools 238/309; G1: 32-bit Brightness/Contrast legacy, Channel Mixer, Photo Filter and Black & White tint unclipped as in Photoshop, Photoshop-oracle floor 149/258; G1: mask feathers blur with their exact variance, psd-tools oracle floor 240/309; G1: Threshold splits on Photoshop's luminosity, psd-tools oracle floor 241/309; 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@@ -98,6 +98,10 @@ what an agent can't finish alone.- **Estimate:** 120–200 h.### G11. Actions and scripting+- **2026-10-21 evidence (#8304):** Save Actions expands compound layer-property edits into+ separate Photoshop Set events, with rename last so named layer references remain valid.+ Exported descriptors and native playback at RGB 8/16/32-bit have [regression coverage](../crates/engine/src/atn_cmds/layer_props_tests.rs);+ independent Photoshop replay of the fix is still pending. No readiness percentage or estimate changed.- **2026-10-13 evidence:** Batch supports [output naming templates](batch-naming.md) using`{name}`, `{serial}` and a captured UTC `{date}`, with a starting serial number. Collidingnames remain errors; custom output names cannot replace inputs. AUTO-219-5 stays partial.@@ -287,6 +291,7 @@ what an agent can't finish alone.| Date | Change | Summary ||---|---|---|+| 2026-10-21 | minor | #8304: compound layer properties export as separate Set events, rename last; independent Photoshop replay pending; percentages and estimates unchanged || 2026-10-15 | minor | G1 / #5972 A1: render only provably constant-RGB `GdFl` noise fills; variable noise synthesis remains open || 2026-10-18 | minor | G9: with no selection, Copy takes fill and adjustment layers whole and Paste recreates them (#2344); UI-217-23 stays partial (a single pixel layer copies its pixels only); estimate unchanged || 2026-10-15 | minor | G2: a cancelled 24 MP Gaussian Blur job stops within 44 ms max (P25, budget 200 ms; was about 400 ms), the uncancelled job about 40% faster; #6205 |diff --git a/docs/target-app-parity.md b/docs/target-app-parity.mdindex a2581c4b4..b7a1fbd4c 100644--- a/docs/target-app-parity.md+++ b/docs/target-app-parity.md@@ -1,6 +1,6 @@# PhotoCraft vs Adobe Photoshop: target-app parity-> **Last reviewed:** 2026-10-12 · **Last updated:** 2026-10-18 · **Change:** minor (Content-Aware Move live preview for every selection size, TOOL-213-4 done, #6680; retouching evidence: Pattern Stamp and Background Eraser draw live, only the Mixer Brush is left of TOOL-213-7; fill and adjustment layers copy and paste whole, UI-217-23 partial, #2344; shape layers take Density and Feather, TOOL-214-12 done, #5846; on-canvas corner radius widgets, TOOL-214-12; `.atn` import maps 112 events; Free Transform H/V skew fields; stale rows corrected against `main` and the scorecard, estimates unchanged; Photoshop Actions `.atn` load and save; 2026-10-10: Tilt-Shift measurements added; earlier the same day: major, full re-measure against Photoshop 2026 27.11.0; merged `parity-estimate.md` and the roadmap's honest assessment; stale missing-tool rows corrected: Color Replacement and Red Eye are live toolbar tools, Frame landed; percentages unchanged) · **Target:** Adobe Photoshop 2026+> **Last reviewed:** 2026-10-12 · **Last updated:** 2026-10-21 · **Change:** minor (compound layer properties export as separate Photoshop Set events, #8304; percentages unchanged; Content-Aware Move live preview for every selection size, TOOL-213-4 done, #6680; retouching evidence: Pattern Stamp and Background Eraser draw live, only the Mixer Brush is left of TOOL-213-7; fill and adjustment layers copy and paste whole, UI-217-23 partial, #2344; shape layers take Density and Feather, TOOL-214-12 done, #5846; on-canvas corner radius widgets, TOOL-214-12; `.atn` import maps 112 events; Free Transform H/V skew fields; stale rows corrected against `main` and the scorecard, estimates unchanged; Photoshop Actions `.atn` load and save; 2026-10-10: Tilt-Shift measurements added; earlier the same day: major, full re-measure against Photoshop 2026 27.11.0; merged `parity-estimate.md` and the roadmap's honest assessment; stale missing-tool rows corrected: Color Replacement and Red Eye are live toolbar tools, Frame landed; percentages unchanged) · **Target:** Adobe Photoshop 2026The authoritative answer to "how close is PhotoCraft to Photoshop, and how much work is left". Theone-page summary is [`ROADMAP.md`](../ROADMAP.md); the ranked work list is [`gaps.md`](gaps.md);@@ -177,7 +177,7 @@ parity for the area and are already contained in the dimension rows above.| Vector shapes and paths | 55% | 80–140 | Pen, Direct/Path Selection, shapes, shape strokes. Freeform and Curvature Pen (#1054). Add/Delete Anchor Point and Convert Point tools exist (`Tool` enum); on-canvas corner radius widgets on live rectangles (TOOL-214-12, 2026-10-13); shape Density and Feather, the path as the fill's soft vector mask, matching Photoshop's 10 px feather ramp within 1 level (#5846, 2026-10-15); missing path-point nudge; shape parity tracking issue #2496 || Colour management and modes | 70% | 60–100 | Own ICC engine, soft proof, CMYK/Lab/Indexed/Duotone/Multichannel; no Adobe CMYK profiles, no spot plates (FILE-215-17), monitor profile only at launch || Camera Raw and computational photo (Photomerge, HDR, lens) | 45% | 120–200 | Raw for DNG/CR2/NEF/ARW/RW2/ORF/RAF(uncompressed)/PEF; no CR3; ACR dialog partial (no masking, calibration); generic lens profiles only |-| Automation, actions, batch, scripting | 45% | 120–200 | CLI/MCP/control channel ahead of Photoshop; Actions panel and recording not document-independent (AUTO-219-1/2); `.atn` load/save since 2026-10-12 (112 events mapped, the rest kept verbatim); no ExtendScript/UXP |+| Automation, actions, batch, scripting | 45% | 120–200 | CLI/MCP/control channel ahead of Photoshop; Actions panel and recording not document-independent (AUTO-219-1/2); `.atn` load/save since 2026-10-12 (112 events mapped, the rest kept verbatim); compound layer properties export as separate Set events with rename last (#8304, 2026-10-21; independent Photoshop replay pending); no ExtendScript/UXP || File I/O | 60% | 300–500 | See [file-format-parity.md](file-format-parity.md) || Print, export, Save for Web | 50% | 60–100 | JPEG Options dialog missing (FILE-215-19), no Photoshop PDF, no separations, Save for Web settings not remembered || Video / timeline, data-driven graphics | 30% | 100–200 | Menu items live; frame model persists in `.pcraft`; no PSD video-layer mapping |@@ -565,6 +565,7 @@ See [method, raw measurements and reproduction](five-algorithm-performance.md).| Date | Change | Summary ||---|---|---|+| 2026-10-21 | minor | #8304: compound layer properties export as separate Set events, rename last; independent Photoshop replay pending; percentages and estimates unchanged || 2026-10-18 | minor | Layers: with no selection, Copy takes fill and adjustment layers whole and Paste recreates them (#2344); UI-217-23 stays partial; percentages unchanged || 2026-10-16 | minor | Content-Aware Move: live result preview for every selection the command takes (TOOL-213-4 done, #6680); percentages unchanged || 2026-10-15 | minor | Vector shapes: shape layers take Density and Feather (Properties › Masks), PSD and .pcraft round trip; TOOL-214-12 done (#5846); estimates unchanged |