Merge branch 'bb-epic-crop-mx5bund6' of github.com:storytold/photocraft into bb-epic-crop-mx5bund6--17677-crop-indexed-palette

# Conflicts:
#	crates/engine-core/src/cmd/image_cmds.rs
This commit is contained in:
David Mann committed 2026-12-02 05:25:35 +01:00
commit cbfbb56c8f
2 files changed
+73

No files matched your search

@@ -0,0 +1,69 @@
//! The area an expanding or turned crop adds to a Multichannel document, measured against the reference
//! application (#17680): no ink in every channel (255 there, density 0 here), whatever the background colour.
use super::*;
/// A 40 x 30 RGB document at `depth`, black all over (full ink once converted), turned into Multichannel
/// (Cyan, Magenta, Yellow), with `background` as the background colour.
fn session(depth: u32, background: [f32; 4]) -> Session {
let mut s = crate::session();
s.execute("file.new", json!({"width": 40, "height": 30, "mode": "rgb", "depth": depth, "background": "white"})).unwrap();
s.edit("paint", |doc, _| {
let surface = doc.background_mut().unwrap().surface_mut().unwrap();
let mut px = vec![0.0; surface.channels()];
if let Some(alpha) = px.get_mut(3) {
*alpha = 1.0;
}
surface.fill_rect(Rect::new(0, 0, 40, 30), &px);
Ok(())
})
.unwrap();
s.execute("image.mode.multichannel", json!({})).unwrap();
assert_eq!(s.active().unwrap().doc.mode, ColorMode::Multichannel);
s.tools.background = background;
s
}
const MAGENTA: [f32; 4] = [1.0, 0.0, 1.0, 1.0];
const WHITE: [f32; 4] = [1.0, 1.0, 1.0, 1.0];
/// The channels' names and their ink density at (`x`, `y`).
fn inks(s: &Session, x: i32, y: i32) -> Vec<(String, f32)> {
s.active().unwrap().doc.channels.iter().map(|c| (c.name.clone(), c.surface.pixel(x, y)[0])).collect()
}
fn names(s: &Session) -> Vec<String> {
s.active().unwrap().doc.channels.iter().map(|c| c.name.clone()).collect()
}
#[test]
fn expanding_and_turned_crops_add_no_ink_whatever_the_background_colour() {
for depth in [8, 16] {
for background in [MAGENTA, WHITE] {
for delete in [true, false] {
for angle in [None, Some(15.0)] {
let what = format!("{depth}-bit, background {background:?}, delete {delete}, angle {angle:?}");
let mut s = session(depth, background);
let before_names = names(&s);
let before = s.active().unwrap().history.entries().len();
let mut p = json!({"x": -6, "y": -6, "width": 52, "height": 42, "deleteCroppedPixels": delete});
if let Some(a) = angle {
p["angle"] = json!(a);
}
s.execute("image.crop", p).unwrap();
// The added corner holds no ink; the old image still holds its ink.
for (name, ink) in inks(&s, 0, 0) {
assert_eq!(ink, 0.0, "{name} in the added corner, {what}");
}
for (name, ink) in inks(&s, 26, 21) {
assert!(ink > 0.5, "{name} in the old image keeps its ink ({ink}), {what}");
}
assert_eq!(names(&s), before_names, "{what}");
let entries = s.active().unwrap().history.entries();
assert_eq!(entries.len(), before + 1, "{what}");
assert_eq!(entries.last().map(String::as_str), Some("Crop"), "{what}");
}
}
}
}
}
+4
View File
@@ -1548,6 +1548,10 @@ mod crop_delete_forced_modes_tests;
#[path = "crop_bitmap_fill_tests.rs"]
mod crop_bitmap_fill_tests;
#[cfg(test)]
#[path = "crop_multichannel_fill_tests.rs"]
mod crop_multichannel_fill_tests;
#[cfg(test)]
#[path = "crop_indexed_palette_tests.rs"]
mod crop_indexed_palette_tests;