Skip to content

feat: Add big endian LERC fixtures - #81

Merged
kylebarron merged 1 commit into
mainfrom
kyle/big-endian-lerc-fixtures
Oct 13, 2026
Merged

kylebarron merged 1 commit into
mainfrom
kyle/big-endian-lerc-fixtures

Conversation

@kylebarron

Copy link
Copy Markdown
Member

Note

This PR was written by Claude (Claude Code), not by @kylebarron.

Ref developmentseed/deck.gl-raster#704, developmentseed/deck.gl-raster#705.

Adds two big endian (MM) LERC fixtures:

  • uint16_1band_lerc_block64_big_endian
  • float32_1band_lerc_block64_big_endian

Both are 128×128 with 64×64 tiles and one overview, rewritten from a little endian LERC COG with rewrite_big_endian, like the existing big endian fixtures. Both are registered in tests/test_big_endian.py, which checks that every level reads back the same as the little endian source.

Why

libtiff swaps samples into the file's byte order before passing them to any codec, LERC included, so the LERC data in a big endian file holds byte-swapped values. A reader that only swaps raw codecs like DEFLATE decodes these wrong. deck.gl-raster did (#704, fixed in #705); async-tiff already reads them correctly.

A GDAL quirk the float32 data avoids

GDAL loses any float whose byte-swapped bits form a NaN. LERC stores NaN as an invalid pixel, so GDAL reads the value back as a byte-swapped NaN (6.9055e-41). The np.linspace(0, 1) data used by float32_1band_lerc_block32 loses 124 of 16,384 pixels this way when written big endian, whichever way the file is written.

The float32 fixture uses multiples of 1/16 between -512 and 512 instead, so the low byte of every mantissa is zero and no value can swap to a NaN. The generator checks this at every level and raises if it fails. The uint16 fixture can't hit this.

Checks

  • pixi run generate and pixi run info change nothing except the new files.
  • pixi run test passes (62), including both new cases in test_big_endian.
  • ruff check and ruff format --check are clean.
  • Tile (0, 0) of each fixture matches GDAL in async-tiff 0.7.0 and in deck.gl-raster with #705, and doesn't match on deck.gl-raster main.

🤖 Written by Claude Code

libtiff swaps samples into the file's byte order before passing them to
any codec, LERC included, so the LERC data in a big endian file holds
byte-swapped values. Readers that only swap raw codecs like DEFLATE get
these wrong (developmentseed/deck.gl-raster#704).

Add uint16 and float32 big endian LERC fixtures, and check both in
test_big_endian.

GDAL loses any float whose byte-swapped bits are a NaN, because LERC
stores NaN as an invalid pixel. The float32 values are multiples of 1/16,
so no value swaps to a NaN, and the generator checks that at every level.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I wish rio cogeo info printed out endianness 🥲

@kylebarron

Copy link
Copy Markdown
Member Author

This seems fine to me

@kylebarron
kylebarron merged commit 892dc40 into main Oct 13, 2026
1 check passed
@kylebarron
kylebarron deleted the kyle/big-endian-lerc-fixtures branch October 13, 2026 15:57
kylebarron added a commit to developmentseed/deck.gl-raster that referenced this pull request Oct 13, 2026
Bump geotiff-test-data to pick up its big endian LERC fixtures
(developmentseed/geotiff-test-data#81) and add both to the rasterio
integration test. On main both fail tile pixel data matches.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kylebarron added a commit to developmentseed/deck.gl-raster that referenced this pull request Oct 16, 2026
> [!NOTE]
> This PR was written by Claude (Claude Code), not by @kylebarron.

Closes #704.

LERC tiles from big endian (`MM`) files decoded byte-swapped. libtiff
swaps samples into the file's byte order before passing them to any
codec, LERC included, so the LERC data in a big endian file holds
byte-swapped values. #687 only swapped the output of codecs that return
raw bytes.

### Changes

- `decode()` now also byte-swaps the typed pixels a codec returns when
the file is big endian and samples are wider than 8 bits. In practice
that means LERC, LERC_DEFLATE and LERC_ZSTD. JPEG and WebP output is
8-bit, so it's untouched.
- The swap happens in place. The `lerc` package copies decoded pixels
out of WASM memory into a new buffer, so nothing else references it.
- `swapBytesInPlace` now takes a `Uint8Array`, because LERC bands are
`subarray` views into one shared buffer.

### Tests

- New unit test in `decode.test.ts`: decoding the existing
`float32_1band_lerc_block32` tile as big endian must give exactly the
little endian result with each sample's bytes reversed. It fails on
`main`.
- The second commit bumps `fixtures/geotiff-test-data` to pick up its
new big endian LERC fixtures (developmentseed/geotiff-test-data#81) and
adds both to `integration-rasterio.test.ts`:
`uint16_1band_lerc_block64_big_endian` and
`float32_1band_lerc_block64_big_endian`. Both fail `tile pixel data
matches` on `main` and pass here. The bump also brings in
geotiff-test-data #78–#80, which no test here uses.
- All package tests pass, including `geotiff` (166/166) with the
rasterio integration suite, and `pnpm typecheck` and `biome check` are
clean.

🤖 Written by [Claude Code](https://claude.com/claude-code)

---------

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.

1 participant