Merge PR #7627: Actions: Minimum / Maximum with Preserve: Roundness is no longer exported as Squareness (#7233)

This commit is contained in:
aiongg committed 2026-10-21 18:15:02 +00:00
commit a6702058db
2 files changed
+37 -3

No files matched your search

+15 -3
View File
@@ -907,6 +907,11 @@ struct Event {
macro_rules! ev {
($code:literal, $name:literal, $label:literal, $id:literal, $fields:expr) => {
ev!($code, $name, $label, $id, $fields, unless | _ | false)
};
// `unless`: params the descriptor can't carry, so such a step isn't exported (it would replay
// differently) rather than losing them.
($code:literal, $name:literal, $label:literal, $id:literal, $fields:expr, unless $skip:expr) => {
Event {
code: $code,
name: $name,
@@ -916,11 +921,18 @@ macro_rules! ev {
Some(m) => step($id, Value::Object(m)),
None => Mapped::Unsupported { harmless: false },
},
to: |_, p| if pixel_target(p) { fields_to(p, $fields, desc("null")) } else { None },
to: |_, p| if pixel_target(p) && !($skip)(p) { fields_to(p, $fields, desc("null")) } else { None },
}
};
}
/// Minimum / Maximum with Preserve: Roundness. The descriptor here maps the radius only, and
/// Photoshop's encoding of the shape isn't verified, so such a step is not exported: it would
/// replay as the default Squareness (#7233).
fn preserves_roundness(p: &Value) -> bool {
p.get("preserve").and_then(Value::as_str) == Some("roundness")
}
/// Whether `p` edits the layer's pixels: no `"target"` or `"target":"pixels"`. Photoshop's
/// descriptor for a plain event has no field for a mask, Quick Mask or channel target, so such
/// a step can't be exported faithfully.
@@ -2822,8 +2834,8 @@ const EVENTS: &[Event] = &[
ev!("ShrM", "sharpenMore", "Sharpen More", "filter.sharpen.sharpenMore", &[]),
ev!("ShrE", "sharpenEdges", "Sharpen Edges", "filter.sharpen.sharpenEdges", &[]),
ev!("HghP", "highPass", "High Pass", "filter.other.highPass", &[F("Rds ", "radius", Kind::Px)]),
ev!("Mnm ", "minimum", "Minimum", "filter.other.minimum", &[F("Rds ", "radius", Kind::Px)]),
ev!("Mxm ", "maximum", "Maximum", "filter.other.maximum", &[F("Rds ", "radius", Kind::Px)]),
ev!("Mnm ", "minimum", "Minimum", "filter.other.minimum", &[F("Rds ", "radius", Kind::Px)], unless preserves_roundness),
ev!("Mxm ", "maximum", "Maximum", "filter.other.maximum", &[F("Rds ", "radius", Kind::Px)], unless preserves_roundness),
ev!(
"Ofst",
"offset",
+22
View File
@@ -1384,6 +1384,28 @@ fn save_while_recording_includes_pending_steps() {
assert_eq!(action["steps"].as_array().unwrap().len(), 2, "both steps must be present without duplication");
}
/// #7233: the Minimum / Maximum descriptor carries the radius only, so a step with Preserve:
/// Roundness is refused by strict export (and left out, reported, otherwise) instead of replaying
/// as the default Squareness. Squareness, explicit or by default, still round-trips.
#[test]
fn minimum_and_maximum_with_roundness_are_not_exported_as_squareness() {
for id in ["filter.other.minimum", "filter.other.maximum"] {
let round = Action { name: "Round".into(), steps: vec![(id.into(), json!({"radius": 2, "preserve": "roundness"}))], ..Default::default() };
assert!(export("Audit", &[&round], &[], false).is_err(), "{id}: strict export refuses it");
let (_, skipped) = export("Audit", &[&round], &[], true).unwrap();
assert_eq!(skipped, vec![Skipped { action: "Round".into(), step: 0, id: id.into() }], "{id}");
for p in [json!({"radius": 2}), json!({"radius": 2, "preserve": "squareness"})] {
let square = Action { name: "Square".into(), steps: vec![(id.into(), p.clone())], ..Default::default() };
let (bytes, skipped) = export("Audit", &[&square], &[], false).unwrap();
assert!(skipped.is_empty(), "{id} {p}");
let imported = import(&bytes).unwrap();
let (got, params) = &imported.actions[0].steps[0];
assert_eq!((got.as_str(), params["radius"].as_f64()), (id, Some(2.0)), "{id} {p}");
assert!(params.get("preserve").is_none_or(|v| v == "squareness"), "{id} {p}: {params}");
}
}
}
/// 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]