LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Merge PR #522
Brandon Thomas630e2edc47c9
diff --cc crates/ui-egui/src/tests_masking.rsindex 905b5e294,379282bc5..0f55c8d92--- a/crates/ui-egui/src/tests_masking.rs+++ b/crates/ui-egui/src/tests_masking.rs@@@ -39,99 -39,46 +39,139 @@@ fn develop(h: &Headless) -> lightcraft_(*h.app.session.develop_of(id).unwrap_or_default()).clone()}+fn click(h: &mut Headless, id: &str) {+ let r = h.request("ui.clickWidget", json!({"id": id}), T);+ assert_eq!(r["ok"], true, "{id}: {r}");+}++fn brush_at(h: &mut Headless, x: f64, y: f64) {+ pointer(h, json!([{"kind": "down", "x": x, "y": y}, {"kind": "up", "x": x, "y": y}]));+}++/// Evaluate the real composite, with a deterministic embedded sky matte (no AI model required).+fn mask_coverage(h: &Headless, mask: usize, x: usize, y: usize) -> f32 {+ use lightcraft_pipeline::{+ geometry::Frame,+ masks::{MatteKind, Mattes, evaluate_one},+ };+ use lightcraft_raster::{Image, Plane, Rgb32f};+ let d = develop(h);+ let mut sky = Image::<u8>::new(100, 100);+ sky.data.fill(255);+ let mut mattes = Mattes::default();+ mattes.push(MatteKind::Sky, sky);+ let a = evaluate_one(+ &d.masks[mask],+ &Frame::new(100, 100, &Default::default(), true),+ 100,+ 100,+ &Rgb32f::new(100, 100),+ &Plane::new(100, 100),+ 0.0,+ Some(&mattes),+ );+ a.get(x, y)+}++#[test]+fn subtract_brush_removes_sky_coverage_and_add_restores_it() {+ let mut h = detail("panel.masking");+ exec(&mut h, "mask.add", json!({"kind": "sky"}));+ let r = h.request("ui.set", json!({"brushSize": 0.15, "brushFeather": 0.0, "brushFlow": 100.0}), T);+ assert_eq!(r["ok"], true, "{r}");+ click(&mut h, "button:maskMinus:1");+ click(&mut h, "maskComp:subtract:brush");+ brush_at(&mut h, 0.5, 0.5);+ assert!(mask_coverage(&h, 0, 50, 50) < 0.01, "Subtract > Brush must remove sky coverage");+ assert!(mask_coverage(&h, 0, 10, 10) > 0.99, "unpainted sky stays selected");+ let subtracted = develop(&h);+ exec(&mut h, "edit.undo", json!({}));+ assert!(mask_coverage(&h, 0, 50, 50) > 0.99);+ exec(&mut h, "edit.redo", json!({}));+ assert_eq!(develop(&h).masks, subtracted.masks);++ // Renaming must not detach subsequent strokes from the subtract component.+ exec(&mut h, "mask.component", json!({"component": 1, "action": "rename", "name": "Sky cleanup"}));+ brush_at(&mut h, 0.25, 0.5);+ assert!(mask_coverage(&h, 0, 25, 50) < 0.01);+ assert_eq!(develop(&h).masks[0].components.len(), 2);++ // Erase removes paint from the subtract component, restoring the underlying sky.+ h.app.ui.brush_erase = true;+ brush_at(&mut h, 0.5, 0.5);+ assert!(mask_coverage(&h, 0, 50, 50) > 0.99);+ click(&mut h, "button:maskPlus:1");+ click(&mut h, "maskComp:add:brush");+ brush_at(&mut h, 0.25, 0.5);+ assert!(mask_coverage(&h, 0, 25, 50) > 0.99, "Add must be composed after Subtract");+ assert_eq!(develop(&h).masks[0].components.len(), 3);+ h.settle(SETTLE);+}++#[test]+fn new_brush_starts_a_separate_mask_in_paint_mode() {+ let mut h = detail("panel.masking");+ exec(&mut h, "mask.add", json!({"kind": "sky"}));+ let original = develop(&h).masks[0].clone();+ h.app.ui.brush_erase = true;+ h.app.ui.mask_overlay = false;+ click(&mut h, "maskNew:brush");+ assert_eq!(h.app.session.active_mask, Some(2));+ assert!(!h.app.ui.brush_erase);+ assert!(h.app.ui.mask_overlay);+ let r = h.request("ui.set", json!({"brushSize": 0.15, "brushFeather": 0.0, "brushFlow": 100.0}), T);+ assert_eq!(r["ok"], true, "{r}");+ brush_at(&mut h, 0.5, 0.5);+ assert!(mask_coverage(&h, 1, 50, 50) > 0.99);+ h.app.ui.brush_erase = true;+ brush_at(&mut h, 0.5, 0.5);+ assert!(mask_coverage(&h, 1, 50, 50) < 0.01);+ exec(&mut h, "edit.undo", json!({}));+ assert!(mask_coverage(&h, 1, 50, 50) > 0.99);+ assert_eq!(develop(&h).masks[0], original);+ h.settle(SETTLE);+}++ #[test]+ fn mask_adjustments_hide_overlay_without_disabling_the_mask() {+ use lightcraft_pipeline::Overlay;+ let mut h = detail("panel.masking");+ exec(&mut h, "mask.add", json!({"kind": "linear", "start": [0.5, 0.2], "end": [0.5, 0.7]}));+ assert!(h.app.ui.mask_overlay);++ // Changing the shape needs the overlay; changing the image needs an unobscured preview.+ exec(&mut h, "mask.refine", json!({"value": 10.0}));+ assert!(h.app.ui.mask_overlay);+ let r = h.request("ui.clickWidget", json!({"id": "slider:exposure", "fx": 0.7}), T);+ assert_eq!(r["ok"], true, "{r}");+ assert!(!h.app.ui.mask_overlay, "the exposure slider hides the overlay after release");+ let d = develop(&h);+ assert!(d.masks[0].adjust.exposure > 0.0);+ assert!(d.masks[0].visible, "hiding the overlay must not disable the mask");+ assert_eq!(crate::panels::detail::view_overlay(&h.app, &d), Overlay::None);+ let mask = d.masks[0].clone();++ let r = h.request("ui.key", json!({"key": "o"}), T);+ assert_eq!(r["ok"], true, "{r}");+ assert!(h.app.ui.mask_overlay, "O can restore the overlay");+ assert_eq!(develop(&h).masks[0], mask, "toggling the overlay leaves the mask and its effect unchanged");+ assert!(matches!(crate::panels::detail::view_overlay(&h.app, &develop(&h)), Overlay::Mask { .. }));++ // Failed edits and global adjustments must not hide the mask overlay.+ assert!(h.app.run("mask.adjust", json!({"id": 999, "values": {"exposure": 1.0}})).is_err());+ assert!(h.app.ui.mask_overlay);+ exec(&mut h, "develop.set", json!({"control": "light.exposure", "value": 0.5}));+ assert!(h.app.ui.mask_overlay);++ // Numeric edits/resets and Amount use the same command path as the sliders.+ for values in [json!({"exposure": 0.0}), json!({"saturation": 20.0}), json!({"amount": 50.0})] {+ exec(&mut h, "view.maskOverlay", json!({"show": true}));+ exec(&mut h, "mask.adjust", json!({"values": values}));+ assert!(!h.app.ui.mask_overlay);+ }+ h.settle(SETTLE);+ }+#[test]fn radial_body_drag_moves_rotated_components_and_undoes_once() {let mut h = detail("panel.masking");