From 26a8f4e706ee52d1fb96448593356873e5f1f2ac Mon Sep 17 00:00:00 2001 From: Dimitrij Denissenko Date: Tue, 10 Nov 2026 09:07:59 +0000 Subject: [PATCH 1/3] LR-MASK-BRUSH: Flow as in Lightroom (process V8): coverage per brush radius travelled Measured in Lightroom Classic on a grey card (#4045), a stroke's centre is covered by 41 % at Flow 25 and 76 % at Flow 50; here every dab added the full flow, r/4 apart (closer on a slow drag), so 90 % and over 99 %. From process V8 a dab adds 1 - (1 - flow)^(d / r) for its distance d from the previous dab, so a point a stroke passes over for a length L is covered by 1 - (1 - flow)^(L / r) however densely the dabs lie: 44 % and 75 %. CPU, GPU (a flow per dab in the brush data) and the live stroke alike; V1 to V7 render as before. --- crates/develop/src/settings.rs | 9 +++- crates/gpu/src/render.rs | 7 +-- crates/gpu/src/wgsl/mask.wgsl | 11 ++-- crates/gpu/tests/it/equivalence.rs | 14 +++++ crates/pipeline/src/finish.rs | 6 +-- crates/pipeline/src/geometry.rs | 4 ++ crates/pipeline/src/light_v3.rs | 2 +- crates/pipeline/src/local.rs | 2 +- crates/pipeline/src/masks.rs | 58 ++++++++++++++++++-- crates/pipeline/src/masks/tests.rs | 66 +++++++++++++++++++++++ crates/pipeline/src/tests_grain.rs | 2 +- crates/ui-egui/src/brush_live.rs | 48 +++++++++++++++-- crates/ui-egui/src/panels/detail/masks.rs | 1 + crates/ui-egui/src/tests/masking.rs | 27 ++++++++++ docs/parity-checklist.md | 3 +- docs/process-versions.md | 4 +- docs/whats-new.md | 5 ++ 17 files changed, 245 insertions(+), 24 deletions(-) diff --git a/crates/develop/src/settings.rs b/crates/develop/src/settings.rs index 85bb3b90f2a..8a6a7168b59 100644 --- a/crates/develop/src/settings.rs +++ b/crates/develop/src/settings.rs @@ -99,12 +99,16 @@ pub enum Process { /// V6, with film grain from a stack of crystal layers (after Aurélien Pierre's model): resolution /// independent, fading out at black and white; V1 to V6 keep their value noise. V7, + /// V7, with brush Flow as the coverage a stroke adds per brush radius it travels, as in + /// Lightroom: a dab adds `1 − (1 − flow)^(distance from the previous dab / radius)`, so a + /// stroke's strength no longer depends on how densely its dabs lie; V1 to V7 add `flow` per dab. + V8, } impl Process { /// Every process, oldest first. - pub const ALL: [Process; 7] = [Process::V1, Process::V2, Process::V3, Process::V4, Process::V5, Process::V6, Process::V7]; - pub const LATEST: Process = Process::V7; + pub const ALL: [Process; 8] = [Process::V1, Process::V2, Process::V3, Process::V4, Process::V5, Process::V6, Process::V7, Process::V8]; + pub const LATEST: Process = Process::V8; pub const fn version(self) -> ProcessVersion { match self { @@ -115,6 +119,7 @@ impl Process { Process::V5 => ProcessVersion(5), Process::V6 => ProcessVersion(6), Process::V7 => ProcessVersion(7), + Process::V8 => ProcessVersion(8), } } } diff --git a/crates/gpu/src/render.rs b/crates/gpu/src/render.rs index 4d658c3ca07..12254a475f2 100644 --- a/crates/gpu/src/render.rs +++ b/crates/gpu/src/render.rs @@ -1459,7 +1459,8 @@ fn prepare(cx: &mut Cx<'_>, lin: &Buf, plan: &Plan<'_>, req: &RenderRequest, pla const MAX_DABS: usize = 4096; /// The `shape` kernel's brush data for `dabs`: stroke records (12 words: dab offset, dab count, -/// r, hard, flow, density, erase, bbox x0 y0 x1 y1, auto) then the dab centres. +/// r, hard, flow, density, erase, bbox x0 y0 x1 y1, auto) then each dab's centre and the flow it +/// adds (3 words; the stroke's flow before process V8, [`lightcraft_pipeline::masks::BrushDabs::dab`]). fn brush_aux(dabs: &[&lightcraft_pipeline::masks::BrushDabs], erase: bool) -> Vec { let mut aux = Vec::new(); let mut off = 12 * dabs.len(); @@ -1471,10 +1472,10 @@ fn brush_aux(dabs: &[&lightcraft_pipeline::masks::BrushDabs], erase: bool) -> Ve aux.extend([off as f32, d.dabs.len() as f32, d.r as f32, d.hard as f32, d.flow, d.density, (erase && d.erase) as u8 as f32]); aux.extend([x0, y0, x1, y1].map(|v| v as f32)); aux.push(d.auto as u8 as f32); - off += 2 * d.dabs.len(); + off += 3 * d.dabs.len(); } for d in dabs { - aux.extend(d.dabs.iter().flat_map(|q| [q.x as f32, q.y as f32])); + aux.extend(d.dabs.iter().enumerate().flat_map(|(i, q)| [q.x as f32, q.y as f32, d.dab(i).2])); } aux } diff --git a/crates/gpu/src/wgsl/mask.wgsl b/crates/gpu/src/wgsl/mask.wgsl index c2d15b64a23..6157b5f866d 100644 --- a/crates/gpu/src/wgsl/mask.wgsl +++ b/crates/gpu/src/wgsl/mask.wgsl @@ -92,11 +92,12 @@ fn shape(@builtin(global_invocation_id) g: vec3) { let cnt = u32(aux[o + 1u]); let r = aux[o + 2u]; let hard = aux[o + 3u]; - let flow = aux[o + 4u]; var keep = 1.0; for (var j = 0u; j < cnt; j++) { - let dx = px - aux[off + 2u * j]; - let dy = py - aux[off + 2u * j + 1u]; + // dab record: centre x, y and the flow it adds (the stroke's before process V8) + let dx = px - aux[off + 3u * j]; + let dy = py - aux[off + 3u * j + 1u]; + let flow = aux[off + 3u * j + 2u]; let dd = sqrt(dx * dx + dy * dy); if (dd > r) { continue; @@ -106,8 +107,8 @@ fn shape(@builtin(global_invocation_id) g: vec3) { a = 1.0 - sstep(hard, r, dd); } if (auto_mask) { - let rx = min(u32(max(floor(aux[off + 2u * j]), 0.0)), w - 1u); - let ry = min(u32(max(floor(aux[off + 2u * j + 1u]), 0.0)), h - 1u); + let rx = min(u32(max(floor(aux[off + 3u * j]), 0.0)), w - 1u); + let ry = min(u32(max(floor(aux[off + 3u * j + 1u]), 0.0)), h - 1u); let ri = ry * w + rx; a *= auto_similarity(lp, chp, log_l[ri], chroma_at(ri)); } diff --git a/crates/gpu/tests/it/equivalence.rs b/crates/gpu/tests/it/equivalence.rs index 427afe424da..15550cfb743 100644 --- a/crates/gpu/tests/it/equivalence.rs +++ b/crates/gpu/tests/it/equivalence.rs @@ -434,6 +434,20 @@ fn cases() -> Vec<(&'static str, Edit)> { }, ]; }), + ("masks (brush, process V7: flow per dab)", |s| { + s.process = lightcraft_develop::Process::V7.version(); + let stroke = BrushStroke { + points: vec![Point::new(0.1, 0.3), Point::new(0.5, 0.4), Point::new(0.8, 0.35)], + size: 0.04, + flow: 25.0, + ..Default::default() + }; + s.masks = vec![Mask { + components: vec![MaskComponent { name: None, op: MaskOp::Add, invert: false, shape: MaskShape::Brush { strokes: vec![stroke] } }], + adjust: lightcraft_develop::LocalAdjustments { exposure: -1.0, ..Default::default() }, + ..Default::default() + }]; + }), ("masks (brush + ranges)", |s| { let stroke = BrushStroke { points: vec![Point::new(0.1, 0.3), Point::new(0.5, 0.4), Point::new(0.8, 0.35)], diff --git a/crates/pipeline/src/finish.rs b/crates/pipeline/src/finish.rs index 3bce268a68c..a4ec7ddec32 100644 --- a/crates/pipeline/src/finish.rs +++ b/crates/pipeline/src/finish.rs @@ -148,8 +148,8 @@ impl GrainModel { seed: g.seed, }) }), - Process::V7 if draft => crate::crystal::CrystalGrain::draft(g, px_per_long).map(GrainModel::Crystal), - Process::V7 => crate::crystal::CrystalGrain::new(g, px_per_long).map(GrainModel::Crystal), + Process::V7 | Process::V8 if draft => crate::crystal::CrystalGrain::draft(g, px_per_long).map(GrainModel::Crystal), + Process::V7 | Process::V8 => crate::crystal::CrystalGrain::new(g, px_per_long).map(GrainModel::Crystal), } } } @@ -407,7 +407,7 @@ pub fn base_tone(s: &DevelopSettings, info: &SourceInfo, peak: f32) -> ToneMap { }, // V4, with a raw's tone curve rolling off into white in stops: a camera curve past its last // knot, the generic curve from half a stop below its white point instead of clipping (issue #1632) - Process::V5 | Process::V6 | Process::V7 => match info.camera_tone.as_ref().filter(|_| info.raw) { + Process::V5 | Process::V6 | Process::V7 | Process::V8 => match info.camera_tone.as_ref().filter(|_| info.raw) { Some(curve) => ToneMap::camera_rolloff_hdr(curve, 0.0, l.whites, 0.0, peak), None if info.raw => ToneMap::rolloff_hdr(l.contrast, l.whites, l.blacks, peak), None => ToneMap::display_hdr(l.contrast, l.whites, l.blacks, peak), diff --git a/crates/pipeline/src/geometry.rs b/crates/pipeline/src/geometry.rs index 5d8a07489a8..3ed32684749 100644 --- a/crates/pipeline/src/geometry.rs +++ b/crates/pipeline/src/geometry.rs @@ -37,6 +37,9 @@ pub struct Frame { /// `lightcraft_develop::Mask::on_photo`); otherwise they are normalized coordinates of this /// frame's transformed image, like spots and the crop. pub masks_on_photo: bool, + /// Brush Flow is coverage per brush radius travelled (process V8, [`crate::masks::flow_per_radius`]), + /// not per dab. + pub brush_flow_per_radius: bool, } /// Where a windowed [`Frame`]'s pixels sit in the full output: its offset and the full output's @@ -82,6 +85,7 @@ impl Frame { warp: (!warp.is_identity()).then_some(warp), view: None, masks_on_photo: false, + brush_flow_per_radius: crate::masks::flow_per_radius(s), }; if apply_crop { f.constrain_to_image(s.geometry.constrain_crop); diff --git a/crates/pipeline/src/light_v3.rs b/crates/pipeline/src/light_v3.rs index a7db45ec066..5f3e0f9bf24 100644 --- a/crates/pipeline/src/light_v3.rs +++ b/crates/pipeline/src/light_v3.rs @@ -284,7 +284,7 @@ pub fn applies(s: &DevelopSettings, info: &SourceInfo) -> bool { let camera_look = info.raw && info.camera_tone.is_some(); match s.process.process() { Process::V1 | Process::V2 | Process::V3 => false, - Process::V4 | Process::V5 | Process::V6 | Process::V7 => camera_look, + Process::V4 | Process::V5 | Process::V6 | Process::V7 | Process::V8 => camera_look, } } diff --git a/crates/pipeline/src/local.rs b/crates/pipeline/src/local.rs index 5fb9ad84ceb..0401c315338 100644 --- a/crates/pipeline/src/local.rs +++ b/crates/pipeline/src/local.rs @@ -375,7 +375,7 @@ pub fn base_detail_radius(px_per_long: f64) -> usize { pub fn tone_base_detail(s: &DevelopSettings, px_per_long: f64) -> usize { match s.process.process() { Process::V1 => 0, - Process::V2 | Process::V3 | Process::V4 | Process::V5 | Process::V6 | Process::V7 => base_detail_radius(px_per_long), + Process::V2 | Process::V3 | Process::V4 | Process::V5 | Process::V6 | Process::V7 | Process::V8 => base_detail_radius(px_per_long), } } diff --git a/crates/pipeline/src/masks.rs b/crates/pipeline/src/masks.rs index b40e3dcd974..a30ecf7e4ac 100644 --- a/crates/pipeline/src/masks.rs +++ b/crates/pipeline/src/masks.rs @@ -511,11 +511,21 @@ pub struct BrushDabs { pub auto: bool, /// Pen pressure (0..1) of each dab, parallel to `dabs`; empty when the stroke has no pressure data (full pressure). pub pressure: Vec, + /// What each dab adds under process V8 ([`travel_flow`], pressure applied), parallel to `dabs`; + /// empty before V8, where every dab adds the stroke's flow. + pub flows: Vec, } impl BrushDabs { - /// Radius, hard core and flow of dab `i`, pen pressure applied ([`pressure_radius`], [`pressure_flow`]). + /// Radius, hard core and flow of dab `i`, pen pressure applied ([`pressure_radius`], [`pressure_flow`]); + /// under process V8 the flow is what the dab adds for the distance it travelled ([`travel_flow`]). pub fn dab(&self, i: usize) -> (f64, f64, f32) { + let (r, hard, flow) = self.pressed(i); + (r, hard, self.flows.get(i).copied().unwrap_or(flow)) + } + + /// [`Self::dab`] with the stroke's flow for every dab, as before process V8. + fn pressed(&self, i: usize) -> (f64, f64, f32) { match self.pressure.get(i) { Some(&p) => { let r = pressure_radius(self.r, p); @@ -524,6 +534,46 @@ impl BrushDabs { None => (self.r, self.hard, self.flow), } } + + /// Give every dab what it adds for the distance it travelled ([`travel_flow`], process V8). + fn flow_by_travel(mut self) -> BrushDabs { + let flows = (0..self.dabs.len()) + .map(|i| { + let (r, _, flow) = self.pressed(i); + // the first dab counts one radius: a click paints its flow, as before + let dist = match (i.checked_sub(1).and_then(|j| self.dabs.get(j)), self.dabs.get(i)) { + (Some(a), Some(b)) => a.dist(*b), + _ => r, + }; + travel_flow(flow, dist, r) + }) + .collect(); + self.flows = flows; + self + } +} + +/// Whether brush Flow is the coverage a stroke adds per brush radius it travels (process V8 on), as +/// in Lightroom, rather than what every dab adds whatever the spacing of the dabs. +pub fn flow_per_radius(s: &lightcraft_develop::DevelopSettings) -> bool { + s.process.process() >= lightcraft_develop::Process::V8 +} + +/// What one dab adds to a stroke's coverage when Flow is coverage per brush radius travelled +/// (process V8): `1 − (1 − flow)^(dist / r)` for a dab `dist` past the previous one, brush radius +/// `r`. A stroke then covers a point it passes over for a length `L` by `1 − (1 − flow)^(L / r)` +/// however densely its dabs lie: a straight stroke's centre (`L` = 2 r) by 44 % at Flow 25, 75 % at +/// Flow 50 and fully at 100, as Lightroom Classic's strokes measure on a grey card (#4045). +pub fn travel_flow(flow: f32, dist: f64, r: f64) -> f32 { + if flow.is_nan() || flow <= 0.0 { + return 0.0; + } + if flow >= 1.0 { + return 1.0; + } + // (a degenerate radius or distance counts one radius; a long jump at most saturates) + let t = if r > 0.0 && dist.is_finite() { (dist / r).clamp(0.0, 64.0) } else { 1.0 }; + 1.0 - (1.0 - flow).powf(t as f32) } /// The radius of a dab of a brush of radius `r` (pixels) painted at pen pressure `p` (0..1): from a tenth of the @@ -604,7 +654,7 @@ pub fn brush_dabs_within(s: &BrushStroke, frame: &Frame, w: usize, h: usize, max prev_p = pq; } } - BrushDabs { + let bd = BrushDabs { dabs, r, hard, @@ -613,7 +663,9 @@ pub fn brush_dabs_within(s: &BrushStroke, frame: &Frame, w: usize, h: usize, max erase: s.erase, auto: s.auto_mask, pressure, - } + flows: Vec::new(), + }; + if frame.brush_flow_per_radius { bd.flow_by_travel() } else { bd } } /// Distance between consecutive dabs of a brush of radius `r` (pixels): a quarter of the radius, diff --git a/crates/pipeline/src/masks/tests.rs b/crates/pipeline/src/masks/tests.rs index b57f9f66881..649e5cc30aa 100644 --- a/crates/pipeline/src/masks/tests.rs +++ b/crates/pipeline/src/masks/tests.rs @@ -456,6 +456,72 @@ fn holding_the_brush_still_adds_no_coverage() { assert_eq!(brush_dabs(&paused, &f, w, h).dabs, brush_dabs(&smooth, &f, w, h).dabs); } +/// A straight Feather 0 stroke of radius 20 px along row 50 of a 400 × 100 frame on `process`. +fn straight_stroke(process: lightcraft_develop::Process, flow: f64, points: Vec) -> Plane { + let (w, h) = (400, 100); + let d = DevelopSettings { process: process.version(), ..Default::default() }; + let f = Frame::new(w, h, &d, true); + let s = BrushStroke { points, size: 0.05, feather: 0.0, flow, ..Default::default() }; + shape_alpha(&MaskShape::Brush { strokes: vec![s] }, &f, w, h, &Rgb32f::new(w, h), &Plane::new(w, h), 0.0, None) +} + +/// Process V8: Flow is the coverage a stroke adds per brush radius it travels, as Lightroom +/// Classic's strokes measure on a grey card (Feather 0, straight strokes, #4045): a point the brush +/// passes over for a length `L` is covered by `1 − (1 − flow)^(L / r)`, so the centre of a stroke +/// (L = 2 r) by 41 % at Flow 25, 76 % at 50 and fully at 100 (Lightroom), and a point 0.6 radii off +/// the centre line less. Process V7 adds the flow per dab, r/4 apart: 90 % at Flow 25. +#[test] +fn flow_is_coverage_per_radius_travelled_as_in_lightroom() { + use lightcraft_develop::Process; + let line = vec![Point::new(0.1, 0.5), Point::new(0.9, 0.5)]; + for (flow, lightroom) in [(25.0, 0.41), (50.0, 0.76), (100.0, 1.0)] { + let a = straight_stroke(Process::V8, flow, line.clone()); + let keep = 1.0 - flow as f32 / 100.0; + let centre = a.get(200, 50); + assert!((centre - (1.0 - keep.powi(2))).abs() < 0.03, "Flow {flow}: centre {centre}"); + assert!((centre - lightroom).abs() < 0.05, "Flow {flow}: Lightroom covers {lightroom}, here {centre}"); + // pixel row 62 is 12.5 px = 0.625 r off the line, under the brush for 2·√(1 − 0.625²) radii + let chord = 2.0 * (1.0 - 0.625f32 * 0.625).sqrt(); + let off = a.get(200, 62); + assert!((off - (1.0 - keep.powf(chord))).abs() < 0.05, "Flow {flow}: 0.6 r off the line {off}"); + assert!(off <= centre + 1e-6); + } + let old = straight_stroke(Process::V7, 25.0, line).get(200, 50); + assert!(old > 0.85, "V7 keeps the flow per dab: {old}"); +} + +/// Process V8: a stroke covers the same however densely its samples lie (a slow drag samples +/// every pixel, a fast one far apart); before V8 a slow stroke laid more dabs and built up more. +#[test] +fn flow_does_not_depend_on_how_fast_the_stroke_was_painted() { + use lightcraft_develop::Process; + let fast = vec![Point::new(0.1, 0.5), Point::new(0.9, 0.5)]; + // one sample per output pixel + let slow: Vec = (40..=360).map(|x| Point::new(x as f64 / 400.0, 0.5)).collect(); + let (f, s) = (straight_stroke(Process::V8, 25.0, fast.clone()).get(200, 50), straight_stroke(Process::V8, 25.0, slow.clone()).get(200, 50)); + assert!((f - s).abs() < 0.02, "fast {f} vs slow {s}"); + let (f7, s7) = (straight_stroke(Process::V7, 25.0, fast).get(200, 50), straight_stroke(Process::V7, 25.0, slow).get(200, 50)); + assert!(s7 > f7, "before V8 a slow stroke builds up more: {f7} vs {s7}"); +} + +/// A click (one dab) paints its flow on every process; Flow 100 paints fully. +#[test] +fn a_click_paints_its_flow() { + use lightcraft_develop::Process; + for p in [Process::V7, Process::V8] { + let a = straight_stroke(p, 40.0, vec![Point::new(0.5, 0.5)]); + assert!((a.get(200, 50) - 0.4).abs() < 1e-4, "{p:?}: {}", a.get(200, 50)); + } + assert_eq!(travel_flow(1.0, 0.25, 1.0), 1.0); + assert_eq!(travel_flow(0.0, 1.0, 1.0), 0.0); + assert_eq!(travel_flow(f32::NAN, 1.0, 1.0), 0.0); + assert!((travel_flow(0.25, 1.0, 1.0) - 0.25).abs() < 1e-6, "one radius adds the flow"); + assert!((travel_flow(0.25, 0.0, 0.0) - 0.25).abs() < 1e-6, "a degenerate radius counts one radius"); + assert!((travel_flow(0.25, f64::INFINITY, 1.0) - 0.25).abs() < 1e-6); + assert!(travel_flow(0.25, 1e12, 1.0) > 0.999 && travel_flow(0.25, 1e12, 1.0) <= 1.0); + assert!(travel_flow(0.25, -5.0, 1.0) == 0.0, "no distance adds nothing"); +} + /// Flow builds up by passes: going back over an area in the same stroke adds coverage. #[test] fn a_second_pass_builds_up_with_low_flow() { diff --git a/crates/pipeline/src/tests_grain.rs b/crates/pipeline/src/tests_grain.rs index 14172a516cd..9dc48924530 100644 --- a/crates/pipeline/src/tests_grain.rs +++ b/crates/pipeline/src/tests_grain.rs @@ -35,7 +35,7 @@ fn processes_before_v7_keep_the_value_noise() { Process::V1 | Process::V2 | Process::V3 | Process::V4 | Process::V5 | Process::V6 => { assert!(matches!(model, Some(GrainModel::Value(_))), "{p:?}") } - Process::V7 => assert!(matches!(model, Some(GrainModel::Crystal(_))), "{p:?}"), + Process::V7 | Process::V8 => assert!(matches!(model, Some(GrainModel::Crystal(_))), "{p:?}"), } assert!(GrainModel::new(&on(p, 0.0), 2000.0, false).is_none(), "{p:?}: no grain at Amount 0"); } diff --git a/crates/ui-egui/src/brush_live.rs b/crates/ui-egui/src/brush_live.rs index 1d31d44d28f..19d25f2a8f6 100644 --- a/crates/ui-egui/src/brush_live.rs +++ b/crates/ui-egui/src/brush_live.rs @@ -9,7 +9,7 @@ use egui::{Color32, ColorImage, Pos2, Rect, TextureHandle, TextureOptions, pos2}; use lightcraft_geom::Point; -use lightcraft_pipeline::masks::{accumulate, dab_alpha, pressure_flow, pressure_radius, push_dabs_counted, push_pressures}; +use lightcraft_pipeline::masks::{accumulate, dab_alpha, pressure_flow, pressure_radius, push_dabs_counted, push_pressures, travel_flow}; /// The largest live-stroke buffer edge (pixels); a bigger canvas is painted at a lower resolution. const MAX_SIDE: usize = 4096; @@ -28,6 +28,9 @@ pub struct LiveParams { /// Flow and density, 0..1. pub flow: f32, pub density: f32, + /// Flow is coverage per brush radius travelled (process V8, `masks::flow_per_radius`), as the + /// committed stroke paints it. + pub per_radius: bool, /// Overlay colour and its opacity (0..1) at full coverage. pub color: [u8; 3], pub opacity: f32, @@ -46,6 +49,8 @@ pub struct LiveStroke { last: Option, /// The pen pressure of the last stamped sample. last_pressure: f32, + /// The last dab painted (buffer pixels): how far the next one travelled. + last_dab: Option, /// Buffer pixels painted since the last upload: (x0, y0, x1, y1), exclusive ends. dirty: Option<(usize, usize, usize, usize)>, texture: Option, @@ -56,7 +61,19 @@ impl 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, emitted: 0, last: None, last_pressure: 1.0, dirty: None, texture: None } + LiveStroke { + params, + w, + h, + alpha: vec![0.0; w * h], + placed: 0, + emitted: 0, + last: None, + last_pressure: 1.0, + last_dab: None, + dirty: None, + texture: None, + } } /// Stroke coverage (0..1) at buffer pixel `(x, y)`; 0 outside. @@ -80,7 +97,7 @@ impl LiveStroke { if new.is_empty() { return false; } - let LiveParams { clip, scale, r, hard, flow, density, .. } = self.params; + let LiveParams { clip, scale, r, hard, flow, density, per_radius, .. } = self.params; let (r, hard) = ((r * scale) as f64, (hard * scale) as f64); let mut dabs = Vec::new(); let mut pressures = Vec::new(); @@ -105,6 +122,10 @@ impl LiveStroke { let r = pressure_radius(base.0, p); let hard = if base.0 > 0.0 { base.1 * r / base.0 } else { base.1 }; let flow = pressure_flow(flow, p); + // the first dab counts one radius, as the committed stroke's does + let travelled = self.last_dab.map_or(r, |a| a.dist(d)); + self.last_dab = Some(d); + let flow = if per_radius { travel_flow(flow, travelled, r) } else { flow }; 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; @@ -220,12 +241,33 @@ mod tests { hard: 5.0, flow: 1.0, density: 1.0, + per_radius: true, color: [230, 30, 40], opacity: 0.5, } } /// Issue #517: two samples far apart (a fast stroke) paint a continuous band between them, + /// Process V8: the live stroke adds Flow per brush radius travelled, as the committed one does, + /// so a slow drag (a sample every point) and a fast one cover a point the same; a stroke's centre + /// at Flow 25 is covered by 1 − 0.75² (Feather 0 here). Before V8 the slow drag built up more. + #[test] + fn flow_per_radius_does_not_depend_on_the_drag_speed() { + let p = LiveParams { flow: 0.25, hard: 10.0, ..params() }; + let paint = |per_radius: bool, step: usize| { + let mut s = LiveStroke::new(LiveParams { per_radius, ..p }); + let pts: Vec = (20..=380).step_by(step).map(|x| pos2(x as f32, 100.0)).collect(); + for n in 1..=pts.len() { + s.stamp(&pts[..n], &[]); + } + s.coverage(200, 100) + }; + let (fast, slow) = (paint(true, 360), paint(true, 1)); + assert!((fast - 0.4375).abs() < 0.03, "{fast}"); + assert!((fast - slow).abs() < 0.02, "fast {fast} vs slow {slow}"); + assert!(paint(false, 1) > paint(false, 360), "before V8 a slow drag builds up more"); + } + /// not two separate dabs. #[test] fn a_fast_segment_is_painted_continuously() { diff --git a/crates/ui-egui/src/panels/detail/masks.rs b/crates/ui-egui/src/panels/detail/masks.rs index ebcb35e6115..06891373c19 100644 --- a/crates/ui-egui/src/panels/detail/masks.rs +++ b/crates/ui-egui/src/panels/detail/masks.rs @@ -716,6 +716,7 @@ fn brush_tool( hard: r * (1.0 - (app.ui.brush_feather / 100.0).clamp(0.0, 1.0)), flow: (app.ui.brush_flow / 100.0).clamp(0.0, 1.0), density: 1.0, + per_radius: lightcraft_pipeline::masks::flow_per_radius(d), color: app.ui.mask_overlay_color, opacity: opacity.clamp(0.0, 1.0), }; diff --git a/crates/ui-egui/src/tests/masking.rs b/crates/ui-egui/src/tests/masking.rs index f7fbc605361..72aa10cca62 100644 --- a/crates/ui-egui/src/tests/masking.rs +++ b/crates/ui-egui/src/tests/masking.rs @@ -2021,6 +2021,33 @@ fn a_fast_brush_stroke_shows_without_gaps_before_the_button_is_released() { } } +/// Process V8: a Flow 25 stroke shows while the button is held as it will once committed, both +/// adding Flow per brush radius travelled (#4045): partly covered along its centre, not almost fully. +#[test] +fn a_low_flow_stroke_shows_as_it_will_be_committed() { + 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": 0.0, "brushFlow": 25.0}), T); + assert_eq!(r["ok"], true, "{r}"); + let y = 0.4; + let (photo, held) = hold_fast_stroke(&mut h, y); + let col = h.app.ui.mask_overlay_color.map(|v| v as f32); + let op = h.app.ui.mask_overlay_opacity / 100.0; + // the tint along the centreline: about 1 − 0.75² of full coverage, not the 90 % of a flow per dab + let cover: Vec = photo.iter().zip(&held).map(|(p, l)| (l[0] - p[0]) / ((col[0] - p[0]) * op)).collect(); + let mid = cover[cover.len() / 2]; + assert!((mid - 0.4375).abs() < 0.08, "live coverage {mid}"); + pointer(&mut h, json!([{"kind": "up", "x": 0.85, "y": y}])); + // (the committed mask's pin sits on the stroke) + h.app.ui.mask_pins = false; + h.settle(SETTLE); + let done = stroke_centreline(&h, y); + for (l, k) in held.iter().zip(&done) { + assert!((0..3).all(|i| (l[i] - k[i]).abs() < 24.0), "live {l:?} vs committed {k:?}"); + } +} + /// What the photo shows along the centreline of [`hold_fast_stroke`]'s stroke at height `y`, away /// from the cursor ring at its end. fn stroke_centreline(h: &Headless, y: f32) -> Vec<[f32; 3]> { diff --git a/docs/parity-checklist.md b/docs/parity-checklist.md index 471263c055b..098f54d0028 100644 --- a/docs/parity-checklist.md +++ b/docs/parity-checklist.md @@ -298,7 +298,7 @@ differences and missing bindings are in [ui-parity.md](ui-parity.md#shortcuts). | 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`, `cmd:app.openSamModelFolder`, `crates/segment`, `crates/engine/src/segment.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 stored grid is enlarged along the photo's edges (a guided filter of its logits by log luminance, so no outline spills onto the background under a raised Exposure, #3272). The model runs on its own worker thread (the UI never waits; panics become errors; a job that fails on the Mac's GPU runs again on the CPU, which then serves the rest of the session, #1974), 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, opens the configured model folder with the host opener, preserves setup on an open error, and links docs/ai-masks.md; Meta's original checkpoint installed in place of the Hugging Face one is named as such, #3378). 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`, `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); with the mask overlay hidden (O / the eye, or after a mask slider hid it) or a colour overlay at opacity 0 it is not tinted while painting either, so dodging and burning is judged on the photo, and its effect shows once the stroke is committed (#2549); coverage builds up by passes, not hold time (holding the brush still adds nothing, live or committed, #518); oversized path segments skip intermediate dabs instead of allocating a million samples; Auto Mask: dabs weighted by similarity to the colour under the dab centre, refined by a guided filter on luminance (CPU + GPU); ⇧-click draws a straight stroke from where the last stroke ended (`connect`), tapering size, feather and flow from that stroke's values when they changed; no A/B brushes; pen pressure (Brush ▸ Pen Pressure, on by default; `pressure` per point in `mask.brushStroke`) scales each dab's size (a tenth to all of it) and flow, live and committed alike, where winit reports a pen force (Windows; not macOS / Linux tablets yet); no tilt | +| 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); with the mask overlay hidden (O / the eye, or after a mask slider hid it) or a colour overlay at opacity 0 it is not tinted while painting either, so dodging and burning is judged on the photo, and its effect shows once the stroke is committed (#2549); coverage builds up by passes, not hold time (holding the brush still adds nothing, live or committed, #518); from process V8 Flow is the coverage a stroke adds per brush radius travelled, as in Lightroom Classic (a stroke's centre: 44 % at Flow 25, 75 % at 50; measured in Lightroom 41 % and 76 %), whatever the drag speed; oversized path segments skip intermediate dabs instead of allocating a million samples; Auto Mask: dabs weighted by similarity to the colour under the dab centre, refined by a guided filter on luminance (CPU + GPU); ⇧-click draws a straight stroke from where the last stroke ended (`connect`), tapering size, feather and flow from that stroke's values when they changed; no A/B brushes; pen pressure (Brush ▸ Pen Pressure, on by default; `pressure` per point in `mask.brushStroke`) scales each dab's size (a tenth to all of it) and flow, live and committed alike, where winit reports a pen force (Windows; not macOS / Linux tablets yet); no tilt | | LR-MASK-LINEAR | Linear gradient | P0 | ✅ | `cmd:tool.linear`, `cmd:mask.update`, `crates/pipeline/src/mask_space.rs` | gradients, brushes and AI selections stay on the photo's content when lens corrections, Upright, Transform or Rotate Left / Right change (`Mask.on_photo`; CPU and GPU) | | 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, respecting section eyes and the requested HDR/SDR rendition), Pick button, Refine slider; at most 64 samples (`MAX_COLOR_RANGE_SAMPLES`, render cost is pixels × samples) however the mask arrives: `mask.add` / `mask.update`, a sidecar's `lc:settings`, a preset, `develop.merge`, `render --settings` or the catalog and history keep the first 64 (issue #2556) | @@ -802,6 +802,7 @@ Latin stays upright. Advanced Japanese composition remains open. Regression cove | Date | Change | Summary | |---|---|---| +| 2026-11-10 | minor | LR-MASK-BRUSH: process V8 makes Flow coverage per brush radius travelled, as Lightroom Classic's strokes measure on a grey card, live and committed, CPU and GPU (`masks::travel_flow`; `flow_is_coverage_per_radius_travelled_as_in_lightroom`); a stroke no longer builds up more when painted slowly; status unchanged (🟡: no A/B brushes) | | 2026-11-07 | correction | Compressed ORF sensor support withdrawn pending provenance review; embedded preview fallback remains. Coverage regenerated without the removed decoder: 557 verified, 665 unverified, 187 preview-only, 37 unsupported; 94% use-weighted coverage. | | 2026-11-04 | minor | Compressed ORF support was introduced in #3775; subsequently withdrawn pending provenance review. Earlier clean-room and verification claims are withdrawn; compressed files use embedded previews when available. See [ORF status](orf-compression.md). | | 2026-10-28 | minor | KEY-HIDEPINS ✅ → 🟡: in the Masking panel an unmodified H toggles the mask pins (`view.maskPins`, the View ▸ Show Mask Pins switch) instead of opening Remove; the toggle yields only to an explicit assignment of H itself, a Remove key reassigned to anything else still opens Remove there, and outside Masking — and the full-screen preview, where no panel shows — H keeps its own binding (Remove, by default). Remove's spot pins keep ⇧H as their only hide toggle (`tests/keymap` `h_toggles_the_mask_pins_while_masking`, `a_remapped_remove_key_still_opens_remove_while_masking`, `h_still_toggles_the_pins_when_remove_moves_to_another_key`) | diff --git a/docs/process-versions.md b/docs/process-versions.md index b27367ed6f8..cdf7f6c4a2c 100644 --- a/docs/process-versions.md +++ b/docs/process-versions.md @@ -15,7 +15,8 @@ stronger Light sliders, issue #196) without changing a single photo someone has | **V4** | V3 plus calibrated global Contrast (per channel) and Blacks (per-channel/luminance mix) on raws with a camera tone curve. Whites behaves exactly as V2, both signs; its calibration is a planned follow-up. Other sources and local adjustments retain V2 operators. See [calibrated Light operators](light-v3.md). | | **V5** | V4 plus: a raw's tone curve rolls off into white in stops instead of reaching it within about a stop of the sensor's white, so raising Exposure keeps the highlights the sensor recorded (issue #1632). **Camera curve** (the look fitted to the embedded JPEG, or a DNG's `ProfileToneCurve`; `CameraTone`): past its last knot `CameraTone::apply_rolloff` closes the gap to white by `gap / (1 + c·(2^t − 1))` at `t` stops past the knot, with `c` matching the curve's slope there and the gap halving every stop in the end (`tone::ROLLOFF_STOPS`); `ToneMap::camera_rolloff_hdr` builds the table from it. Under V1 to V4 the curve past its last knot (fitted only to camera JPEG tones below 0.85, so 1 to 3 stops below the sensor's white on most photos) closes on white exponentially in linear light: the sensor's white renders at 8-bit 246 to 254 at Exposure 0 and 254 to 255 from Exposure +1. On the 11 CC0 corpus files with a fitted look (8 Sony, 2 Nikon, 1 Fujifilm) it now renders at 239 to 250 at Exposure 0 and 247 to 253 at +1. A DNG curve that reaches white at the sensor's white renders as before. **Generic curve** (raws without a camera curve, `ToneMap::rolloff_hdr`): from half a stop below its white point (`tone::GENERIC_KNEE_STOPS`) the same shoulder takes over, with the extended Reinhard curve's value and slope at the join, where V1 to V4 clip at the white point (scene 1.18 at default settings, ¼ stop above the sensor's white). The sensor's white renders at about 235, 248 and 252 at Exposure 0, +1 and +2 (V1 to V4: 239, 255, 255; the CC0 Canon R8 file and 6 CC0 DNGs without a camera curve). Content past the old clip point, such as a clipped sky, now renders up to 15 codes below white at Exposure 0 and reaches 255 about 5 stops past the sensor's white. Below the last knot or the join, JPEGs and other display-referred sources, and the camera fit itself are unchanged; CPU and GPU share the tone LUT. | | **V6** | V5 plus: colour noise reduction filters the linear colour differences R−Y and B−Y with the joint method (issue #815, `docs/nr-color-joint.md`): edge-aware weights from a denoised guide shared by both differences, anisotropic diffusion over scales, a brake for isolated colour specks; Y is kept exactly. V1 to V5 keep the blurred chromaticity (`local::denoise`). CPU (`local::denoise`) and GPU (`render::denoise`) branch on `local::joint_colour_nr`. Renders with Color 0 are the same as V2's. | -| **V7** (the latest) | V6 plus: film grain from crystal layers ([grain.md](grain.md), `crates/pipeline/src/crystal.rs`), after Aurélien Pierre's model: resolution independent (a preview is the export's grain box-downscaled), fading out at black and white, calibrated to Lightroom Classic's strength and width at mid grey. V1 to V6 keep their two-octave value noise exactly (`finish::ValueGrain`; on the GPU `F_GRAIN_MODEL` 0); `finish::GrainModel::new` picks the model per process. Renders without grain don't depend on this. | +| **V7** | V6 plus: film grain from crystal layers ([grain.md](grain.md), `crates/pipeline/src/crystal.rs`), after Aurélien Pierre's model: resolution independent (a preview is the export's grain box-downscaled), fading out at black and white, calibrated to Lightroom Classic's strength and width at mid grey. V1 to V6 keep their two-octave value noise exactly (`finish::ValueGrain`; on the GPU `F_GRAIN_MODEL` 0); `finish::GrainModel::new` picks the model per process. Renders without grain don't depend on this. | +| **V8** (the latest) | V7 plus: brush Flow is the coverage a stroke adds per brush radius it travels, as in Lightroom Classic (#4045): each dab adds `1 − (1 − flow)^(d / r)` for a dab `d` past the previous one (the first dab counts one radius, so a click paints its flow), `masks::travel_flow`. A point a stroke passes over for a length `L` is then covered by `1 − (1 − flow)^(L / r)` however densely the dabs lie: a straight stroke's centre by 44 % at Flow 25 and 75 % at Flow 50, where Lightroom Classic measures 41 % and 76 % on a grey card. V1 to V7 add the full flow per dab (r/4 apart on a fast drag, closer on a slow one): 90 % at Flow 25 on a fast stroke, more on a slow one. CPU (`masks::brush_dabs_within`), GPU (a flow per dab in the `shape` kernel's brush data) and the live stroke (`brush_live`) all branch on `masks::flow_per_radius`. Renders without brush masks, or with Flow 100 only, are the same as V7's. | ## The rule @@ -111,6 +112,7 @@ extra field and retain their existing cached renders. No cache-version bump is n | Date | Change | Summary | |---|---|---| +| 2026-11-10 | minor | V8: brush Flow per brush radius travelled, as in Lightroom Classic; V1 to V7 keep the flow per dab | | 2026-11-07 | minor | V7: film grain from crystal layers ([grain.md](grain.md)); V1 to V6 keep their value noise | | 2026-11-05 | minor | V5: a raw's tone curve rolls off into white in stops, so raising Exposure keeps recorded highlights (#1632) | | 2026-10-12 | minor | Calibrated Contrast and Blacks, V2 Whites, resolved-process cache keys and number coordination | diff --git a/docs/whats-new.md b/docs/whats-new.md index 56fc27ed793..dff197e8488 100644 --- a/docs/whats-new.md +++ b/docs/whats-new.md @@ -2,6 +2,11 @@ ## Unreleased +### Brush Flow as in Lightroom (process V8) +- Flow now builds up the way it does in Lightroom: one stroke at Flow 25 covers a little under half, at Flow 50 about + three quarters, where it used to cover 90 % and more, and a slow stroke covers the same as a fast one (issue #4045). + New photos (and Reset) get it; photos you already edited keep their brushes until Photo ▸ Update to Current Process. + ### Film grain that looks like film (process V7) - Grain now comes from a simulated emulsion of crystal layers (after Aurélien Pierre's model): dense, soft and cloudy rather than dots on top of the photo. It fades out towards black and white as on a print, so shadows keep their depth From fb2085c77e4f53ead86c34b832bb0b31dd3d86f4 Mon Sep 17 00:00:00 2001 From: Dimitrij Denissenko Date: Tue, 10 Nov 2026 10:09:08 +0000 Subject: [PATCH 2/3] LR-MASK-BRUSH: GPU equivalence of a Flow 25 brush on process V8 (review of #4047) --- crates/gpu/tests/it/equivalence.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crates/gpu/tests/it/equivalence.rs b/crates/gpu/tests/it/equivalence.rs index 15550cfb743..780f31a1306 100644 --- a/crates/gpu/tests/it/equivalence.rs +++ b/crates/gpu/tests/it/equivalence.rs @@ -434,6 +434,20 @@ fn cases() -> Vec<(&'static str, Edit)> { }, ]; }), + ("masks (brush, process V8: flow per radius travelled)", |s| { + s.process = lightcraft_develop::Process::V8.version(); + let stroke = BrushStroke { + points: vec![Point::new(0.1, 0.3), Point::new(0.5, 0.4), Point::new(0.8, 0.35)], + size: 0.04, + flow: 25.0, + ..Default::default() + }; + s.masks = vec![Mask { + components: vec![MaskComponent { name: None, op: MaskOp::Add, invert: false, shape: MaskShape::Brush { strokes: vec![stroke] } }], + adjust: lightcraft_develop::LocalAdjustments { exposure: -1.0, ..Default::default() }, + ..Default::default() + }]; + }), ("masks (brush, process V7: flow per dab)", |s| { s.process = lightcraft_develop::Process::V7.version(); let stroke = BrushStroke { From d51c3da2cc108178f72d3004a47bdf2c2b3a0939 Mon Sep 17 00:00:00 2001 From: Dimitrij Denissenko Date: Tue, 24 Nov 2026 18:40:21 +0000 Subject: [PATCH 3/3] Heal: the pinned heal is checked on V14 and every later process, not only while V14 is the latest the_process_picks_the_heal asserted Process::LATEST == V14; V15 (brush Flow) is newer and keeps the pinned heal. --- crates/pipeline/src/spots/pinned.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/pipeline/src/spots/pinned.rs b/crates/pipeline/src/spots/pinned.rs index 983afe014d7..8d4e36bd435 100644 --- a/crates/pipeline/src/spots/pinned.rs +++ b/crates/pipeline/src/spots/pinned.rs @@ -301,8 +301,10 @@ mod tests { for p in [Process::V8, Process::V10, Process::V13] { assert_eq!(HealMethod::of(&on(p)), HealMethod::Averaged, "{p:?}"); } - assert_eq!(HealMethod::of(&on(Process::V14)), HealMethod::Pinned); - assert_eq!(Process::LATEST, Process::V14); + // V14 and every later process keep the pinned heal + for p in Process::ALL.into_iter().filter(|p| *p >= Process::V14) { + assert_eq!(HealMethod::of(&on(p)), HealMethod::Pinned, "{p:?}"); + } assert_eq!(HealMethod::of(&DevelopSettings::default()), HealMethod::Pinned, "new photos get the latest process"); }