Decode predictor=2 on big-endian TIFFs by swapping to native order#1507
Merged
brendancol merged 1 commit intomainfrom May 7, 2026
Merged
Decode predictor=2 on big-endian TIFFs by swapping to native order#1507brendancol merged 1 commit intomainfrom
brendancol merged 1 commit intomainfrom
Conversation
PR #1498 reworked predictor=2 to run sample-wise via a numpy view at the file's byte order. Numba's nopython mode rejects arrays with a non-native byte order, so reading a big-endian TIFF with uint16/uint32/uint64 + predictor=2 raised "Unsupported array dtype: >u2" instead of returning the pixel data. predictor_decode and predictor_encode now byteswap the buffer in place around the kernel call for files whose byte order differs from native. Bytes on the way out stay in the file's order so the downstream chunk.view(file_dtype) step in _decode_strip_or_tile keeps working. uint8 is unaffected (single-byte path skips the view). Tests cover uint16/int16/uint32/int32 round-trips through tifffile-built big-endian predictor=2 files plus a little-endian sanity check.
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.
Summary
PR #1498 reworked predictor=2 (horizontal differencing) to run sample-wise via a numpy view in the file's byte order. Numba's nopython mode rejects arrays with a non-native byte order, so reading a big-endian TIFF with uint16/uint32/uint64 + predictor=2 raised
TypingError: Unsupported array dtype: >u2instead of returning the pixel data.predictor_decodeandpredictor_encodenow byte-swap the buffer in place around the kernel call when the file byte order differs from native, then swap back so the on-disk representation stays intact for thechunk.view(file_dtype)step in_decode_strip_or_tile. uint8 is unaffected since the single-byte path skips the view.Test plan
test_predictor2_big_endian.pycovers uint16/int16/uint32/int32 round-trips through tifffile-built BE predictor=2 deflate files.test_featuresrecursion issue is unrelated).