Skip to content

Decode the lossless Nikon compression - #17

Merged
sputier merged 1 commit into
mainfrom
feature/decode-lossless
Nov 19, 2026
Merged

sputier merged 1 commit into
mainfrom
feature/decode-lossless

Conversation

@sputier

@sputier sputier commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

RawFile.Decode now decodes the lossless variant of the Nikon compression (TIFF compression 34713, 12 and 14 bits), into a new array or a buffer of the caller.

  • The compression record of the MakerNote (tag 0x96) is read with the structure; the lossy variants and files without the record are reported with an UnsupportedCompressionException.
  • The format facts relied on are written in the documentation of NikonLosslessDecoder; the code is original.
  • Checked on 570 real files of a Nikon Z 6: every row decoded, every sample in range, the stream ending at the end of its strip. Also by an encoder-decoder round trip on synthetic files (both bit depths, strips split and empty, streams larger than the read buffer) and with truncated, corrupted and hostile files.
  • Hostile headers: the allocation is bounded by the size of the strips (a minimum number of bits per sample), so a small file cannot claim a huge image.
  • Speed: about 0.26 s for a 24-megapixel image into a reused buffer (BenchmarkDotNet, DecodeBenchmarks), no allocation beyond a few bytes.

Part of #5.

RawFile.Decode now decodes the lossless variant of the Nikon compression (12 and
14 bits). The compression record of the MakerNote (tag 0x96) is read with the
structure. Checked on real files, with an encoder round trip and with damaged
files; the allocation is bounded by the size of the strips.
@sputier
sputier merged commit 8d4aec1 into main Nov 19, 2026
4 checks passed
@sputier
sputier deleted the feature/decode-lossless branch November 19, 2026 01:01
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