Repository navigation
Conversation
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.
Keep reading the JPEG header after a segment length below 2, as GetJpegDimensions does
Problem
GetJpegDimensions(C++, Rust) walks a JPEG's segments from an offset until it finds the frame header (SOF0) with the image's width and height. C++ adds each segment's length to the offset and goes on, whatever the length; a length of 0 still moves it 2 bytes, past the marker it just read. The port returns an error on a length below 2, andfill_image_sizethen leaves the image at 0×0.The size decides what the image is:
FillPreviewImageData(C++, Rust) stores it as the thumbnail when neither side is above 512, and as the preview otherwise. A 0×0 image is always a thumbnail.For example, two RAFs and two RW2s from the campaigns. In each, the Exif in the preview JPEG has a 53-byte thumbnail at JpegOffset 196, and both sides look for its frame header from file offset 196 (see the note below). The port stops at byte 198, on a length of 0, in all four. C++ adds the 0 and keeps walking:
Rw2GetPreviewDatathen replaces the preview with the RW2's own, so only the empty thumbnail shows.Note: both sides read the thumbnail's frame header at its JpegOffset as a file offset (C++, Rust), while JpegOffset counts from the Exif's TIFF header, here at 1,036 in the RAFs and 516 in the RW2s. That is the same on both sides, so this PR leaves it alone.
Question
Which behaviour do we want: C++'s or the Rust port's? Specifically:
GetPreviewImageData'spreview.widthgive 1920 (like the C++ library), or give 0 (like the Rust port)?thumbnail.widthgive 160 (like the C++ library), or give 0 (like the Rust port)?thumbnail.lengthgive 0 (like the C++ library), or give 53 (like the Rust port)?thumbnail.widthgive 160 (like the C++ library), or give 0 (like the Rust port)?This PR implements C++'s behaviour.
Fix
One change covers all four:
get_jpeg_dimensionsadds it and goes on, as C++ does:The examples above then match C++. Replayed before and after:
Notes for review:
NefGetPreviewData(C++, Rust) reads the preview's size with it and returns kUnsupported when it fails, so this PR also changes a NEF whose preview JPEG has such a segment.test_get_jpeg_dimensions_corrupted_casesexpected the error for a length of 1. It now gets the read error past the end of its 14 bytes, where C++ stops too. The port's tests pass (44 + 174).