Skip to content

Decode predictor=2 on big-endian TIFFs by swapping to native order#1507

Merged
brendancol merged 1 commit intomainfrom
fix-predictor2-be-numba
May 7, 2026
Merged

Decode predictor=2 on big-endian TIFFs by swapping to native order#1507
brendancol merged 1 commit intomainfrom
fix-predictor2-be-numba

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

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: >u2 instead of returning the pixel data.

predictor_decode and predictor_encode now 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 the chunk.view(file_dtype) step in _decode_strip_or_tile. uint8 is unaffected since the single-byte path skips the view.

Test plan

  • New test_predictor2_big_endian.py covers uint16/int16/uint32/int32 round-trips through tifffile-built BE predictor=2 deflate files.
  • Little-endian predictor=2 still round-trips (sanity).
  • uint8 BE+pred2 still works (single-byte byte-wise path).
  • Full geotiff test suite passes (552 passed; pre-existing matplotlib test_features recursion issue is unrelated).

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.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label May 7, 2026
@brendancol brendancol merged commit e387c29 into main May 7, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant