From 3886c765827587f4d76f8fde870cbf443e9dd9f2 Mon Sep 17 00:00:00 2001 From: helgehelge123 <117832631+helgehelge123@users.noreply.github.com> Date: Mon, 19 Oct 2026 01:31:39 +0200 Subject: [PATCH 1/4] LR-LIB-CULL: Assisted Culling can stack each burst, best photo on top (#2277) photo.analyze takes stackGroups (default false): every burst becomes one collapsed stack topped by its sharpest photo, in the same undo step as the analysis and flags. Photos already in a stack are left alone (like stack.auto); the rest of the burst is stacked when two or more remain. Duplicate ids are measured once. The dialog gets a "Stack each burst, best photo on top" checkbox, remembered for the session; German translation, parity row and revision history updated. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/cull.rs | 55 ++++++++++++-- crates/engine/src/tests_import.rs | 110 +++++++++++++++++++++++++++ crates/ui-egui/locales/de.json | 1 + crates/ui-egui/src/menus.rs | 2 +- crates/ui-egui/src/panels/dialogs.rs | 9 ++- crates/ui-egui/src/state.rs | 9 ++- docs/parity-checklist.md | 5 +- 7 files changed, 178 insertions(+), 13 deletions(-) diff --git a/crates/engine/src/cmd/cull.rs b/crates/engine/src/cmd/cull.rs index 92a9c3b7cb..71db71c990 100644 --- a/crates/engine/src/cmd/cull.rs +++ b/crates/engine/src/cmd/cull.rs @@ -1,7 +1,7 @@ //! Assisted culling: score photos for focus and clipping, group similar shots taken close //! together (bursts) and mark the sharpest of each group; optionally reject blurry ones and pick -//! each group's best. Scores are kept on the photos (rules / smart albums: `sharpness`, -//! `bestOfGroup`). +//! each group's best, and stack each burst with its best photo on top. Scores are kept on the +//! photos (rules / smart albums: `sharpness`, `bestOfGroup`). use lightcraft_catalog::{Analysis, Flag, Op, PhotoId}; use serde_json::{Value, json}; @@ -22,10 +22,17 @@ fn secs(iso: &str) -> Option { } fn analyze(s: &mut Session, p: &Value) -> Result { - let ids: Vec = if p.get("ids").is_some() || s.selection.ids.len() > 1 { s.targets(p)? } else { s.visible_cloned() }; + let mut ids: Vec = if p.get("ids").is_some() || s.selection.ids.len() > 1 { s.targets(p)? } else { s.visible_cloned() }; + // a photo named twice is measured (and stacked) once + let mut seen = std::collections::HashSet::new(); + ids.retain(|id| seen.insert(*id)); let reject_below = p.get("rejectBelow").and_then(Value::as_f64).map(|v| v as f32); let pick_best = p.get("pickBest").and_then(Value::as_bool).unwrap_or(false); let (gap, same) = burst_params(p)?; + let stack_groups = match p.get("stackGroups") { + None | Some(Value::Null) => false, + Some(v) => v.as_bool().ok_or_else(|| super::bad("photo.analyze", "`stackGroups` must be true or false"))?, + }; // measure (thumbnail-level sources: fast, and enough for focus at 512 px) let mut rows: Vec<(PhotoId, Option, f32, f32, [f32; 64])> = Vec::new(); let mut failed = Vec::new(); @@ -80,10 +87,48 @@ fn analyze(s: &mut Session, p: &Value) -> Result { } out.push(json!({"id": id.0, "sharpness": (sharp * 10.0).round() / 10.0, "clipped": clip, "group": g, "best": is_best})); } + let mut stacks = 0; + if stack_groups { + // Photos already in a stack stay where they are (like `stack.auto`): a burst is stacked + // from its other photos when two or more remain, with the sharpest of those on top. + let index = s.catalog.stack_index(); + let mut members: std::collections::BTreeMap> = Default::default(); + for (i, g) in group_of.iter().enumerate() { + if let (Some(g), Some(r)) = (g, rows.get(i)) + && !index.contains_key(&r.0) + && s.catalog.photo(r.0).is_some_and(|ph| !ph.deleted) + { + members.entry(*g).or_default().push((r.0, r.2)); + } + } + for group in members.values() { + let Some(top) = group.iter().fold(None::<(PhotoId, f32)>, |b, m| if b.is_none_or(|b| m.1 > b.1) { Some(*m) } else { b }) else { + continue; + }; + let photos: Vec = group.iter().map(|m| m.0).collect(); + if photos.len() >= 2 + && let Some(op) = s.catalog.group_ops(top.0, &photos, true) + { + ops.push(op); + stacks += 1; + } + } + } if !ops.is_empty() { s.commit("Assisted Culling", Op::Batch { ops })?; } - Ok(json!({"photos": out, "groups": best.len(), "rejected": rejected, "picked": picked, "failed": failed})) + if stacks > 0 { + // a photo now hidden inside a collapsed stack must not stay the active one + let vis = s.visible_cloned(); + if let Some(a) = s.selection.active + && !vis.contains(&a) + && let Some(st) = s.catalog.stack_of(a) + { + let top = vis.iter().copied().find(|p| st.photos.contains(p)).unwrap_or(st.top()); + s.selection = crate::Selection::single(top); + } + } + Ok(json!({"photos": out, "groups": best.len(), "stacks": stacks, "rejected": rejected, "picked": picked, "failed": failed})) } /// `burstGap` (seconds, 0..=a day) and `similarity` (0..=1) of `photo.analyze`, refused before @@ -152,7 +197,7 @@ pub fn specs() -> Vec { "Assisted Culling", [], None, - "{ids?, rejectBelow?: sharpness 0..100, pickBest?: bool, burstGap?: seconds 0..86400 (10), similarity?: 0..1 (0.93)} — score the selected photos (else all in view) for focus (0..100) and clipping, group look-alike shots (signature similarity at least `similarity`) taken at most `burstGap` seconds apart and mark the sharpest of each; optionally reject blurry photos and pick each group's best; one undo step → {photos: [{id, sharpness, clipped, group, best}], groups, rejected, picked}", + "{ids?, rejectBelow?: sharpness 0..100, pickBest?: bool, stackGroups?: bool (false), burstGap?: seconds 0..86400 (10), similarity?: 0..1 (0.93)} — score the selected photos (else all in view) for focus (0..100) and clipping, group look-alike shots (signature similarity at least `similarity`) taken at most `burstGap` seconds apart and mark the sharpest of each; optionally reject blurry photos, pick each group's best and, with `stackGroups`, stack each burst collapsed with its sharpest photo on top (photos already in a stack stay put: the rest of a burst is stacked when two or more remain); one undo step → {photos: [{id, sharpness, clipped, group, best}], groups, stacks, rejected, picked, failed}", always, analyze ), diff --git a/crates/engine/src/tests_import.rs b/crates/engine/src/tests_import.rs index f581f11dda..101fe43431 100644 --- a/crates/engine/src/tests_import.rs +++ b/crates/engine/src/tests_import.rs @@ -870,6 +870,116 @@ fn assisted_culling_burst_limits_are_adjustable() { let _ = std::fs::remove_dir_all(&dir); } +/// Assisted culling with `stackGroups` (#2277): each burst becomes one collapsed stack with its +/// sharpest photo on top, an unrelated photo stays loose, analysis and stack are one undo step, +/// and a second run neither makes another stack nor splits the existing one. +#[test] +fn assisted_culling_stacks_each_burst_best_on_top() { + let dir = temp_dir("cull-stack"); + let scene = lightcraft_scenes::demo_library()[0].render(480, 320); + let soften = |img: &lightcraft_raster::Rgb32f, r: usize| { + let (w, h) = (img.width, img.height); + let mut out = img.clone(); + for y in 0..h { + for x in 0..w { + let (mut acc, mut n) = ([0f32; 3], 0.0); + for yy in y.saturating_sub(r)..(y + r + 1).min(h) { + for xx in x.saturating_sub(r)..(x + r + 1).min(w) { + let c = img.data[yy * w + xx]; + acc = [acc[0] + c[0], acc[1] + c[1], acc[2] + c[2]]; + n += 1.0; + } + } + out.data[y * w + x] = acc.map(|v| v / n); + } + } + out + }; + let save = |img: &lightcraft_raster::Rgb32f, name: &str| { + let data: Vec<[u8; 4]> = img + .data + .iter() + .map(|c| { + let e = |v: f32| (lightcraft_color::transfer::linear_to_srgb(v.clamp(0.0, 1.0)) * 255.0).round() as u8; + [e(c[0]), e(c[1]), e(c[2]), 255] + }) + .collect(); + let png = lightcraft_codecs::encode_png( + &lightcraft_codecs::EncodeImage::rgba8(&lightcraft_raster::Rgba8 { width: img.width, height: img.height, data }), + &Default::default(), + ) + .unwrap(); + std::fs::write(dir.join(name), png).unwrap(); + }; + save(&soften(&scene, 3), "a_soft.png"); + save(&scene, "b_sharp.png"); + save(&soften(&scene, 6), "c_softer.png"); + save(&lightcraft_scenes::demo_library()[7].render(480, 320), "d_other.png"); + let mut s = Session::new().with_fs(); + let r = s.execute("library.import", &json!({"paths": [dir.to_string_lossy()]})).unwrap(); + let ids: Vec = r["imported"].as_array().unwrap().iter().filter_map(Value::as_u64).collect(); + let by_name = |s: &Session, n: &str| s.catalog.photos().find(|p| p.file_name == n).unwrap().id; + for (i, n) in ["a_soft.png", "b_sharp.png", "c_softer.png", "d_other.png"].iter().enumerate() { + let id = by_name(&s, n); + s.commit("t", lightcraft_catalog::Op::SetCaptured { id, captured: Some(format!("2026-05-01T10:00:0{i}")) }).unwrap(); + } + let (soft, sharp, softer, other) = + (by_name(&s, "a_soft.png"), by_name(&s, "b_sharp.png"), by_name(&s, "c_softer.png"), by_name(&s, "d_other.png")); + // a photo named twice is measured and stacked once + let mut twice = ids.clone(); + twice.push(sharp.0); + let r = s.execute("photo.analyze", &json!({"ids": twice, "stackGroups": true})).unwrap(); + assert_eq!((r["stacks"].clone(), r["groups"].clone()), (json!(1), json!(1)), "{r}"); + let st = s.catalog.stack_of(sharp).unwrap().clone(); + assert!(st.collapsed && st.top() == sharp, "the sharpest photo tops the stack"); + let mut members = st.photos.clone(); + members.sort(); + let mut want = vec![soft, sharp, softer]; + want.sort(); + assert_eq!(members, want); + assert!(s.catalog.stack_of(other).is_none(), "the unrelated photo stays loose"); + assert!(s.catalog.photo(sharp).unwrap().analysis.is_some_and(|a| a.best)); + // one undo step removes the stack and the analysis together + s.execute("edit.undo", &json!({})).unwrap(); + assert!(s.catalog.stacks().next().is_none()); + assert!(s.catalog.photo(sharp).unwrap().analysis.is_none()); + // without `stackGroups` nothing is stacked + let r = s.execute("photo.analyze", &json!({"ids": ids})).unwrap(); + assert_eq!(r["stacks"], 0, "{r}"); + assert!(s.catalog.stacks().next().is_none()); + s.execute("photo.analyze", &json!({"ids": ids, "stackGroups": true})).unwrap(); + assert_eq!(s.catalog.stacks().count(), 1); + // a second run leaves the stack as it is + let before = s.catalog.stack_of(sharp).unwrap().clone(); + let commits = s.commits(); + let r = s.execute("photo.analyze", &json!({"ids": ids, "stackGroups": true})).unwrap(); + assert_eq!(r["stacks"], 0, "{r}"); + assert_eq!(s.catalog.stacks().count(), 1); + assert_eq!(s.catalog.stack_of(sharp).unwrap(), &before); + assert!(s.commits() > commits); + // a burst partly stacked already: the loose photos are stacked among themselves when two remain + let mut s2 = Session::new().with_fs(); + s2.execute("library.import", &json!({"paths": [dir.to_string_lossy()]})).unwrap(); + for (i, n) in ["a_soft.png", "b_sharp.png", "c_softer.png", "d_other.png"].iter().enumerate() { + let id = by_name(&s2, n); + s2.commit("t", lightcraft_catalog::Op::SetCaptured { id, captured: Some(format!("2026-05-01T10:00:0{i}")) }).unwrap(); + } + let (soft, sharp, softer, other) = + (by_name(&s2, "a_soft.png"), by_name(&s2, "b_sharp.png"), by_name(&s2, "c_softer.png"), by_name(&s2, "d_other.png")); + let ids: Vec = [soft, sharp, softer, other].iter().map(|p| p.0).collect(); + s2.execute("stack.group", &json!({"ids": [soft.0, other.0]})).unwrap(); + let r = s2.execute("photo.analyze", &json!({"ids": ids, "stackGroups": true})).unwrap(); + assert_eq!(r["stacks"], 1, "{r}"); + assert!(s2.catalog.stack_of(soft).unwrap().photos.contains(&other), "the existing stack is untouched"); + let st = s2.catalog.stack_of(sharp).unwrap(); + assert!(st.top() == sharp && st.photos.len() == 2 && st.photos.contains(&softer)); + // a non-boolean value is refused before anything changes + let n = s2.commits(); + assert!(s2.execute("photo.analyze", &json!({"ids": ids, "stackGroups": "yes"})).is_err()); + assert_eq!(s2.commits(), n); + let _ = std::fs::remove_dir_all(&dir); +} + /// Find Dust Spots: soft dark spots on a smooth sky are found and healed (one undo step). #[test] fn dust_spots_are_found_and_healed() { diff --git a/crates/ui-egui/locales/de.json b/crates/ui-egui/locales/de.json index 9d2d756800..4d08cbd4a4 100644 --- a/crates/ui-egui/locales/de.json +++ b/crates/ui-egui/locales/de.json @@ -1205,6 +1205,7 @@ "Refresh View": "Ansicht aktualisieren", "Reject": "Ablehnen", "Reject below focus": "Unter Schärfegrenzwert ablehnen", + "Stack each burst, best photo on top": "Jede Serie stapeln, bestes Foto oben", "Burst: shots at most this far apart": "Serie: Aufnahmen höchstens so weit auseinander", "Burst: how alike (loose … strict)": "Serie: wie ähnlich (locker … streng)", "Lower it when a panning or moving burst splits into several groups.": "Senken, wenn eine Mitzieher- oder Bewegungsserie in mehrere Gruppen zerfällt.", diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs index 229b34dc6a..41df245a78 100644 --- a/crates/ui-egui/src/menus.rs +++ b/crates/ui-egui/src/menus.rs @@ -1444,7 +1444,7 @@ pub fn run_ui_command(app: &mut LightcraftApp, id: &str, p: &Value) -> Option open_original_in(app, &ctx, p), "dialog.cull" => { let (burst_gap, similarity) = app.ui.cull_burst.unwrap_or((10.0, 0.93)); - app.ui.dialog = Some(Dialog::Cull { reject_below: 0.0, pick_best: true, burst_gap, similarity }); + app.ui.dialog = Some(Dialog::Cull { reject_below: 0.0, pick_best: true, stack_groups: app.ui.cull_stack, burst_gap, similarity }); Ok(Value::Null) } "app.whatsNew" => { diff --git a/crates/ui-egui/src/panels/dialogs.rs b/crates/ui-egui/src/panels/dialogs.rs index 26e198133a..575ba09cd3 100644 --- a/crates/ui-egui/src/panels/dialogs.rs +++ b/crates/ui-egui/src/panels/dialogs.rs @@ -336,7 +336,7 @@ pub fn show(app: &mut LightcraftApp, ctx: &egui::Context) { egui::RichText::new(crate::i18n::tr_format!("Creates {} stacks from {} of {scope}", preview["stacks"], preview["photos"], scope = crate::i18n::tr(scope))).color(t.text_dim), ); } - Dialog::Cull { reject_below, pick_best, burst_gap, similarity } => { + Dialog::Cull { reject_below, pick_best, stack_groups, burst_gap, similarity } => { let n = app.session.selection.ids.len(); let scope = if n > 1 { crate::i18n::tr_format!("the {n} selected photos", n = n) } else { crate::i18n::tr_format!("the {} photos in view", app.session.visible_cloned().len()) }; ui.label(egui::RichText::new(crate::i18n::tr_format!("Scores {scope} for focus and exposure and finds similar shots taken within seconds of each other (bursts).", scope = scope)).color(t.text_label)); @@ -346,6 +346,8 @@ pub fn show(app: &mut LightcraftApp, ctx: &egui::Context) { ui.label(egui::RichText::new(crate::i18n::tr(if *reject_below > 0.0 { "Blurry photos below the score are flagged as rejects." } else { "0: nothing is rejected." })).color(t.text_dim)); let r = ui.checkbox(pick_best, crate::i18n::tr("Pick the sharpest photo of each burst")); crate::widgets::register(ui.ctx(), "check:cullPick", r.rect); + let r = ui.checkbox(stack_groups, crate::i18n::tr("Stack each burst, best photo on top")); + crate::widgets::register(ui.ctx(), "check:cullStack", r.rect); ui.add_space(6.0); let r = ui.add( egui::Slider::new(burst_gap, 1.0..=600.0) @@ -1918,9 +1920,10 @@ pub fn confirm_dialog(app: &mut LightcraftApp, dlg: &Dialog) -> Result crate::panels::denoise::install(app, info, *accepted), Dialog::FaceModel { path, info, accepted } => crate::panels::faces::install(app, path, info, *accepted), Dialog::AllMetadata { .. } | Dialog::SystemInfo { .. } | Dialog::WhatsNew => Ok(serde_json::Value::Null), - Dialog::Cull { reject_below, pick_best, burst_gap, similarity } => { + Dialog::Cull { reject_below, pick_best, stack_groups, burst_gap, similarity } => { app.ui.cull_burst = Some((*burst_gap, *similarity)); - let mut p = json!({"pickBest": pick_best, "burstGap": burst_gap, "similarity": similarity}); + app.ui.cull_stack = *stack_groups; + let mut p = json!({"pickBest": pick_best, "stackGroups": stack_groups, "burstGap": burst_gap, "similarity": similarity}); if *reject_below > 0.0 { p["rejectBelow"] = json!(reject_below); } diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index 3388bad3b1..f97a4b44dd 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -732,6 +732,9 @@ pub struct UiState { /// session; `None` until the dialog is first confirmed (then 10 s, 0.93). #[serde(skip)] pub cull_burst: Option<(f32, f32)>, + /// Whether Assisted Culling stacked its bursts the last time it was confirmed (this session). + #[serde(skip)] + pub cull_stack: bool, /// "More" faces the user hid with ×, for this session: (photo, region index). #[serde(skip)] pub dismissed_faces: std::collections::HashSet<(u64, usize)>, @@ -1093,11 +1096,12 @@ pub enum Dialog { /// Help ▸ What's New. WhatsNew, /// Photo ▸ Assisted Culling: reject photos below this focus score (0 = none), pick the best - /// of each burst; shots at most `burst_gap` seconds apart and at least `similarity` alike are - /// a burst. + /// of each burst (and stack each burst, best on top, with `stack_groups`); shots at most + /// `burst_gap` seconds apart and at least `similarity` alike are a burst. Cull { reject_below: f32, pick_best: bool, + stack_groups: bool, burst_gap: f32, similarity: f32, }, @@ -1321,6 +1325,7 @@ impl Default for UiState { person_from: None, last_person: None, cull_burst: None, + cull_stack: false, dismissed_faces: Default::default(), unnamed_selected: Default::default(), unnamed_name: String::new(), diff --git a/docs/parity-checklist.md b/docs/parity-checklist.md index 9cce61b9a6..32488a4dda 100644 --- a/docs/parity-checklist.md +++ b/docs/parity-checklist.md @@ -1,6 +1,6 @@ # Lightroom parity checklist -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-19 · **Change:** patch (LR-LIB-CULL: adjustable burst limits) · **Target:** Adobe Lightroom Classic 15.5 / Lightroom 9.6 +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-19 · **Change:** patch (LR-LIB-CULL: bursts can be stacked, best on top) · **Target:** Adobe Lightroom Classic 15.5 / Lightroom 9.6 The measured, row-by-row checklist: one row per Lightroom feature, menu item and shortcut, what we have and what is missing. It answers *does the feature exist?* (feature breadth). Whether it is good @@ -116,7 +116,7 @@ differences and missing bindings are in [ui-parity.md](ui-parity.md#shortcuts). | LR-LIB-CAPTURETIME | Edit capture time | P1 | ✅ | `cmd:photo.setCaptureTime`, `cmd:dialog.captureTime`, `crates/catalog/src/dates.rs` | set (the other selected photos shift by the same amount, or `each`), shift by days/hours/minutes, time-zone shift; one undo step, journaled; Info panel button; no “revert to original capture time”. Impossible calendar dates cannot anchor relative shifts; rejection preserves metadata, selection, Undo and Redo. | | LR-LIB-SHOWFINDER | Reveal original in file manager | P0 | ✅ | `cmd:app.showInFinder` | ⌘R (see MENU-FILE-SHOWFINDER) | | LR-LIB-COVER | Album cover | P2 | ✅ | `cmd:album.setCover` | | -| LR-LIB-CULL | Assisted culling | P2 | 🟡 | `cmd:photo.analyze`, `cmd:dialog.cull`, `crates/pipeline/src/cull.rs` | Photo ▸ Assisted Culling…: focus score (0–100), clipping, burst grouping (look-alike shots within 10 s, both limits adjustable in the dialog and as `burstGap` / `similarity`, #2275) with the sharpest marked; reject below a focus score, pick each burst's best; classical measures — no eyes-closed / expression detection | +| LR-LIB-CULL | Assisted culling | P2 | 🟡 | `cmd:photo.analyze`, `cmd:dialog.cull`, `crates/pipeline/src/cull.rs` | Photo ▸ Assisted Culling…: focus score (0–100), clipping, burst grouping (look-alike shots within 10 s, both limits adjustable in the dialog and as `burstGap` / `similarity`, #2275) with the sharpest marked, optionally stacked collapsed with the best photo on top (`stackGroups`, #2277; photos already stacked are left alone); reject below a focus score, pick each burst's best; classical measures — no eyes-closed / expression detection | | LR-LIB-ACTIVITY | Comments & likes | OOS | 🚫 | | | | LR-LIB-QUICKCOLL | Quick collection [Classic] | P2 | ✅ | `cmd:album.toggleTarget`, `cmd:album.clearQuick` | B in the grids | | LR-LIB-VIRTUALCOPY | Virtual copies [Classic] | P1 | ✅ | `cmd:photo.virtualCopy`, `cmd:photo.delete`, `crates/engine/src/cmd/organize.rs` | “Copy N” badge, stacked with the original, same albums, no XMP writes; deleting a copy dissolves or renumbers the stack (#1493); no “Set Copy as Master” | @@ -797,6 +797,7 @@ Latin stays upright. Advanced Japanese composition remains open. Regression cove | Date | Change | Summary | |---|---|---| +| 2026-10-19 | patch | LR-LIB-CULL: Assisted Culling can stack each burst collapsed with its best photo on top (dialog checkbox, `photo.analyze` `stackGroups`; #2277). Statuses and feature counts unchanged. | | 2026-10-19 | patch | LR-LIB-CULL: Assisted Culling's burst gap and similarity are adjustable (dialog, `photo.analyze` `burstGap` / `similarity`; #2275). Statuses and feature counts unchanged. | | 2026-10-14 | patch | LR-EXP-TYPE: opaque 8-bit PNG/TIFF/WebP use RGB; transparent exports retain alpha (#1670). Statuses and feature counts unchanged. | | 2026-10-15 | minor | LRC-PRINT-PAGE: Page Options (Page Numbers, Page Info, Crop Marks) on Single Image and Contact Sheet pages, in the Print dialog, `print.set` and templates; still 🟡 (no identity plate, watermark, photo info or Cut Guides) | From 76dfb0df11079a9b38e61f879bd38d8657cf3ea6 Mon Sep 17 00:00:00 2001 From: helgehelge123 <117832631+helgehelge123@users.noreply.github.com> Date: Mon, 19 Oct 2026 01:47:17 +0200 Subject: [PATCH 2/4] LR-LIB-CULL: stacking bursts keeps the rest of the selection (#2277) When the active photo goes into a collapsed burst stack, the stack's top becomes active and the other selected photos stay selected, instead of the selection collapsing to one photo. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/cull.rs | 9 +++++++-- crates/engine/src/tests_import.rs | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/cull.rs b/crates/engine/src/cmd/cull.rs index 71db71c990..4266790edd 100644 --- a/crates/engine/src/cmd/cull.rs +++ b/crates/engine/src/cmd/cull.rs @@ -118,14 +118,19 @@ fn analyze(s: &mut Session, p: &Value) -> Result { s.commit("Assisted Culling", Op::Batch { ops })?; } if stacks > 0 { - // a photo now hidden inside a collapsed stack must not stay the active one + // a photo now hidden inside a collapsed stack must not stay the active one: its stack's + // top takes over, and the rest of the selection (what was culled) stays selected let vis = s.visible_cloned(); if let Some(a) = s.selection.active && !vis.contains(&a) && let Some(st) = s.catalog.stack_of(a) { let top = vis.iter().copied().find(|p| st.photos.contains(p)).unwrap_or(st.top()); - s.selection = crate::Selection::single(top); + s.selection.ids.retain(|id| vis.contains(id)); + if !s.selection.ids.contains(&top) { + s.selection.ids.push(top); + } + s.selection.active = Some(top); } } Ok(json!({"photos": out, "groups": best.len(), "stacks": stacks, "rejected": rejected, "picked": picked, "failed": failed})) diff --git a/crates/engine/src/tests_import.rs b/crates/engine/src/tests_import.rs index 101fe43431..170a9d245d 100644 --- a/crates/engine/src/tests_import.rs +++ b/crates/engine/src/tests_import.rs @@ -928,8 +928,12 @@ fn assisted_culling_stacks_each_burst_best_on_top() { // a photo named twice is measured and stacked once let mut twice = ids.clone(); twice.push(sharp.0); + s.selection = crate::Selection { ids: vec![soft, sharp, softer, other], active: Some(soft) }; let r = s.execute("photo.analyze", &json!({"ids": twice, "stackGroups": true})).unwrap(); assert_eq!((r["stacks"].clone(), r["groups"].clone()), (json!(1), json!(1)), "{r}"); + // the active photo went into the collapsed stack: its top takes over, the loose photo stays selected + assert_eq!(s.selection.active, Some(sharp)); + assert!(s.selection.ids.contains(&other) && s.selection.ids.contains(&sharp) && !s.selection.ids.contains(&soft), "{:?}", s.selection.ids); let st = s.catalog.stack_of(sharp).unwrap().clone(); assert!(st.collapsed && st.top() == sharp, "the sharpest photo tops the stack"); let mut members = st.photos.clone(); From 7c3d7901321a9bb4862aa48f055a0c41d83af063 Mon Sep 17 00:00:00 2001 From: helgehelge123 <117832631+helgehelge123@users.noreply.github.com> Date: Mon, 2 Nov 2026 00:26:41 +0100 Subject: [PATCH 3/4] Assisted Culling: test two bursts and a deleted photo with stackGroups Two bursts make two stacks in one undo step; a deleted photo is measured but left out of its burst's stack. The blur and PNG helpers of the stacking test move to module level so both tests share them. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/tests/import.rs | 116 +++++++++++++++++++++--------- 1 file changed, 82 insertions(+), 34 deletions(-) diff --git a/crates/engine/src/tests/import.rs b/crates/engine/src/tests/import.rs index d97b00a9c6..d2d44e722a 100644 --- a/crates/engine/src/tests/import.rs +++ b/crates/engine/src/tests/import.rs @@ -1120,6 +1120,44 @@ fn assisted_culling_burst_limits_are_adjustable() { let _ = std::fs::remove_dir_all(&dir); } +/// A box blur of radius `r`: the larger `r`, the lower the focus score. +fn soften(img: &lightcraft_raster::Rgb32f, r: usize) -> lightcraft_raster::Rgb32f { + let (w, h) = (img.width, img.height); + let mut out = img.clone(); + for y in 0..h { + for x in 0..w { + let (mut acc, mut n) = ([0f32; 3], 0.0); + for yy in y.saturating_sub(r)..(y + r + 1).min(h) { + for xx in x.saturating_sub(r)..(x + r + 1).min(w) { + let c = img.data[yy * w + xx]; + acc = [acc[0] + c[0], acc[1] + c[1], acc[2] + c[2]]; + n += 1.0; + } + } + out.data[y * w + x] = acc.map(|v| v / n); + } + } + out +} + +/// Write a linear image as an sRGB PNG. +fn save_png(img: &lightcraft_raster::Rgb32f, path: &std::path::Path) { + let data: Vec<[u8; 4]> = img + .data + .iter() + .map(|c| { + let e = |v: f32| (lightcraft_color::transfer::linear_to_srgb(v.clamp(0.0, 1.0)) * 255.0).round() as u8; + [e(c[0]), e(c[1]), e(c[2]), 255] + }) + .collect(); + let png = lightcraft_codecs::encode_png( + &lightcraft_codecs::EncodeImage::rgba8(&lightcraft_raster::Rgba8 { width: img.width, height: img.height, data }), + &Default::default(), + ) + .unwrap(); + std::fs::write(path, png).unwrap(); +} + /// Assisted culling with `stackGroups` (#2277): each burst becomes one collapsed stack with its /// sharpest photo on top, an unrelated photo stays loose, analysis and stack are one undo step, /// and a second run neither makes another stack nor splits the existing one. @@ -1127,40 +1165,7 @@ fn assisted_culling_burst_limits_are_adjustable() { fn assisted_culling_stacks_each_burst_best_on_top() { let dir = temp_dir("cull-stack"); let scene = lightcraft_scenes::demo_library()[0].render(480, 320); - let soften = |img: &lightcraft_raster::Rgb32f, r: usize| { - let (w, h) = (img.width, img.height); - let mut out = img.clone(); - for y in 0..h { - for x in 0..w { - let (mut acc, mut n) = ([0f32; 3], 0.0); - for yy in y.saturating_sub(r)..(y + r + 1).min(h) { - for xx in x.saturating_sub(r)..(x + r + 1).min(w) { - let c = img.data[yy * w + xx]; - acc = [acc[0] + c[0], acc[1] + c[1], acc[2] + c[2]]; - n += 1.0; - } - } - out.data[y * w + x] = acc.map(|v| v / n); - } - } - out - }; - let save = |img: &lightcraft_raster::Rgb32f, name: &str| { - let data: Vec<[u8; 4]> = img - .data - .iter() - .map(|c| { - let e = |v: f32| (lightcraft_color::transfer::linear_to_srgb(v.clamp(0.0, 1.0)) * 255.0).round() as u8; - [e(c[0]), e(c[1]), e(c[2]), 255] - }) - .collect(); - let png = lightcraft_codecs::encode_png( - &lightcraft_codecs::EncodeImage::rgba8(&lightcraft_raster::Rgba8 { width: img.width, height: img.height, data }), - &Default::default(), - ) - .unwrap(); - std::fs::write(dir.join(name), png).unwrap(); - }; + let save = |img: &lightcraft_raster::Rgb32f, name: &str| save_png(img, &dir.join(name)); save(&soften(&scene, 3), "a_soft.png"); save(&scene, "b_sharp.png"); save(&soften(&scene, 6), "c_softer.png"); @@ -1234,6 +1239,49 @@ fn assisted_culling_stacks_each_burst_best_on_top() { let _ = std::fs::remove_dir_all(&dir); } +/// Assisted culling with `stackGroups` (#2277): two bursts make two stacks in one undo step, and a +/// deleted photo is measured but left out of its burst's stack, even when it is the sharpest. +#[test] +fn assisted_culling_stacks_two_bursts_and_leaves_deleted_photos_out() { + let dir = temp_dir("cull-stack-two"); + let (one, two) = (lightcraft_scenes::demo_library()[0].render(480, 320), lightcraft_scenes::demo_library()[7].render(480, 320)); + let files = [ + ("a_soft.png", soften(&one, 3), "10:00:00"), + ("b_sharp.png", one.clone(), "10:00:01"), + ("c_softer.png", soften(&one, 6), "10:00:02"), + ("d_sharp.png", two.clone(), "10:05:00"), + ("e_soft.png", soften(&two, 4), "10:05:01"), + ]; + for (name, img, _) in &files { + save_png(img, &dir.join(name)); + } + let mut s = Session::new().with_fs(); + s.execute("library.import", &json!({"paths": [dir.to_string_lossy()]})).unwrap(); + let by_name = |s: &Session, n: &str| s.catalog.photos().find(|p| p.file_name == n).unwrap().id; + for (name, _, at) in &files { + let id = by_name(&s, name); + s.commit("t", lightcraft_catalog::Op::SetCaptured { id, captured: Some(format!("2026-05-01T{at}")) }).unwrap(); + } + let [soft, sharp, softer, d, e] = files.map(|f| by_name(&s, f.0)); + let ids: Vec = [soft, sharp, softer, d, e].iter().map(|p| p.0).collect(); + s.commit("t", lightcraft_catalog::Op::SetDeleted { id: sharp, deleted: true }).unwrap(); + let n = s.commits(); + let r = s.execute("photo.analyze", &json!({"ids": ids, "stackGroups": true})).unwrap(); + assert_eq!((r["groups"].clone(), r["stacks"].clone()), (json!(2), json!(2)), "{r}"); + assert_eq!(s.commits(), n + 1, "analysis and both stacks are one undo step"); + // the deleted photo is measured, but its burst is stacked from the other two + assert!(s.catalog.photo(sharp).unwrap().analysis.is_some()); + assert!(s.catalog.stack_of(sharp).is_none(), "a deleted photo is never stacked"); + let st = s.catalog.stack_of(soft).unwrap(); + assert!(st.collapsed && st.top() == soft && st.photos.len() == 2 && st.photos.contains(&softer), "{st:?}"); + let st = s.catalog.stack_of(d).unwrap(); + assert!(st.collapsed && st.top() == d && st.photos.len() == 2 && st.photos.contains(&e), "{st:?}"); + // one undo removes both stacks + s.execute("edit.undo", &json!({})).unwrap(); + assert!(s.catalog.stacks().next().is_none()); + let _ = std::fs::remove_dir_all(&dir); +} + /// Find Dust Spots: soft dark spots on a smooth sky are found and healed (one undo step). #[test] fn dust_spots_are_found_and_healed() { From ed7dbd8082a5b8c88a313923ad9367c06bc89800 Mon Sep 17 00:00:00 2001 From: helgehelge123 <117832631+helgehelge123@users.noreply.github.com> Date: Mon, 2 Nov 2026 02:30:19 +0100 Subject: [PATCH 4/4] Assisted Culling: a cull dialog without stack_groups reads it as false Like reset_bursts, the field takes its default when the JSON leaves it out, so main's dialog-copy test builds the dialog unchanged. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/state/dialog.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/ui-egui/src/state/dialog.rs b/crates/ui-egui/src/state/dialog.rs index 4c0549e926..092da21881 100644 --- a/crates/ui-egui/src/state/dialog.rs +++ b/crates/ui-egui/src/state/dialog.rs @@ -171,6 +171,7 @@ pub enum Dialog { Cull { reject_below: f32, pick_best: bool, + #[serde(default)] stack_groups: bool, burst_gap: f32, similarity: f32,