Skip to content

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

Merge PR #766

Claude4f9b77cad9f0
diff --cc crates/pipeline/src/masks.rs
index e6508c084,aab169302..0628a6a6f
--- a/crates/pipeline/src/masks.rs
+++ b/crates/pipeline/src/masks.rs
@@@ -450,25 -446,13 +450,16 @@@ pub fn brush_dabs(s: &BrushStroke, fram
let ppl = frame.px_per_long(w);
let r = (s.size * ppl).max(0.5);
let hard = r * (1.0 - (s.feather / 100.0).clamp(0.0, 1.0));
- // Densify the path so dabs overlap (spacing r/4).
+ // Densify the path so dabs overlap (spacing r/4). Coverage builds up by passes, not by how
+ // long the button is held: a sample where the pointer hasn't moved (a stationary hold records
+ // one per frame) lays no dab, so waiting in place adds nothing (#518).
let mut dabs: Vec<Point> = Vec::new();
- let mut prev: Option<Point> = None;
+ let mut prev = None;
for p in &s.points {
let q = to_out.apply(*p);
- if let Some(prev) = prev {
- let dist = prev.dist(q);
- if dist.is_nan() || dist <= STATIONARY_PX {
- continue;
- }
- let n = (dist / (r / 4.0).max(0.5)).ceil() as usize;
- for k in 1..n {
- dabs.push(prev.lerp(q, k as f64 / n as f64));
- }
- push_dabs(&mut dabs, prev, q, r);
- prev = Some(q);
++ if push_dabs(&mut dabs, prev, q, r) {
++ prev = Some(q);
+ }
- dabs.push(q);
- prev = Some(q);
}
BrushDabs {
dabs,
@@@ -481,6 -465,49 +472,60 @@@
}
}
+ /// Distance between consecutive dabs of a brush of radius `r` (pixels): a quarter of the radius,
+ /// so neighbouring dabs overlap and a stroke reads as continuous however fast it was painted.
+ #[inline]
+ pub fn dab_spacing(r: f64) -> f64 {
+ (r / 4.0).max(0.5)
+ }
+
+ /// Append the dabs of one path segment, from the previous sample `prev` (already stamped) to `q`,
+ /// for a brush of radius `r`: evenly spaced at most [`dab_spacing`] apart, ending on `q`. The
+ /// committed stroke ([`brush_dabs`]) and the live one the UI draws while the button is held place
-/// their dabs with this, so they cover the same pixels (issue #517).
-pub fn push_dabs(dabs: &mut Vec<Point>, prev: Option<Point>, q: Point, r: f64) {
++/// their dabs with this, so they cover the same pixels (issue #517). A sample where the pointer
++/// hasn't moved (a stationary hold records one per frame) or that is not a finite point lays
++/// nothing, so holding the brush still adds no coverage (#518). Returns whether `q` was stamped;
++/// callers move `prev` on only then.
++pub fn push_dabs(dabs: &mut Vec<Point>, prev: Option<Point>, q: Point, r: f64) -> bool {
++ if !(q.x.is_finite() && q.y.is_finite()) {
++ return false;
++ }
+ if let Some(prev) = prev {
- let n = (prev.dist(q) / dab_spacing(r)).ceil();
- // a hostile or degenerate segment (NaN, huge) gets no in-between dabs rather than a huge
++ let dist = prev.dist(q);
++ if dist.is_nan() || dist <= STATIONARY_PX {
++ return false;
++ }
++ let n = (dist / dab_spacing(r)).ceil();
++ // a hostile or degenerate segment (huge) gets no in-between dabs rather than a huge
+ // allocation: 1 M dabs is far more than any on-screen stroke needs
+ let n = if n.is_finite() { n.clamp(0.0, 1_000_000.0) as usize } else { 0 };
+ for k in 1..n {
+ dabs.push(prev.lerp(q, k as f64 / n as f64));
+ }
+ }
+ dabs.push(q);
++ true
+ }
+
+ /// How much one dab paints at distance `dd` from its centre: 1 inside the hard core `hard`,
+ /// smoothly falling to 0 at the radius `r`.
+ #[inline]
+ pub fn dab_alpha(dd: f64, r: f64, hard: f64) -> f32 {
+ if dd > r {
+ 0.0
+ } else if dd <= hard {
+ 1.0
+ } else {
+ 1.0 - smooth(hard as f32, r as f32, dd as f32)
+ }
+ }
+
+ /// A stroke's coverage `v` after another dab paints `a` there: flow accumulates up to density.
+ #[inline]
+ pub fn accumulate(v: f32, a: f32, flow: f32, density: f32) -> f32 {
+ (v + a * flow * (1.0 - v)).min(density)
+ }
+
/// Auto Mask tolerances: a pixel takes a dab's paint fully up to half of these from the colour
/// under the dab centre, none beyond them (log2 luminance, chromaticity `rgb / Y`).
pub const AUTO_TOL_EV: f32 = 0.5;
@@@ -706,6 -733,44 +751,47 @@@ mod tests
assert!(e[0].alpha.get(50, 50) < 0.01);
}
+ /// Issue #517: dabs along a long segment (a fast stroke: two pointer samples far apart) are at
+ /// most [`dab_spacing`] apart, painting dab by dab (the live stroke) or the whole path at once
+ /// (the committed one).
+ #[test]
+ fn a_long_segment_gets_dabs_at_most_the_spacing_apart() {
+ let r = 12.0;
+ let pts = [Point::new(10.0, 20.0), Point::new(610.0, 260.0), Point::new(611.0, 260.0), Point::new(40.0, 400.0)];
+ let mut live = Vec::new();
+ let mut prev = None;
+ for q in pts {
- push_dabs(&mut live, prev, q, r);
- prev = Some(q);
++ if push_dabs(&mut live, prev, q, r) {
++ prev = Some(q);
++ }
+ }
+ assert!(live.len() > 3 * 600 / 12, "{} dabs", live.len());
+ assert!(live.windows(2).all(|w| w[0].dist(w[1]) <= dab_spacing(r) + 1e-9));
+ assert_eq!(live.first(), pts.first());
+ assert_eq!(live.last(), pts.last());
+ // the committed stroke places the same dabs (in output pixels; this frame maps 1:1 scaled)
+ let (w, h) = (1000, 500);
+ let f = frame(w, h);
+ let stroke = BrushStroke { points: pts.map(|p| Point::new(p.x / w as f64, p.y / h as f64)).to_vec(), ..Default::default() };
+ let committed = brush_dabs(&stroke, &f, w, h);
+ let mut again = Vec::new();
+ let mut prev = None;
+ for p in &stroke.points {
+ let q = f.norm_to_out(w, h).apply(*p);
- push_dabs(&mut again, prev, q, committed.r);
- prev = Some(q);
++ if push_dabs(&mut again, prev, q, committed.r) {
++ prev = Some(q);
++ }
+ }
+ assert_eq!(committed.dabs, again);
+ assert!(committed.dabs.windows(2).all(|w| w[0].dist(w[1]) <= dab_spacing(committed.r) + 1e-9));
+ // a hostile segment places no in-between dabs
+ let mut v = Vec::new();
- push_dabs(&mut v, Some(Point::new(f64::NAN, 0.0)), Point::new(1.0, 1.0), r);
++ assert!(!push_dabs(&mut v, Some(Point::new(f64::NAN, 0.0)), Point::new(1.0, 1.0), r));
++ assert!(!push_dabs(&mut v, None, Point::new(f64::INFINITY, 1.0), r));
+ push_dabs(&mut v, Some(Point::new(0.0, 0.0)), Point::new(1e300, 1.0), 0.0);
+ assert!(v.len() <= 1_000_002, "{}", v.len());
+ }
+
#[test]
fn brush_and_subtract() {
let f = frame(200, 100);
diff --cc crates/ui-egui/src/brush_live.rs
index 000000000,316af3811..614b5bed3
mode 000000,100644..100644
--- a/crates/ui-egui/src/brush_live.rs
+++ b/crates/ui-egui/src/brush_live.rs
@@@ -1,0 -1,250 +1,251 @@@
+ //! The brush stroke being painted, drawn on the photo while the button is held (issue #517).
+ //!
+ //! The committed stroke is rasterized by the pipeline ([`lightcraft_pipeline::masks::brush_dabs`]
+ //! and friends): dabs a quarter radius apart along the path, each with a hard core and a smooth
+ //! feather, flow accumulating up to density. The live stroke places and paints its dabs with the
+ //! same functions, at screen resolution, so letting go of the button doesn't change what's
+ //! covered. It's incremental: each frame stamps only the dabs of the samples added since the last
+ //! one and uploads only the rectangle they touched.
+
+ use egui::{Color32, ColorImage, Pos2, Rect, TextureHandle, TextureOptions, pos2};
+ use lightcraft_geom::Point;
+ use lightcraft_pipeline::masks::{accumulate, dab_alpha, push_dabs};
+
+ /// The largest live-stroke buffer edge (pixels); a bigger canvas is painted at a lower resolution.
+ const MAX_SIDE: usize = 4096;
+
+ /// What a stroke is painted with; a change (a new canvas size, zoom, brush) repaints it from its
+ /// first sample.
+ #[derive(Clone, Copy, Debug, PartialEq)]
+ pub struct LiveParams {
+ /// The area the stroke may cover (screen points): the canvas.
+ pub clip: Rect,
+ /// Buffer pixels per screen point.
+ pub scale: f32,
+ /// Brush radius (screen points) and its hard core (no feather), as the pipeline computes them.
+ pub r: f32,
+ pub hard: f32,
+ /// Flow and density, 0..1.
+ pub flow: f32,
+ pub density: f32,
+ /// Overlay colour and its opacity (0..1) at full coverage.
+ pub color: [u8; 3],
+ pub opacity: f32,
+ }
+
+ /// An in-progress stroke's coverage at screen resolution and the texture showing it.
+ pub struct LiveStroke {
+ params: LiveParams,
+ w: usize,
+ h: usize,
+ alpha: Vec<f32>,
+ /// Samples stamped so far, and the last one (buffer pixels).
+ placed: usize,
+ last: Option<Point>,
+ /// Buffer pixels painted since the last upload: (x0, y0, x1, y1), exclusive ends.
+ dirty: Option<(usize, usize, usize, usize)>,
+ texture: Option<TextureHandle>,
+ }
+
+ impl LiveStroke {
+ fn new(params: LiveParams) -> LiveStroke {
+ let scale = buffer_scale(params.clip, params.scale);
+ let params = LiveParams { scale, ..params };
+ let (w, h) = buffer_size(params.clip, scale);
+ LiveStroke { params, w, h, alpha: vec![0.0; w * h], placed: 0, last: None, dirty: None, texture: None }
+ }
+
+ /// Stroke coverage (0..1) at buffer pixel `(x, y)`; 0 outside.
+ pub fn coverage(&self, x: usize, y: usize) -> f32 {
+ if x >= self.w {
+ return 0.0;
+ }
+ y.checked_mul(self.w).and_then(|i| i.checked_add(x)).and_then(|i| self.alpha.get(i)).copied().unwrap_or(0.0)
+ }
+
+ /// Buffer size (pixels) and pixels per screen point.
+ pub fn size(&self) -> ([usize; 2], f32) {
+ ([self.w, self.h], self.params.scale)
+ }
+
+ /// Stamp the dabs of `points` (screen positions of the stroke's samples so far) not yet
+ /// painted. Returns `true` when anything new was painted.
+ pub fn stamp(&mut self, points: &[Pos2]) -> bool {
+ let Some(new) = points.get(self.placed..) else { return false };
+ if new.is_empty() {
+ return false;
+ }
+ let LiveParams { clip, scale, r, hard, flow, density, .. } = self.params;
+ let (r, hard) = ((r * scale) as f64, (hard * scale) as f64);
+ let mut dabs = Vec::new();
+ for q in new {
+ let q = Point::new(((q.x - clip.left()) * scale) as f64, ((q.y - clip.top()) * scale) as f64);
- push_dabs(&mut dabs, self.last, q, r);
- self.last = Some(q);
++ if push_dabs(&mut dabs, self.last, q, r) {
++ self.last = Some(q);
++ }
+ }
+ self.placed = points.len();
+ for d in dabs {
+ if !(d.x.is_finite() && d.y.is_finite()) {
+ continue;
+ }
+ let x0 = (d.x - r).floor().clamp(0.0, self.w as f64) as usize;
+ let x1 = (d.x + r).ceil().clamp(0.0, self.w as f64) as usize;
+ let y0 = (d.y - r).floor().clamp(0.0, self.h as f64) as usize;
+ let y1 = (d.y + r).ceil().clamp(0.0, self.h as f64) as usize;
+ if x0 >= x1 || y0 >= y1 {
+ continue;
+ }
+ for y in y0..y1 {
+ let Some(row) = self.alpha.get_mut(y * self.w + x0..y * self.w + x1) else { continue };
+ for (x, v) in (x0..x1).zip(row.iter_mut()) {
+ let dd = Point::new(x as f64 + 0.5, y as f64 + 0.5).dist(d);
+ if dd > r {
+ continue;
+ }
+ *v = accumulate(*v, dab_alpha(dd, r, hard), flow, density);
+ }
+ }
+ self.dirty = Some(match self.dirty {
+ Some((a, b, c, e)) => (a.min(x0), b.min(y0), c.max(x1), e.max(y1)),
+ None => (x0, y0, x1, y1),
+ });
+ }
+ true
+ }
+
+ /// The overlay colour of coverage `a`.
+ fn pixel(&self, a: f32) -> Color32 {
+ let [r, g, b] = self.params.color;
+ let alpha = (a * self.params.opacity * 255.0).round().clamp(0.0, 255.0) as u8;
+ Color32::from_rgba_unmultiplied(r, g, b, alpha)
+ }
+
+ fn region(&self, (x0, y0, x1, y1): (usize, usize, usize, usize)) -> ColorImage {
+ let mut px = Vec::with_capacity((x1 - x0) * (y1 - y0));
+ for y in y0..y1 {
+ for x in x0..x1 {
+ px.push(self.pixel(self.coverage(x, y)));
+ }
+ }
+ ColorImage::new([x1 - x0, y1 - y0], px)
+ }
+
+ /// Bring the texture up to date (the whole buffer the first time, then only what changed).
+ fn upload(&mut self, ctx: &egui::Context) -> Option<&TextureHandle> {
+ match (&mut self.texture, self.dirty.take()) {
+ (None, _) => {
+ let image = self.region((0, 0, self.w, self.h));
+ self.texture = Some(ctx.load_texture("brush-live-stroke", image, TextureOptions::LINEAR));
+ }
+ (Some(_), Some(rect)) => {
+ let image = self.region(rect);
+ if let Some(t) = &mut self.texture {
+ t.set_partial([rect.0, rect.1], image, TextureOptions::LINEAR);
+ }
+ }
+ (Some(_), None) => {}
+ }
+ self.texture.as_ref()
+ }
+ }
+
+ /// Pixels per screen point of a buffer covering `clip`: `want`, lowered so no edge exceeds
+ /// [`MAX_SIDE`].
+ fn buffer_scale(clip: Rect, want: f32) -> f32 {
+ let want = if want.is_finite() && want > 0.0 { want } else { 1.0 };
+ let long = clip.width().max(clip.height());
+ if long.is_finite() && long * want > MAX_SIDE as f32 { MAX_SIDE as f32 / long } else { want }
+ }
+
+ fn buffer_size(clip: Rect, scale: f32) -> (usize, usize) {
+ let side = |v: f32| {
+ let v = (v * scale).ceil();
+ if v.is_finite() { (v.max(1.0) as usize).min(MAX_SIDE) } else { 1 }
+ };
+ (side(clip.width()), side(clip.height()))
+ }
+
+ /// Paint the live stroke whose samples so far are `points` (screen positions) into `painter`,
+ /// keeping its buffer in `slot` (a new stroke, or new parameters, start it afresh).
+ pub fn paint(slot: &mut Option<LiveStroke>, ctx: &egui::Context, painter: &egui::Painter, params: LiveParams, points: &[Pos2]) {
+ let fresh = match slot {
+ Some(s) => {
+ // the same stroke when painted with the same parameters (at the scale it settled on)
+ let same = s.params == LiveParams { scale: buffer_scale(params.clip, params.scale), ..params };
+ !same || points.len() < s.placed
+ }
+ None => true,
+ };
+ if fresh {
+ *slot = Some(LiveStroke::new(params));
+ }
+ let Some(s) = slot else { return };
+ s.stamp(points);
+ let clip = s.params.clip;
+ // the buffer's pixels may overhang the canvas by a fraction of a pixel: map them exactly
+ let (w, h, scale) = (s.w as f32, s.h as f32, s.params.scale);
+ let rect = Rect::from_min_size(clip.min, egui::vec2(w / scale, h / scale));
+ if let Some(t) = s.upload(ctx) {
+ painter.image(t.id(), rect, Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0)), Color32::WHITE);
+ }
+ }
+
+ #[cfg(test)]
+ mod tests {
+ use super::*;
+ use egui::vec2;
+
+ fn params() -> LiveParams {
+ LiveParams {
+ clip: Rect::from_min_size(Pos2::ZERO, vec2(400.0, 200.0)),
+ scale: 1.0,
+ r: 10.0,
+ hard: 5.0,
+ flow: 1.0,
+ density: 1.0,
+ color: [230, 30, 40],
+ opacity: 0.5,
+ }
+ }
+
+ /// Issue #517: two samples far apart (a fast stroke) paint a continuous band between them,
+ /// not two separate dabs.
+ #[test]
+ fn a_fast_segment_is_painted_continuously() {
+ let mut s = LiveStroke::new(params());
+ s.stamp(&[pos2(20.0, 100.0)]);
+ s.stamp(&[pos2(20.0, 100.0), pos2(380.0, 100.0)]);
+ for x in 20..380 {
+ assert!(s.coverage(x, 100) > 0.99, "a gap at x = {x}: {}", s.coverage(x, 100));
+ }
+ // the feather: full inside the core, fading to nothing at the radius
+ assert!(s.coverage(200, 104) > 0.99);
+ assert!((0.01..0.99).contains(&s.coverage(200, 108)), "{}", s.coverage(200, 108));
+ assert_eq!(s.coverage(200, 111), 0.0);
+ }
+
+ /// Painting the samples one frame at a time gives the same coverage as all at once (what the
+ /// committed stroke does).
+ #[test]
+ fn incremental_stamping_matches_painting_the_whole_path() {
+ let pts = [pos2(30.0, 40.0), pos2(200.0, 150.0), pos2(210.0, 152.0), pos2(390.0, 20.0)];
+ let mut once = LiveStroke::new(LiveParams { flow: 0.4, ..params() });
+ once.stamp(&pts);
+ let mut steps = LiveStroke::new(LiveParams { flow: 0.4, ..params() });
+ for n in 1..=pts.len() {
+ steps.stamp(&pts[..n]);
+ }
+ assert_eq!(once.alpha, steps.alpha);
+ }
+
+ #[test]
+ fn hostile_input_paints_nothing_and_does_not_panic() {
+ let mut s = LiveStroke::new(params());
+ s.stamp(&[pos2(f32::NAN, 3.0), pos2(f32::INFINITY, -1e30), pos2(-5000.0, 9000.0)]);
+ assert!(s.alpha.iter().all(|a| *a == 0.0));
+ // an enormous canvas is painted at a capped resolution
+ let big = LiveStroke::new(LiveParams { clip: Rect::from_min_size(Pos2::ZERO, vec2(1e6, 10.0)), scale: 2.0, ..params() });
+ assert!(big.w <= MAX_SIDE && big.h >= 1);
+ }
+ }
diff --cc crates/ui-egui/src/tests_masking.rs
index b707af476,89f3e3c69..5416474b5
--- a/crates/ui-egui/src/tests_masking.rs
+++ b/crates/ui-egui/src/tests_masking.rs
@@@ -1153,83 -1117,60 +1153,140 @@@ fn ai_masks_without_the_model_offer_the
assert!(t.elapsed() < SETTLE, "{:?}", t.elapsed());
}
+fn color_samples(h: &Headless) -> serde_json::Value {
+ let d = develop(h);
+ let m = d.masks.last().expect("a mask");
+ let Some(MaskShape::ColorRange { samples, .. }) = m.components.iter().map(|c| &c.shape).find(|s| matches!(s, MaskShape::ColorRange { .. }))
+ else {
+ panic!("colour range")
+ };
+ serde_json::to_value(samples).expect("samples")
+}
+
+/// Same samples, up to sub-pixel rounding and the preview level sampled.
+#[track_caller]
+fn assert_close(a: &serde_json::Value, b: &serde_json::Value) {
+ let flat = |v: &serde_json::Value| -> Vec<f64> {
+ v.as_array().unwrap().iter().flat_map(|s| s.as_array().unwrap().iter().map(|x| x.as_f64().unwrap())).collect()
+ };
+ let (a, b) = (flat(a), flat(b));
+ assert_eq!(a.len(), b.len());
+ assert!(a.iter().zip(&b).all(|(x, y)| (x - y).abs() < 0.05), "{a:?} vs {b:?}");
+}
+
+/// Regression: the Colour Range "Pick" button armed the eyedropper, but with the Masking panel
+/// open the loupe's clicks went to the mask overlay, so no sample was ever taken.
+#[test]
+fn color_range_pick_button_samples_the_photo() {
+ let mut h = detail("panel.masking");
+ exec(&mut h, "mask.add", json!({"kind": "colorRange"}));
+ h.app.ui.tool.clear();
+ h.settle(SETTLE);
+ click(&mut h, "button:colorPick0");
+ assert_eq!(h.app.ui.tool, "colorRange", "Pick arms the eyedropper");
+ brush_at(&mut h, 0.25, 0.5);
+ let ui_sample = color_samples(&h);
+ assert_eq!(ui_sample.as_array().map(Vec::len), Some(1), "a click samples a colour");
+ // the sample is the colour at that normalized point
+ exec(&mut h, "mask.sampleColor", json!({"x": 0.25, "y": 0.5}));
+ assert_close(&color_samples(&h), &ui_sample);
+ // ⇧-click adds
+ let r = h.request("ui.pointer", json!({"shift": true, "events": [{"kind": "down", "x": 0.7, "y": 0.2}, {"kind": "up", "x": 0.7, "y": 0.2}]}), T);
+ assert_eq!(r["ok"], true, "{r}");
+ assert_eq!(color_samples(&h).as_array().map(Vec::len), Some(2), "⇧-click adds a sample");
+
+ // cropped and zoomed: the click samples the photo point under it
+ exec(&mut h, "crop.set", json!({"rect": [0.2, 0.1, 0.9, 0.8]}));
+ h.app.ui.zoom = crate::state::Zoom::Percent(200.0);
+ h.app.ui.pan = (0.5, 0.5);
+ h.settle(SETTLE);
+ brush_at(&mut h, 0.5, 0.5);
+ let ui_sample = color_samples(&h);
+ assert_eq!(ui_sample.as_array().map(Vec::len), Some(1));
+ // (the centre of the crop box, in normalized source coordinates)
+ let c = develop(&h).crop.geometry.rect;
+ exec(&mut h, "mask.sampleColor", json!({"x": (c.x0 + c.x1) / 2.0, "y": (c.y0 + c.y1) / 2.0}));
+ assert_close(&color_samples(&h), &ui_sample); // a cropped, zoomed pick maps to the same frame point
+ // Pick again ends picking
+ click(&mut h, "button:colorPick0");
+ assert!(h.app.ui.tool.is_empty());
+ h.settle(SETTLE);
+
+#[test]
+fn a_selected_develop_slider_accepts_wheel_nudges() {
+ let mut h = detail("panel.edit");
+ h.settle(SETTLE);
+ let name = "slider:light.exposure";
+ let panel = h.app.widgets.iter().find(|(id, _)| id == "panel:right_panel").unwrap().1;
+ let track = h.app.widgets.iter().find(|(id, _)| id == name).unwrap().1;
+ assert!(panel.contains(track.center()), "slider must be visible before interaction");
+
+ let result = h.request("ui.clickWidget", json!({"id": name, "fx": 0.5}), T);
+ assert_eq!(result["ok"], true, "{result}");
+ let before = lightcraft_develop::controls::get(&develop(&h), "light.exposure");
+
+ // A wheel event over the selected control adjusts exposure instead of
+ // scrolling the right sidebar (an unselected slider leaves scrolling alone).
+ let result = h.request("ui.scroll", json!({"dy": 120.0}), T);
+ assert_eq!(result["ok"], true, "{result}");
+ h.step();
+ let after = lightcraft_develop::controls::get(&develop(&h), "light.exposure");
+ assert!(after > before, "selected exposure did not increase: {before} -> {after}");
++
+ /// Issue #517: a fast brush stroke (pointer samples several brush widths apart) shows on the photo
+ /// while the button is held as the continuous, feathered band it will be once committed, not as
+ /// separate dabs at the samples with gaps between them.
+ #[test]
+ fn a_fast_brush_stroke_shows_without_gaps_before_the_button_is_released() {
+ let mut h = detail("panel.masking");
+ h.settle(SETTLE);
+ exec(&mut h, "tool.brush", json!({"new": true}));
+ let r = h.request("ui.set", json!({"brushSize": 0.03, "brushFeather": 50.0, "brushFlow": 100.0}), T);
+ assert_eq!(r["ok"], true, "{r}");
+ // the photo before painting, and where a normalized image point is on screen
+ pointer(&mut h, json!([{"kind": "move", "x": 0.02, "y": 0.02}]));
+ h.settle(SETTLE);
+ let photo = h.paint();
+ let img = h.app.image_rect.expect("the photo is on screen");
+ let ppp = h.pixels_per_point;
+ let px = |im: &egui::ColorImage, x: f32, y: f32| {
+ let (sx, sy) = (((img.left() + x * img.width()) * ppp) as usize, ((img.top() + y * img.height()) * ppp) as usize);
+ let c = im.pixels[sy * im.size[0] + sx];
+ [c.r() as f32, c.g() as f32, c.b() as f32]
+ };
+ // a drag that starts (past egui's drag threshold, at `a`) and then moves fast: samples far
+ // apart, button held
+ let (a, b, c) = ((0.17_f32, 0.4_f32), (0.5_f32, 0.4_f32), (0.85_f32, 0.4_f32));
+ pointer(
+ &mut h,
+ json!([{"kind": "down", "x": 0.15, "y": a.1}, {"kind": "drag", "x": a.0, "y": a.1}, {"kind": "drag", "x": b.0, "y": b.1}, {"kind": "drag", "x": c.0, "y": c.1}]),
+ );
+ assert!(matches!(h.app.gesture, Some(crate::panels::detail::Gesture::Brush { .. })), "still painting");
+ let held = h.paint();
+ let [r0, g0, b0] = h.app.ui.mask_overlay_color.map(|v| v as f32);
+ let op = h.app.ui.mask_overlay_opacity / 100.0;
+ // along the centreline between the samples (away from the cursor ring at the last one), the
+ // overlay colour at full coverage over the photo
+ let mut gaps = vec![];
+ for i in 1..=74 {
+ let x = a.0 + (c.0 - a.0) * i as f32 / 80.0;
+ let p = px(&photo, x, a.1);
+ let want = [p[0] + (r0 - p[0]) * op, p[1] + (g0 - p[1]) * op, p[2] + (b0 - p[2]) * op];
+ let got = px(&held, x, a.1);
+ if (0..3).any(|k| (got[k] - want[k]).abs() > 12.0) {
+ gaps.push((x, got, want));
+ }
+ }
+ assert!(gaps.is_empty(), "the live stroke has gaps: {} of 74 points, first {:?}", gaps.len(), gaps.first());
+ pointer(&mut h, json!([{"kind": "up", "x": c.0, "y": c.1}]));
+ let d = develop(&h);
+ let MaskShape::Brush { strokes } = &d.masks[0].components[0].shape else { panic!("brush") };
+ assert!(strokes[0].points.len() >= 3, "{strokes:?}");
+ // committed: the rendered overlay covers what the live stroke did, feather included
+ h.settle(SETTLE);
+ let done = h.paint();
+ for (x, y) in [(0.3, a.1), (0.6, a.1), (0.3, a.1 + 0.02), (0.6, a.1 - 0.025), (0.45, a.1 + 0.06)] {
+ let (l, k) = (px(&held, x, y), px(&done, x, y));
+ assert!((0..3).all(|i| (l[i] - k[i]).abs() < 24.0), "live {l:?} vs committed {k:?} at ({x}, {y})");
+ }
}
diff --cc docs/parity-checklist.md
index 6845e083b,3a566500f..3e0e1587a
--- a/docs/parity-checklist.md
+++ b/docs/parity-checklist.md
@@@ -290,7 -290,7 +290,7 @@@ differences and missing bindings are i
| LR-MASK-OBJECTS | Object selection | P2 | 🟡 | `cmd:mask.add` (`object`, `prompt`), `cmd:mask.objectPoint`, `cmd:mask.refineDetail`, `cmd:segment.prepare`, `cmd:segment.model.status`, `cmd:segment.model.download`, `cmd:segment.model.cancel`, `crates/segment`, `crates/engine/src/segment/mod.rs` | SAM 3 in pure Rust (candle; Metal on macOS, CPU elsewhere): Object tile → click to include, ⌥-click to leave out; Describe tile → a text prompt selects every instance ("sky", "the red car"); both also as Add/Subtract/Intersect components; + / − under the selected mask; comma lists (`car, road`); a zoomed-in detail pass for 5–10× finer edges on small objects; per-selection Edge (hard ↔ soft). The model runs on its own worker thread (the UI never waits; panics become errors), is unloaded after 10 min idle, and is optional: the segmentation is stored with the mask (288² logits), so renders and exports never need it. Weights are never bundled (SAM License): without them the app offers a consented background download (mirrors, resume, timeouts, SHA-256) — **but no default download location is configured yet** (users set `LIGHTCRAFT_SAM3_MIRRORS` or install by hand: the dialog names the three files, shows the model folder and links docs/ai-masks.md). Not verified against Lightroom's Select Object; no brush/box object mode; the first click on a photo waits for its analysis (~4 s on an M4 Pro, much longer on CPU) |
| LR-MASK-PEOPLE | People parts | P2 | ⬜ | | shape exists (no UI): uses the photo's person / skin / hair / teeth / glasses mattes when it carries them (DNG semantic masks), else the subject heuristic |
| LR-MASK-LANDSCAPE | Landscape classes | P2 | ⬜ | | shape exists, evaluates empty |
- | LR-MASK-BRUSH | Brush mask | P0 | 🟡 | `cmd:tool.brush`, `cmd:mask.brushStroke` (`autoMask`), `crates/pipeline/src/masks.rs` | size/feather/flow/density/erase; Create New Mask starts a separate brush in paint mode; coverage builds up by passes, not hold time (holding the brush still adds nothing, #518); live-preview gaps (#517) remain; Auto Mask: dabs weighted by similarity to the colour under the dab centre, refined by a guided filter on luminance (CPU + GPU); no A/B brushes, no pressure |
-| LR-MASK-BRUSH | Brush mask | P0 | 🟡 | `cmd:tool.brush`, `cmd:mask.brushStroke` (`autoMask`), `crates/pipeline/src/masks.rs`, `crates/ui-egui/src/brush_live.rs` | size/feather/flow/density/erase; Create New Mask starts a separate brush in paint mode; the stroke shows while the button is held with the committed stroke's dab spacing, feather and flow, so fast strokes have no gaps (#517); stationary accumulation (#518) remains; Auto Mask: dabs weighted by similarity to the colour under the dab centre, refined by a guided filter on luminance (CPU + GPU); no A/B brushes, no pressure |
++| LR-MASK-BRUSH | Brush mask | P0 | 🟡 | `cmd:tool.brush`, `cmd:mask.brushStroke` (`autoMask`), `crates/pipeline/src/masks.rs`, `crates/ui-egui/src/brush_live.rs` | size/feather/flow/density/erase; Create New Mask starts a separate brush in paint mode; the stroke shows while the button is held with the committed stroke's dab spacing, feather and flow, so fast strokes have no gaps (#517); coverage builds up by passes, not hold time (holding the brush still adds nothing, live or committed, #518); Auto Mask: dabs weighted by similarity to the colour under the dab centre, refined by a guided filter on luminance (CPU + GPU); no A/B brushes, no pressure |
| LR-MASK-LINEAR | Linear gradient | P0 | ✅ | `cmd:tool.linear`, `cmd:mask.update` | |
| LR-MASK-RADIAL | Radial gradient | P0 | ✅ | `cmd:tool.radial`, `cmd:mask.update`, `crates/ui-egui/src/panels/detail.rs` | drag the selected ellipse's body or centre pin to move; edge grips resize, outer grip rotates; rotated and compound radial components, hidden pins, outside hit rejection and one-step undo tested |
| LR-MASK-COLORRANGE | Colour range | P1 | ✅ | `cmd:mask.add` (`colorRange`), `cmd:mask.sampleColor`, `cmd:mask.update`, `crates/pipeline/src/lib.rs` (`color_range_sample`) | Color tile → click the photo to sample (⇧-click adds, up to 5; samples taken in the space the mask compares in), Pick button, Refine slider |