Actions: keep a Smart Sharpen step outside the command's amount and radius limits (FredApps review)

filter.sharpen.smartSharpen takes an amount of 1..500 % and a radius of
0.1..64 px and rejects anything else. The importer accepted any finite
value, so such a step mapped and then failed when it played. It now keeps
the Photoshop step, and export refuses those values instead of writing
them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Hector VillarrealandClaude Opus 5.5 committed 2026-11-01 02:35:44 -06:00
1 parent 084130fb8e
commit cfc4c19eb8
2 files changed
+35 -4

No files matched your search

+11 -4
View File
@@ -597,10 +597,16 @@ fn in_unit(unit: [u8; 4]) -> impl Fn(&D) -> Option<f64> {
}
}
/// `filter.sharpen.smartSharpen`'s amount and radius limits, in `smart_sharpen_params`' key order.
/// The command rejects a value outside them, so such a step keeps the Photoshop step on import
/// and is refused on export, rather than mapping a step that fails when it plays.
const SMART_SHARPEN_LIMITS: &[(&str, f64, f64)] = &[("amount", 1.0, 500.0), ("radius", 0.1, 64.0)];
/// Smart Sharpen (`smartSharpen`), as Photoshop records it without its dialog: the legacy
/// filter, removing Lens Blur, with no noise reduction (so `reduceNoise` is 0). A step that
/// asks for what the command does not do (another blur, More Accurate, the newer filter, a
/// preset), or an amount or radius in another unit, keeps it as a Photoshop step.
/// preset), or an amount or radius in another unit or outside the command's limits, keeps it
/// as a Photoshop step.
pub(super) fn smart_sharpen_from(d: &Descriptor) -> Mapped {
match smart_sharpen_params(d) {
Some(p) => step("filter.sharpen.smartSharpen", Value::Object(p)),
@@ -619,8 +625,9 @@ fn smart_sharpen_params(d: &Descriptor) -> Option<Map<String, Value>> {
return None;
}
let mut p = Map::new();
for (key, param, unit, default) in [("Amnt", "amount", *b"#Prc", 200.0), ("Rds", "radius", PX, 1.0)] {
p.insert(param.into(), setting(d, key, in_unit(unit), default)?.into());
for ((key, unit, default), (param, min, max)) in [("Amnt", *b"#Prc", 200.0), ("Rds", PX, 1.0)].into_iter().zip(SMART_SHARPEN_LIMITS) {
let n = setting(d, key, in_unit(unit), default).filter(|n| (*min..=*max).contains(n))?;
p.insert((*param).into(), n.into());
}
p.insert("reduceNoise".into(), 0.into());
Some(p)
@@ -634,7 +641,7 @@ pub(super) fn smart_sharpen_to(_: &str, p: &Value) -> Option<Descriptor> {
}
let num = |k: &str, default: f64| match p.get(k) {
None | Some(Value::Null) => Some(default),
Some(v) => v.as_f64().filter(|n| n.is_finite()),
Some(v) => v.as_f64().filter(|n| SMART_SHARPEN_LIMITS.iter().any(|(param, min, max)| *param == k && (*min..=*max).contains(n))),
};
Some(
desc("null")
+24
View File
@@ -3378,3 +3378,27 @@ fn smart_sharpen_amount_or_radius_in_another_unit_is_kept() {
);
}
}
/// `filter.sharpen.smartSharpen` takes an amount of 1..500 % and a radius of 0.1..64 px and
/// rejects anything else. A step outside them would map and then fail when it plays, so it
/// stays a Photoshop step, and a step outside them is not written either (#10610).
#[test]
fn smart_sharpen_outside_the_commands_limits_is_kept_and_refused() {
kept_when_wrong_typed("smartSharpen", &[("Amnt", pct(0.5)), ("Amnt", pct(500.5)), ("Rds ", px(0.05)), ("Rds ", px(64.5)), ("Rds", px(1000.0))]);
for (amount, radius) in [(1.0, 0.1), (500.0, 64.0)] {
let d = desc("null").with("Amnt", pct(amount)).with("Rds ", px(radius));
assert_eq!(
mapped(newer("smartSharpen", d)),
("filter.sharpen.smartSharpen".into(), json!({"amount": amount, "radius": radius, "reduceNoise": 0})),
"{amount} {radius}"
);
}
for params in [
json!({"amount": 0.5, "reduceNoise": 0}),
json!({"amount": 501, "reduceNoise": 0}),
json!({"radius": 0.05, "reduceNoise": 0}),
json!({"radius": 65, "reduceNoise": 0}),
] {
assert!(export_item("filter.sharpen.smartSharpen", &params, "S").is_none(), "{params} exported");
}
}