Merge pull request #1692 from FredApps/fix/1619-shutter-precision

Preserve shutter precision through import and export (#1619)
This commit is contained in:
FredApps
2026-11-14 16:22:29 +01:00
committed by GitHub
14 changed files with 322 additions and 25 deletions
+38 -1
View File
@@ -180,7 +180,13 @@ pub struct Meta {
pub lens_make: String,
pub focal_mm: Option<f32>,
pub aperture: Option<f32>,
/// Shutter speed for display, from [`lightcraft_meta::format_exposure_time`] (`1/3`, `0.3571`, `2.5`).
pub shutter: String,
/// The file's exact exposure time in seconds, kept beside the rounded `shutter` text so export
/// writes the original duration; read through [`Meta::shutter_seconds`]. Left out of the catalog
/// JSON when unknown, so older catalogs read unchanged.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub exposure_time: Option<f64>,
pub iso: Option<u32>,
/// Whether the flash fired, from Exif `Flash`.
#[serde(default, skip_serializing_if = "Option::is_none")]
@@ -224,6 +230,16 @@ pub struct Meta {
pub focus: Option<lightcraft_meta::FocusPoint>,
}
impl Meta {
/// Shutter speed in seconds: the exact [`Meta::exposure_time`] while `shutter` still shows it,
/// otherwise whatever `shutter` says (set by hand, or a catalog from before the exact time was kept).
pub fn shutter_seconds(&self) -> Option<f64> {
self.exposure_time
.filter(|t| lightcraft_meta::format_exposure_time(*t).is_some_and(|text| text == self.shutter.trim()))
.or_else(|| parse_shutter_seconds(&self.shutter))
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Version {
pub name: String,
@@ -761,7 +777,28 @@ mod edited_tests {
#[cfg(test)]
mod shutter_tests {
use super::parse_shutter_seconds;
use super::*;
#[test]
fn shutter_seconds_prefers_the_exact_time_while_the_text_still_shows_it() {
let mut m = Meta { shutter: "0.3571".into(), exposure_time: Some(1.0 / 2.8), ..Default::default() };
assert_eq!(m.shutter_seconds(), Some(1.0 / 2.8));
m.shutter = "1/3".into();
m.exposure_time = Some(1.0 / 3.0);
assert_eq!(m.shutter_seconds(), Some(1.0 / 3.0));
// the text no longer matches the stored time (edited elsewhere): the text wins
m.shutter = "1/250".into();
assert_eq!(m.shutter_seconds(), Some(1.0 / 250.0));
// an older catalog without the exact time
m.exposure_time = None;
m.shutter = "2.5".into();
assert_eq!(m.shutter_seconds(), Some(2.5));
// the exact time stays out of the JSON when unknown, and round-trips when known
assert!(!serde_json::to_string(&m).unwrap().contains("exposure_time"));
m.exposure_time = Some(2.5);
let back: Meta = serde_json::from_str(&serde_json::to_string(&m).unwrap()).unwrap();
assert_eq!(back.exposure_time, Some(2.5));
}
#[test]
fn a_fraction_needs_a_positive_numerator_and_denominator() {
+2
View File
@@ -1100,6 +1100,8 @@ impl Rule {
"captureDate" => date_op(op, p.captured.as_deref(), value),
"importDate" => date_op(op, Some(&p.imported), value),
"editDate" => date_op(op, p.edited.as_deref(), value),
// (the shown shutter text, not the exact time kept for export: a rule matches the value the
// photo shows, `1/3` or `0.3571`, at every op, including `is` and the edges of a range)
"shutterSpeed" => num_op(op, crate::parse_shutter_seconds(&m.shutter), &shutter_value(value)),
"iso" => num_op(op, m.iso.map(|v| v as f64), value),
"flash" => yes(m.flash.unwrap_or(false)),
+16
View File
@@ -795,3 +795,19 @@ fn file_path_contains_finds_every_piece_of_a_long_path() {
}
}
}
#[test]
fn shutter_speed_rules_match_the_shown_value() {
let cat = Catalog::new();
let mut p = photo(1);
let m =
|p: &Photo, op: &str, value: serde_json::Value| rs(json!({"rules": [{"field": "shutterSpeed", "op": op, "value": value}]})).matches(p, &cat);
p.meta.exposure_time = Some(1.0 / 2.8);
p.meta.shutter = "0.3571".into();
assert!(m(&p, "is", json!("0.3571")) && !m(&p, "isNot", json!("0.3571")), "1/2.8 s is the 0.3571 it shows");
assert!(m(&p, "lte", json!("0.3571")) && m(&p, "gte", json!("0.3571")));
p.meta.exposure_time = Some(3333.0 / 10000.0);
p.meta.shutter = "1/3".into();
assert!(m(&p, "is", json!("1/3")) && !m(&p, "isNot", json!("1/3")), "3333/10000 s is the 1/3 it shows");
assert!(m(&p, "gte", json!("1/3")) && m(&p, "lte", json!("1/3")) && !m(&p, "lt", json!("1/3")));
}
+1 -1
View File
@@ -260,7 +260,7 @@ impl Catalog {
.filter(|p| !p.deleted && !merged(p))
.filter_map(|p| {
let t = iso_seconds(p.captured.as_deref()?)?;
let s = crate::model::parse_shutter_seconds(&p.meta.shutter)?;
let s = p.meta.shutter_seconds()?;
let n = p.meta.aperture.filter(|n| n.is_finite() && *n > 0.0).unwrap_or(1.0) as f64;
let iso = p.meta.iso.filter(|i| *i > 0).unwrap_or(100) as f64;
Some((t, p.file_name.as_str(), p.id, s, (s * iso / (n * n)).log2()))
+105 -2
View File
@@ -241,6 +241,9 @@ fn fill_missing_meta(id: lightcraft_catalog::PhotoId, ph: &lightcraft_catalog::P
}
if m.shutter.is_empty() {
m.shutter = src.shutter.clone();
m.exposure_time = src.exposure_time;
} else {
repair_legacy_shutter(&mut m, src);
}
m.focal_mm = m.focal_mm.or(src.focal_mm);
m.aperture = m.aperture.or(src.aperture);
@@ -265,6 +268,26 @@ fn fill_missing_meta(id: lightcraft_catalog::PhotoId, ph: &lightcraft_catalog::P
ops
}
/// Repair only the shutter data an old import wrote, keeping independently edited metadata.
fn repair_legacy_shutter(m: &mut lightcraft_catalog::Meta, src: &lightcraft_catalog::Meta) -> bool {
if m.exposure_time.is_none()
&& let Some(t) = src.exposure_time
&& (m.shutter.trim() == src.shutter || legacy_shutter_text(t).is_some_and(|old| m.shutter.trim() == old))
{
m.shutter = src.shutter.clone();
m.exposure_time = Some(t);
true
} else {
false
}
}
/// The shutter text an import wrote before the exact exposure time was kept (#1619): whole seconds at
/// one second and over, otherwise `1/n` with `n` rounded. Only for recognising such a text again.
fn legacy_shutter_text(t: f64) -> Option<String> {
(t.is_finite() && t > 0.0).then(|| if t >= 1.0 { format!("{t:.0}") } else { format!("1/{:.0}", 1.0 / t) })
}
/// Ops that give a photo the lens data its file carries now (`info`, a fresh probe), or none when
/// it already has them. A catalog from before the lens data was read at import has none, so such a
/// photo's correction stayed off. When the photo gains lens data and its develop settings are still
@@ -314,8 +337,16 @@ pub(crate) fn reload_ops(
}
// virtual copies share the file
for c in cat.photos().filter(|c| c.copy_of == Some(id)) {
let theirs: Vec<Op> =
content_op(c.id, c, info.clone()).into_iter().chain(lens_ops(c.id, c, info)).chain(as_shot_wb_op(c.id, c, info)).collect();
let mut meta = c.meta.clone();
// Copies share the source file but may have independently edited metadata. Repair only
// recognizable legacy shutter values, not every missing field on the copy.
let shutter_op = repair_legacy_shutter(&mut meta, &info.meta).then(|| Op::SetMeta { id: c.id, meta: Box::new(meta) });
let theirs: Vec<Op> = content_op(c.id, c, info.clone())
.into_iter()
.chain(shutter_op)
.chain(lens_ops(c.id, c, info))
.chain(as_shot_wb_op(c.id, c, info))
.collect();
if !theirs.is_empty() {
ops.extend(theirs);
changed.push(c.id);
@@ -441,6 +472,78 @@ mod tests {
assert!(fill_missing_meta(PhotoId(1), &ph, &info).is_empty());
}
/// Reload from Disk repairs a shutter speed an older import rounded (0.4 s stored as `1/2`, with no
/// exact time): the photo takes the file's exact time and today's text. A shutter speed set by hand
/// that is not what an import wrote, and one that already has its exact time, are kept.
#[test]
fn reload_repairs_a_shutter_speed_an_older_import_rounded() {
let mut ph = Photo::new(PhotoId(1), Source::File { path: "/x.nef".into() }, "x.nef", "NEF", 6000, 4000, "2026-10-06T00:00:00");
ph.captured = Some("2026-10-04T08:16:11".into());
let mut info = crate::media::ProbeInfo { captured: ph.captured.clone(), ..Default::default() };
for (t, legacy, shown) in [(0.4, "1/2", "0.4"), (2.5, "2", "2.5"), (1.0 / 2.8, "1/3", "0.3571"), (1.0 / 250.0, "1/250", "1/250")] {
info.meta.exposure_time = Some(t);
info.meta.shutter = lightcraft_meta::format_exposure_time(t).unwrap();
ph.meta.shutter = legacy.into();
ph.meta.exposure_time = None;
let ops = fill_missing_meta(PhotoId(1), &ph, &info);
let Some(Op::SetMeta { meta, .. }) = ops.first() else { panic!("{t}: {ops:?}") };
assert_eq!((meta.shutter.as_str(), meta.exposure_time), (shown, Some(t)), "{t}");
assert_eq!(meta.shutter_seconds(), Some(t), "{t}");
// repaired → nothing more to do
ph.meta = (**meta).clone();
assert!(fill_missing_meta(PhotoId(1), &ph, &info).is_empty(), "{t}");
}
// typed by hand, not what any import wrote for this file
info.meta.exposure_time = Some(0.4);
info.meta.shutter = "0.4".into();
ph.meta.shutter = "1/8".into();
ph.meta.exposure_time = None;
assert!(fill_missing_meta(PhotoId(1), &ph, &info).is_empty(), "a hand-set shutter speed is kept");
// already has an exact time (the text was edited afterwards): kept
ph.meta.shutter = "1/2".into();
ph.meta.exposure_time = Some(0.4);
assert!(fill_missing_meta(PhotoId(1), &ph, &info).is_empty(), "a photo with an exact time is left alone");
}
#[test]
fn reload_repairs_legacy_shutter_on_copies_without_replacing_edits() {
let mut cat = lightcraft_catalog::Catalog::new();
let mut source = Photo::new(PhotoId(1), Source::File { path: "/x.nef".into() }, "x.nef", "NEF", 6000, 4000, "");
source.meta.shutter = "1/2".into();
cat.apply(Op::AddPhoto { photo: Box::new(source.clone()) }).unwrap();
for (id, text, exact) in [(2, "1/2", None), (3, "0.4", None), (4, "1/8", None), (5, "1/2", Some(0.4))] {
let mut copy = source.clone();
copy.id = PhotoId(id);
copy.copy_of = Some(source.id);
copy.meta.shutter = text.into();
copy.meta.exposure_time = exact;
copy.meta.title = "My copy".into();
cat.apply(Op::AddPhoto { photo: Box::new(copy) }).unwrap();
}
let mut info = crate::media::ProbeInfo::default();
info.meta.shutter = "0.4".into();
info.meta.exposure_time = Some(0.4);
info.meta.title = "File title".into();
let mut ops = Vec::new();
let mut changed = Vec::new();
reload_ops(&cat, source.id, &info, &mut ops, &mut changed);
for op in ops {
cat.apply(op).unwrap();
}
for id in [1, 2, 3] {
let m = &cat.photo(PhotoId(id)).unwrap().meta;
assert_eq!((m.shutter.as_str(), m.exposure_time), ("0.4", Some(0.4)));
assert_eq!(m.shutter_seconds(), Some(0.4));
}
for (id, text, exact) in [(4, "1/8", None), (5, "1/2", Some(0.4))] {
let m = &cat.photo(PhotoId(id)).unwrap().meta;
assert_eq!((m.shutter.as_str(), m.exposure_time), (text, exact));
}
for id in [2, 3, 4, 5] {
assert_eq!(cat.photo(PhotoId(id)).unwrap().meta.title, "My copy");
}
}
/// Reload from Disk gives a photo imported before focus points were read its camera focus point,
/// and never replaces one it has.
#[test]
+1 -4
View File
@@ -1277,10 +1277,7 @@ pub fn specs() -> Vec<CommandSpec> {
// log2 of the light the photo gathered (shutter s × ISO / f-number²)
let gathered = |s: &Session, id: PhotoId| -> Option<f64> {
let m = &s.catalog.photo(id)?.meta;
let t = match m.shutter.split_once('/') {
Some((a, b)) => a.trim().parse::<f64>().ok()? / b.trim().parse::<f64>().ok()?,
None => m.shutter.trim().trim_end_matches('s').trim().parse::<f64>().ok()?,
};
let t = m.shutter_seconds()?;
let (n, iso) = (m.aperture? as f64, m.iso? as f64);
(t > 0.0 && n > 0.0 && iso > 0.0).then(|| (t * iso / (n * n)).log2())
};
+1 -1
View File
@@ -342,7 +342,7 @@ pub fn export_metadata(photo: &lightcraft_catalog::Photo, catalog: &lightcraft_c
out.lens_model = text(&m.lens);
out.focal_length = m.focal_mm.map(f64::from);
out.f_number = m.aperture.map(f64::from);
out.exposure_time = lightcraft_catalog::parse_shutter_seconds(&m.shutter);
out.exposure_time = m.shutter_seconds();
out.iso = m.iso;
}
Some(out)
+3 -1
View File
@@ -3,7 +3,8 @@ use super::preview::embedded_preview_size;
use super::{MediaKind, Meta, Orientation, ProbeInfo};
pub(super) fn meta_of(m: &lightcraft_meta::Metadata) -> (Meta, Option<String>) {
let shutter = m.exposure_time.map(|t| if t >= 1.0 { format!("{t:.0}") } else { format!("1/{:.0}", 1.0 / t) }).unwrap_or_default();
let exposure_time = m.exposure_time.filter(|t| t.is_finite() && *t > 0.0);
let shutter = exposure_time.and_then(lightcraft_meta::format_exposure_time).unwrap_or_default();
let camera = [m.make.clone().unwrap_or_default(), m.model.clone().unwrap_or_default()].join(" ").trim().to_string();
let meta = Meta {
camera,
@@ -14,6 +15,7 @@ pub(super) fn meta_of(m: &lightcraft_meta::Metadata) -> (Meta, Option<String>) {
focal_mm: m.focal_length.map(|f| f as f32),
aperture: m.f_number.map(|f| f as f32),
shutter,
exposure_time,
iso: m.iso,
flash: m.flash.map(|f| f.fired),
exposure_bias: m.exposure_bias.map(|v| v as f32),
+38
View File
@@ -1851,6 +1851,44 @@ fn existing_photo_settings_are_not_rewritten() {
let _ = std::fs::remove_dir_all(&dir);
}
#[test]
fn imported_shutter_times_survive_catalog_and_export_metadata() {
use lightcraft_catalog::{Catalog, Photo, PhotoId};
for (t, shown) in [
(0.3, "0.3"),
(0.4, "0.4"),
(0.6, "0.6"),
(0.8, "0.8"),
(1.3, "1.3"),
(1.6, "1.6"),
(2.5, "2.5"),
(3.2, "3.2"),
(30.0, "30"),
(0.625, "0.625"),
(1.0 / 2.8, "0.3571"),
(1.0 / 3.0, "1/3"),
(0.003, "0.003"),
(1.0 / 250.0, "1/250"),
(1.0 / 8000.0, "1/8000"),
] {
let original = lightcraft_meta::Metadata { exposure_time: Some(t), ..Default::default() };
let (meta, _) = meta_of(&original);
// the catalog shows a short shutter speed, never the raw f64 (`0.35714285714285715`)
assert_eq!(meta.shutter, shown, "{t}");
// Exercise the persisted catalog JSON, not a value kept alongside it in memory.
let meta: Meta = serde_json::from_str(&serde_json::to_string(&meta).unwrap()).unwrap();
let mut photo = Photo::new(PhotoId(1), lightcraft_catalog::Source::Demo { scene: 0 }, "capture.jpg", "JPEG", 2, 2, "");
photo.meta = meta;
let exported = crate::export::export_metadata(&photo, &Catalog::new(), &crate::export::ExportOptions::default()).unwrap();
assert_eq!(exported.exposure_time, Some(t));
let bytes =
crate::export::encode_with_metadata(&lightcraft_raster::Rgba8::new(2, 2), &crate::export::ExportOptions::default(), Some(&exported))
.unwrap();
let back = lightcraft_meta::extract(&bytes);
assert!((back.exposure_time.unwrap() - t).abs() < 0.000001, "{t}: {:?}", back.exposure_time);
}
}
/// Issue #1632: a DNG's `ProfileToneCurve` is the finish stage's camera curve, so process V5 extends
/// it past its last point (the sensor's white, scene 1.0) with the stop roll-off as well. A curve
/// that reaches white there renders as under V4 up to it and white past it; one that ends below
+10
View File
@@ -756,4 +756,14 @@ mod write_tests {
assert!((1.0 / got - den).abs() < 0.5, "1/{den} s came back as 1/{}", 1.0 / got);
}
}
#[test]
fn written_shutter_speeds_show_as_the_same_reciprocal() {
// #1619 / #2542: the exact time is what export writes, and it reads back as the text shown
for (t, want) in [(1.0 / 3.0, "1/3"), (1.0 / 250.0, "1/250"), (1.0 / 12_800.0, "1/12800"), (0.3, "0.3"), (1.0 / 2.8, "0.3571")] {
let back = read_exif(&write_exif(&Metadata { exposure_time: Some(t), ..Default::default() }));
let got = back.exposure_time.unwrap();
assert_eq!(crate::format_exposure_time(got).as_deref(), Some(want), "{t} came back as {got}");
}
}
}
+72 -12
View File
@@ -178,6 +178,29 @@ macro_rules! overlay {
($self:ident, $o:ident, $($f:ident),*) => { $( if $o.$f.is_some() { $self.$f = $o.$f.clone(); } )* };
}
/// How far (relative) a duration may be from an exact `1/n` second and still be shown as `1/n`:
/// absorbs decimal EXIF rationals such as `3333/10000` for 1/3 s without turning 0.3 s or
/// 1/2.8 s into a reciprocal they aren't.
pub const RECIPROCAL_TOLERANCE: f64 = 1e-3;
/// The one shutter-speed formatter for display (catalog `shutter`, Info panel, All Metadata):
/// a near-exact `1/n` second as `1/n` (`1/3`, `1/250`), anything else rounded to four
/// significant digits with trailing zeros dropped (`0.3`, `0.3571`, `2.5`, `30`). Display only:
/// export writes the exact duration. `None` for a time that isn't positive and finite.
pub fn format_exposure_time(t: f64) -> Option<String> {
if !t.is_finite() || t <= 0.0 {
return None;
}
let n = (1.0 / t).round();
if n >= 2.0 && n.is_finite() && (1.0 / (n * t) - 1.0).abs() <= RECIPROCAL_TOLERANCE {
return Some(format!("1/{n}"));
}
// four significant digits; whole seconds never lose digits
let decimals = (3 - t.log10().floor() as i32).max(0) as usize;
let text = format!("{t:.decimals$}");
Some(if text.contains('.') { text.trim_end_matches('0').trim_end_matches('.').to_string() } else { text })
}
impl Metadata {
/// Fill every empty field of `self` from `other`.
pub fn fill_missing(&mut self, other: &Metadata) {
@@ -261,19 +284,10 @@ impl Metadata {
}
}
/// Exposure time formatted like cameras show it: `1/250`, `0.5`, `2″`.
/// Exposure time formatted like cameras show it: `1/250`, `0.3571`, `2.5″` (see [`format_exposure_time`]).
pub fn exposure_display(&self) -> Option<String> {
let t = self.exposure_time?;
if t.is_nan() || t <= 0.0 {
return None;
}
Some(if t < 0.3 {
format!("1/{}", (1.0 / t).round())
} else if t < 1.0 {
format!("{}", (t * 10.0).round() / 10.0)
} else {
format!("{}″", (t * 10.0).round() / 10.0)
})
format_exposure_time(t).map(|text| if t >= 1.0 { format!("{text}″") } else { text })
}
/// Human name of the metering mode.
@@ -435,12 +449,58 @@ mod tests {
assert_eq!(parse_number("inf"), None);
}
#[test]
fn exposure_time_formats_reciprocals_and_significant_digits() {
for (t, want) in [
(1.0 / 3.0, "1/3"),
(1.0 / 250.0, "1/250"),
(1.0 / 8000.0, "1/8000"),
(0.5, "1/2"),
(0.3, "0.3"),
(0.4, "0.4"),
(1.0 / 2.8, "0.3571"),
(0.625, "0.625"),
(0.003, "0.003"),
(1.0, "1"),
(1.3, "1.3"),
(2.5, "2.5"),
(30.0, "30"),
(9.99996, "10"),
(1800.0, "1800"),
] {
assert_eq!(format_exposure_time(t).as_deref(), Some(want), "{t}");
}
for t in [0.0, -1.0, f64::NAN, f64::INFINITY, f64::NEG_INFINITY] {
assert_eq!(format_exposure_time(t), None, "{t}");
}
}
#[test]
fn exposure_time_reciprocal_tolerance() {
// a camera's decimal rational for 1/3 s, and times just inside the tolerance either side
assert_eq!(format_exposure_time(3333.0 / 10000.0).as_deref(), Some("1/3"));
// a microsecond-level rational error still reads as 1/8000; above ~1/1000 s every time is
// within the tolerance of some 1/n, which is how cameras show those speeds anyway
assert_eq!(format_exposure_time(1.0 / 8000.0 * (1.0 + 1e-5)).as_deref(), Some("1/8000"));
for n in [3.0, 10.0, 250.0] {
let inside = 0.9 * RECIPROCAL_TOLERANCE;
let outside = 1.1 * RECIPROCAL_TOLERANCE;
let want = format!("1/{n}");
assert_eq!(format_exposure_time(1.0 / n * (1.0 + inside)).as_deref(), Some(want.as_str()), "{n} +inside");
assert_eq!(format_exposure_time(1.0 / n * (1.0 - inside)).as_deref(), Some(want.as_str()), "{n} -inside");
assert_ne!(format_exposure_time(1.0 / n * (1.0 + outside)).as_deref(), Some(want.as_str()), "{n} +outside");
assert_ne!(format_exposure_time(1.0 / n * (1.0 - outside)).as_deref(), Some(want.as_str()), "{n} -outside");
}
}
#[test]
fn exposure_display() {
let mut m = Metadata { exposure_time: Some(1.0 / 250.0), ..Default::default() };
assert_eq!(m.exposure_display().as_deref(), Some("1/250"));
m.exposure_time = Some(0.5);
assert_eq!(m.exposure_display().as_deref(), Some("0.5"));
assert_eq!(m.exposure_display().as_deref(), Some("1/2"));
m.exposure_time = Some(0.3);
assert_eq!(m.exposure_display().as_deref(), Some("0.3"));
m.exposure_time = Some(2.0);
assert_eq!(m.exposure_display().as_deref(), Some("2″"));
m.exposure_time = Some(0.0);
+26 -1
View File
@@ -250,7 +250,10 @@ fn value_text(group: &str, tag: u16, v: &Value) -> String {
// exposure time as a fraction of a second
let (n, d) = a[0];
let s = n as f64 / d as f64;
if s >= 1.0 || n == 0 { format!("{} s", rational(n as f64, d as f64)) } else { format!("1/{} s", (1.0 / s).round()) }
match crate::format_exposure_time(s) {
Some(text) => format!("{text} s"),
None => format!("{} s", rational(n as f64, d as f64)),
}
}
Value::Rational(a) if tag == 0x829d && group != "GPS" && a.len() == 1 => format!("f/{}", rational(a[0].0 as f64, a[0].1 as f64)),
Value::Rational(a) if tag == 0x920a && group != "GPS" && a.len() == 1 => format!("{} mm", rational(a[0].0 as f64, a[0].1 as f64)),
@@ -380,6 +383,28 @@ pub fn file_tag_rows(bytes: &[u8]) -> Vec<TagRow> {
#[cfg(test)]
mod tests {
#[test]
fn exposure_rows_do_not_round_third_stop_times() {
for (n, d, expected) in [
(3, 10, "0.3 s"),
(4, 10, "0.4 s"),
(6, 10, "0.6 s"),
(8, 10, "0.8 s"),
(13, 10, "1.3 s"),
(16, 10, "1.6 s"),
(25, 10, "2.5 s"),
(32, 10, "3.2 s"),
(5, 8, "0.625 s"),
(1, 3, "1/3 s"),
(10, 28, "0.3571 s"),
(1, 250, "1/250 s"),
(1, 8000, "1/8000 s"),
(30, 1, "30 s"),
] {
assert_eq!(value_text("EXIF", 0x829a, &Value::Rational(vec![(n, d)])), expected);
}
}
use super::*;
#[test]
+3 -2
View File
@@ -170,7 +170,7 @@ differences and missing bindings are in [ui-parity.md](ui-parity.md#shortcuts).
| LR-META-LOCATION | Location editing | P2 | 🟡 | `cmd:photo.setMeta` (`location`, `city`, `state`, `country`, `gps`), `cmd:metadata.reverseGeocode` | place fields and GPS (decimal or degrees / minutes / seconds) edited in Info, read/written as IPTC Core / Photoshop / EXIF XMP; typed GPS consumes the full expression, accepts case-insensitive axis-appropriate hemisphere markers, and refuses malformed text or DMS minutes/seconds outside [0,60) before changing metadata; Show on Map opens OpenStreetMap; Fill Location fills empty City / State / Country from GPS offline (GeoNames, downloaded on request: `cmd:metadata.downloadPlaceNames`); no embedded map |
| LR-META-COPYPASTE | Copy / paste metadata | P2 | ✅ | `cmd:photo.copyMetadata`, `cmd:photo.pasteMetadata` | title, caption, alt text, extended description, copyright (notice, status, usage terms, info URL), creator, place fields, keywords; `fields` picks a subset |
| LR-META-XMP | XMP read/write | P0 | ✅ | `cmd:photo.saveMetadataToFile`, `cmd:photo.readMetadataFromFile`, `cmd:library.xmpPreferences`, `crates/engine/src/sidecar.rs`, `docs/xmp-interop.md` | manual rereading also reads sidecar-free JPEG embedded XMP (first complete standard APP1 before SOS/EOI, within 16 MiB of headers and 4096 marker/fill steps; no extended assembly or between-scan packets, not strict whole-JPEG validation; reader cases in `crates/engine/src/sidecar.rs`); a discovered unreadable sidecar fails without embedded fallback; procedural refresh/undo, non-UTF-8 sidecar and two explicit malformed fixtures in `crates/engine/src/tests/xmp.rs` (file-write checks use auto-write off); sidecar wins for metadata; a sidecar capture time (`exif:DateTimeOriginal` / `photoshop:DateCreated` / `xmp:CreateDate`) fills in only when the file has none; keywords are saved as names in `dc:subject` and paths in `lr:hierarchicalSubject` (`keywords::to_file`; before, paths went into `dc:subject`); saving merges into an existing sidecar (the `lightcraft_meta::merge_xmp` adapter in `crates/meta/src/lib.rs` delegates to shared `craft_metadata::merge_xmp`): another app's `crs:`, `xmpMM:History` and unknown namespaces are kept byte for byte (ownership follows namespace URI: foreign namespaces using `lc:` or `xmp:` cannot supply native settings or ratings and survive saving), an unreadable sidecar is backed up first; with stem naming, files sharing a stem (raw + JPEG) get separate sidecars (`<file>.xmp` for all but the raw; an import ranks the files it is adding the same way, so a TIFF or JPEG arriving beside its raw reads its own `<file>.xmp` and never the raw's `IMG_0001.xmp`, issue #1905); a `crs:` custom white balance on a relative-WB raw is shifted from `crs:AsShotTemperature` rather than read as Kelvin, or kept As Shot and reported when the packet has no as-shot white (issue #510); heal and clone spots (`crs:RetouchAreas`, legacy `crs:RetouchInfo`) are read into our spots (`crates/engine/src/crs_masks.rs`, see `docs/xmp-interop.md` → Spot removal); radial masks (`Mask/CircularGradient`) keep Lightroom's inside / outside: `crs:Flipped="true"` is the effect-inside flag of current masks and of the legacy Radial Filter, `crs:MaskInverted` the inversion, checked against Lightroom Classic's renders (issue #1815); Read Metadata from File never writes the sidecar back, even with auto-write on, so another app's later `crs:` edits are still read (issue #934); settings Lightroom writes only for itself (`CompatibleVersion`, the profile digests, the lens profile's name / file / setup, `CropConstrainToUnitSquare`, the lens profile's strength at 100 %) are not reported as unimported (`crates/engine/src/crs.rs`); malformed XMP capture-time values remain in the raw property map and are not projected, allowing the next valid field to supply the capture time |
| LR-META-EXIF-FULL | Full EXIF/IPTC [Classic] | P1 | ✅ | `cmd:photo.allMetadata`, `cmd:dialog.allMetadata`, `crates/meta/src/tags.rs`, `crates/meta/src/exif.rs`, `crates/meta/src/iptc.rs` | `photo.allMetadata` reuses loaded original bytes for embedded XMP and keeps sidecar precedence (`crates/engine/src/tests/xmp.rs`); read and written on export; Info ▸ All Metadata…: every TIFF / EXIF / GPS / interop tag (named, common values spelled out) and the XMP fields, searchable; PSD/PSB EXIF resource 1058 and XMP resource 1060 feed the same metadata rows and preserve sidecar precedence; metadata presets; malformed EXIF clocks with extra components are rejected so valid DateTimeDigitized, IFD0 DateTime or XMP fallbacks apply, while raw values stay visible in All Metadata (`crates/meta/src/exif.rs`, `crates/engine/src/tests/import.rs`) |
| LR-META-EXIF-FULL | Full EXIF/IPTC [Classic] | P1 | ✅ | `cmd:photo.allMetadata`, `cmd:dialog.allMetadata`, `crates/meta/src/tags.rs`, `crates/meta/src/exif.rs`, `crates/meta/src/iptc.rs` | `photo.allMetadata` reuses loaded original bytes for embedded XMP and keeps sidecar precedence (`crates/engine/src/tests/xmp.rs`); read and written on export; Info ▸ All Metadata…: every TIFF / EXIF / GPS / interop tag (named, common values spelled out) and the XMP fields, searchable; PSD/PSB EXIF resource 1058 and XMP resource 1060 feed the same metadata rows and preserve sidecar precedence; metadata presets; malformed EXIF clocks with extra components are rejected so valid DateTimeDigitized, IFD0 DateTime or XMP fallbacks apply, while raw values stay visible in All Metadata (`crates/meta/src/exif.rs`, `crates/engine/src/tests/import.rs`); shutter display uses 1/n or four significant digits; exact exposure duration is preserved in the catalog and exports (#1619) |
## F. Edit panel — global adjustments (EDIT)
@@ -400,7 +400,7 @@ differences and missing bindings are in [ui-parity.md](ui-parity.md#shortcuts).
| LR-EXP-COLORSPACE | Output colour space | P0 | ✅ | `cmd:app.export` (`colorSpace`), `crates/pipeline/src/output.rs`, `crates/engine/src/export.rs` | sRGB, Display P3, Adobe RGB (1998) compatible, ProPhoto RGB, Rec. 2020: rendered from the working space with gamut mapping into the target gamut (CPU + GPU), own ICC profile embedded; AVIF stays sRGB (muxer has no ICC); lossy JPEG XL declares sRGB / P3 / Rec. 2020 (Adobe RGB and ProPhoto written as Rec. 2020), lossless JPEG XL embeds the profile |
| LR-EXP-HDR | HDR output | P2 | 🟡 | `cmd:app.export`, `crates/ui-egui/src/dialogs.rs` | HDR output checkbox in the export dialog: gain map JPEG, PQ or HLG AVIF, PQ PNG, PQ JPEG XL, float TIFF; no HDR presets yet |
| LR-EXP-SHARPEN | Output sharpening | P1 | ✅ | `cmd:app.export` (`sharpen`, `sharpenAmount`) | |
| LR-EXP-METADATA | Metadata policy | P1 | ✅ | `cmd:app.export` (`metadata`, `removeLocation`) | Original export is refused when Remove Location Info is on and the source embeds GPS or a nonblank sublocation, city, state or country; rendered exports and XMP sidecars remove those modeled fields |
| LR-EXP-METADATA | Metadata policy | P1 | ✅ | `cmd:app.export` (`metadata`, `removeLocation`) | Original export is refused when Remove Location Info is on and the source embeds GPS or a nonblank sublocation, city, state or country; rendered exports and XMP sidecars remove those modeled fields; Export writes the exact exposure time kept in the catalog beside the rounded shutter text (#1619); a photo imported earlier, whose shutter text is still the rounded one import wrote then, gets the exact time and current text from Reload from Disk; a shutter speed set by hand is kept. Smart-album Shutter Speed rules compare the shown value. |
| LR-EXP-WATERMARK | Watermark | P1 | 🟡 | `cmd:app.export` (`watermark`: text, or `{text, vertical, size, opacity, anchor, insetX, insetY, inset, rotation, color, shadow, image, imageWidth}`), `crates/engine/src/export.rs` (`Watermark`, `WATERMARK_PARAMS`) | text uses Inter SemiBold, the existing Mincho-first CJK chain, then Thai faces from `CRAFT_FONTS_DIR`, shared with contact-sheet captions and slideshow overlays (#2052, partial). Decomposed (NFD) text, as macOS often writes file names, is composed to NFC first, so Hangul syllables and Vietnamese letters draw whole instead of as loose jamo and marks; CJK compatibility ideographs keep their code points (issue #3480, #3277; `decomposed_hangul_draws_whole_syllables`, `decomposed_vietnamese_draws_its_composed_letters`, `compatibility_ideographs_keep_their_code_points`). Horizontal Thai mark positioning remains incomplete. Arabic export fallback is deferred until joining and bidi reordering exist; UI font fallback is unchanged. Text (`size` = height as a fraction of the short edge, 0.005..0.5, default 0.035; `color` sRGB `[r,g,b]`; `shadow`; Japanese vertical glyph forms and origins, tested by `biz_ud_vertical_watermarks_place_punctuation_at_the_top_right`; extended grapheme cells keep decomposed dakuten/handakuten and Latin accents together, tested by `vertical_watermarks_keep_combining_marks_in_one_cell` and `upright_watermark_cell_retains_multiple_glyphs` (see `docs/vertical-watermarks.md`)) or a graphic with transparency (EXIF orientation applied before sizing; oversized graphics fit the rotated image bounds without stretching, tested by `graphic_watermark_honours_exif_orientation` and `graphic_watermark_keeps_aspect_when_fitted_and_rotated`; `image` path, `imageWidth` = fraction of the photo's width, 0.01..1, converted to the output colour space); `anchor` (nine positions), `insetX` / `insetY` (margins from the side and from the top/bottom edges, each a fraction of the short edge, 0..0.4; the Export dialog's Horizontal and Vertical inset sliders, as in Lightroom Classic; the older single `inset` still reads as both; tested by `watermark_insets_are_horizontal_and_vertical`), `rotation` (0, 90, 180 or 270 degrees clockwise, the Export dialog's Rotate row, as Lightroom Classic's rotate buttons; sized before it is turned, placed and inset by the turned box; tested by `watermark_rotation_turns_the_text_in_its_corner` and `graphic_watermark_is_placed_scaled_and_blended`), `opacity` 0..1. Unknown keys and out-of-range values are errors (issue #183). The Export dialog previews it on the first exported photo's thumbnail (`draw_watermark_preview` scales the 6 px minimum text size to the preview so it matches the file), tested by `watermark_preview_scales_the_minimum_text_size` and `export_dialog_previews_the_watermark` |
| LR-EXP-NAMING | File naming | P1 | ✅ | `cmd:app.export` (`naming`, `startNumber`), `crates/engine/src/rename.rs` (`expand_tokens`) | one template language for export, Rename Photos and import renaming: `{name}`, `{num}` (number at the end of the name), `{seq}` / `{seq:N}`, `{date}` / `{date:%Y-%m-%d}`, `{folder}`, `{camera}`, `{lens}`, `{iso}`, `{rating}`, `{title}`, `{creator}`, `{ext}`; free-form template rather than a list of named schemes |
| LR-EXP-LOCATION | Destination folder | P0 | ✅ | `cmd:app.export` (`dir`, `destinationMode`: specificFolder / sameAsOriginal, `subfolder`, `conflict`: unique / overwrite / skip), `cmd:export.checkTarget`, `crates/ui-egui/src/dialogs.rs` (Choose… folder picker), `crates/engine/src/originals.rs`, `crates/catalog/src/safe_file.rs` | folder picker on the desktop; Export to: Specific folder or Same folder as original photo (each photo into its original's folder + the subfolder; a demo/browser photo or a missing folder is that photo's error, issue #956); existing files get `-2`, `-3`… by default; the policy covers a file and its sidecars together; a catalogued original (or its sidecar) is never written over, whatever the policy or an exact `path` (export, `ui.render`, MCP `render_photo`, merge `previewPath`, `lightcraft-cli render`); files are written to a temp file and renamed into place (issue #93; not synced file by file — exports can be made again, issue #134) |
@@ -826,6 +826,7 @@ Latin stays upright. Advanced Japanese composition remains open. Regression cove
| 2026-10-24 | minor | LR-EDIT-DETAIL-DENOISE: the built-in denoiser measures noise by colour channel and ignores texture, and its strength follows the measured noise; status and counts unchanged |
| 2026-10-24 | minor | LR-EDIT-DETAIL-DENOISE: the built-in denoiser filters with block-matching collaborative filtering instead of non-local means, and runs that filter on the graphics card where there is one; status and counts unchanged |
| 2026-10-23 | minor | LR-EDIT-DETAIL-DENOISE: built-in denoiser, no model needed |
| 2026-10-25 | patch | LR-META-EXIF-FULL, LR-EXP-METADATA: shutter speeds shown as 1/n or four significant digits; the exact duration is kept in the catalog (optional `exposure_time`, older catalogs read unchanged) and written on export (#1619). Statuses and feature counts unchanged. |
| 2026-10-25 | patch | LR-BEHAV-TITLEBAR: the top bar's title-bar gestures come from craft-window's `title_bar`: a double-click follows the system setting, and a press on a button, the search field or a panel floating over the bar never moves the window; status counts unchanged |
| 2026-10-24 | minor | KEYC-METADATA, LRC-LIB-KEYWORDS: ⌘⌥K / Ctrl+Alt+K (`tool.enablePainting`, Photo ▸ Enable Painting) paints the painter box's keyword or stops painting; status counts unchanged (KEYC-METADATA stays 🟡) |
| 2026-10-24 | minor | KEYC-METADATA: ⌘⇧K / Ctrl+Shift+K (`panel.editKeywords`, Edit Keywords) shows the Keywords panel with its Keyword List open and opens the picked keyword in Edit Keyword Tag; status counts unchanged (KEYC-METADATA stays 🟡) |
+6
View File
@@ -273,6 +273,12 @@ mod tests {
assert!(!p.rust(), "only files something compiles in");
}
#[test]
fn app_icon_changes_retest_both_hosts_and_the_update_prompt() {
let users: Vec<_> = embedders("assets/app-icon/hicolor/128x128/apps/ai.storyteller.lightcraft.png").collect();
assert_eq!(users, ["lightcraft", "lightcraft-ui-egui"]);
}
/// Every `include_str!` / `include_bytes!` of a file outside its package, and every `"../…"`
/// path in a build script, is listed in `EMBEDDED` for that package.
#[test]