From ba4a5db41c27f3cb2af7e06d4f3d85972eec266b Mon Sep 17 00:00:00 2001 From: Khawar Zamman Wani Date: Tue, 17 Nov 2026 15:16:34 +0530 Subject: [PATCH 1/2] Convert to Profile: sRGB to Coated FOGRA39 gives the reference inks (#14267) Picks up storytold/craft-libs#2028: the built-in Coated FOGRA39 profile maps out-of-gamut colours in Oklab, generates black along a measured curve, and has its own Saturation table. sRGB red, blue and grey now separate within 2.2 % per ink of the reference application for every intent, and Perceptual and Saturation differ. Fixes #14267 --- Cargo.lock | 2 +- Cargo.toml | 2 +- crates/engine/src/cmd/color_cmds.rs | 2 + .../convert_profile_fogra39_tests.rs | 49 +++++++++++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 crates/engine/src/cmd/color_cmds/convert_profile_fogra39_tests.rs diff --git a/Cargo.lock b/Cargo.lock index 37a1a28f3a..5d03cb1da7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1352,7 +1352,7 @@ dependencies = [ [[package]] name = "craft-cms" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=c6eb84d427d81b6d64207654c8ee0516cd3d7324#c6eb84d427d81b6d64207654c8ee0516cd3d7324" +source = "git+https://github.com/storytold/craft-libs?rev=20a6279f2d53481af09ff62f9a5e78fad46fec55#20a6279f2d53481af09ff62f9a5e78fad46fec55" dependencies = [ "md-5", "rayon", diff --git a/Cargo.toml b/Cargo.toml index fbf01b73dc..07b20f85da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,7 @@ photocraft-ipp = { path = "crates/ipp" } # external # ICC colour management: the shared crate (replaces crates/cms; craft-libs#779). -craft-cms = { git = "https://github.com/storytold/craft-libs", rev = "c6eb84d427d81b6d64207654c8ee0516cd3d7324" } +craft-cms = { git = "https://github.com/storytold/craft-libs", rev = "20a6279f2d53481af09ff62f9a5e78fad46fec55" } craft-print = { git = "https://github.com/storytold/craft-libs", rev = "fe6b443acf3eccaf514064812e6e6bf24257652a" } # HEIC/HEIF: the shared decoder (replaces crates/heif; craft-libs#784). craft-heif = { git = "https://github.com/storytold/craft-libs", rev = "fe6b443acf3eccaf514064812e6e6bf24257652a" } diff --git a/crates/engine/src/cmd/color_cmds.rs b/crates/engine/src/cmd/color_cmds.rs index 96fe367ea4..3f03d068cc 100644 --- a/crates/engine/src/cmd/color_cmds.rs +++ b/crates/engine/src/cmd/color_cmds.rs @@ -23,6 +23,8 @@ use serde_json::{Value, json}; use crate::commands::CommandSpec; use crate::{EngineError, Result, Session}; +#[cfg(test)] +mod convert_profile_fogra39_tests; #[cfg(test)] mod convert_profile_same_tests; mod profile_dither; diff --git a/crates/engine/src/cmd/color_cmds/convert_profile_fogra39_tests.rs b/crates/engine/src/cmd/color_cmds/convert_profile_fogra39_tests.rs new file mode 100644 index 0000000000..56e0836250 --- /dev/null +++ b/crates/engine/src/cmd/color_cmds/convert_profile_fogra39_tests.rs @@ -0,0 +1,49 @@ +//! #14267: Convert to Profile from sRGB to the built-in Coated FOGRA39 gives the reference +//! application's inks for each intent, and Perceptual and Saturation separate differently. + +use super::*; + +/// Inks (CMYK %) the reference application gives for an sRGB patch, per intent: relative + +/// BPC, relative, perceptual, saturation, absolute (Convert to Profile, dither on). +const REFERENCE: [(&str, [[f32; 4]; 5]); 3] = [ + ("#c81e1e", [[14.5, 97.7, 95.3, 4.3], [13.3, 100.0, 100.0, 5.5], [18.0, 96.9, 92.9, 8.6], [14.9, 100.0, 100.0, 5.9], [8.6, 100.0, 100.0, 2.4]]), + ("#1e3cc8", [[91.8, 75.3, 0.0, 0.0], [94.5, 76.5, 0.0, 0.0], [94.5, 77.7, 0.0, 0.0], [93.7, 76.9, 0.0, 0.0], [92.6, 74.9, 0.0, 0.0]]), + ("#808080", [[49.0, 38.4, 38.4, 20.0], [49.8, 39.2, 38.8, 21.2], [49.0, 38.4, 38.4, 20.0], [49.0, 38.4, 38.4, 20.0], [46.7, 36.9, 38.4, 18.4]]), +]; + +const INTENTS: [(&str, bool); 5] = [("relative", true), ("relative", false), ("perceptual", true), ("saturation", true), ("absolute", false)]; + +/// The inks of an 8-bit sRGB document filled with `background`, converted to Coated FOGRA39. +fn separate(background: &str, intent: &str, bpc: bool) -> [f32; 4] { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 8, "height": 8, "background": background})).unwrap(); + s.execute("edit.assignProfile", json!({"profile": "srgb"})).unwrap(); + s.execute("edit.convertToProfile", json!({"profile": "coated-fogra39", "intent": intent, "bpc": bpc, "dither": false})).unwrap(); + let doc = &s.active().unwrap().doc; + assert_eq!(doc.mode, ColorMode::Cmyk); + let px = doc.layers[0].surface().unwrap().pixel(4, 4); + [px[0], px[1], px[2], px[3]].map(|v| v * 100.0) +} + +/// Within 2.5 % per ink: most land within 2 %; red at the magenta–yellow edge falls between +/// clipped and unclipped nodes of the profile's tables, which costs up to 2.2 %. +#[test] +fn srgb_to_fogra39_matches_the_reference_inks() { + let mut worst = (0.0f32, String::new()); + for (background, want) in REFERENCE { + for ((intent, bpc), want) in INTENTS.into_iter().zip(want) { + let got = separate(background, intent, bpc); + let diff = (0..4).map(|i| (got[i] - want[i]).abs()).fold(0.0f32, f32::max); + if diff > worst.0 { + worst = (diff, format!("{background} {intent} bpc {bpc}: {got:.1?}, reference {want:?}")); + } + } + } + assert!(worst.0 <= 2.5, "{} (max {:.1})", worst.1, worst.0); +} + +#[test] +fn perceptual_and_saturation_separate_differently() { + let (perceptual, saturation) = (separate("#c81e1e", "perceptual", true), separate("#c81e1e", "saturation", true)); + assert!(saturation[1] > perceptual[1] + 1.0 && saturation[2] > perceptual[2] + 1.0, "perceptual {perceptual:?}, saturation {saturation:?}"); +} From 4f3b6ba6c9deac5e97fcc994c367e5df6a9bedd6 Mon Sep 17 00:00:00 2001 From: Khawar Zamman Wani Date: Thu, 19 Nov 2026 20:28:46 +0530 Subject: [PATCH 2/2] Convert to Profile FOGRA39 test: 2 % per ink, 2.5 % only for Saturation red; a NaN ink fails (#14267) --- .../color_cmds/convert_profile_fogra39_tests.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/crates/engine/src/cmd/color_cmds/convert_profile_fogra39_tests.rs b/crates/engine/src/cmd/color_cmds/convert_profile_fogra39_tests.rs index 56e0836250..b1965e1c42 100644 --- a/crates/engine/src/cmd/color_cmds/convert_profile_fogra39_tests.rs +++ b/crates/engine/src/cmd/color_cmds/convert_profile_fogra39_tests.rs @@ -25,21 +25,23 @@ fn separate(background: &str, intent: &str, bpc: bool) -> [f32; 4] { [px[0], px[1], px[2], px[3]].map(|v| v * 100.0) } -/// Within 2.5 % per ink: most land within 2 %; red at the magenta–yellow edge falls between -/// clipped and unclipped nodes of the profile's tables, which costs up to 2.2 %. +/// Within 2 % per ink, except Saturation red: that patch lies between nodes of the profile's +/// table that are clipped to the magenta–yellow edge and nodes that are not, which costs 2.2 % +/// (a finer table closes it, at three times the profile size). It is held to 2.5 %. #[test] fn srgb_to_fogra39_matches_the_reference_inks() { - let mut worst = (0.0f32, String::new()); + let mut failures = Vec::new(); for (background, want) in REFERENCE { for ((intent, bpc), want) in INTENTS.into_iter().zip(want) { let got = separate(background, intent, bpc); - let diff = (0..4).map(|i| (got[i] - want[i]).abs()).fold(0.0f32, f32::max); - if diff > worst.0 { - worst = (diff, format!("{background} {intent} bpc {bpc}: {got:.1?}, reference {want:?}")); + let limit = if (background, intent) == ("#c81e1e", "saturation") { 2.5 } else { 2.0 }; + // A NaN ink compares false with `>`, so it is failed explicitly. + if (0..4).any(|i| (got[i] - want[i]).abs().is_nan() || (got[i] - want[i]).abs() > limit) { + failures.push(format!("{background} {intent} bpc {bpc}: {got:.1?}, reference {want:?}, limit {limit}")); } } } - assert!(worst.0 <= 2.5, "{} (max {:.1})", worst.1, worst.0); + assert!(failures.is_empty(), "{failures:#?}"); } #[test]