Repository navigation
Read the embedded JPEG previews - #15
Merged
Merged
Conversation
RawFile.Previews lists the JPEG previews the library finds in the file, in its sub-directories and in the Nikon MakerNote, from the largest to the smallest. ReadPreviewJpeg reads the largest one, or one of them into a new array or into a buffer of the caller, which allocates nothing. A preview that does not lie inside the file is left out, and data that does not start with a JPEG start-of-image marker is reported as corrupt. Reading a preview of 700 KB into a buffer takes about 30 microseconds. Opening a file now also finds its previews, which costs about 300 bytes; the allocation budget of the open is unchanged. The fuzz tests read every preview of the damaged files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Lot 3: the embedded JPEG previews of a NEF file (issue #3).
RawFile.Previews(the previews found in the sub-directories and in the Nikon MakerNote, largest first, each place once),ReadPreviewJpeg()(the largest, or null),ReadPreviewJpeg(preview)(a new array) andReadPreviewJpeg(preview, buffer)(no allocation).CorruptRawFileExceptionwhen read.ByteCountis anint,Previewsis a read-only wrapper, disposal is idempotent and thread-safe, the sort and de-duplication allocate nothing more than needed, the result array is not zeroed first, docs and README corrected.Checklist
dotnet format --verify-no-changesis clean.README.md,CHANGELOG.md.longarithmetic against the file length; the fuzz tests (random damage and boundary values in every field, both byte orders, with a MakerNote preview) read every preview.Measurements
BenchmarkDotNet (short job): reading a 700 KB preview into a buffer takes about 30 µs and allocates nothing; into a new array about 140 µs (the array is the allocation). Opening a file allocates about 3.3 KB (budget 4 KB, checked by a test).
Not verified