PhotoCraft: An open-source, photo editor written by scratch in pure Rust
fix(actions): .atn export of Image Size with resample none no longer adds a pixel resize (#7189)
VishnuByrrajuc0882504810e
diff --git a/crates/engine/src/atn_cmds.rs b/crates/engine/src/atn_cmds.rsindex 9e8eb6cb7..210888e5c 100644--- a/crates/engine/src/atn_cmds.rs+++ b/crates/engine/src/atn_cmds.rs@@ -2444,13 +2444,21 @@ fn shadows_highlights_to(_: &str, p: &Value) -> Option<Descriptor> {fn image_size_to(_: &str, p: &Value) -> Option<Descriptor> {let mut d = desc("null");- if let Some(pc) = jnum(p, "percent") {+ // `resample: "none"` changes the resolution only and the command ignores any size then. The+ // descriptor has no "none" (it is the absence of `Intr`), so writing the ignored size would+ // turn the step into a pixel resize on playback (#7189).+ let resolution_only = jstr(p, "resample") == Some("none");+ if resolution_only && jnum(p, "resolution").is_none() {+ // Nothing left to record: the step changes nothing.+ return None;+ }+ if let Some(pc) = jnum(p, "percent").filter(|_| !resolution_only) {d = d.with("Wdth", pct(pc)).with("Hght", pct(pc)).with("CnsP", D::Boolean(true));}- if let Some(w) = jnum(p, "width") {+ if let Some(w) = jnum(p, "width").filter(|_| !resolution_only) {d = d.with("Wdth", px(w));}- if let Some(h) = jnum(p, "height") {+ if let Some(h) = jnum(p, "height").filter(|_| !resolution_only) {d = d.with("Hght", px(h));}if let Some(r) = jnum(p, "resolution") {diff --git a/crates/engine/src/atn_cmds/tests.rs b/crates/engine/src/atn_cmds/tests.rsindex 26865d406..385b7025a 100644--- a/crates/engine/src/atn_cmds/tests.rs+++ b/crates/engine/src/atn_cmds/tests.rs@@ -1387,3 +1387,27 @@ fn function_keys_keep_shift_and_command() {}assert_eq!(super::function_key_name(7, false, false), "F7");}++/// `image.imageSize` with `resample: "none"` ignores width, height and percent; the `.atn`+/// round trip must not turn them into a pixel resize (#7189).+#[test]+fn image_size_resample_none_keeps_ignoring_its_size_through_atn_export() {+ let event = event_for(&export_item("image.imageSize", &json!({"resolution": 72}), "S").expect("exports").event).expect("a known event");+ let back = |p: Value| {+ let item = export_item("image.imageSize", &p, "S")?;+ let Mapped::Steps(steps) = (event.from)(item.descriptor.as_ref().unwrap()) else { panic!("does not import back") };+ let mut back = steps[0].1.clone();+ normalise(&mut back);+ Some(back)+ };+ for sized in [json!({"width": 12, "height": 10}), json!({"width": 12}), json!({"percent": 200}), json!({"width": 12, "percent": 50, "height": 3})] {+ let mut p = sized.clone();+ p["resolution"] = json!(144);+ p["resample"] = json!("none");+ assert_eq!(back(p.clone()), Some(json!({"resolution": 144, "resample": "none"})), "{p}");+ }+ // A step with nothing left to record is refused rather than exported as an empty (unsupported) event.+ assert_eq!(back(json!({"width": 12, "height": 10, "resample": "none"})), None);+ // Real resizes are untouched.+ assert_eq!(back(json!({"width": 12, "height": 10, "resample": "bicubic"})), Some(json!({"width": 12, "height": 10, "resample": "bicubic"})));+}