LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Merge PR #434
Claude4ec34947335b
diff --cc crates/engine/src/cmd/library.rsindex 263f94c2b,b8225026c..2d06d73f6--- a/crates/engine/src/cmd/library.rs+++ b/crates/engine/src/cmd/library.rs@@@ -1365,7 -1330,7 +1369,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?: restore|skip|fresh (a file that is in Recently Deleted: restore (default) = bring the photo back with its edits — relinked to the file when its own is gone, skip = leave it there and say so, 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?: [{path, code: cameraProfile|uprightGeometry|unmappedXmp, profile?, mode?: off|auto|level|vertical|full|guided|unknown, fields?}], 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?: restore|skip|fresh (a file that is in Recently Deleted: restore (default) = bring the photo back with its edits — relinked to the file when its own is gone, skip = leave it there and say so, fresh = delete the trashed record and import the file as new)} → {imported, duplicates: [{path, existing, reason, existingDeleted?}], restored?: [photoId], failed, warnings?: [{path, code: cameraProfile|uprightGeometry|unmappedXmp, profile?, mode?: off|auto|level|vertical|full|guided|unknown, fields?}], 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 --cc crates/engine/src/sidecar.rsindex 5257a0187,ed5a9bb73..4f44780ec--- a/crates/engine/src/sidecar.rs+++ b/crates/engine/src/sidecar.rs@@@ -165,7 -168,61 +168,65 @@@ pub fn parse_sidecar(xmp: &str, targetout.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), target, crate::crs_masks::DEFAULT_ASPECT).0))+ let (partial, unmapped) = crate::crs::to_partial_report(&d.properties, Some(&d.values), target, crate::crs_masks::DEFAULT_ASPECT);- let profile = crate::crs::camera_profile_name(&d.properties).map(str::to_string);++ // Lightroom's default profiles are named by nearly every sidecar; our own starting look stands++ // in for them, so only another profile is worth a warning++ let profile = crate::crs::camera_profile_name(&d.properties)++ .filter(|name| !matches!(name.trim(), "Adobe Standard" | "Adobe Color"))++ .map(str::to_string);+ if let Some(name) = profile {+ out.warnings.push(crate::import::ImportWarning {+ path: String::new(),+ code: crate::import::ImportWarningCode::CameraProfile,+ profile: Some(name),+ mode: None,+ fields: Vec::new(),+ });+ }+ 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)+ .map(|mode| match mode {+ "0" => crate::import::ImportUprightMode::Off,+ "1" => crate::import::ImportUprightMode::Auto,+ "2" => crate::import::ImportUprightMode::Level,+ "3" => crate::import::ImportUprightMode::Vertical,+ "4" => crate::import::ImportUprightMode::Full,+ "5" => crate::import::ImportUprightMode::Guided,+ _ => crate::import::ImportUprightMode::Unknown,+ })+ .unwrap_or(crate::import::ImportUprightMode::Unknown);+ out.warnings.push(crate::import::ImportWarning {+ path: String::new(),+ code: crate::import::ImportWarningCode::UprightGeometry,+ profile: None,+ mode: Some(mode),+ fields: Vec::new(),+ });+ }+ 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(crate::import::ImportWarning {+ path: String::new(),+ code: crate::import::ImportWarningCode::UnmappedXmp,+ profile: None,+ mode: None,+ fields: other.into_iter().map(str::to_string).collect(),+ });+ }+ Some(DevelopPatch::Partial(partial))}None => None,};diff --cc crates/engine/src/tests_xmp.rsindex 57981d920,9eceb7e9f..14732d284--- a/crates/engine/src/tests_xmp.rs+++ b/crates/engine/src/tests_xmp.rs@@@ -171,6 -171,111 +171,136 @@@ fn foreign_crs_sidecar_on_import_and_restd::fs::remove_file(src.join("harbour.xmp")).unwrap();let r = s.execute("photo.readMetadataFromFile", &json!({})).unwrap();assert_eq!(r["failed"].as_array().unwrap().len(), 1);+ assert!(r.get("warnings").is_none(), "{r}");+ let _ = std::fs::remove_dir_all(&src);+ }+++/// Lightroom's default profiles (`Adobe Standard`, `Adobe Color`) are named by nearly every sidecar++/// and our own starting look stands in for them: importing one gives no camera-profile warning.++#[test]++fn default_lightroom_profiles_are_not_reported() {++ let src = temp_dir("xmp-default-profile");++ for (i, name) in ["Adobe Standard", "Adobe Color"].into_iter().enumerate() {++ let photo = src.join(format!("p{i}.png"));++ write_png(&photo, 6);++ let xmp = format!(++ 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="{name}" crs:Exposure2012="0.5"/>++ </rdf:RDF></x:xmpmeta>"#++ );++ std::fs::write(src.join(format!("p{i}.xmp")), xmp).unwrap();++ let mut s = Session::new().with_fs();++ let r = s.execute("library.import", &json!({"paths": [photo.to_string_lossy()]})).unwrap();++ let none = Vec::new();++ let warnings = r["warnings"].as_array().unwrap_or(&none);++ assert!(!warnings.iter().any(|w| w["code"] == "cameraProfile"), "{name}: {r}");++ assert_eq!(s.catalog.photos().next().unwrap().develop.light.exposure, 0.5, "{name}: the edits still import");++ }++ 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 photo_path = photo.to_string_lossy().to_string();+ 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["code"] == "cameraProfile" && w["profile"] == "Camera Faithful"), "{r}");+ assert!(warnings.iter().any(|w| w["code"] == "uprightGeometry" && w["mode"] == "auto"), "{r}");+ assert!(warnings.iter().all(|w| w.get("fields").is_none()), "{r}");+ let import_warnings: Vec<crate::import::ImportWarning> =+ warnings.iter().cloned().map(serde_json::from_value).collect::<std::result::Result<_, _>>().unwrap();+ let import_profile = import_warnings.iter().find(|w| w.code == crate::import::ImportWarningCode::CameraProfile).unwrap();+ assert_eq!(import_profile.path, photo_path);+ assert_eq!(import_profile.profile.as_deref(), Some("Camera Faithful"));+ assert!(import_profile.fields.is_empty());+ let import_upright = import_warnings.iter().find(|w| w.code == crate::import::ImportWarningCode::UprightGeometry).unwrap();+ assert_eq!(import_upright.path, photo_path);+ assert_eq!(import_upright.mode, Some(crate::import::ImportUprightMode::Auto));+ assert!(import_upright.fields.is_empty());+ let p = s.catalog.photos().next().unwrap().clone();+ assert_eq!(p.develop.profile.id, "lc.color");+ assert_eq!(p.develop.light.exposure, 1.68);+ assert_eq!(std::fs::read(&sidecar).unwrap(), before, "import never rewrites foreign XMP");++ // Metadata reread carries same structured diagnostics, with each saved Upright mode typed.+ let reread = s.execute("photo.readMetadataFromFile", &json!({"ids": [p.id.0]})).unwrap();+ let reread_wires = reread["warnings"].as_array().unwrap();+ assert!(reread_wires.iter().all(|w| w.get("fields").is_none()), "{reread}");+ let reread_warnings: Vec<crate::import::ImportWarning> =+ reread_wires.iter().cloned().map(serde_json::from_value).collect::<std::result::Result<_, _>>().unwrap();+ let reread_profile = reread_warnings.iter().find(|w| w.code == crate::import::ImportWarningCode::CameraProfile).unwrap();+ assert_eq!(reread_profile.path, photo_path);+ assert_eq!(reread_profile.profile.as_deref(), Some("Camera Faithful"));+ assert!(reread_profile.fields.is_empty());+ let reread_upright = reread_warnings.iter().find(|w| w.code == crate::import::ImportWarningCode::UprightGeometry).unwrap();+ assert_eq!(reread_upright.path, photo_path);+ assert_eq!(reread_upright.mode, Some(crate::import::ImportUprightMode::Auto));+ assert!(reread_upright.fields.is_empty());+ assert!(+ reread["warnings"]+ .as_array()+ .unwrap()+ .iter()+ .any(|w| w["code"] == "cameraProfile" && w["profile"] == "Camera Faithful" && w["path"] == photo_path),+ "{reread}"+ );+ assert!(reread["warnings"].as_array().unwrap().iter().any(|w| w["code"] == "uprightGeometry" && w["mode"] == "auto"), "{reread}");+ for (source, mode) in [("0", "off"), ("2", "level"), ("3", "vertical"), ("4", "full"), ("5", "guided"), ("9", "unknown")] {+ let mode_xmp = xmp.replace("crs:PerspectiveUpright=\"1\"", &format!("crs:PerspectiveUpright=\"{source}\""));+ std::fs::write(&sidecar, mode_xmp).unwrap();+ let reread = s.execute("photo.readMetadataFromFile", &json!({"ids": [p.id.0]})).unwrap();+ assert!(reread["warnings"].as_array().unwrap().iter().any(|w| w["code"] == "uprightGeometry" && w["mode"] == mode), "{source}: {reread}");+ }++ // A foreign name colliding with a built-in profile label remains warning metadata only.+ let collision = src.join("collision.png");+ write_png(&collision, 8);+ std::fs::write(src.join("collision.xmp"), xmp.replace("Camera Faithful", "Color")).unwrap();+ let collision_report = s.execute("library.import", &json!({"paths": [collision.to_string_lossy()]})).unwrap();+ assert!(+ collision_report["warnings"].as_array().unwrap().iter().any(|w| w["code"] == "cameraProfile" && w["profile"] == "Color"),+ "{collision_report}"+ );+ let collision_photo = s.catalog.photos().find(|photo| photo.file_name == "collision.png").unwrap();+ assert_eq!(collision_photo.develop.profile.id, "lc.color");++ let unmapped = crate::import::ImportWarning {+ path: photo_path.clone(),+ code: crate::import::ImportWarningCode::UnmappedXmp,+ profile: None,+ mode: None,+ fields: vec!["Tint".into()],+ };+ let unmapped_wire = serde_json::to_value(&unmapped).unwrap();+ assert_eq!(serde_json::from_value::<crate::import::ImportWarning>(unmapped_wire).unwrap(), unmapped);++ // 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);}diff --cc docs/xmp-interop.mdindex 28a88a8d4,f8e5bea61..3669d1199--- a/docs/xmp-interop.md+++ b/docs/xmp-interop.md@@@ -141,27 -144,10 +145,29 @@@ application's renderer and is ignored:Values pass through our control specs, so anything outside our slider ranges gets clamped.-`crs:CameraProfile` is retained as its selected name in the photo import warning metadata, while active profile-settings stay unchanged: 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.++`crs:CameraProfile` is kept as the selected name in the photo's import warning and the active profile is left as it is: the name carries no rendering data and never selects an Adobe profile. Import reports such a profile as not applied (colours may differ from Lightroom), except Lightroom's default profiles (`Adobe Standard`, `Adobe Color`), which every sidecar names and which LightCraft's own starting look stands in for.+++**Not mapped:** camera profiles and looks (`CameraProfile`, `Look`; we have our own profile set), red eye, lens blur,+process-version 2010 field names, and AI features. Local adjustments and spot removal are read as described below.++## Spot removal++Heal and clone spots stored as `crs:RetouchAreas` (one structure per spot, a mask component inside) and the older+`crs:RetouchInfo` list (one `key = value, …` line per spot; read on its own when it is all a packet has) become our+spots (`crates/engine/src/crs_masks.rs`, `spots`). Implemented from the public data model and by observing what a+sidecar written for a healed photo contains.++| Field | Ours | Notes |+|---|---|---|+| `SpotType` | `mode` | `heal` (default) or `clone`; the removal method (`Method`) is ours |+| `Masks` → `Mask/Ellipse` (`X`, `Y`, `SizeX`) | a circle spot | centre in image fractions; `SizeX` is a fraction of the width, our size of the long edge |+| `Masks` → `Mask/CircularGradient` (`Top/Left/Bottom/Right`) | a circle spot | the box's centre and half-width |+| `Masks` → `Mask/Paint` (`Dabs`, `Radius`) | a brushed spot | the dabs are the path |+| `SourceX`, `OffsetY` | `source_offset` | the source's **absolute** x and y (despite the name); ours is the offset from the target. Only with `SourceState="sourceSetExplicitly"` (or no state); anything else leaves the source automatic |+| `Opacity`, `Feather` | `opacity`, `feather` | 0..1 → 0..100 |++A spot whose mask is any other kind is reported as `Spot: <kind>`. Sizes are clamped to our spot range. A sidecar's+spots replace the photo's, as its masks do.## Local corrections (masks)