Repository navigation
Conversation
C++ fails a directory whose size tags do not read, writes every size it reads, and does not read NewSubfileType for DNG. The port ignored a size that did not read, kept only a larger one, and skipped reduced-size DNG directories.
This was referenced Nov 4, 2026
Collaborator
|
I think this is outdated after updating the C++ code export. Will close, but please reopen if I'm wrong. |
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.
Read the full image size as FillPreviewImageData does
Problem
GetPreviewImageDatafills a directory's fields withFillPreviewImageData(C++, Rust), and the two readfull_widthandfull_heightdifferently.C++ does
success &= GetFullDimension32(...)on every directory:full_widthandfull_height, whatever was there;TiffParser::GetPreviewImageDatathen skips that IFD's Exif, GPS and SubIFDs.The port ignores a size that does not read, writes it only when both values are larger than what is there, and does not take the size from directories whose NewSubfileType is not 0. For DNG it is the only side that reads NewSubfileType at all:
DNG_TAGSasks for it, and C++'s tag set does not.For example:
iso0, GPS not validiso200, GPS validfull_width1024,full_height0full_width×full_height1024×768C++ is on the left and the Rust port on the right in the pictures below. Each panel shows what a viewer would get from that side's fields.
1. A size that does not read
When IFD0's size tags do not read, C++ fails IFD0 and leaves its Exif, GPS and SubIFDs unread. In a DNG this ends in kFail. In a NEF whose IFD0 ImageWidth has two values, C++ goes on to IFD1, which has the thumbnail, and returns kOk with that thumbnail and no preview. The port reads the preview and returns kUnsupported, because it has no full size to compare the preview with:
2. A size already in the caller's PreviewImageData
GetPreviewImageDatawrites into the caller'sPreviewImageData. C++ overwritesfull_widthandfull_heightwith each size it reads. The port keeps whatever was there unless both new values are larger, so a reusedPreviewImageDatawithfull_width1024 comes back as 1024×0 from a 1024×768 file.3. A DNG as converters write it
A DNG converter writes IFD0 as a thumbnail (NewSubfileType 1), and in its SubIFDs puts the raw image (NewSubfileType 0, DefaultCropSize 6000×4000) and then a JPEG preview (NewSubfileType 1, ImageWidth 1024, ImageLength 768). C++ does not read NewSubfileType here. It overwrites the size at every directory, and the preview's directory comes last, so C++ reports the preview's 1024×768 as the full image. The port does not take the size from the two NewSubfileType 1 directories and reports the raw's 6000×4000. The red frame is the full image each side reports, with the preview drawn to scale inside it:
Question
Which behaviour do we want: C++'s or the Rust port's? Specifically:
full_widthandfull_height(like the C++ library), or only a larger one (like the Rust port)?This PR implements C++'s behaviour.
Fix
This PR changes the port to follow C++'s
FillPreviewImageDataandDngGetPreviewData:fill_preview_image_data, an error fromget_full_dimension32setssuccess = false.TagNotFound, the port's answer when there are no size tags at all, does not: C++'sGetFullDimension32returns true then.full_widthandfull_heighttake the size whenever it reads, larger or not.TIFF_TAG_SUB_FILE_TYPEleavesDNG_TAGS, which then holds C++'s tag set. No preview tag set reads NewSubfileType after this, sois_secondarystays false, as in C++.The examples above then return what C++ returns. Replayed before and after (x86-64):
iso0iso200iso0full_width1024 handed inNotes for review:
GetFullDimension32writesfull_widthbefore it fails on an ImageLength that does not read, and the port'sget_full_dimension32returns both values or neither. A NEF with that shape still differs infull_width. Write full_width before failing on the height, as GetFullDimension32 does #18 covers it.