LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Merge main into feat/copyright-status
Brandon Thomasefdd8a4e10e3
diff --cc crates/engine/src/cmd/library.rsindex 666477a29,3cd795a36..35c54eff0--- a/crates/engine/src/cmd/library.rs+++ b/crates/engine/src/cmd/library.rs@@@ -250,9 -250,9 +250,9 @@@ pub fn specs() -> Vec<CommandSpec>Ok(json!({"selected": s.selection.ids.len()}))}),cmd!(query "library.devices", "Cameras and Cards", [], None, "{} → [{name, path (its DCIM folder), root}] — mounted volumes with a DCIM folder", always, |_, _| {- Ok(serde_json::to_value(crate::devices::devices()).unwrap_or_default())+ Ok(serde_json::to_value(crate::devices::devices_now()).unwrap_or_default())}),- cmd!(query "photo.copyMetadata", "Copy Metadata", ["Photo"], None, "{} — title, caption, copyright, creator, location and keywords of the active photo", has_active, |s, _| {+ cmd!(query "photo.copyMetadata", "Copy Metadata", ["Photo"], None, "{} — title, caption, copyright (notice, status, usage terms, info URL), creator, location and keywords of the active photo", has_active, |s, _| {let id = s.active().ok_or_else(|| bad("photo.copyMetadata", "no active photo"))?;let m = &s.catalog.photo(id).ok_or_else(|| bad("photo.copyMetadata", "no photo"))?.meta;let v = json!({"title": m.title, "caption": m.caption, "altText": m.alt_text, "extendedDescription": m.extended_description,diff --cc crates/engine/src/tests_xmp.rsindex 6545cdb0c,c0331ea72..00b8e3b08--- a/crates/engine/src/tests_xmp.rs+++ b/crates/engine/src/tests_xmp.rs@@@ -446,81 -446,54 +446,133 @@@ fn dng_export_compression_choices()assert!(sizes[2].1 > sizes[0].1 && sizes[2].1 > sizes[1].1, "uncompressed is the biggest: {sizes:?}");}+ fn write_jpeg(path: &Path, capture: Option<&str>) {+ let (w, h) = (32usize, 24usize);+ let data: Vec<[u8; 4]> = (0..w * h).map(|i| [(i % w * 7) as u8, (i / w * 9) as u8, 90, 255]).collect();+ let img = lightcraft_raster::Rgba8 { width: w, height: h, data };+ let exif = capture.map(|c| {+ lightcraft_meta::write_exif(&lightcraft_meta::Metadata { capture_time: lightcraft_meta::DateTime::parse_iso(c), ..Default::default() })+ });+ let meta = lightcraft_codecs::EncodeMeta { exif: exif.as_deref(), ..Default::default() };+ let bytes = lightcraft_codecs::encode_jpeg(&lightcraft_codecs::EncodeImage::rgba8(&img), 90, Default::default(), &meta).unwrap();+ std::fs::write(path, bytes).unwrap();+ }++ const DATED_SIDECAR: &str = 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:exif="http://ns.adobe.com/exif/1.0/"+ exif:DateTimeOriginal="2026-01-14T05:58:48" />+ </rdf:RDF>+ </x:xmpmeta>"#;++ #[test]+ fn sidecar_capture_time_fills_in_when_the_file_has_none() {+ let src = temp_dir("sidecar-date");+ write_jpeg(&src.join("sample.jpg"), None);+ std::fs::write(src.join("sample.jpg.xmp"), DATED_SIDECAR).unwrap();+ // the embedded capture time wins over the sidecar's+ write_jpeg(&src.join("dated.jpg"), Some("2020-05-06T07:08:09"));+ std::fs::write(src.join("dated.jpg.xmp"), DATED_SIDECAR).unwrap();+ let lib = temp_dir("sidecar-date-lib");+ let mut s = Session::new().with_fs();+ s.open_library(&lib, false).unwrap();+ // copy: the sidecar's date also files the copy+ let r = s.execute("library.import", &json!({"paths": [src.to_string_lossy()], "mode": "copy"})).unwrap();+ assert_eq!(r["sidecars"], 2, "{r}");+ let by_name = |s: &Session, n: &str| s.catalog.photos().find(|p| p.file_name == n).unwrap().clone();+ let sample = by_name(&s, "sample.jpg");+ assert_eq!(sample.captured.as_deref(), Some("2026-01-14T05:58:48"));+ let lightcraft_catalog::Source::File { path } = &sample.source else { panic!("not a file") };+ assert!(Path::new(path).starts_with(lib.join("Originals").join("2026").join("2026-01-14")), "{path}");+ assert_eq!(by_name(&s, "dated.jpg").captured.as_deref(), Some("2020-05-06T07:08:09"));++ // Read Metadata from File fills in a missing capture time too+ let id = sample.id;+ s.catalog.apply(lightcraft_catalog::Op::SetCaptured { id, captured: None }).unwrap();+ std::fs::copy(src.join("sample.jpg.xmp"), format!("{path}.xmp")).unwrap();+ s.execute("library.select", &json!({"ids": [id.0]})).unwrap();+ s.execute("photo.readMetadataFromFile", &json!({})).unwrap();+ assert_eq!(s.catalog.photo(id).unwrap().captured.as_deref(), Some("2026-01-14T05:58:48"));+ let _ = std::fs::remove_dir_all(&src);+ let _ = std::fs::remove_dir_all(&lib);+ }+++/// Copyright status, rights usage terms and copyright info URL: edited with `photo.setMeta` (one+/// undo step), copied / pasted, kept in metadata presets, written to the sidecar as XMP Rights+/// Management fields and read back on a fresh import.+#[test]+fn copyright_status_usage_terms_and_url_round_trip() {+ use lightcraft_catalog::CopyrightStatus;+ let src = temp_dir("rights-src");+ let lib = temp_dir("rights-lib");+ write_png(&src.join("a.png"), 1);+ write_png(&src.join("b.png"), 2);+ let mut s = Session::new().with_fs();+ s.open_library(&lib, false).unwrap();+ s.execute("library.import", &json!({"paths": [src.to_string_lossy()]})).unwrap();+ let id = |s: &Session, name: &str| s.catalog.photos().find(|p| p.file_name == name).unwrap().id;+ let (a, b) = (id(&s, "a.png"), id(&s, "b.png"));+ let meta = |s: &Session, id: PhotoId| s.catalog.photo(id).unwrap().meta.clone();+ assert_eq!(meta(&s, a).copyright_status, CopyrightStatus::Unknown);+ s.execute("library.select", &json!({"ids": [a.0]})).unwrap();+ s.execute(+ "photo.setMeta",+ &json!({"copyright": "© 2026 A. Person", "copyrightStatus": "copyrighted", "usageTerms": "Editorial use only", "copyrightUrl": "https://example.com/rights"}),+ )+ .unwrap();+ let m = meta(&s, a);+ assert_eq!(+ (m.copyright_status, m.usage_terms.as_str(), m.copyright_url.as_str()),+ (CopyrightStatus::Copyrighted, "Editorial use only", "https://example.com/rights")+ );+ assert!(s.execute("photo.setMeta", &json!({"copyrightStatus": "maybe"})).is_err());+ s.execute("edit.undo", &json!({})).unwrap();+ assert_eq!(meta(&s, a).copyright_status, CopyrightStatus::Unknown, "one undo step");+ s.execute("edit.redo", &json!({})).unwrap();+ // copy → paste onto b+ let clip = s.execute("photo.copyMetadata", &json!({})).unwrap();+ assert_eq!(clip["copyrightStatus"], "copyrighted");+ s.execute("photo.pasteMetadata", &json!({"ids": [b.0], "fields": ["copyrightStatus", "usageTerms"]})).unwrap();+ let mb = meta(&s, b);+ assert_eq!((mb.copyright_status, mb.usage_terms.as_str(), mb.copyright_url.as_str()), (CopyrightStatus::Copyrighted, "Editorial use only", ""));+ // a metadata preset from the active photo carries the copyright fields; applying it sets them+ s.execute("metadata.savePreset", &json!({"name": "Rights"})).unwrap();+ let presets = s.execute("metadata.presets", &json!({})).unwrap();+ assert_eq!(presets[0]["fields"]["copyrightStatus"], "copyrighted", "{presets}");+ assert_eq!(presets[0]["fields"]["copyrightUrl"], "https://example.com/rights");+ s.execute("photo.setMeta", &json!({"ids": [b.0], "copyrightStatus": "publicDomain", "usageTerms": ""})).unwrap();+ s.execute("metadata.applyPreset", &json!({"name": "Rights", "ids": [b.0]})).unwrap();+ let mb = meta(&s, b);+ assert_eq!((mb.copyright_status, mb.copyright_url.as_str()), (CopyrightStatus::Copyrighted, "https://example.com/rights"));+ assert!(s.execute("metadata.savePreset", &json!({"name": "Bad", "fields": {"copyrightStatus": "sort of"}})).is_err());+ // b becomes public domain; smart-album rule on the status+ s.execute("photo.setMeta", &json!({"ids": [b.0], "copyrightStatus": "public domain"})).unwrap();+ let r = s+ .execute(+ "album.createSmart",+ &json!({"name": "PD", "rules": {"ruleSet": {"rules": [{"field": "copyrightStatus", "op": "is", "value": "publicDomain"}]}}}),+ )+ .unwrap();+ assert_eq!(r["count"], 1, "{r}");+ // sidecars: XMP Rights Management fields, read back by a fresh library+ s.execute("photo.saveMetadataToFile", &json!({"ids": [a.0, b.0]})).unwrap();+ let xmp = std::fs::read_to_string(src.join("a.xmp")).unwrap();+ assert!(xmp.contains("<xmpRights:Marked>True</xmpRights:Marked>"), "{xmp}");+ assert!(xmp.contains("<xmpRights:WebStatement>https://example.com/rights</xmpRights:WebStatement>"), "{xmp}");+ assert!(std::fs::read_to_string(src.join("b.xmp")).unwrap().contains("<xmpRights:Marked>False</xmpRights:Marked>"));+ let expect_a = meta(&s, a);+ drop(s);+ std::fs::remove_dir_all(&lib).unwrap();+ let mut s = Session::new().with_fs();+ s.open_library(&lib, false).unwrap();+ s.execute("library.import", &json!({"paths": [src.to_string_lossy()]})).unwrap();+ let ma = meta(&s, id(&s, "a.png"));+ assert_eq!(+ (ma.copyright.as_str(), ma.copyright_status, ma.usage_terms.as_str(), ma.copyright_url.as_str()),+ (expect_a.copyright.as_str(), CopyrightStatus::Copyrighted, "Editorial use only", "https://example.com/rights")+ );+ assert_eq!(meta(&s, id(&s, "b.png")).copyright_status, CopyrightStatus::PublicDomain);+ let _ = std::fs::remove_dir_all(&src);+ let _ = std::fs::remove_dir_all(&lib);+}diff --cc docs/parity.mdindex 06be8dba6,7fffddfe2..4b6abd691--- a/docs/parity.md+++ b/docs/parity.md@@@ -190,11 -190,11 +190,11 @@@ under the UI command that wraps it (a n| Id | Feature | Tier | Status | Evidence | Missing / notes ||---|---|---|---|---|---|-| LR-META-INFO | Info panel | P0 | ✅ | `cmd:panel.info`, `cmd:photo.setMeta`, `crates/ui-egui/src/panels/right.rs` (`info`, `camera_card`) | camera card (camera, lens, size, format, focal length / shutter / aperture / ISO); title, caption, alt text, extended description, copyright, creator; file name (rename), file path (reveal), capture time (edit); location, city, state, country; GPS. No flash, map snippet or people |+| LR-META-INFO | Info panel | P0 | ✅ | `cmd:panel.info`, `cmd:photo.setMeta`, `crates/ui-egui/src/panels/right.rs` (`info`, `camera_card`) | camera card (camera, lens, size, format, focal length / shutter / aperture / ISO); title, caption, alt text, extended description, copyright, copyright status, rights usage terms, copyright info URL, creator; file name (rename), file path (reveal), capture time (edit); location, city, state, country; GPS. No flash, map snippet or people || LR-META-COPYRIGHT-DEFAULT | Default copyright on import | P1 | ✅ | `cmd:library.preferences` (`import.copyright`, `import.creator`), `crates/ui-egui/src/panels/settings.rs` | Settings → Import → Metadata; fills only photos without their own || LR-META-LOCATION | Location editing | P2 | 🟡 | `cmd:photo.setMeta` (`location`, `city`, `state`, `country`, `gps`) | 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; no embedded map, no geocoding |-| LR-META-COPYPASTE | Copy / paste metadata | P2 | ✅ | `cmd:photo.copyMetadata`, `cmd:photo.pasteMetadata` | title, caption, alt text, extended description, copyright, creator, place fields, keywords; `fields` picks a subset |+| 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` | |+ | 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 || 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 |## F. Edit panel — global adjustments (EDIT)