From 2f7f61b8a9b9b1b4367b576a5fb762557cf1e77c Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Wed, 14 Oct 2026 10:24:19 +0200 Subject: [PATCH 001/367] LR-META-EXIF-FULL: preserve shutter precision through import and export (#1619) Share lossless duration formatting between catalog import and All Metadata. Keep the catalog schema unchanged and cover persisted metadata round trips. Co-authored-by: Codex --- crates/engine/src/files.rs | 23 ++++++++++++++++++++++- crates/meta/src/lib.rs | 31 +++++++++++++++++++++++++------ crates/meta/src/tags.rs | 24 +++++++++++++++++++++++- docs/parity-checklist.md | 5 +++-- 4 files changed, 73 insertions(+), 10 deletions(-) diff --git a/crates/engine/src/files.rs b/crates/engine/src/files.rs index e2144eb859..f26e0b2307 100644 --- a/crates/engine/src/files.rs +++ b/crates/engine/src/files.rs @@ -14,7 +14,7 @@ use lightcraft_raster::resample::{Filter, fit}; use crate::media::{DenoiseSpec, FileLoader, FileProbe, PairLoader, PreviewLoader, ProbeInfo}; fn meta_of(m: &lightcraft_meta::Metadata) -> (Meta, Option) { - 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 shutter = m.exposure_display().map(|s| s.trim_end_matches('″').to_string()).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, @@ -1049,6 +1049,27 @@ impl crate::Session { #[cfg(test)] mod tests { + #[test] + fn imported_shutter_times_survive_catalog_and_export_metadata() { + use lightcraft_catalog::{Catalog, Photo, PhotoId}; + for t in [0.3, 0.4, 0.6, 0.8, 1.3, 1.6, 2.5, 3.2, 0.625, 1.0 / 2.8, 0.003, 1.0 / 250.0] { + let original = lightcraft_meta::Metadata { exposure_time: Some(t), ..Default::default() }; + let (meta, _) = meta_of(&original); + assert_eq!(lightcraft_catalog::parse_shutter_seconds(&meta.shutter), Some(t)); + // Exercise the persisted string, 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); + } + } + /// Keywords from a file keep their hierarchy: the paths of `lr:hierarchicalSubject`, not the /// flat names of `dc:subject` that LightCraft's exports (and Lightroom Classic) write besides /// them; an exported `travel|Italy|Rome` comes back as itself. diff --git a/crates/meta/src/lib.rs b/crates/meta/src/lib.rs index 31a35cc652..772c3900c8 100644 --- a/crates/meta/src/lib.rs +++ b/crates/meta/src/lib.rs @@ -222,18 +222,21 @@ impl Metadata { } } - /// Exposure time formatted like cameras show it: `1/250`, `0.5`, `2″`. + /// Exposure time without rounding away capture metadata: `1/250`, `0.625`, `1.3″`. pub fn exposure_display(&self) -> Option { let t = self.exposure_time?; - if t.is_nan() || t <= 0.0 { + if !t.is_finite() || t <= 0.0 { return None; } - Some(if t < 0.3 { - format!("1/{}", (1.0 / t).round()) + let denominator = (1.0 / t).round(); + // Only use a reciprocal when parsing it recovers the original duration. + // Decimal thirds of a stop and unusual camera rationals must not be quantized. + Some(if t < 0.3 && denominator.is_finite() && 1.0 / denominator == t { + format!("1/{denominator}") } else if t < 1.0 { - format!("{}", (t * 10.0).round() / 10.0) + t.to_string() } else { - format!("{}″", (t * 10.0).round() / 10.0) + format!("{t}″") }) } @@ -306,6 +309,22 @@ mod tests { assert_eq!(parse_number("inf"), None); } + #[test] + fn exposure_display_preserves_duration() { + for t in [0.3, 0.4, 0.6, 0.8, 1.3, 1.6, 2.5, 3.2, 0.625, 1.0 / 2.8, 0.003, 1.0 / 250.0] { + let text = Metadata { exposure_time: Some(t), ..Default::default() }.exposure_display().unwrap(); + let number = text.trim_end_matches('″'); + let actual = match number.split_once('/') { + Some((n, d)) => n.parse::().unwrap() / d.parse::().unwrap(), + None => number.parse::().unwrap(), + }; + assert_eq!(actual, t, "{text}"); + } + for t in [0.0, -1.0, f64::NAN, f64::INFINITY, f64::NEG_INFINITY] { + assert!(Metadata { exposure_time: Some(t), ..Default::default() }.exposure_display().is_none()); + } + } + #[test] fn exposure_display() { let mut m = Metadata { exposure_time: Some(1.0 / 250.0), ..Default::default() }; diff --git a/crates/meta/src/tags.rs b/crates/meta/src/tags.rs index 39e26097d6..d69b25735f 100644 --- a/crates/meta/src/tags.rs +++ b/crates/meta/src/tags.rs @@ -237,7 +237,11 @@ 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()) } + let display = crate::Metadata { exposure_time: Some(s), ..Default::default() }.exposure_display(); + match display { + Some(text) => format!("{} s", text.trim_end_matches('″')), + 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)), @@ -355,6 +359,24 @@ pub fn file_tag_rows(bytes: &[u8]) -> Vec { #[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, 250, "1/250 s"), + ] { + assert_eq!(value_text("EXIF", 0x829a, &Value::Rational(vec![(n, d)])), expected); + } + } + use super::*; #[test] diff --git a/docs/parity-checklist.md b/docs/parity-checklist.md index 7bb187811c..f7a4b2b381 100644 --- a/docs/parity-checklist.md +++ b/docs/parity-checklist.md @@ -168,7 +168,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; 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` | sidecar wins for metadata; a sidecar capture time (`exif:DateTimeOriginal` / `photoshop:DateCreated` / `xmp:CreateDate`) fills in only when the file has none; saving merges into an existing sidecar (`crates/meta/src/xmp_merge.rs`): another app's `crs:`, `xmpMM:History` and unknown namespaces are kept byte for byte, an unreadable sidecar is backed up first; with stem naming, files sharing a stem (raw + JPEG) get separate sidecars (`.xmp` for all but the raw); 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); 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) | -| 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` | read and written on export; Info ▸ All Metadata…: every TIFF / EXIF / GPS / interop tag (named, common values spelled out) and the XMP fields, searchable; metadata presets | +| 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` | read and written on export; Info ▸ All Metadata…: every TIFF / EXIF / GPS / interop tag (named, common values spelled out) and the XMP fields, searchable; metadata presets Exposure durations retain their precision in imported catalog metadata and All Metadata (#1619). | ## F. Edit panel — global adjustments (EDIT) @@ -393,7 +393,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/panels/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`) | | +| LR-EXP-METADATA | Metadata policy | P1 | ✅ | `cmd:app.export` (`metadata`, `removeLocation`) | Exposure durations survive catalog serialization and export without import-time reciprocal or whole-second rounding (#1619); previously rounded catalog values require reloading metadata from the original. | | 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 (`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 (`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`, `subfolder`, `conflict`: unique / overwrite / skip), `cmd:export.checkTarget`, `crates/ui-egui/src/panels/dialogs.rs` (Choose… folder picker), `crates/engine/src/originals.rs`, `crates/catalog/src/safe_file.rs` | folder picker on the desktop; 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) | @@ -790,6 +790,7 @@ Latin stays upright. Advanced Japanese composition remains open. Regression cove | Date | Change | Summary | |---|---|---| +| 2026-10-14 | patch | LR-META-EXIF-FULL, LR-EXP-METADATA: preserve shutter duration through import, display and export (#1619); no catalog schema change. Statuses and feature counts unchanged. | | 2026-10-13 | patch | LR-VIEW-COMPARE, LRC-LIB-COMPARE: ⌘/Ctrl- and Shift-clicks on the filmstrip in Compare change the selection as in the grid; the two photos shown stay selected and the active photo is unchanged (#187); statuses unchanged | | 2026-10-13 | minor | KEYC-SELECTONLYACTIVE: Edit → Select Only Active Photo (⌘⇧D) lands as a new row; status 🟡 (headless-tested, native macOS menu path unverified) | | 2026-10-13 | patch | LRC-LIB-CATALOG-IMPORT: a catalog whose tables are all still in its `-wal` file (main file schema format 0) opens instead of failing as an unsupported schema format; status unchanged | From 887752ff94410469da95e9b803b5f15416e0e0d9 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Sun, 18 Oct 2026 17:51:55 +0200 Subject: [PATCH 002/367] LR-1619: one shutter formatter for display, exact time kept for export Show near-exact 1/n second as `1/n` and round everything else to four significant digits through lightcraft_meta::format_exposure_time, used by the catalog `shutter` text, the Info panel (which shows it) and All Metadata. The catalog keeps the exact duration in an optional `exposure_time` beside it (older catalogs read unchanged), and export, auto-stacking, smart-collection shutter rules and Match Total Exposures read it through Meta::shutter_seconds while the text still matches it. --- crates/catalog/src/model.rs | 42 +++++++++++++++ crates/catalog/src/rules.rs | 2 +- crates/catalog/src/stacks.rs | 2 +- crates/engine/src/cmd/convert.rs | 1 + crates/engine/src/cmd/develop.rs | 5 +- crates/engine/src/export.rs | 2 +- crates/engine/src/files.rs | 27 ++++++++-- crates/meta/src/lib.rs | 91 +++++++++++++++++++++++--------- crates/meta/src/tags.rs | 9 ++-- docs/parity-checklist.md | 6 +-- 10 files changed, 145 insertions(+), 42 deletions(-) diff --git a/crates/catalog/src/model.rs b/crates/catalog/src/model.rs index 6ac3544ee7..2c6f5cab08 100644 --- a/crates/catalog/src/model.rs +++ b/crates/catalog/src/model.rs @@ -171,7 +171,13 @@ pub struct Meta { pub lens: String, pub focal_mm: Option, pub aperture: Option, + /// 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, pub iso: Option, /// Place (sublocation, e.g. a landmark). pub location: String, @@ -206,6 +212,16 @@ pub struct Meta { pub focus: Option, } +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 { + 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, @@ -678,3 +694,29 @@ mod edited_tests { } } } + +#[cfg(test)] +mod shutter_tests { + 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)); + } +} diff --git a/crates/catalog/src/rules.rs b/crates/catalog/src/rules.rs index a87c9effc0..42112c65f4 100644 --- a/crates/catalog/src/rules.rs +++ b/crates/catalog/src/rules.rs @@ -887,7 +887,7 @@ 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), - "shutterSpeed" => num_op(op, crate::parse_shutter_seconds(&m.shutter), &shutter_value(value)), + "shutterSpeed" => num_op(op, m.shutter_seconds(), &shutter_value(value)), "iso" => num_op(op, m.iso.map(|v| v as f64), value), "aperture" => num_op(op, m.aperture.map(|v| v as f64), value), "focalLength" => num_op(op, m.focal_mm.map(|v| v as f64), value), diff --git a/crates/catalog/src/stacks.rs b/crates/catalog/src/stacks.rs index eb7e89ef4e..a3e9282370 100644 --- a/crates/catalog/src/stacks.rs +++ b/crates/catalog/src/stacks.rs @@ -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())) diff --git a/crates/engine/src/cmd/convert.rs b/crates/engine/src/cmd/convert.rs index eae955cce4..12c4c4ab4c 100644 --- a/crates/engine/src/cmd/convert.rs +++ b/crates/engine/src/cmd/convert.rs @@ -235,6 +235,7 @@ 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; } m.focal_mm = m.focal_mm.or(src.focal_mm); m.aperture = m.aperture.or(src.aperture); diff --git a/crates/engine/src/cmd/develop.rs b/crates/engine/src/cmd/develop.rs index e3d59c5672..54adb7f3f7 100644 --- a/crates/engine/src/cmd/develop.rs +++ b/crates/engine/src/cmd/develop.rs @@ -934,10 +934,7 @@ pub fn specs() -> Vec { // log2 of the light the photo gathered (shutter s × ISO / f-number²) let gathered = |s: &Session, id: PhotoId| -> Option { let m = &s.catalog.photo(id)?.meta; - let t = match m.shutter.split_once('/') { - Some((a, b)) => a.trim().parse::().ok()? / b.trim().parse::().ok()?, - None => m.shutter.trim().trim_end_matches('s').trim().parse::().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()) }; diff --git a/crates/engine/src/export.rs b/crates/engine/src/export.rs index e9d1cbc585..4d5a07cc45 100644 --- a/crates/engine/src/export.rs +++ b/crates/engine/src/export.rs @@ -1532,7 +1532,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) diff --git a/crates/engine/src/files.rs b/crates/engine/src/files.rs index 4111c02267..35a0c52ba3 100644 --- a/crates/engine/src/files.rs +++ b/crates/engine/src/files.rs @@ -14,7 +14,8 @@ use lightcraft_raster::resample::{Filter, fit}; use crate::media::{DenoiseSpec, FileLoader, FileProbe, PairLoader, PreviewLoader, ProbeInfo}; fn meta_of(m: &lightcraft_meta::Metadata) -> (Meta, Option) { - let shutter = m.exposure_display().map(|s| s.trim_end_matches('″').to_string()).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, @@ -23,6 +24,7 @@ fn meta_of(m: &lightcraft_meta::Metadata) -> (Meta, Option) { 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, location: m.sublocation.clone().unwrap_or_default(), city: m.city.clone().unwrap_or_default(), @@ -1112,11 +1114,28 @@ pub(crate) mod tests { #[test] fn imported_shutter_times_survive_catalog_and_export_metadata() { use lightcraft_catalog::{Catalog, Photo, PhotoId}; - for t in [0.3, 0.4, 0.6, 0.8, 1.3, 1.6, 2.5, 3.2, 0.625, 1.0 / 2.8, 0.003, 1.0 / 250.0] { + 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); - assert_eq!(lightcraft_catalog::parse_shutter_seconds(&meta.shutter), Some(t)); - // Exercise the persisted string, not a value kept alongside it in memory. + // 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; diff --git a/crates/meta/src/lib.rs b/crates/meta/src/lib.rs index 64307d9b06..1edfe9f312 100644 --- a/crates/meta/src/lib.rs +++ b/crates/meta/src/lib.rs @@ -157,6 +157,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 { + 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) { @@ -231,22 +254,10 @@ impl Metadata { } } - /// Exposure time without rounding away capture metadata: `1/250`, `0.625`, `1.3″`. + /// Exposure time formatted like cameras show it: `1/250`, `0.3571`, `2.5″` (see [`format_exposure_time`]). pub fn exposure_display(&self) -> Option { let t = self.exposure_time?; - if !t.is_finite() || t <= 0.0 { - return None; - } - let denominator = (1.0 / t).round(); - // Only use a reciprocal when parsing it recovers the original duration. - // Decimal thirds of a stop and unusual camera rationals must not be quantized. - Some(if t < 0.3 && denominator.is_finite() && 1.0 / denominator == t { - format!("1/{denominator}") - } else if t < 1.0 { - t.to_string() - } else { - format!("{t}″") - }) + format_exposure_time(t).map(|text| if t >= 1.0 { format!("{text}″") } else { text }) } /// Human name of the metering mode. @@ -342,18 +353,46 @@ mod tests { } #[test] - fn exposure_display_preserves_duration() { - for t in [0.3, 0.4, 0.6, 0.8, 1.3, 1.6, 2.5, 3.2, 0.625, 1.0 / 2.8, 0.003, 1.0 / 250.0] { - let text = Metadata { exposure_time: Some(t), ..Default::default() }.exposure_display().unwrap(); - let number = text.trim_end_matches('″'); - let actual = match number.split_once('/') { - Some((n, d)) => n.parse::().unwrap() / d.parse::().unwrap(), - None => number.parse::().unwrap(), - }; - assert_eq!(actual, t, "{text}"); + 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!(Metadata { exposure_time: Some(t), ..Default::default() }.exposure_display().is_none()); + 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"); } } @@ -362,7 +401,9 @@ mod tests { 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); diff --git a/crates/meta/src/tags.rs b/crates/meta/src/tags.rs index 8fb339edf6..faedf04fe5 100644 --- a/crates/meta/src/tags.rs +++ b/crates/meta/src/tags.rs @@ -238,9 +238,8 @@ 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; - let display = crate::Metadata { exposure_time: Some(s), ..Default::default() }.exposure_display(); - match display { - Some(text) => format!("{} s", text.trim_end_matches('″')), + match crate::format_exposure_time(s) { + Some(text) => format!("{text} s"), None => format!("{} s", rational(n as f64, d as f64)), } } @@ -384,7 +383,11 @@ mod tests { (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); } diff --git a/docs/parity-checklist.md b/docs/parity-checklist.md index 10421430dc..4dfd3007b7 100644 --- a/docs/parity-checklist.md +++ b/docs/parity-checklist.md @@ -171,7 +171,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; 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` | sidecar wins for metadata; a sidecar capture time (`exif:DateTimeOriginal` / `photoshop:DateCreated` / `xmp:CreateDate`) fills in only when the file has none; saving merges into an existing sidecar (`crates/meta/src/xmp_merge.rs`): another app's `crs:`, `xmpMM:History` and unknown namespaces are kept byte for byte, an unreadable sidecar is backed up first; with stem naming, files sharing a stem (raw + JPEG) get separate sidecars (`.xmp` for all but the raw); 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) | -| 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` | read and written on export; Info ▸ All Metadata…: every TIFF / EXIF / GPS / interop tag (named, common values spelled out) and the XMP fields, searchable; metadata presets. Exposure durations retain their precision in imported catalog metadata and All Metadata (#1619). | +| 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` | read and written on export; Info ▸ All Metadata…: every TIFF / EXIF / GPS / interop tag (named, common values spelled out) and the XMP fields, searchable; metadata presets. Shutter speeds in the catalog, Info and All Metadata use one formatter (`lightcraft_meta::format_exposure_time`): a near-exact 1/n s as `1/n`, otherwise four significant digits (#1619). | ## F. Edit panel — global adjustments (EDIT) @@ -398,7 +398,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/panels/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`) | Exposure durations survive catalog serialization and export without import-time reciprocal or whole-second rounding (#1619); previously rounded catalog values require reloading metadata from the original. | +| LR-EXP-METADATA | Metadata policy | P1 | ✅ | `cmd:app.export` (`metadata`, `removeLocation`) | Export writes the exact exposure time kept in the catalog beside the rounded shutter text (#1619); previously rounded catalog values require reloading metadata from the original. | | 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 (`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 (`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/panels/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) | @@ -797,7 +797,7 @@ Latin stays upright. Advanced Japanese composition remains open. Regression cove | Date | Change | Summary | |---|---|---| -| 2026-10-14 | patch | LR-META-EXIF-FULL, LR-EXP-METADATA: preserve shutter duration through import, display and export (#1619); no catalog schema change. Statuses and feature counts unchanged. | +| 2026-10-14 | 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-14 | patch | LR-EXP-TYPE: opaque 8-bit PNG/TIFF/WebP use RGB; transparent exports retain alpha (#1670). Statuses and feature counts unchanged. | | 2026-10-15 | minor | LRC-PRINT-PAGE: Page Options (Page Numbers, Page Info, Crop Marks) on Single Image and Contact Sheet pages, in the Print dialog, `print.set` and templates; still 🟡 (no identity plate, watermark, photo info or Cut Guides) | | 2026-10-15 | minor | LR-IMP-FORMATS: Hasselblad 3FR and FFF show their uncompressed RGB preview (no JPEG in these files) in the grid and loupe until developed, and as the stand-in when a file fails to decode; status unchanged (🟡) | From 78a01f47dbe1c61f6bf533df0e258abc2a1efacf Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 19 Oct 2026 11:29:52 +0000 Subject: [PATCH 003/367] #2270: a host bridge for pages framing the web build (?host=parent) A same-origin page that embeds LightCraft in an iframe can now speak to it over postMessage, with the protocol PdfCraft, GridCraft and DeckCraft share (deckcraft#983), under lightcraft: message types: - ready {version} / failed {error} at start-up; - open {name, bytes} from the page adds a photo, as one dropped on the window (the name gives the format); - save {name, bytes} replaces every download: exports, preset and keyword files, the library backup (handed over as a transferred ArrayBuffer); - dirty {dirty} whenever closing the page would start or stop losing something (a write to browser storage queued or running, or changes storage refused), so the page can ask before closing a window with edits; - cmd {id, params} runs a command like lightcraft.command(..) and is answered with response {ok, value}. Only the parent window on the page's own origin is heard or answered. There is no docClosed: LightCraft has a library, not documents. The message layer (apps/lightcraft-web/src/host.rs) is plain Rust with native tests; the postMessage part is wasm32 only. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01AbegtYaPuwqZ81pGfELsFK --- apps/lightcraft-web/src/host.rs | 340 ++++++++++++++++++++++++++++++ apps/lightcraft-web/src/lib.rs | 3 + apps/lightcraft-web/src/safety.rs | 10 +- apps/lightcraft-web/src/web.rs | 112 ++++++++-- docs/web.md | 13 ++ docs/whats-new.md | 7 + 6 files changed, 469 insertions(+), 16 deletions(-) create mode 100644 apps/lightcraft-web/src/host.rs diff --git a/apps/lightcraft-web/src/host.rs b/apps/lightcraft-web/src/host.rs new file mode 100644 index 0000000000..8b6a5997db --- /dev/null +++ b/apps/lightcraft-web/src/host.rs @@ -0,0 +1,340 @@ +//! The `postMessage` bridge to a same-origin parent page (`?host=parent`), for pages that embed +//! LightCraft in an `