# ImgDeal optional HEIC decoder

- libheif **1.23.6**, libde265 **1.0.16**, Emscripten **3.1.61**.
- Upstream sources are distributed unchanged under `source/`, with license texts beside this file.
- Build outputs are served independently as `libheif.mjs` and `libheif.wasm`. No application bundle needs to change to replace them.
- No external fetch URL is embedded in the application decoder. `heic-worker.js` supplies the same-origin WASM bytes explicitly.

## Rebuild

Install and activate the official Emscripten 3.1.61 SDK, CMake 3.31.6 and Ninja 1.11.1.4. Extract both source archives into a temporary build directory. Keep the `libde265-1.0.16.tar.gz` file in the working build directory so the upstream script does not need a network download.

```sh
mkdir heif-build
cd heif-build
CORES=4 LIBDE265_VERSION=1.0.16 USE_WASM=1 USE_ES6=1 \
  USE_TYPESCRIPT=0 USE_UNSAFE_EVAL=0 \
  bash ../libheif-1.23.6/build-emscripten.sh ../libheif-1.23.6
cp libheif.js /path/to/imgdeal/vendor/libheif/libheif.mjs
cp libheif.wasm /path/to/imgdeal/vendor/libheif/libheif.wasm
```

The build uses the original script and post.js from libheif. Dynamic JavaScript execution is disabled; WASM compilation is allowed by the privacy page's `wasm-unsafe-eval` CSP directive. Only libde265 decoding is enabled among the optional HEIC codecs. The module is single-threaded inside a dedicated, cancellable Worker.

## Replace or modify

You may rebuild or modify these library files under their respective licenses and replace the standalone files. Run `npm run build` afterward: the offline manifest contains SHA-256 checksums, so it must match replacement assets. Clear old offline resources or accept the application update before testing the replacement. The app does not sign or prevent replacement of the module.

Upstream: <https://github.com/strukturag/libheif/tree/v1.23.6> and <https://github.com/strukturag/libde265/tree/v1.0.16>.

Emscripten runtime license: see `LICENSE.emscripten` (MIT and University of Illinois/NCSA notices). Compiler tools are not shipped with the application.
