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));