Skip to content

07. GDAL Integration

Aaron Boxer edited this page Mar 25, 2026 · 1 revision

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

  1. Build and install Grok:

    cmake -B build -DCMAKE_INSTALL_PREFIX=/usr/local
    cmake --build build --parallel
    sudo cmake --install build
  2. 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:

  1. grk_decompress() — start decompression (called once)
  2. grk_decompress_wait(&swath) — wait for a swath region to be decoded
  3. grk_decompress_get_tile_image(codec, tile_index, wait) — retrieve per-tile data

See Async Decompression API for full details.

Clone this wiki locally