@bb-studio/exr 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -63,6 +63,8 @@ interface ExrStructure {
63
63
  type ParseExrOptions = EventCapableOptions;
64
64
  interface DecodeExrPartOptions extends EventCapableOptions {
65
65
  partId: number;
66
+ /** Exact physical channel names to materialize. Omit to decode every channel in the part. */
67
+ channelNames?: readonly string[];
66
68
  predecodedZipBlocks?: Map<number, Uint8Array>;
67
69
  predecodedDwaBlocks?: Map<number, Uint8Array>;
68
70
  }
@@ -116,7 +118,7 @@ interface WriteExrInput {
116
118
  }
117
119
  type WriteExrOptions = EventCapableOptions;
118
120
 
119
- type ExrErrorCode = 'BUFFER_TOO_SMALL' | 'INVALID_MAGIC' | 'TRUNCATED_FILE' | 'MALFORMED_HEADER' | 'PART_NOT_FOUND' | 'UNSUPPORTED_PART_TYPE' | 'UNSUPPORTED_COMPRESSION' | 'MISSING_DATA_WINDOW' | 'MALFORMED_OFFSET_TABLE' | 'MALFORMED_CHUNK' | 'DECOMPRESSION_FAILED' | 'INVALID_WRITE_INPUT' | 'UNSUPPORTED_WRITE_COMPRESSION' | 'ENCODING_FAILED';
121
+ type ExrErrorCode = 'BUFFER_TOO_SMALL' | 'INVALID_MAGIC' | 'TRUNCATED_FILE' | 'MALFORMED_HEADER' | 'PART_NOT_FOUND' | 'CHANNEL_NOT_FOUND' | 'UNSUPPORTED_PART_TYPE' | 'UNSUPPORTED_COMPRESSION' | 'MISSING_DATA_WINDOW' | 'MALFORMED_OFFSET_TABLE' | 'MALFORMED_CHUNK' | 'DECOMPRESSION_FAILED' | 'INVALID_WRITE_INPUT' | 'UNSUPPORTED_WRITE_COMPRESSION' | 'ENCODING_FAILED';
120
122
  declare class ExrError extends Error {
121
123
  readonly code: ExrErrorCode;
122
124
  readonly details?: Record<string, string | number>;
@@ -176,10 +178,12 @@ declare function decodeExrRgba(buffer: ExrBinaryInput, options?: DecodeExrRgbaOp
176
178
  declare function writeExr(input: WriteExrInput, options?: WriteExrOptions): Uint8Array;
177
179
 
178
180
  type ExrRgbaPrecision = 'half' | 'float';
181
+ /** UINT uses the decoder's normalized [0, 1] representation of the full uint32 range. */
182
+ type ExrNamedChannelPrecision = 'uint' | ExrRgbaPrecision;
179
183
  interface ExrRgbaNamedChannel {
180
184
  name: string;
181
185
  data: Float32Array;
182
- precision?: ExrRgbaPrecision;
186
+ precision?: ExrNamedChannelPrecision;
183
187
  }
184
188
  interface EncodeExrRgbaImage {
185
189
  width: number;
@@ -198,4 +202,4 @@ interface EncodeExrRgbaOptions {
198
202
  }
199
203
  declare function encodeExrRgba(image: EncodeExrRgbaImage, options: EncodeExrRgbaOptions): Uint8Array;
200
204
 
201
- export { type DecodeExrPartOptions, type DecodeExrRgbaOptions, type DecodedChannel, type DecodedExrRgbaImage, type DecodedPart, EXR_EVENT_CODES, type EncodeExrRgbaImage, type EncodeExrRgbaOptions, type EventCapableOptions, type ExrBinaryInput, type ExrChannel, type ExrChromaticities, type ExrCompression, ExrError, type ExrErrorCode, type ExrEvent, type ExrEventCallback, type ExrEventCode, type ExrEventLevel, type ExrEventPhase, type ExrImageInfo, type ExrPart, type ExrPixelType, type ExrRgbaNamedChannel, type ExrRgbaPrecision, type ExrStructure, type ExrWindow, type InspectExrImageOptions, type ParseExrOptions, type ReadExrOptions, type ReadExrResult, type WriteExrAttribute, type WriteExrChannelInput, type WriteExrInput, type WriteExrOptions, type WriteExrPartInput, decodeExrPart, decodeExrRgba, encodeExrRgba, expandDecodedPartChannels, expandSampledChannel, inspectExrImage, isExrError, parseExr, parseExrStructure, readExr, toArrayBuffer, writeExr };
205
+ export { type DecodeExrPartOptions, type DecodeExrRgbaOptions, type DecodedChannel, type DecodedExrRgbaImage, type DecodedPart, EXR_EVENT_CODES, type EncodeExrRgbaImage, type EncodeExrRgbaOptions, type EventCapableOptions, type ExrBinaryInput, type ExrChannel, type ExrChromaticities, type ExrCompression, ExrError, type ExrErrorCode, type ExrEvent, type ExrEventCallback, type ExrEventCode, type ExrEventLevel, type ExrEventPhase, type ExrImageInfo, type ExrNamedChannelPrecision, type ExrPart, type ExrPixelType, type ExrRgbaNamedChannel, type ExrRgbaPrecision, type ExrStructure, type ExrWindow, type InspectExrImageOptions, type ParseExrOptions, type ReadExrOptions, type ReadExrResult, type WriteExrAttribute, type WriteExrChannelInput, type WriteExrInput, type WriteExrOptions, type WriteExrPartInput, decodeExrPart, decodeExrRgba, encodeExrRgba, expandDecodedPartChannels, expandSampledChannel, inspectExrImage, isExrError, parseExr, parseExrStructure, readExr, toArrayBuffer, writeExr };
package/dist/index.d.ts CHANGED
@@ -63,6 +63,8 @@ interface ExrStructure {
63
63
  type ParseExrOptions = EventCapableOptions;
64
64
  interface DecodeExrPartOptions extends EventCapableOptions {
65
65
  partId: number;
66
+ /** Exact physical channel names to materialize. Omit to decode every channel in the part. */
67
+ channelNames?: readonly string[];
66
68
  predecodedZipBlocks?: Map<number, Uint8Array>;
67
69
  predecodedDwaBlocks?: Map<number, Uint8Array>;
68
70
  }
@@ -116,7 +118,7 @@ interface WriteExrInput {
116
118
  }
117
119
  type WriteExrOptions = EventCapableOptions;
118
120
 
119
- type ExrErrorCode = 'BUFFER_TOO_SMALL' | 'INVALID_MAGIC' | 'TRUNCATED_FILE' | 'MALFORMED_HEADER' | 'PART_NOT_FOUND' | 'UNSUPPORTED_PART_TYPE' | 'UNSUPPORTED_COMPRESSION' | 'MISSING_DATA_WINDOW' | 'MALFORMED_OFFSET_TABLE' | 'MALFORMED_CHUNK' | 'DECOMPRESSION_FAILED' | 'INVALID_WRITE_INPUT' | 'UNSUPPORTED_WRITE_COMPRESSION' | 'ENCODING_FAILED';
121
+ type ExrErrorCode = 'BUFFER_TOO_SMALL' | 'INVALID_MAGIC' | 'TRUNCATED_FILE' | 'MALFORMED_HEADER' | 'PART_NOT_FOUND' | 'CHANNEL_NOT_FOUND' | 'UNSUPPORTED_PART_TYPE' | 'UNSUPPORTED_COMPRESSION' | 'MISSING_DATA_WINDOW' | 'MALFORMED_OFFSET_TABLE' | 'MALFORMED_CHUNK' | 'DECOMPRESSION_FAILED' | 'INVALID_WRITE_INPUT' | 'UNSUPPORTED_WRITE_COMPRESSION' | 'ENCODING_FAILED';
120
122
  declare class ExrError extends Error {
121
123
  readonly code: ExrErrorCode;
122
124
  readonly details?: Record<string, string | number>;
@@ -176,10 +178,12 @@ declare function decodeExrRgba(buffer: ExrBinaryInput, options?: DecodeExrRgbaOp
176
178
  declare function writeExr(input: WriteExrInput, options?: WriteExrOptions): Uint8Array;
177
179
 
178
180
  type ExrRgbaPrecision = 'half' | 'float';
181
+ /** UINT uses the decoder's normalized [0, 1] representation of the full uint32 range. */
182
+ type ExrNamedChannelPrecision = 'uint' | ExrRgbaPrecision;
179
183
  interface ExrRgbaNamedChannel {
180
184
  name: string;
181
185
  data: Float32Array;
182
- precision?: ExrRgbaPrecision;
186
+ precision?: ExrNamedChannelPrecision;
183
187
  }
184
188
  interface EncodeExrRgbaImage {
185
189
  width: number;
@@ -198,4 +202,4 @@ interface EncodeExrRgbaOptions {
198
202
  }
199
203
  declare function encodeExrRgba(image: EncodeExrRgbaImage, options: EncodeExrRgbaOptions): Uint8Array;
200
204
 
201
- export { type DecodeExrPartOptions, type DecodeExrRgbaOptions, type DecodedChannel, type DecodedExrRgbaImage, type DecodedPart, EXR_EVENT_CODES, type EncodeExrRgbaImage, type EncodeExrRgbaOptions, type EventCapableOptions, type ExrBinaryInput, type ExrChannel, type ExrChromaticities, type ExrCompression, ExrError, type ExrErrorCode, type ExrEvent, type ExrEventCallback, type ExrEventCode, type ExrEventLevel, type ExrEventPhase, type ExrImageInfo, type ExrPart, type ExrPixelType, type ExrRgbaNamedChannel, type ExrRgbaPrecision, type ExrStructure, type ExrWindow, type InspectExrImageOptions, type ParseExrOptions, type ReadExrOptions, type ReadExrResult, type WriteExrAttribute, type WriteExrChannelInput, type WriteExrInput, type WriteExrOptions, type WriteExrPartInput, decodeExrPart, decodeExrRgba, encodeExrRgba, expandDecodedPartChannels, expandSampledChannel, inspectExrImage, isExrError, parseExr, parseExrStructure, readExr, toArrayBuffer, writeExr };
205
+ export { type DecodeExrPartOptions, type DecodeExrRgbaOptions, type DecodedChannel, type DecodedExrRgbaImage, type DecodedPart, EXR_EVENT_CODES, type EncodeExrRgbaImage, type EncodeExrRgbaOptions, type EventCapableOptions, type ExrBinaryInput, type ExrChannel, type ExrChromaticities, type ExrCompression, ExrError, type ExrErrorCode, type ExrEvent, type ExrEventCallback, type ExrEventCode, type ExrEventLevel, type ExrEventPhase, type ExrImageInfo, type ExrNamedChannelPrecision, type ExrPart, type ExrPixelType, type ExrRgbaNamedChannel, type ExrRgbaPrecision, type ExrStructure, type ExrWindow, type InspectExrImageOptions, type ParseExrOptions, type ReadExrOptions, type ReadExrResult, type WriteExrAttribute, type WriteExrChannelInput, type WriteExrInput, type WriteExrOptions, type WriteExrPartInput, decodeExrPart, decodeExrRgba, encodeExrRgba, expandDecodedPartChannels, expandSampledChannel, inspectExrImage, isExrError, parseExr, parseExrStructure, readExr, toArrayBuffer, writeExr };
package/dist/index.js CHANGED
@@ -2768,7 +2768,7 @@ function toNumberOffset(low, high) {
2768
2768
  }
2769
2769
  return Number(combined);
2770
2770
  }
2771
- function buildChannelMeta(part) {
2771
+ function buildChannelMeta(part, selectedChannelNames) {
2772
2772
  if (!part.dataWindow) return [];
2773
2773
  const { xMin, xMax, yMin, yMax } = part.dataWindow;
2774
2774
  return part.channels.map((channel) => {
@@ -2779,8 +2779,10 @@ function buildChannelMeta(part) {
2779
2779
  const sampledWidth = countSamplesInRange4(xMin, xMax, xSampling);
2780
2780
  const sampledHeight = countSamplesInRange4(yMin, yMax, ySampling);
2781
2781
  const bytesPerSample = channel.pixelType === 1 ? 2 : 4;
2782
+ const selected = selectedChannelNames?.has(channel.name) ?? true;
2782
2783
  return {
2783
2784
  channel,
2785
+ selected,
2784
2786
  pixelType: channel.pixelType,
2785
2787
  ySampling,
2786
2788
  bytesPerSample,
@@ -2789,7 +2791,7 @@ function buildChannelMeta(part) {
2789
2791
  sampledHeight,
2790
2792
  sampleOriginX,
2791
2793
  sampleOriginY,
2792
- data: new Float32Array(sampledWidth * sampledHeight)
2794
+ data: selected ? new Float32Array(sampledWidth * sampledHeight) : new Float32Array(0)
2793
2795
  };
2794
2796
  });
2795
2797
  }
@@ -2941,7 +2943,18 @@ function decodeExrPart(bufferInput, structure, options) {
2941
2943
  ms: (nowMs2() - tOffsets).toFixed(3)
2942
2944
  }
2943
2945
  });
2944
- const channelMeta = buildChannelMeta(part);
2946
+ const selectedChannelNames = options.channelNames ? new Set(options.channelNames) : void 0;
2947
+ if (selectedChannelNames) {
2948
+ for (const name of selectedChannelNames) {
2949
+ if (!part.channels.some((channel) => channel.name === name)) {
2950
+ throw new ExrError("CHANNEL_NOT_FOUND", `Channel ${name} was not found in EXR part.`, {
2951
+ partId: part.id,
2952
+ channel: name
2953
+ });
2954
+ }
2955
+ }
2956
+ }
2957
+ const channelMeta = buildChannelMeta(part, selectedChannelNames);
2945
2958
  const zipScratch = {
2946
2959
  inflate: new Uint8Array(0),
2947
2960
  output: new Uint8Array(0)
@@ -3048,8 +3061,10 @@ function decodeExrPart(bufferInput, structure, options) {
3048
3061
  blockPointer += byteLength;
3049
3062
  continue;
3050
3063
  }
3051
- const rowOffset = sampledRow * meta.sampledWidth;
3052
- decodeRowIntoChannel(meta, blockData, blockPointer, rowOffset, blockView);
3064
+ if (meta.selected) {
3065
+ const rowOffset = sampledRow * meta.sampledWidth;
3066
+ decodeRowIntoChannel(meta, blockData, blockPointer, rowOffset, blockView);
3067
+ }
3053
3068
  blockPointer += byteLength;
3054
3069
  }
3055
3070
  }
@@ -3069,6 +3084,7 @@ function decodeExrPart(bufferInput, structure, options) {
3069
3084
  }
3070
3085
  const decodedChannels = {};
3071
3086
  for (const meta of channelMeta) {
3087
+ if (!meta.selected) continue;
3072
3088
  decodedChannels[meta.channel.name] = {
3073
3089
  pixelType: meta.channel.pixelType,
3074
3090
  xSampling: meta.channel.xSampling,
@@ -4915,6 +4931,7 @@ function writeExr(input, options = {}) {
4915
4931
 
4916
4932
  // src/writer/encodeExrRgba.ts
4917
4933
  function pixelTypeForPrecision(precision) {
4934
+ if (precision === "uint") return 0;
4918
4935
  return precision === "half" ? 1 : 2;
4919
4936
  }
4920
4937
  function extractRgbaChannel(rgba, offset) {