From 14cde8fd1836235bba7304df43ca2e320f37df5b Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 22 Nov 2026 16:59:52 -0800 Subject: [PATCH] Plug-ins: returned Curves points are checked in both forms, 0 to 255 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A Curves effect a painted live-effect plug-in returns is refused when its `points` string holds a token that is not an `x,y` pair of numbers, or when any point in the string or the `[[x, y], …]` array lies outside 0 to 255. Before, an unreadable string passed and the effect drew the default curve, and an out-of-range point was clamped. --- crates/effects/src/params.rs | 20 +++++++++++++++++--- crates/effects/src/tests/painted.rs | 5 +++++ docs/plugins.md | 4 ++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/crates/effects/src/params.rs b/crates/effects/src/params.rs index 9130d746ae..9cdc305522 100644 --- a/crates/effects/src/params.rs +++ b/crates/effects/src/params.rs @@ -187,7 +187,7 @@ pub fn check_returned_effect(e: &Effect, row: bool) -> Result<(), String> { /// The values in `given`, the parameters of built-in effect `id` that a painted live-effect plug-in /// returned, that are checked further: an SVG filter's XML, `scale`, `origin`, `axes` and -/// `name`; a Free Distort's four `corners`; Curves' `points` as pairs; a Transform's whole +/// `name`; a Free Distort's four `corners`; Curves' `points` as pairs from 0 to 255; a Transform's whole /// `copies` and `reference`; a Warp's `version`; a `color` the effect can draw; a /// shadow's or glow's blend `mode`; a Levels or Curves `channel`; a Radial /// Blur's center; and the type of each parameter without a default. @@ -218,8 +218,8 @@ fn check_returned_values(id: &str, given: &Map) -> Result<(), Str if id == "distort.freeDistort" && given.get("corners").is_some_and(|c| !c.as_array().is_some_and(|c| c.len() == 4 && c.iter().all(pair))) { return Err("`corners` must be four [x, y] pairs of numbers".into()); } - if id == "adjust.curves" && given.get("points").and_then(Value::as_array).is_some_and(|p| !p.iter().all(pair)) { - return Err("`points` must be \"x,y x,y …\" or [[x, y], …] pairs of numbers".into()); + if id == "adjust.curves" && given.get("points").is_some_and(|p| !is_curve_points(p)) { + return Err("`points` must be \"x,y x,y …\" or [[x, y], …] pairs of numbers from 0 to 255".into()); } if id == "distort.transform" && let Some(key) = ["copies", "reference"].into_iter().find(|k| given.get(*k).and_then(Value::as_f64).is_some_and(|x| x.fract() != 0.0)) @@ -261,6 +261,20 @@ fn check_returned_values(id: &str, given: &Map) -> Result<(), Str Ok(()) } +/// Can Curves read `v` as its `points`: `"x,y x,y …"` (pairs split by whitespace or `;`) or +/// `[[x, y], …]`, each number from 0 to 255? +fn is_curve_points(v: &Value) -> bool { + let level = |x: f64| (0.0..=255.0).contains(&x); + match v { + Value::String(s) => s + .split(|c: char| c.is_whitespace() || c == ';') + .filter(|p| !p.is_empty()) + .all(|p| p.split_once(',').is_some_and(|(x, y)| [x, y].into_iter().all(|n| n.trim().parse::().is_ok_and(level)))), + Value::Array(a) => a.iter().all(|p| p.as_array().is_some_and(|p| p.len() == 2 && p.iter().all(|n| n.as_f64().is_some_and(level)))), + _ => false, + } +} + /// Can an effect read `v` as its `color`: a hex color or name [`Color::from_hex`] reads, `[r, g, b]` /// with three numbers from 0 to 1 first, or a color object with its components from 0 to 1 (a Lab /// color's lightness from 0 to 100, and finite a and b)? diff --git a/crates/effects/src/tests/painted.rs b/crates/effects/src/tests/painted.rs index 5792f9f233..d1a9952354 100644 --- a/crates/effects/src/tests/painted.rs +++ b/crates/effects/src/tests/painted.rs @@ -302,6 +302,7 @@ fn returned_effects_are_built_in_effects_with_their_own_parameters() { ("stylize.innerGlow", json!({"color": {"model": "lab", "l": 100, "a": -128, "b": 127}})), // Curves' `points` is also taken as [[x, y], …], and a Transform's whole numbers as such. ("adjust.curves", json!({"points": [[0, 255], [255, 0]]})), + ("adjust.curves", json!({"points": "0,0; 64,32 255,255"})), ("distort.transform", json!({"copies": 2, "reference": 0.0})), ] { assert_eq!(check(&e(id, params.clone()), false), Ok(()), "{id} {params}"); @@ -348,6 +349,10 @@ fn returned_effects_are_built_in_effects_with_their_own_parameters() { ("stylize.innerGlow", json!({"color": {"model": "lab", "l": 101, "a": 0, "b": 0}}), "color"), ("adjust.curves", json!({"points": [[0, 255], [255]]}), "points"), ("adjust.curves", json!({"points": ["0,0", "255,255"]}), "points"), + // Curves' points are read as "x,y" or [x, y] pairs, each number from 0 to 255. + ("adjust.curves", json!({"points": "not-points"}), "points"), + ("adjust.curves", json!({"points": "0,0 255,-1"}), "points"), + ("adjust.curves", json!({"points": [[0, 300], [255, 0]]}), "points"), ("distort.transform", json!({"copies": 1.5}), "copies"), ("distort.transform", json!({"reference": 4.5}), "reference"), ("adjust.levels", json!({"channel": "cyan"}), "channel"), diff --git a/docs/plugins.md b/docs/plugins.md index ffc38b858d..9ba350ce6a 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -876,8 +876,8 @@ fill and stroke the piece returns, three more keys: - An effect record names a built-in effect that `effect.list` lists, other than a 3D effect or a Pathfinder effect (`pathfinder.*`, which has nothing to combine on a piece's one path), with parameters that effect takes, each of the type of its default, within the range `effect.list` gives for it, where it gives one, and one of the choices it - lists for it, where it lists them (Roughen's `points` is `"smooth"` or `"corner"`). Curves' `points` may also be - `[[x, y], …]`, each a pair of numbers, and a Transform's `copies` and `reference` are whole numbers. The values + lists for it, where it lists them (Roughen's `points` is `"smooth"` or `"corner"`). Curves' `points` is + `"x,y x,y …"` or `[[x, y], …]`, each number from 0 to 255, and a Transform's `copies` and `reference` are whole numbers. The values `effect.apply` checks for one effect are checked the same way: an SVG filter's `xml`, `scale`, `origin`, `axes` and `name`, a Warp's `version`, a `color` (`"#rrggbb"`, `[r, g, b]` with each component from 0 to 1, or a color object whose RGB, CMYK or Gray components are each from 0 to 1, or whose Lab `l` is from 0 to 100 and `a` and `b` are any