mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Color Sampler: Bitmap and Multichannel documents keep the Point Sample readout (CodeRabbit review on crates/engine/src/cmd/sampler_cmds.rs:37-40)
#11732 did not measure these two modes, so they keep today's behaviour at every Sample Size.
This commit is contained in:
1 parent
590d0ffecb
commit
ec8b24cebc
2 files changed
+24
-1
No files matched your search
@@ -37,8 +37,10 @@ pub fn device_cmyk(r: f32, g: f32, b: f32) -> [i32; 4] {
|
||||
/// colour-managed CMYK percentages (the document's CMYK profile when it has one), averaged over
|
||||
/// the `size` × `size` box of document pixels centred on it (#11732: the Sample Size the Color
|
||||
/// Sampler shares with the Eyedropper; 1 is Point Sample). The box is in document pixels, so the
|
||||
/// zoom never changes it.
|
||||
/// zoom never changes it. Bitmap and Multichannel documents were not measured, so they keep the
|
||||
/// Point Sample reading at every size.
|
||||
pub fn readout(doc: &Document, pos: [f64; 2], size: u32) -> ([i32; 3], [i32; 4]) {
|
||||
let size = if matches!(doc.mode, photocraft_color::ColorMode::Bitmap | photocraft_color::ColorMode::Multichannel) { 1 } else { size };
|
||||
let rgba = crate::sample_cmds::sample_color(doc, None, pos[0], pos[1], size, crate::sample_cmds::SampleLayers::All);
|
||||
let q = |v: f32| (v.clamp(0.0, 1.0) * 255.0).round() as i32;
|
||||
let cmyk = photocraft_color::convert::with_cmyk_space(photocraft_compose::cmyk_space(doc).as_ref(), || device_cmyk(rgba[0], rgba[1], rgba[2]));
|
||||
|
||||
@@ -101,3 +101,24 @@ fn a_bad_size_is_an_error_not_a_panic() {
|
||||
}
|
||||
assert_eq!(s.active().unwrap().color_samplers.len(), 1, "a refused add adds nothing");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bitmap_and_multichannel_documents_keep_the_point_readout_at_every_size() {
|
||||
// #11732 did not measure these two modes, so they keep today's behaviour: a Point Sample
|
||||
// reading, whatever Sample Size the Color Sampler and the Eyedropper share.
|
||||
for mode in [photocraft_color::ColorMode::Bitmap, photocraft_color::ColorMode::Multichannel] {
|
||||
let mut s = stripes();
|
||||
s.edit("mode", |doc, _| {
|
||||
doc.mode = mode;
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
s.execute("view.colorSamplers.add", json!({"x": 352, "y": 150})).unwrap();
|
||||
for (size, _) in MEASURED {
|
||||
let l = s.execute("view.colorSamplers.list", json!({"size": size})).unwrap();
|
||||
assert_eq!(l["samplers"][0]["rgb"], json!([255, 255, 255]), "{mode:?} at {size} by {size}");
|
||||
}
|
||||
let r = s.execute("view.colorSamplers.add", json!({"x": 352, "y": 150, "size": 3})).unwrap();
|
||||
assert_eq!(r["point"]["rgb"], json!([255, 255, 255]), "{mode:?}: add reports the point readout");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user