From 86d27993eec989186d827a683438a5baf9338468 Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Sat, 14 Nov 2026 08:31:51 +0100 Subject: [PATCH 1/2] Assign Profile: greyed for Lab, Bitmap and Multichannel documents (#14238) edit.assignProfile now has its own enabled check: disabled with no document and for Lab, Bitmap and Multichannel documents, so the menu item is greyed and a scripted run fails with "not available in mode". RGB, CMYK, Grayscale, Indexed and Duotone (not measured) keep today's behaviour, and Convert to Profile keeps has_doc, so it stays enabled for Lab. The convert_profile_options helper no longer assigns lab-d50 to its Lab document, which is now refused. Fixes #14238 --- .../cmd/assign_profile_enabled_modes_tests.rs | 108 ++++++++++++++++++ crates/engine/src/cmd/color_cmds.rs | 20 +++- .../engine/tests/convert_profile_options.rs | 11 +- 3 files changed, 134 insertions(+), 5 deletions(-) create mode 100644 crates/engine/src/cmd/assign_profile_enabled_modes_tests.rs diff --git a/crates/engine/src/cmd/assign_profile_enabled_modes_tests.rs b/crates/engine/src/cmd/assign_profile_enabled_modes_tests.rs new file mode 100644 index 0000000000..2cf85f105c --- /dev/null +++ b/crates/engine/src/cmd/assign_profile_enabled_modes_tests.rs @@ -0,0 +1,108 @@ +//! Edit > Assign Profile's enabled state per colour mode, measured against the reference +//! application (#14238). +//! +//! The reference greys Assign Profile for Lab, Bitmap and Multichannel documents and with no +//! document open, and a script that runs it there fails. It stays enabled for RGB, CMYK, +//! Grayscale and Indexed documents at every depth, and Convert to Profile stays enabled for Lab. +//! Duotone is *not measured* and keeps today's behaviour (enabled). + +use super::*; + +const CMD: &str = "edit.assignProfile"; + +/// A white document of `mode` (as `file.new` names it) at `depth` bits. +fn session(mode: &str, depth: u32) -> Session { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 8, "height": 8, "mode": mode, "depth": depth, "background": "white"})).unwrap(); + s +} + +fn mode(s: &Session) -> ColorMode { + s.active().unwrap().doc.mode +} + +/// Greyed, and a scripted run is refused without touching the document's profile. +fn assert_refused(s: &mut Session, what: &str) { + assert!(!s.is_enabled(CMD), "{what}: Assign Profile is greyed"); + let before = s.active().map(|st| st.doc.icc_profile.clone()); + let e = s.execute(CMD, json!({"profile": "none"})).unwrap_err(); + assert!(matches!(e, EngineError::Disabled(..)), "{what}: {e}"); + assert_eq!(s.active().map(|st| st.doc.icc_profile.clone()), before, "{what}: profile unchanged"); +} + +#[test] +fn no_document_greys_it_out() { + assert_refused(&mut Session::new(), "no document"); +} + +#[test] +fn lab_greys_assign_but_not_convert() { + for depth in [8, 16] { + let mut s = session("lab", depth); + assert_eq!(mode(&s), ColorMode::Lab); + assert_refused(&mut s, &format!("Lab {depth}-bit")); + let e = s.execute(CMD, json!({"profile": "lab-d50"})).unwrap_err(); + assert!(e.to_string().contains("Lab mode"), "the reason names the mode: {e}"); + assert!(s.is_enabled("edit.convertToProfile"), "Lab {depth}-bit: Convert to Profile stays enabled"); + } +} + +#[test] +fn bitmap_greys_it_out() { + let mut s = session("gray", 8); + s.execute("image.mode.bitmap", json!({"method": "threshold"})).unwrap(); + assert_eq!(mode(&s), ColorMode::Bitmap); + assert_refused(&mut s, "Bitmap"); +} + +#[test] +fn multichannel_greys_it_out() { + let mut s = session("rgb", 8); + s.execute("image.mode.multichannel", json!({})).unwrap(); + assert_eq!(mode(&s), ColorMode::Multichannel); + assert_refused(&mut s, "Multichannel"); +} + +#[test] +fn leaving_lab_enables_it_again() { + let mut s = session("rgb", 8); + s.execute("image.mode.lab", json!({})).unwrap(); + assert!(!s.is_enabled(CMD), "Lab"); + s.execute("edit.undo", json!({})).unwrap(); + assert_eq!(mode(&s), ColorMode::Rgb); + assert!(s.is_enabled(CMD), "back in RGB"); +} + +#[test] +fn rgb_cmyk_and_grayscale_stay_enabled_at_every_depth() { + for (name, profile) in [("rgb", "display-p3"), ("cmyk", "coated-cmyk"), ("gray", "sgray")] { + for depth in [8, 16, 32] { + let mut s = session(name, depth); + assert!(s.is_enabled(CMD), "{name} {depth}-bit"); + s.execute(CMD, json!({"profile": profile})).unwrap(); + assert!(s.active().unwrap().doc.icc_profile.is_some(), "{name} {depth}-bit: assigned"); + s.execute(CMD, json!({"profile": "none"})).unwrap(); + assert!(s.active().unwrap().doc.icc_profile.is_none(), "{name} {depth}-bit: none"); + } + } +} + +#[test] +fn indexed_stays_enabled() { + let mut s = session("rgb", 8); + s.execute("image.mode.indexedColor", json!({"palette": "exact", "forced": "none", "dither": "none", "transparency": false})).unwrap(); + assert_eq!(mode(&s), ColorMode::Indexed); + assert!(s.is_enabled(CMD), "Indexed"); + s.execute(CMD, json!({"profile": "display-p3"})).unwrap(); + assert!(s.active().unwrap().doc.icc_profile.is_some(), "Indexed: assigned"); +} + +/// Duotone is not measured: it keeps today's behaviour, enabled with Gray profiles. +#[test] +fn duotone_keeps_todays_behaviour() { + let mut s = session("gray", 8); + s.execute("image.mode.duotone", json!({"type": "monotone"})).unwrap(); + assert_eq!(mode(&s), ColorMode::Duotone); + assert!(s.is_enabled(CMD), "Duotone"); + s.execute(CMD, json!({"profile": "sgray"})).unwrap(); +} diff --git a/crates/engine/src/cmd/color_cmds.rs b/crates/engine/src/cmd/color_cmds.rs index 3f4cfa0083..716da584b8 100644 --- a/crates/engine/src/cmd/color_cmds.rs +++ b/crates/engine/src/cmd/color_cmds.rs @@ -1005,6 +1005,20 @@ fn has_doc(s: &Session) -> std::result::Result<(), String> { s.active().map(|_| ()).ok_or_else(|| "no document open".into()) } +/// Assign Profile is greyed for Lab, Bitmap and Multichannel documents, as in the reference +/// application, and a script that runs it there fails (#14238). Convert to Profile keeps +/// [`has_doc`]: it stays enabled for Lab. +fn assign_profile_enabled(s: &Session) -> std::result::Result<(), String> { + let doc = &s.active().ok_or_else(|| "no document open".to_string())?.doc; + let mode = match doc.mode { + ColorMode::Lab => "Lab", + ColorMode::Bitmap => "Bitmap", + ColorMode::Multichannel => "Multichannel", + _ => return Ok(()), + }; + Err(format!("not available in {mode} mode")) +} + fn always(_: &Session) -> std::result::Result<(), String> { Ok(()) } @@ -1335,7 +1349,7 @@ pub fn specs() -> Vec { "Assign Profile…", ["Edit"], r##"{"profile":"working|srgb|display-p3|adobe-rgb-compat|prophoto-compat|linear-srgb|rec2020|gray-gamma-2.2|sgray|dot-gain-20-compat|lab-d50|coated-cmyk|none" (or a path to an .icc file)}"##, - has_doc, + assign_profile_enabled, assign_profile, true ), @@ -1652,6 +1666,10 @@ mod tests { } } +#[cfg(test)] +#[path = "assign_profile_enabled_modes_tests.rs"] +mod assign_profile_enabled_modes_tests; + #[cfg(test)] mod settings_tests { use super::*; diff --git a/crates/engine/tests/convert_profile_options.rs b/crates/engine/tests/convert_profile_options.rs index 31566d3d09..ad28e2d2d5 100644 --- a/crates/engine/tests/convert_profile_options.rs +++ b/crates/engine/tests/convert_profile_options.rs @@ -31,12 +31,15 @@ fn layered(depth: u32, mode: &str) -> Session { Ok(()) }) .unwrap(); + // Assign Profile is greyed for Lab documents (#14238), which are device-independent anyway. let profile = match mode { - "cmyk" => "coated-cmyk", - "lab" => "lab-d50", - _ => "srgb", + "cmyk" => Some("coated-cmyk"), + "lab" => None, + _ => Some("srgb"), }; - s.execute("edit.assignProfile", json!({"profile": profile})).unwrap(); + if let Some(profile) = profile { + s.execute("edit.assignProfile", json!({"profile": profile})).unwrap(); + } s } From a381df1a244751131f824586508493dc35f2ebff Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Sat, 14 Nov 2026 20:53:15 +0100 Subject: [PATCH 2/2] Assign Profile tests: tag the Lab document before the refusal check (#14238) file.new leaves a Lab document untagged, so the profile-unchanged check compared None with None. Tag it with Lab D50 first, so a refusal that cleared the profile would fail. --- crates/engine/src/cmd/assign_profile_enabled_modes_tests.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/engine/src/cmd/assign_profile_enabled_modes_tests.rs b/crates/engine/src/cmd/assign_profile_enabled_modes_tests.rs index 2cf85f105c..190be4a1bf 100644 --- a/crates/engine/src/cmd/assign_profile_enabled_modes_tests.rs +++ b/crates/engine/src/cmd/assign_profile_enabled_modes_tests.rs @@ -40,6 +40,8 @@ fn lab_greys_assign_but_not_convert() { for depth in [8, 16] { let mut s = session("lab", depth); assert_eq!(mode(&s), ColorMode::Lab); + // `file.new` leaves Lab untagged; tag it, so "profile unchanged" compares a real profile. + std::sync::Arc::make_mut(&mut s.active_mut().unwrap().doc).icc_profile = Some(Builtin::LabD50.profile().to_bytes()); assert_refused(&mut s, &format!("Lab {depth}-bit")); let e = s.execute(CMD, json!({"profile": "lab-d50"})).unwrap_err(); assert!(e.to_string().contains("Lab mode"), "the reason names the mode: {e}");