mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-21 01:18:43 +00:00
test: build the CMYK test profile once, run large raw-develop sizes at one depth
- cmyk_flatten_profile: synthesise the test profile once per process and share one Arc, so CmykSpace's per-allocation cache builds the transforms once; exact() reads both rows from one run (4 documents, not 8). - camera_raw GPU tests: the 858x572 and 1600x900 comparisons run at one depth each. The depth only changes the input quantization (8 and 16 bits both develop with float = false) and every depth runs at 171x113 above. - cols_timing is a benchmark without assertions: ignore it like its siblings. - compose: delete clipped_dissolve_is_binary_and_preserves_the_base_shape, a byte-identical copy of clipped_dissolve_opacity_fill_is_binary_and_ preserves_base_shape (whose doc comment names both issues). Part of #15376. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
957b10cccb
commit
484483b691
4 files changed
+37
-53
No files matched your search
@@ -447,8 +447,9 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// `cargo test -p photocraft-algo --release --lib -- --nocapture cols_timing`
|
||||
/// `cargo test -p photocraft-algo --release --lib -- --ignored --nocapture cols_timing`
|
||||
#[test]
|
||||
#[ignore = "timing"]
|
||||
fn cols_timing() {
|
||||
for (w, h, n, r) in [(324, 324, 2, 9), (1122, 1122, 2, 79), (1122, 786, 2, 79)] {
|
||||
// Each pass gets its own copy of the same input: a pass run after the other would
|
||||
|
||||
@@ -617,35 +617,6 @@ fn clipped_dissolve_matches_whole_render_at_offset_regions_and_depths() {
|
||||
}
|
||||
}
|
||||
|
||||
/// #4921: Dissolve coverage must survive clipping and use Opacity × Fill.
|
||||
#[test]
|
||||
fn clipped_dissolve_is_binary_and_preserves_the_base_shape() {
|
||||
let mut d = doc_white(40, 12);
|
||||
d.layers.push(solid_layer("base", Rect::new(0, 0, 20, 12), [0.0, 0.0, 1.0, 1.0]));
|
||||
let mut clip = solid_layer("clip", d.bounds(), [1.0, 0.0, 0.0, 1.0]);
|
||||
clip.clipped = true;
|
||||
clip.blend = BlendMode::Dissolve;
|
||||
clip.opacity = 0.6;
|
||||
clip.fill_opacity = 0.5;
|
||||
d.layers.push(clip);
|
||||
let mut red = 0;
|
||||
let mut blue = 0;
|
||||
for y in 0..12 {
|
||||
for x in 0..20 {
|
||||
let p = px(&d, x, y);
|
||||
if close4(p, [1.0, 0.0, 0.0, 1.0]) {
|
||||
red += 1;
|
||||
} else {
|
||||
assert!(close4(p, [0.0, 0.0, 1.0, 1.0]), "Dissolve must not interpolate: {p:?} at ({x},{y})");
|
||||
blue += 1;
|
||||
}
|
||||
}
|
||||
assert!(close4(px(&d, 30, y), [1.0; 4]), "outside the base the clip is invisible");
|
||||
}
|
||||
assert!(red > 0 && blue > 0, "Dissolve must expose both source and base: {red}/{blue}");
|
||||
assert!((red as f32 / (red + blue) as f32 - 0.3).abs() < 0.1, "coverage should follow 60% opacity × 50% fill: {red}/{blue}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hidden_base_hides_clipping_group() {
|
||||
let mut d = doc_white(4, 4);
|
||||
|
||||
@@ -33,10 +33,22 @@ const INKS: [[f32; 4]; 8] = [
|
||||
[0.1, 0.0, 0.6, 0.3],
|
||||
];
|
||||
|
||||
/// The test profile, synthesised once per process. Synthesis samples and inverts whole LUTs, and
|
||||
/// `CmykSpace::for_profile` caches by allocation, so one shared `Arc` also builds the transforms
|
||||
/// once instead of for every document.
|
||||
fn profile() -> Arc<Vec<u8>> {
|
||||
craft_cms::synth::cmyk_profile(&craft_cms::synth::CmykParams { description: "Test Uncoated".into(), tvi: [0.26, 0.26, 0.26, 0.3], ..Default::default() })
|
||||
.unwrap()
|
||||
.to_bytes()
|
||||
static PROFILE: std::sync::OnceLock<Arc<Vec<u8>>> = std::sync::OnceLock::new();
|
||||
PROFILE
|
||||
.get_or_init(|| {
|
||||
craft_cms::synth::cmyk_profile(&craft_cms::synth::CmykParams {
|
||||
description: "Test Uncoated".into(),
|
||||
tvi: [0.26, 0.26, 0.26, 0.3],
|
||||
..Default::default()
|
||||
})
|
||||
.unwrap()
|
||||
.to_bytes()
|
||||
})
|
||||
.clone()
|
||||
}
|
||||
|
||||
/// A one-layer (Background) CMYK document, tagged with `profile()` when `tag`: the first row is
|
||||
@@ -85,22 +97,23 @@ fn max_diff(a: &[[f32; 4]], b: &[[f32; 4]]) -> f32 {
|
||||
a.iter().zip(b).flat_map(|(p, q)| (0..4).map(move |c| (p[c] - q[c]).abs())).fold(0.0, f32::max)
|
||||
}
|
||||
|
||||
/// Runs `run` on a document and returns how far the inks of `row` (0 = separations, 1 = any
|
||||
/// Runs `run` on a document and returns how far the inks of each row (0 = separations, 1 = any
|
||||
/// inks) moved.
|
||||
fn drift(depth: u32, tag: bool, row: usize, run: impl FnOnce(&mut Session)) -> f32 {
|
||||
fn drift(depth: u32, tag: bool, run: impl FnOnce(&mut Session)) -> [f32; 2] {
|
||||
let mut s = document(depth, tag);
|
||||
let before = inks(&s);
|
||||
run(&mut s);
|
||||
let after = inks(&s);
|
||||
let r = row * W as usize..(row + 1) * W as usize;
|
||||
max_diff(&before[r.clone()], &after[r])
|
||||
[0, 1].map(|row| {
|
||||
let r = row * W as usize..(row + 1) * W as usize;
|
||||
max_diff(&before[r.clone()], &after[r])
|
||||
})
|
||||
}
|
||||
|
||||
fn exact(what: &str, run: impl Fn(&mut Session)) {
|
||||
for depth in [8, 16] {
|
||||
for tag in [true, false] {
|
||||
for row in [0, 1] {
|
||||
let d = drift(depth, tag, row, &run);
|
||||
for (row, d) in drift(depth, tag, &run).into_iter().enumerate() {
|
||||
assert!(d == 0.0, "{depth}-bit {what} (tagged: {tag}, row {row}): inks moved by {d}");
|
||||
}
|
||||
}
|
||||
@@ -153,7 +166,7 @@ const ROUND_TRIP: f32 = 10.0 / 255.0;
|
||||
#[test]
|
||||
fn merge_down_separates_through_the_document_profile() {
|
||||
for depth in [8, 16] {
|
||||
let d = drift(depth, true, 0, |s| {
|
||||
let [d, _] = drift(depth, true, |s| {
|
||||
s.execute("layer.new.layer", json!({})).unwrap();
|
||||
s.execute("layer.mergeDown", json!({})).unwrap();
|
||||
});
|
||||
@@ -164,7 +177,7 @@ fn merge_down_separates_through_the_document_profile() {
|
||||
#[test]
|
||||
fn merge_visible_separates_through_the_document_profile() {
|
||||
for depth in [8, 16] {
|
||||
let d = drift(depth, true, 0, |s| {
|
||||
let [d, _] = drift(depth, true, |s| {
|
||||
s.execute("layer.new.layer", json!({})).unwrap();
|
||||
s.execute("layer.mergeVisible", json!({})).unwrap();
|
||||
});
|
||||
@@ -179,7 +192,7 @@ fn merge_visible_separates_through_the_document_profile() {
|
||||
#[test]
|
||||
fn rasterize_layer_style_separates_through_the_document_profile() {
|
||||
for depth in [8, 16] {
|
||||
let d = drift(depth, true, 0, |s| {
|
||||
let [d, _] = drift(depth, true, |s| {
|
||||
s.execute("layer.new.layerFromBackground", json!({})).unwrap();
|
||||
s.execute("layer.layerStyle.dropShadow", json!({"distance": 40, "size": 0})).unwrap();
|
||||
s.execute("layer.rasterize.layerStyle", json!({})).unwrap();
|
||||
|
||||
@@ -465,12 +465,12 @@ fn shadows_and_highlights_with_per_pixel_stages() {
|
||||
CameraRaw { shadows: 30.0, highlights: -30.0, whites: 40.0, blacks: -30.0, encoding_gamma: 1.8, ..Default::default() },
|
||||
],
|
||||
);
|
||||
// At the dialog's proxy size.
|
||||
// At the dialog's proxy size, at one depth: the depth only changes how the input is
|
||||
// quantized (8 and 16 bits both develop with `float = false`), and every depth already ran
|
||||
// above at 171×113. The size is what matters here (subsampled pyramid levels).
|
||||
let Some(mut g) = gpu() else { return };
|
||||
for depth in DEPTHS {
|
||||
let d = compare_at(&mut g, &all, depth, (858, 572));
|
||||
eprintln!("shadows/highlights + per pixel 858x572 {depth:?}: max |GPU - CPU| = {d:.2e}");
|
||||
}
|
||||
let d = compare_at(&mut g, &all, Depth::Sixteen, (858, 572));
|
||||
eprintln!("shadows/highlights + per pixel 858x572: max |GPU - CPU| = {d:.2e}");
|
||||
}
|
||||
|
||||
/// Asserts that each of `sets` moves some pixel of the test image by over 2 %, so a comparison
|
||||
@@ -546,12 +546,11 @@ fn clarity_texture_and_dehaze_with_shadows_highlights_and_per_pixel_stages() {
|
||||
check("clarity/texture/dehaze + shadows/highlights + per pixel", &sets);
|
||||
let Some(mut g) = gpu() else { return };
|
||||
// At the dialog's proxy size (Dehaze and Clarity on a copy subsampled twice), and wider (three
|
||||
// times).
|
||||
for size in [(858, 572), (1600, 900)] {
|
||||
for depth in DEPTHS {
|
||||
let d = compare_at(&mut g, &all, depth, size);
|
||||
eprintln!("everything {size:?} {depth:?}: max |GPU - CPU| = {d:.2e}");
|
||||
}
|
||||
// times). One depth per size: the depth only changes how the input is quantized (8 and 16
|
||||
// bits both develop with `float = false`), and every depth already ran above at 171×113.
|
||||
for (size, depth) in [((858, 572), Depth::Eight), ((1600, 900), Depth::Float)] {
|
||||
let d = compare_at(&mut g, &all, depth, size);
|
||||
eprintln!("everything {size:?} {depth:?}: max |GPU - CPU| = {d:.2e}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user