From a856df5f422bc07044a6beaf5bfdb920292bb1c7 Mon Sep 17 00:00:00 2001 From: eliets2 Date: Fri, 6 Nov 2026 11:56:51 +0200 Subject: [PATCH] Write camera make and lens make to EXIF on export (#3828) * Write camera make and lens make to EXIF on export PTGui and similar stitching tools read EXIF Make/LensMake to identify camera and lens; without them, exported JPEGs from CR2 files are not recognized the same way as Adobe's export. Add make and lens_make fields to catalog Meta, populate them from the raw's EXIF on import in meta_of, and write them as EXIF Make and LensMake tags in export_metadata. Test: export_writes_camera_make_and_lens_make_to_exif failed before the change and passes after. * Export: read Make and LensMake on import and write them, with Model on its own Co-Authored-By: Claude Opus 5.5 * Export: strip the maker from Model only as a separate word Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: eliets2 <287273517+eliets2@users.noreply.github.com> Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 --- crates/catalog/src/model.rs | 6 ++++++ crates/engine/src/cmd/convert.rs | 6 ++++++ crates/engine/src/export/encoding.rs | 6 +++++- crates/engine/src/files/probe.rs | 2 ++ crates/engine/src/tests/export.rs | 24 ++++++++++++++++++++++++ 5 files changed, 43 insertions(+), 1 deletion(-) diff --git a/crates/catalog/src/model.rs b/crates/catalog/src/model.rs index 69a99bd803..ebf2d1ef08 100644 --- a/crates/catalog/src/model.rs +++ b/crates/catalog/src/model.rs @@ -171,7 +171,13 @@ pub fn parse_shutter_seconds(s: &str) -> Option { #[serde(default)] pub struct Meta { pub camera: String, + /// The camera's maker, from Exif `Make` (`camera` is maker and model together). + #[serde(skip_serializing_if = "String::is_empty")] + pub make: String, pub lens: String, + /// The lens's maker, from Exif `LensMake`. + #[serde(skip_serializing_if = "String::is_empty")] + pub lens_make: String, pub focal_mm: Option, pub aperture: Option, pub shutter: String, diff --git a/crates/engine/src/cmd/convert.rs b/crates/engine/src/cmd/convert.rs index c3dd8733f1..261a4dd018 100644 --- a/crates/engine/src/cmd/convert.rs +++ b/crates/engine/src/cmd/convert.rs @@ -233,6 +233,12 @@ fn fill_missing_meta(id: lightcraft_catalog::PhotoId, ph: &lightcraft_catalog::P if m.lens.is_empty() { m.lens = src.lens.clone(); } + if m.make.is_empty() { + m.make = src.make.clone(); + } + if m.lens_make.is_empty() { + m.lens_make = src.lens_make.clone(); + } if m.shutter.is_empty() { m.shutter = src.shutter.clone(); } diff --git a/crates/engine/src/export/encoding.rs b/crates/engine/src/export/encoding.rs index 862c72cd01..ecdc32aa31 100644 --- a/crates/engine/src/export/encoding.rs +++ b/crates/engine/src/export/encoding.rs @@ -334,7 +334,11 @@ pub fn export_metadata(photo: &lightcraft_catalog::Photo, catalog: &lightcraft_c out.gps = m.gps.map(|(latitude, longitude)| Gps { latitude, longitude, altitude: None }); } if o.metadata == MetadataPolicy::All { - out.model = text(&m.camera); + // `camera` is maker and model together: Exif keeps them apart, and a photo from before + // the maker was read keeps the whole string as its Model + out.make = text(&m.make); + out.model = text(m.camera.strip_prefix(m.make.as_str()).and_then(|rest| rest.strip_prefix(' ')).unwrap_or(&m.camera)); + out.lens_make = text(&m.lens_make); out.lens_model = text(&m.lens); out.focal_length = m.focal_mm.map(f64::from); out.f_number = m.aperture.map(f64::from); diff --git a/crates/engine/src/files/probe.rs b/crates/engine/src/files/probe.rs index 481d4aabc9..b4e88943e6 100644 --- a/crates/engine/src/files/probe.rs +++ b/crates/engine/src/files/probe.rs @@ -7,6 +7,8 @@ pub(super) fn meta_of(m: &lightcraft_meta::Metadata) -> (Meta, Option) { let camera = [m.make.clone().unwrap_or_default(), m.model.clone().unwrap_or_default()].join(" ").trim().to_string(); let meta = Meta { camera, + make: m.make.clone().unwrap_or_default(), + lens_make: m.lens_make.clone().unwrap_or_default(), // (a camera that writes no lens name, like Nikon's DSLRs, still says what range the lens covers) lens: m.lens_model.clone().or_else(|| m.lens_spec.and_then(lightcraft_meta::lens_spec_name)).unwrap_or_default(), focal_mm: m.focal_length.map(|f| f as f32), diff --git a/crates/engine/src/tests/export.rs b/crates/engine/src/tests/export.rs index bd5124d71e..1bddd2c44c 100644 --- a/crates/engine/src/tests/export.rs +++ b/crates/engine/src/tests/export.rs @@ -945,6 +945,30 @@ fn metadata_none_in_any_case_exports_no_metadata() { assert!(m.gps.is_none() && m.city.is_none(), "{m:?}"); } +/// A raw's Exif Make, Model and LensMake reach an exported JPEG apart, as stitching tools read them. +#[test] +fn export_writes_camera_make_and_lens_make_to_exif() { + let dir = temp_dir("export-raw-exif"); + let src = dir.join("Canon.dng"); + let meta = lightcraft_meta::Metadata { + make: Some("Canon".into()), + model: Some("EOS R5".into()), + lens_make: Some("Sigma".into()), + lens_model: Some("RF 24-105mm f/4L IS USM".into()), + ..Default::default() + }; + std::fs::write(&src, synthetic_dng_with(None, meta)).unwrap(); + let mut s = Session::new().with_fs(); + s.execute("library.import", &json!({"paths": [src.to_string_lossy()]})).unwrap(); + let id = s.catalog.photos().next().unwrap().id; + let e = export_photo(&mut s, id, &ExportOptions::from_json(&json!({"format": "jpeg", "longEdge": 64, "metadata": "all"})), 1).unwrap(); + let back = lightcraft_meta::extract(&e.bytes); + assert_eq!(back.make.as_deref(), Some("Canon"), "EXIF Make is missing: {back:?}"); + assert_eq!(back.model.as_deref(), Some("EOS R5"), "EXIF Model holds the model alone: {back:?}"); + assert_eq!(back.lens_make.as_deref(), Some("Sigma"), "EXIF LensMake is missing: {back:?}"); + let _ = std::fs::remove_dir_all(&dir); +} + /// An original raw whose own metadata holds GPS is refused under "Remove location info". #[test] fn remove_location_refuses_a_raw_that_embeds_gps() {