diff --git a/crates/engine/src/atn_cmds.rs b/crates/engine/src/atn_cmds.rs index dee2a6088a..d9f36a988f 100644 --- a/crates/engine/src/atn_cmds.rs +++ b/crates/engine/src/atn_cmds.rs @@ -856,7 +856,7 @@ const ADJUSTMENTS: &[Adjustment] = &[ Adjustment { class: "ClrB", suffix: "colorBalance", from: color_balance_from, to: color_balance_to }, adj_fields!("Vbrn", "vibrance", &[F("vibrance", "vibrance", Kind::Long), F("Strt", "saturation", Kind::Long)]), adj_fields!("Exps", "exposure", &[F("Exps", "exposure", Kind::Dbl), F("Ofst", "offset", Kind::Dbl), F("gammaCorrection", "gamma", Kind::Dbl)]), - adj_fields!("PhtF", "photoFilter", &[F("Clr ", "color", Kind::Color), F("Dnst", "density", Kind::Long), F("PrsL", "preserveLuminosity", Kind::Bool)]), + Adjustment { class: "PhtF", suffix: "photoFilter", from: |d| fields_from(d, PHOTO_FILTER_FIELDS).map(Value::Object), to: photo_filter_to }, adj_fields!("BlnW", "blackWhite", BW), Adjustment { class: "ChnM", suffix: "channelMixer", from: channel_mixer_from, to: channel_mixer_to }, Adjustment { class: "SlcC", suffix: "selectiveColor", from: selective_from, to: selective_to }, @@ -867,6 +867,29 @@ fn adjustment_by_class(c: &str) -> Option<&'static Adjustment> { ADJUSTMENTS.iter().find(|a| a.class.trim_end() == c.trim_end()) } +const PHOTO_FILTER_FIELDS: &[F] = &[F("Clr ", "color", Kind::Color), F("Dnst", "density", Kind::Long), F("PrsL", "preserveLuminosity", Kind::Bool)]; + +/// A `PhtF` step whose params carry a `filter` preset without an explicit `color`: the descriptor +/// form is colour-only (Photoshop stores no preset key — the `phfl` notes in `crates/io` conclude +/// the same from its CS2 oracles), so the resolved colour must be written, or re-imported playback +/// falls back to the default warming filter. With both present, the explicit colour wins, as when +/// running the command. An unknown preset id keeps the old export (no colour) instead of failing. +fn photo_filter_to(p: &Value) -> Option { + let mut p = p.clone(); + if p.get("color").is_none() { + let hex = p.get("filter").and_then(Value::as_str).and_then(preset_color); + if let (Some(hex), Some(o)) = (hex, p.as_object_mut()) { + o.insert("color".into(), hex.into()); + } + } + fields_to(&p, PHOTO_FILTER_FIELDS, desc("PhtF")) +} + +/// The preset id's resolved `#rrggbb`, or none (no id given, or an unknown one). +fn preset_color(id: &str) -> Option { + crate::adjust_params::PHOTO_FILTERS.iter().find(|f| f.0 == id).map(|(_, _, rgb)| format!("#{:02x}{:02x}{:02x}", rgb[0], rgb[1], rgb[2])) +} + fn adjustment_by_suffix(suffix: &str) -> Option<&'static Adjustment> { ADJUSTMENTS.iter().find(|a| a.suffix == suffix) } diff --git a/crates/engine/src/atn_cmds/tests.rs b/crates/engine/src/atn_cmds/tests.rs index a76eb1fc15..97be5b733b 100644 --- a/crates/engine/src/atn_cmds/tests.rs +++ b/crates/engine/src/atn_cmds/tests.rs @@ -577,6 +577,45 @@ fn bucket_keeps_an_explicit_color_through_atn() { } } +/// `image.adjustments.photoFilter` exported to .atn and imported back → its params, or None. +fn photo_filter_round_trip(params: Value) -> Option { + let item = export_item("image.adjustments.photoFilter", ¶ms, "S")?; + let e = event_for(&item.event)?; + match (e.from)(item.descriptor.as_ref()?) { + Mapped::Steps(steps) => steps.first().map(|(id, p)| { + assert_eq!(id, "image.adjustments.photoFilter"); + p.clone() + }), + _ => None, + } +} + +#[test] +fn photo_filter_preset_only_step_keeps_its_resolved_color() { + // #7235: the Photoshop descriptor keeps only a colour (`phfl`/`PhtF` are colour-only; the io + // notes reach the same conclusion from the CS2 oracles). A step recorded with only `filter` + // previously exported with no colour at all, so re-imported playback fell back to the default + // warming filter; it must export the resolved colour of the chosen preset instead. + let mut back = photo_filter_round_trip(json!({"filter": "cooling80", "density": 60, "preserveLuminosity": true})).unwrap(); + normalise(&mut back); + assert_eq!(back, json!({"color": "#006dff", "density": 60, "preserveLuminosity": true})); + // An omitted density stays omitted: running the imported step applies the same default. + let mut back = photo_filter_round_trip(json!({"filter": "red"})).unwrap(); + normalise(&mut back); + assert_eq!(back, json!({"color": "#ea1a1a"})); + // With an explicit colour too, the colour wins, as when running the command. + let mut back = photo_filter_round_trip(json!({"filter": "cooling80", "color": "#123456", "density": 25})).unwrap(); + normalise(&mut back); + assert_eq!(back, json!({"color": "#123456", "density": 25})); + let mut back = photo_filter_round_trip(json!({"color": "#123456", "density": 25})).unwrap(); + normalise(&mut back); + assert_eq!(back, json!({"color": "#123456", "density": 25})); + // An unknown preset id keeps the old export: no colour resolves, playback applies its default. + let mut back = photo_filter_round_trip(json!({"filter": "nope", "density": 25})).unwrap(); + normalise(&mut back); + assert_eq!(back, json!({"density": 25})); +} + #[test] fn unsupported_shapes_become_photoshop_steps_not_errors() { // Image size in two different percentages, a Paint Bucket click in percent of the canvas, a