Plug-ins: returned Curves points are checked in both forms, 0 to 255

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.
This commit is contained in:
dotCooCoo committed 2026-11-22 16:59:52 -08:00
1 parent d327f6be5f
commit 14cde8fd18
3 files changed
+24 -5

No files matched your search

+17 -3
View File
@@ -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<String, Value>) -> 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<String, Value>) -> 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::<f64>().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)?
+5
View File
@@ -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"),
+2 -2
View File
@@ -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