Skip to content

feat(raw): decode CR3, compressed RAF, CRW, NX1, IIQ S and Panasonic v8 natively - #98

Merged
IAmJSD merged 1 commit into
mainfrom
raw-codecs-complete
Sep 3, 2026
Merged

IAmJSD merged 1 commit into
mainfrom
raw-codecs-complete

Conversation

@IAmJSD

@IAmJSD IAmJSD commented Sep 3, 2026

Copy link
Copy Markdown
Member

Summary

The six codecs schist-codec-raw declined after #94 now decode natively, so LibRaw is only reached for Foveon, GoPro VC-5 and a few old odd formats. Based on main with #97 merged.

Method. Classic two-team clean room: three separate agents read the LGPL reference (fetched under /tmp, never into the repo), instrumented it, and wrote functional specifications in prose and tables with worked intermediate values (/tmp/raw-specs/*.md). Three implementers then worked from those specifications, the sample files and LibRaw's oracle output only, and never opened the reference. The specification writers reported only summaries to the coordinator, so no source entered the coordinating context either.

codec exact vs LibRaw's unpacked frame
Canon CR3 — CRX lossless and lossy (cRAW), 0–3 wavelet levels, multi-tile 10/10 (EOS R, 90D, R5, R8 incl. dual-pixel); EOS R in 120 ms
Fujifilm compressed RAF — lossless and lossy, X-Trans and Bayer 4/4 (X100F, X-Pro3, X-T5, GFX100S)
Canon CRW compressed 3/3 (D60, 10D, PowerShot G2)
Samsung SRW compression 32773 2/2 (NX1, NX500)
Phase One IIQ S, formats 5 and 6 6/6 → all 11 Phase One files exact
Panasonic RW2 RawFormat 8 2/2 (GH6, G9 II)

Every allow-list in those modules is now empty. Against LibRaw's own development the new paths sit at 36–45 dB in the plugin's comparison harness (110 files compared, none below 20 dB).

Oracle note. LibRaw 0.21.2 (the box's package) does not implement RawFormat 8 and lacks the Samsung output clamp; the four affected oracle dumps were regenerated from LibRaw 0.22.2 (recorded in /tmp/raw-specs/oracle-notes.md).

Spec corrections found by the implementers (all in module docs): the Samsung length-0 dequantiser offset (would have corrupted 15% of an NX500 frame followed literally), Phase One row interleave and companding notes, a CRW record-field offset, a Fuji prose off-by-one, and CRX's predictor being numerically the LOCO-I median.

Review. 80,863 mutated inputs across all six codecs with overflow checks on: no blind panics. Five hand-targeted crashes were found and are fixed here: CRX allocating from an unbounded header (now through the crate's frame ceiling), a zero bit depth, a quantiser-step overflow, the Panasonic curve underflowing on a forged threshold, the CRW predictor overflowing on a crafted stream; plus a quadratic CRX frame assembly (24 MB → 9 s) rewritten to one pass. Latent items noted, not fixed: a compressed RAF whose strip header disagrees with the container is refused rather than trusting the header; a corrupt Samsung v3 row desyncs the rest of the frame into noise rather than black; Phase One's per-row/column black tables are not applied (LibRaw's dump doesn't either).

For a human to judge

  • The reviewer flagged three comment phrasings that mention "the reference decoder" or "every other decoder"; the content is spec-supported and no code was transcribed, but the wording invites the question. Left as is for you to see.

Test plan

  • Crate: 360 tests incl. every spec's worked values as assertions and per-format corpus comparison (SCHIST_RAW_CORPUS=/tmp/rawsamples)
  • Plugin sweep over the full corpus; native-vs-LibRaw PSNR table
  • The reviewer's five crash inputs run clean in a debug build with a 4 GB address-space limit
  • cargo fmt --check, clippy -D warnings on the crate

🤖 Generated with Claude Code

…v8 natively

The six codecs the clean-room crate declined, implemented clean-room in
the classic two-team form: separate agents read the LGPL reference and
wrote functional specifications (prose, tables, worked intermediate
values from an instrumented build) under /tmp; the implementers worked
from those specifications, the sample files and LibRaw's oracle output
only, and never opened the reference. Every one now matches LibRaw's
unpacked frame sample for sample across the corpus:

  Canon CR3 (CRX lossless and lossy)        10/10  EOS R, 90D, R5, R8
  Fujifilm compressed RAF (lossless, lossy)   4/4  X100F, X-Pro3, X-T5, GFX100S
  Canon CRW compressed                        3/3  D60, 10D, G2
  Samsung SRW compression 32773               2/2  NX1, NX500
  Phase One IIQ S (formats 5 and 6)           6/6  P25+, P45, H25, iXU180, IQ140
  Panasonic RW2 RawFormat 8                   2/2  GH6, G9 II

LibRaw 0.21.2 does not implement RawFormat 8 and lacks the Samsung
output clamp, so those four oracle dumps were regenerated from 0.22.2.

The implementers fed back a dozen corrections to the specifications
(the Samsung length-0 dequantiser offset alone would have corrupted 15%
of an NX500 frame followed literally), all recorded in module docs.

Reviewed adversarially (80k mutated inputs, no blind panics): the five
hand-targeted crashes it found — CRX allocating from an unbounded
header, a zero bit depth, a quantiser-step overflow, the Panasonic
curve underflowing on a forged threshold, the CRW predictor overflowing
on a crafted stream — are fixed, along with a quadratic CRX frame
assembly.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@IAmJSD
IAmJSD merged commit 61d1edc into main Sep 3, 2026
4 checks passed
@IAmJSD
IAmJSD deleted the raw-codecs-complete branch September 3, 2026 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant