diff --git a/crates/engine-core/src/cmd/selection_cmds.rs b/crates/engine-core/src/cmd/selection_cmds.rs index d173edc50dc..c5338d76749 100644 --- a/crates/engine-core/src/cmd/selection_cmds.rs +++ b/crates/engine-core/src/cmd/selection_cmds.rs @@ -170,10 +170,12 @@ fn parse_color(p: &Value) -> [f32; 3] { } } -/// Composite RGB (the compositor's output profile for the document) → CIE Lab D50. +/// Composite RGB (the profile the session shows the document's composite in) → CIE Lab D50. fn lab_transform(s: &Session) -> Result> { let d = s.active().ok_or(EngineError::NoDocument)?; - let src = crate::color_cmds::composite_profile(&d.doc); + // An untagged document's composite is the working space (#14224), so the hue rows and the + // sampled colours select what the canvas actually shows. + let src = s.color().composite_profile(&d.doc); craft_cms::cached(&src, craft_cms::Builtin::LabD50.profile(), craft_cms::TransformOptions::default()) .map_err(|e| EngineError::Other(format!("colour management: {e}"))) } diff --git a/crates/engine-core/src/color_settings_untagged_display_tests.rs b/crates/engine-core/src/color_settings_untagged_display_tests.rs index 7760508dc50..d674af69544 100644 --- a/crates/engine-core/src/color_settings_untagged_display_tests.rs +++ b/crates/engine-core/src/color_settings_untagged_display_tests.rs @@ -397,6 +397,27 @@ fn an_untagged_indexed_document_follows_the_mode_default_until_it_becomes_rgb() assert_eq!(reported(&mut s)["description"], s.color().working(ColorMode::Rgb).description, "and Profile Info agrees"); } +#[test] +fn colour_range_judges_sampled_colours_in_the_space_the_canvas_shows() { + let mut s = crate::session(); + // A box spanned by two sampled colours and a ramp of columns across it. Membership is decided in + // Lab, through the profile the composite is read in, so once the working space moves the box has + // to move with the picture: with the ramp below one column drops out going from sRGB to + // ProPhoto, and none of this changes at the default setting. + let columns: Vec<[f32; 3]> = (0..8).map(|i| [0.55 + 0.03 * i as f32, 0.45 - 0.03 * i as f32, 0.45 - 0.02 * i as f32]).collect(); + s.open_document(untagged_rgb(&columns, SampleType::U8), None); + let marked = |s: &mut Session| -> Vec { + s.execute("select.colorRange", json!({"select": "sampledColors", "colors": ["#cc4d4d", "#996666"], "fuzziness": 40})).unwrap(); + let doc = s.active().unwrap().doc.clone(); + let selection = doc.selection.clone().expect("a selection was set"); + (0..columns.len()).filter(|i| selection.pixel(*i as i32 * 4 + 2, 2)[0] > 0.5).collect() + }; + let as_built_in = marked(&mut s); + s.execute("edit.colorSettings", json!({"workingRgb": "prophoto-compat"})).unwrap(); + let as_working = marked(&mut s); + assert_ne!(as_built_in, as_working, "the sampled colour box marked the same columns whatever the working space: {as_built_in:?} vs {as_working:?}"); +} + #[test] fn the_profile_commands_answer_the_same_for_a_tagged_document() { let mut replies = Vec::new();