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 <noreply@anthropic.com>

* Export: strip the maker from Model only as a separate word

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

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 <noreply@anthropic.com>
This commit is contained in:
eliets2
2026-11-06 10:56:51 +01:00
committed by GitHub
co-authored by Claude Opus 5.5 eliets2 FredApps
parent 9c07f427f0
commit a856df5f42
5 changed files with 43 additions and 1 deletions
+6
View File
@@ -171,7 +171,13 @@ pub fn parse_shutter_seconds(s: &str) -> Option<f64> {
#[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<f32>,
pub aperture: Option<f32>,
pub shutter: String,
+6
View File
@@ -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();
}
+5 -1
View File
@@ -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);
+2
View File
@@ -7,6 +7,8 @@ pub(super) fn meta_of(m: &lightcraft_meta::Metadata) -> (Meta, Option<String>) {
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),
+24
View File
@@ -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() {