diff options
| author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2026-10-28 09:23:46 +0100 |
|---|---|---|
| committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2026-10-28 10:34:53 +0100 |
| commit | 11689fb14f3a4d0291e2ccc05d6cb3556e4ea1ab (patch) | |
| tree | 4ffabbb3e395e4cf0c9930d10f9beaa055fbcae0 /crates/gipfel-core/src | |
| parent | aab6af1601fa4cdb9b351987220f32de062d4b2c (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 in both apps 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)
Diffstat (limited to 'crates/gipfel-core/src')
| -rw-r--r-- | crates/gipfel-core/src/metadata.rs | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/crates/gipfel-core/src/metadata.rs b/crates/gipfel-core/src/metadata.rs index f55bf1c..9d73a8d 100644 --- a/crates/gipfel-core/src/metadata.rs +++ b/crates/gipfel-core/src/metadata.rs @@ -25,6 +25,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, } @@ -44,6 +48,7 @@ impl Default for ImageMetaData { x0: NAN, focal_length: NAN, focal_length_35mm: NAN, + focal_from_comment: false, projection_type: 0, } } @@ -147,6 +152,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 @@ -548,13 +554,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: @@ -721,4 +734,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); + } } |
