Add LZ4 and LERC compression codecs for geotiff#1063
Merged
brendancol merged 2 commits intomasterfrom Mar 23, 2026
Merged
Conversation
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
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
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.lercpackage. Supports lossless (max_z_error=0) and controlled-error lossy mode. Explicit CPU fallback in_gpu_decode.pyfor 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 ingpu_decode_tiles()andgpu_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)