mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Merge PR #7590: fix(atn): keep a Transform Selection's interpolation; refuse what the transform descriptor can't carry
Conflicts: crates/engine/src/atn_cmds/tests.rs: appended tests, kept both
This commit is contained in:
commit
1cbeb4a784
2 files changed
+49
-3
No files matched your search
@@ -1783,8 +1783,15 @@ fn transform_from(d: &Descriptor) -> Mapped {
|
||||
// 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;
|
||||
// The resampling applies to a selection as much as to a layer (#7515).
|
||||
let interpolation = get_enum(d, "Intr").and_then(|i| lookup(INTERPOLATION, &i)).filter(|i| matches!(*i, "bicubic" | "bilinear" | "nearest"));
|
||||
match (ref_class(r).as_deref(), target(r)) {
|
||||
(Some("Chnl"), Target::Property(prop)) if prop == "fsel" => step("select.transformSelection", Value::Object(p)),
|
||||
(Some("Chnl"), Target::Property(prop)) if prop == "fsel" => {
|
||||
if let Some(i) = interpolation {
|
||||
p.insert("interpolation".into(), i.into());
|
||||
}
|
||||
step("select.transformSelection", Value::Object(p))
|
||||
}
|
||||
(Some("Lyr"), _) => {
|
||||
let Some(mut lp) = layer_target(r) else { return unsupported };
|
||||
if geometry_only {
|
||||
@@ -1793,7 +1800,7 @@ fn transform_from(d: &Descriptor) -> Mapped {
|
||||
return step("layer.translate", Value::Object(lp));
|
||||
}
|
||||
lp.extend(p);
|
||||
if let Some(i) = get_enum(d, "Intr").and_then(|i| lookup(INTERPOLATION, &i)).filter(|i| matches!(*i, "bicubic" | "bilinear" | "nearest")) {
|
||||
if let Some(i) = interpolation {
|
||||
lp.insert("interpolation".into(), i.into());
|
||||
}
|
||||
step("edit.transform", Value::Object(lp))
|
||||
@@ -1803,7 +1810,16 @@ fn transform_from(d: &Descriptor) -> Mapped {
|
||||
}
|
||||
|
||||
fn transform_to(id: &str, p: &Value) -> Option<Descriptor> {
|
||||
if p.get("quad").is_some() || p.get("matrix").is_some() || p.get("rect").is_some() {
|
||||
let given = |k: &str| p.get(k).is_some_and(|v| !v.is_null());
|
||||
if ["quad", "corners", "matrix", "rect"].iter().any(|k| given(k)) {
|
||||
return None;
|
||||
}
|
||||
// The descriptor scales and rotates about the centre (`FTcs` average) without skew or warp:
|
||||
// another reference point, a skew or a warp would replay as a different transform (#7516,
|
||||
// #7517, #7518, #7519).
|
||||
let nonzero = |k: &str| p.get(k).is_some_and(|v| !v.is_null() && v.as_f64() != Some(0.0));
|
||||
let off_centre = p.get("reference").is_some_and(|v| !v.is_null() && *v != json!("center"));
|
||||
if nonzero("skewX") || nonzero("skewY") || off_centre || ["warp", "style", "mesh", "grid"].iter().any(|k| given(k)) {
|
||||
return None;
|
||||
}
|
||||
let target = match id {
|
||||
|
||||
@@ -1580,6 +1580,36 @@ fn minimum_and_maximum_with_roundness_are_not_exported_as_squareness() {
|
||||
}
|
||||
}
|
||||
|
||||
/// #7515: a Transform Selection's interpolation survives the round trip as a layer transform's
|
||||
/// does. #7516-#7519: a reference point other than the centre, a skew or a warp can't be written,
|
||||
/// so the step is refused instead of replaying as a plain scale.
|
||||
#[test]
|
||||
fn transform_selection_keeps_its_interpolation_and_refuses_what_it_cannot_carry() {
|
||||
let one = |id: &str, p: Value| Action { name: "Probe".into(), steps: vec![(id.into(), p)], ..Default::default() };
|
||||
let p = json!({"dx": 0.7, "dy": 0, "scaleX": 140, "scaleY": 80, "interpolation": "nearest"});
|
||||
let (bytes, skipped) = export("Audit7", &[&one("select.transformSelection", p.clone())], &[], false).unwrap();
|
||||
assert!(skipped.is_empty());
|
||||
let imported = import(&bytes).unwrap();
|
||||
assert_eq!(imported.actions[0].steps, vec![("select.transformSelection".to_string(), p)]);
|
||||
for id in ["select.transformSelection", "edit.transform"] {
|
||||
for p in [
|
||||
json!({"scaleX": 140, "reference": "topLeft"}),
|
||||
json!({"scaleX": 140, "reference": [3, 4]}),
|
||||
json!({"scaleX": 140, "skewX": 12}),
|
||||
json!({"scaleX": 140, "skewY": -5}),
|
||||
json!({"warp": "arc"}),
|
||||
json!({"corners": [[0, 0], [10, 0], [10, 10], [0, 10]]}),
|
||||
] {
|
||||
let err = export("Audit7", &[&one(id, p.clone())], &[], false).unwrap_err();
|
||||
assert!(err.contains("no Photoshop equivalent") && err.contains(&format!("`{id}`")), "{id} {p}: {err}");
|
||||
let (_, skipped) = export("Audit7", &[&one(id, p.clone())], &[], true).unwrap();
|
||||
assert_eq!(skipped, vec![Skipped { action: "Probe".into(), step: 0, id: id.into() }], "{id} {p}");
|
||||
}
|
||||
let carried = json!({"scaleX": 140, "reference": "center", "skewX": 0, "skewY": 0});
|
||||
assert!(export("Audit7", &[&one(id, carried.clone())], &[], false).is_ok(), "{id} {carried}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Photoshop's Close has no document target: a Close of a specific document must not be
|
||||
/// exported as a plain Close, which would close the active document on playback.
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user