LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Merge PR #1443
Brandon Thomas07f73c44dae0
diff --cc crates/engine/src/files.rsindex c9442f5a9,2c5ae8654..1e68e0c3a--- a/crates/engine/src/files.rs+++ b/crates/engine/src/files.rs@@@ -721,7 -709,7 +721,7 @@@ pub fn fs_preview_loader() -> PreviewLolet gate = crate::memory::work_gate();let _permit = if crate::memory::is_background() { gate.acquire(len.saturating_mul(2)) } else { gate.acquire_urgent(len.saturating_mul(2)) };if let Some(image) =- preview_window(path, max_edge).ok().flatten().and_then(|(header, window, _)| quick_image_srgb(&header, &window, max_edge))- preview_window(path).ok().flatten().and_then(|(header, window, read)| quick_image_srgb(&header, &window, read.adobe_rgb, max_edge))++ preview_window(path, max_edge).ok().flatten().and_then(|(header, window, read)| quick_image_srgb(&header, &window, read.adobe_rgb, max_edge)){return Some(image);}@@@ -1267,39 -1244,7 +1275,39 @@@ mod tests// caller's whole-file read is what answers (no guessing at what a file might hold).let not_a_raw = tiff_with_preview_strip(&jpeg, 400_000, Fixture::default());std::fs::write(&path, ¬_a_raw).unwrap();- assert!(preview_window(&path).expect("the file reads").is_none(), "an unknown container falls back");+ assert!(preview_window(&path, max_edge).expect("the file reads").is_none(), "an unknown container falls back");+ let _ = std::fs::remove_dir_all(&dir);+ }++ /// A raw that keeps several JPEGs is shown, on the plan route as on the whole-file path, from the smallest one that+ /// covers the box (`embedded_preview_covering`). The plan route used to hand on the largest whatever the size: an+ /// A7R VI ARW's 9984 × 6656 JPEG for a 512 px thumbnail instead of its 1616 × 1080 one.+ #[test]+ fn preview_loading_plans_the_smallest_covering_jpeg() {+ let jpeg = |w: u32, h: u32| {+ let rgb: Vec<u8> = (0..w * h * 3).map(|i| (i * 31 % 247) as u8).collect();+ encode_jpeg(&EncodeImage::new(w, h, 3, Samples::U8(&rgb)), 90, ChromaSubsampling::S420, &EncodeMeta::default()).unwrap()+ };+ let (big, small) = (jpeg(96, 64), jpeg(48, 32));+ assert!(big.len() > small.len(), "the full-size JPEG is the largest");+ let file = tiff_with_preview_strips(&big, &[&small], 400_000, Fixture { dng: true, ..Default::default() });+ let dir = crate::tests_xmp::temp_dir("preview-plan-covering");+ let path = dir.join("two-previews.dng");+ std::fs::write(&path, &file).unwrap();+ let path = path.to_string_lossy().into_owned();++ for (edge, want, which) in [(48, &small, "small"), (49, &big, "full-size"), (usize::MAX, &big, "full-size")] {+ let (header, window, read) = preview_window(&path, edge).expect("the file reads").expect("the plan locates its preview");+ assert!(read.planned, "the planner is what answered");+ assert!(&window == want, "a {edge} px box takes the {which} JPEG");- let quick = quick_image_srgb(&header, &window, edge).expect("the window holds a decodable preview");++ let quick = quick_image_srgb(&header, &window, read.adobe_rgb, edge).expect("the window holds a decodable preview");+ let whole = embedded_preview_srgb(&file, edge).expect("the whole file decodes too");+ assert_eq!(+ (quick.width, quick.height, quick.data),+ (whole.width, whole.height, whole.data),+ "{edge} px: the plan and the whole file agree"+ );+ }let _ = std::fs::remove_dir_all(&dir);}@@@ -1350,13 -1295,20 +1358,20 @@@let adobe = tiff_with_preview_strip(&jpeg, 400_000, Fixture { sony: true, color_space: Some(0xFFFF), ..Default::default() });assert_eq!(lightcraft_raw::embedded_preview_color_space(&adobe), Some(PreviewColorSpace::AdobeRgb), "the fixture declares Adobe RGB");std::fs::write(&path, &adobe).unwrap();- assert!(preview_window(&path, usize::MAX).expect("the file reads").is_none(), "the whole-file path applies the space");- let (header, window, read) = preview_window(&path).expect("the file reads").expect("the plan answers for Adobe RGB too");++ let (header, window, read) = preview_window(&path, usize::MAX).expect("the file reads").expect("the plan answers for Adobe RGB too");+ assert!(read.planned && read.adobe_rgb, "{read:?}");+ assert!(read.fraction() < 0.5, "the sensor strip is not read: {read:?}");+ let quick = quick_image_srgb(&header, &window, read.adobe_rgb, 512).expect("the window decodes");+ let whole = embedded_preview_srgb(&adobe, 512).expect("the whole file decodes too");+ assert_eq!(quick.data, whole.data, "the space is applied as the whole-file path applies it");+ let plain = quick_image_srgb(&header, &window, false, 512).expect("the window decodes");+ assert_ne!(plain.data, whole.data, "and it changes the pixels (the fixture's colours are saturated enough)");let srgb = tiff_with_preview_strip(&jpeg, 400_000, Fixture { sony: true, color_space: Some(1), ..Default::default() });assert_eq!(lightcraft_raw::embedded_preview_color_space(&srgb), Some(PreviewColorSpace::Srgb), "the fixture declares sRGB");std::fs::write(&path, &srgb).unwrap();- let (_, window, read) = preview_window(&path).expect("the file reads").expect("sRGB is what the JPEG-only decode assumes");+ let (_, window, read) = preview_window(&path, usize::MAX).expect("the file reads").expect("sRGB is what the JPEG-only decode assumes");- assert!(read.planned, "the plan still answers");+ assert!(read.planned && !read.adobe_rgb, "the plan still answers");assert!(window.starts_with(&[0xff, 0xd8]), "and hands on the JPEG");}diff --cc docs/raw-preview-reads.mdindex de155bf9f,d766c1eda..a16b9a333--- a/docs/raw-preview-reads.md+++ b/docs/raw-preview-reads.md@@@ -136,11 -119,10 +138,12 @@@ use the largest JPEG, so their geometrwhole-file path produce identical pixels, and the read stays under half the file. On a syntheticTIFF/DNG whose preview only its tags locate — the plan path — the same identity holds and the CFAstrip is not read; the same structure without the tag that makes it a raw declines instead of- guessing, and the caller keeps reading it whole. So do a file whose own orientation or Adobe RGB- colour space only the whole-file path can show, while one that states sRGB stays on the fast path.- A synthetic DNG with a full-size and a half-size JPEG gets, on the plan path, the half-size one for- a box it covers and the full-size one otherwise, with the same pixels as the whole-file path- (`preview_loading_plans_the_smallest_covering_jpeg`).+ guessing, and the caller keeps reading it whole. So does a file whose own orientation only the+ whole-file path can show. One that states Adobe RGB takes the plan route and shows the same pixels+ as the whole-file path (the space changes them: decoded as sRGB they differ), and one that states- sRGB stays on the fast path.++ sRGB stays on the fast path. A synthetic DNG with a full-size and a half-size JPEG gets, on the plan++ path, the half-size one for a box it covers and the full-size one otherwise, with the same pixels as++ the whole-file path (`preview_loading_plans_the_smallest_covering_jpeg`).- `crates/raw/tests/sparse_corpus.rs`: `preview_plan` is asked for **every** corpus file, not onlythe ones whose header plan is `Ready`, and the preview it yields must equal the whole file's withthe skipped bytes `0` and `0xFF`. The test prints what each format reads.diff --cc docs/whats-new.mdindex cc1ec7ccd,340b29980..d994c0ed9--- a/docs/whats-new.md+++ b/docs/whats-new.md@@@ -2,62 -2,16 +2,72 @@@## 2026-10-13+### HDR merges keep the lens correction+- An HDR made with Photo ▸ Photo Merge ▸ HDR now keeps the lens correction the photos carry (Sony's, Panasonic's+ and Leica's, and the one some DNGs carry, e.g. from drones): Optics ▸ Enable Lens Corrections straightens it as it+ does the photos it was made from. HDRs merged before this don't have it; merge them again.++### Portable mode+- A file named `portable.txt` next to the LightCraft program makes it keep its settings, logs and downloaded+ models in a `LightCraftData` folder beside it instead of the per-user settings folder (issue #1200), as+ PhotoCraft does. If that folder can't be written, the usual folder is used and the log says why.++### Reliability+- A photo whose Defringe amount was stored far past the sliders' 20 (in a damaged catalog or sidecar) no longer+ crashes LightCraft each time it renders: the amount acts as 20.++### Reliability+- Importing a preset zip that unpacks to far more than any preset (a "zip bomb") is refused with a message naming+ the file, instead of asking for gigabytes of memory, which could end LightCraft.++### Reliability+- A crop of no size (from an agent or a sidecar) no longer gives the Detail view a photo of no size to lay out+ (its width over its height was 0 / 0, which stopped debug builds); it shows as a single pixel's colour.++### Reliability+- A crop a hair wide (or of no size), set by an agent or read from a sidecar, no longer crashes or hangs the+ render with Clarity, Dehaze, Texture or Highlights / Shadows on: their blurs are held to the picture's size.+- A crop of no size with healing spots or masks no longer crashes the render: samples outside the picture read its+ edge.++### Reliability+- A library whose catalog file was damaged (or edited by hand) in a way that still reads no longer crashes+ LightCraft when it shows a stack, or hangs it when a folder is moved: on opening, records are put back under+ their own ids, stacks keep only photos that exist (at least two), folders inside themselves move to the top,+ and new photos never reuse an id in use. What was repaired is written to the log.++### Nikon lens corrections+- Raws from the Nikon Z 6II and Z f now open with the camera's own distortion correction, as Lightroom applies a+ built-in profile: straight lines near the edges stay straight and the framing matches the camera's JPEG. It works+ with Z lenses and with F-mount lenses on the FTZ adapter, follows the in-body stabilisation's shift of the optical+ centre, and can be turned off under Lens Corrections. Vignetting correction from the file comes later.++### Thumbnail cache stays in its folder+- The thumbnail cache no longer follows a shard folder (`thumbs/ab/`) that is a symlink or junction to somewhere+ else (issue #1504): trimming or clearing the cache can't delete files outside it, and thumbnails are never read+ from or written through such a link.+## 2026-10-13++### Large libraries: Synchronize Folder, import and sidecars start sooner+- Opening Synchronize Folder, an import review or an import no longer makes a table of every photo in the library+ before it looks at the first file. In a library of 3.5 million photos that held the window for about 6 s before+ a Synchronize scan began (now under 1 s), 2.6 s before an import review (now 0.05 s) and 1.7 s before an import+ (now 0.05 s). The scan looks up only the files it finds and the contents it reads, on its own thread.+- Writing one photo's XMP sidecar (Save Metadata to File, or automatically after an edit) no longer works out who+ owns every shared sidecar name in the library: 2.4 s a write in that library, now under 1 s.+- Nothing else changes: the same files are found new, already there, moved or missing, and sidecars get the same+ names.++ ### Faces load faster in the People view+ - Faces on unedited raws are cut from the camera's preview inside the file instead of developing the raw (issue+ #1440): a Sony α1 face reads 8 MB instead of 70 MB, an A7S III face about 1 MB instead of 24 MB, several times+ faster on an external hard disk. A face whose preview is too small, and any edited photo, is still developed from+ the raw, so it keeps its look.+ - Raws whose preview is in Adobe RGB (Sony α1 among others) no longer read the whole file for their grid thumbnail:+ only the header and the preview are read, as for other raws.+ - Faces are kept in the thumbnail cache at a few fixed sizes, so moving the thumbnail slider no longer renders them+ all again.+### Slider drags on large raws- Dragging a slider no longer re-renders the edited photo's filmstrip thumbnail on every frame; it follows once youlet go. On a 64 MP raw the first of those renders decoded the whole file again, which held up the loupe's