PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Refuse strict .atn export of Apply Image with a blending mask
NetterSilvere371bc34e389
diff --git a/crates/engine/src/atn_cmds.rs b/crates/engine/src/atn_cmds.rsindex 9e8eb6cb7..a897876b4 100644--- a/crates/engine/src/atn_cmds.rs+++ b/crates/engine/src/atn_cmds.rs@@ -1736,6 +1736,15 @@ fn apply_image_from(d: &Descriptor) -> Mapped {}fn apply_image_to(_: &str, p: &Value) -> Option<Descriptor> {+ // The optional blending mask has no descriptor mapping: refuse it rather than drop it,+ // which would widen the edit to the whole layer.+ let mask_channel = match p.get("mask") {+ Some(m) => m.get("channel"),+ None => p.get("maskChannel"),+ };+ if mask_channel.is_some_and(|c| !(c.is_null() || c == "none" || c == "")) {+ return None;+ }let source = p.get("source").cloned().unwrap_or(json!({}));let channel = jstr(&source, "channel").unwrap_or("composite");let chan = lookup_back(SOURCE_CHANNELS, channel).or_else(|| lookup_back(CHANNELS, channel))?;diff --git a/crates/engine/src/atn_cmds/tests.rs b/crates/engine/src/atn_cmds/tests.rsindex 26865d406..1d32b4eec 100644--- a/crates/engine/src/atn_cmds/tests.rs+++ b/crates/engine/src/atn_cmds/tests.rs@@ -1387,3 +1387,23 @@ fn function_keys_keep_shift_and_command() {}assert_eq!(super::function_key_name(7, false, false), "F7");}++/// Apply Image's optional blending mask has no `.atn` mapping: a strict export must refuse the+/// step rather than drop the mask and widen the edit to the whole layer.+#[test]+fn apply_image_with_blending_mask_is_not_exported_without_its_mask() {+ let source = json!({"layer": "Pixels", "channel": "green", "invert": true});+ for params in [json!({"source": source, "blending": "normal", "mask": {"channel": 0}}), json!({"source": source, "blending": "normal", "maskChannel": 0})] {+ let masked = Action { name: "Masked".into(), steps: vec![("image.applyImage".into(), params.clone())], ..Default::default() };+ assert!(export("Audit5", &[&masked], &[], false).is_err(), "{params}");+ let (_, skipped) = export("Audit5", &[&masked], &[], true).unwrap();+ assert_eq!(skipped, vec![Skipped { action: "Masked".into(), step: 0, id: "image.applyImage".into() }]);+ }+ for params in [json!({"source": source, "blending": "normal"}), json!({"source": source, "blending": "normal", "mask": {"channel": "none"}})] {+ let plain = Action { name: "Plain".into(), steps: vec![("image.applyImage".into(), params.clone())], ..Default::default() };+ let (bytes, skipped) = export("Audit5", &[&plain], &[], false).unwrap();+ assert!(skipped.is_empty());+ let imported = import(&bytes).unwrap();+ assert_eq!(imported.actions[0].steps, vec![("image.applyImage".to_string(), json!({"source": source, "blending": "normal"}))]);+ }+}