LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Merge PR #664
Claude62ece65ac99b
diff --cc crates/engine/src/tests_export.rsindex da4a249bd,6c418cf97..aaecc0b39--- a/crates/engine/src/tests_export.rs+++ b/crates/engine/src/tests_export.rs@@@ -455,65 -441,27 +455,90 @@@ fn hdr_avif_export_is_pq_rec2020()assert!(nclx(&sdr.bytes).is_none_or(|c| c[3] != 16));}+/// "Remove location info" holds for the file-copying formats too: the sidecar and the DNG's+/// packet carry no location, and an original that embeds GPS is refused rather than copied.+#[test]+fn remove_location_holds_for_original_and_dng_exports() {+ let dir = temp_dir("export-noloc");+ let gps =+ lightcraft_meta::Metadata { gps: Some(lightcraft_meta::Gps { latitude: 48.85, longitude: 2.35, altitude: None }), ..Default::default() };+ // a raw with no embedded GPS, located in the catalog+ let raw = dir.join("Raw.dng");+ std::fs::write(&raw, synthetic_dng_with(None, Default::default())).unwrap();+ // a JPEG with GPS in its EXIF+ let jpg = dir.join("Geo.jpg");+ let img = lightcraft_raster::Rgba8::from_fn(32, 24, |x, y| [(x * 8) as u8, (y * 10) as u8, 90, 255]);+ let exif = lightcraft_meta::write_exif(&gps);+ let meta = lightcraft_codecs::EncodeMeta { exif: Some(&exif), ..Default::default() };+ std::fs::write(&jpg, lightcraft_codecs::encode_jpeg(&lightcraft_codecs::EncodeImage::rgba8(&img), 90, Default::default(), &meta).unwrap())+ .unwrap();+ let mut s = Session::new().with_fs();+ s.execute("library.import", &json!({"paths": [raw.to_string_lossy(), jpg.to_string_lossy()]})).unwrap();+ let id = |s: &Session, n: &str| s.catalog.photos().find(|p| p.file_name == n).unwrap().id;+ let (rid, jid) = (id(&s, "Raw.dng"), id(&s, "Geo.jpg"));+ s.execute("photo.setMeta", &json!({"ids": [rid.0, jid.0], "gps": [48.85, 2.35], "city": "Paris"})).unwrap();+ let opts = |f: &str, remove: bool| ExportOptions::from_json(&json!({"format": f, "removeLocation": remove}));++ // original raw: the sidecar keeps the location unless it is removed+ let side = |e: &crate::export::Exported| lightcraft_meta::parse_xmp(std::str::from_utf8(&e.sidecars[0].1).unwrap()).unwrap().metadata;+ let kept = side(&export_photo(&mut s, rid, &opts("original", false), 1).unwrap());+ assert!(kept.gps.is_some() && kept.city.is_some());+ let gone = side(&export_photo(&mut s, rid, &opts("original", true), 1).unwrap());+ assert!(gone.gps.is_none() && gone.city.is_none(), "{gone:?}");++ // dng: the embedded packet+ let e = export_photo(&mut s, rid, &opts("dng", false), 1).unwrap();+ assert!(lightcraft_meta::extract(&e.bytes).gps.is_some());+ let e = export_photo(&mut s, rid, &opts("dng", true), 1).unwrap();+ let m = lightcraft_meta::extract(&e.bytes);+ assert!(m.gps.is_none() && m.city.is_none(), "{m:?}");++ // original JPEG embedding GPS: copied as is normally, refused when the location must go+ let e = export_photo(&mut s, jid, &opts("original", false), 1).unwrap();+ assert!(lightcraft_meta::extract(&e.bytes).gps.is_some());+ let err = export_photo(&mut s, jid, &opts("original", true), 1).err().unwrap();+ assert!(err.contains("can't remove the location") && err.contains("export as JPEG"), "{err}");+ 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() {+ let dir = temp_dir("export-noloc-raw");+ let gps = lightcraft_meta::Metadata { gps: Some(lightcraft_meta::Gps { latitude: 10.0, longitude: 20.0, altitude: None }), ..Default::default() };+ let raw = dir.join("Geo.dng");+ let bytes = synthetic_dng_with(Some(&lightcraft_meta::write_xmp(&gps, None)), Default::default());+ assert!(lightcraft_meta::extract(&bytes).gps.is_some(), "fixture embeds GPS");+ std::fs::write(&raw, bytes).unwrap();+ let mut s = Session::new().with_fs();+ s.execute("library.import", &json!({"paths": [raw.to_string_lossy()]})).unwrap();+ let id = s.catalog.photos().next().unwrap().id;+ let err = export_photo(&mut s, id, &ExportOptions::from_json(&json!({"format": "original", "removeLocation": true})), 1).err().unwrap();+ assert!(err.contains("can't remove the location"), "{err}");+ let _ = std::fs::remove_dir_all(&dir);+}+++ #[test]+ fn hdr_png_export_is_16_bit_pq_rec2020() {+ let mut s = Session::with_demo();+ let id = sunset(&mut s);+ let o = ExportOptions::from_json(&json!({"longEdge": 160, "format": "png", "hdr": true}));+ assert!(o.hdr_output());+ assert_eq!(o.effective_space(), lightcraft_pipeline::OutputSpace::Rec2020);+ // a photo without an HDR edit exports as an ordinary (sRGB, 8-bit) PNG+ let sdr = export_photo(&mut s, id, &o, 1).unwrap();+ assert!(!sdr.bytes.windows(4).any(|w| w == b"cICP"));+ assert_eq!(sdr.bytes[24], 8, "8-bit");+ s.execute("develop.hdr", &json!({"enabled": true, "maxEv": 2})).unwrap();+ let hdr = export_photo(&mut s, id, &o, 1).unwrap();+ let at = hdr.bytes.windows(4).position(|w| w == b"cICP").expect("cICP chunk");+ assert_eq!(&hdr.bytes[at + 4..at + 8], &[9, 16, 0, 1], "BT.2020, PQ, RGB, full range");+ assert_eq!(hdr.bytes[24], 16, "16-bit");+ // the highlights above SDR white are there: MaxCLL beyond the 203 cd/m² of SDR white+ let at = hdr.bytes.windows(4).position(|w| w == b"cLLI").expect("cLLI chunk");+ let max_cll = u32::from_be_bytes(hdr.bytes[at + 4..at + 8].try_into().unwrap()) as f32 / 10_000.0;+ assert!(max_cll > 250.0 && max_cll <= 4.0 * 203.0 + 1.0, "MaxCLL {max_cll}");+ // HDR output off: the HDR edit exports its SDR rendition+ let plain = export_photo(&mut s, id, &ExportOptions::from_json(&json!({"longEdge": 160, "format": "png"})), 1).unwrap();+ assert!(!plain.bytes.windows(4).any(|w| w == b"cICP"));+ }diff --cc crates/mcp/src/headless.rsindex c7a2e9b66,f77a1700f..1a55be6b6--- a/crates/mcp/src/headless.rs+++ b/crates/mcp/src/headless.rs@@@ -133,7 -131,7 +133,7 @@@ impl Backend for Headless"engine.commands" => {let mut v: Vec<Value> = self.session.commands().into_iter().map(|c| serde_json::to_value(c).unwrap_or_default()).collect();v.push(json!({"id": "app.export", "label": "Export Now", "menu": [], "shortcut": null,- "params": "{path?: output file (.jpg/.png/.tif/.webp/.avif/.dng) | dir?, ids?, preset?, format?: jpeg|png|tiff|webp|avif|dng|original, longEdge?|shortEdge?|width?|height?|megapixels?|percent? (default longEdge 3000; longEdge 0 = full size), dontEnlarge?, ppi?, quality?: 1..100, limitKb?, colorSpace?: srgb|displayP3|adobeRgb|proPhoto|rec2020, bitDepth?: 8|10|16|32, hdr? (HDR output for HDR edits: gain map JPEG, float TIFF), sharpen?: none|screen|matte|glossy, sharpenAmount?: low|standard|high, metadata?: all|allExceptCamera|copyright|none, removeLocation?, naming?, startNumber?, subfolder?, conflict?: unique|overwrite|skip, tiffCompression?: none|lzw|zip, dngCompression?: lossless|deflate|uncompressed, watermark?: text | {text?, vertical? (upright columns, right to left), size? (text height, 0.005..0.5 of the short edge; default 0.035), opacity? (0..1; 0.7), anchor?: topLeft|top|topRight|left|center|right|bottomLeft|bottom|bottomRight, insetX? (margin from the left/right edge, 0..0.4 of the short edge; 0.025), insetY? (from the top/bottom edge; 0.025), inset? (sets both), rotation?: 0|90|180|270 (degrees clockwise; 0), color? [r,g,b] sRGB, shadow?, image? (graphic drawn instead of the text), imageWidth? (0.01..1 of the photo's width; 0.2)}} — an unknown parameter, an out-of-range watermark size or a value of the wrong kind is an error, not a default",- "params": "{path?: output file (.jpg/.png/.tif/.webp/.avif/.dng) | dir?, ids?, preset?, format?: jpeg|png|tiff|webp|avif|dng|original, longEdge?|shortEdge?|width?|height?|megapixels?|percent? (default longEdge 3000; longEdge 0 = full size), dontEnlarge?, ppi?, quality?: 1..100, limitKb?, colorSpace?: srgb|displayP3|adobeRgb|proPhoto|rec2020, bitDepth?: 8|10|16|32, hdr? (HDR output for HDR edits: gain map JPEG, PQ AVIF / PNG, float TIFF), sharpen?: none|screen|matte|glossy, sharpenAmount?: low|standard|high, metadata?: all|allExceptCamera|copyright|none, removeLocation?, naming?, startNumber?, subfolder?, conflict?: unique|overwrite|skip, tiffCompression?: none|lzw|zip, dngCompression?: lossless|deflate|uncompressed, watermark?: text | {text?, vertical? (upright columns, right to left), size? (text height, 0.005..0.5 of the short edge; default 0.035), opacity? (0..1; 0.7), anchor?: topLeft|top|topRight|left|center|right|bottomLeft|bottom|bottomRight, inset? (margin, 0..0.4 of the short edge; 0.025), color? [r,g,b] sRGB, shadow?, image? (graphic drawn instead of the text), imageWidth? (0.01..1 of the photo's width; 0.2)}} — an unknown parameter, an out-of-range watermark size or a value of the wrong kind is an error, not a default",++ "params": "{path?: output file (.jpg/.png/.tif/.webp/.avif/.dng) | dir?, ids?, preset?, format?: jpeg|png|tiff|webp|avif|dng|original, longEdge?|shortEdge?|width?|height?|megapixels?|percent? (default longEdge 3000; longEdge 0 = full size), dontEnlarge?, ppi?, quality?: 1..100, limitKb?, colorSpace?: srgb|displayP3|adobeRgb|proPhoto|rec2020, bitDepth?: 8|10|16|32, hdr? (HDR output for HDR edits: gain map JPEG, PQ AVIF / PNG, float TIFF), sharpen?: none|screen|matte|glossy, sharpenAmount?: low|standard|high, metadata?: all|allExceptCamera|copyright|none, removeLocation?, naming?, startNumber?, subfolder?, conflict?: unique|overwrite|skip, tiffCompression?: none|lzw|zip, dngCompression?: lossless|deflate|uncompressed, watermark?: text | {text?, vertical? (upright columns, right to left), size? (text height, 0.005..0.5 of the short edge; default 0.035), opacity? (0..1; 0.7), anchor?: topLeft|top|topRight|left|center|right|bottomLeft|bottom|bottomRight, insetX? (margin from the left/right edge, 0..0.4 of the short edge; 0.025), insetY? (from the top/bottom edge; 0.025), inset? (sets both), rotation?: 0|90|180|270 (degrees clockwise; 0), color? [r,g,b] sRGB, shadow?, image? (graphic drawn instead of the text), imageWidth? (0.01..1 of the photo's width; 0.2)}} — an unknown parameter, an out-of-range watermark size or a value of the wrong kind is an error, not a default","enabled": self.session.active().is_some()}));Ok(Value::Array(v))}diff --cc crates/mcp/src/tools.rsindex c347cada2,2526bf828..d20ae093f--- a/crates/mcp/src/tools.rs+++ b/crates/mcp/src/tools.rs@@@ -258,8 -258,8 +258,8 @@@ pub fn helper_tools(has_ui: bool) -> Ve"removeLocation": {"type": "boolean"},"colorSpace": {"type": "string", "enum": ["srgb", "displayP3", "adobeRgb", "proPhoto", "rec2020"], "description": "Output colour space (default sRGB; AVIF is always sRGB). adobeRgb = Adobe RGB (1998) compatible; the embedded ICC profile is generated from the published primaries"},"bitDepth": {"type": "integer", "enum": [8, 10, 16, 32], "description": "Bits per channel: PNG 8|16 (default 8), TIFF 8|16|32 (default 16; 32 = linear float with a linear profile), AVIF 8|10; JPEG/WebP are 8-bit"},- "hdr": {"type": "boolean", "description": "HDR output for photos edited in HDR (develop.hdr): JPEG as an ISO 21496-1 gain map JPEG, AVIF as 10-bit Rec. 2020 PQ, 32-bit TIFF with highlights above 1; other formats and SDR edits export as usual"},+ "hdr": {"type": "boolean", "description": "HDR output for photos edited in HDR (develop.hdr): JPEG as an ISO 21496-1 gain map JPEG, AVIF as 10-bit and PNG as 16-bit Rec. 2020 PQ, 32-bit TIFF with highlights above 1; other formats and SDR edits export as usual"},- "watermark": {"description": "Text, or {text, vertical (boolean; defaults to false: upright columns right to left), size (text height as a fraction of the short edge, 0.005..0.5; default 0.035), opacity (0..1; default 0.7), anchor (topLeft|top|topRight|left|center|right|bottomLeft|bottom|bottomRight), inset (margin as a fraction of the short edge, 0..0.4; default 0.025), color [r,g,b] (sRGB 0..255), shadow (boolean), image (path of a graphic drawn instead of the text), imageWidth (fraction of the photo's width, 0.01..1; default 0.2)}. Unknown keys and out-of-range sizes are errors"}+ "watermark": {"description": "Text, or {text, vertical (boolean; defaults to false: upright columns right to left), size (text height as a fraction of the short edge, 0.005..0.5; default 0.035), opacity (0..1; default 0.7), anchor (topLeft|top|topRight|left|center|right|bottomLeft|bottom|bottomRight), insetX (margin from the left or right edge as a fraction of the short edge, 0..0.4; default 0.025), insetY (margin from the top or bottom edge, same units), inset (sets both), rotation (degrees clockwise: 0|90|180|270; default 0; the watermark is sized before it is turned), color [r,g,b] (sRGB 0..255), shadow (boolean), image (path of a graphic drawn instead of the text), imageWidth (fraction of the photo's width, 0.01..1; default 0.2)}. Unknown keys and out-of-range sizes are errors"}}),&[],),diff --cc docs/parity-checklist.mdindex eb4ef08bc,7ea398cc6..70598f196--- a/docs/parity-checklist.md+++ b/docs/parity-checklist.md@@@ -389,10 -388,10 +389,10 @@@ differences and missing bindings are i| LR-EXP-BITDEPTH | Bit depth | P1 | ✅ | `cmd:app.export` (`bitDepth`), `crates/pipeline/src/output.rs` (`OutputDepth`), `crates/engine/src/export.rs` | 16-bit PNG/TIFF rendered at 16 bits (TIFF defaults to 16), 32-bit float linear TIFF with a linear profile, 10-bit AVIF; high-bit-depth renders run on the CPU || LR-EXP-COMPRESSION | TIFF compression | P1 | ✅ | `cmd:app.export` (`tiffCompression`: none / lzw / zip) | || LR-EXP-COLORSPACE | Output colour space | P0 | ✅ | `cmd:app.export` (`colorSpace`), `crates/pipeline/src/output.rs`, `crates/engine/src/export.rs` | sRGB, Display P3, Adobe RGB (1998) compatible, ProPhoto RGB, Rec. 2020: rendered from the working space with gamut mapping into the target gamut (CPU + GPU), own ICC profile embedded; AVIF stays sRGB (muxer has no ICC) |- | LR-EXP-HDR | HDR output | P2 | 🟡 | `cmd:app.export`, `crates/ui-egui/src/panels/dialogs.rs` | HDR output checkbox in the export dialog: gain map JPEG, PQ AVIF, float TIFF; no HDR presets yet |+ | LR-EXP-HDR | HDR output | P2 | 🟡 | `cmd:app.export`, `crates/ui-egui/src/panels/dialogs.rs` | HDR output checkbox in the export dialog: gain map JPEG, PQ AVIF, PQ PNG, float TIFF; no HDR presets yet || LR-EXP-SHARPEN | Output sharpening | P1 | ✅ | `cmd:app.export` (`sharpen`, `sharpenAmount`) | || LR-EXP-METADATA | Metadata policy | P1 | ✅ | `cmd:app.export` (`metadata`, `removeLocation`) | |-| LR-EXP-WATERMARK | Watermark | P1 | ✅ | `cmd:app.export` (`watermark`: text, or `{text, vertical, size, opacity, anchor, inset, color, shadow, image, imageWidth}`), `crates/engine/src/export.rs` (`Watermark`, `WATERMARK_PARAMS`) | text (`size` = height as a fraction of the short edge, 0.005..0.5, default 0.035; `color` sRGB `[r,g,b]`; `shadow`; Japanese vertical glyph forms and origins, tested by `biz_ud_vertical_watermarks_place_punctuation_at_the_top_right`; extended grapheme cells keep decomposed dakuten/handakuten and Latin accents together, tested by `vertical_watermarks_keep_combining_marks_in_one_cell` and `upright_watermark_cell_retains_multiple_glyphs` (see `docs/vertical-watermarks.md`)) or a graphic with transparency (`image` path, `imageWidth` = fraction of the photo's width, 0.01..1, converted to the output colour space); `anchor`, `inset` (fraction of the short edge, 0..0.4), `opacity` 0..1. Unknown keys and out-of-range values are errors (issue #183) |+| LR-EXP-WATERMARK | Watermark | P1 | ✅ | `cmd:app.export` (`watermark`: text, or `{text, vertical, size, opacity, anchor, insetX, insetY, inset, rotation, color, shadow, image, imageWidth}`), `crates/engine/src/export.rs` (`Watermark`, `WATERMARK_PARAMS`) | text (`size` = height as a fraction of the short edge, 0.005..0.5, default 0.035; `color` sRGB `[r,g,b]`; `shadow`; Japanese vertical glyph forms and origins, tested by `biz_ud_vertical_watermarks_place_punctuation_at_the_top_right`; extended grapheme cells keep decomposed dakuten/handakuten and Latin accents together, tested by `vertical_watermarks_keep_combining_marks_in_one_cell` and `upright_watermark_cell_retains_multiple_glyphs` (see `docs/vertical-watermarks.md`)) or a graphic with transparency (`image` path, `imageWidth` = fraction of the photo's width, 0.01..1, converted to the output colour space); `anchor` (nine positions), `insetX` / `insetY` (margins from the side and from the top/bottom edges, each a fraction of the short edge, 0..0.4; the Export dialog's Horizontal and Vertical inset sliders, as in Lightroom Classic; the older single `inset` still reads as both; tested by `watermark_insets_are_horizontal_and_vertical`), `rotation` (0, 90, 180 or 270 degrees clockwise, the Export dialog's Rotate row, as Lightroom Classic's rotate buttons; sized before it is turned, placed and inset by the turned box; tested by `watermark_rotation_turns_the_text_in_its_corner` and `graphic_watermark_is_placed_scaled_and_blended`), `opacity` 0..1. Unknown keys and out-of-range values are errors (issue #183). The Export dialog previews it on the first exported photo's thumbnail (`draw_watermark_preview` scales the 6 px minimum text size to the preview so it matches the file), tested by `watermark_preview_scales_the_minimum_text_size` and `export_dialog_previews_the_watermark` || LR-EXP-NAMING | File naming | P1 | ✅ | `cmd:app.export` (`naming`, `startNumber`), `crates/engine/src/rename.rs` (`expand_tokens`) | one template language for export, Rename Photos and import renaming: `{name}`, `{num}` (number at the end of the name), `{seq}` / `{seq:N}`, `{date}` / `{date:%Y-%m-%d}`, `{folder}`, `{camera}`, `{lens}`, `{iso}`, `{rating}`, `{title}`, `{creator}`, `{ext}`; free-form template rather than a list of named schemes || LR-EXP-LOCATION | Destination folder | P0 | ✅ | `cmd:app.export` (`dir`, `subfolder`, `conflict`: unique / overwrite / skip), `cmd:export.checkTarget`, `crates/ui-egui/src/panels/dialogs.rs` (Choose… folder picker), `crates/engine/src/originals.rs`, `crates/catalog/src/safe_file.rs` | folder picker on the desktop; existing files get `-2`, `-3`… by default; the policy covers a file and its sidecars together; a catalogued original (or its sidecar) is never written over, whatever the policy or an exact `path` (export, `ui.render`, MCP `render_photo`, merge `previewPath`, `lightcraft-cli render`); files are written to a temp file and renamed into place (issue #93; not synced file by file — exports can be made again, issue #134) || LR-EXP-PREVIOUS | Export with previous settings | P0 | ✅ | `cmd:app.exportPrevious`, `cmd:dialog.export` | last options persist in prefs.json; dialog prefilled; no named export presets yet |diff --cc docs/whats-new.mdindex 0f33afe47,ebd41a569..fdb932621--- a/docs/whats-new.md+++ b/docs/whats-new.md@@@ -25,31 -11,16 +25,39 @@@- Quitting while a task that can be stopped is running asks first ("Quit Anyway" stops it).- Agents list and stop tasks with `activity.list` and `activity.cancel`; `ui.inspect` reports them as `activity`.+### Importing a deleted photo again+- Importing a file whose photo is in Recently Deleted brings the photo back, with its edits, rating and albums+ (issue #706; before, the import skipped it as "already in the library" while the grid showed it deleted). The+ import review checks such files, marks them "Will be restored" and counts them as "in Recently Deleted"; the+ choice next to that (Restore them / Import as new / Leave them) now starts on Restore. Files dropped on the window+ restore the photo too and say "Restored 1 photo from Recently Deleted". A deleted photo whose file was moved is+ relinked to the file it is imported from. Browsing a folder in Local, Auto Import and a Lightroom catalog import+ never restore anything. Agents: `library.import` → `onDeleted` defaults to `restore` (`skip` keeps the old+ behaviour, `fresh` imports a clean copy and deletes the old record).++### Formats+- File extensions match whatever their letter case: `IMG_0001.JPG` and `DSC_0002.NEF` as Nikon writes them, `.Jpg`+ after a rename, an `.XMP` sidecar. Adding photos or a folder, Browse Folder (Local), drag-and-drop, the CLI and the+ sidecar lookup always did; the Add Photos dialog on Linux did not until 0.5.0 (GTK and the desktop portal match+ `*.jpg` case-sensitively, so `.JPG` and `.NEF` files were hidden — issues #342 and #705).++### Reliability+- Closing a library releases its lock explicitly (issue #680). On Linux and macOS the lock used to go with the file+ handle, and a program being started by another thread at that moment held a copy of the handle until it was fully+ launched, so reopening the library straight away could be refused with "This library is already open in another+ LightCraft program" although nothing had it open. Nothing in the shipped app is known to hit the window today; it+ made a lock test flaky, and the fix closes the window for good.+## 2026-10-09+ ### HDR PNG export+ - With **HDR output** on, a photo edited in HDR can now be exported as a **16-bit PNG** with the PQ curve in Rec. 2020,+ like the HDR AVIF: the same brightness, with SDR white at 203 cd/m², and content light levels recorded.+ - The colour is described by the PNG `cICP` chunk, not an ICC profile. HDR-aware viewers (current Chromium-based+ browsers, for example) show it in HDR; **viewers that don't read `cICP` show the PQ values as if they were sRGB**,+ so the picture looks flat and washed out there. That's how PQ PNG works, not a broken file: for a picture that+ looks right everywhere, export a JPEG with HDR output on (an SDR image plus a gain map).+### Smart album rules- The rule editor's field menu is grouped: Rating, Pick Flag, Color Label and Any Searchable Text at the top, thensubmenus for Source, File, Date, Keywords & People, Description, Camera Info, Location, Size, Develop and Assisted