From 7835d05a54bc426a3053870666a11cb5e43ce7c1 Mon Sep 17 00:00:00 2001 From: Hamza Date: Mon, 19 Oct 2026 17:11:27 +0500 Subject: [PATCH 1/2] Actions: a Selective Color step keeps the values of its scalar form `image.adjustments.selectiveColor` takes a range two ways, and the command reads both: the array form `"reds": [c, m, y, k]`, and the scalar form that names one range and gives the channels it changes, `"colors": "reds", "cyan": 35`. `selective_to` looked only for the arrays. A step recorded the other way exported with an empty `ClrC` list -- an adjustment that changes nothing -- with `skipped` empty and no warning on import, so nothing said the values had gone. On a single red pixel the step produces [0.6509804, 0, 0, 1] run directly and leaves [1, 0, 0, 1] after a round trip through .atn. The rows are now built the way `selective_from_params` reads them: the arrays first, then the scalar form over the range it names, so a step that gives both exports what playing it would produce. An unknown range in `colors` still cannot be written and refuses the step. Fixes #7672. --- crates/engine/src/atn_cmds.rs | 27 ++++++++++++++++++++--- crates/engine/src/atn_cmds/tests.rs | 33 +++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/atn_cmds.rs b/crates/engine/src/atn_cmds.rs index d5c688f0a6..a4d6c33de5 100644 --- a/crates/engine/src/atn_cmds.rs +++ b/crates/engine/src/atn_cmds.rs @@ -724,12 +724,33 @@ fn selective_from(d: &Descriptor) -> Option { } fn selective_to(p: &Value) -> Option { - let mut list = Vec::new(); - for (ps, name) in SELECTIVE_RANGES { + // Each range, as the command reads it (`adjust_cmds::selective_from_params`): the array form + // `"reds": [c, m, y, k]` first, then the scalar form, which names one range in `"colors"` and + // gives the channels it changes. Writing only the arrays dropped the scalar form's values, and + // the step exported as an adjustment that changes nothing (#7672). + let mut rows: Vec> = vec![None; SELECTIVE_RANGES.len()]; + for (row, (_, name)) in rows.iter_mut().zip(SELECTIVE_RANGES) { if let Some(a) = p.get(*name).and_then(Value::as_array) { let v = |i: usize| a.get(i).and_then(Value::as_f64).unwrap_or(0.0); + *row = Some([v(0), v(1), v(2), v(3)]); + } + } + if let Some(named) = jstr(p, "colors") { + let i = SELECTIVE_RANGES.iter().position(|(_, name)| *name == named)?; + let row = rows.get_mut(i)?; + let mut v = row.unwrap_or([0.0; 4]); + for (slot, key) in v.iter_mut().zip(["cyan", "magenta", "yellow", "black"]) { + if let Some(n) = jnum(p, key) { + *slot = n; + } + } + *row = Some(v); + } + let mut list = Vec::new(); + for (row, (ps, _)) in rows.iter().zip(SELECTIVE_RANGES) { + if let Some(v) = row { list.push(D::Descriptor( - desc("ClrC").with("Clrs", enm("Clrs", ps)).with("Cyn ", pct(v(0))).with("Mgnt", pct(v(1))).with("Yllw", pct(v(2))).with("Blck", pct(v(3))), + desc("ClrC").with("Clrs", enm("Clrs", ps)).with("Cyn ", pct(v[0])).with("Mgnt", pct(v[1])).with("Yllw", pct(v[2])).with("Blck", pct(v[3])), )); } } diff --git a/crates/engine/src/atn_cmds/tests.rs b/crates/engine/src/atn_cmds/tests.rs index c4fe00eb95..8ecf7334f7 100644 --- a/crates/engine/src/atn_cmds/tests.rs +++ b/crates/engine/src/atn_cmds/tests.rs @@ -166,6 +166,39 @@ fn save_round_trips_through_photoshop_events() { assert_eq!(r["set"], "Ours"); } +/// `image.adjustments.selectiveColor` takes a range as an array (`"reds": [c, m, y, k]`) or as +/// the scalar form that names one range (`"colors": "reds", "cyan": 35`). Only the arrays were +/// written, so a step recorded the other way exported as an adjustment that changes nothing, with +/// `skipped` empty (#7672). +#[test] +fn a_selective_color_step_in_the_scalar_form_keeps_its_values() { + let back = |params: Value| -> Value { + let mut s = Session::new(); + s.actions.list.push(Action::new("A", vec![("image.adjustments.selectiveColor".into(), params)])); + let r = s.execute("actions.save", json!({"action": "A"})).unwrap(); + assert_eq!(r["skipped"], json!([])); + let imported = import(&photocraft_paint::tile::b64_decode(r["data"].as_str().unwrap()).unwrap()).unwrap(); + imported.actions[0].steps[0].1.clone() + }; + + // The numbers are read back as numbers; a percentage may arrive as 35 or 35.0. + let range = + |step: &Value, name: &str| -> Vec { step[name].as_array().unwrap_or(&Vec::new()).iter().map(|v| v.as_f64().unwrap_or(f64::NAN)).collect() }; + + // The reported step: one range, one channel. + let scalar = back(json!({"method": "absolute", "colors": "reds", "cyan": 35})); + assert_eq!(scalar["method"], "absolute"); + assert_eq!(range(&scalar, "reds"), [35.0, 0.0, 0.0, 0.0], "{scalar}"); + + // The scalar form over an array keeps both, as playing the step would. + let both = back(json!({"reds": [10, 20, 30, 40], "colors": "reds", "cyan": 35})); + assert_eq!(range(&both, "reds"), [35.0, 20.0, 30.0, 40.0], "{both}"); + + // The array form is unchanged. + let array = back(json!({"method": "relative", "yellows": [0, 0, -15, 5]})); + assert_eq!(range(&array, "yellows"), [0.0, 0.0, -15.0, 5.0], "{array}"); +} + #[test] fn every_mapped_command_exports_and_imports_back() { let cases: Vec<(&str, Value)> = vec![ From f30966569467231f34765998d136eb36ed6140f2 Mon Sep 17 00:00:00 2001 From: Hamza Date: Mon, 19 Oct 2026 18:29:33 +0500 Subject: [PATCH 2/2] Refuse a Selective Color channel the command would refuse MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The scalar form's channels went through `jnum`, which returns `None` for anything that is not a number, so `{"colors": "reds", "cyan": "35"}` exported as an untouched range while the command errors on it (`adjust_cmds::selective_from_params` → `percent`). The export would have written an adjustment that is not the one recorded. A channel that is present and not null must now be a finite number, or the step cannot be written and takes the refusal path. `null` counts as absent, as the command's `given` reads it. --- crates/engine/src/atn_cmds.rs | 9 +++++++-- crates/engine/src/atn_cmds/tests.rs | 11 +++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/atn_cmds.rs b/crates/engine/src/atn_cmds.rs index a4d6c33de5..87749a64d6 100644 --- a/crates/engine/src/atn_cmds.rs +++ b/crates/engine/src/atn_cmds.rs @@ -740,8 +740,13 @@ fn selective_to(p: &Value) -> Option { let row = rows.get_mut(i)?; let mut v = row.unwrap_or([0.0; 4]); for (slot, key) in v.iter_mut().zip(["cyan", "magenta", "yellow", "black"]) { - if let Some(n) = jnum(p, key) { - *slot = n; + // A channel that is given but is not a number is an error in the command + // (`adjust_cmds::selective_from_params`), so a step carrying one cannot be written + // either: ignoring it would export a different adjustment than the one recorded. + // `null` counts as absent there, and so here. + match p.get(key) { + None | Some(Value::Null) => {} + Some(_) => *slot = jnum(p, key)?, } } *row = Some(v); diff --git a/crates/engine/src/atn_cmds/tests.rs b/crates/engine/src/atn_cmds/tests.rs index 8ecf7334f7..81766af2cb 100644 --- a/crates/engine/src/atn_cmds/tests.rs +++ b/crates/engine/src/atn_cmds/tests.rs @@ -197,6 +197,17 @@ fn a_selective_color_step_in_the_scalar_form_keeps_its_values() { // The array form is unchanged. let array = back(json!({"method": "relative", "yellows": [0, 0, -15, 5]})); assert_eq!(range(&array, "yellows"), [0.0, 0.0, -15.0, 5.0], "{array}"); + + // A channel the command would refuse is not quietly dropped: the step is refused too, since + // writing it would export an adjustment that is not the one recorded. `null` is absent, as + // the command reads it. + let mut s = Session::new(); + s.actions.list.push(Action::new("A", vec![("image.adjustments.selectiveColor".into(), json!({"colors": "reds", "cyan": "35"}))])); + let e = s.execute("actions.save", json!({"action": "A"})).unwrap_err().to_string(); + assert!(e.contains("image.adjustments.selectiveColor"), "{e}"); + + let nulled = back(json!({"colors": "reds", "cyan": 35, "magenta": null})); + assert_eq!(range(&nulled, "reds"), [35.0, 0.0, 0.0, 0.0], "{nulled}"); } #[test]