From fa93d6f836c34cff721842d53ddd3c03cce38109 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 31 Oct 2026 04:39:00 -0700 Subject: [PATCH 01/11] LRC-SS-PLAYBACK: pan and zoom moves and zooms each photo during playback The new Pan and zoom setting (Settings > Slideshow > Playback, or panAndZoom in slideshow.playback and view.slideshow) moves each photo slowly from one window of itself to another over its slide's time, its fade in included. Its Low to High amount (panAndZoomAmount, 0 to 1, default 0.5) sets how far it zooms: about 1.01x at Low and 1.12x at High for the closer view. Every photo gets its own path from the playback seed, the pass and the photo, so each pass moves differently and a seed replays the same paths. The window never leaves the photo. In a composed slide the photo moves inside its image cell while the backdrop, margins, stroke and shadow stay still; with overlays on, the whole slide moves so an overlay is never split. Title screens do not move. Pause freezes the motion, a photo fading out stays at its end view, and a manual slideshow holds each photo at its start view. The setting is off by default, saved with the library and in slideshow templates. Exports show the photos still. --- crates/engine/src/cmd/slideshow.rs | 2 +- crates/engine/src/slide_template/tests.rs | 6 +- crates/engine/src/slideshow.rs | 81 +++++++++- crates/engine/src/slideshow/tests.rs | 84 +++++++++++ crates/engine/src/tests/prefs.rs | 4 +- crates/slideshow/src/lib.rs | 5 +- crates/slideshow/src/motion.rs | 140 ++++++++++++++++++ .../ui-egui/src/dialogs/settings/slideshow.rs | 22 +++ crates/ui-egui/src/panels/slideshow.rs | 94 +++++++++--- crates/ui-egui/src/tests/slideshow.rs | 74 +++++++++ docs/parity-checklist.md | 2 +- docs/slideshow.md | 6 +- 12 files changed, 486 insertions(+), 34 deletions(-) create mode 100644 crates/slideshow/src/motion.rs diff --git a/crates/engine/src/cmd/slideshow.rs b/crates/engine/src/cmd/slideshow.rs index 191cee953f..78fe2f65a2 100644 --- a/crates/engine/src/cmd/slideshow.rs +++ b/crates/engine/src/cmd/slideshow.rs @@ -379,7 +379,7 @@ pub fn specs() -> Vec { "Slideshow Playback Settings", [], None, - "{slideDuration?: seconds (0.5–120), fadeDuration?: seconds (0 = cut; at most 10 and the slide duration), fadeColor?: \"#rrggbb\"|[r,g,b]|null (fade through a colour instead of crossfading), randomOrder?: bool, repeat?: bool, preparePreviews?: bool (render the next slides before they are due), manual?: bool (manual slideshow: a slide stays up until ← or → changes it)} — omitted keys keep their value, {} reads them; saved with the library → {slideDuration, fadeDuration, fadeColor, randomOrder, repeat, preparePreviews, manual}", + "{slideDuration?: seconds (0.5–120), fadeDuration?: seconds (0 = cut; at most 10 and the slide duration), fadeColor?: \"#rrggbb\"|[r,g,b]|null (fade through a colour instead of crossfading), randomOrder?: bool, repeat?: bool, preparePreviews?: bool (render the next slides before they are due), manual?: bool (manual slideshow: a slide stays up until ← or → changes it), panAndZoom?: bool (each photo moves and zooms slowly over its slide, on its own path), panAndZoomAmount?: 0 (low) to 1 (high)} — omitted keys keep their value, {} reads them; saved with the library → {slideDuration, fadeDuration, fadeColor, randomOrder, repeat, preparePreviews, manual, panAndZoom, panAndZoomAmount}", always, playback ), diff --git a/crates/engine/src/slide_template/tests.rs b/crates/engine/src/slide_template/tests.rs index 9d3e9c807b..241e069929 100644 --- a/crates/engine/src/slide_template/tests.rs +++ b/crates/engine/src/slide_template/tests.rs @@ -39,7 +39,11 @@ fn ids(s: &mut Session) -> Vec { /// A look different from the defaults in every section. fn custom(s: &mut Session) { - run(s, "slideshow.playback", json!({"slideDuration": 7.5, "fadeDuration": 0.5, "fadeColor": "#102030", "randomOrder": true, "repeat": false})); + run( + s, + "slideshow.playback", + json!({"slideDuration": 7.5, "fadeDuration": 0.5, "fadeColor": "#102030", "randomOrder": true, "repeat": false, "panAndZoom": true, "panAndZoomAmount": 0.8}), + ); run( s, "slideshow.layout", diff --git a/crates/engine/src/slideshow.rs b/crates/engine/src/slideshow.rs index 0e1c1294de..3eb538627a 100644 --- a/crates/engine/src/slideshow.rs +++ b/crates/engine/src/slideshow.rs @@ -1,6 +1,6 @@ //! Slideshow playback: the settings of Lightroom Classic's Playback panel and the timeline that //! plays the photos in view (durations, fades, random order, repeat, pause, stepping, manual -//! advance), between an optional intro and ending screen (the Titles panel, +//! advance, pan and zoom), between an optional intro and ending screen (the Titles panel, //! [`crate::slide_title`]). //! //! No UI here: [`Playback`] is a pure state machine driven with injected times (seconds on any @@ -14,6 +14,7 @@ //! with the `slideshow.playback` command. use lightcraft_catalog::PhotoId; +use lightcraft_slideshow::{Motion, View}; use serde::{Deserialize, Serialize}; use serde_json::{Value, json}; @@ -23,7 +24,7 @@ pub const SLIDE_MAX: f64 = 120.0; /// Longest fade (seconds); a fade is never longer than the slide duration. pub const FADE_MAX: f64 = 10.0; -/// How playback runs (Lightroom Classic's Playback panel, without music and pan & zoom). +/// How playback runs (Lightroom Classic's Playback panel, without music). #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(default, rename_all = "camelCase")] pub struct PlaybackSettings { @@ -43,6 +44,10 @@ pub struct PlaybackSettings { /// Manual slideshow: a slide stays up until ← / → (or the controls) change it; the slide /// duration is not used for playback then. pub manual: bool, + /// Pan and zoom: each photo moves and zooms slowly over its slide's time, on its own path. + pub pan_and_zoom: bool, + /// How much it moves: 0 (Low) to 1 (High). + pub pan_and_zoom_amount: f64, } impl Default for PlaybackSettings { @@ -55,18 +60,22 @@ impl Default for PlaybackSettings { repeat: true, prepare_previews: true, manual: false, + pan_and_zoom: false, + pan_and_zoom_amount: 0.5, } } } impl PlaybackSettings { - /// The settings with every value in range (a non-finite duration takes the default; the fade - /// is never longer than the slide). + /// The settings with every value in range (a non-finite duration or amount takes the default; + /// the fade is never longer than the slide). pub fn sanitized(mut self) -> Self { let d = PlaybackSettings::default(); self.slide_duration = if self.slide_duration.is_finite() { self.slide_duration.clamp(SLIDE_MIN, SLIDE_MAX) } else { d.slide_duration }; let fade = if self.fade_duration.is_finite() { self.fade_duration } else { d.fade_duration }; self.fade_duration = fade.clamp(0.0, FADE_MAX).min(self.slide_duration); + self.pan_and_zoom_amount = + if self.pan_and_zoom_amount.is_finite() { self.pan_and_zoom_amount.clamp(0.0, 1.0) } else { d.pan_and_zoom_amount }; self } @@ -79,6 +88,8 @@ impl PlaybackSettings { "repeat": self.repeat, "preparePreviews": self.prepare_previews, "manual": self.manual, + "panAndZoom": self.pan_and_zoom, + "panAndZoomAmount": self.pan_and_zoom_amount, }) } @@ -96,9 +107,14 @@ impl PlaybackSettings { "repeat" => s.repeat = boolean(k, v)?, "preparePreviews" => s.prepare_previews = boolean(k, v)?, "manual" => s.manual = boolean(k, v)?, + "panAndZoom" => s.pan_and_zoom = boolean(k, v)?, + "panAndZoomAmount" => match v.as_f64() { + Some(x) if x.is_finite() => s.pan_and_zoom_amount = x, + _ => return Err(format!("`{k}` must be a finite number from 0 (low) to 1 (high), not {v}")), + }, other => { return Err(format!( - "unknown setting `{other}` (slideDuration, fadeDuration, fadeColor, randomOrder, repeat, preparePreviews, manual)" + "unknown setting `{other}` (slideDuration, fadeDuration, fadeColor, randomOrder, repeat, preparePreviews, manual, panAndZoom, panAndZoomAmount)" )); } } @@ -229,6 +245,16 @@ pub struct Frame { pub fade_color: Option<[u8; 3]>, } +/// The pan and zoom views at a moment of playback (`None`: the slide shows its whole picture, as +/// a title screen always does, and every slide when pan and zoom is off). +#[derive(Clone, Copy, Debug, PartialEq)] +pub struct PanZoom { + /// The current slide's view. + pub current: Option, + /// The view of the slide being faded out: where its motion ended. + pub from: Option, +} + /// Where the timeline is: the intro, the photos, or the ending. #[derive(Clone, Copy, Debug, PartialEq, Eq)] enum Phase { @@ -261,6 +287,10 @@ pub struct Playback { started: f64, /// The slide fading out (until the transition ends). from: Option, + /// The pan and zoom key of the slide fading out. + from_key: Option, + /// Times a single photo repeating has started over (each time on a new path). + reps: u64, /// Paused at this time. paused_at: Option, ended: bool, @@ -319,6 +349,8 @@ impl Playback { ending: None, started: now, from: None, + from_key: None, + reps: 0, paused_at: None, ended: false, held: None, @@ -516,8 +548,10 @@ impl Playback { } let Some(next) = self.upcoming(1).first().copied() else { if self.settings.repeat { - // a single photo repeating: nothing to change to + // a single photo repeating: nothing to change to (its pan and zoom starts again, + // on a new path) self.started = now; + self.reps = self.reps.wrapping_add(1); return Tick::Idle; } self.ended = true; @@ -529,14 +563,48 @@ impl Playback { } self.held = None; let old = self.current(); + let old_key = self.motion_key(old); let t = self.advance(); if let Tick::Advanced(new) = t { self.started = now; self.from = (self.fade_to(new) > 0.0).then_some(old); + self.from_key = self.from.and(old_key); } t } + /// The pan and zoom key of `item` up in the current pass (`None` for a title screen): the + /// seed, the pass, the photo and the repeats of a single photo, so every photo has its own + /// path, a new one in each pass, and the same seed plays the same paths. + fn motion_key(&self, item: Item) -> Option { + let photo = item.photo()?; + let mut st = self.seed ^ 0x7061_6e7a_6f6f_6d00; + for v in [self.pass, photo.0, self.reps] { + st = splitmix(&mut st) ^ v; + } + Some(splitmix(&mut st)) + } + + /// Where each slide's picture is at `now` with pan and zoom on: the current photo moves from + /// its start view (as it comes up, its fade in included) to its end view over its duration, + /// frozen while paused and held at the start in a manual slideshow (no slide is ever due + /// there); a photo fading out stays at its end view. Both are `None` with pan and zoom off. + pub fn pan_zoom(&self, now: f64) -> PanZoom { + if !self.settings.pan_and_zoom { + return PanZoom { current: None, from: None }; + } + let amount = self.settings.pan_and_zoom_amount; + let current = self.current(); + let t = if self.settings.manual { + 0.0 + } else { + let d = self.duration(current); + if d > 0.0 { (self.clock(now) - self.started) / d } else { 1.0 } + }; + let from = self.frame(now).from.and(self.from_key).map(|k| Motion::new(k, amount).at(1.0)); + PanZoom { current: self.motion_key(current).map(|k| Motion::new(k, amount).at(t)), from } + } + /// What to draw at `now`. pub fn frame(&self, now: f64) -> Frame { let now = self.clock(now); @@ -597,6 +665,7 @@ impl Playback { t = Tick::Advanced(self.current()); } self.from = None; + self.from_key = None; self.held = None; self.started = now; if self.paused_at.is_some() { diff --git a/crates/engine/src/slideshow/tests.rs b/crates/engine/src/slideshow/tests.rs index d329d5993d..310004e0d3 100644 --- a/crates/engine/src/slideshow/tests.rs +++ b/crates/engine/src/slideshow/tests.rs @@ -212,6 +212,90 @@ fn a_manual_slideshow_moves_only_with_the_arrows() { assert!(d.merged(&json!({"manual": "yes"})).is_err()); } +#[test] +fn pan_and_zoom_moves_each_photo_over_its_slide_on_its_own_path() { + // off: every slide shows its whole picture + let p = Playback::new(ids(3), None, settings(4.0, 1.0), 1, 0.0).unwrap(); + assert_eq!(p.pan_zoom(2.0), PanZoom { current: None, from: None }); + + let s = PlaybackSettings { pan_and_zoom: true, repeat: true, ..settings(4.0, 1.0) }; + let mut p = Playback::new(ids(3), None, s.clone(), 9, 0.0).unwrap().with_titles(Some(2.0), None); + assert_eq!(p.pan_zoom(1.0).current, None, "a title screen doesn't move"); + assert_eq!(p.tick(2.0, all_ready), Tick::Advanced(ph(1))); + let m1 = Motion::new(p.motion_key(ph(1)).unwrap(), 0.5); + assert_eq!(p.pan_zoom(2.0).current, Some(m1.start), "a photo comes up at its start view"); + assert_eq!(p.pan_zoom(2.5).from, None, "the intro fading out doesn't move either"); + assert_eq!(p.pan_zoom(4.0).current, Some(m1.at(0.5)), "half way through its 4 s, fade in included"); + // paused: frozen + p.toggle_pause(4.0); + assert_eq!(p.pan_zoom(100.0).current, Some(m1.at(0.5))); + p.toggle_pause(100.0); + assert_eq!(p.pan_zoom(101.0).current, Some(m1.at(0.75)), "and carries on from there"); + // the next photo: its own path from its start; the one fading out stays at its end view + assert_eq!(p.tick(102.0, all_ready), Tick::Advanced(ph(2))); + let z = p.pan_zoom(102.5); + let m2 = Motion::new(p.motion_key(ph(2)).unwrap(), 0.5); + assert_ne!(m1, m2, "every photo has its own path"); + assert_eq!(z.current, Some(m2.at(0.125))); + assert_eq!(z.from, Some(m1.end)); + assert_eq!(p.pan_zoom(103.5).from, None, "after the fade"); + // a slide that is due but not ready holds its end view + assert_eq!(p.tick(106.0, |i| i != ph(3)), Tick::Waiting(ph(3))); + assert_eq!(p.pan_zoom(110.0).current, Some(m2.end)); + // the same seed plays the same paths; another seed other ones + let q = Playback::new(ids(3), None, s.clone(), 9, 0.0).unwrap(); + assert_eq!(q.motion_key(ph(1)).map(|k| Motion::new(k, 0.5)), Some(m1)); + let r = Playback::new(ids(3), None, s, 10, 0.0).unwrap(); + assert_ne!(r.motion_key(ph(1)), q.motion_key(ph(1))); +} + +#[test] +fn pan_and_zoom_paths_change_each_pass_and_hold_in_a_manual_slideshow() { + let s = PlaybackSettings { pan_and_zoom: true, repeat: true, ..settings(4.0, 1.0) }; + // a new pass: a new path for the same photo + let mut p = Playback::new(ids(2), None, PlaybackSettings { fade_duration: 0.0, ..s.clone() }, 9, 0.0).unwrap(); + let first = p.pan_zoom(0.0).current; + p.tick(4.0, all_ready); + assert_eq!(p.tick(8.0, all_ready), Tick::Advanced(ph(1))); + assert_ne!(p.pan_zoom(8.0).current, first, "a fresh path in the next pass"); + // a single photo repeating starts again on a new path + let mut p = Playback::new(ids(1), None, s.clone(), 9, 0.0).unwrap(); + let first = p.pan_zoom(0.0).current; + assert_eq!(p.tick(4.0, all_ready), Tick::Idle); + assert_ne!(p.pan_zoom(4.0).current, first); + // the amount sets the zoom + let close = |amount: f64| { + let p = Playback::new(ids(1), None, PlaybackSettings { pan_and_zoom_amount: amount, ..s.clone() }, 9, 0.0).unwrap(); + let m = Motion::new(p.motion_key(ph(1)).unwrap(), amount); + m.start.zoom.max(m.end.zoom) + }; + assert!(close(1.0) > close(0.0)); + // a manual slideshow holds each photo at its start view; ← / → start the next one there + let mut p = Playback::new(ids(3), None, PlaybackSettings { manual: true, ..s }, 9, 0.0).unwrap(); + let start = Motion::new(p.motion_key(ph(1)).unwrap(), 0.5).start; + assert_eq!(p.pan_zoom(500.0).current, Some(start)); + p.step(1, 500.0); + assert_eq!(p.pan_zoom(900.0).current, Some(Motion::new(p.motion_key(ph(2)).unwrap(), 0.5).start)); +} + +#[test] +fn pan_and_zoom_settings_round_trip_and_are_checked() { + let d = PlaybackSettings::default(); + assert!(!d.pan_and_zoom, "off by default"); + assert_eq!(d.pan_and_zoom_amount, 0.5); + let m = d.merged(&json!({"panAndZoom": true, "panAndZoomAmount": 0.8})).unwrap(); + assert!(m.pan_and_zoom); + assert_eq!((m.to_json()["panAndZoom"].clone(), m.to_json()["panAndZoomAmount"].clone()), (json!(true), json!(0.8))); + assert_eq!(d.merged(&json!({"panAndZoomAmount": 3})).unwrap().pan_and_zoom_amount, 1.0, "clamped"); + assert_eq!(d.merged(&json!({"panAndZoomAmount": -1})).unwrap().pan_and_zoom_amount, 0.0); + assert!(d.merged(&json!({"panAndZoom": "on"})).is_err()); + assert!(d.merged(&json!({"panAndZoomAmount": "high"})).is_err()); + let s = PlaybackSettings { pan_and_zoom_amount: f64::NAN, ..d.clone() }.sanitized(); + assert_eq!(s.pan_and_zoom_amount, 0.5, "not finite: the default"); + let off = d.merged(&json!({"panAndZoomAmount": 0.2, "panAndZoom": false})).unwrap(); + assert_eq!(off.pan_and_zoom_amount, 0.2, "the amount is kept with the effect off"); +} + #[test] fn a_single_photo_repeats_without_changing() { let mut p = Playback::new(ids(1), None, settings(1.0, 0.5), 1, 0.0).unwrap(); diff --git a/crates/engine/src/tests/prefs.rs b/crates/engine/src/tests/prefs.rs index c0ded23ddb..a5b0a842b6 100644 --- a/crates/engine/src/tests/prefs.rs +++ b/crates/engine/src/tests/prefs.rs @@ -403,7 +403,7 @@ fn slideshow_playback_settings_persist_with_the_library() { let r = s .execute( "slideshow.playback", - &json!({"slideDuration": 6, "fadeDuration": 2.5, "fadeColor": "#000000", "randomOrder": true, "repeat": false, "manual": true}), + &json!({"slideDuration": 6, "fadeDuration": 2.5, "fadeColor": "#000000", "randomOrder": true, "repeat": false, "manual": true, "panAndZoom": true, "panAndZoomAmount": 0.25}), ) .unwrap(); assert_eq!(r["fadeColor"], "#000000"); @@ -417,7 +417,7 @@ fn slideshow_playback_settings_persist_with_the_library() { let r = s.execute("slideshow.playback", &json!({})).unwrap(); assert_eq!( r, - json!({"slideDuration": 6.0, "fadeDuration": 2.5, "fadeColor": "#000000", "randomOrder": true, "repeat": false, "preparePreviews": true, "manual": true}) + json!({"slideDuration": 6.0, "fadeDuration": 2.5, "fadeColor": "#000000", "randomOrder": true, "repeat": false, "preparePreviews": true, "manual": true, "panAndZoom": true, "panAndZoomAmount": 0.25}) ); drop(s); // out-of-range values written by hand are clamped when the library opens diff --git a/crates/slideshow/src/lib.rs b/crates/slideshow/src/lib.rs index 5827491d92..7de62086cd 100644 --- a/crates/slideshow/src/lib.rs +++ b/crates/slideshow/src/lib.rs @@ -1,6 +1,7 @@ //! Slideshow slides for LightCraft: the settings of Lightroom Classic's Slideshow Layout, Options //! and Backdrop panels ([`SlideSettings`]) and the CPU composer that draws one slide from a -//! rendered photo ([`compose`]). +//! rendered photo ([`compose`]), and the pan and zoom path a slide's photo follows during +//! playback ([`Motion`]). //! //! No UI and no catalog here: playback, the settings preview, the `slideshow.preview` command and //! (later) slideshow export all call [`compose`], so every one of them draws the same pixels. @@ -17,7 +18,9 @@ #![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)] mod compose; +mod motion; mod settings; pub use compose::{Layout, Rect, compose, compose_with, layout, photo_size}; +pub use motion::{Motion, View, ZOOM_HIGH, ZOOM_LOW}; pub use settings::{Aspect, MARGIN_MAX, MAX_SIDE, SHADOW_OFFSET_MAX, SHADOW_RADIUS_MAX, STROKE_MAX, SlideSettings, hex, parse_color}; diff --git a/crates/slideshow/src/motion.rs b/crates/slideshow/src/motion.rs new file mode 100644 index 0000000000..ed6d9cd8aa --- /dev/null +++ b/crates/slideshow/src/motion.rs @@ -0,0 +1,140 @@ +//! Pan and zoom (the Playback panel's Pan And Zoom): which part of a photo shows at each moment of +//! its slide. +//! +//! A [`Motion`] runs at constant speed from one [`View`] to another over the slide's time. A view +//! is a window of the photo in normalized coordinates (0–1 across and down) with the photo's own +//! aspect, so it never reaches past the photo's edges and is the same at any resolution. The path +//! comes from a key (playback derives it from its seed, the pass and the photo): the same key +//! always gives the same path, and different keys give different ones. + +/// Zoom of the closer view at amount 0 (Low) and at amount 1 (High). +pub const ZOOM_LOW: f64 = 1.01; +pub const ZOOM_HIGH: f64 = 1.12; +/// The wider view's share of the closer view's zoom above 1. +const WIDE_SHARE: f64 = 0.25; + +/// A window of the photo: its zoom (1 = the whole photo) and its centre (0–1 across and down). +#[derive(Clone, Copy, Debug, PartialEq)] +pub struct View { + pub zoom: f64, + pub x: f64, + pub y: f64, +} + +impl View { + /// The whole photo. + pub const FULL: View = View { zoom: 1.0, x: 0.5, y: 0.5 }; + + /// The window as (x0, y0, x1, y1), inside 0–1: a zoom below 1 or not finite is 1, and the + /// centre is kept far enough from the edges for the window to fit. + pub fn window(&self) -> (f64, f64, f64, f64) { + let z = if self.zoom.is_finite() { self.zoom.max(1.0) } else { 1.0 }; + let h = 0.5 / z; + let c = |v: f64| if v.is_finite() { v.clamp(h, 1.0 - h) } else { 0.5 }; + let (x, y) = (c(self.x), c(self.y)); + (x - h, y - h, x + h, y + h) + } +} + +/// A slide's pan and zoom: from `start` when the slide comes up to `end` when its time is over. +#[derive(Clone, Copy, Debug, PartialEq)] +pub struct Motion { + pub start: View, + pub end: View, +} + +/// SplitMix64 step. +fn mix(state: &mut u64) -> u64 { + *state = state.wrapping_add(0x9e37_79b9_7f4a_7c15); + let mut z = *state; + z = (z ^ (z >> 30)).wrapping_mul(0xbf58_476d_1ce4_e5b9); + z = (z ^ (z >> 27)).wrapping_mul(0x94d0_49bb_1331_11eb); + z ^ (z >> 31) +} + +/// A number in 0–1 from `state`. +fn unit(state: &mut u64) -> f64 { + (mix(state) >> 11) as f64 / (1u64 << 53) as f64 +} + +impl Motion { + /// The path for `key` at `amount` (0 = Low, 1 = High; clamped, not finite = 0.5). One end is + /// the closer view (zoom [`ZOOM_LOW`] at Low to [`ZOOM_HIGH`] at High), the other a wider one; + /// whether the slide zooms in or out and where each view sits come from the key. + pub fn new(key: u64, amount: f64) -> Motion { + let a = if amount.is_finite() { amount.clamp(0.0, 1.0) } else { 0.5 }; + let close = ZOOM_LOW + (ZOOM_HIGH - ZOOM_LOW) * a; + let wide = 1.0 + (close - 1.0) * WIDE_SHARE; + let mut st = key; + let (z0, z1) = if unit(&mut st) < 0.5 { (wide, close) } else { (close, wide) }; + let mut place = |z: f64| { + let room = 1.0 - 1.0 / z; + View { zoom: z, x: 0.5 / z + room * unit(&mut st), y: 0.5 / z + room * unit(&mut st) } + }; + let start = place(z0); + let end = place(z1); + Motion { start, end } + } + + /// The view at `t` (0 = the slide's start, 1 = its end; clamped, not finite = 0). Zoom and + /// centre move linearly; the window stays inside the photo all the way. + pub fn at(&self, t: f64) -> View { + let t = if t.is_finite() { t.clamp(0.0, 1.0) } else { 0.0 }; + let l = |a: f64, b: f64| a + (b - a) * t; + View { zoom: l(self.start.zoom, self.end.zoom), x: l(self.start.x, self.end.x), y: l(self.start.y, self.end.y) } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + fn inside(v: View) -> bool { + let (x0, y0, x1, y1) = v.window(); + x0 >= 0.0 && y0 >= 0.0 && x1 <= 1.0 + 1e-12 && y1 <= 1.0 + 1e-12 && x1 > x0 && y1 > y0 + } + + #[test] + fn the_same_key_gives_the_same_path_and_other_keys_other_paths() { + assert_eq!(Motion::new(7, 0.5), Motion::new(7, 0.5)); + let paths: Vec = (0..32).map(|k| Motion::new(k, 0.5)).collect(); + for (i, a) in paths.iter().enumerate() { + for b in &paths[i + 1..] { + assert_ne!(a, b, "every key has its own path"); + } + } + assert!(paths.iter().any(|m| m.start.zoom < m.end.zoom) && paths.iter().any(|m| m.start.zoom > m.end.zoom), "in and out"); + } + + #[test] + fn the_amount_sets_how_far_it_zooms() { + for k in 0..64 { + let low = Motion::new(k, 0.0); + let high = Motion::new(k, 1.0); + let close = |m: &Motion| m.start.zoom.max(m.end.zoom); + assert!((close(&low) - ZOOM_LOW).abs() < 1e-12, "{low:?}"); + assert!((close(&high) - ZOOM_HIGH).abs() < 1e-12, "{high:?}"); + assert!(low.start.zoom > 1.0 && low.end.zoom > 1.0, "Low still moves a little"); + } + assert_eq!(Motion::new(3, 7.0), Motion::new(3, 1.0), "clamped"); + assert_eq!(Motion::new(3, f64::NAN), Motion::new(3, 0.5)); + } + + #[test] + fn the_window_never_leaves_the_photo() { + for k in 0..256 { + let m = Motion::new(k, (k % 5) as f64 / 4.0); + for i in 0..=20 { + let v = m.at(i as f64 / 20.0); + assert!(inside(v), "key {k} at {i}: {v:?} {:?}", v.window()); + } + } + let m = Motion::new(1, 1.0); + assert_eq!(m.at(-1.0), m.start); + assert_eq!(m.at(2.0), m.end); + assert_eq!(m.at(f64::NAN), m.start); + assert_eq!(View::FULL.window(), (0.0, 0.0, 1.0, 1.0)); + assert_eq!(View { zoom: f64::NAN, x: 9.0, y: -1.0 }.window(), (0.0, 0.0, 1.0, 1.0), "bad values: the whole photo"); + assert_eq!(View { zoom: 2.0, x: 0.0, y: 1.0 }.window(), (0.0, 0.5, 0.5, 1.0), "the centre is moved in"); + } +} diff --git a/crates/ui-egui/src/dialogs/settings/slideshow.rs b/crates/ui-egui/src/dialogs/settings/slideshow.rs index a11bbfff60..1d280d0d31 100644 --- a/crates/ui-egui/src/dialogs/settings/slideshow.rs +++ b/crates/ui-egui/src/dialogs/settings/slideshow.rs @@ -93,6 +93,28 @@ fn playback_section(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { } } }); + let mut v = s.pan_and_zoom; + if check(ui, "settings.slideshowPanAndZoom", &mut v, "Pan and zoom") { + let _ = app.run("slideshow.playback", json!({"panAndZoom": v})); + } + row(ui, t, crate::i18n::tr("Amount"), |ui| { + ui.add_enabled_ui(s.pan_and_zoom, |ui| { + ui.label(crate::i18n::tr("Low")); + let mut a = s.pan_and_zoom_amount; + let r = ui.add(egui::Slider::new(&mut a, 0.0..=1.0).show_value(false)); + register(ui, "slider:slideshowPanAndZoom", r.rect); + ui.label(crate::i18n::tr("High")); + if r.changed() + && let Ok(next) = app.session.slideshow.merged(&json!({"panAndZoomAmount": a})) + { + app.session.slideshow = next; + } + if r.drag_stopped() || (r.changed() && !r.dragged()) { + let _ = app.run("slideshow.playback", json!({"panAndZoomAmount": a})); + } + }); + }); + hint(ui, t, crate::i18n::tr("Each photo moves and zooms slowly while it is up, on a path of its own. Exports show the photos still.")); let mut v = s.random_order; if check(ui, "settings.slideshowRandom", &mut v, "Random order") { let _ = app.run("slideshow.playback", json!({"randomOrder": v})); diff --git a/crates/ui-egui/src/panels/slideshow.rs b/crates/ui-egui/src/panels/slideshow.rs index cfe0ce6e68..9671c96bf8 100644 --- a/crates/ui-egui/src/panels/slideshow.rs +++ b/crates/ui-egui/src/panels/slideshow.rs @@ -1,6 +1,6 @@ //! The slideshow (View ▸ Slideshow, ⌥⌘↩): the photos in view, full screen, played with the //! library's Playback settings (`slideshow.playback`: slide and fade durations, fade colour, -//! random order, repeat, preparing previews in advance, manual slideshow). +//! random order, repeat, preparing previews in advance, manual slideshow, pan and zoom). //! //! The timeline is [`lightcraft_engine::slideshow::Playback`] (no egui, tested on its own); this //! module renders the slides, draws the frame it asks for and the playback controls. @@ -22,11 +22,17 @@ //! render worker ([`crate::render::Renderer::request_title`]), prepared ahead, waited for and //! faded like photo slides. They never move the selection, and the controls show "Intro" / "End" //! in place of "n / N" while one is up (titles aren't photos, so N stays the number of photos). +//! +//! Pan and zoom ([`Playback::pan_zoom`]) moves the photo's part of each slide's texture: the photo +//! inside its image cell for a composed slide, while the backdrop, margins, stroke and shadow stay +//! where they are. A photo drawn on its own, and a slide with overlays (drawn into its texture, +//! where they can cross the cell's edge), move as a whole. A title screen does not move. use egui::{Align2, Color32, Pos2, Rect, pos2, vec2}; use lightcraft_catalog::PhotoId; use lightcraft_engine::slideshow::{Item, Playback, Tick, Title}; use lightcraft_pipeline::geometry::Frame; +use lightcraft_slideshow::View; use serde_json::{Value, json}; use crate::LightcraftApp; @@ -53,9 +59,10 @@ pub struct Run { } /// `view.slideshow {interval?, seed?, slideDuration?, fadeDuration?, fadeColor?, randomOrder?, -/// repeat?, preparePreviews?, manual?}`: play the photos in view from the selected one with the library's -/// playback settings; the keys given change them for this run only (`interval` = slideDuration, -/// `seed` fixes the random order). The intro and ending screens that are on (`slideshow.titles`) +/// repeat?, preparePreviews?, manual?, panAndZoom?, panAndZoomAmount?}`: play the photos in view +/// from the selected one with the library's playback settings; the keys given change them for +/// this run only (`interval` = slideDuration, `seed` fixes the random order and the pan and zoom +/// paths). The intro and ending screens that are on (`slideshow.titles`) /// play before the first photo and after the last one. With no photos in view there is nothing /// to show (titles alone don't make a slideshow). pub fn start(app: &mut LightcraftApp, p: &Value, now: f64) -> Result { @@ -130,6 +137,12 @@ pub fn state(play: &Playback, now: f64) -> Value { // (null in a manual slideshow: no slide is ever due) "remaining": play.remaining(now), "manual": play.settings().manual, + "panAndZoom": play.settings().pan_and_zoom, + // (the current photo's window, 0–1 across and down; null when it shows whole) + "view": play.pan_zoom(now).current.map(|v| { + let (x0, y0, x1, y1) = v.window(); + json!([x0, y0, x1, y1]) + }), }) } @@ -173,8 +186,9 @@ pub fn tick(app: &mut LightcraftApp, ctx: &egui::Context, now: f64) { after(app, t); let Some(run) = app.ui.slideshow.as_ref() else { return }; let f = run.play.frame(now); - if f.from.is_some() { - ctx.request_repaint(); // a fade draws every frame + let moving = run.play.pan_zoom(now).current.is_some() && !run.play.is_paused() && !run.play.settings().manual; + if f.from.is_some() || moving { + ctx.request_repaint(); // a fade, and pan and zoom, draw every frame } else if !run.play.is_paused() && !run.play.settings().manual { ctx.request_repaint_after(std::time::Duration::from_secs_f64(run.play.remaining(now).clamp(0.016, 120.0))); } @@ -253,12 +267,44 @@ fn wanted(play: &Playback, now: f64) -> Vec<(Item, u32)> { /// screen has nothing to stand in for it: the black canvas shows until it lands. fn texture(app: &LightcraftApp, item: Item) -> Option<&crate::render::Tex> { let Item::Photo(id) = item else { return app.renderer.textures.get(&Slot::Slide(item)) }; - app.renderer - .textures - .get(&Slot::Slide(item)) - .filter(|t| t.photo == id) - .or_else(|| app.renderer.textures.get(&Slot::Main).filter(|t| t.photo == id)) - .or_else(|| app.renderer.thumb(id)) + slide_texture(app, id).or_else(|| app.renderer.textures.get(&Slot::Main).filter(|t| t.photo == id)).or_else(|| app.renderer.thumb(id)) +} + +/// Photo `id`'s own slide render. +fn slide_texture(app: &LightcraftApp, id: PhotoId) -> Option<&crate::render::Tex> { + app.renderer.textures.get(&Slot::Slide(Item::Photo(id))).filter(|t| t.photo == id) +} + +/// The part of `item`'s texture `t` that pan and zoom moves, in texture coordinates (0–1): the +/// photo's visible part of a composed slide without overlays (its image cell), else all of it (a +/// photo drawn on its own, a plain slide or a stand-in, and a slide with overlays, which are +/// drawn into its texture and can cross the cell's edge: they move with the slide). +pub(crate) fn moving_part(app: &LightcraftApp, item: Item, t: &crate::render::Tex) -> Rect { + let Item::Photo(id) = item else { return full_uv() }; + let composed = !app.session.slides_plain() && !app.session.slide_overlays.any() && slide_texture(app, id).is_some_and(|s| std::ptr::eq(s, t)); + let [w, h] = t.size; + let Some(aspect) = app.session.slide_photo_aspect(id).filter(|_| composed && w > 0 && h > 0) else { return full_uv() }; + let v = lightcraft_slideshow::layout(&app.session.slide_layout, aspect, w, h).visible; + let (w, h) = (w as f64, h as f64); + let uv = Rect::from_min_max(pos2((v.x0 / w) as f32, (v.y0 / h) as f32), pos2((v.x1 / w) as f32, (v.y1 / h) as f32)); + if uv.is_positive() { uv.intersect(full_uv()) } else { full_uv() } +} + +/// Draw texture `t` into `r` with `tint`. With a pan and zoom `view`, the `part` of it (texture +/// coordinates) shows that view's window of itself in the same place; the rest is drawn as is. +fn paint(p: &egui::Painter, t: &crate::render::Tex, r: Rect, part: Rect, view: Option, tint: Color32) { + let Some(v) = view else { + p.image(t.tex.id(), r, full_uv(), tint); + return; + }; + let at = |u: Pos2| pos2(r.min.x + u.x * r.width(), r.min.y + u.y * r.height()); + let place = Rect::from_min_max(at(part.min), at(part.max)); + for band in outside(r, place) { + p.with_clip_rect(band).image(t.tex.id(), r, full_uv(), tint); + } + let (x0, y0, x1, y1) = v.window(); + let sub = |x: f64, y: f64| pos2(part.min.x + x as f32 * part.width(), part.min.y + y as f32 * part.height()); + p.image(t.tex.id(), place, Rect::from_min_max(sub(x0, y0), sub(x1, y1)), tint); } fn full_uv() -> Rect { @@ -299,6 +345,7 @@ pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui) { let side = super::detail::texture_side(ui.ctx()); let want = wanted(&run.play, now); let frame = run.play.frame(now); + let pz = run.play.pan_zoom(now); let mut unrenderable = Vec::new(); for (item, priority) in &want { match *item { @@ -325,12 +372,22 @@ pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui) { let p = ui.painter_at(canvas); p.rect_filled(canvas, 0.0, Color32::BLACK); let rect_of = |t: &crate::render::Tex| super::detail::fit_texture_rect(canvas, t.size); - let draw = |id: Item, alpha: f32| -> Option { + let view_of = |id: Item| { + if id == frame.current { + pz.current + } else if Some(id) == frame.from { + pz.from + } else { + None + } + }; + let draw_on = |p: &egui::Painter, id: Item, alpha: f32| -> Option { let t = texture(app, id)?; let r = rect_of(t); - p.image(t.tex.id(), r, full_uv(), Color32::WHITE.gamma_multiply(alpha.clamp(0.0, 1.0))); + paint(p, t, r, moving_part(app, id, t), view_of(id), Color32::WHITE.gamma_multiply(alpha.clamp(0.0, 1.0))); Some(r) }; + let draw = |id: Item, alpha: f32| draw_on(&p, id, alpha); let k = frame.progress.clamp(0.0, 1.0); match (frame.from, frame.fade_color) { // fade through a colour: out to it, then in from it @@ -348,17 +405,16 @@ pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui) { // the old one is, it fades to the backdrop (Some(from), None) => { let new_rect = texture(app, frame.current).map(rect_of); - if let Some(t) = texture(app, from) { - let r = rect_of(t); + if let Some(r) = texture(app, from).map(rect_of) { match new_rect { Some(n) => { - p.with_clip_rect(n.intersect(canvas)).image(t.tex.id(), r, full_uv(), Color32::WHITE); + draw_on(&p.with_clip_rect(n.intersect(canvas)), from, 1.0); for band in outside(r, n) { - p.with_clip_rect(band).image(t.tex.id(), r, full_uv(), Color32::WHITE.gamma_multiply(1.0 - k)); + draw_on(&p.with_clip_rect(band), from, 1.0 - k); } } None => { - p.image(t.tex.id(), r, full_uv(), Color32::WHITE.gamma_multiply(1.0 - k)); + draw(from, 1.0 - k); } } } diff --git a/crates/ui-egui/src/tests/slideshow.rs b/crates/ui-egui/src/tests/slideshow.rs index 137dd9317a..e1b4b8b2cb 100644 --- a/crates/ui-egui/src/tests/slideshow.rs +++ b/crates/ui-egui/src/tests/slideshow.rs @@ -301,6 +301,80 @@ fn a_manual_slideshow_waits_for_the_arrow_keys() { h.settle(SETTLE); } +#[test] +fn pan_and_zoom_moves_the_photo_inside_its_cell() { + let mut h = grid(); + run(&mut h, "slideshow.layout", json!({"margins": 0.1, "backdropColor": "#ff0000"})); + run(&mut h, "slideshow.playback", json!({"panAndZoom": true, "panAndZoomAmount": 1.0})); + let r = run(&mut h, "view.slideshow", json!({"interval": 60, "fadeDuration": 0, "seed": 3})); + assert_eq!((r["settings"]["panAndZoom"].clone(), r["settings"]["panAndZoomAmount"].clone()), (json!(true), json!(1.0)), "{r}"); + let current = photo_up(&h); + assert!(h.step_until(SETTLE, |h| has_slide(h, current)), "the slide is composed and ready"); + h.step(); + let s = run(&mut h, "slideshow.togglePause", json!({})); + assert_eq!(s["panAndZoom"], true, "{s}"); + let start = s["view"].clone(); + let w = start.as_array().map(|v| v.iter().filter_map(|x| x.as_f64()).collect::>()).unwrap_or_default(); + assert_eq!(w.len(), 4, "{s}"); + assert!(w[0] >= 0.0 && w[1] >= 0.0 && w[2] <= 1.0 && w[3] <= 1.0 && w[2] - w[0] < 1.0, "a window inside the photo: {s}"); + let moving = h.paint(); + // the backdrop stays where it is + for (x, y) in [(5, 5), (995, 5), (500, 30), (30, 350), (985, 350)] { + assert_eq!(painted(&moving, x, y), [255, 0, 0], "margin at ({x}, {y})"); + } + // playing on, it moves + run(&mut h, "slideshow.togglePause", json!({})); + for _ in 0..240 { + h.step(); + } + assert_eq!(photo_up(&h), current, "the same slide is up"); + let s = run(&mut h, "slideshow.togglePause", json!({})); + assert_ne!(s["view"], start, "{s}"); + // the photo's cell moves; with an overlay drawn into the slide, the whole slide moves, so an + // overlay crossing the cell's edge stays in one piece + let part = |h: &Headless| { + let tex = h.app.renderer.textures.get(&Slot::Slide(current.into())).unwrap(); + crate::panels::slideshow::moving_part(&h.app, current.into(), tex) + }; + let cell = part(&h); + assert!(cell.min.x > 0.05 && cell.max.x < 0.95 && cell.min.y > 0.05 && cell.max.y < 0.95, "{cell:?}"); + run(&mut h, "slideshow.overlays", json!({"ratingStars": {"enabled": true}})); + assert_eq!(part(&h), egui::Rect::from_min_max(egui::pos2(0.0, 0.0), egui::pos2(1.0, 1.0))); + run(&mut h, "slideshow.overlays", json!({"ratingStars": {"enabled": false}})); + run(&mut h, "slideshow.end", json!({})); + // off: the photo shows whole, so the same slide paints other pixels in its cell + run(&mut h, "slideshow.playback", json!({"panAndZoom": false})); + run(&mut h, "library.select", json!({"ids": [current.0]})); + run(&mut h, "view.slideshow", json!({"interval": 60, "fadeDuration": 0, "manual": true})); + assert_eq!(photo_up(&h), current); + assert!(h.step_until(SETTLE, |h| has_slide(h, current))); + h.step(); + let s = run(&mut h, "slideshow.togglePause", json!({})); + assert_eq!((s["panAndZoom"].clone(), s["view"].clone()), (json!(false), json!(null)), "{s}"); + let still = h.paint(); + let mut changed = 0; + for y in (100..600).step_by(4) { + for x in (100..900).step_by(4) { + if painted(&moving, x, y) != painted(&still, x, y) { + changed += 1; + } + } + } + assert!(changed > 500, "the zoomed photo differs from the whole one ({changed} samples)"); + assert_eq!(painted(&still, 5, 5), [255, 0, 0]); + run(&mut h, "slideshow.end", json!({})); + // the Settings controls + run(&mut h, "view.slideshowOptions", json!({})); + h.step(); + reveal(&mut h, "check:settings.slideshowPanAndZoom"); + assert!(latest_widget_rect(&h, "slider:slideshowPanAndZoom").is_some(), "the Low to High slider"); + let r = h.request("ui.clickWidget", json!({"id": "check:settings.slideshowPanAndZoom"}), T); + assert_eq!(r["ok"], true, "{r}"); + h.step(); + assert!(h.app.session.slideshow.pan_and_zoom, "the checkbox goes through slideshow.playback"); + h.settle(SETTLE); +} + #[test] fn random_order_starts_at_the_selection_and_is_fixed_by_the_seed() { let order = |seed: u64| { diff --git a/docs/parity-checklist.md b/docs/parity-checklist.md index a9dd725236..21b94d253d 100644 --- a/docs/parity-checklist.md +++ b/docs/parity-checklist.md @@ -757,7 +757,7 @@ From `08-lightroom-classic-extras.md` (Classic-only features) and part 2 of `06- | LRC-SS-BACKDROP | Slideshow backdrop | P2 | ✅ | `cmd:slideshow.layout`, `path:crates/slideshow/src/compose.rs` | Background colour, Color Wash (a gradient from a second colour, full at the side its angle points to, at an opacity), Background Image (a library photo filling the slide at an opacity: "Use selected photo" in Settings ▸ Slideshow, `backgroundImage` in `slideshow.layout`; rendered once and shared by the slides). In the web build the composition runs on the main thread when a worker's render comes back | | LRC-SS-TITLES | Slideshow titles | P2 | 🟡 | `cmd:slideshow.titles`, `cmd:slideshow.preview`, `path:crates/engine/src/slide_title.rs`, `path:crates/ui-egui/src/dialogs/settings/slide_titles.rs` | Intro screen and ending screen, each on or off (library preference, `slideshow.titles`; Settings ▸ Slideshow ▸ Titles): a background colour and, centred on it, the identity plate of the Overlays section (its text or image; Add Identity Plate) or the screen's own line of text, in the plate's colour or an override colour, at a scale (height as a share of the slide's shorter side; text wider than the slide shrinks to fit), for its own duration (default: the slide duration). Titles are items of the playback timeline: composed off the UI thread by the same composer at the screen's size, prepared ahead, waited for and faded like slides; the intro plays once before the first photo, the ending after the last photo when repeat is off; random order never moves them; ←/→ step across them; they never change the selection and the control bar shows Intro / End instead of n / N. `slideshow.preview {title}` renders a screen; the Settings preview shows Photo / Intro / Ending. An empty view still refuses to play ("no photos to show"). Missing: Classic's exact behaviour with Repeat on is not verified (we never show the ending, and show the intro only at the start, while repeating), the Identity Plate Editor's styled text (Inter SemiBold only), override colour leaves an image plate's colours alone, the Slideshow module's Titles panel (settings live in Settings ▸ Slideshow). Slideshow export (LRC-SS-EXPORT) includes them: a PDF page / JPEG each, and in video they hold and fade like slides | | LRC-SS-MUSIC | Slideshow music | P2 | ⬜ | | | -| LRC-SS-PLAYBACK | Slideshow playback | P2 | 🟡 | `cmd:slideshow.playback`, `cmd:view.slideshowOptions`, `cmd:slideshow.togglePause`, `cmd:slideshow.next`, `cmd:slideshow.previous`, `cmd:slideshow.end` | Playback settings (library preference, `slideshow.playback`; Settings ▸ Slideshow, View ▸ Slideshow Options…): slide duration 0.5–120 s, fade 0–10 s (≤ slide; 0 = cut) as a crossfade or through a colour, random order (seeded shuffle, every photo once per pass, a new order each pass), repeat (off: ends after the last slide), prepare previews in advance (the next 2 slides render off the UI thread; a transition never starts before its slide is rendered — the current one is held), manual slideshow (`manual`: a slide, the intro or the ending stays up until ←/→ or the control bar changes it; exports keep the slide duration). Space / ←/→ (cut) / Esc and a control bar (previous, play/pause, next, n / N, end) that shows on pointer movement. Missing: the Slideshow module view and its "preview in the view" (phase 2 of the module plan), music and sync to music (LRC-SS-MUSIC), pan & zoom, choosing the screen to play on. Intro and ending screens play as items of the same timeline (LRC-SS-TITLES). Slides are composed with the layout, options and backdrop (LRC-SS-LAYOUT / OPTIONS / BACKDROP) and carry the overlays (LRC-SS-OVERLAYS) | +| LRC-SS-PLAYBACK | Slideshow playback | P2 | 🟡 | `cmd:slideshow.playback`, `cmd:view.slideshowOptions`, `cmd:slideshow.togglePause`, `cmd:slideshow.next`, `cmd:slideshow.previous`, `cmd:slideshow.end`, `path:crates/slideshow/src/motion.rs` | Playback settings (library preference, `slideshow.playback`; Settings ▸ Slideshow, View ▸ Slideshow Options…): slide duration 0.5–120 s, fade 0–10 s (≤ slide; 0 = cut) as a crossfade or through a colour, random order (seeded shuffle, every photo once per pass, a new order each pass), repeat (off: ends after the last slide), prepare previews in advance (the next 2 slides render off the UI thread; a transition never starts before its slide is rendered — the current one is held), manual slideshow (`manual`: a slide, the intro or the ending stays up until ←/→ or the control bar changes it; exports keep the slide duration), pan and zoom (`panAndZoom`, off by default, with a Low–High amount `panAndZoomAmount` 0–1, default 0.5: each photo moves at constant speed from one window of itself to another over its slide's time, its fade in included, zooming in or out between about 1.0025× and 1.01× at Low and 1.03× and 1.12× at High, on a path from the playback seed, the pass and the photo, so every photo and every pass has its own path and a seed replays it; the photo moves inside its image cell and the backdrop stays still, except that with overlays on the whole slide moves with them; title screens don't move; pause freezes it, a photo fading out stays at its end view, a manual slideshow holds each photo at its start view; these motion rules are LightCraft's own). Space / ←/→ (cut) / Esc and a control bar (previous, play/pause, next, n / N, end) that shows on pointer movement. Missing: the Slideshow module view and its "preview in the view" (phase 2 of the module plan), music and sync to music (LRC-SS-MUSIC), pan and zoom in exports (LRC-SS-EXPORT), choosing the screen to play on. Intro and ending screens play as items of the same timeline (LRC-SS-TITLES). Slides are composed with the layout, options and backdrop (LRC-SS-LAYOUT / OPTIONS / BACKDROP) and carry the overlays (LRC-SS-OVERLAYS) | | LRC-SS-EXPORT | Slideshow export | P2 | 🟡 | `cmd:slideshow.export`, `cmd:slideshow.exportStatus`, `cmd:dialog.slideshowExport`, `cmd:app.slideshowExport`, `path:crates/engine/src/slideshow_export.rs`, `path:crates/codecs/src/video.rs`, `path:crates/ui-egui/src/dialogs/slideshow_export.rs` | View ▸ Export Slideshow… (and Export PDF / JPEG / Video in Settings ▸ Slideshow): the photos in view as their composed slides (layout, overlays) between the intro and ending screens that are on, in view order. **PDF**: one page per slide at 1024 / 1920 / 3840 px (any 64–8192 by command; page = slide pixels in points, aspect from the aspect preview, "screen" = 16:9), JPEG quality, each page carrying the slide duration and a fade transition for presentation mode, "Automatically show full screen" (`/PageMode /FullScreen`). **JPEG**: `-001.jpg`… in a new folder. **Video**: AV1 (rav1e, fast preset) in MP4 or WebM written by our own muxers, 720p / 1080p (64–2160 by command), 24 / 30 fps (25 / 60 by command); each slide held for its duration (one long sample: variable frame rate) and fades rendered as blended frames (crossfade or through the fade colour); at most 2 hours. Runs in the background with a row in the activity stack (frames or slides done, ✕ cancels); files are written as `.part` and renamed when complete, so a cancelled or failed export leaves nothing; a photo that can't be rendered is skipped with a warning. Missing: H.264 (Classic's codec; patents, no pure-Rust encoder), audio / music in the video (LRC-SS-MUSIC), random order and pan & zoom in exports, the PDF's per-page fades follow the viewer (Acrobat), export presets, Classic's export dialog sizes beyond these, the web build (no export) | | LRC-PRINT-LAYOUTSTYLE | Print layout styles | P2 | ✅ | `cmd:dialog.print`, `cmd:print.set`, `cmd:print.get`, `cmd:print.exportPdf`, `cmd:export.contactSheet`, `crates/ui-egui/src/dialogs/print_view.rs` | File → Print… (⌘P): Single Image, Contact Sheet, Picture Package and Custom Package, one page preview each; also `print.*` commands for the CLI, control channel and MCP; the older File → Contact Sheet PDF stays | | LRC-PRINT-IMAGESETTINGS | Print image settings | P2 | ✅ | `cmd:print.set`, `crates/engine/src/print/compose.rs`, `crates/ui-egui/src/dialogs/print_view.rs` | Zoom to Fill Frame, Rotate to Fit, Photo Border (width, colour; package styles) and Inner Stroke (width in points, colour) in the dialog, drawn in the preview and in the PDF; pixel-tested | diff --git a/docs/slideshow.md b/docs/slideshow.md index e0c89b0311..fc2084e2c7 100644 --- a/docs/slideshow.md +++ b/docs/slideshow.md @@ -7,7 +7,7 @@ next to a live preview of the selected photo's slide, and View ▸ Slideshow ( | Part | Commands | Code | |---|---|---| -| Playback: slide and fade durations, fade colour, random order, repeat, preparing slides ahead, manual slideshow | `slideshow.playback`, `view.slideshow` | `crates/engine/src/slideshow.rs` (the timeline), `crates/ui-egui/src/panels/slideshow.rs` | +| Playback: slide and fade durations, fade colour, random order, repeat, preparing slides ahead, manual slideshow, pan and zoom | `slideshow.playback`, `view.slideshow` | `crates/engine/src/slideshow.rs` (the timeline), `crates/slideshow/src/motion.rs` (the pan and zoom path), `crates/ui-egui/src/panels/slideshow.rs` | | Layout, options, backdrop: margins, aspect preview, zoom to fill, stroke, shadow, colour, colour wash, background photo | `slideshow.layout` | `crates/slideshow` (the composer, no UI), `crates/engine/src/slide.rs` | | Overlays: identity plate, rating stars, text with tokens, watermark | `slideshow.overlays` | `crates/engine/src/slide_overlay.rs` | | Intro and ending screens | `slideshow.titles` | `crates/engine/src/slide_title.rs` | @@ -23,7 +23,7 @@ the same pixels through the same composer. View ▸ Export Slideshow… (or Export PDF / JPEG / Video at the end of Settings ▸ Slideshow) chooses a format and size, then asks where to write. The slides are the photos in view, in view order, between the intro and ending screens that -are on; random order, repeat and manual slideshow are playback choices and don't apply. The slide aspect is the Layout's aspect preview +are on; random order, repeat, manual slideshow and pan and zoom are playback choices and don't apply. The slide aspect is the Layout's aspect preview (Screen exports 16:9). - **PDF** — one page per slide, its picture a JPEG at the chosen quality, the page as many points as the slide has @@ -61,4 +61,4 @@ rendering included. The cost is in the fades (one encoded frame per frame of fad ## Not yet The Slideshow module view (left-panel template browser, slide editor with draggable guides and overlays), music and -sync to music, pan & zoom, H.264 video, saving a slideshow with an album, export presets. +sync to music, pan and zoom in exports, H.264 video, saving a slideshow with an album, export presets. From 0f0ab7709c354c3c15a00a895b4d2f30b5118c89 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 31 Oct 2026 05:10:58 -0700 Subject: [PATCH 02/11] LRC-SS-PLAYBACK: the pan and zoom amount is saved and an old slide render moves whole The Amount slider writes the live value while it moves, so slideshow.playback found no change when the drag ended and did not save the library preferences. The slider now saves them after the command runs. While a slide's new render is on the way after a layout, overlay or crop change, pan and zoom moved the old texture's pixels at the cell the new settings give. The cell is now used only for the current render; an older texture moves whole until the new one lands. --- .../ui-egui/src/dialogs/settings/slideshow.rs | 5 ++ crates/ui-egui/src/panels/slideshow.rs | 9 ++- crates/ui-egui/src/tests/slideshow.rs | 71 +++++++++++++++++++ 3 files changed, 83 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/dialogs/settings/slideshow.rs b/crates/ui-egui/src/dialogs/settings/slideshow.rs index 1d280d0d31..49eebed646 100644 --- a/crates/ui-egui/src/dialogs/settings/slideshow.rs +++ b/crates/ui-egui/src/dialogs/settings/slideshow.rs @@ -111,6 +111,11 @@ fn playback_section(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { } if r.drag_stopped() || (r.changed() && !r.dragged()) { let _ = app.run("slideshow.playback", json!({"panAndZoomAmount": a})); + // the live value above already holds the amount, so the command finds no change + // to save: save it here + if let Err(e) = app.session.save_prefs() { + log::warn!("slideshow: {e}"); + } } }); }); diff --git a/crates/ui-egui/src/panels/slideshow.rs b/crates/ui-egui/src/panels/slideshow.rs index 9671c96bf8..4e843a03b5 100644 --- a/crates/ui-egui/src/panels/slideshow.rs +++ b/crates/ui-egui/src/panels/slideshow.rs @@ -278,10 +278,15 @@ fn slide_texture(app: &LightcraftApp, id: PhotoId) -> Option<&crate::render::Tex /// The part of `item`'s texture `t` that pan and zoom moves, in texture coordinates (0–1): the /// photo's visible part of a composed slide without overlays (its image cell), else all of it (a /// photo drawn on its own, a plain slide or a stand-in, and a slide with overlays, which are -/// drawn into its texture and can cross the cell's edge: they move with the slide). +/// drawn into its texture and can cross the cell's edge: they move with the slide). The cell +/// comes from the current settings, so a texture rendered with older ones (its new render still +/// on the way) also moves whole. pub(crate) fn moving_part(app: &LightcraftApp, item: Item, t: &crate::render::Tex) -> Rect { let Item::Photo(id) = item else { return full_uv() }; - let composed = !app.session.slides_plain() && !app.session.slide_overlays.any() && slide_texture(app, id).is_some_and(|s| std::ptr::eq(s, t)); + let composed = !app.session.slides_plain() + && !app.session.slide_overlays.any() + && slide_texture(app, id).is_some_and(|s| std::ptr::eq(s, t)) + && app.renderer.is_current(Slot::Slide(item), t.key); let [w, h] = t.size; let Some(aspect) = app.session.slide_photo_aspect(id).filter(|_| composed && w > 0 && h > 0) else { return full_uv() }; let v = lightcraft_slideshow::layout(&app.session.slide_layout, aspect, w, h).visible; diff --git a/crates/ui-egui/src/tests/slideshow.rs b/crates/ui-egui/src/tests/slideshow.rs index e1b4b8b2cb..48544c04b7 100644 --- a/crates/ui-egui/src/tests/slideshow.rs +++ b/crates/ui-egui/src/tests/slideshow.rs @@ -375,6 +375,77 @@ fn pan_and_zoom_moves_the_photo_inside_its_cell() { h.settle(SETTLE); } +/// While a slide's new render (after a layout change) is on the way, the old texture moves +/// whole: its cell is where the old settings put it, not where the new ones do. +#[test] +fn pan_and_zoom_moves_an_old_render_whole_until_the_new_one_lands() { + let mut h = grid(); + let open = Rc::new(Cell::new(true)); + h.app.renderer.set_offload(Box::new(RenderGate::new(open.clone()))); + run(&mut h, "slideshow.layout", json!({"margins": 0.1})); + run(&mut h, "slideshow.playback", json!({"panAndZoom": true, "panAndZoomAmount": 1.0})); + run(&mut h, "view.slideshow", json!({"interval": 60, "fadeDuration": 0, "manual": true, "seed": 3})); + let current = photo_up(&h); + let slot = Slot::Slide(current.into()); + assert!(h.step_until(SETTLE, |h| has_slide(h, current) && h.app.renderer.wanted(slot) == h.app.renderer.textures.get(&slot).map(|t| t.key))); + let part = |h: &Headless| { + let tex = h.app.renderer.textures.get(&slot).unwrap(); + crate::panels::slideshow::moving_part(&h.app, current.into(), tex) + }; + let cell = part(&h); + assert!(cell.min.x > 0.05 && cell.max.x < 0.95, "the photo's cell: {cell:?}"); + // the margins change while the next render is held back + open.set(false); + let old = h.app.renderer.textures.get(&slot).map(|t| t.key); + run(&mut h, "slideshow.layout", json!({"margins": 0.3})); + h.step(); + assert_eq!(h.app.renderer.textures.get(&slot).map(|t| t.key), old, "the old render is still drawn"); + assert_ne!(h.app.renderer.wanted(slot), old, "a new render is on the way"); + assert_eq!(part(&h), egui::Rect::from_min_max(egui::pos2(0.0, 0.0), egui::pos2(1.0, 1.0)), "the old texture moves whole"); + // the new render lands: its own cell moves again + open.set(true); + assert!(h.step_until(SETTLE, |h| h.app.renderer.textures.get(&slot).map(|t| t.key) != old)); + let cell = part(&h); + assert!(cell.min.x > 0.2 && cell.max.x < 0.8, "the new, smaller cell: {cell:?}"); + run(&mut h, "slideshow.end", json!({})); + h.settle(SETTLE); +} + +/// The amount set on the Low to High slider is saved with the library: the slider writes the +/// live value as it moves, which leaves `slideshow.playback` nothing to change when it ends. +#[test] +fn the_pan_and_zoom_amount_from_the_slider_is_there_when_the_library_reopens() { + struct Folder(std::path::PathBuf); + impl Drop for Folder { + fn drop(&mut self) { + let _ = std::fs::remove_dir_all(&self.0); + } + } + let dir = Folder(std::env::temp_dir().join(format!("lc-ui-pan-zoom-amount-{}", std::process::id()))); + let _ = std::fs::remove_dir_all(&dir.0); + std::fs::create_dir_all(&dir.0).unwrap(); + let mut session = lightcraft_engine::Session::new().with_fs(); + session.open_library(&dir.0, false).unwrap(); + let mut h = Headless::new(LightcraftApp::new(session, Services { png: None, ..Default::default() }), [1000.0, 700.0], 1.0); + h.step(); + run(&mut h, "slideshow.playback", json!({"panAndZoom": true})); + let before = h.app.session.slideshow.pan_and_zoom_amount; + run(&mut h, "view.slideshowOptions", json!({})); + h.step(); + let slider = reveal(&mut h, "slider:slideshowPanAndZoom"); + let r = h.request("ui.dragWidget", json!({"id": "slider:slideshowPanAndZoom", "toX": slider.left(), "toY": slider.center().y}), T); + assert_eq!(r["ok"], true, "{r}"); + h.step(); + let amount = h.app.session.slideshow.pan_and_zoom_amount; + assert!(amount < before - 0.1, "the slider moved the amount from {before} to {amount}"); + h.settle(SETTLE); + drop(h); + let mut again = lightcraft_engine::Session::new().with_fs(); + again.open_library(&dir.0, false).unwrap(); + assert!(again.slideshow.pan_and_zoom, "the checkbox's setting is saved"); + assert_eq!(again.slideshow.pan_and_zoom_amount, amount, "the slider's amount is saved"); +} + #[test] fn random_order_starts_at_the_selection_and_is_fixed_by_the_seed() { let order = |seed: u64| { From 41e2d5450ca9240313989ccbfcc963678c752554 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 31 Oct 2026 05:22:46 -0700 Subject: [PATCH 03/11] LRC-SS-PLAYBACK: motion comments use American spelling --- crates/slideshow/src/motion.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/slideshow/src/motion.rs b/crates/slideshow/src/motion.rs index ed6d9cd8aa..9313b55257 100644 --- a/crates/slideshow/src/motion.rs +++ b/crates/slideshow/src/motion.rs @@ -13,7 +13,7 @@ pub const ZOOM_HIGH: f64 = 1.12; /// The wider view's share of the closer view's zoom above 1. const WIDE_SHARE: f64 = 0.25; -/// A window of the photo: its zoom (1 = the whole photo) and its centre (0–1 across and down). +/// A window of the photo: its zoom (1 = the whole photo) and its center (0–1 across and down). #[derive(Clone, Copy, Debug, PartialEq)] pub struct View { pub zoom: f64, @@ -26,7 +26,7 @@ impl View { pub const FULL: View = View { zoom: 1.0, x: 0.5, y: 0.5 }; /// The window as (x0, y0, x1, y1), inside 0–1: a zoom below 1 or not finite is 1, and the - /// centre is kept far enough from the edges for the window to fit. + /// center is kept far enough from the edges for the window to fit. pub fn window(&self) -> (f64, f64, f64, f64) { let z = if self.zoom.is_finite() { self.zoom.max(1.0) } else { 1.0 }; let h = 0.5 / z; @@ -77,7 +77,7 @@ impl Motion { } /// The view at `t` (0 = the slide's start, 1 = its end; clamped, not finite = 0). Zoom and - /// centre move linearly; the window stays inside the photo all the way. + /// center move linearly; the window stays inside the photo all the way. pub fn at(&self, t: f64) -> View { let t = if t.is_finite() { t.clamp(0.0, 1.0) } else { 0.0 }; let l = |a: f64, b: f64| a + (b - a) * t; @@ -135,6 +135,6 @@ mod tests { assert_eq!(m.at(f64::NAN), m.start); assert_eq!(View::FULL.window(), (0.0, 0.0, 1.0, 1.0)); assert_eq!(View { zoom: f64::NAN, x: 9.0, y: -1.0 }.window(), (0.0, 0.0, 1.0, 1.0), "bad values: the whole photo"); - assert_eq!(View { zoom: 2.0, x: 0.0, y: 1.0 }.window(), (0.0, 0.5, 0.5, 1.0), "the centre is moved in"); + assert_eq!(View { zoom: 2.0, x: 0.0, y: 1.0 }.window(), (0.0, 0.5, 0.5, 1.0), "the center is moved in"); } } From 32836313ee7fc9418b74fe1e023735a88c09e9f6 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 3 Nov 2026 20:56:08 -0800 Subject: [PATCH 04/11] LRC-SS-PLAYBACK: tests for pan and zoom across a slide, a pause, a fade and photo aspects The view is checked at the start, the middle and the end of a slide, while paused and after resuming (during the fade too), and through a fade that overlaps the move, straight and through a color. The window keeps the shape of the visible photo for a photo with the screen's aspect, a very narrow one and a very wide one. --- crates/engine/src/slideshow/tests.rs | 71 ++++++++++++++++++++++++++++ crates/slideshow/src/motion.rs | 26 ++++++++++ 2 files changed, 97 insertions(+) diff --git a/crates/engine/src/slideshow/tests.rs b/crates/engine/src/slideshow/tests.rs index 310004e0d3..1e7d959a91 100644 --- a/crates/engine/src/slideshow/tests.rs +++ b/crates/engine/src/slideshow/tests.rs @@ -296,6 +296,77 @@ fn pan_and_zoom_settings_round_trip_and_are_checked() { assert_eq!(off.pan_and_zoom_amount, 0.2, "the amount is kept with the effect off"); } +#[test] +fn pan_and_zoom_shows_the_start_the_middle_and_the_end_of_a_slide() { + let s = PlaybackSettings { pan_and_zoom: true, ..settings(4.0, 1.0) }; + let mut p = Playback::new(ids(2), None, s, 5, 10.0).unwrap(); + let first = p.current(); + let m = Motion::new(p.motion_key(first).unwrap(), 0.5); + assert_ne!(m.start, m.end, "the photo moves"); + assert_eq!(p.tick(10.0, all_ready), Tick::Idle); + assert_eq!(p.pan_zoom(10.0).current, Some(m.start), "at 0"); + let half = p.pan_zoom(12.0).current.unwrap(); + assert_eq!(half, m.at(0.5), "half way"); + for (a, b, mid) in [(m.start.zoom, m.end.zoom, half.zoom), (m.start.x, m.end.x, half.x), (m.start.y, m.end.y, half.y)] { + assert!((mid - (a + b) / 2.0).abs() < 1e-12, "half way along the path: {half:?}"); + } + assert_eq!(p.tick(13.99, all_ready), Tick::Idle); + assert_eq!(p.pan_zoom(14.0).current, Some(m.end), "at the end"); + assert_eq!(p.pan_zoom(30.0).current, Some(m.end), "a slide that runs over stays at its end"); + let Tick::Advanced(next) = p.tick(14.0, all_ready) else { panic!("the next slide comes up at 14") }; + let m2 = Motion::new(p.motion_key(next).unwrap(), 0.5); + assert_eq!(p.pan_zoom(14.0), PanZoom { current: Some(m2.start), from: Some(m.end) }, "the next one starts at its start"); +} + +#[test] +fn pan_and_zoom_stops_while_paused_and_carries_on_after() { + let s = PlaybackSettings { pan_and_zoom: true, ..settings(4.0, 1.0) }; + let mut p = Playback::new(ids(2), None, s, 5, 0.0).unwrap(); + let m1 = Motion::new(p.motion_key(p.current()).unwrap(), 0.5); + assert!(p.toggle_pause(1.0)); + for now in [1.0, 2.0, 50.0] { + assert_eq!(p.pan_zoom(now).current, Some(m1.at(0.25)), "paused at {now}"); + } + assert_eq!(p.tick(50.0, all_ready), Tick::Idle, "no slide change while paused"); + assert!(!p.toggle_pause(50.0)); + assert_eq!(p.pan_zoom(50.0).current, Some(m1.at(0.25)), "it resumes where it stopped"); + assert_eq!(p.pan_zoom(52.0).current, Some(m1.at(0.75))); + assert_eq!(p.tick(52.99, all_ready), Tick::Idle); + let Tick::Advanced(next) = p.tick(53.0, all_ready) else { panic!("the slide had 3 s left after the pause") }; + let m2 = Motion::new(p.motion_key(next).unwrap(), 0.5); + // paused during the fade: both photos hold their views, and the fade waits too + assert!(p.toggle_pause(53.5)); + assert_eq!(p.pan_zoom(80.0), PanZoom { current: Some(m2.at(0.125)), from: Some(m1.end) }); + assert_eq!(p.tick(80.0, all_ready), Tick::Idle); + assert_eq!(p.pan_zoom(80.0).from, Some(m1.end)); + assert!(!p.toggle_pause(80.0)); + assert_eq!(p.pan_zoom(80.25), PanZoom { current: Some(m2.at(0.1875)), from: Some(m1.end) }); + assert_eq!(p.tick(80.5, all_ready), Tick::Idle); + assert_eq!(p.pan_zoom(80.5), PanZoom { current: Some(m2.at(0.25)), from: None }, "the fade is over after its second"); +} + +#[test] +fn pan_and_zoom_moves_through_a_fade_that_overlaps_it() { + // a 2 s fade in a 4 s slide, straight and through a color: the new photo moves from its start + // view as it fades in, and the old one shows at its end view until the fade is over + for color in [None, Some([0, 0, 0])] { + let s = PlaybackSettings { pan_and_zoom: true, fade_color: color, ..settings(4.0, 2.0) }; + let mut p = Playback::new(ids(2), None, s, 5, 0.0).unwrap(); + let old = p.current(); + let m1 = Motion::new(p.motion_key(old).unwrap(), 0.5); + let Tick::Advanced(new) = p.tick(4.0, all_ready) else { panic!("the next slide comes up at 4") }; + let m2 = Motion::new(p.motion_key(new).unwrap(), 0.5); + for (now, t, progress) in [(4.0, 0.0, 0.0), (5.0, 0.25, 0.5), (5.5, 0.375, 0.75)] { + let f = p.frame(now); + assert_eq!((f.current, f.from), (new, Some(old)), "{color:?} at {now}"); + assert!((f.progress - progress).abs() < 1e-6, "{color:?} at {now}: {f:?}"); + assert_eq!(p.pan_zoom(now), PanZoom { current: Some(m2.at(t)), from: Some(m1.end) }, "{color:?} at {now}"); + } + assert_eq!(p.tick(6.0, all_ready), Tick::Idle); + assert_eq!(p.pan_zoom(6.0), PanZoom { current: Some(m2.at(0.5)), from: None }, "{color:?}: the fade is over, the move goes on"); + } +} + #[test] fn a_single_photo_repeats_without_changing() { let mut p = Playback::new(ids(1), None, settings(1.0, 0.5), 1, 0.0).unwrap(); diff --git a/crates/slideshow/src/motion.rs b/crates/slideshow/src/motion.rs index 9313b55257..3fc4fa2aa3 100644 --- a/crates/slideshow/src/motion.rs +++ b/crates/slideshow/src/motion.rs @@ -137,4 +137,30 @@ mod tests { assert_eq!(View { zoom: f64::NAN, x: 9.0, y: -1.0 }.window(), (0.0, 0.0, 1.0, 1.0), "bad values: the whole photo"); assert_eq!(View { zoom: 2.0, x: 0.0, y: 1.0 }.window(), (0.0, 0.5, 0.5, 1.0), "the center is moved in"); } + + /// On a 16:9 screen, a photo with the screen's aspect, a very narrow one and a very wide one: + /// the window, placed on the photo's visible part in slide pixels, stays inside that part and + /// has its shape, so the photo is not stretched and no empty edge shows. + #[test] + fn the_window_keeps_the_shape_of_the_visible_photo_at_any_aspect() { + for aspect in [16.0 / 9.0, 0.01, 50.0] { + let l = crate::layout(&crate::SlideSettings::default(), aspect, 1920, 1080); + let v = l.visible; + if aspect == 16.0 / 9.0 { + assert_eq!(v, l.cell, "a photo with the screen's aspect fills the screen"); + } + let (w, h) = (v.width(), v.height()); + assert!(w >= 1.0 && h >= 1.0, "{aspect}: {v:?}"); + for k in 0..64 { + let m = Motion::new(k, 1.0); + for i in 0..=10 { + let (x0, y0, x1, y1) = m.at(i as f64 / 10.0).window(); + let (sx0, sy0, sx1, sy1) = (v.x0 + x0 * w, v.y0 + y0 * h, v.x0 + x1 * w, v.y0 + y1 * h); + assert!(sx0 >= v.x0 && sy0 >= v.y0 && sx1 <= v.x1 + 1e-9 && sy1 <= v.y1 + 1e-9, "{aspect}, key {k} at {i}"); + let shape = ((sx1 - sx0) / (sy1 - sy0)) / (w / h); + assert!((shape - 1.0).abs() < 1e-9, "{aspect}, key {k} at {i}: stretched by {shape}"); + } + } + } + } } From 87dea3a63454b95c04103fc5a5905f8ac21f4cf4 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 3 Nov 2026 21:36:22 -0800 Subject: [PATCH 05/11] LRC-SS-PLAYBACK: the slideshow stops redrawing every frame once a photo's move is over When a slide's time is over and the next slide is not ready, the photo holds its end view. The slideshow now redraws every frame only while Playback::pan_zoom_moving says the photo is moving, and otherwise keeps its usual redraw timing. --- crates/engine/src/slideshow.rs | 11 +++++++++++ crates/engine/src/slideshow/tests.rs | 23 +++++++++++++++++++++++ crates/ui-egui/src/panels/slideshow.rs | 3 +-- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/slideshow.rs b/crates/engine/src/slideshow.rs index 3eb538627a..2eaf5adef2 100644 --- a/crates/engine/src/slideshow.rs +++ b/crates/engine/src/slideshow.rs @@ -605,6 +605,17 @@ impl Playback { PanZoom { current: self.motion_key(current).map(|k| Motion::new(k, amount).at(t)), from } } + /// Whether pan and zoom moves the current photo at `now`: on, playing (not paused, not a + /// manual slideshow), a photo up and its time not over. A slide whose time is over while the + /// next one is not ready yet stays at its end view. + pub fn pan_zoom_moving(&self, now: f64) -> bool { + self.settings.pan_and_zoom + && self.paused_at.is_none() + && !self.settings.manual + && self.current().photo().is_some() + && self.remaining(now) > 0.0 + } + /// What to draw at `now`. pub fn frame(&self, now: f64) -> Frame { let now = self.clock(now); diff --git a/crates/engine/src/slideshow/tests.rs b/crates/engine/src/slideshow/tests.rs index 1e7d959a91..9cf93e54dd 100644 --- a/crates/engine/src/slideshow/tests.rs +++ b/crates/engine/src/slideshow/tests.rs @@ -318,6 +318,29 @@ fn pan_and_zoom_shows_the_start_the_middle_and_the_end_of_a_slide() { assert_eq!(p.pan_zoom(14.0), PanZoom { current: Some(m2.start), from: Some(m.end) }, "the next one starts at its start"); } +#[test] +fn pan_and_zoom_moves_only_while_a_photo_plays_out_its_time() { + let s = PlaybackSettings { pan_and_zoom: true, ..settings(4.0, 1.0) }; + let mut p = Playback::new(ids(2), None, s.clone(), 5, 0.0).unwrap(); + for now in [0.0, 2.0, 3.99] { + assert!(p.pan_zoom_moving(now), "moving at {now}"); + } + // its time is over and the next slide is not ready: it holds its end view, so nothing moves + let next = p.upcoming(1)[0]; + assert_eq!(p.tick(4.0, |i| i != next), Tick::Waiting(next)); + assert!(!p.pan_zoom_moving(4.0) && !p.pan_zoom_moving(9.0)); + assert_eq!(p.tick(9.0, all_ready), Tick::Advanced(next)); + assert!(p.pan_zoom_moving(9.0), "the next photo moves"); + p.toggle_pause(10.0); + assert!(!p.pan_zoom_moving(11.0), "paused"); + let off = Playback::new(ids(2), None, settings(4.0, 1.0), 5, 0.0).unwrap(); + assert!(!off.pan_zoom_moving(1.0), "off"); + let manual = Playback::new(ids(2), None, PlaybackSettings { manual: true, ..s.clone() }, 5, 0.0).unwrap(); + assert!(!manual.pan_zoom_moving(1.0), "a manual slideshow holds its start view"); + let titled = Playback::new(ids(2), None, s, 5, 0.0).unwrap().with_titles(Some(2.0), None); + assert!(!titled.pan_zoom_moving(1.0), "a title screen does not move"); +} + #[test] fn pan_and_zoom_stops_while_paused_and_carries_on_after() { let s = PlaybackSettings { pan_and_zoom: true, ..settings(4.0, 1.0) }; diff --git a/crates/ui-egui/src/panels/slideshow.rs b/crates/ui-egui/src/panels/slideshow.rs index 4e843a03b5..63cf6c23ee 100644 --- a/crates/ui-egui/src/panels/slideshow.rs +++ b/crates/ui-egui/src/panels/slideshow.rs @@ -186,8 +186,7 @@ pub fn tick(app: &mut LightcraftApp, ctx: &egui::Context, now: f64) { after(app, t); let Some(run) = app.ui.slideshow.as_ref() else { return }; let f = run.play.frame(now); - let moving = run.play.pan_zoom(now).current.is_some() && !run.play.is_paused() && !run.play.settings().manual; - if f.from.is_some() || moving { + if f.from.is_some() || run.play.pan_zoom_moving(now) { ctx.request_repaint(); // a fade, and pan and zoom, draw every frame } else if !run.play.is_paused() && !run.play.settings().manual { ctx.request_repaint_after(std::time::Duration::from_secs_f64(run.play.remaining(now).clamp(0.016, 120.0))); From 3e8e088320e3c64ae4e18abbedad6c4ac409a6a4 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 3 Nov 2026 21:50:45 -0800 Subject: [PATCH 06/11] LRC-SS-PLAYBACK: a single repeating photo starts its next path where the last one ended With pan and zoom on and one photo repeating, each new path started at a new view, so the picture jumped at every repeat. The new path now starts at the view the last one ended on. --- crates/engine/src/slideshow.rs | 18 ++++++++++++++++-- crates/engine/src/slideshow/tests.rs | 7 +++++++ docs/parity-checklist.md | 2 +- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/slideshow.rs b/crates/engine/src/slideshow.rs index 2eaf5adef2..51f8622a5a 100644 --- a/crates/engine/src/slideshow.rs +++ b/crates/engine/src/slideshow.rs @@ -291,6 +291,9 @@ pub struct Playback { from_key: Option, /// Times a single photo repeating has started over (each time on a new path). reps: u64, + /// Where a single repeating photo's last path ended: its new path starts there, so the + /// picture does not jump when it starts over. + rep_start: Option, /// Paused at this time. paused_at: Option, ended: bool, @@ -351,6 +354,7 @@ impl Playback { from: None, from_key: None, reps: 0, + rep_start: None, paused_at: None, ended: false, held: None, @@ -549,7 +553,8 @@ impl Playback { let Some(next) = self.upcoming(1).first().copied() else { if self.settings.repeat { // a single photo repeating: nothing to change to (its pan and zoom starts again, - // on a new path) + // on a new path from where the last one ended) + self.rep_start = self.motion(self.current()).map(|m| m.end); self.started = now; self.reps = self.reps.wrapping_add(1); return Tick::Idle; @@ -569,10 +574,18 @@ impl Playback { self.started = now; self.from = (self.fade_to(new) > 0.0).then_some(old); self.from_key = self.from.and(old_key); + self.rep_start = None; } t } + /// The pan and zoom path of `item` up now (`None` for a title screen): from its key, starting + /// where the last path ended when a single photo repeats. + fn motion(&self, item: Item) -> Option { + let m = Motion::new(self.motion_key(item)?, self.settings.pan_and_zoom_amount); + Some(Motion { start: self.rep_start.unwrap_or(m.start), ..m }) + } + /// The pan and zoom key of `item` up in the current pass (`None` for a title screen): the /// seed, the pass, the photo and the repeats of a single photo, so every photo has its own /// path, a new one in each pass, and the same seed plays the same paths. @@ -602,7 +615,7 @@ impl Playback { if d > 0.0 { (self.clock(now) - self.started) / d } else { 1.0 } }; let from = self.frame(now).from.and(self.from_key).map(|k| Motion::new(k, amount).at(1.0)); - PanZoom { current: self.motion_key(current).map(|k| Motion::new(k, amount).at(t)), from } + PanZoom { current: self.motion(current).map(|m| m.at(t)), from } } /// Whether pan and zoom moves the current photo at `now`: on, playing (not paused, not a @@ -677,6 +690,7 @@ impl Playback { } self.from = None; self.from_key = None; + self.rep_start = None; self.held = None; self.started = now; if self.paused_at.is_some() { diff --git a/crates/engine/src/slideshow/tests.rs b/crates/engine/src/slideshow/tests.rs index 9cf93e54dd..8cd1c53887 100644 --- a/crates/engine/src/slideshow/tests.rs +++ b/crates/engine/src/slideshow/tests.rs @@ -261,8 +261,15 @@ fn pan_and_zoom_paths_change_each_pass_and_hold_in_a_manual_slideshow() { // a single photo repeating starts again on a new path let mut p = Playback::new(ids(1), None, s.clone(), 9, 0.0).unwrap(); let first = p.pan_zoom(0.0).current; + let ended = p.pan_zoom(4.0).current; assert_eq!(p.tick(4.0, all_ready), Tick::Idle); assert_ne!(p.pan_zoom(4.0).current, first); + assert_eq!(p.pan_zoom(4.0).current, ended, "the new path starts where the last one ended: no jump"); + let second_end = p.pan_zoom(8.0).current; + assert_ne!(second_end, ended, "and goes somewhere new"); + assert_eq!(p.tick(8.0, all_ready), Tick::Idle); + assert_eq!(p.pan_zoom(8.0).current, second_end, "again"); + assert_ne!(p.pan_zoom(12.0).current, second_end); // the amount sets the zoom let close = |amount: f64| { let p = Playback::new(ids(1), None, PlaybackSettings { pan_and_zoom_amount: amount, ..s.clone() }, 9, 0.0).unwrap(); diff --git a/docs/parity-checklist.md b/docs/parity-checklist.md index 21b94d253d..abea867b99 100644 --- a/docs/parity-checklist.md +++ b/docs/parity-checklist.md @@ -757,7 +757,7 @@ From `08-lightroom-classic-extras.md` (Classic-only features) and part 2 of `06- | LRC-SS-BACKDROP | Slideshow backdrop | P2 | ✅ | `cmd:slideshow.layout`, `path:crates/slideshow/src/compose.rs` | Background colour, Color Wash (a gradient from a second colour, full at the side its angle points to, at an opacity), Background Image (a library photo filling the slide at an opacity: "Use selected photo" in Settings ▸ Slideshow, `backgroundImage` in `slideshow.layout`; rendered once and shared by the slides). In the web build the composition runs on the main thread when a worker's render comes back | | LRC-SS-TITLES | Slideshow titles | P2 | 🟡 | `cmd:slideshow.titles`, `cmd:slideshow.preview`, `path:crates/engine/src/slide_title.rs`, `path:crates/ui-egui/src/dialogs/settings/slide_titles.rs` | Intro screen and ending screen, each on or off (library preference, `slideshow.titles`; Settings ▸ Slideshow ▸ Titles): a background colour and, centred on it, the identity plate of the Overlays section (its text or image; Add Identity Plate) or the screen's own line of text, in the plate's colour or an override colour, at a scale (height as a share of the slide's shorter side; text wider than the slide shrinks to fit), for its own duration (default: the slide duration). Titles are items of the playback timeline: composed off the UI thread by the same composer at the screen's size, prepared ahead, waited for and faded like slides; the intro plays once before the first photo, the ending after the last photo when repeat is off; random order never moves them; ←/→ step across them; they never change the selection and the control bar shows Intro / End instead of n / N. `slideshow.preview {title}` renders a screen; the Settings preview shows Photo / Intro / Ending. An empty view still refuses to play ("no photos to show"). Missing: Classic's exact behaviour with Repeat on is not verified (we never show the ending, and show the intro only at the start, while repeating), the Identity Plate Editor's styled text (Inter SemiBold only), override colour leaves an image plate's colours alone, the Slideshow module's Titles panel (settings live in Settings ▸ Slideshow). Slideshow export (LRC-SS-EXPORT) includes them: a PDF page / JPEG each, and in video they hold and fade like slides | | LRC-SS-MUSIC | Slideshow music | P2 | ⬜ | | | -| LRC-SS-PLAYBACK | Slideshow playback | P2 | 🟡 | `cmd:slideshow.playback`, `cmd:view.slideshowOptions`, `cmd:slideshow.togglePause`, `cmd:slideshow.next`, `cmd:slideshow.previous`, `cmd:slideshow.end`, `path:crates/slideshow/src/motion.rs` | Playback settings (library preference, `slideshow.playback`; Settings ▸ Slideshow, View ▸ Slideshow Options…): slide duration 0.5–120 s, fade 0–10 s (≤ slide; 0 = cut) as a crossfade or through a colour, random order (seeded shuffle, every photo once per pass, a new order each pass), repeat (off: ends after the last slide), prepare previews in advance (the next 2 slides render off the UI thread; a transition never starts before its slide is rendered — the current one is held), manual slideshow (`manual`: a slide, the intro or the ending stays up until ←/→ or the control bar changes it; exports keep the slide duration), pan and zoom (`panAndZoom`, off by default, with a Low–High amount `panAndZoomAmount` 0–1, default 0.5: each photo moves at constant speed from one window of itself to another over its slide's time, its fade in included, zooming in or out between about 1.0025× and 1.01× at Low and 1.03× and 1.12× at High, on a path from the playback seed, the pass and the photo, so every photo and every pass has its own path and a seed replays it; the photo moves inside its image cell and the backdrop stays still, except that with overlays on the whole slide moves with them; title screens don't move; pause freezes it, a photo fading out stays at its end view, a manual slideshow holds each photo at its start view; these motion rules are LightCraft's own). Space / ←/→ (cut) / Esc and a control bar (previous, play/pause, next, n / N, end) that shows on pointer movement. Missing: the Slideshow module view and its "preview in the view" (phase 2 of the module plan), music and sync to music (LRC-SS-MUSIC), pan and zoom in exports (LRC-SS-EXPORT), choosing the screen to play on. Intro and ending screens play as items of the same timeline (LRC-SS-TITLES). Slides are composed with the layout, options and backdrop (LRC-SS-LAYOUT / OPTIONS / BACKDROP) and carry the overlays (LRC-SS-OVERLAYS) | +| LRC-SS-PLAYBACK | Slideshow playback | P2 | 🟡 | `cmd:slideshow.playback`, `cmd:view.slideshowOptions`, `cmd:slideshow.togglePause`, `cmd:slideshow.next`, `cmd:slideshow.previous`, `cmd:slideshow.end`, `path:crates/slideshow/src/motion.rs` | Playback settings (library preference, `slideshow.playback`; Settings ▸ Slideshow, View ▸ Slideshow Options…): slide duration 0.5–120 s, fade 0–10 s (≤ slide; 0 = cut) as a crossfade or through a colour, random order (seeded shuffle, every photo once per pass, a new order each pass), repeat (off: ends after the last slide), prepare previews in advance (the next 2 slides render off the UI thread; a transition never starts before its slide is rendered — the current one is held), manual slideshow (`manual`: a slide, the intro or the ending stays up until ←/→ or the control bar changes it; exports keep the slide duration), pan and zoom (`panAndZoom`, off by default, with a Low–High amount `panAndZoomAmount` 0–1, default 0.5: each photo moves at constant speed from one window of itself to another over its slide's time, its fade in included, zooming in or out between about 1.0025× and 1.01× at Low and 1.03× and 1.12× at High, on a path from the playback seed, the pass and the photo, so every photo and every pass has its own path and a seed replays it; the photo moves inside its image cell and the backdrop stays still, except that with overlays on the whole slide moves with them; title screens don't move; pause freezes it, a photo fading out stays at its end view, a manual slideshow holds each photo at its start view, a single repeating photo starts each new path where the last one ended; these motion rules are LightCraft's own). Space / ←/→ (cut) / Esc and a control bar (previous, play/pause, next, n / N, end) that shows on pointer movement. Missing: the Slideshow module view and its "preview in the view" (phase 2 of the module plan), music and sync to music (LRC-SS-MUSIC), pan and zoom in exports (LRC-SS-EXPORT), choosing the screen to play on. Intro and ending screens play as items of the same timeline (LRC-SS-TITLES). Slides are composed with the layout, options and backdrop (LRC-SS-LAYOUT / OPTIONS / BACKDROP) and carry the overlays (LRC-SS-OVERLAYS) | | LRC-SS-EXPORT | Slideshow export | P2 | 🟡 | `cmd:slideshow.export`, `cmd:slideshow.exportStatus`, `cmd:dialog.slideshowExport`, `cmd:app.slideshowExport`, `path:crates/engine/src/slideshow_export.rs`, `path:crates/codecs/src/video.rs`, `path:crates/ui-egui/src/dialogs/slideshow_export.rs` | View ▸ Export Slideshow… (and Export PDF / JPEG / Video in Settings ▸ Slideshow): the photos in view as their composed slides (layout, overlays) between the intro and ending screens that are on, in view order. **PDF**: one page per slide at 1024 / 1920 / 3840 px (any 64–8192 by command; page = slide pixels in points, aspect from the aspect preview, "screen" = 16:9), JPEG quality, each page carrying the slide duration and a fade transition for presentation mode, "Automatically show full screen" (`/PageMode /FullScreen`). **JPEG**: `-001.jpg`… in a new folder. **Video**: AV1 (rav1e, fast preset) in MP4 or WebM written by our own muxers, 720p / 1080p (64–2160 by command), 24 / 30 fps (25 / 60 by command); each slide held for its duration (one long sample: variable frame rate) and fades rendered as blended frames (crossfade or through the fade colour); at most 2 hours. Runs in the background with a row in the activity stack (frames or slides done, ✕ cancels); files are written as `.part` and renamed when complete, so a cancelled or failed export leaves nothing; a photo that can't be rendered is skipped with a warning. Missing: H.264 (Classic's codec; patents, no pure-Rust encoder), audio / music in the video (LRC-SS-MUSIC), random order and pan & zoom in exports, the PDF's per-page fades follow the viewer (Acrobat), export presets, Classic's export dialog sizes beyond these, the web build (no export) | | LRC-PRINT-LAYOUTSTYLE | Print layout styles | P2 | ✅ | `cmd:dialog.print`, `cmd:print.set`, `cmd:print.get`, `cmd:print.exportPdf`, `cmd:export.contactSheet`, `crates/ui-egui/src/dialogs/print_view.rs` | File → Print… (⌘P): Single Image, Contact Sheet, Picture Package and Custom Package, one page preview each; also `print.*` commands for the CLI, control channel and MCP; the older File → Contact Sheet PDF stays | | LRC-PRINT-IMAGESETTINGS | Print image settings | P2 | ✅ | `cmd:print.set`, `crates/engine/src/print/compose.rs`, `crates/ui-egui/src/dialogs/print_view.rs` | Zoom to Fill Frame, Rotate to Fit, Photo Border (width, colour; package styles) and Inner Stroke (width in points, colour) in the dialog, drawn in the preview and in the PDF; pixel-tested | From 3e9231e010de0cff19581b91de022986820c019d Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 4 Nov 2026 08:06:57 -0800 Subject: [PATCH 07/11] LRC-SS-PLAYBACK: test pan and zoom on very narrow and very wide photos in the slideshow The slideshow test crops one photo to its cell's shape, to aspect 0.01 and to aspect 50, and checks that the part that moves is the photo's visible part of the slide, that the backdrop beside it stays and that the photo still shows in it. The motion test now checks only the window's equal share of width and height, which holds at any aspect. --- crates/slideshow/src/motion.rs | 27 ++++------ crates/ui-egui/src/tests/slideshow.rs | 71 +++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 18 deletions(-) diff --git a/crates/slideshow/src/motion.rs b/crates/slideshow/src/motion.rs index 3fc4fa2aa3..3f4a47db0a 100644 --- a/crates/slideshow/src/motion.rs +++ b/crates/slideshow/src/motion.rs @@ -138,27 +138,18 @@ mod tests { assert_eq!(View { zoom: 2.0, x: 0.0, y: 1.0 }.window(), (0.0, 0.5, 0.5, 1.0), "the center is moved in"); } - /// On a 16:9 screen, a photo with the screen's aspect, a very narrow one and a very wide one: - /// the window, placed on the photo's visible part in slide pixels, stays inside that part and - /// has its shape, so the photo is not stretched and no empty edge shows. + /// The window takes the same share of the photo's width and height at every moment, so it + /// keeps the photo's shape whatever the photo's aspect. The slideshow's drawing of very narrow + /// and very wide photos is tested in the app. #[test] - fn the_window_keeps_the_shape_of_the_visible_photo_at_any_aspect() { - for aspect in [16.0 / 9.0, 0.01, 50.0] { - let l = crate::layout(&crate::SlideSettings::default(), aspect, 1920, 1080); - let v = l.visible; - if aspect == 16.0 / 9.0 { - assert_eq!(v, l.cell, "a photo with the screen's aspect fills the screen"); - } - let (w, h) = (v.width(), v.height()); - assert!(w >= 1.0 && h >= 1.0, "{aspect}: {v:?}"); - for k in 0..64 { - let m = Motion::new(k, 1.0); + fn the_window_takes_the_same_share_of_width_and_height() { + for k in 0..64 { + for amount in [0.0, 0.5, 1.0] { + let m = Motion::new(k, amount); for i in 0..=10 { let (x0, y0, x1, y1) = m.at(i as f64 / 10.0).window(); - let (sx0, sy0, sx1, sy1) = (v.x0 + x0 * w, v.y0 + y0 * h, v.x0 + x1 * w, v.y0 + y1 * h); - assert!(sx0 >= v.x0 && sy0 >= v.y0 && sx1 <= v.x1 + 1e-9 && sy1 <= v.y1 + 1e-9, "{aspect}, key {k} at {i}"); - let shape = ((sx1 - sx0) / (sy1 - sy0)) / (w / h); - assert!((shape - 1.0).abs() < 1e-9, "{aspect}, key {k} at {i}: stretched by {shape}"); + assert!(((x1 - x0) - (y1 - y0)).abs() < 1e-12, "key {k} at {i}: {:?}", (x0, y0, x1, y1)); + assert!(x1 - x0 < 1.0, "key {k} at {i}: zoomed in"); } } } diff --git a/crates/ui-egui/src/tests/slideshow.rs b/crates/ui-egui/src/tests/slideshow.rs index 48544c04b7..f332fb857e 100644 --- a/crates/ui-egui/src/tests/slideshow.rs +++ b/crates/ui-egui/src/tests/slideshow.rs @@ -411,6 +411,77 @@ fn pan_and_zoom_moves_an_old_render_whole_until_the_new_one_lands() { h.settle(SETTLE); } +/// A photo cropped to its cell's shape, a very narrow one (aspect 0.01) and a very wide one +/// (aspect 50): the part that moves is the photo's visible part of the slide, so the backdrop +/// beside it stays where it is and the photo still shows inside it. +#[test] +fn pan_and_zoom_moves_only_the_visible_photo_at_any_aspect() { + let mut h = grid(); + run(&mut h, "slideshow.layout", json!({"margins": 0.1, "backdropColor": "#ff0000"})); + run(&mut h, "slideshow.playback", json!({"panAndZoom": true, "panAndZoomAmount": 1.0})); + let id = h.app.session.visible_cloned()[0]; + let own = h.app.session.slide_photo_aspect(id).unwrap(); + // 70 px margins around a 860 × 560 cell + for aspect in [860.0 / 560.0, 0.01, 50.0] { + let mut d = (*h.app.session.develop_of(id).expect("settings")).clone(); + d.crop.geometry.rect = if aspect < own { + let f = aspect / own; + lightcraft_geom::Rect::new(0.5 - f / 2.0, 0.0, 0.5 + f / 2.0, 1.0) + } else { + let f = own / aspect; + lightcraft_geom::Rect::new(0.0, 0.5 - f / 2.0, 1.0, 0.5 + f / 2.0) + }; + h.app.session.set_develop(id, d, "Test").expect("edit"); + let shown = h.app.session.slide_photo_aspect(id).unwrap(); + assert!((shown / aspect - 1.0).abs() < 0.01, "{aspect}: the crop shows at {shown}"); + run(&mut h, "library.select", json!({"ids": [id.0]})); + run(&mut h, "view.slideshow", json!({"interval": 60, "fadeDuration": 0, "manual": true, "seed": 3})); + assert_eq!(photo_up(&h), id); + let slot = Slot::Slide(id.into()); + assert!(h.step_until(SETTLE, |h| has_slide(h, id) && h.app.renderer.wanted(slot) == h.app.renderer.textures.get(&slot).map(|t| t.key))); + h.step(); + let s = run(&mut h, "slideshow.togglePause", json!({})); + assert!(s["view"].is_array(), "{aspect}: a manual slideshow holds the photo at its start view: {s}"); + let tex = h.app.renderer.textures.get(&slot).unwrap(); + assert_eq!(tex.size, [1000, 700]); + let v = lightcraft_slideshow::layout(&h.app.session.slide_layout, shown, 1000, 700).visible; + let part = crate::panels::slideshow::moving_part(&h.app, id.into(), tex); + let px = |r: egui::Rect| [r.min.x * 1000.0, r.min.y * 700.0, r.max.x * 1000.0, r.max.y * 700.0]; + for (got, want) in px(part).into_iter().zip([v.x0, v.y0, v.x1, v.y1]) { + assert!((f64::from(got) - want).abs() < 0.01, "{aspect}: moves {part:?}, the photo shows at {v:?}"); + } + if aspect < 1.0 { + assert!(v.width() < 8.0, "{aspect}: a strip of {v:?}"); + } else if aspect > 10.0 { + assert!(v.height() < 20.0, "{aspect}: a strip of {v:?}"); + } else { + assert!((v.width() - 860.0).abs() <= 1.0 && (v.height() - 560.0).abs() <= 1.0, "{aspect}: fills its cell: {v:?}"); + } + let img = h.paint(); + let (cx, cy) = (((v.x0 + v.x1) / 2.0) as usize, ((v.y0 + v.y1) / 2.0) as usize); + assert_ne!(painted(&img, cx, cy), [255, 0, 0], "{aspect}: the photo shows in its part"); + let (x0, y0, x1, y1) = (v.x0 as usize, v.y0 as usize, v.x1 as usize, v.y1 as usize); + // the backdrop just beside the photo stays (away from the top center, where the + // slideshow's controls draw over it) + let (sx, sy) = (if v.width() > 200.0 { x0 + 100 } else { cx }, if v.height() > 200.0 { y0 + 100 } else { cy }); + let mut beside = vec![(x0 - 3, sy), (x1 + 2, sy)]; + if v.width() > 200.0 { + beside.extend([(sx, y0 - 3), (sx, y1 + 2)]); + } + for (x, y) in beside { + assert_eq!(painted(&img, x, y), [255, 0, 0], "{aspect}: backdrop at ({x}, {y})"); + } + // and no backdrop shows inside the photo's edges + if aspect > 1.0 && aspect < 10.0 { + for (x, y) in [(x0 + 3, sy), (x1 - 4, sy), (sx, y0 + 3), (sx, y1 - 4)] { + assert_ne!(painted(&img, x, y), [255, 0, 0], "{aspect}: photo at ({x}, {y})"); + } + } + run(&mut h, "slideshow.end", json!({})); + } + h.settle(SETTLE); +} + /// The amount set on the Low to High slider is saved with the library: the slider writes the /// live value as it moves, which leaves `slideshow.playback` nothing to change when it ends. #[test] From eea0393998ba4e9a5a0aeb60fc25b4f4dc7269de Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 4 Nov 2026 08:14:40 -0800 Subject: [PATCH 08/11] LRC-SS-PLAYBACK: a pan and zoom amount outside 0 to 1 is an error `slideshow.playback` and `view.slideshow` refuse a `panAndZoomAmount` below 0 or above 1 instead of clamping it. A saved value outside the range is still clamped when the library is read. --- crates/engine/src/slideshow.rs | 2 +- crates/engine/src/slideshow/tests.rs | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/slideshow.rs b/crates/engine/src/slideshow.rs index 51f8622a5a..9b14d5708a 100644 --- a/crates/engine/src/slideshow.rs +++ b/crates/engine/src/slideshow.rs @@ -109,7 +109,7 @@ impl PlaybackSettings { "manual" => s.manual = boolean(k, v)?, "panAndZoom" => s.pan_and_zoom = boolean(k, v)?, "panAndZoomAmount" => match v.as_f64() { - Some(x) if x.is_finite() => s.pan_and_zoom_amount = x, + Some(x) if (0.0..=1.0).contains(&x) => s.pan_and_zoom_amount = x, _ => return Err(format!("`{k}` must be a finite number from 0 (low) to 1 (high), not {v}")), }, other => { diff --git a/crates/engine/src/slideshow/tests.rs b/crates/engine/src/slideshow/tests.rs index 8cd1c53887..371434eb90 100644 --- a/crates/engine/src/slideshow/tests.rs +++ b/crates/engine/src/slideshow/tests.rs @@ -293,8 +293,13 @@ fn pan_and_zoom_settings_round_trip_and_are_checked() { let m = d.merged(&json!({"panAndZoom": true, "panAndZoomAmount": 0.8})).unwrap(); assert!(m.pan_and_zoom); assert_eq!((m.to_json()["panAndZoom"].clone(), m.to_json()["panAndZoomAmount"].clone()), (json!(true), json!(0.8))); - assert_eq!(d.merged(&json!({"panAndZoomAmount": 3})).unwrap().pan_and_zoom_amount, 1.0, "clamped"); - assert_eq!(d.merged(&json!({"panAndZoomAmount": -1})).unwrap().pan_and_zoom_amount, 0.0); + for out in [json!(3), json!(-1), json!(1.0001), json!(-0.0001)] { + assert!(d.merged(&json!({"panAndZoomAmount": out})).is_err(), "{out} is outside 0 to 1"); + } + assert_eq!(d.merged(&json!({"panAndZoomAmount": 0})).unwrap().pan_and_zoom_amount, 0.0); + assert_eq!(d.merged(&json!({"panAndZoomAmount": 1})).unwrap().pan_and_zoom_amount, 1.0); + let saved = PlaybackSettings { pan_and_zoom_amount: 3.0, ..d.clone() }.sanitized(); + assert_eq!(saved.pan_and_zoom_amount, 1.0, "a saved value outside the range is clamped when read"); assert!(d.merged(&json!({"panAndZoom": "on"})).is_err()); assert!(d.merged(&json!({"panAndZoomAmount": "high"})).is_err()); let s = PlaybackSettings { pan_and_zoom_amount: f64::NAN, ..d.clone() }.sanitized(); From 19e10be7765dc03fc8496e1abc66b558d03be10e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 12 Nov 2026 09:08:07 -0800 Subject: [PATCH 09/11] LRC-SS-PLAYBACK: test that the pan and zoom amount sets the playback view The test builds playbacks that differ only in pan_and_zoom_amount and checks that Playback::pan_zoom starts and ends on the path for that amount at 0, 0.5 and 1, and that a higher amount zooms in more. --- crates/engine/src/slideshow/tests.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crates/engine/src/slideshow/tests.rs b/crates/engine/src/slideshow/tests.rs index 371434eb90..b0acee1afe 100644 --- a/crates/engine/src/slideshow/tests.rs +++ b/crates/engine/src/slideshow/tests.rs @@ -277,6 +277,15 @@ fn pan_and_zoom_paths_change_each_pass_and_hold_in_a_manual_slideshow() { m.start.zoom.max(m.end.zoom) }; assert!(close(1.0) > close(0.0)); + // the playback view follows the path for its amount + let view = |amount: f64| { + let p = Playback::new(ids(1), None, PlaybackSettings { pan_and_zoom_amount: amount, ..s.clone() }, 9, 0.0).unwrap(); + let m = Motion::new(p.motion_key(ph(1)).unwrap(), amount); + let (a, b) = (p.pan_zoom(0.0).current.unwrap(), p.pan_zoom(100.0).current.unwrap()); + assert_eq!((a, b), (m.at(0.0), m.at(1.0)), "the view at amount {amount} starts and ends on its path"); + a.zoom.max(b.zoom) + }; + assert!(view(1.0) > view(0.5) && view(0.5) > view(0.0), "the amount sets the zoom of the playback view"); // a manual slideshow holds each photo at its start view; ← / → start the next one there let mut p = Playback::new(ids(3), None, PlaybackSettings { manual: true, ..s }, 9, 0.0).unwrap(); let start = Motion::new(p.motion_key(ph(1)).unwrap(), 0.5).start; From fe9266cdff57ee0ca1c7598e73866f92f6ce765e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 17 Nov 2026 18:25:03 -0800 Subject: [PATCH 10/11] Slideshow: pan and zoom draws every frame only once its slide is ready A slide's time starts only when its render is in, so pan and zoom does not move while the slide waits. The slideshow no longer asks for every frame then; it asks for one 16 ms later so the render is taken and shown, and asks for every frame once the slide is ready. --- crates/ui-egui/src/panels/slideshow.rs | 8 +++++- crates/ui-egui/src/tests/slideshow.rs | 40 ++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/panels/slideshow.rs b/crates/ui-egui/src/panels/slideshow.rs index f74ec061d4..442bc3295a 100644 --- a/crates/ui-egui/src/panels/slideshow.rs +++ b/crates/ui-egui/src/panels/slideshow.rs @@ -186,8 +186,14 @@ pub fn tick(app: &mut LightcraftApp, ctx: &egui::Context, now: f64) { after(app, t); let Some(run) = app.ui.slideshow.as_ref() else { return }; let f = run.play.frame(now); - if f.from.is_some() || run.play.pan_zoom_moving(now) { + // A slide's time, and so its pan and zoom, starts only once it is ready: until then the + // next frame comes soon, for the render queue to take the slide and show it. + let shown = ready(app, run.play.current()); + let moving = run.play.pan_zoom_moving(now) && shown; + if f.from.is_some() || moving { ctx.request_repaint(); // a fade, and pan and zoom, draw every frame + } else if !shown { + ctx.request_repaint_after(std::time::Duration::from_millis(16)); } else if !run.play.is_paused() && !run.play.settings().manual { ctx.request_repaint_after(std::time::Duration::from_secs_f64(run.play.remaining(now).clamp(0.016, 120.0))); } diff --git a/crates/ui-egui/src/tests/slideshow.rs b/crates/ui-egui/src/tests/slideshow.rs index f332fb857e..c66c79c14a 100644 --- a/crates/ui-egui/src/tests/slideshow.rs +++ b/crates/ui-egui/src/tests/slideshow.rs @@ -411,6 +411,46 @@ fn pan_and_zoom_moves_an_old_render_whole_until_the_new_one_lands() { h.settle(SETTLE); } +/// A slide's time starts only once its render is in, so while it is held back pan and zoom does +/// not ask for every frame, only for one 16 ms later so the render is taken and shown; once the +/// render lands, every frame is drawn. +#[test] +fn pan_and_zoom_draws_every_frame_only_once_its_slide_is_ready() { + let mut h = grid(); + let open = Rc::new(Cell::new(false)); + h.app.renderer.set_offload(Box::new(RenderGate::new(open.clone()))); + run(&mut h, "slideshow.playback", json!({"panAndZoom": true, "panAndZoomAmount": 1.0})); + run(&mut h, "view.slideshow", json!({"interval": 60, "fadeDuration": 0, "seed": 3})); + let current = photo_up(&h); + let ctx = egui::Context::default(); + let delays = std::sync::Arc::new(std::sync::Mutex::new(Vec::new())); + let seen = delays.clone(); + ctx.set_request_repaint_callback(move |info| seen.lock().unwrap().push(info.delay)); + let raw = egui::RawInput::default(); + let tick = |h: &mut Headless| { + let now = h.time(); + // (the first passes of a context ask for frames at once, which would hide the slideshow's) + for _ in 0..3 { + let _ = ctx.run_logic(&raw, |ctx| crate::panels::slideshow::tick(&mut h.app, ctx, now)); + } + delays.lock().unwrap().clear(); + let _ = ctx.run_logic(&raw, |ctx| crate::panels::slideshow::tick(&mut h.app, ctx, now)); + delays.lock().unwrap().clone() + }; + assert!(!has_slide(&h, current), "the slide's render is held back"); + assert!(play(&h).pan_zoom_moving(h.time()), "the playback counts the slide as moving"); + let got = tick(&mut h); + assert!(!got.contains(&Duration::ZERO), "no frame at once while the slide is not ready: {got:?}"); + // a 60 second slide still asks for a frame soon, for its render to be taken and shown + assert!(got.iter().any(|d| *d <= Duration::from_millis(16)), "a frame soon while the slide is not ready: {got:?}"); + open.set(true); + assert!(h.step_until(SETTLE, |h| has_slide(h, current)), "the render lands"); + let got = tick(&mut h); + assert!(got.contains(&Duration::ZERO), "every frame once it is ready: {got:?}"); + run(&mut h, "slideshow.end", json!({})); + h.settle(SETTLE); +} + /// A photo cropped to its cell's shape, a very narrow one (aspect 0.01) and a very wide one /// (aspect 50): the part that moves is the photo's visible part of the slide, so the backdrop /// beside it stays where it is and the photo still shows inside it. From bd8409cdb42b04c9dd6f4c1d583bb207c30b383e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 17 Nov 2026 19:05:56 -0800 Subject: [PATCH 11/11] Slideshow: pan and zoom moves the strip an extreme crop is composed into The part of a composed slide that pan and zoom moves came from the crop's aspect. The composer lays the photo out at its render's size in whole pixels, at least 1 px a side, so for a very narrow or wide crop the two differ: at aspect 0.001 the crop's aspect gave the whole image cell while the photo was a 1 px strip, and the backdrop in the cell moved with it. A slide job's result now records the size of the photo's render it was composed from (RenderResult::slide_photo, also set by the web build's render workers), the slide's texture keeps it, and moving_part lays the slide out with that size. --- apps/lightcraft-web/src/workers.rs | 5 ++ crates/engine/src/media/quick.rs | 2 + crates/engine/src/media/render.rs | 11 ++++ crates/engine/src/slide_title.rs | 1 + .../ui-egui/examples/thumb_request_bench.rs | 1 + crates/ui-egui/src/panels/slideshow.rs | 9 ++-- crates/ui-egui/src/render.rs | 38 +++++++++++-- crates/ui-egui/src/render/thumbnail_tests.rs | 1 + crates/ui-egui/src/tests/lifecycle_037.rs | 14 ++++- crates/ui-egui/src/tests/slideshow.rs | 53 +++++++++++++++++++ crates/ui-egui/src/tests/zoom.rs | 1 + 11 files changed, 129 insertions(+), 7 deletions(-) diff --git a/apps/lightcraft-web/src/workers.rs b/apps/lightcraft-web/src/workers.rs index 56f7abea4a..40f6252068 100644 --- a/apps/lightcraft-web/src/workers.rs +++ b/apps/lightcraft-web/src/workers.rs @@ -319,6 +319,7 @@ impl Workers { quick: None, display: None, frame: None, + slide_photo: None, }; g.done.push((b.slot, r, 0.0)); } @@ -390,8 +391,10 @@ impl Workers { }); } g.remote_done += 1; + let mut slide_photo = None; let rendered = match (rendered, &b.slide) { (Ok(mut r), Some(slide)) => { + slide_photo = Some([r.image.width, r.image.height]); r.image = slide.compose(&r.image); Ok(r) } @@ -411,6 +414,7 @@ impl Workers { quick: None, display: None, frame: None, + slide_photo, }, ms, )); @@ -466,6 +470,7 @@ impl RenderOffload for Workers { quick: None, display: None, frame: None, + slide_photo: None, }; g.done.push((slot, r, 0.0)); return None; diff --git a/crates/engine/src/media/quick.rs b/crates/engine/src/media/quick.rs index f7163b0693..c3d9047d3f 100644 --- a/crates/engine/src/media/quick.rs +++ b/crates/engine/src/media/quick.rs @@ -59,6 +59,7 @@ impl QuickJob { quick: None, display: None, frame: None, + slide_photo: None, }) } @@ -77,6 +78,7 @@ impl QuickJob { quick, display: None, frame: None, + slide_photo: None, }; let rendered = |image: Rgba8| { let histogram = Histogram::of_srgb8(&image); diff --git a/crates/engine/src/media/render.rs b/crates/engine/src/media/render.rs index af7d10e268..f9c7a2a204 100644 --- a/crates/engine/src/media/render.rs +++ b/crates/engine/src/media/render.rs @@ -91,6 +91,9 @@ pub struct RenderResult { /// The result as a texture on the window's GPU device ([`RenderJob::on_screen`]); `rendered` /// then holds its histogram and an empty image. pub frame: Option, + /// A slide job's result: the size in pixels of the photo's render the slide was composed + /// from, which sets where the slide's layout put the photo ([`RenderJob::with_slide`]). + pub slide_photo: Option<[usize; 2]>, } impl RenderJob { @@ -216,6 +219,7 @@ impl RenderJob { quick: None, display: None, frame: None, + slide_photo: None, } } @@ -235,6 +239,7 @@ impl RenderJob { let slide = self.slide.clone(); let mut r = self.run_photo(); if let (Some(slide), Ok(rendered)) = (slide, r.rendered.as_mut()) { + r.slide_photo = Some([rendered.image.width, rendered.image.height]); rendered.image = slide.compose(&rendered.image); rendered.deep = None; } @@ -291,6 +296,7 @@ impl RenderJob { quick: Some(QuickSource::Cached), display: None, frame: None, + slide_photo: None, }; } if let Some((cache, key)) = &self.cache @@ -310,6 +316,7 @@ impl RenderJob { quick: None, display: None, frame: None, + slide_photo: None, }; } // a face tile of an unedited raw: cut from the camera's embedded preview when it is big enough @@ -331,6 +338,7 @@ impl RenderJob { quick: None, display: None, frame: None, + slide_photo: None, }; } let was_loaded = matches!(self.source, SourceRef::Loaded(_)); @@ -369,6 +377,7 @@ impl RenderJob { quick: None, display: None, frame: None, + slide_photo: None, }; } let pixels_needed = @@ -393,6 +402,7 @@ impl RenderJob { quick: None, display: None, frame: Some(frame), + slide_photo: None, }; } Some(OnScreen::Pixels(r)) => (r, None), @@ -453,6 +463,7 @@ impl RenderJob { quick: None, display, frame: None, + slide_photo: None, } } Err(e) => self.failed(e), diff --git a/crates/engine/src/slide_title.rs b/crates/engine/src/slide_title.rs index 0acda876d1..e59e61fe13 100644 --- a/crates/engine/src/slide_title.rs +++ b/crates/engine/src/slide_title.rs @@ -364,6 +364,7 @@ impl TitleCompose { display: None, gpu_fallback: None, frame: None, + slide_photo: None, } } } diff --git a/crates/ui-egui/examples/thumb_request_bench.rs b/crates/ui-egui/examples/thumb_request_bench.rs index 980434b317..728059b0e3 100644 --- a/crates/ui-egui/examples/thumb_request_bench.rs +++ b/crates/ui-egui/examples/thumb_request_bench.rs @@ -124,6 +124,7 @@ fn micro(points: usize, pending: bool) { quick: None, pixels: None, native: None, + slide_photo: None, }, ); } diff --git a/crates/ui-egui/src/panels/slideshow.rs b/crates/ui-egui/src/panels/slideshow.rs index 442bc3295a..351b8d531c 100644 --- a/crates/ui-egui/src/panels/slideshow.rs +++ b/crates/ui-egui/src/panels/slideshow.rs @@ -284,8 +284,9 @@ fn slide_texture(app: &LightcraftApp, id: PhotoId) -> Option<&crate::render::Tex /// photo's visible part of a composed slide without overlays (its image cell), else all of it (a /// photo drawn on its own, a plain slide or a stand-in, and a slide with overlays, which are /// drawn into its texture and can cross the cell's edge: they move with the slide). The cell -/// comes from the current settings, so a texture rendered with older ones (its new render still -/// on the way) also moves whole. +/// comes from the current settings and the size of the photo's render the slide was composed +/// from, so a texture rendered with older settings (its new render still on the way) also moves +/// whole. pub(crate) fn moving_part(app: &LightcraftApp, item: Item, t: &crate::render::Tex) -> Rect { let Item::Photo(id) = item else { return full_uv() }; let composed = !app.session.slides_plain() @@ -293,7 +294,9 @@ pub(crate) fn moving_part(app: &LightcraftApp, item: Item, t: &crate::render::Te && slide_texture(app, id).is_some_and(|s| std::ptr::eq(s, t)) && app.renderer.is_current(Slot::Slide(item), t.key); let [w, h] = t.size; - let Some(aspect) = app.session.slide_photo_aspect(id).filter(|_| composed && w > 0 && h > 0) else { return full_uv() }; + let photo = t.slide_photo.filter(|[pw, ph]| composed && w > 0 && h > 0 && *pw > 0 && *ph > 0); + let Some([pw, ph]) = photo else { return full_uv() }; + let aspect = pw as f64 / ph as f64; let v = lightcraft_slideshow::layout(&app.session.slide_layout, aspect, w, h).visible; let (w, h) = (w as f64, h as f64); let uv = Rect::from_min_max(pos2((v.x0 / w) as f32, (v.y0 / h) as f32), pos2((v.x1 / w) as f32, (v.y1 / h) as f32)); diff --git a/crates/ui-egui/src/render.rs b/crates/ui-egui/src/render.rs index a2eb3bf342..6b09bc89d3 100644 --- a/crates/ui-egui/src/render.rs +++ b/crates/ui-egui/src/render.rs @@ -102,6 +102,9 @@ pub struct Tex { pub pixels: Option>, /// Showing a render that stayed on the GPU ([`ScreenTextures`]): drawn by this id instead of `tex`. pub native: Option, + /// A composed slide's photo: the size of the render the slide was laid out with + /// ([`RenderResult::slide_photo`]). + pub slide_photo: Option<[usize; 2]>, } impl Tex { @@ -1333,13 +1336,25 @@ impl Renderer { t.histogram = Some(histogram); t.ms = ms; t.quick = None; + t.slide_photo = r.slide_photo; } None => { // (`tex` is never drawn while `native` is set) let blank = egui::ColorImage::filled([1, 1], egui::Color32::BLACK); let tex = ctx.load_texture(format!("{slot:?}"), blank, egui::TextureOptions::LINEAR); - let t = - Tex { look, key: r.key, photo: r.photo, tex, size, histogram: Some(histogram), ms, quick: None, pixels: None, native: Some(id) }; + let t = Tex { + look, + key: r.key, + photo: r.photo, + tex, + size, + histogram: Some(histogram), + ms, + quick: None, + pixels: None, + native: Some(id), + slide_photo: r.slide_photo, + }; self.textures.insert(slot, t); } } @@ -1479,6 +1494,7 @@ impl Renderer { t.histogram = Some(rendered.histogram); t.ms = ms; t.quick = r.quick; + t.slide_photo = r.slide_photo; } None => { let tex = ctx.load_texture(name, color, egui::TextureOptions::LINEAR); @@ -1495,6 +1511,7 @@ impl Renderer { quick: r.quick, pixels, native: None, + slide_photo: r.slide_photo, }, ); } @@ -1767,7 +1784,19 @@ mod stage_budget_tests { let tex = ctx.load_texture("window", egui::ColorImage::new([1, 1], vec![egui::Color32::BLACK]), Default::default()); r.textures.insert( Slot::Region, - Tex { look: None, key: 1, photo: PhotoId(1), tex, native: None, size: [1, 1], histogram: None, ms: 0.0, quick: None, pixels: None }, + Tex { + look: None, + key: 1, + photo: PhotoId(1), + tex, + native: None, + size: [1, 1], + histogram: None, + ms: 0.0, + quick: None, + pixels: None, + slide_photo: None, + }, ); let long_ago = std::time::Instant::now().checked_sub(IDLE_TRIM * 2).unwrap(); r.idle = Some((long_ago, false)); @@ -1797,6 +1826,7 @@ mod stage_budget_tests { ms: 0.0, quick: None, pixels: None, + slide_photo: None, }; r.textures.insert(Slot::Before, view(tex("before"), Some(egui::TextureId::User(7)))); r.textures.insert(Slot::Compare(0), view(tex("compare"), Some(egui::TextureId::User(8)))); @@ -1824,6 +1854,7 @@ mod stage_budget_tests { ms: 0.0, quick: None, pixels: Some(std::sync::Arc::new(egui::ColorImage::new([1, 1], vec![egui::Color32::BLACK]))), + slide_photo: None, }; t.show_native(egui::TextureId::User(7)); assert_eq!(t.tex.size(), [1, 1], "the pixel image is released"); @@ -1953,6 +1984,7 @@ mod color_image_tests { quick: None, display: None, frame: None, + slide_photo: None, }; let histogram = Histogram::of_srgb8(&image); let ok = Renderer::run_for(|| result(Ok(lightcraft_pipeline::Rendered { image: image.clone(), histogram, deep: None })), &None); diff --git a/crates/ui-egui/src/render/thumbnail_tests.rs b/crates/ui-egui/src/render/thumbnail_tests.rs index b2a87e6522..db99ed5b22 100644 --- a/crates/ui-egui/src/render/thumbnail_tests.rs +++ b/crates/ui-egui/src/render/thumbnail_tests.rs @@ -330,6 +330,7 @@ fn larger_texture_for_another_key_does_not_count_as_current() { quick: None, pixels: None, native: None, + slide_photo: None, }; let mut r = Renderer::default(); // A completed larger bucket: the remembered request is bucket 512, key 77. diff --git a/crates/ui-egui/src/tests/lifecycle_037.rs b/crates/ui-egui/src/tests/lifecycle_037.rs index e29946baa2..052f410169 100644 --- a/crates/ui-egui/src/tests/lifecycle_037.rs +++ b/crates/ui-egui/src/tests/lifecycle_037.rs @@ -609,7 +609,19 @@ fn hidden_slideshow_pauses_and_keeps_its_remaining_time() { let tex = ctx.load_texture(format!("slide-{}", id.0), egui::ColorImage::filled([2, 2], egui::Color32::WHITE), Default::default()); app.renderer.textures.insert( Slot::Slide(Item::Photo(id)), - Tex { look: None, key: 0, photo: id, tex, native: None, size: [2, 2], histogram: None, ms: 0.0, quick: None, pixels: None }, + Tex { + look: None, + key: 0, + photo: id, + tex, + native: None, + size: [2, 2], + histogram: None, + ms: 0.0, + quick: None, + pixels: None, + slide_photo: None, + }, ); } let first = app.ui.slideshow.as_ref().unwrap().play.current(); diff --git a/crates/ui-egui/src/tests/slideshow.rs b/crates/ui-egui/src/tests/slideshow.rs index be277fe1f1..6d90cf6848 100644 --- a/crates/ui-egui/src/tests/slideshow.rs +++ b/crates/ui-egui/src/tests/slideshow.rs @@ -522,6 +522,59 @@ fn pan_and_zoom_moves_only_the_visible_photo_at_any_aspect() { h.settle(SETTLE); } +/// A crop so narrow (aspect 0.001) or so wide (aspect 1000) that the photo's render is 1 px +/// across: the slide is laid out with that render's size, not the crop's aspect, so the part that +/// moves is the strip of the slide the photo was composed into, not the whole cell around it. +#[test] +fn pan_and_zoom_moves_the_composed_strip_of_an_extreme_crop() { + let mut h = grid(); + h.app.renderer.keep_pixels = true; + run(&mut h, "slideshow.layout", json!({"margins": 0.1, "backdropColor": "#ff0000"})); + run(&mut h, "slideshow.playback", json!({"panAndZoom": true, "panAndZoomAmount": 1.0})); + let id = h.app.session.visible_cloned()[0]; + let own = h.app.session.slide_photo_aspect(id).unwrap(); + for aspect in [0.001, 1000.0] { + let mut d = (*h.app.session.develop_of(id).expect("settings")).clone(); + d.crop.geometry.rect = if aspect < own { + let f = aspect / own; + lightcraft_geom::Rect::new(0.5 - f / 2.0, 0.0, 0.5 + f / 2.0, 1.0) + } else { + let f = own / aspect; + lightcraft_geom::Rect::new(0.0, 0.5 - f / 2.0, 1.0, 0.5 + f / 2.0) + }; + h.app.session.set_develop(id, d, "Test").expect("edit"); + run(&mut h, "library.select", json!({"ids": [id.0]})); + run(&mut h, "view.slideshow", json!({"interval": 60, "fadeDuration": 0, "manual": true, "seed": 3})); + assert_eq!(photo_up(&h), id); + let slot = Slot::Slide(id.into()); + assert!(h.step_until(SETTLE, |h| has_slide(h, id) && h.app.renderer.wanted(slot) == h.app.renderer.textures.get(&slot).map(|t| t.key))); + h.step(); + let tex = h.app.renderer.textures.get(&slot).unwrap(); + assert_eq!(tex.size, [1000, 700]); + // where the photo is in the composed slide: every pixel that is not the red backdrop + let px = tex.pixels.as_ref().expect("the slide's pixels"); + let [w, rows] = px.size; + let (mut x0, mut y0, mut x1, mut y1) = (w, rows, 0, 0); + for y in 0..rows { + for x in 0..w { + let c = px.pixels[y * w + x]; + if !(c.r() > 240 && c.g() < 15 && c.b() < 15) { + (x0, y0, x1, y1) = (x0.min(x), y0.min(y), x1.max(x + 1), y1.max(y + 1)); + } + } + } + assert!(x1 > x0 && y1 > y0, "{aspect}: the photo shows in the slide"); + assert!((x1 - x0).min(y1 - y0) <= 2, "{aspect}: a strip of {x0}..{x1} × {y0}..{y1}"); + let part = crate::panels::slideshow::moving_part(&h.app, id.into(), tex); + let got = [part.min.x * 1000.0, part.min.y * 700.0, part.max.x * 1000.0, part.max.y * 700.0]; + for (g, want) in got.into_iter().zip([x0, y0, x1, y1]) { + assert!((g - want as f32).abs() <= 1.0, "{aspect}: moves {got:?}, the photo is at {:?}", [x0, y0, x1, y1]); + } + run(&mut h, "slideshow.end", json!({})); + } + h.settle(SETTLE); +} + /// The amount set on the Low to High slider is saved with the library: the slider writes the /// live value as it moves, which leaves `slideshow.playback` nothing to change when it ends. #[test] diff --git a/crates/ui-egui/src/tests/zoom.rs b/crates/ui-egui/src/tests/zoom.rs index 518bd477af..5253d40a3e 100644 --- a/crates/ui-egui/src/tests/zoom.rs +++ b/crates/ui-egui/src/tests/zoom.rs @@ -81,6 +81,7 @@ fn a_pending_crop_or_rotation_does_not_reuse_the_old_textures_aspect() { ms: 0.0, quick: None, pixels: None, + slide_photo: None, }, ); edit(&mut h, |d| d.crop.geometry.rect = lightcraft_geom::Rect::new(0.25, 0.2, 0.75, 0.2 + 1.0 / 3.0));