charls-js
JS/WebAssembly build of CharLS
Try It Out!
Try it in your browser here
Install
Install this in your JavaScript project using npm:
Usage
Before using this library, you must wait for it to be initialized:
const charls = require('charlsjs')
charls.onRuntimeInitialized = async _ => {
}
To decode a JPEG-LS image, create a decoder instance, copy the JPEG-LS bitstream
into its memory space, decode it, copy the decoded pixels out of its memory
space and finally, delete the decoder instance.
function decode(jpeglsEncodedBitStream) {
const decoder = new charls.JpegLSDecoder();
const encodedBufferInWASM = decoder.getEncodedBuffer(jpeglsEncodedBitStream.length);
encodedBufferInWASM.set(jpeglsEncodedBitStream);
decoder.decode();
const frameInfo = decoder.getFrameInfo();
const interleaveMode = decoder.getInterleaveMode();
const nearLossless = decoder.getNearLossless();
const decodedPixelsInWASM = decoder.getDecodedBuffer();
decoder.delete();
}
const jpeglsEncodedBitStream =
decode(jpeglsEncodedBitStream)
See examples for browsers and nodejs.
Also read the API documentation for JpegLSDecoder.hpp and
JpegLSEncoder.hpp
Building
See information about building here
Design
Read about the design considerations that went into this library here
Performance
Read about the encode/decode performance of this library with NodeJS 14,
Google Chrome and FireFox vs Native here