mirror of
https://github.com/storytold/lightcraft.git
synced 2026-11-01 14:07:34 -06:00
LR-CROP-AUTO: Auto straighten builds the analysis image once
From CodeRabbit's review of #2809: on a cache miss, `level_degrees` built the analysis plane for the horizon and `analyze_source` built it again for the segments. `analyze_cached` now takes the plane `level_degrees` already has; other callers of `analyze_source` are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
6d569719b6
commit
583deac156
@@ -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).
|
||||
|
||||
Reference in New Issue
Block a user