Repository navigation
feat: camera raw import — clean-room pure-Rust decoder with a LibRaw fallback - #94
Merged
Merged
Conversation
Opens NEF, ARW, CR2, CR3, DNG, RAF, ORF, RW2, PEF and the rest of what LibRaw reads. Every pure-Rust raw decoder is LGPL (rawler, rawloader, quickraw) or AGPL (zenraw), so this makes the choice HEIC made: nothing links at build time and nothing is bundled; LibRaw is dlopen'd on first import from a managed directory, else the system (Homebrew, the distro package), preferring the reentrant build and serialising the plain one. Development is camera white balance, sRGB primaries, 16 bits a channel, and an exposure lift with a soft shoulder in place of dcraw's histogram stretch, so raws open at the camera JPEG's brightness with the highlights still there. The codec registers before TIFF, since most raws are TIFF containers; its probe walks the IFDs for sensor data so a plain TIFF still goes to its own codec. Thumbnails and Quick Look use the camera's embedded JPEG, turned upright. Unedited raws archive verbatim; the gallery reads ORF/RW2/RAF EXIF through container shims (CR3 still has none). Packaging gains weak LibRaw dependencies, the raw MIME types and the camera-raw UTI. Co-Authored-By: Claude Fable 5.1 <[email protected]>
A new crate that decodes and develops camera raws without LibRaw: every vendor container (DNG, NEF, ARW, CR2/CRW/CR3, RAF, ORF, RW2, PEF, SRW, MRW, Kodak, ERF, MEF, IIQ, 3FR/FFF, MOS, X3F) behind one RawImage contract, a develop pipeline (levels, white balance, Hamilton-Adams and X-Trans demosaic, D65-normalised camera matrix, crop, orientation), and a 189-body colour matrix table with per-entry provenance. Written from the public specifications and observation of real files; nothing derives from a copyleft decoder. Verified sample for sample against LibRaw's unpacked frames on some 250 raw.pixls.us files. Exact: DNG 26, Sony 24, Nikon 36, Canon CR2 14, Pentax 10, Samsung 15, Olympus 12, Panasonic 29, Fuji 9 (uncompressed), Hasselblad 7, Phase One 5, Leaf 3, and the Minolta/Kodak/Epson/Mamiya set. Declined with a reason: Canon CR3 pixels (CRX), Fuji compressed RAF, sRAW, compressed CRW, Panasonic RawFormat 8, Samsung NX1/NX500, IIQ S, Foveon, GoPro VC-5. The codecs-common plugin now tries the native crate first and falls back to the dlopen'd LibRaw for what it declines or has no matrix for, so nothing regresses; SCHIST_RAW_DECODER pins either. Against LibRaw's own development the native output sits at a median 33 dB over the files both handle. Reviewed adversarially (four passes, ~30k mutated files): every frame allocation is now bounded by a 400 MP ceiling and by the bytes the file holds, arithmetic on file-derived values is checked, and the findings (Sony overflows, Samsung CFA phase on five bodies, DNG AsShotWhiteXY, float DNG outside deflate, restart-marker indices) are fixed with tests. Co-Authored-By: Claude Fable 5.1 <[email protected]>
This was referenced Sep 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two commits: the first adds camera raw import through a runtime-loaded LibRaw; the second adds
crates/codec-raw, a pure-Rust, clean-room raw decoder that the plugin now tries first, falling back to LibRaw for whatever it declines. Most files no longer need LibRaw at all; nothing regresses where it is still needed.Commit 1 — LibRaw via dlopen (the HEIC pattern)
libraw_rpreferred, plain build serialised). Every pure-Rust raw crate is LGPL/AGPL, hence no static link.public.camera-raw-image.Commit 2 —
schist-codec-rawWritten by a fan-out of 4 foundation + 10 vendor Opus workers under a clean-room rule (specs, ExifTool tag docs, real files and LibRaw's output as oracle; no copyleft decoder source read or fetched), then 4 adversarial review passes (~30k mutated files) whose findings are fixed here.
Support ("exact" = every sample matches LibRaw's unpacked frame)
Colour: DNG carries its matrix; others use
cameras.rs(189 bodies; 64 read from real DNGs, the rest recalled Adobe D65 values cross-checked against each body's own WB presets, with a duplicate-matrix guard). No matrix → the plugin prefers LibRaw.Native vs LibRaw's own development over the 103 corpus files both handle: median 33 dB, p10 25 dB, worst 19.6 dB (a CHDK DNG).
SCHIST_RAW_COMPARE=1 SCHIST_RAW_CORPUS=… cargo test -p schist-codecs-common native_agrees_with_libraw -- --nocaptureprints the table;SCHIST_RAW_DECODER=native|librawpins a decoder.Robustness
Every decoder sizes its frame through
frame_samples(400 MP ceiling, overflow-checked) and requires the file to hold at least a bit per sample;validateis overflow-safe; the plugin wraps native calls incatch_unwind. Reviewer fuzzing: 0 panics after fixes.For a human to judge (licensing)
Known gaps / follow-ups
Test plan
cargo test --workspace,cargo fmt --check,clippy --workspace --all-targets -D warningsSCHIST_RAW_CORPUS=/tmp/rawsamples)🤖 Generated with Claude Code