Skip to content

LR-IMP-FORMATS: decode table-less Nikon 34713 NEFs stored as packed 12/14-bit data - #671

Merged
aiongg merged 5 commits into
storytold:mainfrom
radialmonster:nef-packed-34713
Oct 22, 2026
Merged

aiongg merged 5 commits into
storytold:mainfrom
radialmonster:nef-packed-34713

Conversation

@radialmonster

@radialmonster radialmonster commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Covers packed NEF/NRW layouts, including the Z 6II geometry reported in #769.

Some NEFs labelled compression 34713 contain packed samples rather than a compressed stream, with no linearization table. This extends the existing Nikon reader to select the layout from bit depth, dimensions and complete strip length: LSB-packed rows, 16-byte padded rows, D100 groups and big-endian 16-bit NRW words. High Efficiency codestream detection and the current compressed decoder stay in the same routing chain.

Rebased onto main’s Mode/MASK_ROWS implementation. Header probes decode only the needed prefix; header/full geometry agrees. Width/bit/stride arithmetic is checked and strips outside the file are rejected. Render-cache version is 65.

Raw tests, all-target raw Clippy and raw wasm checks pass. Together with stacked #673, a fresh comparison covers 86 CC0 Nikon raws and controls: 22 newly decode (all 20 known packed-layout files and two small-RAW files from #673), and the other 64 retain identical decoded sensor samples. Synthetic regressions cover layout geometry, overflow, truncated strips and bounded header probes.

The packed reader validates the complete declared strip range before both Header and Full behavior. A strip clipped at EOF is corrupt even when all metadata is intact. A metadata-first tail-truncation regression fails with the guard disabled; valid decoded samples remain unchanged.

Validation limitation: cargo xtask ci passes formatting, then stops at the unchanged tests_export.rs Clippy drop_non_drop error reproduced on main. The full workspace baseline also has Windows export-path and folder-drop test failures. Only 62 of the 447 pinned corpus files are available here; unavailable cases are skipped.

Credit: @radialmonster.

Copy link
Copy Markdown
Member

Thanks, the packed-layout analysis is careful work. This needs a rebase. #727 (compressed NEFs probed from their headers) is landing now and restructures the same strip-decode path in crates/raw/src/vendor/nef.rs: there is now a Mode, and the first MASK_ROWS rows are read for the probe. The packed layouts have to sit inside that path, so this is a merge by hand rather than a mechanical one.

While you're in there:

  • packed_layout computes w * bits as usize unchecked, before the MAX_SAMPLES check, so it can overflow on wasm32. Please use checked_mul.
  • RENDER_CACHE_VERSION should go one past whatever main has when you rebase.

Generated by Claude Code

… under 34713

The Coolpix P330, P7700 and P7800 NRWs carry compression 34713 with no maker
note 0x0096 table, 12 bits, one sample per pixel and a single strip of exactly
width * height * 2 bytes. The strip is one big-endian 16-bit word per pixel,
row-major with no header or padding; the sample is the word >> 4.

The layout was found by black-box analysis of the CC0 raw.pixls.us files
(strip byte-count identity, same-colour smoothness, correlation with the
embedded JPEG), not from any other converter's code.

The group is tried after the other packed layouts, so it cannot take a strip
they handle. Black level: these files have no 0x003d and no NRW block and no
masked pixels, so it is 200 (the floor of the P7800 frame is 201; the other
Coolpix NRWs state 200), never above the darkest sample. White comes from the
data. Other Nikon NEF/NRW files decode identically (278 checked).

Bumps RENDER_CACHE_VERSION to 52.
@radialmonster

Copy link
Copy Markdown
Contributor Author

Rebased onto main’s current Nikon reader. Packed decodes now follow Mode/MASK_ROWS, including a bounded header prefix and matching header/full geometry. Width × bit-depth and row-padding arithmetic are checked, and truncated strips are refused. The render-cache version is 65.

Raw tests, all-target raw Clippy and raw wasm checks pass. Full CI stops at the same tests_export.rs Clippy error reproduced on unchanged main. #673 is stacked on this refreshed head.

@radialmonster

Copy link
Copy Markdown
Contributor Author

The table-less packed-strip reader now requires the entire declared strip range to be present before either a Header probe or a Full decode succeeds. The shared TIFF helper can return a clipped slice at EOF, so checking only that a slice exists was insufficient.

The regression relocates the strip after all intact metadata, then removes its tail. It fails with the length guard disabled and passes with the guard enabled, for both probe modes. Valid packed files retain their existing decoded samples. This changes malformed-input rejection and does not add another render-cache version bump.

Credit: @radialmonster.

deunderscorepaul pushed a commit to deunderscorepaul/lightcraft-classic that referenced this pull request Oct 17, 2026
…E5700 CYGM, E8400, E8800)

Only the PR's own commits on top of storytold/lightcraft#671 (table-less 34713 NEFs, which the fork already decodes: fork issue emmertex#769).

Thanks @radialmonster

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
deunderscorepaul pushed a commit to deunderscorepaul/lightcraft-classic that referenced this pull request Oct 17, 2026
…4:2:2 luma/chroma

Only the PR's own commits on top of storytold/lightcraft#671 (already in the fork, issue emmertex#769); the small-raw path sits beside the fork's table-less packed decoder.

Thanks @radialmonster

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aiongg
aiongg merged commit 758f2e2 into storytold:main Oct 22, 2026
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.

3 participants