Skip to content

LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust

LR-CROP-AUTO: Auto straighten builds the analysis image once

ingolfteetz583deac15635
diff --git a/crates/pipeline/src/upright.rs b/crates/pipeline/src/upright.rs
index a0b3cc0e6..f90bd2c4a 100644
--- a/crates/pipeline/src/upright.rs
+++ b/crates/pipeline/src/upright.rs
@@ -546,6 +546,12 @@ const ANALYSIS_LONG: usize = 1024;
/// Analyse a source: the lens-corrected (optics applied, no perspective/crop) image at [`ANALYSIS_LONG`] px,
/// segment detection and vanishing points. Cached per source + optics settings.
pub fn analyze_source(src: &Rgb32f, info: &SourceInfo, s: &DevelopSettings) -> Analysis {
+ analyze_cached(src, info, s, None)
+}
+
+/// [`analyze_source`], reading `plane` (the [`analysis_plane`] of the same source and settings) on a
+/// cache miss instead of building it again.
+fn analyze_cached(src: &Rgb32f, info: &SourceInfo, s: &DevelopSettings, plane: Option<&Plane>) -> Analysis {
static CACHE: Mutex<Vec<(u64, Analysis)>> = Mutex::new(Vec::new());
let key = crate::optics::fingerprint(src)
^ lightcraft_develop::DevelopSettings { optics: s.optics, orientation: s.orientation, ..Default::default() }.hash64().rotate_left(17);
@@ -554,7 +560,10 @@ pub fn analyze_source(src: &Rgb32f, info: &SourceInfo, s: &DevelopSettings) -> A
{
return a.clone();
}
- let a = analyze(&detect_segments(&analysis_plane(src, info, s)));
+ let a = match plane {
+ Some(p) => analyze(&detect_segments(p)),
+ None => analyze(&detect_segments(&analysis_plane(src, info, s))),
+ };
if let Ok(mut c) = CACHE.lock() {
c.push((key, a.clone()));
if c.len() > 8 {
@@ -583,7 +592,8 @@ pub(crate) fn analysis_plane(src: &Rgb32f, info: &SourceInfo, s: &DevelopSetting
/// The crop angle (degrees, clockwise +) Auto straighten levels `src` by, if it finds a horizon or
/// plumb lines it can trust ([`crate::straighten`]). Used by the crop panel's Auto straighten.
pub fn level_degrees(src: &Rgb32f, info: &SourceInfo, s: &DevelopSettings) -> Option<f64> {
- crate::straighten::decide(&analysis_plane(src, info, s), &analyze_source(src, info, s))
+ let plane = analysis_plane(src, info, s);
+ crate::straighten::decide(&plane, &analyze_cached(src, info, s, Some(&plane)))
}
/// The automatic Upright correction for `mode` on `src` (identity for Off and Guided).