LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
XMP: report unsupported photo import settings
Adrian D'souza20b6eb885e66
diff --git a/crates/engine/src/cmd/library.rs b/crates/engine/src/cmd/library.rsindex 436ad123b..a634f37fa 100644--- a/crates/engine/src/cmd/library.rs+++ b/crates/engine/src/cmd/library.rs@@ -1103,7 +1103,7 @@ pub fn specs() -> Vec<CommandSpec> {"Import Photos",["File"],Some("Cmd+Shift+I"),- "{paths: [file or folder (recursive)], mode?: add|copy|move (add = reference the files in place; copy = into the library's Originals/YYYY/YYYY-MM-DD/; move = as copy, then each original and its XMP sidecars are removed from the source — only after the copy is verified (a hard link on the same volume, else copied, synced and compared byte for byte) and its catalog record is saved; failed, duplicate and unchecked files keep their sources; a taken name gets -1, -2…; undo removes the photos from the library but leaves the files at the destination), destination?: folder for copies / moves, organize?: date (YYYY/YYYY-MM-DD) | month (YYYY/YYYY-MM) | flat | a folder template, e.g. `{date:%Y}/{date:%Y%m%d}` → 2026/20260114 (the template's `/` make the folders, each level expanded with the rename tokens and made a safe folder name: never outside the destination; must be relative, no `..`; a level with missing metadata is `unknown`) — dated by capture time, else the import time, rename?: file-name template for copies, original extension added (tokens: {name} {num} {seq} {seq:N} {date} {date:%Y%m%d} {folder} {camera} {lens} {iso} {rating} {title} {creator} {ext}; photo.renameTokens explains each; blank = keep names), renameStart?: 1, metadataPreset?: name, dng?: bool (copy raws as DNG; copy only), local?: bool (browsing: the photos stay out of the library, like library.browse; not with move), album?: albumId, albumName?: new album, preset?: presetId, keywords?: [..], onDeleted?: skip|restore|fresh (a file that is in Recently Deleted: skip = leave it there and say so, restore = bring the photo back with its edits, fresh = delete the trashed record and import the file as new)} → {imported, duplicates: [{path, existing, reason, existingDeleted?}], restored?: [photoId], failed, moved?: [{from, to, sidecars?}], kept?: [{path, reason}] (move: sources left in place and why), album?}",+ "{paths: [file or folder (recursive)], mode?: add|copy|move (add = reference the files in place; copy = into the library's Originals/YYYY/YYYY-MM-DD/; move = as copy, then each original and its XMP sidecars are removed from the source — only after the copy is verified (a hard link on the same volume, else copied, synced and compared byte for byte) and its catalog record is saved; failed, duplicate and unchecked files keep their sources; a taken name gets -1, -2…; undo removes the photos from the library but leaves the files at the destination), destination?: folder for copies / moves, organize?: date (YYYY/YYYY-MM-DD) | month (YYYY/YYYY-MM) | flat | a folder template, e.g. `{date:%Y}/{date:%Y%m%d}` → 2026/20260114 (the template's `/` make the folders, each level expanded with the rename tokens and made a safe folder name: never outside the destination; must be relative, no `..`; a level with missing metadata is `unknown`) — dated by capture time, else the import time, rename?: file-name template for copies, original extension added (tokens: {name} {num} {seq} {seq:N} {date} {date:%Y%m%d} {folder} {camera} {lens} {iso} {rating} {title} {creator} {ext}; photo.renameTokens explains each; blank = keep names), renameStart?: 1, metadataPreset?: name, dng?: bool (copy raws as DNG; copy only), local?: bool (browsing: the photos stay out of the library, like library.browse; not with move), album?: albumId, albumName?: new album, preset?: presetId, keywords?: [..], onDeleted?: skip|restore|fresh (a file that is in Recently Deleted: skip = leave it there and say so, restore = bring the photo back with its edits, fresh = delete the trashed record and import the file as new)} → {imported, duplicates: [{path, existing, reason, existingDeleted?}], restored?: [photoId], failed, warnings?: [per-photo XMP diagnostic], moved?: [{from, to, sidecars?}], kept?: [{path, reason}] (move: sources left in place and why), album?}",always,|s, p| {let req = import_params(s, p)?;diff --git a/crates/engine/src/crs.rs b/crates/engine/src/crs.rsindex 0b0c83b94..32e3c3ea9 100644--- a/crates/engine/src/crs.rs+++ b/crates/engine/src/crs.rs@@ -416,6 +416,22 @@ pub fn to_partial_report(props: &Props, values: Option<&crate::crs_masks::Values(out, unmapped)}+/// The selected camera profile name from an XMP packet. The name is metadata only: it does not+/// identify or carry the profile's rendering data.+pub fn camera_profile_name(props: &Props) -> Option<&str> {+ first(props, "crs:CameraProfile")+}++/// Whether an XMP packet contains a saved Lightroom Upright matrix. Lightroom's matrix uses a+/// coordinate convention that LightCraft does not currently import.+pub fn has_saved_upright_transform(props: &Props) -> bool {+ props.keys().any(|key| {+ key.strip_prefix("crs:").is_some_and(|name| {+ name.starts_with("UprightTransform_") && props.get(key).is_some_and(|values| values.iter().any(|v| !v.trim().is_empty()))+ })+ })+}+/// Read an XMP preset (`crs:` fields + `crs:Name` / `crs:Group`) into one of our presets./// Returns `None` when the packet has no adjustments we understand.pub fn preset_from_xmp(xmp: &str, fallback_name: &str) -> Option<Preset> {diff --git a/crates/engine/src/import.rs b/crates/engine/src/import.rsindex 282d93b79..b12b19e84 100644--- a/crates/engine/src/import.rs+++ b/crates/engine/src/import.rs@@ -198,6 +198,9 @@ pub struct ImportReport {pub scanned: usize,/// Photos whose metadata/develop settings were read from an XMP sidecar (or embedded XMP).pub sidecars: usize,+ /// Per-photo diagnostics from foreign XMP develop settings that could not be fully carried over.+ #[serde(skip_serializing_if = "Vec::is_empty")]+ pub warnings: Vec<String>,}/// A file moved by an import.@@ -1235,6 +1238,7 @@ pub fn commit_prepared(s: &mut Session, opts: &ImportOptions, now: &str, prepareif let Some(sc) = &sidecar {crate::sidecar::merge_into(&mut p, sc, &now);report.sidecars += 1;+ report.warnings.extend(sc.warnings.iter().map(|warning| format!("{path}: {warning}")));}if let Some(mp) = opts.metadata_preset.as_ref().and_then(|n| s.metadata_presets.iter().find(|m| m.name.eq_ignore_ascii_case(n))) {crate::cmd::metadata::apply_to(&mut p.meta, &mp.fields);diff --git a/crates/engine/src/sidecar.rs b/crates/engine/src/sidecar.rsindex 7e9249489..3cd0d132b 100644--- a/crates/engine/src/sidecar.rs+++ b/crates/engine/src/sidecar.rs@@ -104,6 +104,9 @@ pub struct SidecarData {/// `xmp:CreateDate` (first found). Used only when the file itself has no capture time.pub captured: Option<String>,pub develop: Option<DevelopPatch>,+ /// Actionable diagnostics for foreign develop settings that were not fully carried over.+ /// These are surfaced in the photo import report and never persisted in the catalog.+ pub warnings: Vec<String>,}#[derive(Clone, Debug, PartialEq)]@@ -162,7 +165,44 @@ pub fn parse_sidecar(xmp: &str, raw: bool) -> std::result::Result<SidecarData, Sout.develop = match full {Some(s) => Some(DevelopPatch::Full(Box::new(s))),None if crate::crs::has_adjustments(&d.properties) => {- Some(DevelopPatch::Partial(crate::crs::to_partial_report(&d.properties, Some(&d.values), Some(raw), crate::crs_masks::DEFAULT_ASPECT).0))+ let (mut partial, unmapped) = crate::crs::to_partial_report(&d.properties, Some(&d.values), Some(raw), crate::crs_masks::DEFAULT_ASPECT);+ let profile = crate::crs::camera_profile_name(&d.properties).map(str::to_string);+ if let Some(name) = &profile+ && let Some(profile) = partial.get_mut("profile").and_then(Value::as_object_mut)+ {+ // Keep the selected name for inspection and round trips. An unknown id renders+ // as LightCraft's neutral profile; the warning below makes that limitation clear.+ profile.insert("id".into(), Value::String(name.clone()));+ }+ if let Some(name) = profile {+ out.warnings.push(format!("{name} could not be applied; colors may differ from Lightroom."));+ }+ let upright = crate::crs::has_saved_upright_transform(&d.properties);+ if upright {+ let mode = d.properties.get("crs:PerspectiveUpright").and_then(|values| values.first()).map(String::as_str).unwrap_or_default();+ let mode = match mode {+ "1" => "Auto",+ "2" => "Level",+ "3" => "Vertical",+ "4" => "Full",+ "5" => "Guided",+ _ => "Upright",+ };+ out.warnings.push(format!("Lightroom geometry was not preserved; {mode} will be recalculated."));+ }+ let other: Vec<&str> = unmapped+ .iter()+ .map(String::as_str)+ .filter(|name| {+ *name != "CameraProfile"+ && !name.starts_with("UprightTransform_")+ && !matches!(*name, "UprightTransformCount" | "UprightCenterNormX" | "UprightCenterNormY" | "UprightVersion")+ })+ .collect();+ if !other.is_empty() {+ out.warnings.push(format!("XMP adjustments not imported: {}.", other.join(", ")));+ }+ Some(DevelopPatch::Partial(partial))}None => None,};diff --git a/crates/engine/src/tests_xmp.rs b/crates/engine/src/tests_xmp.rsindex fede1fec0..962042d97 100644--- a/crates/engine/src/tests_xmp.rs+++ b/crates/engine/src/tests_xmp.rs@@ -173,6 +173,51 @@ fn foreign_crs_sidecar_on_import_and_read_from_file() {let _ = std::fs::remove_dir_all(&src);}+/// Foreign profile names and saved Upright matrices stay visible without pretending their+/// proprietary colour or coordinate data was imported. Diagnostics are per-photo report data;+/// importing a file without XMP remains quiet, and the source packet is never rewritten.+#[test]+fn foreign_profile_and_upright_import_diagnostics_are_actionable() {+ let src = temp_dir("xmp-diagnostics");+ let photo = src.join("faithful.png");+ write_png(&photo, 6);+ let xmp = r#"<x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">+ <rdf:Description rdf:about="" xmlns:crs="http://ns.adobe.com/camera-raw-settings/1.0/"+ crs:CameraProfile="Camera Faithful" crs:Exposure2012="1.68" crs:PerspectiveUpright="1"+ crs:UprightVersion="151388160" crs:UprightTransformCount="6"+ crs:UprightCenterNormX="0.554156" crs:UprightCenterNormY="0.529745"+ crs:UprightTransform_1="0.897233402,-0.013204641,-0.030578613,-0.096087436,0.953621255,0.003270197,-0.157075841,-0.043520282,1.000000000"/>+ </rdf:RDF></x:xmpmeta>"#;+ let sidecar = src.join("faithful.xmp");+ std::fs::write(&sidecar, xmp).unwrap();+ let before = std::fs::read(&sidecar).unwrap();+ let mut s = Session::new().with_fs();+ let r = s.execute("library.import", &json!({"paths": [photo.to_string_lossy()]})).unwrap();+ let warnings = r["warnings"].as_array().unwrap();+ assert!(warnings.iter().any(|w| w.as_str().is_some_and(|w| w.contains("Camera Faithful could not be applied"))), "{r}");+ assert!(+ warnings+ .iter()+ .any(|w| w.as_str().is_some_and(|w| w.contains("Lightroom geometry was not preserved") && w.contains("Auto will be recalculated"))),+ "{r}"+ );+ let p = s.catalog.photos().next().unwrap();+ assert_eq!(p.develop.profile.id, "Camera Faithful");+ assert_eq!(p.develop.light.exposure, 1.68);+ assert_eq!(std::fs::read(&sidecar).unwrap(), before, "import never rewrites foreign XMP");++ // A second import still diagnoses the untouched foreign packet, while an XMP-free photo does not.+ drop(s);+ let clean = src.join("clean.png");+ write_png(&clean, 7);+ let mut s = Session::new().with_fs();+ let clean_report = s.execute("library.import", &json!({"paths": [clean.to_string_lossy()]})).unwrap();+ assert!(clean_report.get("warnings").is_none(), "{clean_report}");+ let repeat = s.execute("library.import", &json!({"paths": [photo.to_string_lossy()]})).unwrap();+ assert_eq!(repeat["warnings"].as_array().unwrap().len(), 2, "{repeat}");+ let _ = std::fs::remove_dir_all(&src);+}+const MWG_REGIONS: &str = r#"<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?><x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">diff --git a/docs/xmp-interop.md b/docs/xmp-interop.mdindex 735432312..ebdbb5d2e 100644--- a/docs/xmp-interop.md+++ b/docs/xmp-interop.md@@ -37,6 +37,10 @@ used — on import (it then also files a copied photo in its date folder) and by`xmp:Rating="-1"` (the XMP convention for rejected) sets the reject flag. Develop settings come from`lc:settings` when present (exact); otherwise from the `crs:` fields below (approximate).+When foreign `crs:` settings are only partly transferable, `library.import` includes per-photo `warnings` in its+report. Warnings identify unsupported profile names, saved Upright geometry that will be recalculated, and other+unmapped adjustments; they do not change the source packet or become catalog edits.+## Saving into an existing sidecarA sidecar may already hold another application's data — e.g. its `crs:` develop settings and `xmpMM:History` — often@@ -133,12 +137,14 @@ names are read (e.g. `Exposure2012`, not the older `Exposure`).| `DefringePurple/GreenAmount/HueLo/HueHi` | `optics.defringe_*` | || `ShadowTint`, `RedHue/Saturation`, `GreenHue/Saturation`, `BlueHue/Saturation` | `calibration.shadows_tint`, `calibration.red_hue/red_sat`, … | Calibration panel, 1:1 || `PerspectiveVertical/Horizontal/Rotate/Scale/Aspect/X/Y` | `geometry.vertical/horizontal/rotate/scale/aspect/offset_x/offset_y` | |-| `PerspectiveUpright` | `geometry.upright` | 0 off, 1 auto, 2 level, 3 vertical, 4 full, 5 guided |+| `PerspectiveUpright` | `geometry.upright` | 0 off, 1 auto, 2 level, 3 vertical, 4 full, 5 guided; saved `UprightTransform_*` matrices are not imported, so photo import reports that Lightroom geometry was not preserved and the selected mode will be recalculated || `HasCrop`, `CropLeft/Top/Right/Bottom`, `CropAngle` | `crop.geometry` | normalized edges → rect; angle in degrees; `HasCrop="False"` → no crop |Values pass through our control specs, so anything outside our slider ranges gets clamped.-**Not mapped:** camera profiles and looks (`CameraProfile`, `Look`; we have our own profile set), local adjustments+`crs:CameraProfile` is retained as its selected name in the photo's profile settings, but the name carries no+rendering data and does not select an Adobe profile. Photo import reports that the profile could not be applied and+colours may differ from Lightroom. Camera profiles and looks (`Look`; we have our own profile set), local adjustments(masks, gradients, brushes), spot removal, red eye, lens blur, process-version 2010 field names, and AI features.## Local corrections (masks)