Skip to content

LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust

Merge PR #1533

Brandon Thomas1c65549d10d3
diff --cc crates/engine/src/tests.rs
index b8553a126,d0d6d4340..0b76e2cfe
--- a/crates/engine/src/tests.rs
+++ b/crates/engine/src/tests.rs
@@@ -402,28 -402,26 +402,48 @@@ fn paste_selected_settings_pastes_only_
assert_eq!(s.develop_of(ids[1]).unwrap().color.vibrance, 30.0);
}
+/// A crop of no size (or a hair wide), as `crop.set` or a sidecar can set it, made the render's
+/// samplers read at infinite coordinates and its blurs ask for sigmas of millions of pixels: with a
+/// healing spot and masks on, render workers panicked (an i32 square in the blur, a bilinear
+/// neighbour past isize::MAX). Such a photo renders, quickly.
+#[test]
+fn degenerate_crops_render_with_spots_and_masks() {
+ for rect in [[0.5, 0.5, 0.5, 0.5], [0.0, 0.0, 1e-9, 1.0]] {
+ let mut s = demo();
+ let id = s.active().unwrap();
+ s.execute("spot.add", &json!({"points": [[0.5, 0.5]], "size": 0.2, "mode": "heal"})).unwrap();
+ s.execute("mask.add", &json!({"kind": "radial", "rx": 0.3, "ry": 0.3})).unwrap();
+ s.execute("mask.add", &json!({"kind": "linear"})).unwrap();
+ s.execute("develop.set", &json!({"control": "effects.clarity", "value": 80})).unwrap();
+ s.execute("develop.set", &json!({"control": "effects.dehaze", "value": 50})).unwrap();
+ s.execute("crop.set", &json!({"rect": rect, "angle": 30})).unwrap();
+ let t = std::time::Instant::now();
+ let r = s.render_now(id, 700, 450).unwrap();
+ assert!(r.image.width >= 1 && r.image.height >= 1, "{rect:?}");
+ assert!(t.elapsed().as_secs_f64() < 60.0, "{rect:?}: {:?}", t.elapsed());
+ }
+}
+
+ /// `mask.move` with a delta near `i64::MAX` overflowed `index + delta` (a panic wherever overflow
+ /// checks are on); extreme deltas and indices now move the mask to the bottom or the top.
+ #[test]
+ fn mask_move_with_extreme_deltas() {
+ let mut s = demo();
+ for kind in ["linear", "radial", "brush"] {
+ s.execute("mask.add", &json!({"kind": kind})).unwrap();
+ }
+ let ids = |s: &Session| active_dev(s).masks.iter().map(|m| m.id).collect::<Vec<_>>();
+ let [a, b, c] = ids(&s)[..] else { panic!("{:?}", ids(&s)) };
+ s.execute("mask.move", &json!({"id": b, "delta": i64::MAX})).unwrap();
+ assert_eq!(ids(&s), [a, c, b], "to the bottom");
+ s.execute("mask.move", &json!({"id": b, "delta": i64::MIN})).unwrap();
+ assert_eq!(ids(&s), [b, a, c], "to the top");
+ s.execute("mask.move", &json!({"id": c, "to": i64::MIN})).unwrap();
+ assert_eq!(ids(&s), [c, b, a]);
+ s.execute("mask.move", &json!({"id": c, "to": i64::MAX})).unwrap();
+ assert_eq!(ids(&s), [b, a, c]);
+ }
+
#[test]
fn masks_reorder_and_duplicate_and_invert() {
let mut s = demo();