Actions: keep a Match Color step whose noReference isn't a Boolean (CodeRabbit review on crates/engine/src/cmd/atn_cmds/steps_channels.rs:88)

Only a Boolean false kept the step: any other non-Boolean value read as
missing, so the step played as a source-less Match Color and saved back
as `noReference` true. A `setting` helper (as in steps_image.rs) reads
the present key as a Boolean, and anything but true keeps the step.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Hector VillarrealandClaude Opus 5.5 committed 2026-10-31 21:53:01 -06:00
1 parent ce6b88c12b
commit fc88c45117
3 files changed
+44 -10

No files matched your search

+14 -6
View File
@@ -20,13 +20,17 @@ pub(super) fn get_num(d: &Descriptor, k: &str) -> Option<f64> {
d.get(k).and_then(num)
}
pub(super) fn get_bool(d: &Descriptor, k: &str) -> Option<bool> {
match d.get(k) {
Some(D::Boolean(b)) => Some(*b),
pub(super) fn boolean(v: &D) -> Option<bool> {
match v {
D::Boolean(b) => Some(*b),
_ => None,
}
}
pub(super) fn get_bool(d: &Descriptor, k: &str) -> Option<bool> {
d.get(k).and_then(boolean)
}
pub(super) fn get_text(d: &Descriptor, k: &str) -> Option<String> {
match d.get(k) {
Some(D::Text(t)) => Some(t.to_string_lossy()),
@@ -35,13 +39,17 @@ pub(super) fn get_text(d: &Descriptor, k: &str) -> Option<String> {
}
/// An enumerated value's id, trailing spaces removed (`Ordn.Trgt` → `"Trgt"`).
pub(super) fn get_enum(d: &Descriptor, k: &str) -> Option<String> {
match d.get(k) {
Some(D::Enumerated { value, .. }) => Some(trimmed(value)),
pub(super) fn enumerated(v: &D) -> Option<String> {
match v {
D::Enumerated { value, .. } => Some(trimmed(value)),
_ => None,
}
}
pub(super) fn get_enum(d: &Descriptor, k: &str) -> Option<String> {
d.get(k).and_then(enumerated)
}
pub(super) fn get_obj<'a>(d: &'a Descriptor, k: &str) -> Option<&'a Descriptor> {
match d.get(k) {
Some(D::Descriptor(o) | D::GlobalObject(o)) => Some(o),
@@ -1,7 +1,7 @@
//! Photoshop's channel and colour steps (#10609): Split Channels, Merge Spot Channel, Trap and
//! Match Color, with the keys Photoshop records.
use super::descriptors::{desc, get_bool, get_num, px, trimmed};
use super::descriptors::{boolean, desc, get_num, px, trimmed};
use super::events::pixel_target;
use super::fields::{Mapped, step};
use super::{D, Descriptor, Value, json};
@@ -11,6 +11,16 @@ fn only_keys(d: &Descriptor, keys: &[&str]) -> bool {
d.items.iter().all(|(k, _)| keys.contains(&trimmed(k).as_str()))
}
/// The step's `key` read by `read` (its space padding ignored, as `only_keys` admits it),
/// `default` when the step leaves it out, `None` when it holds a value `read` can't take: that
/// is still the step's setting, so the step is kept rather than played with the default.
fn setting<T>(d: &Descriptor, key: &str, read: impl Fn(&D) -> Option<T>, default: T) -> Option<T> {
match d.items.iter().find(|(k, _)| trimmed(k) == key.trim_end()) {
Some((_, v)) => read(v),
None => Some(default),
}
}
/// Whether `p` sets nothing but `allowed` (a `null` counts as unset).
fn sets_only(p: &Value, allowed: &[&str]) -> bool {
p.as_object().is_none_or(|m| m.iter().all(|(k, v)| v.is_null() || allowed.contains(&k.as_str())))
@@ -71,10 +81,10 @@ pub(super) fn trap_to(_: &str, p: &Value) -> Option<Descriptor> {
const MATCH_COLOR: &[(&str, &str, i32)] = &[("Lght", "luminance", 100), ("ClrR", "intensity", 100), ("Fade", "fade", 0)];
/// Match Color (`matchColor`) without a source, as Photoshop records it (`noReference`). A
/// step that matches another image (`noReference` false) names no source here, so it keeps
/// the Photoshop step.
/// step that matches another image (`noReference` false, or not a Boolean) names no source
/// here, so it keeps the Photoshop step.
pub(super) fn match_color_from(d: &Descriptor) -> Mapped {
if !only_keys(d, &["Lght", "ClrR", "Fade", "noReference"]) || get_bool(d, "noReference") == Some(false) {
if !only_keys(d, &["Lght", "ClrR", "Fade", "noReference"]) || setting(d, "noReference", boolean, true) != Some(true) {
return Mapped::Unsupported { harmless: false };
}
let mut p = serde_json::Map::new();
+16
View File
@@ -3275,3 +3275,19 @@ fn trap_wider_than_photoshop_takes_is_refused() {
let d = export_item("image.trap", &json!({"width": 32767}), "S").unwrap().descriptor.unwrap();
assert_eq!(d.items, desc("null").with("Wdth", px(32767.0)).items);
}
/// The channel or colour step `d` of the Photoshop event `name`, as PhotoCraft loads it.
fn channel_step(name: &str, d: Descriptor) -> Mapped {
let event = if name.len() == 4 { AtnEvent::Code(name.as_bytes().try_into().unwrap()) } else { AtnEvent::name(name) };
(events::event_for(&event).unwrap_or_else(|| panic!("{name} is unknown")).from)(&d)
}
/// A `noReference` that isn't a Boolean doesn't say the step has no source, so the step stays
/// a Photoshop step instead of playing as a source-less Match Color (#10609).
#[test]
fn match_color_with_a_non_boolean_no_reference_is_kept() {
for v in [D::Integer(1), text("true"), enm("Ordn", "Trgt")] {
let m = channel_step("matchColor", desc("null").with("noReference", v.clone()));
assert!(matches!(m, Mapped::Unsupported { harmless: false }), "noReference {v:?} was mapped");
}
}