LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Merge storytold/lightcraft main into LR-MERGE-HDR (lens corrections)
Claude8bb084074cf2
diff --cc crates/engine/src/tests_merge.rsindex 42049a4e8,27a82fbed..cb42dbc2a--- a/crates/engine/src/tests_merge.rs+++ b/crates/engine/src/tests_merge.rs@@@ -67,57 -67,31 +67,82 @@@ fn hdr_merge_command_creates_and_importlet _ = std::fs::remove_dir_all(&dir);}+/// An HDR merge keeps the reference frame's lens corrections. The sources carry an off-centre `WarpRectilinear` and+/// `FixVignetteRadial` for their active area and have a default crop; the merged DNG must give "Enable Profile+/// Corrections" the same correction as the reference photo, upright and for a vertical bracket (whose DNG keeps the+/// pixels unturned).+#[test]+fn hdr_merge_keeps_the_reference_frames_lens_corrections() {+ use lightcraft_geom::{Orientation, Point};+ use lightcraft_pipeline::optics::{embedded_vignette_gain, embedded_warp};+ use lightcraft_raw::Opcode;+ for orientation in [Orientation::Normal, Orientation::Rotate90] {+ let dir = temp_dir(&format!("hdr-lens-{orientation:?}"));+ let mut paths = Vec::new();+ for (i, b) in lightcraft_merge::synth::bracket_dngs(480, 320, &[-2.0, 0.0, 2.0]).unwrap().into_iter().enumerate() {+ let mut raw = lightcraft_raw::decode(&b).unwrap();+ raw.crop = lightcraft_raw::Rect::new(10, 6, 452, 304);+ raw.orientation = orientation;+ raw.metadata.orientation = Some(orientation);+ raw.opcodes.list3 = vec![+ Opcode::WarpRectilinear { planes: vec![[0.96, 0.05, -0.012, 0.002, 0.001, -0.0005]], center: [0.48, 0.53] },+ Opcode::FixVignetteRadial { k: [0.35, -0.05, 0.01, 0.0, 0.0], center: [0.48, 0.53] },+ ];+ let p = dir.join(format!("IMG_{i}.dng"));+ std::fs::write(&p, lightcraft_raw::write_dng(&raw, &Default::default()).unwrap()).unwrap();+ paths.push(p.to_string_lossy().to_string());+ }+ let mut s = Session::new().with_fs();+ let ids = import(&mut s, paths);+ let r = s.execute("merge.hdr", &json!({"ids": ids})).unwrap();+ assert_eq!(r["reference"].as_u64(), Some(ids[1]), "{r}");+ let merged = s.catalog.photo(lightcraft_catalog::PhotoId(r["id"].as_u64().unwrap())).unwrap().clone();+ let reference = s.catalog.photo(lightcraft_catalog::PhotoId(ids[1])).unwrap().clone();+ let expect = if orientation == Orientation::Normal { (452, 304) } else { (304, 452) };+ assert_eq!(((merged.width, merged.height), (reference.width, reference.height)), (expect, expect));+ let a = reference.embedded_lens.expect("the source's correction");+ let b = merged.embedded_lens.expect("the merged DNG carries the reference frame's correction");+ let (wa, wb) = (a.warp.unwrap(), b.warp.unwrap());+ let (va, vb) = (a.vignette.unwrap(), b.vignette.unwrap());+ let (w, h) = (expect.0 as f64, expect.1 as f64);+ for (x, y) in [(0.0, 0.0), (w, h), (w, 0.0), (0.0, h), (w * 0.3, h * 0.7), (w * 0.5, h * 0.5)] {+ let p = Point::new(x, y);+ for ch in 0..3 {+ let (pa, pb) = (embedded_warp(&wa, p, ch, w, h), embedded_warp(&wb, p, ch, w, h));+ assert!((pa.x - pb.x).abs() < 1e-6 && (pa.y - pb.y).abs() < 1e-6, "{orientation:?} {p:?}: {pa:?} vs {pb:?}");+ }+ let (ga, gb) = (embedded_vignette_gain(&va, p, w, h), embedded_vignette_gain(&vb, p, w, h));+ assert!((ga - gb).abs() < 1e-9, "{orientation:?} {p:?}: {ga} vs {gb}");+ }+ let _ = std::fs::remove_dir_all(&dir);+ }+}++ /// Raws without colour matrices of their own (CR2, NEF, ARW…) merge into a DNG with the colour they open with,+ /// not with no colour at all (issue #965: an HDR merge of CR2s rendered green and dark).+ #[test]+ fn a_merge_of_raws_without_colour_matrices_keeps_their_colour() {+ let dir = temp_dir("hdr-colour");+ let neutral = [0.5, 1.0, 0.7];+ let mut paths = Vec::new();+ for (i, b) in lightcraft_merge::synth::bracket_dngs(240, 160, &[-1.0, 0.0, 1.0]).unwrap().into_iter().enumerate() {+ // the same pixels with a white balance but no colour matrices+ let mut raw = lightcraft_raw::decode(&b).unwrap();+ raw.color = lightcraft_raw::ColorData { as_shot_neutral: Some(neutral), ..Default::default() };+ let p = dir.join(format!("IMG_{i}.dng"));+ std::fs::write(&p, lightcraft_raw::write_dng(&raw, &Default::default()).unwrap()).unwrap();+ paths.push(p.to_string_lossy().to_string());+ }+ let mut s = Session::new().with_fs();+ let ids = import(&mut s, paths);+ let r = s.execute("merge.hdr", &json!({"ids": ids, "autoSettings": false})).unwrap();+ let merged = lightcraft_raw::decode(&std::fs::read(r["path"].as_str().unwrap()).unwrap()).unwrap();+ assert!(lightcraft_raw::color::has_matrix(&merged.color), "{:?}", merged.color);+ let got = merged.color.as_shot_neutral.expect("the sources' white balance");+ assert!(got.iter().zip(neutral).all(|(a, b)| (a - b).abs() < 1e-3), "{got:?}");+ let _ = std::fs::remove_dir_all(&dir);+ }+#[test]fn panorama_command_with_auto_crop() {let dir = temp_dir("pano");diff --cc crates/merge/src/frame.rsindex b7c583220,69743a1b3..9ce00a505--- a/crates/merge/src/frame.rs+++ b/crates/merge/src/frame.rs@@@ -116,22 -120,11 +126,25 @@@ pub fn load_frame_with(bytes: &[u8], malet exposure = exif_exposure(&metadata);if lightcraft_raw::probe(bytes).is_some() {let mut raw = lightcraft_raw::decode(bytes).map_err(|e| MergeError::Decode(e.to_string()))?;- // geometric lens corrections stay with the develop settings ("profile corrections")+ // Lens corrections stay with the develop settings ("profile corrections"): frames are merged uncorrected, and+ // the output DNG carries the reference frame's corrections, re-expressed for the default crop `develop` keeps.+ // The DNG 1.6 skip rule is applied here, so no `WarpRectilinear2` is left optional.+ let (aw, ah) = (raw.active_area.width, raw.active_area.height);+ let crop = raw.develop_crop(aw, ah);+ let lens = lightcraft_raw::opcodes::applied_ops(&raw.opcodes.list3)+ .filter(|op| op.is_lens_correction())+ .filter_map(|op| op.cropped(aw, ah, crop))+ .map(|op| match op {+ Opcode::WarpRectilinear2 { planes, center, reciprocal, .. } => {+ Opcode::WarpRectilinear2 { planes, center, reciprocal, optional: false }+ }+ op => op,+ })+ .collect();raw.opcodes.list3.retain(|op| !op.is_lens_correction());+ if let Some(color) = colour(&mut raw, bytes) {+ raw.color = color;+ }let small = max_edge.is_some_and(|m| m <= 1200);let method = if small { lightcraft_raw::Method::Bilinear } else { lightcraft_raw::Method::Ahd };let mut image = raw.develop(method).map_err(|e| MergeError::Decode(e.to_string()))?;diff --cc docs/parity-checklist.mdindex ca4b71d5a,0ab638f35..0861fb1c0--- a/docs/parity-checklist.md+++ b/docs/parity-checklist.md@@@ -346,7 -346,7 +346,7 @@@ differences and missing bindings are i| Id | Feature | Tier | Status | Evidence | Missing / notes ||---|---|---|---|---|---|- | LR-MERGE-HDR | HDR merge | P2 | ✅ | `cmd:merge.hdr`, `cmd:dialog.mergeHdr`, `crates/merge/src/frame.rs` (`Frame::lens`) | auto align, deghost None–High + overlay, auto settings, float DNG, Create Stack; the DNG keeps the reference frame's embedded lens corrections (tested by `hdr_merge_keeps_the_reference_frames_lens_corrections`); JPEG brackets treated as linear; measured on synthetic brackets only (docs/merge.md) |-| LR-MERGE-HDR | HDR merge | P2 | ✅ | `cmd:merge.hdr`, `cmd:dialog.mergeHdr` | auto align, deghost None–High + overlay, auto settings, float DNG, Create Stack; JPEG brackets treated as linear; raws without colour matrices of their own (CR2, NEF, ARW…) keep the colour they open with, written as DNG tags (`starting_colour_tags`; the look's chroma curve has no tag; panoramas too), issue #965 |++| LR-MERGE-HDR | HDR merge | P2 | ✅ | `cmd:merge.hdr`, `cmd:dialog.mergeHdr`, `crates/merge/src/frame.rs` (`Frame::lens`) | auto align, deghost None–High + overlay, auto settings, float DNG, Create Stack; the DNG keeps the reference frame's embedded lens corrections (tested by `hdr_merge_keeps_the_reference_frames_lens_corrections`); JPEG brackets treated as linear; raws without colour matrices of their own (CR2, NEF, ARW…) keep the colour they open with, written as DNG tags (`starting_colour_tags`; the look's chroma curve has no tag; panoramas too), issue #965 || LR-MERGE-PANO | Panorama | P2 | ✅ | `cmd:merge.panorama`, `cmd:dialog.mergePanorama` | spherical/cylindrical/perspective + auto, boundary warp, auto crop, fill edges (diffusion), DNG; no lens model / 360° wrap || LR-MERGE-HDRPANO | HDR panorama | P2 | ✅ | `cmd:merge.hdrPanorama`, `cmd:dialog.mergeHdrPanorama` | brackets grouped by EXIF || LR-MERGE-HEADLESS | Merge with last settings | P2 | ✅ | `cmd:merge.hdrLast`, `cmd:merge.panoramaLast`, `cmd:merge.hdrPanoramaLast` | no dialog; the options of the last merge of that kind (defaults the first time) |diff --cc docs/whats-new.mdindex fa14499a7,81d9ad7fc..a47be984c--- a/docs/whats-new.md+++ b/docs/whats-new.md@@@ -2,13 -2,106 +2,111 @@@## 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.++ ### Slider drags on large raws+ - Dragging a slider no longer re-renders the edited photo's filmstrip thumbnail on every frame; it follows once you+ let go. On a 64 MP raw the first of those renders decoded the whole file again, which held up the loupe's+ previews for up to a second.+ - A thumbnail of the photo open in Detail is made from its already decoded preview instead of decoding the file+ again.+ ## 2026-10-12++ ### Canon CR2 highlights+ - Blown highlights in CR2 files from the Canon EOS 50D, 60D, 450D (Rebel XSi), 500D (Rebel T1i), 550D (Rebel T2i),+ 1200D (Rebel T5) and 100D (Rebel SL1) now count as clipped (issue #1272). They used to stop at 81–98% of white, so+ highlight recovery missed them and, darkened, they took a colour cast instead of going neutral grey.+ ## 2026-10-12++ ### Pentax raws without black borders+ - Raws from the Pentax KP, KF, K-3 Mark III (and Monochrome), K-70, K-1, K-1 Mark II, K-S1, K-S2 and 645Z no longer+ show a black (or, on the 645Z, white) band along one or more edges (issue #1271). The sensor's masked border is+ left out, so these photos come out a little smaller, closer to the camera's own JPEG. Crops and masks on photos+ edited earlier may shift by a few pixels.+ ## 2026-10-12++ ### Camera-look deep shadows++ - The starting look fitted from a raw's camera JPEG now uses its darkest tones too (issue #1307).+ Photos with deep shadows no longer have to extend the first measured tone in a straight line to black.+ Existing smart previews are refreshed when their originals are online, and cached renders are redrawn.+ ### Slider drags follow the pointer more closely+ - With a GPU, a slider drag's preview is drawn in the same frame as the slider moves instead of one frame later,+ when the preview renders in a few milliseconds (it waits at most 40 % of a frame for it; slower renders, such as+ on the CPU, are not waited for).+ ## 2026-10-12++ ### Kelvin white balance for more Sony cameras+ - Sony ILCA-99M2, ILCA-77M2, SLT-A33, DSC-RX10, ILCE-3500 and ILCE-7S raws now show white balance in Kelvin too,+ read from the white-balance presets the camera stores in every ARW: a photo shot at 3400 K on the camera reads+ 3396 K, one on the Shade preset 7493 K. As for #730, only the numbers change: edits made on the old relative+ scale keep their look, and As Shot shows the real temperature once the file is opened.+ ## 2026-10-12++ ### Bold text in other scripts+ - Arabic names and other Arabic text in headings, chosen tabs and other bold places are now drawn bold, as Latin text+ beside them is; they used to stay at regular weight.+ ## 2026-10-12++ ### Older raw cameras+ - Canon PowerShot G9 raws open with the camera's white balance (White Balance ▸ As Shot); it used to start from a+ neutral default.+ ## 2026-10-12++ ### Older raw cameras+ - Olympus E-10 raws open with the camera's white balance (White Balance ▸ As Shot) and without the grey haze in+ the shadows: the black level recorded in the file is now subtracted.+ ### Told when there is no GPU+ - When GPU rendering is on but no graphics processor can be found, LightCraft now says so once at start-up instead+ of quietly rendering everything on the CPU, much more slowly. Help ▸ System Info says why. On NixOS this happens+ when a `cargo` build runs outside `nix develop` (no Vulkan loader); start it from there.+ ## 2026-10-12++ ### Leaf and Hasselblad raws+ - The Hasselblad Lunar's raws (a Sony NEX-7 inside) now develop from their sensor data with every editing tool,+ instead of opening as their embedded preview. Photos imported earlier switch over with Photo ▸ Reload from Disk.+ - An uncompressed Leaf Aptus 22 MOS no longer opens as a dark, colourless picture of its sensor mosaic: it imports+ as a raw and shows its embedded preview (preview only, with the reason), as the compressed MOS files do.+ ## 2026-10-12++ ### Zoomed 64 MP raws stay decoded+ - Panning a photo zoomed to 1:1, or moving a slider while zoomed, no longer decodes the whole raw again each time on+ high-resolution cameras such as the Sony A7R VI (64 MP). Their decoded original (~800 MB) is bigger than the+ default cache share (768 MB), so it was evicted as soon as it was stored. The original of the photo shown in Detail+ now stays, like its preview, until another photo or view is shown.+ - Zooming in with Before/After side by side decodes the original once: the Before side used to decode its own copy+ beside the After's, and a window asked for again while the first was still decoding (a pan, the layout settling)+ started yet another decode.+ - A zoomed view keeps the GPU copy of the original while it is on screen: pausing for a few seconds between pans no+ longer frees it, which cost a re-upload of about a second on the next pan (800 MB for a 64 MP raw). It is freed+ once you zoom out or move on.+ - The kept original no longer pushes everything else out of the cache: on a 64 MP raw it filled the cache share+ alone, so the photo's preview and thumbnail sources and its neighbours' were decoded from the raw again on every+ edit at 1:1, every zoom out and every step to the next photo.+## 2026-10-11+ ### HDR and panorama merges of CR2 keep their colour+ - Photo Merge of Canon CR2 (and other raws whose colour LightCraft fits from the camera's own JPEG, such as NEF and+ ARW) gives the merged DNG the colour each photo has when opened alone (issue #965). An HDR merge of CR2s used to come+ out green and dark.+ ### "Rendering…" on the photo+ - The loupe says "Rendering…" at the bottom of the photo when what it shows isn't the finished photo yet: the+ camera's embedded JPEG while a raw decodes, the previous render while an edit renders, or the magnified frame+ while the 1:1 detail is on its way. It appears once that has lasted half a second, so quick renders never show it.+ - If LightCraft can't open a photo (its original is on a drive that isn't connected, or the file is damaged) but has+ its embedded JPEG or a thumbnail to show, the loupe now says so at the bottom of the photo ("Original offline · no+ smart preview" or "This photo can't be opened", the reason on hover) instead of showing that preview as if it were+ the photo.+ ### `--import <folder>` takes HEIC+ - `lightcraft-cli run --import <folder>` (and the MCP tools that take folders) now picks up HEIC, HEIF and Nikon NRW+ files, the same files as `library.import` (issue #1080). They used to be skipped without a word.+ - Compare and Reference View panes say "Rendering…" (or that the photo can't be opened) the same way, so a+ magnified preview isn't taken for the photo when checking focus at 1:1.+### JPEG XL export- Export as JPEG XL (issue #247): Format ▸ JPEG XL in the Export dialog, `format: "jxl"` for agents and the CLI(`render in.raw -o out.jxl`). Quality as for JPEG, or Lossless; Effort (Fast / Normal) trades time for a