Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Merge PR #7665: File Info: print a slow shutter speed as the fraction a camera writes

aiongge1492a75f436
diff --cc crates/engine/src/file_cmds.rs
index 0bb2b7892,e86e4252a..708af16f2
--- a/crates/engine/src/file_cmds.rs
+++ b/crates/engine/src/file_cmds.rs
@@@ -810,10 -777,18 +822,18 @@@ fn exposure_text(t: f64) -> Option<Stri
return None;
}
let r = 1.0 / t;
- if t < 1.0 && r.round() > 1.0 && (r - r.round()).abs() <= r * 0.01 {
- return Some(format!("1/{} s", r.round()));
- }
- Some(format!("{} s", short_num(t, if t < 1.0 { 2 } else { 1 })))
+ let n = r.round();
+ // Below 1/10 s the reciprocal is above 10, so its nearest whole number puts the shown time
+ // within 5 % of the stored one, and is the form a photographer expects ("1/32 s"). The test
+ // used to be relative to the reciprocal, so it shrank as the exposure slowed: under 1/50 s it
+ // fell below half a rounding step and nearly every fraction fell through to the decimal form
+ // (#6958). Above 1/10 s the fraction is only right when the reciprocal is very nearly whole
+ // (1/2 s, 1/4 s) — 0.4 s stays "0.4 s" rather than becoming "1/3 s".
- let fraction = n.is_finite() && (1.0..=1e9).contains(&n) && (t < 0.1 || (t < 1.0 && (r - n).abs() <= r * 0.01));
++ let fraction = n.is_finite() && (1.0..=1e9).contains(&n) && (t < 0.1 || (t < 1.0 && n > 1.0 && (r - n).abs() <= r * 0.01));
+ if fraction {
+ return Some(format!("1/{} s", n as u64));
+ }
+ Some(format!("{} s", sig3(t)))
}
/// EXIF (`2024:02:17 12:40:19`) or XMP (`2024-02-17T12:40:19.00+01:00`) dates as