diff --git a/crates/engine/src/cmd/atn_cmds/steps_image.rs b/crates/engine/src/cmd/atn_cmds/steps_image.rs index 91c4b20bfa..d6e98a744e 100644 --- a/crates/engine/src/cmd/atn_cmds/steps_image.rs +++ b/crates/engine/src/cmd/atn_cmds/steps_image.rs @@ -538,9 +538,21 @@ const OIL_PAINT: &[(&str, &str, f64, f64)] = &[ ("microBrush", "bristleDetail", 10.0, 5.0), ]; +/// `filter.stylize.oilPaint`'s ranges. The command clamps a value outside them when it plays, +/// so such a step keeps the Photoshop step on import and is refused on export, rather than +/// mapping a step that plays clamped and saves back unchanged. +const OIL_PAINT_LIMITS: &[(&str, f64, f64)] = + &[("stylization", 0.1, 10.0), ("cleanliness", 0.0, 10.0), ("scale", 0.1, 10.0), ("bristleDetail", 0.0, 10.0), ("shine", 0.0, 10.0)]; + +/// Whether `n` is within `filter.stylize.oilPaint`'s range for `param` (a param without one is). +fn in_oil_paint_limits(param: &str, n: f64) -> bool { + OIL_PAINT_LIMITS.iter().all(|(p, min, max)| *p != param || (*min..=*max).contains(&n)) +} + /// Oil Paint (`oilPaint`). Missing keys take Photoshop's defaults, which differ from the /// command's for cleanliness, scale, bristle detail and shine, so they are written out. A -/// setting of another number type, or with a unit, keeps the Photoshop step. +/// setting of another number type, with a unit, or outside the command's ranges keeps the +/// Photoshop step. pub(super) fn oil_paint_from(d: &Descriptor) -> Mapped { match oil_paint_params(d) { Some(p) => step("filter.stylize.oilPaint", Value::Object(p)), @@ -556,22 +568,23 @@ fn oil_paint_params(d: &Descriptor) -> Option> { let mut p = Map::new(); p.insert("lighting".into(), setting(d, "lightingOn", boolean, true)?.into()); for (key, param, ps, _) in OIL_PAINT { - p.insert((*param).into(), setting(d, key, double, *ps)?.into()); + p.insert((*param).into(), setting(d, key, double, *ps).filter(|n| in_oil_paint_limits(param, *n))?.into()); } p.insert("angle".into(), setting(d, "LghD", |v| integer(v).map(f64::from), -60.0)?.into()); - p.insert("shine".into(), setting(d, "specularity", double, 1.299_999_952_316_28)?.into()); + p.insert("shine".into(), setting(d, "specularity", double, 1.299_999_952_316_28).filter(|n| in_oil_paint_limits("shine", *n))?.into()); Some(p) } /// Every key in recorded order, the command's defaults for what the step leaves out. The light -/// direction is an integer: a fractional angle would replay rounded, so the step is refused. +/// direction is an integer: a fractional angle would replay rounded, so the step is refused, as +/// is a setting outside the command's ranges. pub(super) fn oil_paint_to(_: &str, p: &Value) -> Option { if !pixel_target(p) || !sets_only(p, &["target", "lighting", "stylization", "cleanliness", "scale", "bristleDetail", "angle", "shine"]) { return None; } 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| n.is_finite() && in_oil_paint_limits(k, *n)), }; let lighting = match p.get("lighting") { None | Some(Value::Null) => true, diff --git a/crates/engine/src/cmd/atn_cmds/tests.rs b/crates/engine/src/cmd/atn_cmds/tests.rs index 9cfa53d83e..b0849d3254 100644 --- a/crates/engine/src/cmd/atn_cmds/tests.rs +++ b/crates/engine/src/cmd/atn_cmds/tests.rs @@ -3434,3 +3434,56 @@ fn newer_feature_selection_steps_play() { assert!(played.get("failed").is_none(), "{played}"); assert_eq!(played["ran"], 3, "{played}"); } + +/// `filter.stylize.oilPaint` takes a stylization and scale of 0.1..10 and a cleanliness, bristle +/// detail and shine of 0..10, and clamps anything else when it plays. A step outside them would +/// play clamped and save back unchanged, so it stays a Photoshop step, and a step outside them +/// is not written either (#10610). +#[test] +fn oil_paint_outside_the_commands_ranges_is_kept_and_refused() { + kept_when_wrong_typed( + "oilPaint", + &[ + ("stylization", D::Double(0.05)), + ("stylization", D::Double(10.5)), + ("cleanliness", D::Double(-0.5)), + ("cleanliness", D::Double(10.5)), + ("brushScale", D::Double(0.05)), + ("brushScale", D::Double(10.5)), + ("microBrush", D::Double(-1.0)), + ("microBrush", D::Double(10.5)), + ("specularity", D::Double(-0.5)), + ("specularity", D::Double(10.5)), + ], + ); + for (low, high) in [(0.1, 0.0), (10.0, 10.0)] { + let d = desc("null") + .with("stylization", D::Double(low)) + .with("cleanliness", D::Double(high)) + .with("brushScale", D::Double(low)) + .with("microBrush", D::Double(high)) + .with("specularity", D::Double(high)); + assert_eq!( + mapped(newer("oilPaint", d)), + ( + "filter.stylize.oilPaint".into(), + json!({"lighting": true, "stylization": low, "cleanliness": high, "scale": low, "bristleDetail": high, "angle": -60.0, "shine": high}) + ), + "{low} {high}" + ); + } + for params in [ + json!({"stylization": 0.05}), + json!({"stylization": 10.5}), + json!({"cleanliness": -0.5}), + json!({"cleanliness": 10.5}), + json!({"scale": 0.05}), + json!({"scale": 10.5}), + json!({"bristleDetail": -1}), + json!({"bristleDetail": 11}), + json!({"shine": -0.5}), + json!({"shine": 10.5}), + ] { + assert!(export_item("filter.stylize.oilPaint", ¶ms, "S").is_none(), "{params} exported"); + } +}