PhotoCraft: An open-source, photo editor written by scratch in pure Rust
test(engine): expect signed HDR outputs from destructive Levels
abc2cb05af9b146bf1
diff --git a/crates/engine/src/adjust_params.rs b/crates/engine/src/adjust_params.rsindex 00fb67dd0..8bc99a40b 100644--- a/crates/engine/src/adjust_params.rs+++ b/crates/engine/src/adjust_params.rs@@ -1240,9 +1240,12 @@ mod tests {#[test]fn destructive_levels_dont_clip_in_32_bit() {// Input 15..230, gamma 1.3, output 10..245: black and white land on the output range in- // integer documents, but in a 32-bit document the curve runs on past it (then 0..1).+ // integer documents. A 32-bit document evaluates the signed power curve beyond both+ // ranges, retaining negative values and highlights above 1. The float expectations+ // below were evaluated independently from the configured curve, not a clipped LUT.let params = json!({"inBlack": 15, "inWhite": 230, "gamma": 1.3, "outBlack": 10, "outWhite": 245});- for (depth, low, high) in [(8, 10.0, 245.0), (16, 10.0, 245.0), (32, 0.0, 255.0)] {+ for depth in [8, 16, 32] {+ let (low, high, tolerance) = if depth == 32 { (-0.079_642_7, 1.042_158, 1e-6) } else { (10.0 / 255.0, 245.0 / 255.0, 0.6 / 255.0) };let mut s = crate::Session::new();s.execute("file.new", json!({"width": 16, "height": 16, "depth": depth, "background": "white"})).unwrap();s.execute("select.rect", json!({"x": 0, "y": 0, "width": 8, "height": 16})).unwrap();@@ -1250,8 +1253,10 @@ mod tests {s.execute("select.deselect", json!({})).unwrap();s.execute("image.adjustments.levels", params.clone()).unwrap();let px = pixels(&s);- assert!((px[0][0] * 255.0 - low).abs() < 0.6, "black @{depth}: {:?}", px[0]);- assert!((px[1][0] * 255.0 - high).abs() < 0.6, "white @{depth}: {:?}", px[1]);+ assert!((px[0][0] - low).abs() < tolerance, "black @{depth}: {:?}", px[0]);+ assert!((px[1][0] - high).abs() < tolerance, "white @{depth}: {:?}", px[1]);+ assert_eq!(px[0][3], 1.0, "Levels keeps alpha");+ assert_eq!(px[1][3], 1.0, "Levels keeps alpha");}}