diff --git a/crates/engine/src/cmd/atn_cmds/adjustments.rs b/crates/engine/src/cmd/atn_cmds/adjustments.rs index 21bebcb5c8..6115166271 100644 --- a/crates/engine/src/cmd/atn_cmds/adjustments.rs +++ b/crates/engine/src/cmd/atn_cmds/adjustments.rs @@ -242,12 +242,12 @@ fn color_balance_to(p: &Value) -> Option { } const BW: &[F] = &[ - F("Rd ", "reds", Kind::Long), - F("Yllw", "yellows", Kind::Long), - F("Grn ", "greens", Kind::Long), - F("Cyn ", "cyans", Kind::Long), - F("Bl ", "blues", Kind::Long), - F("Mgnt", "magentas", Kind::Long), + F("Rd ", "reds", Kind::ExactLong), + F("Yllw", "yellows", Kind::ExactLong), + F("Grn ", "greens", Kind::ExactLong), + F("Cyn ", "cyans", Kind::ExactLong), + F("Bl ", "blues", Kind::ExactLong), + F("Mgnt", "magentas", Kind::ExactLong), F("useTint", "tint", Kind::Bool), F("tintColor", "tintColor", Kind::Color), ]; diff --git a/crates/engine/src/cmd/atn_cmds/tests.rs b/crates/engine/src/cmd/atn_cmds/tests.rs index 7cbd32b06d..f9e80e0c15 100644 --- a/crates/engine/src/cmd/atn_cmds/tests.rs +++ b/crates/engine/src/cmd/atn_cmds/tests.rs @@ -2445,6 +2445,72 @@ fn black_white_adjustment_layer_saves_as_photoshops_class_and_old_class_still_im assert_eq!(t.actions.list.actions()[0].steps[1].params["reds"], 17, "{r}"); } +/// #11517: a native Black & White coefficient may be fractional, but an ATN long cannot. +#[test] +fn black_white_fractional_coefficients_refuse_lossy_export() { + for key in ["reds", "yellows", "greens", "cyans", "blues", "magentas"] { + for id in ["layer.newAdjustmentLayer.blackWhite", "image.adjustments.blackWhite", "layer.setAdjustment"] { + let mut params = json!({key: 40.4}); + if id == "layer.setAdjustment" { + params["kind"] = json!("blackWhite"); + } + let action = Action::new("Fractional BW", vec![(id.into(), params.clone())]); + let error = export("BW", &[&action], &[], false).unwrap_err(); + assert!(error.contains(id) && error.contains("skipUnsupported"), "{id} {key}: {error}"); + let (bytes, skipped) = export("BW", &[&action], &[], true).unwrap(); + assert_eq!(skipped, vec![Skipped { action: "Fractional BW".into(), step: 0, id: id.into() }]); + assert!(import(&bytes).unwrap().actions[0].steps.is_empty()); + assert_eq!(action.steps[0].1, params, "export must preserve the native action"); + } + } +} + +#[test] +fn black_white_whole_coefficients_and_defaults_round_trip() { + for id in ["layer.newAdjustmentLayer.blackWhite", "image.adjustments.blackWhite", "layer.setAdjustment"] { + for mut params in [ + json!({}), + json!({"reds": 40.0}), + json!({"reds": 17, "yellows": 83, "greens": -12, "cyans": 107, "blues": 51, "magentas": 133, "tint": true, "tintColor": "#c08040"}), + ] { + if id == "layer.setAdjustment" && params == json!({}) { + continue; + } + if id == "layer.setAdjustment" { + params["kind"] = json!("blackWhite"); + } + let action = Action::new("Whole BW", vec![(id.into(), params.clone())]); + let (bytes, skipped) = export("BW", &[&action], &[], false).unwrap(); + assert!(skipped.is_empty()); + let imported = import(&bytes).unwrap(); + assert!(imported.unsupported.is_empty() && imported.warnings.is_empty()); + let (back_id, back) = &imported.actions[0].steps[0]; + assert_eq!(back_id, id); + for key in ["reds", "yellows", "greens", "cyans", "blues", "magentas"] { + assert_eq!(back.get(key).and_then(Value::as_f64), params.get(key).and_then(Value::as_f64), "{id} {key}: {back}"); + } + for key in ["tint", "tintColor"] { + assert_eq!(back.get(key), params.get(key), "{id} {key}"); + } + } + } +} + +/// The reported fraction remains a real native edit at every supported document depth. +#[test] +fn black_white_native_fraction_keeps_its_pixels_at_every_depth() { + for depth in [8, 16, 32] { + let mut samples = Vec::new(); + for reds in [40.4, 40.0] { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 1, "height": 1, "background": "#ff0000", "depth": depth})).unwrap(); + s.execute("layer.newAdjustmentLayer.blackWhite", json!({"reds": reds})).unwrap(); + samples.push(photocraft_compose::flatten(&s.active().unwrap().doc).into_px()); + } + assert_ne!(samples[0], samples[1], "{depth}-bit native 40.4 must differ from rounded 40"); + } +} + /// Smart Blur's quality uses Photoshop's `SmBQ` codes (`SBQL`/`SBQM`/`SBQH`): measured in /// Photoshop, the old `Hgh `/`Mdm `/`Low ` play back as its fallback quality. Old codes still read. #[test] diff --git a/docs/atn.md b/docs/atn.md index 7570d8a0e8..35a99a4ef5 100644 --- a/docs/atn.md +++ b/docs/atn.md @@ -486,6 +486,9 @@ This is another implemented subset of #10723, not support for its remaining even - Close without `Svng` preserves the unanswered save choice. Headless playback refuses to discard a changed document. Native `file.close` still defaults to discard; `save: "ask"` opts into this policy. - Photo Filter converts recorded Lab colours through `craft-cms`. +- Black & White exports store coefficients as signed 32-bit integers. Strict export refuses + fractional coefficients; `skipUnsupported:true` reports the omitted step. Native commands + retain fractional coefficients. - Direct Vibrance and Gradient Map save as the string events `vibrance` and `gradientMapEvent`. Stroke Outside uses `StrL.Otsd`, group Pass Through uses `BlnM.passThrough`, Canvas Size extension colours use `FrgC` and `Clr `, and Absolute Colorimetric intent uses `Inte.AClr`.