@discourse/jxr
v1.0.0
Published
Wasm JPEG XR decoder supporting the browser.
Downloads
36
Readme
@jsquash/jxr
An easy way to decode JPEG XR images in the browser with WebAssembly.
Uses the jxrlib library.
A jSquash package.
Installation
npm install --save @jsquash/jxrUsage
Note: You will need to either manually include the wasm files from the codec directory or use a bundler like WebPack or Rollup to include them in your app/server.
decode(data: ArrayBuffer): Promise<ImageData>
Decodes JPEG XR binary data to ImageData.
Example
import { decode } from '@jsquash/jxr';
const imageBuffer = await fetch('/example.jxr').then((res) => res.arrayBuffer());
const imageData = await decode(imageBuffer);Manual WASM initialisation (not recommended)
The decode module exports an init function that can be used to manually load the wasm module.
import decode, { init as initJXRDecode } from '@jsquash/jxr/decode';
initJXRDecode(WASM_MODULE);
const image = await fetch('./image.jxr').then((res) => res.arrayBuffer()).then(decode);You can also pass custom options to the init function to customise the behaviour of the module. See the Emscripten documentation for more information.
import decode, { init as initJXRDecode } from '@jsquash/jxr/decode';
initJXRDecode(null, {
locateFile: (path, prefix) => `https://example.com/${prefix}/${path}`,
});