mirror of
https://github.com/storytold/lightcraft.git
synced 2026-11-28 01:09:49 +01:00
Merge pull request #2350 from helgehelge123/cull-group-dnd
LR-LIB-CULL: arrange bursts by hand with drag and drop, the first photo is the pick (stacked on #2281)
This commit is contained in:
25 files changed
+1452
-49
No files matched your search
@@ -0,0 +1,167 @@
|
||||
//! Bursts: the look-alike shots Assisted Culling groups ([`crate::Analysis::group`]), in the
|
||||
//! order they are shown and arranged — the pick first.
|
||||
//!
|
||||
//! A burst culling made is ordered by what culling found: its best photo, then the sharper
|
||||
//! shots, then capture time. Once the person arranges a burst by hand every member carries its
|
||||
//! place ([`crate::Analysis::rank`]), and that order is kept.
|
||||
|
||||
use std::cmp::Reverse;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use crate::{Catalog, Photo, PhotoId};
|
||||
|
||||
/// A photo's place in its burst: hand-placed ones by their place, then the best, the sharper,
|
||||
/// the earlier (a time that doesn't read last), the lower id.
|
||||
fn order_key(p: &Photo) -> (u32, bool, Reverse<i64>, bool, &str, PhotoId) {
|
||||
let a = p.analysis.unwrap_or_default();
|
||||
let when = p.captured.as_deref().and_then(wall_clock);
|
||||
(a.rank.unwrap_or(u32::MAX), !a.best, Reverse(sharpness_key(a.sharpness)), when.is_none(), when.unwrap_or(""), p.id)
|
||||
}
|
||||
|
||||
/// Sharpness (0..100) in thousandths: a fixed-point key keeps the sort total. `as` saturates, so
|
||||
/// an infinity is the sharpest or softest there is, and a NaN counts as 0.
|
||||
fn sharpness_key(sharpness: f32) -> i64 {
|
||||
(sharpness * 1000.0) as i64
|
||||
}
|
||||
|
||||
/// The local wall-clock part of an ISO 8601 capture time (`2026-05-01T10:00:00`, with any
|
||||
/// fraction of a second), or `None` when it isn't one. Its digits stand in fixed places, so as
|
||||
/// text it sorts in time order. A zone suffix is left out, as culling's burst gap does: a burst's
|
||||
/// shots are seconds apart from one camera and share their zone.
|
||||
fn wall_clock(iso: &str) -> Option<&str> {
|
||||
let b = iso.as_bytes();
|
||||
let digits = |from: usize, to: usize| b.get(from..to).is_some_and(|d| d.iter().all(u8::is_ascii_digit));
|
||||
let at = |i: usize, c: u8| b.get(i) == Some(&c);
|
||||
let shape = digits(0, 4) && at(4, b'-') && digits(5, 7) && at(7, b'-') && digits(8, 10) && at(10, b'T');
|
||||
if !(shape && digits(11, 13) && at(13, b':') && digits(14, 16) && at(16, b':') && digits(17, 19)) {
|
||||
return None;
|
||||
}
|
||||
let end = iso[19..].find(|c: char| c != '.' && !c.is_ascii_digit()).map_or(iso.len(), |i| 19 + i);
|
||||
Some(&iso[..end])
|
||||
}
|
||||
|
||||
impl Catalog {
|
||||
/// Every burst: its number → its photos (deleted ones left out), pick first.
|
||||
pub fn burst_index(&self) -> HashMap<u32, Vec<PhotoId>> {
|
||||
let mut by: HashMap<u32, Vec<&Photo>> = HashMap::new();
|
||||
for p in self.photos.values().filter(|p| !p.deleted) {
|
||||
if let Some(g) = p.analysis.and_then(|a| a.group) {
|
||||
by.entry(g).or_default().push(&**p);
|
||||
}
|
||||
}
|
||||
by.into_iter()
|
||||
.map(|(g, mut photos)| {
|
||||
photos.sort_by(|a, b| order_key(a).cmp(&order_key(b)));
|
||||
(g, photos.into_iter().map(|p| p.id).collect())
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The photos of burst `group`, pick first (empty when there is no such burst).
|
||||
pub fn burst(&self, group: u32) -> Vec<PhotoId> {
|
||||
self.burst_index().remove(&group).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// The bursts `ids` meet, in the order their first photo appears in `ids`, each pick first.
|
||||
/// Only photos in `scope` count as members (the photos of a view and the hidden members of
|
||||
/// its collapsed stacks, say); `None` takes every photo of the burst.
|
||||
pub fn bursts_among(&self, ids: &[PhotoId], scope: Option<&HashSet<PhotoId>>) -> Vec<(u32, Vec<PhotoId>)> {
|
||||
let mut index = self.burst_index();
|
||||
let mut out = Vec::new();
|
||||
for id in ids {
|
||||
let Some(g) = self.photo(*id).and_then(|p| p.analysis).and_then(|a| a.group) else { continue };
|
||||
if let Some(mut photos) = index.remove(&g) {
|
||||
if let Some(scope) = scope {
|
||||
photos.retain(|p| scope.contains(p));
|
||||
}
|
||||
if !photos.is_empty() {
|
||||
out.push((g, photos));
|
||||
}
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// A burst number no photo uses (deleted ones included, so Undo never brings back a clash).
|
||||
pub fn next_burst_id(&self) -> u32 {
|
||||
self.photos.values().filter_map(|p| p.analysis.and_then(|a| a.group)).max().unwrap_or(0) + 1
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{Analysis, Catalog, Op, Photo, PhotoId, Source};
|
||||
|
||||
fn add(c: &mut Catalog, when: &str, a: Option<Analysis>) -> PhotoId {
|
||||
let id = c.alloc_photo_id();
|
||||
let mut p = Photo::new(id, Source::File { path: format!("/p/{}.jpg", id.0) }, "p.jpg", "JPEG", 4, 3, "2026-01-01");
|
||||
p.captured = Some(when.into());
|
||||
p.analysis = a;
|
||||
c.apply(Op::AddPhoto { photo: Box::new(p) }).unwrap();
|
||||
id
|
||||
}
|
||||
|
||||
fn shot(group: u32, sharpness: f32, best: bool, rank: Option<u32>) -> Option<Analysis> {
|
||||
Some(Analysis { sharpness, group: Some(group), best, rank, ..Default::default() })
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_culled_burst_shows_its_best_then_the_sharper_shots() {
|
||||
let mut c = Catalog::new();
|
||||
let a = add(&mut c, "2026-05-01T10:00:00", shot(1, 20.0, false, None));
|
||||
let b = add(&mut c, "2026-05-01T10:00:01", shot(1, 80.0, true, None));
|
||||
let d = add(&mut c, "2026-05-01T10:00:02", shot(1, 50.0, false, None));
|
||||
let loose = add(&mut c, "2026-05-01T10:00:03", Some(Analysis::default()));
|
||||
assert_eq!(c.burst(1), vec![b, d, a]);
|
||||
assert!(c.burst(2).is_empty());
|
||||
assert_eq!(c.bursts_among(&[a, loose, d], None), vec![(1, vec![b, d, a])]);
|
||||
assert_eq!(c.next_burst_id(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_burst_arranged_by_hand_keeps_its_order() {
|
||||
let mut c = Catalog::new();
|
||||
// the pick by hand is the softest shot
|
||||
let a = add(&mut c, "2026-05-01T10:00:00", shot(3, 20.0, true, Some(0)));
|
||||
let b = add(&mut c, "2026-05-01T10:00:01", shot(3, 80.0, false, Some(2)));
|
||||
let d = add(&mut c, "2026-05-01T10:00:02", shot(3, 50.0, false, Some(1)));
|
||||
let other = add(&mut c, "2026-05-01T11:00:00", shot(7, 50.0, true, None));
|
||||
let other2 = add(&mut c, "2026-05-01T11:00:01", shot(7, 40.0, false, None));
|
||||
assert_eq!(c.burst(3), vec![a, d, b]);
|
||||
// in the order the view meets them; a scope keeps a burst's members within it
|
||||
assert_eq!(c.bursts_among(&[other, b], None), vec![(7, vec![other, other2]), (3, vec![a, d, b])]);
|
||||
let scope = [b, d, other].into_iter().collect();
|
||||
assert_eq!(c.bursts_among(&[b, other], Some(&scope)), vec![(3, vec![d, b]), (7, vec![other])]);
|
||||
assert_eq!(c.next_burst_id(), 8);
|
||||
// deleted photos are no member
|
||||
c.apply(Op::SetDeleted { id: d, deleted: true }).unwrap();
|
||||
assert_eq!(c.burst(3), vec![a, b]);
|
||||
assert_eq!(c.next_burst_id(), 8);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_sharpness_that_does_not_measure_sorts_without_a_panic() {
|
||||
let mut c = Catalog::new();
|
||||
let nan = add(&mut c, "2026-05-01T10:00:00", shot(4, f32::NAN, false, None));
|
||||
let soft = add(&mut c, "2026-05-01T10:00:01", shot(4, 10.0, false, None));
|
||||
let low = add(&mut c, "2026-05-01T10:00:02", shot(4, f32::NEG_INFINITY, false, None));
|
||||
let high = add(&mut c, "2026-05-01T10:00:03", shot(4, f32::INFINITY, false, None));
|
||||
// a NaN counts as 0; the infinities saturate at either end
|
||||
assert_eq!(c.burst(4), vec![high, soft, nan, low]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn capture_times_sort_by_their_wall_clock() {
|
||||
let mut c = Catalog::new();
|
||||
let s = |c: &mut Catalog, when: &str| add(c, when, shot(5, 50.0, false, None));
|
||||
let unread = s(&mut c, "1. Mai 2026");
|
||||
let second = s(&mut c, "2026-05-01T10:00:01+02:00");
|
||||
let half = s(&mut c, "2026-05-01T10:00:00.5");
|
||||
let missing = s(&mut c, "");
|
||||
let tenth = s(&mut c, "2026-05-01T10:00:00.12Z");
|
||||
// fractions of a second in order, the zone left out, a time that doesn't read last by id
|
||||
assert_eq!(c.burst(5), vec![tenth, half, second, unread, missing]);
|
||||
assert_eq!(super::wall_clock("2026-05-01T10:00:00.12-07:00"), Some("2026-05-01T10:00:00.12"));
|
||||
assert_eq!(super::wall_clock("2026-05-01 10:00:00"), None);
|
||||
}
|
||||
}
|
||||
@@ -65,6 +65,7 @@
|
||||
//! | 11 | lens database profiles named in the Optics panel | `EmbeddedLens.source` |
|
||||
//! | 12 | history steps and versions share segmentation grids (#2154) | `Catalog.grids`, `SegMask.grid` |
|
||||
//! | 13 | Lens Blur | `DevelopSettings.lens_blur`, `Mask.adjust.lens_blur` |
|
||||
//! | 14 | bursts arranged by hand in Assisted Culling | `Analysis.rank` |
|
||||
//!
|
||||
//! Rules:
|
||||
//! - **Bump [`VERSION`]** (and add a row above) in the change that adds an [`Op`] variant or a
|
||||
@@ -89,7 +90,7 @@ pub const LOG: &str = "catalog.log";
|
||||
const FORMAT: &str = "lightcraft-catalog";
|
||||
/// The catalog format this build writes (and the newest it reads). See the module docs →
|
||||
/// *Format versions*; bump it whenever an [`Op`] variant or a serialized field is added.
|
||||
pub const VERSION: u32 = 13;
|
||||
pub const VERSION: u32 = 14;
|
||||
|
||||
/// When [`Journal::wants_snapshot`] says it's time to compact the log.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#![forbid(unsafe_code)]
|
||||
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]
|
||||
|
||||
pub mod bursts;
|
||||
pub mod dates;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[doc(hidden)]
|
||||
|
||||
@@ -355,6 +355,20 @@ pub struct Analysis {
|
||||
pub group: Option<u32>,
|
||||
/// The best photo of its group.
|
||||
pub best: bool,
|
||||
/// Set when the person arranged this photo's burst by hand (Window ▸ Bursts, or
|
||||
/// `photo.moveToBurst`): its place in [`Analysis::group`], 0 being the pick, or `Some(0)` for
|
||||
/// a photo taken out of every burst. Culling run again keeps such a photo's burst, place and
|
||||
/// pick (unless asked to regroup). `None` while the burst is as culling made it; left out of the
|
||||
/// catalog JSON then, so older catalogs read unchanged.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub rank: Option<u32>,
|
||||
}
|
||||
|
||||
impl Analysis {
|
||||
/// Whether the person placed this photo by hand (see [`Analysis::rank`]).
|
||||
pub fn by_hand(&self) -> bool {
|
||||
self.rank.is_some()
|
||||
}
|
||||
}
|
||||
|
||||
/// Raw formats whose files carry vendor white-balance multipliers but no colour matrices: their starting
|
||||
|
||||
@@ -192,6 +192,33 @@ fn bad_crc_is_still_a_torn_tail() {
|
||||
assert!(r.torn_bytes > 0 && r.damaged.is_none(), "{r:?}");
|
||||
}
|
||||
|
||||
/// A v13 library (bursts as culling made them) reads every analysis as not arranged by hand and
|
||||
/// is rewritten in the current format; a place set by hand survives the round trip, and none is
|
||||
/// written for a photo left as culling placed it.
|
||||
#[test]
|
||||
fn v13_analysis_loads_unarranged_and_is_upgraded() {
|
||||
let mut c = Catalog::new();
|
||||
let id = c.alloc_photo_id();
|
||||
let mut p = Photo::new(id, Source::File { path: "/p/a.jpg".into() }, "a.jpg", "JPEG", 160, 120, "2026-01-01");
|
||||
p.analysis = Some(Analysis { sharpness: 61.0, clipped: 0.01, group: Some(2), best: true, ..Default::default() });
|
||||
c.apply(Op::AddPhoto { photo: Box::new(p) }).unwrap();
|
||||
let snap = c.to_snapshot();
|
||||
assert!(!snap.contains("rank"), "nothing new is written for a burst culling made: {snap}");
|
||||
let m = MemStore::new();
|
||||
m.set(SNAPSHOT, format!("{{\"format\":\"lightcraft-catalog\",\"version\":13,\"seq\":1,\"catalog\":{snap}}}\n").into_bytes());
|
||||
let (_, loaded, r) = Journal::open(Box::new(m.clone())).unwrap();
|
||||
let a = loaded.photo(id).unwrap().analysis.unwrap();
|
||||
assert_eq!((a.group, a.best, a.rank, a.by_hand()), (Some(2), true, None, false));
|
||||
assert_eq!(r.upgraded_from, Some(13));
|
||||
assert_eq!(snapshot_version(&m), u64::from(VERSION));
|
||||
// a place set by hand round-trips
|
||||
let mut c = loaded;
|
||||
let b = Analysis { rank: Some(1), best: false, ..a };
|
||||
c.apply(Op::SetAnalysis { id, analysis: Some(b) }).unwrap();
|
||||
let again: Catalog = serde_json::from_str(&c.to_snapshot()).unwrap();
|
||||
assert_eq!(again.photo(id).unwrap().analysis, Some(b));
|
||||
}
|
||||
|
||||
/// Guard for the version rule (see `journal` → *Format versions*): adding an [`Op`] variant breaks
|
||||
/// this match. When it does, bump `journal::VERSION`, add a row to the format table, and add the
|
||||
/// variant here under the new version. A version that only adds serialized fields raises
|
||||
@@ -238,9 +265,9 @@ fn op_variants_are_versioned() {
|
||||
Op::SetHistoryCursor { .. } => 8,
|
||||
}
|
||||
}
|
||||
/// v13: Lens Blur in develop settings and mask adjustments (v12: `Catalog.grids` and `SegMask.grid`; v11: `EmbeddedLens.source`;
|
||||
/// v10: `Mask.on_photo`; v9: `Photo.preview_checked` and `Op::SetContent.preview_checked`).
|
||||
const NEWEST_FIELDS: u32 = 13;
|
||||
/// v14: `Analysis.rank` (v13: Lens Blur in develop settings and mask adjustments; v12: `Catalog.grids` and `SegMask.grid`;
|
||||
/// v11: `EmbeddedLens.source`; v10: `Mask.on_photo`; v9: `Photo.preview_checked` and `Op::SetContent.preview_checked`).
|
||||
const NEWEST_FIELDS: u32 = 14;
|
||||
let newest = since(&Op::SetHistoryCursor { id: PhotoId(1), cursor: None });
|
||||
assert_eq!(newest.max(NEWEST_FIELDS), VERSION, "the newest op's or fields' version must be the current format version");
|
||||
}
|
||||
+249
-35
@@ -29,10 +29,14 @@ fn analyze(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
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"))?,
|
||||
let flag_param = |key: &str| -> Result<bool> {
|
||||
match p.get(key) {
|
||||
None | Some(Value::Null) => Ok(false),
|
||||
Some(v) => v.as_bool().ok_or_else(|| super::bad("photo.analyze", format!("`{key}` must be true or false"))),
|
||||
}
|
||||
};
|
||||
let stack_groups = flag_param("stackGroups")?;
|
||||
let reset = flag_param("resetBursts")?;
|
||||
// measure (thumbnail-level sources: fast, and enough for focus at 512 px)
|
||||
let mut rows: Vec<(PhotoId, Option<i64>, f32, f32, [f32; 64])> = Vec::new();
|
||||
let mut failed = Vec::new();
|
||||
@@ -48,17 +52,25 @@ fn analyze(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
// bursts: consecutive (by capture time) look-alike shots
|
||||
rows.sort_by_key(|r| (r.1.unwrap_or(i64::MAX), r.0));
|
||||
// A photo whose burst was arranged by hand keeps it (burst, place, pick): only its scores
|
||||
// are measured again. The others are grouped among themselves, in bursts numbered after
|
||||
// every burst that stays (earlier runs on other photos, the ones arranged by hand).
|
||||
let by_hand = |id: PhotoId| -> Option<Analysis> { s.catalog.photo(id).and_then(|p| p.analysis).filter(|a| !reset && a.by_hand()) };
|
||||
let kept: Vec<Option<Analysis>> = rows.iter().map(|r| by_hand(r.0)).collect();
|
||||
let auto: Vec<usize> = (0..rows.len()).filter(|i| kept[*i].is_none()).collect();
|
||||
let regrouped: std::collections::HashSet<PhotoId> = auto.iter().map(|i| rows[*i].0).collect();
|
||||
let mut next = s.catalog.photos().filter(|p| !regrouped.contains(&p.id)).filter_map(|p| p.analysis.and_then(|a| a.group)).max().unwrap_or(0) + 1;
|
||||
let mut group_of: Vec<Option<u32>> = vec![None; rows.len()];
|
||||
let mut next = 1u32;
|
||||
for i in 1..rows.len() {
|
||||
let (a, b) = (&rows[i - 1], &rows[i]);
|
||||
for w in auto.windows(2) {
|
||||
let (i, j) = (w[0], w[1]);
|
||||
let (a, b) = (&rows[i], &rows[j]);
|
||||
let close = matches!((a.1, b.1), (Some(x), Some(y)) if (y.saturating_sub(x)).unsigned_abs() as f64 <= gap);
|
||||
if close && lightcraft_pipeline::cull::similarity(&a.4, &b.4) >= same {
|
||||
let g = *group_of[i - 1].get_or_insert_with(|| {
|
||||
let g = *group_of[i].get_or_insert_with(|| {
|
||||
next += 1;
|
||||
next - 1
|
||||
});
|
||||
group_of[i] = Some(g);
|
||||
group_of[j] = Some(g);
|
||||
}
|
||||
}
|
||||
let mut best: std::collections::HashMap<u32, (usize, f32)> = Default::default();
|
||||
@@ -74,9 +86,16 @@ fn analyze(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let (mut rejected, mut picked) = (0, 0);
|
||||
let mut out = Vec::new();
|
||||
for (i, (id, _, sharp, clip, _)) in rows.iter().enumerate() {
|
||||
let g = group_of[i];
|
||||
let is_best = g.is_some_and(|g| best.get(&g).is_some_and(|b| b.0 == i));
|
||||
ops.push(Op::SetAnalysis { id: *id, analysis: Some(Analysis { sharpness: *sharp, clipped: *clip, group: g, best: is_best }) });
|
||||
let analysis = match kept[i] {
|
||||
Some(k) => Analysis { sharpness: *sharp, clipped: *clip, ..k },
|
||||
None => {
|
||||
let g = group_of[i];
|
||||
let is_best = g.is_some_and(|g| best.get(&g).is_some_and(|b| b.0 == i));
|
||||
Analysis { sharpness: *sharp, clipped: *clip, group: g, best: is_best, rank: None }
|
||||
}
|
||||
};
|
||||
let (g, is_best) = (analysis.group, analysis.best);
|
||||
ops.push(Op::SetAnalysis { id: *id, analysis: Some(analysis) });
|
||||
let flag = s.catalog.photo(*id).map(|p| p.flag).unwrap_or_default();
|
||||
if reject_below.is_some_and(|t| *sharp < t) && flag != Flag::Reject {
|
||||
ops.push(Op::SetFlag { id: *id, flag: Flag::Reject });
|
||||
@@ -85,29 +104,49 @@ fn analyze(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
ops.push(Op::SetFlag { id: *id, flag: Flag::Pick });
|
||||
picked += 1;
|
||||
}
|
||||
out.push(json!({"id": id.0, "sharpness": (sharp * 10.0).round() / 10.0, "clipped": clip, "group": g, "best": is_best}));
|
||||
out.push(json!({"id": id.0, "sharpness": (sharp * 10.0).round() / 10.0, "clipped": clip, "group": g, "best": is_best, "byHand": kept[i].is_some()}));
|
||||
}
|
||||
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.
|
||||
// from its other photos when two or more remain. A burst culling grouped has the sharpest
|
||||
// of those on top; a burst arranged by hand keeps its order, its pick (place 0) on top.
|
||||
let index = s.catalog.stack_index();
|
||||
let mut members: std::collections::BTreeMap<u32, Vec<(PhotoId, f32)>> = 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));
|
||||
let mut arranged: std::collections::BTreeMap<u32, Vec<(u32, PhotoId)>> = Default::default();
|
||||
for (i, r) in rows.iter().enumerate() {
|
||||
if index.contains_key(&r.0) || !s.catalog.photo(r.0).is_some_and(|ph| !ph.deleted) {
|
||||
continue;
|
||||
}
|
||||
match kept[i] {
|
||||
Some(k) => {
|
||||
if let Some(g) = k.group {
|
||||
arranged.entry(g).or_default().push((k.rank.unwrap_or(u32::MAX), r.0));
|
||||
}
|
||||
}
|
||||
None => {
|
||||
if let Some(g) = group_of[i] {
|
||||
members.entry(g).or_default().push((r.0, r.2));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut orders: Vec<Vec<PhotoId>> = Vec::new();
|
||||
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<PhotoId> = group.iter().map(|m| m.0).collect();
|
||||
let mut photos = vec![top.0];
|
||||
photos.extend(group.iter().map(|m| m.0).filter(|p| *p != top.0));
|
||||
orders.push(photos);
|
||||
}
|
||||
for group in arranged.values_mut() {
|
||||
group.sort();
|
||||
orders.push(group.iter().map(|m| m.1).collect());
|
||||
}
|
||||
for photos in orders {
|
||||
if photos.len() >= 2
|
||||
&& let Some(op) = s.catalog.group_ops(top.0, &photos, true)
|
||||
&& let Some(op) = s.catalog.group_ops(photos[0], &photos, true)
|
||||
{
|
||||
ops.push(op);
|
||||
stacks += 1;
|
||||
@@ -118,22 +157,188 @@ fn analyze(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
s.commit("Assisted Culling", Op::Batch { ops })?;
|
||||
}
|
||||
if stacks > 0 {
|
||||
// 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.ids.retain(|id| vis.contains(id));
|
||||
if !s.selection.ids.contains(&top) {
|
||||
s.selection.ids.push(top);
|
||||
keep_active_shown(s);
|
||||
}
|
||||
let kept = kept.iter().filter(|k| k.is_some()).count();
|
||||
Ok(json!({"photos": out, "groups": best.len(), "kept": kept, "stacks": stacks, "rejected": rejected, "picked": picked, "failed": failed}))
|
||||
}
|
||||
|
||||
/// 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 stays selected.
|
||||
fn keep_active_shown(s: &mut Session) {
|
||||
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.ids.retain(|id| vis.contains(id));
|
||||
if !s.selection.ids.contains(&top) {
|
||||
s.selection.ids.push(top);
|
||||
}
|
||||
s.selection.active = Some(top);
|
||||
}
|
||||
}
|
||||
|
||||
/// Where `photo.moveToBurst` puts the photos.
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
enum Dest {
|
||||
Burst(u32),
|
||||
New,
|
||||
Nowhere,
|
||||
}
|
||||
|
||||
/// Arrange bursts by hand: `ids` go into a burst at `index` (0 = the pick), into a new burst, or
|
||||
/// out of every burst. Every burst touched is then arranged by hand ([`Analysis::rank`]), so
|
||||
/// culling run again keeps it. What marks a burst's pick follows its first photo: `best` (the
|
||||
/// Best of Similar Shots rule), the Pick flag when culling's pick had it, and the top of the
|
||||
/// burst's stack when the burst is stacked. One undo step.
|
||||
fn move_to_burst(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
const C: &str = "photo.moveToBurst";
|
||||
let mut ids = s.targets(p)?;
|
||||
let mut seen = std::collections::HashSet::new();
|
||||
ids.retain(|id| seen.insert(*id));
|
||||
if ids.is_empty() {
|
||||
return Err(super::bad(C, "no photos"));
|
||||
}
|
||||
for id in &ids {
|
||||
match s.catalog.photo(*id) {
|
||||
Some(ph) if ph.deleted => return Err(super::bad(C, format!("“{}” is deleted", ph.file_name))),
|
||||
Some(ph) if ph.analysis.is_none() => {
|
||||
return Err(super::bad(C, format!("“{}” has no culling scores yet: run Assisted Culling on it first", ph.file_name)));
|
||||
}
|
||||
s.selection.active = Some(top);
|
||||
Some(_) => {}
|
||||
None => return Err(super::bad(C, format!("no photo {}", id.0))),
|
||||
}
|
||||
}
|
||||
Ok(json!({"photos": out, "groups": best.len(), "stacks": stacks, "rejected": rejected, "picked": picked, "failed": failed}))
|
||||
let group = |s: &Session, id: PhotoId| s.catalog.photo(id).and_then(|p| p.analysis).and_then(|a| a.group);
|
||||
let index = s.catalog.burst_index();
|
||||
let into = match p.get("burst") {
|
||||
None => Dest::Burst(group(s, ids[0]).ok_or_else(|| super::bad(C, "the photo isn't in a burst: say which `burst` it goes to"))?),
|
||||
Some(Value::Null) => Dest::Nowhere,
|
||||
Some(Value::String(n)) if n == "new" => Dest::New,
|
||||
Some(v) => match v.as_u64().and_then(|n| u32::try_from(n).ok()) {
|
||||
Some(n) if index.contains_key(&n) => Dest::Burst(n),
|
||||
Some(n) => return Err(super::bad(C, format!("there is no burst {n}"))),
|
||||
None => return Err(super::bad(C, "`burst` must be a burst number, \"new\" or null")),
|
||||
},
|
||||
};
|
||||
let at = match p.get("index") {
|
||||
None | Some(Value::Null) => usize::MAX,
|
||||
Some(v) => v.as_u64().map(|n| n as usize).ok_or_else(|| super::bad(C, "`index` must be a place in the burst: 0 (the pick), 1, …"))?,
|
||||
};
|
||||
// the bursts touched, before and after
|
||||
let target = match into {
|
||||
Dest::Burst(g) => Some(g),
|
||||
Dest::New => Some(s.catalog.next_burst_id()),
|
||||
Dest::Nowhere => None,
|
||||
};
|
||||
let mut old: BTreeMap<u32, Vec<PhotoId>> = BTreeMap::new();
|
||||
for g in ids.iter().filter_map(|id| group(s, *id)).chain(target) {
|
||||
old.entry(g).or_insert_with(|| index.get(&g).cloned().unwrap_or_default());
|
||||
}
|
||||
let mut new = old.clone();
|
||||
for members in new.values_mut() {
|
||||
members.retain(|m| !ids.contains(m));
|
||||
}
|
||||
if let Some(g) = target {
|
||||
let members = new.entry(g).or_default();
|
||||
let at = at.min(members.len());
|
||||
members.splice(at..at, ids.iter().copied());
|
||||
}
|
||||
// each photo's burst, place and pick: a burst a move leaves with one photo is no burst (the
|
||||
// burst moved into stays one, so a new burst may start with one photo for more to join)
|
||||
let remains = |g: u32, members: &Vec<PhotoId>| members.len() >= 2 || (target == Some(g) && !members.is_empty());
|
||||
let mut placed: HashMap<PhotoId, (Option<u32>, u32, bool)> = ids.iter().map(|id| (*id, (None, 0, false))).collect();
|
||||
for (g, members) in &new {
|
||||
let stays = remains(*g, members);
|
||||
for (i, m) in members.iter().enumerate() {
|
||||
placed.insert(*m, if stays { (Some(*g), i as u32, i == 0) } else { (None, 0, false) });
|
||||
}
|
||||
}
|
||||
let mut ops = Vec::new();
|
||||
let mut by_id: Vec<_> = placed.iter().collect();
|
||||
by_id.sort_by_key(|(id, _)| **id);
|
||||
for (id, (g, rank, best)) in by_id {
|
||||
let Some(was) = s.catalog.photo(*id).and_then(|p| p.analysis) else { continue };
|
||||
let now = Analysis { group: *g, rank: Some(*rank), best: *best, ..was };
|
||||
if now != was {
|
||||
ops.push(Op::SetAnalysis { id: *id, analysis: Some(now) });
|
||||
}
|
||||
}
|
||||
// what the target burst holds now
|
||||
let members: Option<Vec<u64>> = target.and_then(|g| new.get(&g).filter(|m| remains(g, m))).map(|m| m.iter().map(|p| p.0).collect());
|
||||
let report = |changed: bool| json!({"burst": members.as_ref().and(target), "pick": members.as_ref().and_then(|m| m.first()), "photos": members, "changed": changed});
|
||||
if ops.is_empty() {
|
||||
return Ok(report(false));
|
||||
}
|
||||
// the Pick culling gave a burst's pick goes to its new pick
|
||||
let is_pick = |id: PhotoId| placed.get(&id).is_some_and(|p| p.2);
|
||||
let flag = |s: &Session, id: PhotoId| s.catalog.photo(id).map(|p| p.flag).unwrap_or_default();
|
||||
let mut flags: BTreeMap<PhotoId, Flag> = BTreeMap::new();
|
||||
for (g, before) in &old {
|
||||
let Some(old_pick) = before.iter().copied().find(|m| s.catalog.photo(*m).and_then(|p| p.analysis).is_some_and(|a| a.best)) else { continue };
|
||||
let new_pick = new.get(g).filter(|m| remains(*g, m)).and_then(|m| m.first()).copied();
|
||||
if flag(s, old_pick) != Flag::Pick || new_pick == Some(old_pick) {
|
||||
continue;
|
||||
}
|
||||
if !is_pick(old_pick) {
|
||||
flags.insert(old_pick, Flag::None);
|
||||
}
|
||||
// the new pick was chosen by hand: it takes the Pick even over a Reject
|
||||
if let Some(n) = new_pick {
|
||||
flags.insert(n, Flag::Pick);
|
||||
}
|
||||
}
|
||||
ops.extend(flags.into_iter().map(|(id, flag)| Op::SetFlag { id, flag }));
|
||||
// a stacked burst (a stack of exactly its photos, as culling stacks them) follows it: its stack
|
||||
// shrinks, grows or goes, in the burst's order. Shrinking first: a photo is in one stack at a time.
|
||||
let (mut shrink, mut grow) = (Vec::new(), Vec::new());
|
||||
let mut grows_target = false;
|
||||
let mut followed = std::collections::HashSet::new();
|
||||
for (g, before) in old.iter().filter(|(_, m)| m.len() >= 2) {
|
||||
let Some(st) = s.catalog.stack_of(before[0]).filter(|st| st.photos.len() == before.len() && before.iter().all(|m| st.photos.contains(m)))
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
followed.insert(st.id);
|
||||
let after = new.get(g).filter(|m| m.len() >= 2);
|
||||
match after {
|
||||
None => shrink.push(Op::RemoveStack { id: st.id }),
|
||||
Some(after) if after == &st.photos => {}
|
||||
Some(after) => {
|
||||
let op = Op::SetStack { id: st.id, photos: after.clone(), collapsed: st.collapsed };
|
||||
if after.iter().all(|m| st.photos.contains(m)) {
|
||||
shrink.push(op)
|
||||
} else {
|
||||
grows_target = true;
|
||||
grow.push(op)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if grows_target {
|
||||
// photos joining a stacked burst leave any other stack they are in
|
||||
let strays: Vec<PhotoId> = ids.iter().copied().filter(|id| s.catalog.stack_of(*id).is_some_and(|st| !followed.contains(&st.id))).collect();
|
||||
shrink.extend(s.catalog.remove_from_stacks_ops(&strays));
|
||||
}
|
||||
let restacked = !shrink.is_empty() || !grow.is_empty();
|
||||
ops.extend(shrink);
|
||||
ops.extend(grow);
|
||||
let same = matches!(into, Dest::Burst(g) if ids.iter().all(|id| group(s, *id) == Some(g)));
|
||||
let label = match into {
|
||||
Dest::Burst(_) if same && at == 0 => "Choose Burst Pick",
|
||||
Dest::Burst(_) if same => "Rearrange Burst",
|
||||
Dest::Burst(_) => "Move to Burst",
|
||||
Dest::New => "New Burst",
|
||||
Dest::Nowhere => "Remove from Burst",
|
||||
};
|
||||
s.commit(label, Op::Batch { ops })?;
|
||||
if restacked {
|
||||
keep_active_shown(s);
|
||||
}
|
||||
Ok(report(true))
|
||||
}
|
||||
|
||||
/// `burstGap` (seconds, 0..=a day) and `similarity` (0..=1) of `photo.analyze`, refused before
|
||||
@@ -168,9 +373,18 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Assisted Culling",
|
||||
[],
|
||||
None,
|
||||
"{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}",
|
||||
"{ids?, rejectBelow?: sharpness 0..100, pickBest?: bool, stackGroups?: bool (false), burstGap?: seconds 0..86400 (10), similarity?: 0..1 (0.93), resetBursts?: bool (false)} — 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). Photos whose burst was arranged by hand (`photo.moveToBurst`) keep their burst, place and pick and are only scored again, unless `resetBursts`; one undo step → {photos: [{id, sharpness, clipped, group, best, byHand}], groups, kept, stacks, rejected, picked, failed}",
|
||||
always,
|
||||
analyze
|
||||
),
|
||||
cmd!(
|
||||
"photo.moveToBurst",
|
||||
"Move to Burst",
|
||||
[],
|
||||
None,
|
||||
"{ids?, burst?: number | \"new\" | null (default: the first photo's burst), index?: place (0 = the pick; default last)} — arrange Assisted Culling's bursts by hand (Window ▸ Bursts): the photos go into that burst at `index`, into a new burst, or (null) out of every burst; reordering within a burst is the same call. A burst left with one photo is no burst. The pick follows the first place: Best of Similar Shots, the Pick flag culling gave the old pick, and the top of the burst's stack. Every burst touched is kept as arranged when culling runs again (`photo.analyze` `resetBursts` forgets it). Photos must have been culled; one undo step → {burst, photos, pick, changed}",
|
||||
always,
|
||||
move_to_burst
|
||||
),
|
||||
]
|
||||
}
|
||||
@@ -9,6 +9,7 @@ mod album_remove;
|
||||
mod albums_local;
|
||||
mod autosync_wb;
|
||||
mod batch_sidebar;
|
||||
mod bursts;
|
||||
mod color;
|
||||
mod constrain_crop;
|
||||
mod crop_angle;
|
||||
|
||||
@@ -0,0 +1,262 @@
|
||||
//! Bursts arranged by hand (`photo.moveToBurst`): a photo moved within its burst, into another,
|
||||
//! into a new one or out of every burst; the pick follows the first place, and with it the
|
||||
//! Best of Similar Shots rule, the Pick flag culling set and the burst's stack. Culling run again
|
||||
//! keeps what was arranged by hand.
|
||||
|
||||
use lightcraft_catalog::{Analysis, Flag, Op, Photo, PhotoId, Source, Stack};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::Session;
|
||||
|
||||
/// A photo culled into `group` (`None`: culled, in no burst; `best`: its pick), or never culled.
|
||||
fn add(s: &mut Session, name: &str, when: &str, culled: Option<(Option<u32>, f32, bool)>) -> PhotoId {
|
||||
let id = s.catalog.alloc_photo_id();
|
||||
let mut p = Photo::new(id, Source::File { path: format!("/nowhere/{name}") }, name, "JPEG", 40, 30, "2026-05-01T12:00:00");
|
||||
p.captured = Some(when.into());
|
||||
p.analysis = culled.map(|(group, sharpness, best)| Analysis { sharpness, group, best, ..Default::default() });
|
||||
s.catalog.apply(Op::AddPhoto { photo: Box::new(p) }).unwrap();
|
||||
id
|
||||
}
|
||||
|
||||
fn an(s: &Session, id: PhotoId) -> Analysis {
|
||||
s.catalog.photo(id).unwrap().analysis.unwrap()
|
||||
}
|
||||
|
||||
fn flag(s: &Session, id: PhotoId) -> Flag {
|
||||
s.catalog.photo(id).unwrap().flag
|
||||
}
|
||||
|
||||
fn mv(s: &mut Session, p: Value) -> Value {
|
||||
s.execute("photo.moveToBurst", &p).unwrap_or_else(|e| panic!("{p}: {e}"))
|
||||
}
|
||||
|
||||
/// Burst 1 (a best and picked, b, c), burst 2 (d best, e), x culled in no burst, y never culled.
|
||||
fn library() -> (Session, [PhotoId; 7]) {
|
||||
let mut s = Session::new();
|
||||
let a = add(&mut s, "a.jpg", "2026-05-01T10:00:00", Some((Some(1), 80.0, true)));
|
||||
let b = add(&mut s, "b.jpg", "2026-05-01T10:00:01", Some((Some(1), 60.0, false)));
|
||||
let c = add(&mut s, "c.jpg", "2026-05-01T10:00:02", Some((Some(1), 40.0, false)));
|
||||
let d = add(&mut s, "d.jpg", "2026-05-01T11:00:00", Some((Some(2), 70.0, true)));
|
||||
let e = add(&mut s, "e.jpg", "2026-05-01T11:00:01", Some((Some(2), 30.0, false)));
|
||||
let x = add(&mut s, "x.jpg", "2026-05-01T12:00:00", Some((None, 50.0, false)));
|
||||
let y = add(&mut s, "y.jpg", "2026-05-01T13:00:00", None);
|
||||
s.catalog.apply(Op::SetFlag { id: a, flag: Flag::Pick }).unwrap();
|
||||
(s, [a, b, c, d, e, x, y])
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_photo_dragged_to_the_front_of_its_burst_becomes_the_pick() {
|
||||
let (mut s, [a, b, c, ..]) = library();
|
||||
assert_eq!(s.catalog.burst(1), vec![a, b, c]);
|
||||
let commits = s.commits();
|
||||
// the softest shot is the one the person likes best
|
||||
let r = mv(&mut s, json!({"ids": [c.0], "index": 0}));
|
||||
assert_eq!((r["burst"].clone(), r["photos"].clone(), r["pick"].clone()), (json!(1), json!([c.0, a.0, b.0]), json!(c.0)), "{r}");
|
||||
assert_eq!(s.catalog.burst(1), vec![c, a, b]);
|
||||
assert!(an(&s, c).best && !an(&s, a).best);
|
||||
assert_eq!([an(&s, c).rank, an(&s, a).rank, an(&s, b).rank], [Some(0), Some(1), Some(2)], "the whole burst is now arranged by hand");
|
||||
// the Pick culling gave the old best goes with it
|
||||
assert_eq!((flag(&s, c), flag(&s, a)), (Flag::Pick, Flag::None));
|
||||
// and so does Best of Similar Shots
|
||||
s.execute("library.filter", &json!({"ruleSet": {"rules": [{"field": "bestOfGroup", "op": "is", "value": true}]}})).unwrap();
|
||||
let shown = s.visible_cloned();
|
||||
assert!(shown.contains(&c) && !shown.contains(&a), "{shown:?}");
|
||||
// one undo step
|
||||
assert_eq!(s.commits(), commits + 1);
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert_eq!(s.catalog.burst(1), vec![a, b, c]);
|
||||
assert!(an(&s, a).best && an(&s, a).rank.is_none());
|
||||
assert_eq!((flag(&s, a), flag(&s, c)), (Flag::Pick, Flag::None));
|
||||
// reordering further back: the pick stays, the order is kept
|
||||
mv(&mut s, json!({"ids": [b.0], "index": 2}));
|
||||
assert_eq!(s.catalog.burst(1), vec![a, c, b]);
|
||||
assert!(an(&s, a).best);
|
||||
assert_eq!(flag(&s, a), Flag::Pick);
|
||||
// a rejected shot dragged to the front was chosen by hand: it takes the Pick
|
||||
s.catalog.apply(Op::SetFlag { id: b, flag: Flag::Reject }).unwrap();
|
||||
mv(&mut s, json!({"ids": [b.0], "index": 0}));
|
||||
assert_eq!((flag(&s, b), flag(&s, a)), (Flag::Pick, Flag::None));
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert_eq!((flag(&s, b), flag(&s, a)), (Flag::Reject, Flag::Pick));
|
||||
// placing a photo where it already is changes nothing and makes no undo step
|
||||
let commits = s.commits();
|
||||
let r = mv(&mut s, json!({"ids": [a.0], "index": 0}));
|
||||
assert_eq!(r["changed"], false, "{r}");
|
||||
assert_eq!(s.commits(), commits);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn photos_move_between_bursts_into_new_ones_and_out() {
|
||||
let (mut s, [a, b, c, d, e, x, y]) = library();
|
||||
// e joins burst 1 in second place; burst 2 keeps only d, which is then in no burst
|
||||
let r = mv(&mut s, json!({"ids": [e.0], "burst": 1, "index": 1}));
|
||||
assert_eq!(r["photos"], json!([a.0, e.0, b.0, c.0]), "{r}");
|
||||
assert_eq!(an(&s, e).group, Some(1));
|
||||
assert!(s.catalog.burst(2).is_empty());
|
||||
assert_eq!((an(&s, d).group, an(&s, d).best, an(&s, d).by_hand()), (None, false, true));
|
||||
// without an index it goes last; a culled loose photo can join too
|
||||
mv(&mut s, json!({"ids": [x.0], "burst": 1}));
|
||||
assert_eq!(s.catalog.burst(1), vec![a, e, b, c, x]);
|
||||
// two photos make a new burst, in the order named
|
||||
let r = mv(&mut s, json!({"ids": [c.0, b.0], "burst": "new"}));
|
||||
let new = r["burst"].as_u64().unwrap() as u32;
|
||||
assert_ne!(new, 1, "a number no photo uses: {r}");
|
||||
assert_eq!(s.catalog.burst(new), vec![c, b]);
|
||||
assert!(an(&s, c).best);
|
||||
assert_eq!(s.catalog.burst(1), vec![a, e, x]);
|
||||
// out of every burst: the photo left alone in its burst is out too
|
||||
let r = mv(&mut s, json!({"ids": [b.0], "burst": null}));
|
||||
assert_eq!(r["burst"], Value::Null, "{r}");
|
||||
assert!(s.catalog.burst(new).is_empty());
|
||||
assert!([b, c].iter().all(|p| an(&s, *p).group.is_none() && !an(&s, *p).best && an(&s, *p).by_hand()));
|
||||
// a whole burst dropped on another merges them, the target's pick first
|
||||
mv(&mut s, json!({"ids": [b.0, c.0], "burst": "new"}));
|
||||
let merged = s.catalog.burst(1);
|
||||
let theirs = s.catalog.bursts_among(&[b], None)[0].clone();
|
||||
mv(&mut s, json!({"ids": theirs.1.iter().map(|p| p.0).collect::<Vec<_>>(), "burst": 1}));
|
||||
assert_eq!(s.catalog.burst(1), [merged, theirs.1].concat());
|
||||
assert!(s.catalog.burst(theirs.0).is_empty());
|
||||
// refused, with nothing changed: a photo never culled, a burst that isn't there, a bad index
|
||||
let commits = s.commits();
|
||||
for (p, why) in [
|
||||
(json!({"ids": [y.0], "burst": 1}), "Assisted Culling"),
|
||||
(json!({"ids": [a.0], "burst": 99}), "no burst 99"),
|
||||
(json!({"ids": [a.0], "index": -1}), "index"),
|
||||
(json!({"ids": [a.0], "burst": "first"}), "burst"),
|
||||
(json!({"ids": [d.0]}), "isn't in a burst"),
|
||||
(json!({"ids": []}), "no photos"),
|
||||
] {
|
||||
let err = s.execute("photo.moveToBurst", &p).expect_err(&p.to_string()).to_string();
|
||||
assert!(err.contains(why), "{p}: {err}");
|
||||
}
|
||||
assert_eq!(s.commits(), commits);
|
||||
// a new burst may start with one photo, for more to join
|
||||
let r = mv(&mut s, json!({"ids": [d.0], "burst": "new"}));
|
||||
let solo = r["burst"].as_u64().unwrap() as u32;
|
||||
assert_eq!(s.catalog.burst(solo), vec![d]);
|
||||
assert!(an(&s, d).best);
|
||||
mv(&mut s, json!({"ids": [x.0], "burst": solo, "index": 0}));
|
||||
assert_eq!(s.catalog.burst(solo), vec![x, d]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_stacked_burst_follows_its_pick_and_its_members() {
|
||||
let (mut s, [a, b, c, d, e, ..]) = library();
|
||||
// as Assisted Culling with "Stack each burst" leaves them: collapsed, the best on top
|
||||
s.catalog.apply(Op::AddStack { stack: Stack { id: lightcraft_catalog::StackId(1), photos: vec![a, b, c], collapsed: true } }).unwrap();
|
||||
s.catalog.apply(Op::AddStack { stack: Stack { id: lightcraft_catalog::StackId(2), photos: vec![d, e], collapsed: true } }).unwrap();
|
||||
mv(&mut s, json!({"ids": [c.0], "index": 0}));
|
||||
let st = s.catalog.stack_of(c).unwrap();
|
||||
assert_eq!((st.photos.clone(), st.collapsed), (vec![c, a, b], true), "the new pick tops the stack");
|
||||
// d moves into burst 1: its stack (now just e) goes, burst 1's stack takes it in
|
||||
s.selection = crate::Selection::single(d);
|
||||
mv(&mut s, json!({"ids": [d.0], "burst": 1, "index": 1}));
|
||||
assert_eq!(s.catalog.stack_of(c).unwrap().photos, vec![c, d, a, b]);
|
||||
assert!(s.catalog.stack_of(e).is_none());
|
||||
// d is hidden in the collapsed stack now: the stack's top is the active photo
|
||||
assert_eq!(s.selection.active, Some(c));
|
||||
// one undo brings both stacks back as they were
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert_eq!(s.catalog.stack_of(e).unwrap().photos, vec![d, e]);
|
||||
assert_eq!(s.catalog.stack_of(c).unwrap().photos, vec![c, a, b]);
|
||||
// a photo stacked with something else than its burst keeps that stack when it goes to an unstacked burst
|
||||
let (mut s, [a, b, c, _, e, x, _]) = library();
|
||||
s.catalog.apply(Op::AddStack { stack: Stack { id: lightcraft_catalog::StackId(5), photos: vec![x, e], collapsed: false } }).unwrap();
|
||||
mv(&mut s, json!({"ids": [e.0], "burst": 1}));
|
||||
assert_eq!(s.catalog.stack_of(e).unwrap().photos, vec![x, e]);
|
||||
assert_eq!(s.catalog.burst(1), vec![a, b, c, e]);
|
||||
}
|
||||
|
||||
/// Look-alike PNGs (a scene and two softer copies) for the culling runs below.
|
||||
fn burst_files(tag: &str, scene: usize) -> std::path::PathBuf {
|
||||
let dir = std::env::temp_dir().join(format!("lc-bursts-{tag}-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let img = lightcraft_scenes::demo_library()[scene].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
|
||||
};
|
||||
for (name, im) in [("1_sharp.png", img.clone()), ("2_soft.png", soften(&img, 3)), ("3_softer.png", soften(&img, 6))] {
|
||||
let data: Vec<[u8; 4]> = im
|
||||
.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: im.width, height: im.height, data }),
|
||||
&Default::default(),
|
||||
)
|
||||
.unwrap();
|
||||
std::fs::write(dir.join(format!("s{scene}_{name}")), png).unwrap();
|
||||
}
|
||||
dir
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn culling_again_keeps_bursts_arranged_by_hand() {
|
||||
let (one, two) = (burst_files("keep-1", 0), burst_files("keep-2", 7));
|
||||
let mut s = Session::new().with_fs();
|
||||
let import = |s: &mut Session, dir: &std::path::Path, hour: u32| -> Vec<PhotoId> {
|
||||
let r = s.execute("library.import", &json!({"paths": [dir.to_string_lossy()]})).unwrap();
|
||||
let mut ids: Vec<PhotoId> = r["imported"].as_array().unwrap().iter().filter_map(Value::as_u64).map(PhotoId).collect();
|
||||
ids.sort_by_key(|id| s.catalog.photo(*id).unwrap().file_name.clone());
|
||||
for (i, id) in ids.iter().enumerate() {
|
||||
s.commit("t", Op::SetCaptured { id: *id, captured: Some(format!("2026-05-01T{hour:02}:00:0{i}")) }).unwrap();
|
||||
}
|
||||
ids
|
||||
};
|
||||
let first = import(&mut s, &one, 10);
|
||||
let second = import(&mut s, &two, 14);
|
||||
let ids = |v: &[PhotoId]| v.iter().map(|p| p.0).collect::<Vec<_>>();
|
||||
// two runs on different photos number their bursts apart
|
||||
s.execute("photo.analyze", &json!({"ids": ids(&first), "pickBest": true})).unwrap();
|
||||
s.execute("photo.analyze", &json!({"ids": ids(&second)})).unwrap();
|
||||
let (g1, g2) = (an(&s, first[0]).group.unwrap(), an(&s, second[0]).group.unwrap());
|
||||
assert_ne!(g1, g2, "each run's bursts get numbers of their own");
|
||||
assert_eq!(s.catalog.burst(g1), first, "sharpest first");
|
||||
// the softest is the person's pick
|
||||
let softest = first[2];
|
||||
mv(&mut s, json!({"ids": [softest.0], "index": 0}));
|
||||
assert_eq!(flag(&s, softest), Flag::Pick);
|
||||
// culling the whole view again keeps that burst as arranged, with fresh scores
|
||||
let r = s.execute("photo.analyze", &json!({"ids": ids(&[first.clone(), second.clone()].concat()), "pickBest": true})).unwrap();
|
||||
assert_eq!(r["kept"], 3, "{r}");
|
||||
assert_eq!(s.catalog.burst(g1), vec![first[2], first[0], first[1]]);
|
||||
assert!(an(&s, softest).best && !an(&s, first[0]).best);
|
||||
assert_eq!(flag(&s, first[0]), Flag::None, "pickBest picks the pick chosen by hand, not the sharpest");
|
||||
let g2_again = an(&s, second[0]).group.unwrap();
|
||||
assert_ne!(g2_again, g1, "an automatic burst never takes a hand-made burst's number");
|
||||
assert_eq!(s.catalog.burst(g2_again), second);
|
||||
// stacking each burst stacks the one arranged by hand too, in its order, the pick on top
|
||||
let r = s.execute("photo.analyze", &json!({"ids": ids(&[first.clone(), second.clone()].concat()), "stackGroups": true})).unwrap();
|
||||
assert_eq!(r["stacks"], 2, "{r}");
|
||||
let st = s.catalog.stack_of(softest).expect("the hand-arranged burst is stacked");
|
||||
assert_eq!(st.photos, vec![first[2], first[0], first[1]], "in the order set by hand, its pick on top");
|
||||
assert_eq!(s.catalog.stack_of(second[0]).map(|st| st.top()), Some(second[0]), "an automatic burst: the sharpest on top");
|
||||
// asked to regroup, culling forgets the order set by hand
|
||||
s.execute("photo.analyze", &json!({"ids": ids(&first), "resetBursts": true})).unwrap();
|
||||
let g = an(&s, first[0]).group.unwrap();
|
||||
assert_eq!(s.catalog.burst(g), first);
|
||||
assert!(first.iter().all(|p| !an(&s, *p).by_hand()));
|
||||
assert!(s.execute("photo.analyze", &json!({"ids": ids(&first), "resetBursts": "yes"})).is_err());
|
||||
let _ = std::fs::remove_dir_all(&one);
|
||||
let _ = std::fs::remove_dir_all(&two);
|
||||
}
|
||||
@@ -2358,6 +2358,28 @@
|
||||
"CPU": "CPU",
|
||||
"A face model uses the GPU only when a check shows it gives the same results faster.": "Ein Gesichtsmodell nutzt die GPU nur, wenn eine Prüfung zeigt, dass sie dieselben Ergebnisse schneller liefert.",
|
||||
"Checking the GPU for faces": "GPU für Gesichter wird geprüft",
|
||||
"Bursts": "Serien",
|
||||
"Burst": "Serie",
|
||||
"Photo → Assisted Culling… groups look-alike shots into bursts. They show here to put right by hand.": "Foto → Unterstützte Fotoauswahl… fasst ähnliche Aufnahmen zu Serien zusammen. Hier lassen sie sich von Hand korrigieren.",
|
||||
"Drag a photo to its place: the first of a burst is its pick. Drag one into another burst, or a burst by its title onto another to merge them.": "Ziehe ein Foto an seinen Platz: Das erste einer Serie ist ihre Auswahl. Ziehe ein Foto in eine andere Serie oder eine Serie an ihrem Titel auf eine andere, um sie zusammenzuführen.",
|
||||
"New burst": "Neue Serie",
|
||||
"Not in a burst": "In keiner Serie",
|
||||
"Run Assisted Culling on it first": "Zuerst die unterstützte Fotoauswahl darauf anwenden",
|
||||
"Run Assisted Culling on these photos first": "Zuerst die unterstützte Fotoauswahl auf diese Fotos anwenden",
|
||||
"Only photos Assisted Culling scored can be in a burst: run Photo → Assisted Culling… on them first": "Nur Fotos, die die unterstützte Fotoauswahl bewertet hat, können in einer Serie sein: Wende zuerst Foto → Unterstützte Fotoauswahl… darauf an",
|
||||
"Merge into this burst": "Mit dieser Serie zusammenführen",
|
||||
"Make it the pick": "Zur Auswahl machen",
|
||||
"Put first: the first is the pick": "An den Anfang: Das erste ist die Auswahl",
|
||||
"Move here": "Hierher verschieben",
|
||||
"Move to this burst": "In diese Serie verschieben",
|
||||
"Take out of its burst": "Aus der Serie nehmen",
|
||||
"Regroup bursts I arranged by hand": "Von Hand geordnete Serien neu gruppieren",
|
||||
"Put bursts right by dragging in Window → Bursts: the first photo of a burst is its pick, and culling again keeps what you arranged.": "Serien lassen sich unter Fenster → Serien per Ziehen korrigieren: Das erste Foto einer Serie ist ihre Auswahl, und eine erneute Fotoauswahl behält, was du geordnet hast.",
|
||||
"Choose Burst Pick": "Auswahl der Serie wählen",
|
||||
"Rearrange Burst": "Serie umordnen",
|
||||
"Move to Burst": "In Serie verschieben",
|
||||
"New Burst": "Neue Serie",
|
||||
"Remove from Burst": "Aus Serie nehmen",
|
||||
"Set Folder Color Label": "Ordner-Farbmarkierung festlegen",
|
||||
"Photo Below": "Foto darunter",
|
||||
"Photo Above": "Foto darüber",
|
||||
|
||||
@@ -852,7 +852,7 @@ fn auto_stack_body(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens, dlg:
|
||||
|
||||
/// The body of the Cull dialog.
|
||||
fn cull_body(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens, dlg: &mut Dialog) {
|
||||
let Dialog::Cull { reject_below, pick_best, stack_groups, burst_gap, similarity } = dlg else { return };
|
||||
let Dialog::Cull { reject_below, pick_best, stack_groups, burst_gap, similarity, reset_bursts } = dlg else { return };
|
||||
let n = app.session.selection.ids.len();
|
||||
let scope = if n > 1 {
|
||||
crate::i18n::tr_format!("the {n} selected photos", n = n)
|
||||
@@ -906,6 +906,14 @@ fn cull_body(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens, dlg: &mut D
|
||||
crate::widgets::register(ui, "field:cullSimilar", r.rect);
|
||||
clamp_cull_burst(burst_gap, similarity);
|
||||
ui.label(egui::RichText::new(crate::i18n::tr("Lower it when a panning or moving burst splits into several groups.")).color(t.text_dim));
|
||||
let r = ui.checkbox(reset_bursts, crate::i18n::tr("Regroup bursts I arranged by hand"));
|
||||
crate::widgets::register(ui, "check:cullResetBursts", r.rect);
|
||||
ui.label(
|
||||
egui::RichText::new(crate::i18n::tr(
|
||||
"Put bursts right by dragging in Window → Bursts: the first photo of a burst is its pick, and culling again keeps what you arranged.",
|
||||
))
|
||||
.color(t.text_dim),
|
||||
);
|
||||
ui.label(
|
||||
egui::RichText::new(crate::i18n::tr("Scores stay on the photos: filter or make smart albums with Focus and Best of Similar Shots."))
|
||||
.color(t.text_dim),
|
||||
|
||||
@@ -178,11 +178,12 @@ pub fn confirm_dialog(app: &mut LightcraftApp, dlg: &Dialog) -> Result<serde_jso
|
||||
Dialog::DenoiseModel { info, accepted } => 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 | Dialog::Welcome { .. } => Ok(serde_json::Value::Null),
|
||||
Dialog::Cull { reject_below, pick_best, stack_groups, burst_gap, similarity } => {
|
||||
Dialog::Cull { reject_below, pick_best, stack_groups, burst_gap, similarity, reset_bursts } => {
|
||||
app.ui.cull_burst = Some((*burst_gap, *similarity));
|
||||
app.ui.cull_stack = *stack_groups;
|
||||
let mut p = cull_params(*reject_below, *pick_best, *burst_gap, *similarity);
|
||||
p["stackGroups"] = json!(stack_groups);
|
||||
p["resetBursts"] = json!(reset_bursts);
|
||||
app.run("photo.analyze", p)
|
||||
}
|
||||
Dialog::SmartRules { id, name, rules, parent, .. } => {
|
||||
|
||||
@@ -617,6 +617,11 @@ pub fn split_presets(dropped: Vec<String>) -> (Vec<String>, Vec<String>) {
|
||||
#[derive(Default)]
|
||||
pub struct Caches {
|
||||
keyword_tree: Option<(u64, std::sync::Arc<Vec<lightcraft_catalog::KeywordNode>>)>,
|
||||
/// The Bursts panel's bursts, by the view's generation.
|
||||
bursts: Option<(u64, panels::bursts::Shown)>,
|
||||
/// Every burst of the library (pick first), by the view's generation: what a drag in the
|
||||
/// Bursts panel compares with, so a frame of the drag builds no index of its own.
|
||||
burst_index: Option<(u64, panels::bursts::All)>,
|
||||
/// The Keywording box's read-only names (with containing keywords, or Will Export), by library
|
||||
/// revision, selection and view.
|
||||
keyword_names: Option<(u64, u64, std::sync::Arc<Vec<panels::keywording::Chip>>)>,
|
||||
|
||||
@@ -305,6 +305,7 @@ const LAYOUT: &[(&str, &[&str])] = &[
|
||||
"panel.activity",
|
||||
"panel.info",
|
||||
"panel.keywords",
|
||||
"panel.bursts",
|
||||
"---",
|
||||
"@Edit Sections",
|
||||
"@Tools",
|
||||
@@ -440,6 +441,7 @@ pub fn checked(app: &LightcraftApp, id: &str) -> Option<bool> {
|
||||
"panel.activity" => panel(RightPanel::Activity),
|
||||
"panel.info" => panel(RightPanel::Info),
|
||||
"panel.keywords" => panel(RightPanel::Keywords),
|
||||
"panel.bursts" => panel(RightPanel::Bursts),
|
||||
"panel.presets" => Some(u.presets),
|
||||
"library.toggleAutoWriteXmp" => Some(app.session.xmp.auto_write),
|
||||
_ => None,
|
||||
|
||||
@@ -1032,6 +1032,10 @@ fn ui_commands_7(app: &mut LightcraftApp, ctx: &egui::Context, id: &str, p: &Val
|
||||
panel(app, ctx, RightPanel::Activity, "History");
|
||||
Ok(Value::Null)
|
||||
}
|
||||
"panel.bursts" => {
|
||||
panel(app, ctx, RightPanel::Bursts, "Bursts");
|
||||
Ok(Value::Null)
|
||||
}
|
||||
"panel.presets" => {
|
||||
app.ui.presets = !app.ui.presets || !crate::docking::exposed(app, crate::docking::Panel::Presets);
|
||||
if app.ui.presets && app.ui.view != ViewMode::Detail {
|
||||
@@ -1326,7 +1330,14 @@ fn ui_commands_10(app: &mut LightcraftApp, ctx: &egui::Context, id: &str, p: &Va
|
||||
"photo.openOriginalInExternal" => 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, stack_groups: app.ui.cull_stack, 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,
|
||||
reset_bursts: false,
|
||||
});
|
||||
Ok(Value::Null)
|
||||
}
|
||||
"app.whatsNew" => {
|
||||
|
||||
@@ -157,6 +157,7 @@ pub const UI_COMMANDS: &[UiCommand] = &[
|
||||
// Edit Keyword Tag for the keyword picked in the Keyword List
|
||||
("panel.editKeywords", "Edit Keywords", Some("Cmd+Shift+K"), ""),
|
||||
("panel.activity", "History", None, "Window"),
|
||||
("panel.bursts", "Bursts", None, "Window"),
|
||||
("panel.close", "Close Panel", None, ""),
|
||||
// {solo?}: true opens just that section (⌥-click on its header); otherwise opens or closes it
|
||||
("section.light", "Light", Some("Cmd+1"), "Window>Edit Sections"),
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
pub mod activity;
|
||||
pub mod bottombar;
|
||||
pub mod bursts;
|
||||
pub mod chips;
|
||||
pub mod compare;
|
||||
pub mod crop_overlay;
|
||||
|
||||
@@ -0,0 +1,362 @@
|
||||
//! Window ▸ Bursts: Assisted Culling's bursts among the photos in view (with the hidden members of
|
||||
//! their collapsed stacks), each a row of thumbnails with its pick first, to put right by hand.
|
||||
//!
|
||||
//! Drag a photo to another place in its burst (to the front, and it becomes the pick), into
|
||||
//! another burst, onto *New burst* or onto *Not in a burst*; drag a burst by its title onto
|
||||
//! another to merge them. Photos dragged from the grid drop here too. A drag is the grid's photo
|
||||
//! drag ([`crate::state::UiState::dragging_photos`]: its label, Esc and release), and a drop is one
|
||||
//! `photo.moveToBurst`, so one undo step.
|
||||
//!
|
||||
//! Widgets: `burst:{n}` (a burst's title, `n` its number), `burstPhoto:{id}`, `burstPick:{n}`,
|
||||
//! `burst:new`, `burst:none`.
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::sync::Arc;
|
||||
|
||||
use egui::{Align2, Color32, Rect, Sense, Stroke, StrokeKind, pos2, vec2};
|
||||
use lightcraft_catalog::{Flag, PhotoId};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::LightcraftApp;
|
||||
use crate::theme::Tokens;
|
||||
use crate::widgets::register;
|
||||
|
||||
/// Thumbnail cells: side, gap, row inset.
|
||||
const CELL: f32 = 68.0;
|
||||
const GAP: f32 = 6.0;
|
||||
const INSET: f32 = 20.0;
|
||||
/// A burst's title row.
|
||||
const TITLE_H: f32 = 30.0;
|
||||
|
||||
/// The bursts shown, by the view's generation (which follows every catalog change).
|
||||
pub type Shown = Arc<Vec<(u32, Vec<PhotoId>)>>;
|
||||
|
||||
/// The bursts among the photos in view and the hidden members of their stacks, in view order.
|
||||
fn bursts(app: &mut LightcraftApp) -> Shown {
|
||||
let (generation, ids) = app.session.visible_shared();
|
||||
if let Some((g, b)) = &app.caches.bursts
|
||||
&& *g == generation
|
||||
{
|
||||
return b.clone();
|
||||
}
|
||||
let cat = &app.session.catalog;
|
||||
// each photo in view, then the hidden members of its stack: a burst whose photos are all
|
||||
// hidden in another burst's collapsed stack is listed too, after that stack's top
|
||||
let mut anchors: Vec<PhotoId> = Vec::with_capacity(ids.len());
|
||||
for id in ids.iter() {
|
||||
anchors.push(*id);
|
||||
if let Some(st) = cat.stack_of(*id) {
|
||||
anchors.extend(st.photos.iter().copied().filter(|p| p != id));
|
||||
}
|
||||
}
|
||||
let scope: HashSet<PhotoId> = anchors.iter().copied().collect();
|
||||
let b: Shown = Arc::new(cat.bursts_among(&anchors, Some(&scope)));
|
||||
app.caches.bursts = Some((generation, b.clone()));
|
||||
b
|
||||
}
|
||||
|
||||
/// Every burst of the library: its number → its photos, pick first.
|
||||
pub type All = Arc<HashMap<u32, Vec<PhotoId>>>;
|
||||
|
||||
/// Every burst of the library, built once per view generation (it follows every catalog change).
|
||||
fn all_bursts(app: &mut LightcraftApp) -> All {
|
||||
let (generation, _) = app.session.visible_shared();
|
||||
if let Some((g, b)) = &app.caches.burst_index
|
||||
&& *g == generation
|
||||
{
|
||||
return b.clone();
|
||||
}
|
||||
let b: All = Arc::new(app.session.catalog.burst_index());
|
||||
app.caches.burst_index = Some((generation, b.clone()));
|
||||
b
|
||||
}
|
||||
|
||||
/// A [`Target::Burst`] slot after every photo of the burst: a drop on its title or after its
|
||||
/// last photo.
|
||||
const LAST: usize = usize::MAX;
|
||||
|
||||
/// Where a drop under the pointer would put the dragged photos.
|
||||
#[derive(Clone, Copy, PartialEq, Debug)]
|
||||
enum Target {
|
||||
/// Burst `n` at `slot` (a place among its photos as shown, the dragged ones included;
|
||||
/// [`LAST`]: after every photo of the burst, those out of view too), dropped on the left half
|
||||
/// of the photo at `slot` (`true`: right before it) or the right half of the one before.
|
||||
Burst(u32, usize, bool),
|
||||
New,
|
||||
Nowhere,
|
||||
}
|
||||
|
||||
/// Where the pointer is over the panel, and what a drop there would do (with the line marking it).
|
||||
type Drop = Option<(Target, Option<Rect>)>;
|
||||
|
||||
pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
egui::ScrollArea::vertical().id_salt("bursts-scroll").auto_shrink([false, false]).show(ui, |ui| {
|
||||
ui.spacing_mut().item_spacing.y = 0.0;
|
||||
super::left::drag_auto_scroll(app, ui);
|
||||
super::right::header(ui, "Bursts");
|
||||
let shown = bursts(app);
|
||||
let dragged: Option<Vec<PhotoId>> = app.ui.dragging_photos.as_ref().map(|v| v.iter().copied().map(PhotoId).collect());
|
||||
let pointer = ui.input(|i| i.pointer.latest_pos()).filter(|p| ui.clip_rect().contains(*p));
|
||||
let mut target: Drop = None;
|
||||
let width = ui.available_width();
|
||||
let explain = if shown.is_empty() {
|
||||
"Photo → Assisted Culling… groups look-alike shots into bursts. They show here to put right by hand."
|
||||
} else {
|
||||
"Drag a photo to its place: the first of a burst is its pick. Drag one into another burst, or a burst by its title onto another to merge them."
|
||||
};
|
||||
egui::Frame::NONE.inner_margin(egui::Margin { left: INSET as i8, right: INSET as i8, top: 0, bottom: 10 }).show(ui, |ui| {
|
||||
ui.set_width(width - 2.0 * INSET);
|
||||
ui.label(egui::RichText::new(crate::i18n::tr(explain)).color(t.text_dim).size(12.0));
|
||||
});
|
||||
for (k, (g, photos)) in shown.iter().enumerate() {
|
||||
burst_rows(app, ui, &t, (k, *g, photos), pointer, dragged.is_some(), &mut target);
|
||||
}
|
||||
// drop places for a new burst and for none: there while there are bursts, or a drag
|
||||
if !shown.is_empty() || dragged.is_some() {
|
||||
drop_zones(ui, &t, pointer, dragged.is_some(), &mut target);
|
||||
}
|
||||
if let Some(ids) = dragged
|
||||
&& let Some((tgt, mark)) = target
|
||||
{
|
||||
drop_on(app, ui, &shown, &ids, tgt, mark);
|
||||
}
|
||||
ui.add_space(12.0);
|
||||
});
|
||||
}
|
||||
|
||||
/// Burst `g` (the `k`th shown): its title, then its photos in rows. Sets `target` when the pointer
|
||||
/// is over it.
|
||||
fn burst_rows(
|
||||
app: &mut LightcraftApp,
|
||||
ui: &mut egui::Ui,
|
||||
t: &Tokens,
|
||||
(k, g, photos): (usize, u32, &[PhotoId]),
|
||||
pointer: Option<egui::Pos2>,
|
||||
dragging: bool,
|
||||
target: &mut Drop,
|
||||
) {
|
||||
let width = ui.available_width();
|
||||
let cols = (((width - 2.0 * INSET + GAP) / (CELL + GAP)).floor() as usize).max(1);
|
||||
let title = burst_title(app, ui, t, (k, g, photos.len()), pointer, dragging, target);
|
||||
let n = photos.len();
|
||||
// the photos, in rows
|
||||
let rows = n.div_ceil(cols);
|
||||
let (area, _) = ui.allocate_exact_size(vec2(width, rows as f32 * (CELL + GAP) + GAP), Sense::hover());
|
||||
let cell_at = |i: usize| {
|
||||
let (r, c) = (i / cols, i % cols);
|
||||
Rect::from_min_size(pos2(area.left() + INSET + c as f32 * (CELL + GAP), area.top() + r as f32 * (CELL + GAP)), vec2(CELL, CELL))
|
||||
};
|
||||
for (i, id) in photos.iter().enumerate() {
|
||||
let r = cell_at(i);
|
||||
if let Some(badge) = photo_cell(app, ui, *id, r) {
|
||||
register(ui, format!("burstPick:{g}"), badge);
|
||||
}
|
||||
// a drop on a photo's left half goes before it, on its right half after it
|
||||
if let Some(p) = pointer
|
||||
&& r.expand(GAP / 2.0).contains(p)
|
||||
{
|
||||
let slot = if p.x < r.center().x { i } else { i + 1 };
|
||||
let edge = if slot == i { r.left() - GAP / 2.0 } else { r.right() + GAP / 2.0 };
|
||||
*target = Some((Target::Burst(g, slot, slot == i), Some(Rect::from_min_max(pos2(edge - 1.5, r.top()), pos2(edge + 1.5, r.bottom())))));
|
||||
}
|
||||
}
|
||||
if target.is_none()
|
||||
&& let Some(p) = pointer
|
||||
&& area.contains(p)
|
||||
{
|
||||
// the room after the last photo: last
|
||||
let last = cell_at(n.saturating_sub(1));
|
||||
*target = Some((
|
||||
Target::Burst(g, LAST, false),
|
||||
Some(Rect::from_min_max(pos2(last.right() + GAP / 2.0 - 1.5, last.top()), pos2(last.right() + GAP / 2.0 + 1.5, last.bottom()))),
|
||||
));
|
||||
}
|
||||
if dragging && matches!(target, Some((Target::Burst(tg, ..), _)) if *tg == g) {
|
||||
ui.painter().rect_stroke(title.union(area).shrink2(vec2(8.0, 1.0)), 4.0, Stroke::new(1.0, t.accent.gamma_multiply(0.6)), StrokeKind::Inside);
|
||||
}
|
||||
}
|
||||
|
||||
/// Burst `g`'s title (the `k`th shown, of `n` photos): a drop there puts the photos last;
|
||||
/// dragged, it takes the burst along.
|
||||
fn burst_title(
|
||||
app: &mut LightcraftApp,
|
||||
ui: &mut egui::Ui,
|
||||
t: &Tokens,
|
||||
(k, g, n): (usize, u32, usize),
|
||||
pointer: Option<egui::Pos2>,
|
||||
dragging: bool,
|
||||
target: &mut Drop,
|
||||
) -> Rect {
|
||||
let width = ui.available_width();
|
||||
let (title, resp) = ui.allocate_exact_size(vec2(width, TITLE_H), Sense::click_and_drag());
|
||||
register(ui, format!("burst:{g}"), title);
|
||||
let p = ui.painter();
|
||||
let name = format!("{} {}", crate::i18n::tr("Burst"), k + 1);
|
||||
p.text(pos2(title.left() + INSET, title.center().y), Align2::LEFT_CENTER, name, t.semibold(12.5), t.text);
|
||||
let count = crate::i18n::tr_format!("{n} photo{}", if n == 1 { "" } else { "s" }, n = n);
|
||||
p.text(pos2(title.right() - INSET, title.center().y), Align2::RIGHT_CENTER, count, t.font(11.5), t.text_dim);
|
||||
if resp.hovered() && !dragging {
|
||||
ui.ctx().set_cursor_icon(egui::CursorIcon::Grab);
|
||||
}
|
||||
// the whole burst, also its photos out of view
|
||||
if resp.drag_started() {
|
||||
app.ui.dragging_photos = Some(all_bursts(app).get(&g).map(|m| m.iter().map(|p| p.0).collect()).unwrap_or_default());
|
||||
}
|
||||
if pointer.is_some_and(|p| title.contains(p)) {
|
||||
*target = Some((Target::Burst(g, LAST, false), None));
|
||||
}
|
||||
title
|
||||
}
|
||||
|
||||
/// The drop places for a new burst and for none. Sets `target` when a drag is over one.
|
||||
fn drop_zones(ui: &mut egui::Ui, t: &Tokens, pointer: Option<egui::Pos2>, dragging: bool, target: &mut Drop) {
|
||||
let width = ui.available_width();
|
||||
ui.add_space(8.0);
|
||||
for (key, label, tgt) in [("burst:new", "New burst", Target::New), ("burst:none", "Not in a burst", Target::Nowhere)] {
|
||||
let (row, _) = ui.allocate_exact_size(vec2(width, 40.0), Sense::hover());
|
||||
let zone = row.shrink2(vec2(INSET, 4.0));
|
||||
register(ui, key, zone);
|
||||
let over = dragging && pointer.is_some_and(|p| zone.contains(p));
|
||||
let stroke = if over { Stroke::new(1.5, t.accent) } else { Stroke::new(1.0, t.divider) };
|
||||
ui.painter().rect_stroke(zone, 6.0, stroke, StrokeKind::Inside);
|
||||
ui.painter().text(zone.center(), Align2::CENTER_CENTER, crate::i18n::tr(label), t.font(12.0), if over { t.text } else { t.text_dim });
|
||||
if over {
|
||||
*target = Some((tgt, None));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// One photo of a burst: its thumbnail, the pick's badge (returned), the active photo's outline;
|
||||
/// a click selects it, a drag takes it along.
|
||||
fn photo_cell(app: &mut LightcraftApp, ui: &mut egui::Ui, id: PhotoId, r: Rect) -> Option<Rect> {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let photo = app.session.catalog.photo(id).cloned()?;
|
||||
let pick = photo.analysis.is_some_and(|a| a.best);
|
||||
let resp = ui.interact(r, egui::Id::unique(("burst-photo", id.0)), Sense::click_and_drag());
|
||||
register(ui, format!("burstPhoto:{}", id.0), r);
|
||||
// Any thumbnail will do at this size: one is asked for only when there is none, so the grid's
|
||||
// larger ones are never asked again at this size (and back) every frame. Above the grid's own
|
||||
// priorities: a member hidden in a collapsed stack isn't in the grid, which evicts the rest.
|
||||
if app.renderer.thumb(id).is_none() && !app.renderer.is_pending(crate::render::Slot::Thumb(id)) {
|
||||
let px = (CELL * ui.ctx().pixels_per_point()).ceil() as usize;
|
||||
super::grid::request_thumb(app, id, px, 12);
|
||||
}
|
||||
let p = ui.painter();
|
||||
p.rect_filled(r, 3.0, Color32::from_gray(30));
|
||||
let shown = match app.renderer.thumb(id) {
|
||||
Some(tex) => {
|
||||
let fit = super::detail::fit_texture_rect(r, tex.size);
|
||||
p.image(tex.tex.id(), fit, Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0)), Color32::WHITE);
|
||||
fit
|
||||
}
|
||||
None => r,
|
||||
};
|
||||
if photo.flag == Flag::Reject {
|
||||
p.rect_filled(shown, 0.0, Color32::from_black_alpha(110));
|
||||
}
|
||||
let state = app.session.selection.state_of(id);
|
||||
if state == lightcraft_engine::SelectionState::Active {
|
||||
p.rect_stroke(shown, 0.0, Stroke::new(2.0, Color32::WHITE), StrokeKind::Outside);
|
||||
} else if state != lightcraft_engine::SelectionState::NotSelected {
|
||||
p.rect_stroke(shown, 0.0, Stroke::new(2.0, Color32::from_gray(170)), StrokeKind::Outside);
|
||||
}
|
||||
let badge = pick.then(|| {
|
||||
let g = p.layout_no_wrap(crate::i18n::tr("Pick").into(), t.semibold(9.5), Color32::WHITE);
|
||||
let badge = Rect::from_min_size(r.min + vec2(3.0, 3.0), vec2(g.size().x + 10.0, 14.0));
|
||||
p.rect_filled(badge, 7.0, t.accent);
|
||||
p.galley(pos2(badge.left() + 5.0, badge.center().y - g.size().y / 2.0), g, Color32::WHITE);
|
||||
badge
|
||||
});
|
||||
if photo.flag == Flag::Pick {
|
||||
crate::icons::paint(
|
||||
p,
|
||||
Rect::from_min_size(pos2(r.right() - 16.0, r.bottom() - 16.0), vec2(13.0, 13.0)),
|
||||
crate::icons::Icon::FlagPick,
|
||||
t.pick,
|
||||
);
|
||||
}
|
||||
let focus = photo.analysis.map(|a| a.sharpness.round() as i32).unwrap_or_default();
|
||||
let resp = resp.on_hover_text(format!("{} · {} {focus}", photo.file_name, crate::i18n::tr("Focus")));
|
||||
if resp.clicked() {
|
||||
let _ = app.run("library.select", json!({"ids": [id.0]}));
|
||||
}
|
||||
if resp.drag_started() {
|
||||
app.ui.dragging_photos = Some(vec![id.0]);
|
||||
}
|
||||
badge
|
||||
}
|
||||
|
||||
/// Photos dragged over `tgt`: the mark where they would go, the label saying what a drop does,
|
||||
/// and on release the move.
|
||||
fn drop_on(app: &mut LightcraftApp, ui: &mut egui::Ui, shown: &Shown, ids: &[PhotoId], tgt: Target, mark: Option<Rect>) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let released = ui.input(|i| i.pointer.any_released());
|
||||
// only photos culling scored can be in a burst
|
||||
if ids.iter().any(|id| app.session.catalog.photo(*id).is_none_or(|p| p.analysis.is_none())) {
|
||||
ui.ctx().set_cursor_icon(egui::CursorIcon::NotAllowed);
|
||||
let why = if ids.len() == 1 { "Run Assisted Culling on it first" } else { "Run Assisted Culling on these photos first" };
|
||||
super::grid::drag_hint(ui.ctx(), crate::i18n::tr(why).into());
|
||||
if released {
|
||||
app.toast(
|
||||
ui.ctx(),
|
||||
crate::i18n::tr("Only photos Assisted Culling scored can be in a burst: run Photo → Assisted Culling… on them first"),
|
||||
);
|
||||
app.ui.dragging_photos = None;
|
||||
}
|
||||
return;
|
||||
}
|
||||
let (params, hint) = match tgt {
|
||||
Target::Burst(g, slot, before) => {
|
||||
let all = all_bursts(app);
|
||||
let members = shown.iter().find(|(n, _)| *n == g).map(|(_, m)| m.as_slice()).unwrap_or(&[]);
|
||||
// the place in the whole burst (members the view leaves out included) once the dragged
|
||||
// photos have left theirs: right before the photo dropped on, or right after the one
|
||||
// whose right half it was (members out of view between them stay on their side)
|
||||
let rest: Vec<PhotoId> = all.get(&g).map(|m| m.iter().copied().filter(|p| !ids.contains(p)).collect()).unwrap_or_default();
|
||||
let at = |m: &PhotoId| rest.iter().position(|p| p == m);
|
||||
let next = members.get(slot..).and_then(|after| after.iter().find(|m| !ids.contains(m)));
|
||||
let index = if slot == LAST {
|
||||
rest.len()
|
||||
} else if let Some(i) = next.filter(|_| before).and_then(at) {
|
||||
i
|
||||
} else {
|
||||
members[..slot.min(members.len())]
|
||||
.iter()
|
||||
.rev()
|
||||
.find(|m| !ids.contains(m))
|
||||
.and_then(|m| rest.iter().position(|p| p == m))
|
||||
.map_or(0, |i| i + 1)
|
||||
};
|
||||
// the dragged photos are a whole other burst (one lookup: the first one's burst)
|
||||
let from = ids.first().and_then(|id| app.session.catalog.photo(*id)).and_then(|p| p.analysis).and_then(|a| a.group);
|
||||
let whole = from
|
||||
.filter(|n| *n != g)
|
||||
.and_then(|n| all.get(&n))
|
||||
.is_some_and(|m| m.len() > 1 && m.len() == ids.len() && m.iter().all(|p| ids.contains(p)));
|
||||
let hint = if whole {
|
||||
"Merge into this burst"
|
||||
} else if index == 0 && slot < members.len() {
|
||||
if ids.len() == 1 { "Make it the pick" } else { "Put first: the first is the pick" }
|
||||
} else if ids.iter().all(|id| members.contains(id)) {
|
||||
"Move here"
|
||||
} else {
|
||||
"Move to this burst"
|
||||
};
|
||||
let index = if index >= rest.len() { Value::Null } else { json!(index) };
|
||||
(json!({"ids": ids.iter().map(|p| p.0).collect::<Vec<_>>(), "burst": g, "index": index}), hint)
|
||||
}
|
||||
Target::New => (json!({"ids": ids.iter().map(|p| p.0).collect::<Vec<_>>(), "burst": "new"}), "New burst"),
|
||||
Target::Nowhere => (json!({"ids": ids.iter().map(|p| p.0).collect::<Vec<_>>(), "burst": null}), "Take out of its burst"),
|
||||
};
|
||||
if let Some(mark) = mark {
|
||||
ui.painter().rect_filled(mark, 1.5, t.accent);
|
||||
}
|
||||
super::grid::drag_hint(ui.ctx(), crate::i18n::tr(hint).into());
|
||||
if released {
|
||||
if let Err(e) = app.run("photo.moveToBurst", params) {
|
||||
app.toast(ui.ctx(), e);
|
||||
}
|
||||
app.ui.dragging_photos = None;
|
||||
}
|
||||
}
|
||||
@@ -19,8 +19,9 @@ mod local;
|
||||
mod rows;
|
||||
mod sections;
|
||||
|
||||
use albums::albums_rows;
|
||||
pub(crate) use albums::drag_auto_scroll;
|
||||
pub use albums::{album_drag_feedback, auto_scroll_speed};
|
||||
use albums::{albums_rows, drag_auto_scroll};
|
||||
pub(crate) use dates::browse_all_photos;
|
||||
use dates::date_rows;
|
||||
pub(crate) use folders::{created_text, folder_row_of, move_photos, moved_text};
|
||||
|
||||
@@ -158,7 +158,7 @@ pub fn auto_scroll_speed(y: f32, top: f32, bottom: f32) -> f32 {
|
||||
/// While an album, or photos from the grid, are dragged over the sidebar: scrolls it when the
|
||||
/// pointer is near its top or bottom edge, so rows beyond the visible part can be reached. Call
|
||||
/// inside the scroll area.
|
||||
pub(super) fn drag_auto_scroll(app: &LightcraftApp, ui: &egui::Ui) {
|
||||
pub(crate) fn drag_auto_scroll(app: &LightcraftApp, ui: &egui::Ui) {
|
||||
if app.ui.dragging_album.is_none() && app.ui.dragging_photos.is_none() && app.ui.dragging_section.is_none() {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! The right-hand panel next to the tool strip: Edit, Crop, Remove, Masking, Red Eye, Info,
|
||||
//! Keywords, Versions, Activity.
|
||||
//! Keywords, Versions, Activity, Bursts.
|
||||
|
||||
use egui::{Align2, Rect, Sense, pos2, vec2};
|
||||
use lightcraft_catalog::PhotoId;
|
||||
@@ -33,6 +33,11 @@ pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let frame = egui::Frame::NONE.fill(t.chrome).stroke(egui::Stroke::new(1.0, t.divider));
|
||||
frame.show(ui, |ui| {
|
||||
// the bursts are the view's, not a photo's: they are there without a selection
|
||||
if app.ui.right == RightPanel::Bursts {
|
||||
super::bursts::show(app, ui);
|
||||
return;
|
||||
}
|
||||
// (taken on every pass the panel is drawn; one from earlier than the pass before is forgotten)
|
||||
let held = held_offset(ui.ctx());
|
||||
let Some(id) = app.session.active() else {
|
||||
@@ -91,7 +96,7 @@ pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui) {
|
||||
RightPanel::Keywords => keywords(app, ui, id),
|
||||
RightPanel::Versions => versions(app, ui, id),
|
||||
RightPanel::Activity => activity(app, ui, id),
|
||||
RightPanel::None => {}
|
||||
RightPanel::Bursts | RightPanel::None => {}
|
||||
}
|
||||
});
|
||||
ui.data_mut(|d| d.insert_temp(egui::Id::unique(AREA), scrolled.id));
|
||||
|
||||
@@ -184,7 +184,8 @@ pub enum Dialog {
|
||||
},
|
||||
/// Photo ▸ Assisted Culling: reject photos below this focus score (0 = none), pick the best
|
||||
/// 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.
|
||||
/// `burst_gap` seconds apart and at least `similarity` alike are a burst. Bursts arranged by
|
||||
/// hand (Window ▸ Bursts) are kept unless `reset_bursts`.
|
||||
Cull {
|
||||
reject_below: f32,
|
||||
pick_best: bool,
|
||||
@@ -192,6 +193,8 @@ pub enum Dialog {
|
||||
stack_groups: bool,
|
||||
burst_gap: f32,
|
||||
similarity: f32,
|
||||
#[serde(default)]
|
||||
reset_bursts: bool,
|
||||
},
|
||||
/// Help ▸ System Info: (label, value) rows.
|
||||
DenoiseModel {
|
||||
|
||||
@@ -35,6 +35,8 @@ pub enum RightPanel {
|
||||
Info,
|
||||
/// The profile browser (part of Edit).
|
||||
Profiles,
|
||||
/// Assisted Culling's bursts, to arrange by hand (Window ▸ Bursts).
|
||||
Bursts,
|
||||
}
|
||||
|
||||
impl RightPanel {
|
||||
|
||||
@@ -19,6 +19,7 @@ mod alt_preview;
|
||||
mod appearance;
|
||||
mod before_after;
|
||||
mod browse_active;
|
||||
mod bursts;
|
||||
mod button;
|
||||
mod canvas_keys;
|
||||
mod canvas_pan;
|
||||
|
||||
@@ -0,0 +1,290 @@
|
||||
//! Window ▸ Bursts: Assisted Culling's bursts as rows of thumbnails, pick first. A photo dragged
|
||||
//! to the front of its burst becomes the pick; dragged into another burst, onto New Burst or Not
|
||||
//! in a Burst it moves there; a burst dragged by its title merges into another; photos dragged
|
||||
//! from the grid drop here too. Each drop is one undo step.
|
||||
|
||||
use egui::{Pos2, Rect, pos2};
|
||||
use lightcraft_catalog::{Analysis, Flag, Op, Photo, PhotoId, Source};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::headless::Headless;
|
||||
use crate::state::RightPanel;
|
||||
use crate::{LightcraftApp, Services};
|
||||
|
||||
/// Burst 1: a (picked by culling), b, c; burst 2: d, e; f never culled. The grid, with the
|
||||
/// Bursts panel open.
|
||||
fn app() -> (Headless, [PhotoId; 6]) {
|
||||
let mut session = lightcraft_engine::Session::new();
|
||||
let mut add = |name: &str, when: &str, culled: Option<(u32, f32, bool)>| {
|
||||
let id = session.catalog.alloc_photo_id();
|
||||
let mut p = Photo::new(id, Source::File { path: format!("/nowhere/{name}") }, name, "JPEG", 300, 200, "2026-05-01T12:00:00");
|
||||
p.captured = Some(when.into());
|
||||
p.analysis = culled.map(|(g, sharpness, best)| Analysis { sharpness, group: Some(g), best, ..Default::default() });
|
||||
session.catalog.apply(Op::AddPhoto { photo: Box::new(p) }).unwrap();
|
||||
id
|
||||
};
|
||||
let ids = [
|
||||
add("a.jpg", "2026-05-01T10:00:00", Some((1, 80.0, true))),
|
||||
add("b.jpg", "2026-05-01T10:00:01", Some((1, 60.0, false))),
|
||||
add("c.jpg", "2026-05-01T10:00:02", Some((1, 40.0, false))),
|
||||
add("d.jpg", "2026-05-01T11:00:00", Some((2, 70.0, true))),
|
||||
add("e.jpg", "2026-05-01T11:00:01", Some((2, 30.0, false))),
|
||||
add("f.jpg", "2026-05-01T12:00:00", None),
|
||||
];
|
||||
session.catalog.apply(Op::SetFlag { id: ids[0], flag: Flag::Pick }).unwrap();
|
||||
let mut h = Headless::new(LightcraftApp::new(session, Services { png: None, ..Default::default() }), [1400.0, 900.0], 1.0);
|
||||
let r = h.request("ui.set", json!({"view": "photoGrid"}), std::time::Duration::from_secs(10));
|
||||
assert_eq!(r["ok"], true, "{r}");
|
||||
h.app.run("panel.bursts", json!({})).unwrap();
|
||||
for _ in 0..4 {
|
||||
h.step();
|
||||
}
|
||||
assert_eq!(h.app.ui.right, RightPanel::Bursts);
|
||||
(h, ids)
|
||||
}
|
||||
|
||||
fn widget(h: &Headless, id: &str) -> Rect {
|
||||
h.app.widgets.iter().find(|(w, _)| w == id).map(|(_, r)| *r).unwrap_or_else(|| {
|
||||
panic!("no {id} in {:?}", h.app.widgets.iter().filter(|(w, _)| w.starts_with("burst")).map(|(w, _)| w).collect::<Vec<_>>())
|
||||
})
|
||||
}
|
||||
|
||||
fn cell(h: &Headless, id: PhotoId) -> Rect {
|
||||
widget(h, &format!("burstPhoto:{}", id.0))
|
||||
}
|
||||
|
||||
fn press(h: &mut Headless, at: Pos2) {
|
||||
h.app.synthetic.push(egui::Event::PointerMoved(at));
|
||||
h.app.synthetic.push(egui::Event::PointerButton {
|
||||
pos: at,
|
||||
button: egui::PointerButton::Primary,
|
||||
pressed: true,
|
||||
modifiers: egui::Modifiers::NONE,
|
||||
});
|
||||
h.step();
|
||||
}
|
||||
|
||||
fn glide(h: &mut Headless, from: Pos2, to: Pos2) {
|
||||
for i in 1..=8 {
|
||||
h.app.synthetic.push(egui::Event::PointerMoved(from + (to - from) * (i as f32 / 8.0)));
|
||||
h.step();
|
||||
}
|
||||
// (synthetic input arrives a frame or two behind)
|
||||
for _ in 0..3 {
|
||||
h.step();
|
||||
}
|
||||
}
|
||||
|
||||
fn release(h: &mut Headless, at: Pos2) {
|
||||
h.app.synthetic.push(egui::Event::PointerButton {
|
||||
pos: at,
|
||||
button: egui::PointerButton::Primary,
|
||||
pressed: false,
|
||||
modifiers: egui::Modifiers::NONE,
|
||||
});
|
||||
h.step();
|
||||
h.step();
|
||||
}
|
||||
|
||||
fn drag(h: &mut Headless, from: Pos2, to: Pos2) {
|
||||
press(h, from);
|
||||
glide(h, from, to);
|
||||
}
|
||||
|
||||
fn hint(h: &Headless) -> Option<String> {
|
||||
h.view.ctx.data(|d| d.get_temp::<(u64, String)>(egui::Id::unique("drag-photos-hint"))).map(|(_, text)| text)
|
||||
}
|
||||
|
||||
fn best(h: &Headless, id: PhotoId) -> bool {
|
||||
h.app.session.catalog.photo(id).unwrap().analysis.unwrap().best
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bursts_show_their_pick_first() {
|
||||
let (h, [a, b, c, d, e, f]) = app();
|
||||
// a row per burst, its pick first
|
||||
let (one, two) = (widget(&h, "burst:1"), widget(&h, "burst:2"));
|
||||
assert!(one.bottom() <= cell(&h, a).top() && cell(&h, e).top() >= two.bottom(), "each title above its photos");
|
||||
assert!(cell(&h, a).left() < cell(&h, b).left() && cell(&h, b).left() < cell(&h, c).left());
|
||||
assert!(cell(&h, d).left() < cell(&h, e).left());
|
||||
widget(&h, "burstPick:1");
|
||||
assert!(widget(&h, "burstPick:1").intersects(cell(&h, a)), "the pick is marked");
|
||||
// a photo culling never saw has no row; the drop places for a new burst and for none are there
|
||||
assert!(!h.app.widgets.iter().any(|(w, _)| w == &format!("burstPhoto:{}", f.0)));
|
||||
widget(&h, "burst:new");
|
||||
widget(&h, "burst:none");
|
||||
}
|
||||
|
||||
/// A burst whose photos are all hidden in a collapsed stack of another burst's photo is still
|
||||
/// listed, so it can be arranged.
|
||||
#[test]
|
||||
fn a_burst_hidden_in_another_bursts_stack_is_listed() {
|
||||
let (mut h, [a, _, _, d, e, _]) = app();
|
||||
h.app.session.selection.ids = vec![a, d, e];
|
||||
h.app.session.selection.active = Some(a);
|
||||
h.app.session.execute("stack.group", &json!({"collapsed": true})).unwrap();
|
||||
for _ in 0..4 {
|
||||
h.step();
|
||||
}
|
||||
let visible = h.app.session.visible_cloned();
|
||||
assert!(visible.contains(&a) && !visible.contains(&d) && !visible.contains(&e), "d and e are hidden under a: {visible:?}");
|
||||
let (one, two) = (widget(&h, "burst:1"), widget(&h, "burst:2"));
|
||||
assert!(one.top() < two.top(), "listed after the burst of the stack's top");
|
||||
assert!(cell(&h, d).top() >= two.bottom() && cell(&h, e).top() >= two.bottom(), "with its photos");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_photo_dragged_to_the_front_becomes_the_pick() {
|
||||
let (mut h, [a, b, c, ..]) = app();
|
||||
let to = pos2(cell(&h, a).left() + 4.0, cell(&h, a).center().y);
|
||||
let from = cell(&h, c).center();
|
||||
drag(&mut h, from, to);
|
||||
assert_eq!(h.app.ui.dragging_photos, Some(vec![c.0]));
|
||||
assert_eq!(hint(&h).as_deref(), Some("Make it the pick"));
|
||||
release(&mut h, to);
|
||||
assert!(h.app.ui.dragging_photos.is_none());
|
||||
assert_eq!(h.app.session.catalog.burst(1), vec![c, a, b]);
|
||||
assert!(best(&h, c) && !best(&h, a));
|
||||
assert_eq!(h.app.session.catalog.photo(c).unwrap().flag, Flag::Pick, "culling's Pick follows the pick");
|
||||
// the panel shows the new order
|
||||
h.step();
|
||||
assert!(cell(&h, c).left() < cell(&h, a).left());
|
||||
// one undo step
|
||||
h.app.run("edit.undo", json!({})).unwrap();
|
||||
assert_eq!(h.app.session.catalog.burst(1), vec![a, b, c]);
|
||||
assert!(best(&h, a));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn photos_move_between_bursts_and_bursts_merge() {
|
||||
let (mut h, [a, b, c, d, e, _]) = app();
|
||||
let group = |h: &Headless, id: PhotoId| h.app.session.catalog.photo(id).unwrap().analysis.unwrap().group;
|
||||
// e onto burst 1 between a and b; burst 2 is left with d alone: no burst any more
|
||||
let to = pos2(cell(&h, b).left() + 4.0, cell(&h, b).center().y);
|
||||
let from = cell(&h, e).center();
|
||||
drag(&mut h, from, to);
|
||||
assert_eq!(hint(&h).as_deref(), Some("Move to this burst"));
|
||||
release(&mut h, to);
|
||||
assert_eq!(h.app.session.catalog.burst(1), vec![a, e, b, c]);
|
||||
assert!(h.app.session.catalog.burst(2).is_empty() && group(&h, d).is_none());
|
||||
h.step();
|
||||
// d dragged from the grid onto burst 1's title goes last
|
||||
let title = widget(&h, "burst:1").center();
|
||||
let from = widget(&h, &format!("thumb:{}", d.0)).center();
|
||||
drag(&mut h, from, title);
|
||||
assert_eq!(hint(&h).as_deref(), Some("Move to this burst"));
|
||||
release(&mut h, title);
|
||||
assert_eq!(h.app.session.catalog.burst(1), vec![a, e, b, c, d]);
|
||||
h.step();
|
||||
// b onto New Burst: a burst of its own, which c then joins by its title
|
||||
let new = widget(&h, "burst:new").center();
|
||||
let from = cell(&h, b).center();
|
||||
drag(&mut h, from, new);
|
||||
assert_eq!(hint(&h).as_deref(), Some("New burst"));
|
||||
release(&mut h, new);
|
||||
let g = group(&h, b).expect("a new burst");
|
||||
assert_eq!(h.app.session.catalog.burst(g), vec![b]);
|
||||
h.step();
|
||||
let to = widget(&h, &format!("burst:{g}")).center();
|
||||
let from = cell(&h, c).center();
|
||||
drag(&mut h, from, to);
|
||||
release(&mut h, to);
|
||||
assert_eq!(h.app.session.catalog.burst(g), vec![b, c]);
|
||||
h.step();
|
||||
// e onto Not in a Burst
|
||||
let out = widget(&h, "burst:none").center();
|
||||
let from = cell(&h, e).center();
|
||||
drag(&mut h, from, out);
|
||||
assert_eq!(hint(&h).as_deref(), Some("Take out of its burst"));
|
||||
release(&mut h, out);
|
||||
assert!(group(&h, e).is_none());
|
||||
assert_eq!(h.app.session.catalog.burst(1), vec![a, d]);
|
||||
h.step();
|
||||
// a burst dragged by its title onto another merges into it
|
||||
let to = widget(&h, "burst:1").center();
|
||||
let from = widget(&h, &format!("burst:{g}")).center();
|
||||
drag(&mut h, from, to);
|
||||
assert_eq!(hint(&h).as_deref(), Some("Merge into this burst"));
|
||||
release(&mut h, to);
|
||||
assert_eq!(h.app.session.catalog.burst(1), vec![a, d, b, c]);
|
||||
assert!(h.app.session.catalog.burst(g).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_photo_never_culled_is_refused() {
|
||||
let (mut h, [_, _, _, _, _, f]) = app();
|
||||
let to = widget(&h, "burst:1").center();
|
||||
let from = widget(&h, &format!("thumb:{}", f.0)).center();
|
||||
drag(&mut h, from, to);
|
||||
assert_eq!(hint(&h).as_deref(), Some("Run Assisted Culling on it first"));
|
||||
let commits = h.app.session.commits();
|
||||
release(&mut h, to);
|
||||
assert_eq!(h.app.session.commits(), commits);
|
||||
let toast = h.app.ui.toast.as_ref().map(|(t, _, _)| t.clone()).unwrap_or_default();
|
||||
assert!(toast.contains("Assisted Culling"), "{toast}");
|
||||
}
|
||||
|
||||
/// A burst dragged by its title takes all its photos along, also those the view leaves out.
|
||||
#[test]
|
||||
fn a_burst_dragged_by_its_title_takes_its_photos_out_of_view() {
|
||||
let (mut h, [a, b, c, d, e, _]) = app();
|
||||
// only the picks are in view: e (of burst 2) is left out
|
||||
let r = h.app.session.execute("library.filter", &json!({"ruleSet": {"rules": [{"field": "bestOfGroup", "op": "is", "value": true}]}})).unwrap();
|
||||
assert!(r.is_object(), "{r}");
|
||||
for _ in 0..4 {
|
||||
h.step();
|
||||
}
|
||||
assert!(!h.app.session.visible_cloned().contains(&e), "e is out of view");
|
||||
let to = widget(&h, "burst:1").center();
|
||||
let from = widget(&h, "burst:2").center();
|
||||
drag(&mut h, from, to);
|
||||
assert_eq!(hint(&h).as_deref(), Some("Merge into this burst"));
|
||||
release(&mut h, to);
|
||||
assert_eq!(h.app.session.catalog.burst(1), vec![a, b, c, d, e], "e came along");
|
||||
assert!(h.app.session.catalog.burst(2).is_empty());
|
||||
}
|
||||
|
||||
/// A photo dropped after a shown member lands right after it in the whole burst, before the
|
||||
/// members the view leaves out, not after them.
|
||||
#[test]
|
||||
fn a_drop_after_a_shown_photo_goes_before_the_photos_out_of_view() {
|
||||
let (mut h, [a, b, c, d, _, _]) = app();
|
||||
// only the picks are in view: burst 1 shows a, its b and c are left out
|
||||
h.app.session.execute("library.filter", &json!({"ruleSet": {"rules": [{"field": "bestOfGroup", "op": "is", "value": true}]}})).unwrap();
|
||||
for _ in 0..4 {
|
||||
h.step();
|
||||
}
|
||||
let to = pos2(cell(&h, a).right() - 4.0, cell(&h, a).center().y);
|
||||
let from = cell(&h, d).center();
|
||||
drag(&mut h, from, to);
|
||||
assert_eq!(hint(&h).as_deref(), Some("Move to this burst"));
|
||||
release(&mut h, to);
|
||||
assert_eq!(h.app.session.catalog.burst(1), vec![a, d, b, c], "right after a, before b and c");
|
||||
}
|
||||
|
||||
/// Between two shown photos with one out of view between them, a drop on the left half of the
|
||||
/// second goes right before it, a drop on the right half of the first right after that one.
|
||||
#[test]
|
||||
fn a_drop_keeps_its_side_of_a_photo_out_of_view() {
|
||||
let (mut h, [a, b, c, d, _, _]) = app();
|
||||
// b is left out: burst 1 shows a, c
|
||||
h.app.session.execute("library.filter", &json!({"ruleSet": {"rules": [{"field": "fileName", "op": "notContains", "value": "b.jpg"}]}})).unwrap();
|
||||
for _ in 0..4 {
|
||||
h.step();
|
||||
}
|
||||
assert!(!h.app.session.visible_cloned().contains(&b));
|
||||
let before_c = pos2(cell(&h, c).left() + 4.0, cell(&h, c).center().y);
|
||||
let from = cell(&h, d).center();
|
||||
drag(&mut h, from, before_c);
|
||||
release(&mut h, before_c);
|
||||
assert_eq!(h.app.session.catalog.burst(1), vec![a, b, d, c], "right before c");
|
||||
h.app.run("edit.undo", json!({})).unwrap();
|
||||
for _ in 0..4 {
|
||||
h.step();
|
||||
}
|
||||
let after_a = pos2(cell(&h, a).right() - 4.0, cell(&h, a).center().y);
|
||||
let from = cell(&h, d).center();
|
||||
drag(&mut h, from, after_a);
|
||||
release(&mut h, after_a);
|
||||
assert_eq!(h.app.session.catalog.burst(1), vec![a, d, b, c], "right after a");
|
||||
}
|
||||
@@ -120,7 +120,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. A capture time that doesn't fully read (cut short, or text after it) is left as it is and counted (`unreadable`); it can't anchor a set that moves other photos, and set alone repairs it. |
|
||||
| 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, 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-CULL | Assisted culling | P2 | 🟡 | `cmd:photo.analyze`, `cmd:dialog.cull`, `cmd:photo.moveToBurst`, `cmd:panel.bursts`, `crates/pipeline/src/cull.rs`, `crates/ui-egui/src/panels/bursts.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; bursts put right by hand in Window ▸ Bursts (drag a photo within its burst — first place is the pick, and the Pick flag culling set, Best of Similar Shots and a stacked burst's top follow — into another burst, a new one or none; drag a burst onto another to merge; kept when culling runs again unless *Regroup bursts I arranged by hand*); 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`, `crates/ui-egui/src/thumb.rs` | “Copy N” tag on the grid and on the filmstrip (widgets `copy:<id>`, `film:copy:<id>`; on a narrow thumbnail it drops its name and then hides rather than meet the stack badge), stacked with the original, same albums, no XMP writes; default numbers are checked across the batch before copies are created, while explicit names bypass the counter; deleting a copy dissolves or renumbers the stack (#1493); no “Set Copy as Master” |
|
||||
@@ -884,6 +884,8 @@ Latin stays upright. Advanced Japanese composition remains open. Regression cove
|
||||
| 2026-10-19 | patch | LR-CROP-RECT: on a straightened photo a free crop corner dragged out grows both sides to the place nearest the pointer that fits (#2308); status unchanged |
|
||||
| 2026-10-19 | patch | LR-CROP-RECT: on a straightened photo a moved crop slides along the tilted edges, so a box that fills the photo's height reaches its sides (#2299); status unchanged |
|
||||
| 2026-10-19 | patch | LR-VIEW-ZOOM: the slow slider-drag verdict is described as per photo and control, as the code keys it; status unchanged |
|
||||
| 2026-10-19 | patch | LR-LIB-CULL: bursts can be arranged by hand by drag and drop in Window ▸ Bursts; the first photo of a burst is its pick, and culling again keeps the arrangement (`photo.moveToBurst`, `panel.bursts`, `photo.analyze` `resetBursts`). Statuses and feature counts unchanged. |
|
||||
| 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-18 | patch | Export regression integration (maintenance): Graphic watermarks honour EXIF rotation/mirroring through the shared `read_graphic` path and keep their aspect ratio when fitted to the output. HDR JPEG `limitKb` includes the gain map and metadata. Refreshed onto main fb7ac08b, retaining upstream export bounds, colour metadata, JPEG encoding and opaque RGB/real-alpha handling (#1691); no feature-count or readiness estimate changes. |
|
||||
| 2026-10-18 | patch | LR-META-XMP: Lightroom's profile and version bookkeeping (`CompatibleVersion`, profile digests, lens profile identity, `CropConstrainToUnitSquare`, default-strength lens profile scales) is no longer reported as unimported XMP; status unchanged (✅) |
|
||||
| 2026-10-17 | minor | MENU-VIEW-DETAIL, MENU-VIEW-EDIT, MENU-VIEW-CLIPPING, MENU-VIEW-MASKOVERLAY, MENU-VIEW-PHOTOCOUNT, MENU-VIEW-BEFOREAFTER, LR-VIEW-FOCUSPOINT: menu labels renamed: switches are named for what they show (Photo Counts, Focus Point, Clipping, Mask Overlay, All Mask Overlays, Mask Pins, Layout Image), View ▸ Detail is Detail View, Window ▸ Edit is Edit Panel, Compare Before and After is Before/After Side by Side, Clear Preview Cache is Discard Preview Cache; shortcuts and commands unchanged; statuses unchanged |
|
||||
@@ -894,7 +896,6 @@ Latin stays upright. Advanced Japanese composition remains open. Regression cove
|
||||
| 2026-10-15 | minor | LR-BEHAV-BG-TASKS: Reload from Disk reads its files on a worker thread with a cancellable activity row instead of freezing the window on a selection of raws; its result is committed through the command wrapper (XMP sidecars auto-written as before) and an older reload finishing late no longer overwrites a newer one; status unchanged (✅) |
|
||||
| 2026-10-19 | patch | LR-LIB-STACK: the filmstrip's stack badge expands / collapses the stack like the grid's, and a badge click works on a stack that isn't selected (it is selected first). Statuses and feature counts unchanged. |
|
||||
| 2026-10-14 | minor | LR-VIEW-ZOOM: Visualize Spots, Point Color range and Visualize HDR render zoom windows; LRC-DEV-SOFTPROOF: output-space proofs on the GPU |
|
||||
| 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-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) |
|
||||
| 2026-10-15 | minor | LR-IMP-FORMATS: Hasselblad 3FR and FFF show their uncompressed RGB preview (no JPEG in these files) in the grid and loupe until developed, and as the stand-in when a file fails to decode; status unchanged (🟡) |
|
||||
|
||||
Reference in new issue
Block a user