Skip to content

LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust

Merge upstream/main into pr/file-writes

Andrew Frahne5efaea6a826
diff --cc crates/raw/src/dngwrite.rs
index da19df68e,379267c87..af7a7f44b
--- a/crates/raw/src/dngwrite.rs
+++ b/crates/raw/src/dngwrite.rs
@@@ -23,69 -23,12 +23,73 @@@ pub enum DngCompression
tile: u32,
half: bool,
},
+ /// Lossy DNG (DNG 1.4 compression 34892): the raw data demosaiced to linear camera RGB (with `OpcodeList3`
+ /// and the default crop applied), scaled down to at most `long_edge` pixels on the long side when given,
+ /// then stored as 8-bit baseline JPEG tiles of `tile × tile` pixels at JPEG `quality` (1–100). The 8-bit
+ /// codes follow a 1/2.2 power curve that a `LinearizationTable` maps back to linear 16-bit values, so
+ /// shadows keep their precision. The colour tags (matrices, white balance, profile look) are kept.
+ LossyJpeg {
+ tile: u32,
+ quality: u8,
+ long_edge: Option<u32>,
+ },
+}
+
+/// Gamma of the 8-bit codes in a lossy DNG (own choice: perceptually close to even steps, like sRGB).
+const LOSSY_GAMMA: f64 = 2.2;
+
+/// The 256-entry `LinearizationTable` of a lossy DNG: code → linear 16-bit value.
+fn lossy_linearization() -> Vec<u16> {
+ (0..256u32).map(|i| ((i as f64 / 255.0).powf(LOSSY_GAMMA) * 65535.0).round() as u16).collect()
+}
+
+/// The image a lossy DNG stores: `raw` developed to linear camera RGB (white = 1), scaled to fit
+/// `long_edge`, as 8-bit codes (in `u16` samples) on the [`LOSSY_GAMMA`] curve, with the levels,
+/// geometry and opcode lists that this data needs (black 0, white 65535 after linearization).
+fn lossy_source(raw: &RawImage, long_edge: Option<u32>) -> Result<RawImage> {
+ let mut rgb = raw.develop(crate::Method::Ahd)?;
+ if let Some(edge) = long_edge.map(|e| e.max(1) as usize) {
+ let long = rgb.width.max(rgb.height);
+ if long > edge {
+ let s = edge as f64 / long as f64;
+ let w = ((rgb.width as f64 * s).round() as usize).max(1);
+ let h = ((rgb.height as f64 * s).round() as usize).max(1);
+ rgb = lightcraft_raster::resample::resize(&rgb, w, h, lightcraft_raster::resample::Filter::Lanczos3);
+ }
+ }
+ let (w, h) = (rgb.width, rgb.height);
+ if w == 0 || h == 0 {
+ return Err(RawError::Corrupt("empty image".into()));
+ }
+ let inv = 1.0 / LOSSY_GAMMA as f32;
+ let data: Vec<u16> = rgb
+ .data
+ .par_iter()
+ .flat_map_iter(|px| px.map(|v| if v.is_finite() { (v.clamp(0.0, 1.0).powf(inv) * 255.0).round() as u16 } else { 0 }))
+ .collect();
+ let full = crate::Rect::new(0, 0, w, h);
+ Ok(RawImage {
+ width: w,
+ height: h,
+ cpp: 3,
+ data: RawData::U16(data),
+ cfa: None,
+ bits: 8,
+ black: crate::BlackLevel::default(),
+ white: vec![65535.0],
+ active_area: full,
+ crop: full,
+ // list 1 and 2 work on the undemosaiced data and list 3 is applied by `develop`
+ opcodes: crate::OpcodeLists::default(),
+ linearized: true,
+ ..raw.clone()
+ })
}
+ /// Software tag of the DNGs this writer makes. A bare "LightCraft" marks older files, whose CFAPattern is anchored at
+ /// the sensor origin instead of the ActiveArea (the reader keeps their original reading).
+ pub const SOFTWARE: &str = "LightCraft DNG 2";
+
/// IEEE 754 binary32 → binary16 (round to nearest even; overflow → ±inf, NaN kept).
pub fn f32_to_f16(v: f32) -> u16 {
let b = v.to_bits();
diff --cc docs/gaps.md
index a8a218db2,ee6e58d1c..aceee2500
--- a/docs/gaps.md
+++ b/docs/gaps.md
@@@ -1,6 -1,6 +1,6 @@@
# Gaps: where LightCraft falls short of Lightroom
- > **Last reviewed:** 2026-10-11 · **Last updated:** 2026-10-12 · **Change:** minor (gap 25: lossy DNG export; earlier: gap 10: Leica Q3 verified, 236 models; CR3 entry names the EOS R7 C-RAW fix and the refused CRX variants; CI and Windows / Linux entries note the 0.6.0 riscv64 build; camera colour: tone curve from black-and-white camera JPEGs; Compare and Reference get sharp zoom windows; gap 4 shrinks; gap 14: the HDR switch is read from crs XMP; gaps 2 and 10: EOS R5 Mark II CR3 verified) · **Target:** Adobe Lightroom Classic 15.5 / Lightroom 9.6
-> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-10-13 · **Change:** patch (gap 8: Nikon Z 6II / Z 8 / Z f in-file distortion; gaps 10, 22 and 23 listed once again: merges had left two copies of each, and `cargo xtask parity` now fails on a gap listed twice)
++> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-10-13 · **Change:** minor (gap 25: lossy DNG export; earlier: gap 8: Nikon Z 6II / Z 8 / Z f in-file distortion; gaps 10, 22 and 23 listed once again: merges had left two copies of each, and `cargo xtask parity` now fails on a gap listed twice) · **Target:** Adobe Lightroom Classic 15.5 / Lightroom 9.6
Every known shortfall, one entry each, ranked by user impact (how many Lightroom users hit it, and
how hard it blocks them), then by effort. **Agents pick work from the top** (the first entry nobody is
@@@ -37,12 -36,10 +36,10 @@@ Hours are Opus 5.5 agent wall-clock hou
| 19 | **Plug-in ecosystem**: no Lightroom SDK equivalent (export / publish plug-ins, metadata plug-ins) | ⬜ | pro workflows built on plug-ins (LR/Enfuse, Jeffrey's exporters, Negative Lab Pro) | 40–80 + owner decision | [target-app-parity](target-app-parity.md#by-dimension) |
| 20 | **Long-tail raw formats**: compressed SRW, ARQ pixel shift, IIQ, Hasselblad compression, X3F, CRW, MRW, ERF, KDC, DCR, MEF, GPR, old FinePix | raw-parity.md | small user share each | 45–85 | [raw-parity](raw-parity.md) |
| 21 | **Localization**: 9 of 15 shipped languages partial (74–99% of catalog messages), lower-layer errors English; Hindi, Arabic, Indonesian, Korean, Vietnamese absent; no RTL or complex shaping | measured from catalogs | non-English users see mixed English | 55–90 (shipped to full); 145–255 (five new) | [localization-parity](localization-parity.md) |
- | 22 | **Pen pressure**, OS monitor profiles, follow-window colour | hardware-parity.md | brush users with tablets; multi-monitor setups | 11–22 | [hardware-parity](hardware-parity.md) |
| 23 | **Accessibility**: AccessKit tree audited by a test (every control named, sliders with range); left: canvas handles, spot and mask placement by keyboard, a session with a real screen reader | LR-BEHAV-ACCESS 🟡 | blind and low-vision users | 4–8 | [ui-parity](ui-parity.md) |
| 22 | **Pen pressure**, OS monitor profiles on Windows (Linux reads colord's, macOS the screen's), follow-window colour on Linux / Windows | hardware-parity.md | brush users with tablets; multi-monitor setups | 11–22 | [hardware-parity](hardware-parity.md) |
- | 23 | **Accessibility** audit with screen readers; canvas tools keyboard-reachable | LR-BEHAV-ACCESS 🟡 | blind and low-vision users | 10–20 | [ui-parity](ui-parity.md) |
| 24 | **Brush live preview and masking feel** (#517, #518); Feather / Edge mask refinement (15.5) | issues | masking feels slower than Lightroom | 8–12 | [ui-parity](ui-parity.md) |
-| 25 | **File writes**: lossy DNG; AVIF import; Render to DNG as a catalog command (the export format landed) (PSD export landed with Edit in PhotoCraft, #953) | file-format-parity.md | interchange edge cases | 19–34 | [file-format-parity](file-format-parity.md) |
+| 25 | **File writes**: AVIF import; Render to DNG as a catalog command (lossy DNG and the Render to DNG export format landed) (PSD export landed with Edit in PhotoCraft, #953) | file-format-parity.md | interchange edge cases | 19–34 | [file-format-parity](file-format-parity.md) |
| 26 | **Performance at scale**: 85k-photo library opens in 1.7–4.7 s; 100k grid test pending; colour NR at half resolution | ROADMAP log, gpu-pipeline.md | large-catalog users | 15–30 | [target-app-parity](target-app-parity.md#by-dimension) |
| 27 | **Windows / Linux runtime coverage**: Windows installer UI unverified on Windows (#79); GPU path proven on Apple and on one AMD GPU on Linux (Radeon 8060S, Vulkan); NVIDIA, Intel and DX12 unverified; the Linux riscv64 tarball (new in 0.6.0, #844) is cross-compiled and never run beyond a QEMU smoke test | ROADMAP, issues, `release.yml` | non-Mac users find bugs first | 13–27 | [hardware-parity](hardware-parity.md) |
| 28 | **Small Classic shortcuts and keys**: rating `[` `]`, flag cycling, filter-bar keys, F1 help, panel keys (Tab, F5–F8) | [ui-parity](ui-parity.md#shortcuts) | Classic muscle memory | 4–8 | [ui-parity](ui-parity.md) |