@cornerstonejs/codec-charls

中文文档
1.2.7发布于 2026/09/09MITCommonJS零依赖构建来源已验证近 30 天下载 44.8万

WASM Build of CharLS

原始使用文档
文档目录7 节
  1. Try It Out!
  2. Install
  3. Usage
  4. Building
  5. Design
  6. Performance
  7. Testing

charls-js

JavaScript/WebAssembly build of CharLS.

Try It Out!

Try it in your browser here

Install

Install this in your JavaScript project using npm:

# NOTE - this is not published yet so won't work yet...
#npm install --save-dev charls-js 

Usage

Before using this library, you must wait for it to be initialized:

const charls = require('charlsjs')
charls.onRuntimeInitialized = async _ => {
    // Now you can use it
}

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) {
  // Create a decoder instance
  const decoder = new charls.JpegLSDecoder();
  
  // get pointer to the source/encoded bit stream buffer in WASM memory
  // that can hold the encoded bitstream
  const encodedBufferInWASM = decoder.getEncodedBuffer(jpeglsEncodedBitStream.length);
  
  // copy the encoded bitstream into WASM memory buffer
  encodedBufferInWASM.set(jpeglsEncodedBitStream);
  
  // decode it
  decoder.decode();
  
  // get information about the decoded image
  const frameInfo = decoder.getFrameInfo();
  const interleaveMode = decoder.getInterleaveMode();
  const nearLossless = decoder.getNearLossless();
  
  // get the decoded pixels
  const decodedPixelsInWASM = decoder.getDecodedBuffer();
  
  // TODO: do something with the decoded pixels here (e.g. display them)
  // The pixel arrangement for color images varies depending upon the
  // interleaveMode parameter, see documentation in JpegLSDecode::getInterleaveMode()
  
  // delete the instance.  Note that this frees up memory including the
  // encodedBufferInWASM and decodedPixelsInWASM invalidating them. 
  // Do not use either after calling delete!
  decoder.delete();
}

const jpeglsEncodedBitStream = // read from file, load from URL, etc
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

Testing

pnpm run build   # compile wasm into dist/
pnpm run test    # run vitest against dist/

Tests skip cleanly when dist/ is absent.

版本与发布记录

@cornerstonejs/codec-charls 共发布 15 个版本,首次发布于 2021/02/15;过去 12 个月发布了 4 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.2.7latest2026/09/092 个月前
1.2.62026/09/012 个月前
1.2.52026/08/142 个月前
1.2.42026/08/112 个月前
1.2.32023/02/143 年前
1.2.12023/01/043 年前

关于 @cornerstonejs/codec-charls 的常见问题

@cornerstonejs/codec-charls 是什么?

WASM Build of CharLS

如何安装 @cornerstonejs/codec-charls?

在项目目录运行 npm install @cornerstonejs/codec-charls,或使用 pnpm add / yarn add / bun add。

@cornerstonejs/codec-charls 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/cornerstonejs__codec-charls 是否存在。

@cornerstonejs/codec-charls 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@cornerstonejs/codec-charls 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=0.14。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@cornerstonejs/codec-charls 可以商用吗?

@cornerstonejs/codec-charls 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cornerstonejs/codec-charls 的下载量有多少?

根据 npm 官方下载统计,@cornerstonejs/codec-charls 在 2026/10/11 – 2026/11/09 这 30 天内被下载 448,284 次,日均约 14,943 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cornerstonejs/codec-charls 还在维护吗?

最新版本 1.2.7 发布于 2026/09/09(2 个月前);至今共发布 15 个版本,其中过去 12 个月发布了 4 个;首次发布于 2021/02/15。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。