Grayscale swatch through sGray, as agreed on the PR (#11940)

The reference's Eraser paints 173 for background RGB 0,200,0 in a Grayscale
document; the document's Dot Gain curve gives 153, so swatch_in_doc now
converts through the sRGB tone curve (sGray, 172-173) instead. Pixel
conversions keep the document's profile. The two Grayscale tests are no
longer ignored, and eraser_locked's Gray case checks the sGray value, since
the Brush's own conversion into Gray (not measured) is unchanged.
This commit is contained in:
Hector Villarreal committed 2026-11-10 08:37:07 -06:00
1 parent 515e1d660e
commit 7b20000052
3 files changed
+25 -16

No files matched your search

+11 -7
View File
@@ -561,16 +561,20 @@ pub fn document_profile(doc: &Document) -> Arc<Profile> {
}
/// A swatch colour (straight RGB in the RGB working space, as the foreground and background hold
/// it) as the active document takes it. In a Grayscale document that is the colour's gray in the
/// document's gray profile, through `photocraft-cms` (relative colorimetric with black point
/// compensation, Photoshop's default), returned as equal R, G and B so the pixel conversion keeps
/// it: RGB 0,200,0 becomes gray 153 with the default Dot Gain 20%-compatible profile, not its
/// Rec.601 luma 117 (#11940; the reference measures 173, an open question on the issue). Other
/// it) as the active document takes it. In a Grayscale document that is the colour's gray with the
/// sRGB tone curve (sGray), through `photocraft-cms` (relative colorimetric with black point
/// compensation), returned as equal R, G and B so the pixel conversion keeps it: RGB 0,200,0
/// becomes gray 172, as the reference paints it (173, measured), not its Rec.601 luma 117 (#11940).
/// The reference's swatch conversion doesn't follow the document's Dot Gain curve (that gives 153),
/// so pixel conversions such as Image › Mode › Grayscale keep using the document's profile. Other
/// modes, and a failed conversion, keep the colour.
pub fn swatch_in_doc(s: &Session, c: [f32; 4]) -> [f32; 4] {
let Some(st) = s.active().filter(|st| st.doc.mode == ColorMode::Grayscale) else { return c };
if s.active().is_none_or(|st| st.doc.mode != ColorMode::Grayscale) {
return c;
}
let opts = photocraft_cms::TransformOptions { intent: Intent::RelativeColorimetric, bpc: true, ..Default::default() };
let Ok(t) = photocraft_cms::cached(&working_profile(ColorMode::Rgb), &document_profile(&st.doc), opts) else { return c };
let sgray = Arc::new(Builtin::SGray.profile().clone());
let Ok(t) = photocraft_cms::cached(&working_profile(ColorMode::Rgb), &sgray, opts) else { return c };
let mut out = [0.0f32; 16];
t.eval(&[c[0], c[1], c[2]], &mut out);
let g = out[0];
@@ -1,7 +1,7 @@
//! On a Grayscale document's Background, the Eraser and Edit › Fill with the background colour
//! paint that colour's grey as the reference converts it: RGB 0, 200, 0 gives 173, not its 117
//! luminance (#11940). Converting through the document's grey profile gives 153, so the two
//! Grayscale tests are ignored until the issue says which conversion the swatch uses.
//! luminance (#11940). The swatch goes through the sRGB tone curve (sGray), not the document's Dot
//! Gain curve, which would give 153.
use crate::Session;
use serde_json::json;
@@ -30,7 +30,6 @@ fn erase_at(s: &mut Session, x: i32, y: i32) {
}
#[test]
#[ignore = "#11940: the grey profile gives 153 for RGB 0,200,0; the issue measures 173. Waiting on which conversion the swatch should use"]
fn the_eraser_on_a_gray_background_paints_the_background_colours_gray() {
let mut s = session("grayscale");
erase_at(&mut s, 20, 16);
@@ -42,7 +41,6 @@ fn the_eraser_on_a_gray_background_paints_the_background_colours_gray() {
}
#[test]
#[ignore = "#11940: the grey profile gives 153 for RGB 0,200,0; the issue measures 173. Waiting on which conversion the swatch should use"]
fn edit_fill_with_the_background_colour_gives_the_same_gray() {
let mut s = session("grayscale");
s.execute("edit.fill", json!({"contents": "background"})).unwrap();
+12 -5
View File
@@ -43,11 +43,18 @@ fn eraser_on_background_paints_background_colour_at_every_depth_and_mode() {
erase(&mut s, json!({})).unwrap_or_else(|e| panic!("{mode}/{depth}: {e}"));
let got = layer_px(&s, 20, 10);
assert_eq!(got[3], 1.0, "{mode}/{depth}: the Background stays opaque");
// Exactly what the Brush paints with the background colour (CMYK and Gray documents
// hold the colour converted into their mode).
let mut brush = doc(mode, depth);
brush.execute("paint.stroke", json!({"points": [[2, 10], [38, 10]], "size": 8, "hardness": 1.0, "color": "#ff0000"})).unwrap();
assert!(close(got, layer_px(&brush, 20, 10)), "{mode}/{depth}: got {got:?}");
if mode == "gray" {
// A Gray document takes the background swatch through the sRGB tone curve, as the
// reference's Eraser paints it (#11940): pure red is grey 130. The Brush's own
// conversion of a colour into Gray was not measured and stays as it was.
assert!(close(got, [0.51, 0.51, 0.51, 1.0]), "{mode}/{depth}: got {got:?}");
} else {
// Exactly what the Brush paints with the background colour (CMYK documents hold
// the colour converted into their mode).
let mut brush = doc(mode, depth);
brush.execute("paint.stroke", json!({"points": [[2, 10], [38, 10]], "size": 8, "hardness": 1.0, "color": "#ff0000"})).unwrap();
assert!(close(got, layer_px(&brush, 20, 10)), "{mode}/{depth}: got {got:?}");
}
assert!(!close(got, before), "{mode}/{depth}: the stroke shows");
if mode == "rgb" {
assert!(close(got, [1.0, 0.0, 0.0, 1.0]), "{mode}/{depth}: got {got:?}");