07. GDAL Integration - GrokImageCompression/grok GitHub Wiki
7. GDAL Integration
Grok provides a JPEG 2000 driver for GDAL — the JP2Grok driver.
The integration code lives in integrations/gdal/ (for reference) and is maintained upstream
in the GDAL repository at frmts/grok/.
Overview
The JP2Grok driver allows GDAL to read and write JPEG 2000 files using the Grok library as the codec backend. It supports:
- Part 1 (J2K/JP2) and Part 15 (HTJ2K/JPH) formats
- Random-access decoding using PLT/TLM markers
- Multi-threaded T1 encode/decode
- Cloud storage input via
/vsis3/,/vsiaz/,/vsigs/, etc. (see Cloud Storage) - Asynchronous swath-based decompression via
grk_decompress_wait()/grk_decompress_get_tile_image() - ICC profile handling
- Geospatial metadata (GeoJP2, GMLJP2)
Building GDAL with Grok
-
Build and install Grok:
cmake -B build -DCMAKE_INSTALL_PREFIX=/usr/local cmake --build build --parallel sudo cmake --install build -
Build GDAL with the Grok driver enabled:
cmake -B build -DGDAL_USE_GROK=ON cmake --build build --parallel
Usage
Once GDAL is built with Grok, JPEG 2000 files can be accessed through standard GDAL tools:
# Get image info
gdalinfo image.jp2
# Convert JPEG 2000 to GeoTIFF
gdal_translate image.jp2 output.tif
# Create JPEG 2000 from GeoTIFF
gdal_translate -of JP2Grok input.tif output.jp2
# Read from S3
gdalinfo /vsis3/mybucket/image.jp2
Async Decompression Pattern
The GDAL driver uses Grok's asynchronous API for efficient tile-by-tile access, which is especially beneficial for large tiled images and cloud-hosted data:
grk_decompress()— start decompression (called once)grk_decompress_wait(&swath)— wait for a swath region to be decodedgrk_decompress_get_tile_image(codec, tile_index, wait)— retrieve per-tile data
See Async Decompression API for full details.