summaryrefslogtreecommitdiff
path: root/crates/gipfel-core
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2026-10-28 10:35:03 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2026-10-28 10:35:03 +0100
commit8a4fea421c5a1701889b42bd5100d70999709c40 (patch)
treed853a88967a9e6f31fbb8b321f7e44f1b2387891 /crates/gipfel-core
parent6e38ef31467a85edc2aff0a1b6889a417f5ef20f (diff)
core: fix focal-length-to-scale constant (36 mm film width, not 35)
The 35mm film frame is 36 mm wide, so a lens with 35mm-equivalent focal length f projects with focal length f*w/36 in pixels. The original C++ code divided by 35, making the EXIF-derived initial scale ~2.9% too large (and the fitted focal readout ~2.9% low). - EXIF init and the focal slider/readout now use /36 - the gipfel JPEG comment KEEPS its historical scale*35/w encoding (focal_from_comment flag), so annotated JPEGs written by any older gipfel version still reproduce the identical view, and files saved by this version remain readable by them - new regression test focal_scale_exif_vs_comment; golden tests untouched (they pin the comment path) Verified against real photos: optical shots now agree with EXIF within ~1% (was ~3.6%).
Diffstat (limited to 'crates/gipfel-core')
-rw-r--r--crates/gipfel-core/src/metadata.rs36
1 files changed, 33 insertions, 3 deletions
diff --git a/crates/gipfel-core/src/metadata.rs b/crates/gipfel-core/src/metadata.rs
index e2a888f..9da4f50 100644
--- a/crates/gipfel-core/src/metadata.rs
+++ b/crates/gipfel-core/src/metadata.rs
@@ -28,6 +28,10 @@ pub struct ImageMetaData {
pub x0: f64,
pub focal_length: f64,
pub focal_length_35mm: f64,
+ /// true when focal_length_35mm came from a gipfel JPEG comment rather
+ /// than EXIF; the comment uses a legacy scale encoding (see
+ /// apply_image_metadata)
+ pub focal_from_comment: bool,
pub projection_type: i32,
}
@@ -47,6 +51,7 @@ impl Default for ImageMetaData {
x0: NAN,
focal_length: NAN,
focal_length_35mm: NAN,
+ focal_from_comment: false,
projection_type: 0,
}
}
@@ -134,6 +139,7 @@ impl ImageMetaData {
self.pitch = pit.unwrap();
self.roll = rol.unwrap();
self.focal_length_35mm = fr.unwrap();
+ self.focal_from_comment = true;
self.projection_type = pt;
// n >= 10: k0 and k1 were matched; x0 defaults to 0.0 when only 10
@@ -521,13 +527,20 @@ pub fn apply_image_metadata(
pan.set_roll_angle(md.roll);
}
- // set_focal_length_35mm: scale = fl * max(w, h) / 35
+ // scale = f35 * w / 36: the 35mm film frame is 36 mm wide, so a lens
+ // with 35mm-equivalent focal length f projects with focal length
+ // f * w / 36 in pixels. Exception: the gipfel JPEG comment has always
+ // encoded the focal as scale * 35 / w, so that legacy encoding is
+ // kept for comments to reproduce identical views with annotated
+ // JPEGs written by older gipfel versions.
let w = img_w.max(img_h);
if md.focal_length_35mm.is_nan() || md.focal_length_35mm == 0.0 {
- pan.set_scale(35.0 * w as f64 / 35.0);
+ pan.set_scale(35.0 * w as f64 / 36.0);
have_info = false;
- } else {
+ } else if md.focal_from_comment {
pan.set_scale(md.focal_length_35mm * w as f64 / 35.0);
+ } else {
+ pan.set_scale(md.focal_length_35mm * w as f64 / 36.0);
}
// distortion parameters, C ordering:
@@ -694,4 +707,21 @@ mod tests {
}
let _ = std::fs::remove_dir_all(&dir);
}
+
+ #[test]
+ fn focal_scale_exif_vs_comment() {
+ // EXIF 35mm-equivalent focal: scale = f * w / 36 (film width)
+ let mut md = ImageMetaData::new();
+ md.focal_length_35mm = 50.0;
+ let mut pan = crate::panorama::Panorama::new();
+ apply_image_metadata(&mut pan, &md, 1000, 800);
+ assert!((pan.get_scale() - 50.0 * 1000.0 / 36.0).abs() < 1e-9);
+
+ // gipfel comment: legacy encoding scale = f * w / 35, kept so
+ // annotated JPEGs from older versions reproduce the same view
+ md.focal_from_comment = true;
+ let mut pan = crate::panorama::Panorama::new();
+ apply_image_metadata(&mut pan, &md, 1000, 800);
+ assert!((pan.get_scale() - 50.0 * 1000.0 / 35.0).abs() < 1e-9);
+ }
}