Skip to content

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

LR-REM-SPOT-EDIT + LR-REM-BRUSH-PARAMS: select, move, resize, refresh and delete spots; brush keys

Brandon Thomasd91aaa4ca177
diff --git a/crates/engine/src/cmd/library.rs b/crates/engine/src/cmd/library.rs
index 4cbfc22d3..32239656a 100644
--- a/crates/engine/src/cmd/library.rs
+++ b/crates/engine/src/cmd/library.rs
@@ -45,6 +45,7 @@ fn step(s: &mut Session, d: isize) -> Result<Value> {
s.end_interaction()?;
s.selection = Selection::single(vis[next]);
s.active_mask = None;
+ s.active_spot = None;
Ok(json!({"active": vis[next].0}))
}
@@ -169,6 +170,7 @@ pub fn specs() -> Vec<CommandSpec> {
other => return Err(bad("library.select", format!("unknown mode `{other}`"))),
}
s.active_mask = None;
+ s.active_spot = None;
Ok(json!({"selected": s.selection.ids.len()}))
}),
cmd!("library.selectAll", "Select All", ["Edit"], Some("Cmd+A"), "{}", always, |s, _| {
diff --git a/crates/engine/src/cmd/masks.rs b/crates/engine/src/cmd/masks.rs
index 0db1c58c4..a09cecbb1 100644
--- a/crates/engine/src/cmd/masks.rs
+++ b/crates/engine/src/cmd/masks.rs
@@ -251,7 +251,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Add Remove Spot",
[],
None,
- "{mode?: remove|heal|clone, points: [[x,y],…], size?: fraction of long edge, feather?, opacity?, source?: [dx,dy]}",
+ "{mode?: remove|heal|clone, points: [[x,y],…], size?: fraction of long edge, feather?, opacity?, source?: [dx,dy] (default: the best match nearby)} — selects the new spot; returns {index}",
has_active,
|s, p| {
let mode: SpotMode =
@@ -265,31 +265,113 @@ pub fn specs() -> Vec<CommandSpec> {
return Err(bad("spot.add", "missing points"));
}
let d = Spot::default();
- let spot = Spot {
+ let mut spot = Spot {
mode,
points: pts,
- size: f64_or(p, "size", d.size),
- feather: f64_or(p, "feather", d.feather),
- opacity: f64_or(p, "opacity", d.opacity),
+ size: f64_or(p, "size", d.size).clamp(SPOT_SIZE.0, SPOT_SIZE.1),
+ feather: f64_or(p, "feather", d.feather).clamp(0.0, 100.0),
+ opacity: f64_or(p, "opacity", d.opacity).clamp(0.0, 100.0),
source_offset: point(p, "source"),
};
let id = s.active().ok_or_else(|| bad("spot.add", "no active photo"))?;
let mut dd = (*s.develop_of(id).unwrap_or_default()).clone();
+ if spot.source_offset.is_none() {
+ // resolve the automatic source now: it gets a pin and stays put at every size
+ spot.source_offset = pick_source(s, id, &dd, &spot, None);
+ }
dd.spots.push(spot);
let n = dd.spots.len();
s.set_develop(id, dd, "Remove")?;
+ s.active_spot = Some(n - 1);
Ok(json!({"index": n - 1}))
}
),
- cmd!("spot.delete", "Delete Spot", [], None, "{index}", has_active, |s, p| {
- let i = super::f64_req(p, "index", "spot.delete")? as usize;
- let id = s.active().ok_or_else(|| bad("spot.delete", "no active photo"))?;
- let mut dd = (*s.develop_of(id).unwrap_or_default()).clone();
- if i >= dd.spots.len() {
- return Err(bad("spot.delete", "no such spot"));
+ cmd!("spot.select", "Select Spot", [], None, "{index|null}", has_active, |s, p| {
+ let n = spots_len(s);
+ s.active_spot = match p.get("index").and_then(Value::as_u64) {
+ Some(i) if (i as usize) < n => Some(i as usize),
+ Some(_) => return Err(bad("spot.select", "no such spot")),
+ None => None,
+ };
+ Ok(json!({"activeSpot": s.active_spot}))
+ }),
+ cmd!(
+ "spot.update",
+ "Edit Spot",
+ [],
+ None,
+ "{index? (the selected spot), move?: [dx,dy] (the target, normalized), source?: [dx,dy] (offset from the target), moveSource?: [dx,dy], size?, feather?, opacity?, mode?}",
+ has_active,
+ |s, p| {
+ let c = "spot.update";
+ let i = spot_index(s, p, c)?;
+ let mode: Option<SpotMode> = match p.get("mode") {
+ Some(m) => Some(serde_json::from_value(m.clone()).map_err(|e| bad(c, e.to_string()))?),
+ None => None,
+ };
+ spots_edit(s, c, "Edit Spot", |spots| {
+ let sp = &mut spots[i];
+ if let Some(d) = point(p, "move") {
+ sp.points.iter_mut().for_each(|q| *q = Point::new(q.x + d.x, q.y + d.y));
+ // the source moves along (its offset is relative to the target)
+ }
+ if let Some(o) = point(p, "source") {
+ sp.source_offset = Some(o);
+ }
+ if let Some(d) = point(p, "moveSource") {
+ let o = sp.source_offset.unwrap_or(Point::new(0.0, 0.0));
+ sp.source_offset = Some(Point::new(o.x + d.x, o.y + d.y));
+ }
+ if let Some(v) = p.get("size").and_then(Value::as_f64) {
+ sp.size = v.clamp(SPOT_SIZE.0, SPOT_SIZE.1);
+ }
+ if let Some(v) = p.get("feather").and_then(Value::as_f64) {
+ sp.feather = v.clamp(0.0, 100.0);
+ }
+ if let Some(v) = p.get("opacity").and_then(Value::as_f64) {
+ sp.opacity = v.clamp(0.0, 100.0);
+ }
+ if let Some(m) = mode {
+ sp.mode = m;
+ }
+ Ok(())
+ })?;
+ Ok(json!({"index": i}))
+ }
+ ),
+ cmd!(
+ "spot.refreshSource",
+ "Refresh Source",
+ [],
+ None,
+ "{index? (the selected spot)} — picks the next-best source away from the current one",
+ has_active,
+ |s, p| {
+ let c = "spot.refreshSource";
+ let i = spot_index(s, p, c)?;
+ let id = s.active().ok_or_else(|| bad(c, "no active photo"))?;
+ let dd = (*s.develop_of(id).unwrap_or_default()).clone();
+ let spot = dd.spots[i].clone();
+ let next = pick_source(s, id, &dd, &spot, spot.source_offset).ok_or_else(|| bad(c, "no other source fits in the photo"))?;
+ spots_edit(s, c, "Refresh Source", |spots| {
+ spots[i].source_offset = Some(next);
+ Ok(())
+ })?;
+ Ok(json!({"index": i, "source": [next.x, next.y]}))
}
- dd.spots.remove(i);
- s.set_develop(id, dd, "Delete Spot")?;
+ ),
+ cmd!("spot.delete", "Delete Spot", [], None, "{index? (the selected spot)}", has_active, |s, p| {
+ let c = "spot.delete";
+ let i = spot_index(s, p, c)?;
+ spots_edit(s, c, "Delete Spot", |spots| {
+ spots.remove(i);
+ Ok(())
+ })?;
+ s.active_spot = match s.active_spot {
+ Some(a) if a == i => None,
+ Some(a) if a > i => Some(a - 1),
+ a => a,
+ };
ok()
}),
// ---- Red eye / pet eye
@@ -358,6 +440,36 @@ pub fn specs() -> Vec<CommandSpec> {
]
}
+/// Spot radius limits (fraction of the long edge).
+pub const SPOT_SIZE: (f64, f64) = (0.001, 0.25);
+
+fn spots_len(s: &Session) -> usize {
+ s.active().and_then(|id| s.develop_of(id)).map(|d| d.spots.len()).unwrap_or(0)
+}
+
+/// `index` from the params, else the selected spot.
+fn spot_index(s: &Session, p: &Value, c: &str) -> Result<usize> {
+ let i = p.get("index").and_then(Value::as_u64).map(|v| v as usize).or(s.active_spot).ok_or_else(|| bad(c, "no spot selected (give `index`)"))?;
+ if i >= spots_len(s) {
+ return Err(bad(c, "no such spot"));
+ }
+ Ok(i)
+}
+
+fn spots_edit(s: &mut Session, c: &str, label: &str, f: impl FnOnce(&mut Vec<Spot>) -> Result<()>) -> Result<()> {
+ let id = s.active().ok_or_else(|| bad(c, "no active photo"))?;
+ let mut d = (*s.develop_of(id).unwrap_or_default()).clone();
+ f(&mut d.spots)?;
+ s.set_develop(id, d, label)
+}
+
+/// An automatic source for `spot` on photo `id` (a small proxy of the photo, framed by `d`).
+fn pick_source(s: &mut Session, id: crate::PhotoId, d: &lightcraft_develop::DevelopSettings, spot: &Spot, avoid: Option<Point>) -> Option<Point> {
+ let src = s.source_now(id, crate::media::SourceLevel::Thumb).ok()?;
+ let info = crate::media::source_info(s.catalog.photo(id)?);
+ lightcraft_pipeline::spots::pick_source(&src, &info, d, spot, avoid)
+}
+
fn clamp_local(mut a: LocalAdjustments) -> LocalAdjustments {
let c = |v: &mut f64, lo: f64, hi: f64| *v = if v.is_finite() { v.clamp(lo, hi) } else { 0.0 };
c(&mut a.exposure, -4.0, 4.0);
diff --git a/crates/engine/src/cmd/query.rs b/crates/engine/src/cmd/query.rs
index b705791aa..bbaf0dcec 100644
--- a/crates/engine/src/cmd/query.rs
+++ b/crates/engine/src/cmd/query.rs
@@ -89,6 +89,7 @@ pub fn specs() -> Vec<CommandSpec> {
"selection": s.selection,
"visibleCount": n,
"activeMask": s.active_mask,
+ "activeSpot": s.active_spot,
"undo": s.undo.last().map(|u| u.label.clone()),
"redo": s.redo.last().map(|u| u.label.clone()),
"clipboard": s.clipboard.is_some(),
diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs
index f022268ed..789a7b452 100644
--- a/crates/engine/src/lib.rs
+++ b/crates/engine/src/lib.rs
@@ -91,6 +91,8 @@ pub struct Session {
depth: u32,
/// Selected mask (Masking panel), by mask id.
pub active_mask: Option<u32>,
+ /// Selected spot (Remove panel), by index into the active photo's spots.
+ pub active_spot: Option<usize>,
/// The persistent library this session writes to (`None` = in-memory only).
pub library: Option<library::Library>,
/// XMP sidecar preferences (persisted with the library).
@@ -127,6 +129,7 @@ impl Session {
clock: Box::new(|| "2026-09-30T12:00:00".to_string()),
depth: 0,
active_mask: None,
+ active_spot: None,
library: None,
xmp: sidecar::XmpPrefs::default(),
last_export: None,
@@ -346,4 +349,6 @@ mod tests_merge;
#[cfg(test)]
mod tests_organize;
#[cfg(test)]
+mod tests_spots;
+#[cfg(test)]
mod tests_xmp;
diff --git a/crates/engine/src/tests_spots.rs b/crates/engine/src/tests_spots.rs
new file mode 100644
index 000000000..16bfe52b9
--- /dev/null
+++ b/crates/engine/src/tests_spots.rs
@@ -0,0 +1,57 @@
+//! Remove tool commands: add (automatic source), select, move target/source, edit, refresh, delete.
+
+use serde_json::json;
+
+use crate::Session;
+
+fn spots(s: &Session) -> Vec<lightcraft_develop::Spot> {
+ s.develop_of(s.active().unwrap()).unwrap().spots.clone()
+}
+
+#[test]
+fn spots_select_move_edit_refresh_and_delete() {
+ let mut s = Session::with_demo();
+ // a remove spot gets a resolved source (a pin to show) and is selected
+ let r = s.execute("spot.add", &json!({"points": [[0.4, 0.5]], "size": 0.02})).unwrap();
+ assert_eq!(r["index"], 0);
+ assert_eq!(s.active_spot, Some(0));
+ let src0 = spots(&s)[0].source_offset.expect("automatic source resolved");
+ assert!(src0.x.hypot(src0.y) > 0.02, "the source is outside the spot: {src0:?}");
+ s.execute("spot.add", &json!({"mode": "clone", "points": [[0.7, 0.3]], "source": [0.1, 0.0]})).unwrap();
+ assert_eq!(s.active_spot, Some(1));
+ assert_eq!(s.execute("library.state", &json!({})).unwrap()["activeSpot"], 1);
+ // select
+ s.execute("spot.select", &json!({"index": 0})).unwrap();
+ assert_eq!(s.active_spot, Some(0));
+ assert!(s.execute("spot.select", &json!({"index": 9})).is_err());
+ // move the target (the source follows: its offset is relative), then the source alone
+ s.execute("spot.update", &json!({"move": [0.05, -0.1]})).unwrap();
+ let sp = &spots(&s)[0];
+ assert!((sp.points[0].x - 0.45).abs() < 1e-9 && (sp.points[0].y - 0.4).abs() < 1e-9);
+ assert_eq!(sp.source_offset, Some(src0));
+ s.execute("spot.update", &json!({"moveSource": [0.01, 0.02]})).unwrap();
+ let o = spots(&s)[0].source_offset.unwrap();
+ assert!((o.x - src0.x - 0.01).abs() < 1e-9 && (o.y - src0.y - 0.02).abs() < 1e-9);
+ // size / feather / opacity of the selected spot (clamped), one undo step each
+ s.execute("spot.update", &json!({"size": 0.03, "feather": 20, "opacity": 150})).unwrap();
+ let sp = &spots(&s)[0];
+ assert_eq!((sp.size, sp.feather, sp.opacity), (0.03, 20.0, 100.0));
+ s.execute("edit.undo", &json!({})).unwrap();
+ assert_eq!(spots(&s)[0].size, 0.02);
+ // refresh: a different source, at least a spot radius away
+ let before = spots(&s)[0].source_offset.unwrap();
+ let r = s.execute("spot.refreshSource", &json!({})).unwrap();
+ let after = spots(&s)[0].source_offset.unwrap();
+ assert!((after.x - before.x).hypot(after.y - before.y) > 0.01, "{r}");
+ // delete the selected spot: the selection clears; deleting before a selected one shifts it
+ s.execute("spot.delete", &json!({})).unwrap();
+ assert_eq!((spots(&s).len(), s.active_spot), (1, None));
+ assert_eq!(spots(&s)[0].mode, lightcraft_develop::SpotMode::Clone);
+ assert!(s.execute("spot.delete", &json!({})).is_err(), "nothing selected");
+ s.execute("spot.add", &json!({"points": [[0.2, 0.2]], "source": [0.05, 0.0]})).unwrap();
+ s.execute("spot.delete", &json!({"index": 0})).unwrap();
+ assert_eq!(s.active_spot, Some(0));
+ // another photo: no selection
+ s.execute("library.next", &json!({})).unwrap();
+ assert_eq!(s.active_spot, None);
+}
diff --git a/crates/pipeline/src/spots.rs b/crates/pipeline/src/spots.rs
index 3e79f67c0..f9edff72c 100644
--- a/crates/pipeline/src/spots.rs
+++ b/crates/pipeline/src/spots.rs
@@ -54,20 +54,56 @@ fn score(img: &Rgb32f, target: (f32, f32), source: (f32, f32), r: f32) -> f32 {
s
}
-/// Pick a source offset (in output pixels) for a remove/heal spot.
-pub fn auto_source(img: &Rgb32f, target: (f32, f32), r: f32) -> (f32, f32) {
- let mut best = (f32::MAX, (r * 2.5, 0.0));
+/// Candidate source offsets (output pixels) for a spot of radius `r` at `target`, best first
+/// (candidates reaching outside the image are left out).
+pub fn ranked_sources(img: &Rgb32f, target: (f32, f32), r: f32) -> Vec<(f32, f32)> {
+ let mut c: Vec<(f32, (f32, f32))> = Vec::new();
for ring in [2.4f32, 3.2, 4.2] {
for i in 0..16 {
let a = i as f32 / 16.0 * std::f32::consts::TAU;
let d = (a.cos() * r * ring, a.sin() * r * ring);
let s = score(img, target, (target.0 + d.0, target.1 + d.1), r);
- if s < best.0 {
- best = (s, d);
+ if s < f32::MAX {
+ c.push((s, d));
}
}
}
- best.1
+ c.sort_by(|a, b| a.0.total_cmp(&b.0));
+ c.into_iter().map(|(_, d)| d).collect()
+}
+
+/// Pick a source offset (in output pixels) for a remove/heal spot.
+pub fn auto_source(img: &Rgb32f, target: (f32, f32), r: f32) -> (f32, f32) {
+ ranked_sources(img, target, r).first().copied().unwrap_or((r * 2.5, 0.0))
+}
+
+/// A source offset (normalized, as [`Spot::source_offset`]) for `spot` on `src` developed with
+/// `s`: the best match, or with `avoid` (the current offset) the best one at least a spot radius
+/// away from it ("refresh source"). `None` when no candidate fits in the image.
+pub fn pick_source(
+ src: &Rgb32f,
+ info: &crate::SourceInfo,
+ s: &lightcraft_develop::DevelopSettings,
+ spot: &Spot,
+ avoid: Option<Point>,
+) -> Option<Point> {
+ let frame = crate::frame_for(src, info, s, true);
+ let (w, h) = frame.fit(512, 512);
+ if w == 0 || h == 0 {
+ return None;
+ }
+ let img = frame.sample(src, w, h);
+ let (to_out, to_norm) = (frame.norm_to_out(w, h), frame.out_to_norm(w, h));
+ let t = to_out.apply(*spot.points.first()?);
+ let r = (spot.size * frame.px_per_long(w)).max(1.0) as f32;
+ let avoid = avoid.map(|o| {
+ let (a, b) = (to_out.apply(Point::new(0.0, 0.0)), to_out.apply(o));
+ ((b.x - a.x) as f32, (b.y - a.y) as f32)
+ });
+ let far = |d: &(f32, f32)| avoid.is_none_or(|a| ((d.0 - a.0).powi(2) + (d.1 - a.1).powi(2)).sqrt() > r);
+ let d = ranked_sources(&img, (t.x as f32, t.y as f32), r).into_iter().find(far)?;
+ let (n0, n1) = (to_norm.apply(t), to_norm.apply(Point::new(t.x + d.0 as f64, t.y + d.1 as f64)));
+ Some(Point::new(n1.x - n0.x, n1.y - n0.y))
}
/// Apply all spots to `img` (output resolution). `ppl` = output pixels per long-edge unit.
diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs
index 16a9240db..913cdab83 100644
--- a/crates/ui-egui/src/control.rs
+++ b/crates/ui-egui/src/control.rs
@@ -101,6 +101,8 @@ fn key_from(name: &str) -> Option<egui::Key> {
"tab" => Some(egui::Key::Tab),
"\\" | "backslash" => Some(egui::Key::Backslash),
"/" | "slash" => Some(egui::Key::Slash),
+ "[" => Some(egui::Key::OpenBracket),
+ "]" => Some(egui::Key::CloseBracket),
_ => None,
})
}
diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs
index fe287a1ee..df5d4d5ff 100644
--- a/crates/ui-egui/src/menus.rs
+++ b/crates/ui-egui/src/menus.rs
@@ -63,6 +63,11 @@ pub const UI_COMMANDS: &[UiCommand] = &[
("tool.radial", "Radial Gradient", Some("R"), "Window>Tools"),
("tool.wbPicker", "White Balance Selector", Some("W"), "Window>Tools"),
("tool.none", "No Tool", None, ""),
+ // brush size / feather of the active brush (Masking brush, Remove tool and its selected spot)
+ ("brush.smaller", "Decrease Brush Size", Some("["), "Window>Tools"),
+ ("brush.larger", "Increase Brush Size", Some("]"), "Window>Tools"),
+ ("brush.featherLess", "Decrease Brush Feather", Some("Shift+["), "Window>Tools"),
+ ("brush.featherMore", "Increase Brush Feather", Some("Shift+]"), "Window>Tools"),
("dialog.newAlbum", "New Album…", Some("Cmd+N"), "File"),
("dialog.newFolder", "New Folder…", Some("Cmd+Shift+N"), "File"),
("dialog.newSmartAlbum", "New Smart Album from Filter…", Some("Cmd+Alt+N"), "File"),
@@ -100,6 +105,30 @@ fn panel(app: &mut LightcraftApp, ctx: &egui::Context, p: RightPanel, name: &str
let _ = app.session.end_interaction();
}
+/// `[` / `]` (size ×`k`) and ⇧`[` / ⇧`]` (feather +`df`) for the brush in use: the Remove tool's
+/// (and its selected spot's) or the Masking brush's.
+fn adjust_brush(app: &mut LightcraftApp, k: f32, df: f32) -> Value {
+ if app.ui.right == RightPanel::Remove {
+ app.ui.remove_size = (app.ui.remove_size * k).clamp(0.001, 0.25);
+ app.ui.remove_feather = (app.ui.remove_feather + df).clamp(0.0, 100.0);
+ if app.session.active_spot.is_some() {
+ let mut p = json!({});
+ if k != 1.0 {
+ p["size"] = json!(app.ui.remove_size);
+ }
+ if df != 0.0 {
+ p["feather"] = json!(app.ui.remove_feather);
+ }
+ let _ = app.run("spot.update", p);
+ }
+ json!({"size": app.ui.remove_size, "feather": app.ui.remove_feather})
+ } else {
+ app.ui.brush_size = (app.ui.brush_size * k).clamp(0.002, 0.5);
+ app.ui.brush_feather = (app.ui.brush_feather + df).clamp(0.0, 100.0);
+ json!({"size": app.ui.brush_size, "feather": app.ui.brush_feather})
+ }
+}
+
/// An sRGB colour from `"#rrggbb"` or `[r, g, b]` (0..255).
pub fn parse_rgb(v: &Value) -> Option<[u8; 3]> {
if let Some(s) = v.as_str() {
@@ -252,6 +281,15 @@ pub fn run_ui_command(app: &mut LightcraftApp, id: &str, p: &Value) -> Option<Re
let [r, g, b] = app.ui.mask_overlay_color;
Ok(json!({"color": format!("#{r:02x}{g:02x}{b:02x}"), "opacity": app.ui.mask_overlay_opacity}))
}
+ "brush.smaller" | "brush.larger" | "brush.featherLess" | "brush.featherMore" => {
+ let (k, df) = match id {
+ "brush.smaller" => (1.0 / 1.2, 0.0),
+ "brush.larger" => (1.2, 0.0),
+ "brush.featherLess" => (1.0, -10.0),
+ _ => (1.0, 10.0),
+ };
+ Ok(adjust_brush(app, k, df))
+ }
"view.maskPins" => {
app.ui.mask_pins = p.get("show").and_then(Value::as_bool).unwrap_or(!app.ui.mask_pins);
Ok(json!({"maskPins": app.ui.mask_pins}))
diff --git a/crates/ui-egui/src/panels/detail.rs b/crates/ui-egui/src/panels/detail.rs
index 6491ae41b..9c77ebc6e 100644
--- a/crates/ui-egui/src/panels/detail.rs
+++ b/crates/ui-egui/src/panels/detail.rs
@@ -23,6 +23,11 @@ pub enum Gesture {
Spot {
points: Vec<Point>,
},
+ /// Remove tool: dragging spot `spot`'s target (or its source).
+ SpotMove {
+ spot: usize,
+ source: bool,
+ },
CropHandle {
handle: u8,
start: lightcraft_geom::Rect,
@@ -795,19 +800,89 @@ fn pin(p: &egui::Painter, c: Pos2, sel: bool) {
// ------------------------------------------------------------------------ remove
+/// The Remove tool on the photo: every spot's outline and pin (the selected one with its source),
+/// click a pin to select its spot, drag a target or source to move it, paint elsewhere to add one.
fn remove_overlay(app: &mut LightcraftApp, ui: &mut egui::Ui, resp: &egui::Response, map: &CanvasMap, d: &DevelopSettings) {
let long = (map.rect.width().max(map.rect.height())) as f64;
- let p = ui.painter();
- for s in &d.spots {
+ let p = ui.painter_at(app.canvas_rect.unwrap_or(map.rect));
+ let active = app.session.active_spot.filter(|i| *i < d.spots.len());
+ // (spot, is source, screen centre, radius) of everything that can be grabbed
+ let mut grips: Vec<(usize, bool, Pos2, f32)> = Vec::new();
+ for (i, s) in d.spots.iter().enumerate() {
let r = (s.size * long) as f32;
+ let sel = Some(i) == active;
+ let col = Color32::from_white_alpha(if sel { 230 } else { 150 });
for q in &s.points {
- p.circle_stroke(map.screen(*q), r, Stroke::new(1.0, Color32::from_white_alpha(200)));
+ p.circle_stroke(map.screen(*q), r, Stroke::new(if sel { 1.5 } else { 1.0 }, col));
+ }
+ let Some(&t) = s.points.first() else { continue };
+ let tq = map.screen(t);
+ if let Some(o) = s.source_offset.filter(|_| sel) {
+ let sq = map.screen(Point::new(t.x + o.x, t.y + o.y));
+ for q in &s.points {
+ p.circle_stroke(map.screen(Point::new(q.x + o.x, q.y + o.y)), r, Stroke::new(1.0, Color32::from_white_alpha(170)));
+ }
+ let dir = (tq - sq).normalized();
+ p.arrow(sq + dir * r, (tq - sq) - dir * (2.0 * r).min((tq - sq).length()), Stroke::new(1.0, Color32::from_white_alpha(200)));
+ register(ui.ctx(), format!("spotSource:{i}"), Rect::from_center_size(sq, vec2(14.0, 14.0)));
+ grips.push((i, true, sq, r));
}
+ pin(&p, tq, sel);
+ register(ui.ctx(), format!("spotPin:{i}"), Rect::from_center_size(tq, vec2(14.0, 14.0)));
+ grips.push((i, false, tq, r));
}
let r = (app.ui.remove_size as f64 * long) as f32;
+ // a target or source under `q`: the selected spot's first, then the nearest pin
+ let hit = |q: Pos2| {
+ grips
+ .iter()
+ .filter(|g| g.2.distance(q) < g.3.max(8.0))
+ .min_by(|a, b| {
+ (Some(a.0) != active, a.2.distance(q)).partial_cmp(&(Some(b.0) != active, b.2.distance(q))).unwrap_or(std::cmp::Ordering::Equal)
+ })
+ .copied()
+ };
+ let hover = resp.hover_pos().and_then(hit);
if let Some(h) = resp.hover_pos() {
- ui.ctx().set_cursor_icon(egui::CursorIcon::None);
- p.circle_stroke(h, r, Stroke::new(1.0, Color32::WHITE));
+ if hover.is_some() {
+ ui.ctx().set_cursor_icon(egui::CursorIcon::Grab);
+ } else {
+ ui.ctx().set_cursor_icon(egui::CursorIcon::None);
+ p.circle_stroke(h, r, Stroke::new(1.0, Color32::WHITE));
+ p.circle_stroke(h, r * (1.0 - app.ui.remove_feather / 100.0).max(0.05), Stroke::new(1.0, Color32::from_white_alpha(110)));
+ }
+ }
+ let press = ui.input(|i| i.pointer.press_origin()).or(resp.interact_pointer_pos());
+ if resp.drag_started()
+ && let Some((spot, source, ..)) = press.and_then(hit)
+ {
+ if Some(spot) != active {
+ let _ = app.run("spot.select", json!({"index": spot}));
+ }
+ let _ = app.run("develop.beginInteraction", json!({"label": "Edit Spot"}));
+ app.gesture = Some(Gesture::SpotMove { spot, source });
+ }
+ if let Some(Gesture::SpotMove { spot, source }) = app.gesture.clone() {
+ if resp.dragged()
+ && let Some(q) = resp.interact_pointer_pos()
+ {
+ let (n, n0) = (map.norm(q), map.norm(q - resp.drag_delta()));
+ let dn = [n.x - n0.x, n.y - n0.y];
+ if dn != [0.0, 0.0] {
+ let _ = app.run("spot.update", json!({"index": spot, if source { "moveSource" } else { "move" }: dn}));
+ }
+ }
+ if resp.drag_stopped() {
+ app.gesture = None;
+ let _ = app.run("develop.endInteraction", json!({}));
+ }
+ return;
+ }
+ if resp.clicked()
+ && let Some((spot, ..)) = press.and_then(hit)
+ {
+ let _ = app.run("spot.select", json!({"index": spot}));
+ return;
}
if let Some(q) = resp.interact_pointer_pos()
&& (resp.drag_started() || resp.dragged() || resp.clicked())
@@ -832,7 +907,10 @@ fn remove_overlay(app: &mut LightcraftApp, ui: &mut egui::Ui, resp: &egui::Respo
_ => "remove",
};
let pts: Vec<[f64; 2]> = points.iter().map(|q| [q.x, q.y]).collect();
- let _ = app.run("spot.add", json!({"mode": mode, "points": pts, "size": app.ui.remove_size}));
+ let _ = app.run(
+ "spot.add",
+ json!({"mode": mode, "points": pts, "size": app.ui.remove_size, "feather": app.ui.remove_feather, "opacity": app.ui.remove_opacity}),
+ );
}
}
diff --git a/crates/ui-egui/src/panels/right.rs b/crates/ui-egui/src/panels/right.rs
index 016c9a1d0..d271ffd09 100644
--- a/crates/ui-egui/src/panels/right.rs
+++ b/crates/ui-egui/src/panels/right.rs
@@ -213,20 +213,59 @@ fn remove(app: &mut LightcraftApp, ui: &mut egui::Ui, id: PhotoId) {
ui.add_space(4.0);
ui.label(egui::RichText::new("Paint over a distraction on the photo to remove it.").color(Tokens::get(ui.ctx()).text_dim));
});
- let spec = lightcraft_develop::ControlSpec {
- id: "ui.removeSize",
- label: "Size",
+ // brush settings; with a spot selected they edit that spot too
+ let sel = app.session.active_spot.and_then(|i| d.spots.get(i).map(|sp| (i, sp.clone())));
+ if let Some((i, sp)) = &sel {
+ (app.ui.remove_size, app.ui.remove_feather, app.ui.remove_opacity) = (sp.size as f32, sp.feather as f32, sp.opacity as f32);
+ divider(ui);
+ let mode = match sp.mode {
+ lightcraft_develop::SpotMode::Heal => "Heal",
+ lightcraft_develop::SpotMode::Clone => "Clone",
+ lightcraft_develop::SpotMode::Remove => "Remove",
+ };
+ super::edit::sub_title(ui, &format!("{mode} spot {} of {}", i + 1, d.spots.len()));
+ }
+ let plain = |id: &'static str, label: &'static str, min: f64, max: f64, default: f64| lightcraft_develop::ControlSpec {
+ id,
+ label,
section: lightcraft_develop::Section::Detail,
- min: 1.0,
- max: 100.0,
- default: 20.0,
+ min,
+ max,
+ default,
step: 1.0,
decimals: 0,
track: lightcraft_develop::Track::Plain,
};
- let out = slider(ui, &spec, (app.ui.remove_size * 1000.0) as f64, true, None);
- if let Some(v) = out.value {
- app.ui.remove_size = (v / 1000.0) as f32;
+ let sliders = [
+ (plain("ui.removeSize", "Size", 1.0, 250.0, 20.0), "size", (app.ui.remove_size * 1000.0) as f64),
+ (plain("ui.removeFeather", "Feather", 0.0, 100.0, 50.0), "feather", app.ui.remove_feather as f64),
+ (plain("ui.removeOpacity", "Opacity", 0.0, 100.0, 100.0), "opacity", app.ui.remove_opacity as f64),
+ ];
+ for (spec, key, v) in sliders {
+ let out = slider(ui, &spec, v, true, None);
+ let scale = if key == "size" { 1000.0 } else { 1.0 };
+ if let Some(v) = out.value {
+ match key {
+ "size" => app.ui.remove_size = (v / scale) as f32,
+ "feather" => app.ui.remove_feather = v as f32,
+ _ => app.ui.remove_opacity = v as f32,
+ }
+ }
+ if sel.is_some() {
+ super::edit::apply_slider_out(app, &spec, out, |app, v| app.run("spot.update", json!({key: v / scale})));
+ }
+ }
+ if sel.is_some() {
+ padded(ui, |ui| {
+ ui.horizontal(|ui| {
+ if text_button(ui, "spotRefresh", "Refresh Source (/)", false).clicked() {
+ let _ = app.run("spot.refreshSource", json!({}));
+ }
+ if text_button(ui, "spotDelete", "Delete (⌫)", false).clicked() {
+ let _ = app.run("spot.delete", json!({}));
+ }
+ });
+ });
}
// Visualize Spots (A): a black/white high-pass view that makes dust and specks stand out
padded(ui, |ui| {
diff --git a/crates/ui-egui/src/shortcuts.rs b/crates/ui-egui/src/shortcuts.rs
index 065802175..ed4fcc8c0 100644
--- a/crates/ui-egui/src/shortcuts.rs
+++ b/crates/ui-egui/src/shortcuts.rs
@@ -15,6 +15,9 @@ pub const ALIASES: &[(&str, &str, &str)] = &[
("Shift+M", "version.create", "{}"),
("Shift+X", "photo.flag", r#"{"flag": "reject", "advance": true}"#),
("Shift+U", "photo.flag", r#"{"flag": "none", "advance": true}"#),
+ // Shift+[ / Shift+] arrive as { / } on most layouts
+ ("Shift+{", "brush.featherLess", "{}"),
+ ("Shift+}", "brush.featherMore", "{}"),
];
pub fn parse(s: &str) -> Option<(Modifiers, Key)> {
@@ -167,7 +170,13 @@ pub fn handle(app: &mut LightcraftApp, ctx: &egui::Context) {
}
continue;
}
- R::Remove | R::RedEye => continue,
+ R::Remove => {
+ if app.session.active_spot.is_some() {
+ let _ = app.run("spot.delete", json!({}));
+ }
+ continue;
+ }
+ R::RedEye => continue,
_ => {}
}
}
@@ -179,6 +188,11 @@ pub fn handle(app: &mut LightcraftApp, ctx: &egui::Context) {
if f == "crop.rotateAspect" && app.ui.right != crate::state::RightPanel::Crop {
continue;
}
+ // / refreshes the selected spot's source in the Remove tool (the filmstrip elsewhere)
+ if f == "view.filmstrip" && app.ui.right == crate::state::RightPanel::Remove && app.session.active_spot.is_some() {
+ let _ = app.run("spot.refreshSource", json!({}));
+ continue;
+ }
// Shift+O cycles the mask overlay mode while masking (the crop overlay elsewhere)
if f == "view.cropOverlay" && app.ui.right == crate::state::RightPanel::Masking {
let _ = app.run("view.maskOverlayMode", json!({}));
diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs
index cb3583924..cdca7f19e 100644
--- a/crates/ui-egui/src/state.rs
+++ b/crates/ui-egui/src/state.rs
@@ -121,7 +121,10 @@ pub struct UiState {
pub brush_erase: bool,
/// Brush Auto Mask: dabs stick to areas like the one under the brush centre.
pub brush_auto_mask: bool,
+ /// Remove tool brush: size (fraction of the long edge), feather and opacity (0..100).
pub remove_size: f32,
+ pub remove_feather: f32,
+ pub remove_opacity: f32,
/// Selected Point Color sample.
pub point_color: usize,
/// Point Color "Visualize range": the selected sample's range in colour, the rest grey.
@@ -224,6 +227,8 @@ impl Default for UiState {
brush_erase: false,
brush_auto_mask: false,
remove_size: 0.02,
+ remove_feather: 50.0,
+ remove_opacity: 100.0,
point_color: 0,
point_color_visualize: false,
eye: 0,
diff --git a/crates/ui-egui/src/tests_masking.rs b/crates/ui-egui/src/tests_masking.rs
index 74b360f28..75e946ff4 100644
--- a/crates/ui-egui/src/tests_masking.rs
+++ b/crates/ui-egui/src/tests_masking.rs
@@ -106,3 +106,65 @@ fn brush_strokes_carry_auto_mask() {
assert!(strokes[0].auto_mask && strokes[0].points.len() >= 2, "{strokes:?}");
h.settle(SETTLE);
}
+
+#[test]
+fn remove_spots_by_pointer_and_keyboard() {
+ let mut h = detail("panel.remove");
+ assert_eq!(h.app.ui.right, RightPanel::Remove);
+ let spots = |h: &Headless| develop(h).spots;
+ // paint a spot: it's added with the brush's size/feather/opacity and selected
+ let r = h.request("ui.set", json!({"removeFeather": 30.0, "removeOpacity": 80.0}), T);
+ assert_eq!(r["ok"], true, "{r}");
+ pointer(&mut h, json!([{"kind": "down", "x": 0.3, "y": 0.6}, {"kind": "up", "x": 0.3, "y": 0.6}]));
+ assert_eq!(spots(&h).len(), 1);
+ assert_eq!((spots(&h)[0].feather, spots(&h)[0].opacity), (30.0, 80.0));
+ assert_eq!(h.app.session.active_spot, Some(0));
+ // [ / ] resize the selected spot, Shift+[ / Shift+] feather it
+ let s0 = spots(&h)[0].size;
+ h.request("ui.key", json!({"key": "]"}), T);
+ assert!(spots(&h)[0].size > s0 * 1.1, "{} vs {s0}", spots(&h)[0].size);
+ h.request("ui.key", json!({"key": "["}), T);
+ h.request("ui.key", json!({"key": "["}), T);
+ assert!(spots(&h)[0].size < s0 * 0.9);
+ h.request("ui.key", json!({"key": "[", "shift": true}), T);
+ assert_eq!(spots(&h)[0].feather, 20.0);
+ h.request("ui.key", json!({"key": "]", "shift": true}), T);
+ assert_eq!(spots(&h)[0].feather, 30.0);
+ // / picks another source (and leaves the filmstrip alone)
+ let (src, film) = (spots(&h)[0].source_offset, h.app.ui.filmstrip);
+ h.request("ui.key", json!({"key": "/"}), T);
+ assert_ne!(spots(&h)[0].source_offset, src);
+ assert_eq!(h.app.ui.filmstrip, film);
+ // a second spot elsewhere; clicking the first one's pin selects it
+ pointer(&mut h, json!([{"kind": "down", "x": 0.7, "y": 0.3}, {"kind": "up", "x": 0.7, "y": 0.3}]));
+ assert_eq!((spots(&h).len(), h.app.session.active_spot), (2, Some(1)));
+ pointer(&mut h, json!([{"kind": "down", "x": 0.3, "y": 0.6}, {"kind": "up", "x": 0.3, "y": 0.6}]));
+ assert_eq!((spots(&h).len(), h.app.session.active_spot), (2, Some(0)));
+ // drag its target: it moves, its source offset stays
+ let src = spots(&h)[0].source_offset;
+ pointer(
+ &mut h,
+ json!([{"kind": "down", "x": 0.3, "y": 0.6}, {"kind": "drag", "x": 0.32, "y": 0.6}, {"kind": "drag", "x": 0.4, "y": 0.6}, {"kind": "up", "x": 0.4, "y": 0.6}]),
+ );
+ let sp = spots(&h)[0].clone();
+ assert!((sp.points[0].x - 0.4).abs() < 0.01 && (sp.points[0].y - 0.6).abs() < 0.01, "{:?}", sp.points);
+ assert_eq!(sp.source_offset, src);
+ // drag its source to a fixed place
+ let o = sp.source_offset.unwrap();
+ let (sx, sy) = (sp.points[0].x + o.x, sp.points[0].y + o.y);
+ pointer(
+ &mut h,
+ json!([{"kind": "down", "x": sx, "y": sy}, {"kind": "drag", "x": sx + 0.01, "y": sy}, {"kind": "drag", "x": 0.5, "y": 0.8}, {"kind": "up", "x": 0.5, "y": 0.8}]),
+ );
+ let sp = spots(&h)[0].clone();
+ let o = sp.source_offset.unwrap();
+ assert!((sp.points[0].x + o.x - 0.5).abs() < 0.01 && (sp.points[0].y + o.y - 0.8).abs() < 0.01, "{o:?}");
+ // ⌫ deletes the selected spot, not the photo
+ let photos = h.app.session.visible_cloned().len();
+ h.request("ui.key", json!({"key": "delete"}), T);
+ assert_eq!((spots(&h).len(), h.app.session.active_spot), (1, None));
+ assert_eq!(h.app.session.visible_cloned().len(), photos);
+ h.request("ui.key", json!({"key": "delete"}), T);
+ assert_eq!(spots(&h).len(), 1, "nothing selected: nothing deleted");
+ h.settle(SETTLE);
+}
diff --git a/docs/parity.md b/docs/parity.md
index 756e3f421..9d2fb8805 100644
--- a/docs/parity.md
+++ b/docs/parity.md
@@ -29,7 +29,7 @@ and prints the summary; `cargo xtask parity --write` refreshes the summary table
| F. Edit panel — global adjustments (EDIT) | 36 | 2 | 10 | 1 | 28/28 (100%) | 8/14 (57%) |
| G. Profiles (PROF) | 3 | 1 | 6 | 0 | 2/3 (67%) | 1/3 (33%) |
| H. Crop & rotate (CROP) | 7 | 2 | 0 | 1 | 6/6 (100%) | 1/3 (33%) |
-| I. Remove / healing (REM) | 3 | 3 | 4 | 2 | 2/4 (50%) | 1/3 (33%) |
+| I. Remove / healing (REM) | 5 | 1 | 4 | 2 | 4/4 (100%) | 1/3 (33%) |
| J. Red eye (EYE) | 0 | 0 | 2 | 0 | — | 0/1 (0%) |
| K. Masking (MASK) | 10 | 6 | 7 | 0 | 7/8 (88%) | 3/5 (60%) |
| L. Presets (PRE) | 1 | 4 | 2 | 1 | 0/2 (0%) | 1/2 (50%) |
@@ -48,7 +48,7 @@ and prints the summary; `cargo xtask parity --write` refreshes the summary table
| Y. Menus | 46 | 18 | 21 | 8 | 37/47 (79%) | 7/23 (30%) |
| Z. Keyboard shortcuts (desktop) | 46 | 16 | 18 | 1 | 39/52 (75%) | 7/23 (30%) |
| Lightroom Classic extras | 4 | 19 | 56 | 9 | — | 3/21 (14%) |
-| **Total** | 212 | 99 | 189 | 37 | 155/198 (78%) | 49/144 (34%) |
+| **Total** | 214 | 97 | 189 | 37 | 157/198 (79%) | 49/144 (34%) |
<!-- /parity:summary -->
## Top gaps
@@ -57,8 +57,6 @@ Ordered by tier, then user value, then (low) effort. Take the first one nobody i
1. **LR-EXP-COLORSPACE** (P0) — export is sRGB only. Add Display P3 / Adobe RGB-compatible / ProPhoto-compatible /
Rec.2020 output (our own primaries + ICC from `crates/codecs/src/icc.rs`). High value, low–medium effort.
-4. **LR-REM-SPOT-EDIT + LR-REM-BRUSH-PARAMS** (P0) — select a spot pin, move target/source, delete with ⌫,
- feather/opacity sliders, `[`/`]` size keys. Medium effort.
5. **LR-VIEW-PHOTOGRID** (P0) — group the justified grid by capture date with headers. Low–medium effort.
6. **LR-PRE-CREATE + LR-PRE-PANEL + LR-BEHAV-PREVIEW-HOVER** (P0/P1) — per-group checkboxes in Create Preset;
live preview while hovering presets/profiles/versions. Medium effort.
@@ -307,8 +305,8 @@ under the UI command that wraps it (a no-op error); the UI command now wins.
| LR-REM-CLONE | Clone | P0 | ✅ | `cmd:spot.add` (`mode: clone`) | |
| LR-REM-GEN | Generative remove | OOS | 🚫 | | |
| LR-REM-DETECT | Object detection for remove | P2 | ⬜ | | |
-| LR-REM-BRUSH-PARAMS | Brush size / feather / opacity | P0 | 🟡 | `cmd:spot.add` (`size`, `feather`, `opacity`), `crates/ui-egui/src/panels/right.rs` | UI has size only; no `[` `]` keys |
-| LR-REM-SPOT-EDIT | Edit existing spots | P0 | 🟡 | `cmd:spot.delete` | no pin selection, no moving target/source, ⌫ deletes the photo instead |
+| LR-REM-BRUSH-PARAMS | Brush size / feather / opacity | P0 | ✅ | `cmd:spot.add` (`size`, `feather`, `opacity`), `cmd:brush.smaller`, `cmd:brush.larger`, `cmd:brush.featherLess`, `cmd:brush.featherMore`, `crates/ui-egui/src/panels/right.rs` | Size / Feather / Opacity sliders (for new spots and the selected one); `[` `]` size, ⇧`[` ⇧`]` feather (also the Masking brush) |
+| LR-REM-SPOT-EDIT | Edit existing spots | P0 | ✅ | `cmd:spot.select`, `cmd:spot.update`, `cmd:spot.refreshSource`, `cmd:spot.delete` | click a pin to select, drag target or source, ⌫ deletes the selected spot, `/` picks another source; automatic sources are resolved when the spot is added |
| LR-REM-VISUALIZE | Visualize spots | P1 | ⬜ | | |
| LR-REM-PEOPLE | Remove people (generative) | OOS | 🚫 | | |
| LR-REM-REFLECT | Remove reflections | P2 | ⬜ | | |