* raw: clean-room camera raw decoder and developer (photocraft-raw) A new standalone crate (no workspace deps, wasm-safe, no unsafe) written from TIFF 6.0, TIFF/EP, the DNG 1.7 spec, ITU-T T.81 Annex H and published demosaicing papers: - Lossless JPEG (LJ92) decoder: predictors 1-7, point transform, restart intervals, combined Huffman+extra-bits fast table. - DNG: uncompressed (8-16 bit, packed) and LJ92, strips and tiles, CFA and LinearRaw, linearization, black level (repeat, deltas), white level, active area, default crop, ColorMatrix/CameraCalibration/ForwardMatrix interpolation by CCT, AnalogBalance, AsShotNeutral/WhiteXY, BaselineExposure, orientation. - CR2 (LJ92 slices, SensorInfo borders, ColorData as-shot WB, measured black) and TIFF/EP raws (NEF/ARW/PEF uncompressed or LJ92, incl. Sony lossless ARW tiles, Nikon/Sony documented black and WB tags). - Develop: black/white scaling, WB with highlight clipping, bilinear / Malvar-He-Cutler / AHD demosaic (rayon bands, sequential on wasm), camera -> XYZ D50 -> ProPhoto, exposure, gamma 1.8, 16-bit, orientation. - Embedded JPEG preview finder; clear Unsupported errors for CR3, RAF, ORF, RW2, vendor-compressed NEF/ARW/PEF, lossy/JXL/float DNG, X-Trans. - Limits checked before every allocation; testgen feature with an LJ92 encoder and DNG/CR2/TIFF-EP writers; round-trip, colour-reference, truncation and corruption tests. Registered as a standalone crate in xtask layers. Co-Authored-By: Claude Opus 5.5 <[email protected]> * io: open camera raws through photocraft-raw (16-bit ProPhoto), preview fallback Co-Authored-By: Claude Opus 5.5 <[email protected]> * raw: DNG GainMap opcode, fuzz targets, stress tools; open raws from the apps - Apply DNG OpcodeList2 GainMap (lens shading, e.g. phone DNGs); report other opcodes. - cargo-fuzz targets (develop, ljpeg) and a mutation stress example. - Raw extensions in the desktop/web open dialogs and the batch folder list. - file.open returns the import notes (how a raw was developed, preview fallback). - codecs: the camera raw refusal points at photocraft-raw. Co-Authored-By: Claude Opus 5.5 <[email protected]> * raw: clippy 1.99 (is_multiple_of, clamp) Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
photocraft-raw
A clean-room, pure-Rust camera raw decoder and developer. The crate is standalone (no workspace
dependencies), has no unsafe, does no I/O (&[u8] in), builds for wasm32-unknown-unknown
(sequential there, rayon-parallel on native) and never panics on hostile input: every offset is
bounds-checked and sizes are checked against Limits before allocating.
use photocraft_raw::{develop, DevelopOptions, Demosaic};
let dev = develop(&bytes, &DevelopOptions { demosaic: Demosaic::Ahd, ..Default::default() })?;
// dev.rgb: interleaved 16-bit RGB in ProPhoto RGB (ROMM primaries, D50, gamma 1.8)
// dev.warnings: anything approximated or not applied
photocraft-io uses it so opening a raw file yields a normal 16-bit RGB document tagged with the
built-in ProPhoto-compatible profile.
Sources (clean-room)
Implemented only from public specifications, papers and observation of files:
- TIFF 6.0, TIFF/EP (ISO 12234-2) and the Adobe DNG Specification 1.7.
- ITU-T T.81 (ISO 10918-1) Annex H: lossless JPEG, process 14 ("LJ92").
- The published description of Canon's CR2 container (header, raw IFD, slice tag 0xC640).
- Publicly documented maker-note / private tags: Canon SensorInfo (0x00E0) and ColorData (0x4001), Nikon WB_RBLevels (0x000C) and BlackLevel (0x003D), Sony BlackLevel (0x7310) and WB_RGGBLevels (0x7313).
- Demosaicing: Malvar, He & Cutler (ICASSP 2004); Hirakawa & Parks, "Adaptive homogeneity-directed demosaicing" (IEEE TIP 2005).
- McCamy's CCT approximation (1992); the Bradford chromatic adaptation transform.
No code from dcraw, LibRaw, rawspeed, rawler, rawloader or darktable was read or used, and no camera colour tables were copied.
Support matrix
| Format | Status |
|---|---|
| DNG | Uncompressed (8–16 bit, packed or not) and lossless JPEG; strips and tiles; CFA (Bayer) and LinearRaw; LinearizationTable, BlackLevel (+ repeat, DeltaH/V), WhiteLevel, ActiveArea, DefaultCrop, ColorMatrix1/2, CameraCalibration, ForwardMatrix, AnalogBalance, AsShotNeutral / AsShotWhiteXY, BaselineExposure, Orientation, OpcodeList2 GainMap (lens shading) |
| DNG (lossy JPEG, JPEG XL, floating point; opcodes other than GainMap) | Unsupported / not applied (reported) |
| CR2 | Lossless JPEG with slices, borders and as-shot white balance from the maker note, black measured on the masked border |
| CR2 sRAW / mRAW | Unsupported |
| NEF / NRW, ARW, PEF and other TIFF/EP raws | Uncompressed and lossless-JPEG (incl. Sony lossless ARW) CFA data |
| Nikon compressed NEF, Sony compressed ARW, Pentax compressed PEF | Unsupported (vendor compression; photocraft-io opens the embedded JPEG preview instead) |
| CR3, RAF, ORF, RW2 | Recognised, unsupported (preview fallback where a preview is found) |
| X-Trans and other non-Bayer CFAs | Unsupported |
Development pipeline
- Linearization table, per-position black level, scale to the white level.
- White balance (as shot; or grey-world when the file has none; or explicit multipliers), normalized so the smallest multiplier is 1, then clip to 1 so blown highlights stay white.
- Demosaic:
Bilinear,Mhc(Malvar–He–Cutler) orAhd(default). - Camera → XYZ (D50) per the DNG specification (ColorMatrix interpolated by the white's correlated colour temperature, or ForwardMatrix), → linear ProPhoto; exposure (BaselineExposure + user EV); gamma 1.8; 16 bits.
- Orientation.
Files without colour calibration (CR2, NEF, ARW…) use a documented neutral fallback: the white-balanced camera channels are treated as linear sRGB primaries (colours are plausible but less saturated than a calibrated profile; converting to DNG gives calibrated colour). No tone curve is applied: the result is a scene-referred rendering, flatter than a camera JPEG.
Tools
cargo run --release -p photocraft-raw --example rawinfo -- [--dump] [--demosaic ahd] [--png DIR] FILE...
prints what was decoded, times decode and develop, and can write sRGB PNG previews and the
embedded JPEG previews.