mirror of
https://github.com/storytold/lightcraft.git
synced 2026-11-28 09:19:25 +01:00
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.
This commit is contained in:
1 parent
5b201a945d
commit
bd8409cdb4
11 files changed
+129
-7
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<ScreenFrame>,
|
||||
/// 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),
|
||||
|
||||
@@ -364,6 +364,7 @@ impl TitleCompose {
|
||||
display: None,
|
||||
gpu_fallback: None,
|
||||
frame: None,
|
||||
slide_photo: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,6 +124,7 @@ fn micro(points: usize, pending: bool) {
|
||||
quick: None,
|
||||
pixels: None,
|
||||
native: None,
|
||||
slide_photo: None,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -102,6 +102,9 @@ pub struct Tex {
|
||||
pub pixels: Option<std::sync::Arc<egui::ColorImage>>,
|
||||
/// Showing a render that stayed on the GPU ([`ScreenTextures`]): drawn by this id instead of `tex`.
|
||||
pub native: Option<egui::TextureId>,
|
||||
/// 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);
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in new issue
Block a user