@cornerstonejs/codec-libjxl

中文文档
1.2.0发布于 2026/10/14BSD-3-ClauseES Module零依赖构建来源已验证近 30 天下载 9.9万

WASM build of libjxl (JPEG XL) for DICOM, with the decoder and encoder as separate modules

原始使用文档
文档目录6 节
  1. Installing
  2. Usage
  3. Decoder
  4. Encoder
  5. JPEG recompression
  6. Building

@cornerstonejs/codec-libjxl

JavaScript/WebAssembly build of libjxl with separate decoder and encoder modules for JPEG XL DICOM images.

Installing

Using npm:

npm install @cornerstonejs/codec-libjxl

Using yarn:

yarn add @cornerstonejs/codec-libjxl

Usage

The package exports separate JavaScript loaders and WASM binaries for decoding and encoding:

  • @cornerstonejs/codec-libjxl/decodewasmjs
  • @cornerstonejs/codec-libjxl/decodewasm
  • @cornerstonejs/codec-libjxl/encodewasmjs
  • @cornerstonejs/codec-libjxl/encodewasm

Decoder

import createJpegXLDecoder from '@cornerstonejs/codec-libjxl/decodewasmjs';

const codec = await createJpegXLDecoder();
const decoder = new codec.JpegXLDecoder();

decoder.getEncodedBuffer(bitstream.length).set(bitstream);
decoder.decode();

const frameInfo = decoder.getFrameInfo();
const decodedPixels = decoder.getDecodedBuffer();

Encoder

import createJpegXLEncoder from '@cornerstonejs/codec-libjxl/encodewasmjs';

const codec = await createJpegXLEncoder();
const encoder = new codec.JpegXLEncoder();
const frameInfo = {
  width,
  height,
  bitsPerSample,
  componentCount,
  isSigned: false,
};

encoder.getDecodedBuffer(frameInfo).set(decodedPixels);
encoder.setLossless(true);
encoder.encode();

const bitstream = encoder.getEncodedBuffer();

The encoder accepts greyscale samples with one channel or RGB samples with three channels at bit depths from 1 to 16. Copy returned buffer views before the next operation or before calling releaseBuffers().

setProgressive(true) writes a progressive stream: a decoder can show a preview from the first part of the stream. The encoder uses the same settings as cjxl -p (responsive mode and quantised progressive AC).

JPEG recompression

The DICOM transfer syntax JPEG XL JPEG Recompression (1.2.840.10008.1.2.4.111) stores a JPEG bitstream without loss. The encoder reads the JPEG bytes, not pixels, and the decoder gives back the same JPEG bytes:

encoder.getJpegBuffer(jpeg.length).set(jpeg);
encoder.encodeJpeg();
const jxl = encoder.getEncodedBuffer().slice();

decoder.getEncodedBuffer(jxl.length).set(jxl);
decoder.decodeToJpeg(); // throws if the stream has no JPEG reconstruction data
const sameJpeg = decoder.getJpegBuffer().slice();

Each encodeJpeg() consumes the JPEG buffer, so call getJpegBuffer() again before the next frame.

decode() also decodes such a stream to pixels.

Building

This project uses a Git submodule for libjxl. Initialize the submodules from the repository root:

git submodule update --init --recursive

An activated Emscripten SDK is required. Build both WASM modules with:

cd packages/libjxl
yarn build

The generated decoder and encoder .js and .wasm files are written to dist/.

版本与发布记录

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

版本发布日期距今
1.2.0latest2026/10/1427 天前
1.1.12026/09/092 个月前
1.1.02026/09/042 个月前

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

@cornerstonejs/codec-libjxl 是什么?

WASM build of libjxl (JPEG XL) for DICOM, with the decoder and encoder as separate modules

如何安装 @cornerstonejs/codec-libjxl?

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

@cornerstonejs/codec-libjxl 支持 TypeScript 吗?

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

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

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

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

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

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

@cornerstonejs/codec-libjxl 使用 BSD-3-Clause 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。另外不得用原作者名义为衍生产品背书。以上为概括,不构成法律意见,请以许可原文为准。

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

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

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

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