Skip to content

feat: Add big endian fixtures with predictor 2 and predictor 3 - #73

Merged
kylebarron merged 1 commit into
developmentseed:mainfrom
james-willis:jw/big-endian-fixtures
Oct 5, 2026
Merged

kylebarron merged 1 commit into
developmentseed:mainfrom
james-willis:jw/big-endian-fixtures

Conversation

@james-willis

@james-willis james-willis commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Adds two big endian (MM) fixtures, as requested in developmentseed/deck.gl-raster#687.

Fixture Exercises
uint16_1band_lzw_block128_predictor2_big_endian Samples must be swapped to native order before undoing horizontal differencing, which adds neighbouring samples as integers.
float32_1band_deflate_block64_predictor3_big_endian Predictor 3 byte planes are most significant byte first whatever the file's byte order, so these samples must not be swapped.

Both are 128×128 with 64×64 tiles and one overview, and pass rio cogeo validate.

How they're made

GDAL's COG driver has no ENDIANNESS option, so a new rewrite_big_endian helper in write_utils.py copies a little endian COG through the GTiff driver with COPY_SRC_OVERVIEWS=YES and ENDIANNESS=BIG, which keeps the COG layout. The uint16 fixture is rewritten from uint16_1band_lzw_block128_predictor2; the float32 one from a np.linspace COG built the same way as float32_1band_lerc_block32.

Tiling, compression and predictor are copied from the source, which relies on #74 (write_cog now writes the predictor into the COG).

Tests

tests/test_big_endian.py checks, for each fixture, that the file starts with MM, that every IFD carries the expected predictor (via tifffile), and that every level matches its little endian source as read by rasterio. pyproject.toml gains pythonpath = ["."] so the test can import the generators. pixi run check and pixi run test pass locally, and regenerating is byte-for-byte stable.

Downstream check

With deck.gl-raster's fixtures submodule pointed at this branch and both fixtures added to integration-rasterio.test.ts:

GDAL's COG driver can't write big endian files, so these are rewritten
from a little endian COG through the GTiff driver with COPY_SRC_OVERVIEWS,
which keeps the COG layout.

- uint16_1band_lzw_block128_predictor2_big_endian: readers must swap
  samples to native order before undoing horizontal differencing.
- float32_1band_deflate_block64_predictor3_big_endian: predictor 3 byte
  planes are most significant byte first in every file, so readers must
  not swap these samples.

A test checks that both files are MM, carry their predictor on every IFD,
and match their little endian source at every level.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The fixtures, generation path, metadata, and regression coverage consistently satisfy the stated endian and predictor requirements.

Review effort: Balanced
Findings: None

What changed in this PR

Adds big-endian predictor fixtures to validate downstream GeoTIFF decoding behavior.

Changes:

  • Adds Predictor 2 and Predictor 3 big-endian COG fixtures.
  • Adds reusable endian-rewriting logic and fixture validation tests.
  • Configures pytest imports for generator modules.
File Description
pyproject.toml Adds the repository root to pytest’s Python path.
rasterio_generated/​write_utils.py Adds the big-endian COG rewrite helper.
tests/​test_big_endian.py Validates byte order, predictors, and pixels.
rasterio_generated/​fixtures/​uint16_1band_lzw_block128_predictor2_big_endian.py Generates the Predictor 2 fixture.
rasterio_generated/​fixtures/​uint16_1band_lzw_block128_predictor2_big_endian.tif Provides the generated uint16 fixture.
rasterio_generated/​fixtures/​uint16_1band_lzw_block128_predictor2_big_endian_info.md Records uint16 fixture metadata.
rasterio_generated/​fixtures/​float32_1band_deflate_block64_predictor3_big_endian.py Generates the Predictor 3 fixture.
rasterio_generated/​fixtures/​float32_1band_deflate_block64_predictor3_big_endian.tif Provides the generated float32 fixture.
rasterio_generated/​fixtures/​float32_1band_deflate_block64_predictor3_big_endian_info.md Records float32 fixture metadata.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@kylebarron kylebarron left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@kylebarron
kylebarron merged commit ffbbfcd into developmentseed:main Oct 5, 2026
1 check passed
kylebarron added a commit that referenced this pull request Oct 5, 2026
uint16_1band_lzw_block128_predictor2_big_endian is rewritten from
uint16_1band_lzw_block128_predictor2. #73 was branched before #76
changed that source to 256x256 with 128x128 tiles and triangle wave
data, and was merged without rebasing. So the committed file still held
the old 128x128 source with 64x64 tiles, and the "generated files are
up to date" check on main failed.

Regenerate the file and its info, and fix the docstring to give the new
size and tiling.

Co-authored-by: Claude Opus 5.5 <[email protected]>
kylebarron added a commit to developmentseed/deck.gl-raster that referenced this pull request Oct 13, 2026
)

Closes #686.

Big endian (`MM`) TIFFs decoded to byte-swapped pixel values:
`toTypedArray` views the decoded bytes in the platform's byte order, and
`DecoderMetadata` didn't carry the file's.

### Changes

- `DecoderMetadata` gains an optional `littleEndian` (default `true`, so
existing callers of `decode()` are unaffected). `fetch.ts` sets it from
`image.tiff.isLittleEndian` for both data and mask tiles.
- `decode()` byte-swaps samples wider than 8 bits from big endian files,
**before** `applyPredictor`, since horizontal differencing (predictor 2)
has to accumulate native-order integers.
- Predictor 3 is excluded: its byte planes are most significant byte
first in every file (TIFF Technical Note 3), and
`decodeRowFloatingPoint` already reassembles them in platform order.
- The swap writes to a new buffer, because the uncompressed decoder
returns the caller's bytes, which may be shared with the block cache.
- Codecs that return typed pixels (LERC, JPEG, WebP) don't go through
this path and are unchanged.

### Tests

Three unit tests in `decode.test.ts` build big endian tiles from known
values:

- float32, no predictor (also asserts the input buffer is untouched)
- uint16, predictor 2
- float32, predictor 3, decoded as both `II` and `MM`, which must agree

The first two fail on main; the third fails if the swap is applied to
predictor 3. `pnpm typecheck` and `biome check` are clean.

The second commit bumps `fixtures/geotiff-test-data` to pick up its big
endian fixtures (developmentseed/geotiff-test-data#73, #77) and adds
both to `integration-rasterio.test.ts`:

- `uint16_1band_lzw_block128_predictor2_big_endian`: fails `tile pixel
data matches` on main, passes here.
- `float32_1band_deflate_block64_predictor3_big_endian`: passes either
way, and guards against swapping predictor 3 byte planes.

With `pixi run generate-npy` as in CI, the integration suite passes
19/19 here and fails only the uint16 big endian case against main's
`decode.ts` / `fetch.ts`.

---------

Co-authored-by: Kyle Barron <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants