@bb-studio/exr

中文文档
0.2.0发布于 2026/09/20MITTypeScriptESM + CJS近 30 天下载 4647

OpenEXR scanline parser/decoder/encoder and backend-neutral RGBA helpers for browser and Node.js

原始使用文档
文档目录7 节
  1. Install
  2. Image API
  3. Core API
  4. Browser Worker Helpers
  5. Error/Diagnostics
  6. Writer Support
  7. License

@bb-studio/exr

npm version GitHub Pages GitHub

OpenEXR scanline parser/decoder/encoder and backend-neutral RGBA helpers for browser and Node.js.

Install

npm install @bb-studio/exr

Image API

import { decodeExrRgba, encodeExrRgba, inspectExrImage } from '@bb-studio/exr';

const info = inspectExrImage(buffer);
const image = decodeExrRgba(buffer);
const encodedImage = encodeExrRgba(
  { width: image.width, height: image.height, rgba: image.rgba },
  { precision: 'half', includeAlpha: true },
);

decodeExrRgba selects the requested part, or the first part with a data window, expands sampled channels, and resolves conventional RGB/A names including layered suffixes and Y/luma fallback. The result retains data/display windows, channel descriptors, and part attributes.

encodeExrRgba accepts straight Float32Array RGBA pixels plus optional named channels, typed attributes, compression, and non-zero data/display windows. It returns EXR bytes and has no Blob, renderer, or platform dependency.

Core API

import { parseExr, decodeExrPart, readExr, writeExr } from '@bb-studio/exr';

const buffer = await fetch('/image.exr').then((r) => r.arrayBuffer());
const structure = parseExr(buffer);
const decoded = decodeExrPart(buffer, structure, { partId: structure.parts[0].id });

// Convenience parse+decode in one call
const result = readExr(buffer);

// Encode scanline EXR
const encoded = writeExr({
  parts: [
    {
      compression: 3, // ZIP
      dataWindow: { xMin: 0, yMin: 0, xMax: 1, yMax: 1 },
      channels: [{ name: 'R', pixelType: 2, data: new Float32Array([0, 1, 2, 3]) }],
    },
  ],
});

Each part may also provide typed string, int, float, or chromaticities attributes:

const attributes = {
  ocioColorSpace: { type: 'string', value: 'ACEScg' },
  chromaticities: {
    type: 'chromaticities',
    value: {
      redX: 0.713,
      redY: 0.293,
      greenX: 0.165,
      greenY: 0.83,
      blueX: 0.128,
      blueY: 0.044,
      whiteX: 0.32168,
      whiteY: 0.33767,
    },
  },
} as const;

decodeExrPart returns sampled-native channel planes with sampling metadata. To materialize only specific physical channels, pass exact names through channelNames:

const depth = decodeExrPart(buffer, structure, {
  partId: structure.parts[0].id,
  channelNames: ['depth.Z'],
});

The decoder still decompresses each required scanline chunk because OpenEXR compression is chunk-based, but it allocates and converts sample planes only for the selected channels. Unselected channel bytes are skipped while preserving their physical row layout. Unknown requested names fail with CHANNEL_NOT_FOUND. The worker-assisted decodeExrPartWithWorkers API accepts the same selection.

Browser Worker Helpers

import { decodeExrPartWithWorkers, expandDecodedPartChannels } from '@bb-studio/exr/browser';
  • decodeExrPartWithWorkers optionally pre-decodes ZIP/DWA chunks using workers.
  • decodeExrRgbaWithWorkers applies the same RGBA semantics through the worker-assisted path.
  • expandDecodedPartChannels is available from the root package and remains re-exported here for existing browser consumers.

Error/Diagnostics

  • Typed failures via ExrError and ExrErrorCode.
  • Structured progress events via onEvent callbacks (ExrEvent, ExrEventCode).

Writer Support

  • Scanline single-part and multipart writing.
  • Compression: NO_COMPRESSION, RLE_COMPRESSION, ZIPS_COMPRESSION, ZIP_COMPRESSION, PIZ_COMPRESSION, PXR24_COMPRESSION, B44_COMPRESSION, B44A_COMPRESSION.
  • Pixel types: UINT, HALF, FLOAT.

License

版本与发布记录

@bb-studio/exr 共发布 5 个版本,首次发布于 2026/03/14;过去 12 个月发布了 5 个版本。

版本发布日期距今
0.2.0latest2026/09/201 个月前
0.1.32026/08/302 个月前
0.1.22026/06/284 个月前
0.1.12026/03/147 个月前
0.1.02026/03/147 个月前

关于 @bb-studio/exr 的常见问题

@bb-studio/exr 是什么?

OpenEXR scanline parser/decoder/encoder and backend-neutral RGBA helpers for browser and Node.js

如何安装 @bb-studio/exr?

在项目目录运行 npm install @bb-studio/exr,或使用 pnpm add / yarn add / bun add。

@bb-studio/exr 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bb-studio/exr 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@bb-studio/exr 可以商用吗?

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

@bb-studio/exr 的下载量有多少?

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

@bb-studio/exr 还在维护吗?

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