Skip to content

feature: add libjpeg-turbo and enable JPEG codec in libtiff/GDAL#57

Merged
bugra9 merged 2 commits intobugra9:mainfrom
progsung:feat/tiff-jpeg
Apr 30, 2026
Merged

feature: add libjpeg-turbo and enable JPEG codec in libtiff/GDAL#57
bugra9 merged 2 commits intobugra9:mainfrom
progsung:feat/tiff-jpeg

Conversation

@progsung
Copy link
Copy Markdown
Contributor

Build libjpeg-turbo 3.1.4.1 statically with emscripten as the @cpp.js/package-jpegturbo (and -wasm) workspace package, then wire it into libtiff via -Djpeg=ON + JPEG_INCLUDE_DIR / JPEG_LIBRARY, and into GDAL via -DGDAL_USE_JPEG=ON + JPEG_INCLUDE_DIR / JPEG_LIBRARY_RELEASE.

This lets libtiff's JPEG codec resolve at runtime, so GeoTIFFs with Compression=JPEG decode correctly instead of failing with "Cannot open TIFF file due to missing codec JPEG".

Notes:

  • The newly added packages (cppjs-package-jpegturbo and
    cppjs-package-jpegturbo-wasm) are defined with private: true
    for now. Please flip them to publishable when ready.
  • iOS and Android sub-packages are not included at this time,
    as I don't have a test environment for those platforms.

Build libjpeg-turbo 3.1.4.1 statically with emscripten as the
@cpp.js/package-jpegturbo (and -wasm) workspace package, then
wire it into libtiff via -Djpeg=ON + JPEG_INCLUDE_DIR /
JPEG_LIBRARY, and into GDAL via -DGDAL_USE_JPEG=ON +
JPEG_INCLUDE_DIR / JPEG_LIBRARY_RELEASE.

This lets libtiff's JPEG codec resolve at runtime, so GeoTIFFs
with Compression=JPEG decode correctly instead of failing with
"Cannot open TIFF file due to missing codec JPEG".

Verification: libtiff.a contains tif_jpeg.c.o, tif_jpeg_12.c.o,
and tif_ojpeg.c.o (JPEG codec compiled in). GDAL wasm builds
successfully with the JPEG driver active.

Changes (19 files, +275/-6):

- New packages under cppjs-packages/cppjs-package-jpegturbo/
  (version 2.0.0-beta.12, nativeVersion 3.1.4.1):
  * meta sub-package: package.json, cppjs.config.js, README.md,
    CHANGELOG.md, LICENSE, .npmignore
  * -wasm sub-package: package.json, cppjs.config.js, cppjs.build.js

- root package.json: include @cpp.js/package-jpegturbo in
  scripts.build:packages before tiff (preserves dependency order).

- cppjs-package-tiff-wasm:
  * cppjs.build.js: add -Djpeg=ON, JPEG_INCLUDE_DIR, JPEG_LIBRARY
  * cppjs.config.js: add jpegturboWasm to dependencies
  * package.json: add @cpp.js/package-jpegturbo-wasm workspace dep

- cppjs-package-geotiff-wasm:
  * cppjs.build.js: minor adjustment for jpeg path forwarding
  * cppjs.config.js: add jpegturboWasm to dependencies
    (libgeotiff itself does not call libjpeg, but configure's
    link test against libtiff requires the jpeg path on wasm)
  * package.json: add @cpp.js/package-jpegturbo-wasm workspace dep

- cppjs-package-gdal-wasm:
  * cppjs.build.js: add -DGDAL_USE_JPEG=ON, JPEG_INCLUDE_DIR,
    JPEG_LIBRARY_RELEASE
  * cppjs.config.js: add jpegturboWasm to dependencies
  * package.json: add @cpp.js/package-jpegturbo-wasm workspace dep

libjpeg-turbo cmake flags:
  -DENABLE_SHARED=OFF -DENABLE_STATIC=ON -DWITH_TURBOJPEG=OFF

WITH_TURBOJPEG=OFF: GDAL only uses the standard libjpeg API,
so the TurboJPEG wrapper (libturbojpeg.a) would be dead code in
the final wasm — skipping it saves build time and intermediate
output size.

WITH_SIMD is left at cmake default. libjpeg-turbo's cmake
auto-disables SIMD on wasm32 since no hand-written backend
exists for that target. If upstream adds a wasm32 SIMD backend
later, this build will pick it up automatically.
@progsung progsung requested a review from bugra9 as a code owner April 29, 2026 06:24
@bugra9 bugra9 merged commit ea0ebb6 into bugra9:main Apr 30, 2026
1 check passed
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.

3 participants