Skip to content

Add LZ4 and LERC compression codecs for geotiff#1063

Merged
brendancol merged 2 commits intomasterfrom
additional-geotiff-fixes
Mar 23, 2026
Merged

Add LZ4 and LERC compression codecs for geotiff#1063
brendancol merged 2 commits intomasterfrom
additional-geotiff-fixes

Conversation

@brendancol
Copy link
Contributor

Summary

  • LZ4 (TIFF tag 50004): CPU codec via lz4.frame. Decompress/compress functions, dispatcher entries, writer tag mapping. GDAL-compatible frame format. GPU path deferred since nvCOMP uses raw LZ4 and the frame-format bridging needs more work.
  • LERC (TIFF tag 34887): CPU codec via Esri's lerc package. Supports lossless (max_z_error=0) and controlled-error lossy mode. Explicit CPU fallback in _gpu_decode.py for both read and write since no GPU LERC library exists.

Both follow the existing optional-dependency pattern (availability flag, lazy import, ImportError with install hint).

Closes #1051, closes #1052.

Files changed

  • _compression.py: LZ4 and LERC codec functions, constants, dispatch entries
  • _writer.py: compression tag mappings, LERC special handling in strip/tile writers
  • _gpu_decode.py: LERC CPU fallback in gpu_decode_tiles() and gpu_compress_tiles()
  • tests/test_lz4.py: 13 tests (codec roundtrips, write-read, availability)
  • tests/test_lerc.py: 13 tests (codec roundtrips, lossy tolerance, write-read, availability)

Test plan

  • pytest xrspatial/geotiff/tests/test_lz4.py (13 pass)
  • pytest xrspatial/geotiff/tests/test_lerc.py (13 pass)
  • pytest xrspatial/geotiff/tests/ full suite (338 pass, no regressions)

Add CPU LZ4 codec using python-lz4 (lz4.frame format) for TIFF
compression tag 50004. GPU nvCOMP acceleration deferred to a follow-up
since GDAL uses lz4-frame format which needs bridging to nvCOMP's raw
LZ4 format -- the CPU fallback path handles GPU reads/writes correctly
in the meantime.

Changes:
- _compression.py: lz4_decompress/lz4_compress functions, COMPRESSION_LZ4
  constant, wired into decompress/compress dispatchers
- _writer.py: 'lz4' key in _compression_tag mapping
- tests/test_lz4.py: 13 tests covering codec roundtrips, write-read
  roundtrips (tiled, stripped, float32, predictor), public API, and
  error handling when lz4 is not installed
Adds support for LERC (Limited Error Raster Compression, TIFF tag 34887)
to the geotiff module. LERC is CPU-only and wraps Esri's C library via
the `lerc` Python package. The key feature is the max_z_error parameter
which guarantees a maximum per-pixel encoding error (0 = lossless).

Changes:
- _compression.py: lerc_compress/lerc_decompress functions, COMPRESSION_LERC
  constant, dispatch entries in compress() and decompress()
- _writer.py: LERC in compression tag map, strip writer, tile writer
- _gpu_decode.py: explicit CPU fallback for LERC in both decode and encode
  paths (no GPU LERC library exists)
- tests/test_lerc.py: codec roundtrips (float32, uint8, uint16), lossy
  tolerance check, write-read roundtrips (tiled, stripped, public API),
  availability flag tests
@github-actions github-actions bot added the performance PR touches performance-sensitive code label Mar 23, 2026
@brendancol brendancol merged commit 784168f into master Mar 23, 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.

Add LERC compression for controlled-error lossy raster encoding Add LZ4 compression via nvCOMP and python-lz4

1 participant