Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Keep fractional translation-only Free Transform on .atn import (#7401)

NetterSilver706649788634
diff --git a/crates/engine/src/atn_cmds.rs b/crates/engine/src/atn_cmds.rs
index e0767330c..a32256920 100644
--- a/crates/engine/src/atn_cmds.rs
+++ b/crates/engine/src/atn_cmds.rs
@@ -1613,14 +1613,17 @@ fn transform_from(d: &Descriptor) -> Mapped {
if d.get("Skew").is_some() || d.get("Usng").is_some() {
return unsupported;
}
- let geometry_only = p.keys().all(|k| k == "dx" || k == "dy");
+ // A whole-pixel move is a plain `layer.translate`; a fractional one needs `edit.transform`
+ // to keep its sub-pixel placement and interpolation.
+ let whole_pixels = ["dx", "dy"].iter().all(|k| p.get(*k).and_then(Value::as_f64).is_none_or(|v| v.fract() == 0.0));
+ let geometry_only = p.keys().all(|k| k == "dx" || k == "dy") && whole_pixels;
match (ref_class(r).as_deref(), target(r)) {
(Some("Chnl"), Target::Property(prop)) if prop == "fsel" => step("select.transformSelection", Value::Object(p)),
(Some("Lyr"), _) => {
let Some(mut lp) = layer_target(r) else { return unsupported };
if geometry_only {
- lp.insert("dx".into(), p.get("dx").and_then(Value::as_f64).unwrap_or(0.0).round().into());
- lp.insert("dy".into(), p.get("dy").and_then(Value::as_f64).unwrap_or(0.0).round().into());
+ lp.insert("dx".into(), p.get("dx").and_then(Value::as_f64).unwrap_or(0.0).into());
+ lp.insert("dy".into(), p.get("dy").and_then(Value::as_f64).unwrap_or(0.0).into());
return step("layer.translate", Value::Object(lp));
}
lp.extend(p);
diff --git a/crates/engine/src/atn_cmds/tests.rs b/crates/engine/src/atn_cmds/tests.rs
index b280a6d67..335a3cbea 100644
--- a/crates/engine/src/atn_cmds/tests.rs
+++ b/crates/engine/src/atn_cmds/tests.rs
@@ -649,7 +649,7 @@ fn remaining_events_import_in_their_photoshop_shapes() {
let moved = desc("null")
.with("null", target_ref("Lyr "))
.with("FTcs", enm("QCSt", "Qcsa"))
- .with("Ofst", D::Descriptor(desc("Ofst").with("Hrzn", px(-57.4)).with("Vrtc", px(12.0))))
+ .with("Ofst", D::Descriptor(desc("Ofst").with("Hrzn", px(-57.0)).with("Vrtc", px(12.0))))
.with("Intr", enm("Intp", "Bcbc"));
let scaled = desc("null")
.with("null", target_ref("Lyr "))
@@ -1047,3 +1047,24 @@ fn close_with_document_target_is_not_exported_as_plain_close() {
let imported = import(&bytes).unwrap();
assert_eq!(imported.actions[0].steps, vec![("file.close".to_string(), json!({}))]);
}
+
+/// A translation-only Free Transform with a fractional offset must not collapse into an
+/// integer `layer.translate`: the sub-pixel placement and interpolation have to survive.
+#[test]
+fn fractional_translation_only_transform_keeps_offset_and_interpolation() {
+ let params = json!({"dx": 0.5, "dy": 0, "interpolation": "bilinear"});
+ let d = transform_to("edit.transform", &params).unwrap();
+ let file = AtnFile {
+ name: UnicodeString::new_nul("Frac"),
+ expanded: false,
+ actions: vec![AtnAction { name: UnicodeString::new_nul("A"), items: vec![item("transform", "Transform", Some(d))], ..Default::default() }],
+ warnings: vec![],
+ };
+ let imp = import(&atn::write(&file).unwrap()).unwrap();
+ assert!(imp.unsupported.is_empty());
+ let steps = &imp.actions[0].steps;
+ assert_eq!(steps.len(), 1);
+ assert_eq!(steps[0].0, "edit.transform");
+ assert_eq!(steps[0].1.get("dx").and_then(Value::as_f64), Some(0.5));
+ assert_eq!(steps[0].1.get("interpolation"), Some(&json!("bilinear")));
+}