LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
LR-CROP-RECT: the source level is sized from the bounded crop (#2555)
insideTheFluxf860577c5100
diff --git a/crates/engine/src/media/source.rs b/crates/engine/src/media/source.rsindex 51c54c60a..308ca24c1 100644--- a/crates/engine/src/media/source.rs+++ b/crates/engine/src/media/source.rs@@ -59,9 +59,12 @@ impl SourceLevel {/// Pixels along the source's long edge that an output `out_long` pixels long needs: a crop shows/// only part of the photo, so its pixels come from a source that many times larger (the source/// level is chosen from this, or a tight crop shown at its own pixels would be a stretched preview).+/// The crop is bounded as the render bounds it (issue #2555), so one reaching far past the photo+/// doesn't pick a source too small for the frame it renders.pub(super) fn source_edge_needed(p: &Photo, settings: &DevelopSettings, apply_crop: bool, out_long: usize) -> usize {let (w, h) = (f64::from(p.width.max(1)), f64::from(p.height.max(1)));- let r = settings.crop.geometry.rect;+ let (ow, oh) = if settings.orientation.swaps_axes() { (h, w) } else { (w, h) };+ let r = settings.crop.geometry.bounded(ow, oh).rect;let shown = if apply_crop { (r.width() * w).max(r.height() * h) } else { w.max(h) };if !shown.is_finite() || shown < 1.0 {return out_long;diff --git a/crates/engine/src/media/tests.rs b/crates/engine/src/media/tests.rsindex d36284262..8eec0fd03 100644--- a/crates/engine/src/media/tests.rs+++ b/crates/engine/src/media/tests.rs@@ -368,6 +368,54 @@ fn a_tight_crop_reads_the_source_level_its_pixels_need() {assert_eq!(s.render_job(id, 600, 600, false, true).unwrap().level, SourceLevel::Preview);}+// Issue #2555: a turned crop reaching far past the photo (from a sidecar or an agent) is rendered+// bounded to the turned photo, so its source is sized from that bounded crop: shown 1600 px long it+// needs the preview, not the 512 px thumbnail its rect of 1000 photos across asked for+#[test]+fn a_crop_far_past_the_photo_reads_the_source_its_bounded_frame_needs() {+ let mut s = crate::Session::with_demo();+ let id = s.catalog.photos().next().unwrap().id;+ let wild = lightcraft_geom::CropGeometry { rect: lightcraft_geom::Rect::new(0.0, 0.0, 1000.0, 1000.0), angle: 5.0 };+ let mut d = (*s.develop_of(id).unwrap()).clone();+ d.crop.geometry = wild;+ s.set_develop(id, d, "Crop").unwrap();+ assert_eq!(s.render_job(id, 1600, 1600, false, true).unwrap().level, SourceLevel::Preview);+ // bounded in the frame the render bounds it in: the photo's own, or turned a quarter+ let p = s.catalog.photo(id).unwrap().clone();+ let (w, h) = (f64::from(p.width), f64::from(p.height));+ assert_ne!(w, h, "a square photo can't tell the two frames apart");+ for orientation in [lightcraft_geom::Orientation::Normal, lightcraft_geom::Orientation::Rotate90] {+ let (ow, oh) = if orientation.swaps_axes() { (h, w) } else { (w, h) };+ let mut d = lightcraft_develop::DevelopSettings { orientation, ..Default::default() };+ d.crop.geometry = wild;+ let r = wild.bounded(ow, oh).rect;+ let expected = (1600.0 * w.max(h) / (r.width() * w).max(r.height() * h)) as usize;+ assert_eq!(super::source::source_edge_needed(&p, &d, true, 1600), expected, "{orientation:?}");+ }+}++// …while every crop the crop tools make, turned or not, on a photo shown upright or turned a+// quarter, still asks for exactly the source its own rect needs+#[test]+fn crops_on_the_photo_keep_the_source_size_they_need() {+ use lightcraft_geom::{Orientation, crop_fit_angle};+ let s = crate::Session::with_demo();+ let p = s.catalog.photos().next().unwrap().clone();+ let (w, h) = (f64::from(p.width), f64::from(p.height));+ for orientation in [Orientation::Normal, Orientation::Rotate90] {+ let (ow, oh) = if orientation.swaps_axes() { (h, w) } else { (w, h) };+ for angle in [-45.0, -12.5, 0.0, 7.0, 45.0] {+ for aspect in [None, Some(1.0), Some(3.0), Some(0.25)] {+ let mut d = lightcraft_develop::DevelopSettings { orientation, ..Default::default() };+ d.crop.geometry = crop_fit_angle(ow, oh, angle, aspect);+ let r = d.crop.geometry.rect;+ let expected = (1600.0 * w.max(h) / (r.width() * w).max(r.height() * h)) as usize;+ assert_eq!(super::source::source_edge_needed(&p, &d, true, 1600), expected, "{orientation:?} {angle} {aspect:?}");+ }+ }+ }+}+// a window whose spot reads from further away than a render can hold is refused#[test]fn a_region_job_is_refused_when_a_spot_reads_beyond_what_fits() {