From 0d9e6995727b54c7d6bed753220483af9d1fbc42 Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Thu, 5 Nov 2026 20:13:07 +0100 Subject: [PATCH 1/3] fix(atn): refuse lossy Black & White coefficients Use the existing ExactLong mapping for all six Black & White coefficients so strict ATN export reports fractions it cannot preserve. Whole coefficients and native edits retain their existing behavior. --- crates/engine/src/cmd/atn_cmds/adjustments.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/engine/src/cmd/atn_cmds/adjustments.rs b/crates/engine/src/cmd/atn_cmds/adjustments.rs index 383b0b6267..39454e94d6 100644 --- a/crates/engine/src/cmd/atn_cmds/adjustments.rs +++ b/crates/engine/src/cmd/atn_cmds/adjustments.rs @@ -240,12 +240,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), ]; From ec143207512e83d6def0d875264a98a43910df69 Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Thu, 5 Nov 2026 20:14:20 +0100 Subject: [PATCH 2/3] test(atn): cover exact Black & White coefficients Cover all six fractional coefficients through new, direct and existing adjustment exports, strict refusal and explicit skipping, whole-number/tint controls, and native 8/16/32-bit pixel differences. The regression fails on upstream before the six field mappings change; all 234 ATN tests and 2,985 engine unit tests pass with the fix. --- crates/engine/src/cmd/atn_cmds/tests.rs | 66 +++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/crates/engine/src/cmd/atn_cmds/tests.rs b/crates/engine/src/cmd/atn_cmds/tests.rs index b7c3764346..c2e3c564d0 100644 --- a/crates/engine/src/cmd/atn_cmds/tests.rs +++ b/crates/engine/src/cmd/atn_cmds/tests.rs @@ -2362,6 +2362,72 @@ fn black_white_adjustment_layer_saves_as_photoshops_class_and_old_class_still_im assert_eq!(t.actions.list[0].steps[1].1["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] From 1f22e5e6e2bcb7e7ab6b8ced7c18e3a04ac10485 Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Thu, 5 Nov 2026 20:15:40 +0100 Subject: [PATCH 3/3] docs(atn): explain fractional Black & White refusal Document integer ATN coefficient storage, strict refusal and explicit skip reporting while native Black & White commands retain fractional coefficients. --- docs/atn.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/atn.md b/docs/atn.md index 0e72430eeb..b9f900afaf 100644 --- a/docs/atn.md +++ b/docs/atn.md @@ -372,6 +372,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 `photocraft-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`.