Repository navigation
Read the metadata of a NEF file - #14
Merged
Merged
Conversation
RawFile.Open (from a path, a seekable stream or memory) and RawFile.ReadMetadata read the structure of the file and give a RawMetadata: camera, serial number, lens, exposure, ISO, capture date and clock offset, shutter count, image size, active area, colour filter pattern, bit depth and compression. No pixel is decoded. The TIFF structure is read by a small internal reader behind an internal interface. Little- and big-endian files, the Nikon MakerNote with its own header and offsets, and the choice of the largest colour filter array image among the sub-directories are handled. A file that is not a NEF, comes from another maker, or is damaged or truncated fails with a RawException and nothing else: tests truncate the file at every length, damage it at random, and put boundary values in every field of its structure, in both byte orders. Reading the metadata of a file allocates about 3 KB (checked by a test) and takes about 1.4 microseconds from memory. BenchmarkDotNet benchmarks are added to the benchmarks project, and an optional test reads every file of a folder named by RAWNET_SAMPLES_DIR.
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 2: reading the metadata of a NEF file without decoding any pixel.
RawFile.Open(path, seekable stream, memory),RawFile.ReadMetadata(path),RawMetadata,RawRectangle,CfaPattern,RawCompression,RawMediaTypes.NikonNef(image/x-nikon-nef).INefStructureReader), so another implementation could replace it. Little- and big-endian files, the Nikon MakerNote (own header, own offsets), the largest colour filter array image of the sub-directories.UnsupportedFormatException), comes from another maker (UnsupportedCameraException) or is damaged or truncated (CorruptRawFileException) fails with aRawExceptionand nothing else. I/O errors propagate; wrong arguments giveArgumentException.ToString; handle leak on failure fixed; open file share allows other readers and deletion.Checklist
dotnet format --verify-no-changesis clean.README.md,CHANGELOG.md.longarithmetic, allocations are bounded (directory buffer, 65 536 strips, 256 characters of text), and tests truncate the file at every length, damage it at random and put boundary values in every field, in both byte orders.Measurements
BenchmarkDotNet (short job, one machine): about 1.4 µs and about 3 KB allocated per read from memory; about 0.13 ms from a file of 28 MB already in the system cache. An optional test reads every file of a local folder of 570 real NEF files in well under 50 ms per file.
Not verified