@team-charls/charls-wasm
v0.8.0
Published
WebAssembly build of CharLS - High-performance JPEG-LS codec for browsers and Node.js
Maintainers
Readme
CharLS WebAssembly
CharLS WebAssembly is a WebAssembly build of CharLS, a high-performance JPEG-LS codec library. This package provides JavaScript/TypeScript bindings for encoding and decoding JPEG-LS images in both Node.js and browser environments.
This project was originally forked from charls-js, created by Chris Hafey. It has been updated to use Wasm 3.0 and the latest version of CharLS.
Installation
npm install @team-charls/charls-wasmQuick Start
Decoding a JPEG-LS Image
import { createJpegLSDecoder } from '@team-charls/charls-wasm'
// Typical pattern is to re-use decoder instances for better performance.
const decoder = await createJpegLSDecoder()
function decodeImage (sourceBuffer) {
const destinationBuffer = decoder.decode(sourceBuffer)
console.log('Frame info:', decoder.getFrameInfo())
console.log('Interleave mode:', decoder.getInterleaveMode())
console.log('Near lossless:', decoder.getNearLossless())
return destinationBuffer
}Encoding to JPEG-LS
import { createJpegLSEncoder } from '@team-charls/charls-wasm'
// Typical pattern is to re-use encoder instances for better performance.
const encoder = await createJpegLSEncoder()
function encodeImageLossless (pixelBuffer, frameInfo) {
const destinationBuffer = encoder.encode(pixelBuffer,
frameInfo.width,
frameInfo.height,
frameInfo.bitsPerSample,
frameInfo.componentCount,
0, // Interleave mode (0 = none, 1 = line, 2 = sample)
0, // Encoding options bitmask (0=none, 1=evenSize, 2=includeVersion, 4=includePCParametersJAI)
0 // NEAR parameter (0 = lossless, >0 = near-lossless)
)
return destinationBuffer
}API Reference
Factory Functions
createJpegLSDecoder()- Creates a new decoder instance (async)createJpegLSEncoder()- Creates a new encoder instance (async)initializeModule()- Explicitly initialize the WASM module (optional, called automatically)
Classes
JpegLSDecoder- Decoder class for advanced usageJpegLSEncoder- Encoder class for advanced usageJpegLSError- Custom error class for JPEG-LS operations
Supported Platforms
All environments that can run Wasm 3.0 modules are supported:
- Browsers: Chrome/Edge 137+, Firefox 131+, Safari 26.2+
- Node.js: 18.0+
Examples
For complete examples, see:
Resources
License
BSD-3-Clause - See LICENSE.md
