Skip to content

fix(raw): decode Samsung linear DNGs correctly#4

Open
VailElla wants to merge 5 commits into
CyberTimon:mainfrom
VailElla:codex/fix-samsung-linear-dng-decoding
Open

fix(raw): decode Samsung linear DNGs correctly#4
VailElla wants to merge 5 commits into
CyberTimon:mainfrom
VailElla:codex/fix-samsung-linear-dng-decoding

Conversation

@VailElla

@VailElla VailElla commented Jul 15, 2026

Copy link
Copy Markdown

Note

These decoder changes have been resubmitted upstream as dnglab/dnglab#810. This downstream PR remains open temporarily because CyberTimon/RapidRAW#1380 currently pins commit ee86c32e3d85ff6057fdc8b3c3eed38923712d91. Once the upstream PR is merged and this fork is synchronized, RapidRAW's dependency will be refreshed and this PR will be closed as superseded.

Summary

  • honor BlackLevelRepeatDim for interleaved linear DNG data instead of assuming the black- and white-level arrays have the same length
  • parse JPEG DRI segments, validate RST0-RST7 ordering, resume entropy decoding, and reset the lossless JPEG predictor at restart boundaries
  • reject truncated entropy segments instead of consuming synthetic zero-fill bits, and validate restart padding and trailing entropy bytes
  • reject unsupported restart sampling in every component, truncated DRI segments, undeclared or zero-interval restart markers, invalid BlackLevel counts, and malformed normalization metadata instead of panicking or silently producing corrupted pixels
  • warn and skip black-level correction when generic black/white-level array lengths still do not match, rather than aborting the process

Root cause and impact

This enables the decoder-side fixes needed by:

  • CyberTimon/RapidRAW#777: the Samsung S23 Ultra sample has a valid 2x2x3 black-level repeat pattern plus three white levels. It also uses lossless JPEG restart markers; the previous bit pump stopped at the first marker, corrupting rows after the first restart interval.
  • CyberTimon/RapidRAW#884: the Samsung Galaxy Z Fold6 JPEG XL sample uses the same valid repeated black-level representation, which previously reached a black/white-level length mismatch.

Both public issue samples now complete full RAW decoding. This PR intentionally does not implement default-rendering metadata such as BaselineExposure or OpcodeList2 gain maps; those belong to later rendering stages. RapidRAW#1380 applies baseline exposure, while GainMap rendering remains a planned follow-up and pixel parity is not claimed here.

Validation

  • cargo +1.96.1 test -p rawler --test linear_blacklevel --test jpeg_restart (18 passed)
    • covers predictor reset, RST ordering, stuffed bytes, fill bytes, all-component sampling validation, undeclared and zero-interval restart markers, missing entropy, invalid padding, extra entropy, truncated final intervals, and malformed DRI metadata
  • direct regression probe confirmed a generic black/white-level length mismatch returns without panic and leaves pixels unchanged
  • cargo +1.96.1 check -p rawler
  • cargo +1.96.1 build -p dnglab
  • decoded the public Nikon ZR support dnglab/dnglab#777 and #884 attachments through dnglab analyze --raw-checksum

The issue fixtures are used only for local validation and are not included in this branch.

@VailElla
VailElla marked this pull request as ready for review July 15, 2026 02:25
@VailElla
VailElla force-pushed the codex/fix-samsung-linear-dng-decoding branch from 528ffb3 to 6ac6ec2 Compare July 15, 2026 21:54
@SimonIT

SimonIT commented Jul 20, 2026

Copy link
Copy Markdown

Wouldn't it be better to submit the pull request to dnglab itself? This way, when Timon updates this fork, the changes will be pulled in automatically

@VailElla

Copy link
Copy Markdown
Author

Thanks — agreed. I moved the decoder changes to a clean branch based on dnglab/dnglab:main and opened the upstream PR here: dnglab#810

I’ll keep this PR open temporarily because CyberTimon/RapidRAW#1380 currently pins this fork revision. Once the upstream PR is merged and this fork is synced, I’ll update the RapidRAW dependency and close this PR as superseded.

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