Skip to content

LR-IMP-FORMATS: decode Canon EOS R5 Mark II C-RAW (CRX QP-map first literal and escape) - #915

Closed
ingolfteetz wants to merge 3 commits into
storytold:mainfrom
ingolfteetz:cr3-r5m2-qp-map-escape
Closed

ingolfteetz wants to merge 3 commits into
storytold:mainfrom
ingolfteetz:cr3-r5m2-qp-map-escape

Conversation

@ingolfteetz

@ingolfteetz ingolfteetz commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the R5 Mark II part of #832: many EOS R5 Mark II C-RAW files open as previews with Canon CRX adaptive QP value -21087 (or another out-of-range value).

Cause. The CRX 0x200 QP map starts with its first symbol as a 32-bit literal. Every later symbol is Rice-coded with a limited-length escape: 23 zeros, the terminating 1, then the symbol in 8 bits. That is the ITU-T T.87 escape layout for a 32-bit limit and 8-bit symbols, without its −1 offset. Main treats any 16-zero prefix as an escape followed by a 16-bit literal. That reads the first symbol the same way, which is all the R8 and R7 maps need. R5 Mark II maps (QP 150–162), though, jump by up to 12 where the Rice parameter is 0. That gives 18- to 22-zero prefixes, which are ordinary symbols, and real escapes (symbols 23 and 24). No QP value outside the verified 131–167 table is involved.

Tested with

  • 33,665 R5 Mark II C-RAW files from my library (version 0x200, 8480 × 5650; not shareable): every QP map decodes to the exact end of its entropy stream, QP 150–162. Both tracks of a 306-file sample do too; on main, 174 of those 306 (57 %) open as previews, all with out-of-range values and none at 168.
  • One of them (_A3A2841.CR3, ISO 1000), fully decoded and rendered: it matches the camera's embedded 8192 × 5464 JPEG at 100 %, with no steps in the bottom rows. The Bayer planes are 2825 rows, odd at every wavelet level.
  • raw.pixls.us 7881–7884 (R5 Mark II RAW, C-RAW, crop-mode RAW and crop-mode C-RAW; CC0, sha256 checked), added to the xtask corpus. Their hashes pin this decoder's sensor samples; no external decoder was run on them. These low-ISO files decode on main too, so the escape is covered by synthetic unit tests: an 18-zero prefix, a 23-zero escape and every truncation.
  • The six oracle fixtures (M50, R100 and R8, RAW and C-RAW): hashes unchanged.
  • Escapes appeared in 100 of 612 maps, always at Rice parameter 0. At a larger parameter they are assumed to use the same layout (unobserved).

What changes

  • crates/raw/src/vendor/crx.rs: the first QP symbol is read as a 32-bit literal, and the escape is 23 zeros, the terminating 1 and an 8-bit symbol, with tests.
  • crates/raw/tests/cr3_corpus.rs and xtask: the four CC0 files with pinned sensor hashes. The crop-mode files also check the camera's 5088 × 3392 framing, which LR-IMP-FORMATS: EOS R5 Mark II crop-mode CR3s develop without a black band #754 gives them.
  • RENDER_CACHE_VERSION 50 → 51, so thumbnails of files whose decode changed are redrawn. Photos imported as preview-only switch over with Photo ▸ Reload from Disk.
  • Docs: cr3.md, raw-parity (EOS R5 Mark II now verified: 235 models, use-weighted 85 %), coverage and evidence, gaps, the checklist rows, ROADMAP, target-app-parity and What's New (with German).

Related, now on main

With the header-only probe proposed in #832, the R5 Mark II files now probe as raws, so only their headers and QP maps are read instead of the 3 MB JPEG track.

Checks. Before merging main: cargo xtask ci passes except export_progress_and_cancel (#674). After merging main (#975): cargo fmt --check, clippy -D warnings on raw and engine, the engine lib tests, cargo xtask parity and cargo test -p lightcraft-raw with the corpus (including cr3_corpus) pass.

🤖 Generated with Claude Code

…iteral and escape)

The CRX 0x200 QP map opens with its first symbol as a 32-bit literal; every
later symbol is Rice coded with a limited-length escape: 23 zeros, the
terminating 1 and the symbol in 8 bits (the ITU-T T.87 layout for a 32-bit
limit and 8-bit symbols, without its minus-one offset). The old rule (an
escape after 16 zeros with a 16-bit literal) matched only the first symbol,
which is all the R8 and R7 maps need. R5 Mark II maps (QP 150-162) jump by up
to 12 where the Rice parameter is 0, giving 18- to 22-zero prefixes that
misparsed ("Canon CRX adaptive QP value -21087"): 174 of 306 sampled files
from a private R5 Mark II library opened as previews. Every QP map of its
33,665 C-RAW files now decodes to the exact end of its entropy stream; the six
oracle fixtures are unchanged. Established by black-box analysis of the
bitstream; no third-party decoder source consulted.

Adds the four CC0 R5 Mark II samples (raw.pixls.us 7881-7884) to the corpus
with pinned sensor hashes (the crop-mode framing is left to storytold#754), bumps
RENDER_CACHE_VERSION to 43, and updates cr3.md, raw-parity (235 verified
models), coverage, gaps, the checklist rows, ROADMAP, target-app-parity and
What's New.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ingolfteetz and others added 2 commits October 11, 2026 14:38
# Conflicts:
#	crates/engine/src/media.rs
#	crates/raw/src/vendor/crx.rs
#	docs/parity-checklist.md
… x 3392 framing

With storytold#754 on main, the recommended crop is the valid area of the crop-mode
files (raw.pixls.us 7883, 7884), so their pinned tests assert the developed
size again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copy link
Copy Markdown
Member

Landed in #981 together with #961. #829's QP 168 test and yours both pass on the merged decoder. Thanks again, @ingolfteetz!


Generated by Claude Code

EddifyBot pushed a commit to good-shepherd-insights/lightcraft that referenced this pull request Oct 11, 2026
# Conflicts:
#	crates/engine/src/media.rs
#	crates/raw/src/vendor/crx.rs
#	crates/ui-egui/locales/de.json
#	docs/gaps.md
#	docs/parity-checklist.md
#	docs/raw-parity.md
#	docs/whats-new.md
EddifyBot pushed a commit to good-shepherd-insights/lightcraft that referenced this pull request Oct 11, 2026
…t] was lost merging storytold#915 next to storytold#829)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BKWB9TCnvzJHV6xMLAj2J4
@ingolfteetz

Copy link
Copy Markdown
Contributor Author

Thanks @bflatastic, and @radialmonster for the review! Closing this, since it landed via #981. Two small leftovers stay on this branch and can go into a later PR: the crop-mode fixtures (7883, 7884) could assert the 5088 × 3392 framing again now that #754 is in, and docs/cr3.md still names render cache version 43 (main is at 60).

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.

2 participants