@bb-studio/exr 0.2.0 → 0.4.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
@@ -129,7 +129,52 @@ declare function isExrError(value: unknown): value is ExrError;
129
129
  declare function parseExrStructure(bufferInput: ExrBinaryInput, options?: ParseExrOptions): ExrStructure;
130
130
  declare const parseExr: typeof parseExrStructure;
131
131
 
132
- declare function decodeExrPart(bufferInput: ExrBinaryInput, structure: ExrStructure, options: DecodeExrPartOptions): DecodedPart;
132
+ declare function decodeExrPart(buffer: ExrBinaryInput, structure: ExrStructure, options: DecodeExrPartOptions): DecodedPart;
133
+
134
+ /** A byte source. Return up to length bytes, with a short read only at EOF. */
135
+ interface ExrRandomAccessSource {
136
+ readonly size?: number;
137
+ readRange(offset: number, length: number, signal?: AbortSignal): Promise<ArrayBuffer>;
138
+ }
139
+ interface ExrChunk {
140
+ readonly index: number;
141
+ readonly partId: number;
142
+ readonly yMin: number;
143
+ readonly yMax: number;
144
+ readonly offset: number;
145
+ /** Known physical span; undefined for the last chunk when source size is unknown. */
146
+ readonly byteLength?: number;
147
+ }
148
+ interface ExrDecodeOptions extends EventCapableOptions {
149
+ partId: number;
150
+ channelNames?: readonly string[];
151
+ signal?: AbortSignal;
152
+ /** Limit coalesced reads (one large chunk may exceed this). Default 2 MiB. */
153
+ batchBytes?: number | (() => number);
154
+ /** Prioritize a region, then read the remainder; evaluated between batches. */
155
+ priority?: () => ExrWindow | undefined;
156
+ }
157
+ interface ExrDecodedRegion extends DecodedPart {
158
+ readonly window: ExrWindow;
159
+ }
160
+ interface OpenExrOptions extends EventCapableOptions {
161
+ signal?: AbortSignal;
162
+ /** Bound metadata reads for untrusted input. Default 16 MiB. */
163
+ maxMetadataBytes?: number;
164
+ }
165
+ declare function bufferExrSource(input: ExrBinaryInput): ExrRandomAccessSource;
166
+ declare function openExr(source: ExrRandomAccessSource, options?: OpenExrOptions): Promise<ExrReader>;
167
+ interface ExrReader {
168
+ readonly structure: ExrStructure;
169
+ getChunks(partId: number): readonly ExrChunk[];
170
+ decodeChunks(options: ExrDecodeOptions & {
171
+ region?: ExrWindow;
172
+ }): AsyncGenerator<ExrDecodedRegion>;
173
+ decodePart(options: ExrDecodeOptions): Promise<DecodedPart>;
174
+ decodeRegion(options: ExrDecodeOptions & {
175
+ region: ExrWindow;
176
+ }): Promise<ExrDecodedRegion>;
177
+ }
133
178
 
134
179
  interface ReadExrOptions extends ParseExrOptions {
135
180
  partId?: number;
@@ -159,21 +204,38 @@ declare function inspectExrImage(buffer: ExrBinaryInput, options?: InspectExrIma
159
204
  declare function expandSampledChannel(width: number, height: number, xMin: number, yMin: number, channel: DecodedChannel): Float32Array;
160
205
  declare function expandDecodedPartChannels(decoded: DecodedPart, dataWindow: ExrWindow): Record<string, Float32Array>;
161
206
 
207
+ type ExrRgbaStoragePrecision = 'float16' | 'float32';
208
+ /** HALF storage is lossless only when every selected physical RGBA channel
209
+ * is HALF. Unselected technical channels do not determine RGB storage. */
210
+ declare function getExrRgbaStoragePrecision(channels: readonly ExrChannel[], channelNames?: readonly string[]): ExrRgbaStoragePrecision;
211
+
162
212
  interface DecodeExrRgbaOptions extends ParseExrOptions {
163
213
  partId?: number;
164
214
  decode?: Omit<DecodeExrPartOptions, 'partId' | 'onEvent'>;
165
215
  }
166
- interface DecodedExrRgbaImage {
216
+ interface ExrRgbaImageMetadata {
167
217
  width: number;
168
218
  height: number;
169
- rgba: Float32Array;
170
219
  partId: number;
171
220
  dataWindow: ExrWindow;
172
221
  displayWindow?: ExrWindow;
173
222
  channels: readonly ExrChannel[];
174
223
  attributes: Readonly<Record<string, unknown>>;
175
224
  }
225
+ interface DecodedExrRgbaImage extends ExrRgbaImageMetadata {
226
+ rgba: Float32Array;
227
+ }
228
+ type DecodedExrNativeRgbaImage = ExrRgbaImageMetadata & ({
229
+ storagePrecision: 'float16';
230
+ rgba: Uint16Array;
231
+ } | {
232
+ storagePrecision: 'float32';
233
+ rgba: Float32Array;
234
+ });
176
235
  declare function decodeExrRgba(buffer: ExrBinaryInput, options?: DecodeExrRgbaOptions): DecodedExrRgbaImage;
236
+ /** Decode directly into lossless native RGBA storage. HALF output contains
237
+ * binary16 bits, not integer-valued samples; FLOAT/UINT selections use Float32. */
238
+ declare function decodeExrNativeRgba(buffer: ExrBinaryInput, options?: DecodeExrRgbaOptions): DecodedExrNativeRgbaImage;
177
239
 
178
240
  declare function writeExr(input: WriteExrInput, options?: WriteExrOptions): Uint8Array;
179
241
 
@@ -202,4 +264,4 @@ interface EncodeExrRgbaOptions {
202
264
  }
203
265
  declare function encodeExrRgba(image: EncodeExrRgbaImage, options: EncodeExrRgbaOptions): Uint8Array;
204
266
 
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 };
267
+ export { type DecodeExrPartOptions, type DecodeExrRgbaOptions, type DecodedChannel, type DecodedExrNativeRgbaImage, type DecodedExrRgbaImage, type DecodedPart, EXR_EVENT_CODES, type EncodeExrRgbaImage, type EncodeExrRgbaOptions, type EventCapableOptions, type ExrBinaryInput, type ExrChannel, type ExrChromaticities, type ExrChunk, type ExrCompression, type ExrDecodeOptions, type ExrDecodedRegion, ExrError, type ExrErrorCode, type ExrEvent, type ExrEventCallback, type ExrEventCode, type ExrEventLevel, type ExrEventPhase, type ExrImageInfo, type ExrNamedChannelPrecision, type ExrPart, type ExrPixelType, type ExrRandomAccessSource, type ExrReader, type ExrRgbaNamedChannel, type ExrRgbaPrecision, type ExrRgbaStoragePrecision, type ExrStructure, type ExrWindow, type InspectExrImageOptions, type OpenExrOptions, type ParseExrOptions, type ReadExrOptions, type ReadExrResult, type WriteExrAttribute, type WriteExrChannelInput, type WriteExrInput, type WriteExrOptions, type WriteExrPartInput, bufferExrSource, decodeExrNativeRgba, decodeExrPart, decodeExrRgba, encodeExrRgba, expandDecodedPartChannels, expandSampledChannel, getExrRgbaStoragePrecision, inspectExrImage, isExrError, openExr, parseExr, parseExrStructure, readExr, toArrayBuffer, writeExr };
package/dist/index.d.ts CHANGED
@@ -129,7 +129,52 @@ declare function isExrError(value: unknown): value is ExrError;
129
129
  declare function parseExrStructure(bufferInput: ExrBinaryInput, options?: ParseExrOptions): ExrStructure;
130
130
  declare const parseExr: typeof parseExrStructure;
131
131
 
132
- declare function decodeExrPart(bufferInput: ExrBinaryInput, structure: ExrStructure, options: DecodeExrPartOptions): DecodedPart;
132
+ declare function decodeExrPart(buffer: ExrBinaryInput, structure: ExrStructure, options: DecodeExrPartOptions): DecodedPart;
133
+
134
+ /** A byte source. Return up to length bytes, with a short read only at EOF. */
135
+ interface ExrRandomAccessSource {
136
+ readonly size?: number;
137
+ readRange(offset: number, length: number, signal?: AbortSignal): Promise<ArrayBuffer>;
138
+ }
139
+ interface ExrChunk {
140
+ readonly index: number;
141
+ readonly partId: number;
142
+ readonly yMin: number;
143
+ readonly yMax: number;
144
+ readonly offset: number;
145
+ /** Known physical span; undefined for the last chunk when source size is unknown. */
146
+ readonly byteLength?: number;
147
+ }
148
+ interface ExrDecodeOptions extends EventCapableOptions {
149
+ partId: number;
150
+ channelNames?: readonly string[];
151
+ signal?: AbortSignal;
152
+ /** Limit coalesced reads (one large chunk may exceed this). Default 2 MiB. */
153
+ batchBytes?: number | (() => number);
154
+ /** Prioritize a region, then read the remainder; evaluated between batches. */
155
+ priority?: () => ExrWindow | undefined;
156
+ }
157
+ interface ExrDecodedRegion extends DecodedPart {
158
+ readonly window: ExrWindow;
159
+ }
160
+ interface OpenExrOptions extends EventCapableOptions {
161
+ signal?: AbortSignal;
162
+ /** Bound metadata reads for untrusted input. Default 16 MiB. */
163
+ maxMetadataBytes?: number;
164
+ }
165
+ declare function bufferExrSource(input: ExrBinaryInput): ExrRandomAccessSource;
166
+ declare function openExr(source: ExrRandomAccessSource, options?: OpenExrOptions): Promise<ExrReader>;
167
+ interface ExrReader {
168
+ readonly structure: ExrStructure;
169
+ getChunks(partId: number): readonly ExrChunk[];
170
+ decodeChunks(options: ExrDecodeOptions & {
171
+ region?: ExrWindow;
172
+ }): AsyncGenerator<ExrDecodedRegion>;
173
+ decodePart(options: ExrDecodeOptions): Promise<DecodedPart>;
174
+ decodeRegion(options: ExrDecodeOptions & {
175
+ region: ExrWindow;
176
+ }): Promise<ExrDecodedRegion>;
177
+ }
133
178
 
134
179
  interface ReadExrOptions extends ParseExrOptions {
135
180
  partId?: number;
@@ -159,21 +204,38 @@ declare function inspectExrImage(buffer: ExrBinaryInput, options?: InspectExrIma
159
204
  declare function expandSampledChannel(width: number, height: number, xMin: number, yMin: number, channel: DecodedChannel): Float32Array;
160
205
  declare function expandDecodedPartChannels(decoded: DecodedPart, dataWindow: ExrWindow): Record<string, Float32Array>;
161
206
 
207
+ type ExrRgbaStoragePrecision = 'float16' | 'float32';
208
+ /** HALF storage is lossless only when every selected physical RGBA channel
209
+ * is HALF. Unselected technical channels do not determine RGB storage. */
210
+ declare function getExrRgbaStoragePrecision(channels: readonly ExrChannel[], channelNames?: readonly string[]): ExrRgbaStoragePrecision;
211
+
162
212
  interface DecodeExrRgbaOptions extends ParseExrOptions {
163
213
  partId?: number;
164
214
  decode?: Omit<DecodeExrPartOptions, 'partId' | 'onEvent'>;
165
215
  }
166
- interface DecodedExrRgbaImage {
216
+ interface ExrRgbaImageMetadata {
167
217
  width: number;
168
218
  height: number;
169
- rgba: Float32Array;
170
219
  partId: number;
171
220
  dataWindow: ExrWindow;
172
221
  displayWindow?: ExrWindow;
173
222
  channels: readonly ExrChannel[];
174
223
  attributes: Readonly<Record<string, unknown>>;
175
224
  }
225
+ interface DecodedExrRgbaImage extends ExrRgbaImageMetadata {
226
+ rgba: Float32Array;
227
+ }
228
+ type DecodedExrNativeRgbaImage = ExrRgbaImageMetadata & ({
229
+ storagePrecision: 'float16';
230
+ rgba: Uint16Array;
231
+ } | {
232
+ storagePrecision: 'float32';
233
+ rgba: Float32Array;
234
+ });
176
235
  declare function decodeExrRgba(buffer: ExrBinaryInput, options?: DecodeExrRgbaOptions): DecodedExrRgbaImage;
236
+ /** Decode directly into lossless native RGBA storage. HALF output contains
237
+ * binary16 bits, not integer-valued samples; FLOAT/UINT selections use Float32. */
238
+ declare function decodeExrNativeRgba(buffer: ExrBinaryInput, options?: DecodeExrRgbaOptions): DecodedExrNativeRgbaImage;
177
239
 
178
240
  declare function writeExr(input: WriteExrInput, options?: WriteExrOptions): Uint8Array;
179
241
 
@@ -202,4 +264,4 @@ interface EncodeExrRgbaOptions {
202
264
  }
203
265
  declare function encodeExrRgba(image: EncodeExrRgbaImage, options: EncodeExrRgbaOptions): Uint8Array;
204
266
 
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 };
267
+ export { type DecodeExrPartOptions, type DecodeExrRgbaOptions, type DecodedChannel, type DecodedExrNativeRgbaImage, type DecodedExrRgbaImage, type DecodedPart, EXR_EVENT_CODES, type EncodeExrRgbaImage, type EncodeExrRgbaOptions, type EventCapableOptions, type ExrBinaryInput, type ExrChannel, type ExrChromaticities, type ExrChunk, type ExrCompression, type ExrDecodeOptions, type ExrDecodedRegion, ExrError, type ExrErrorCode, type ExrEvent, type ExrEventCallback, type ExrEventCode, type ExrEventLevel, type ExrEventPhase, type ExrImageInfo, type ExrNamedChannelPrecision, type ExrPart, type ExrPixelType, type ExrRandomAccessSource, type ExrReader, type ExrRgbaNamedChannel, type ExrRgbaPrecision, type ExrRgbaStoragePrecision, type ExrStructure, type ExrWindow, type InspectExrImageOptions, type OpenExrOptions, type ParseExrOptions, type ReadExrOptions, type ReadExrResult, type WriteExrAttribute, type WriteExrChannelInput, type WriteExrInput, type WriteExrOptions, type WriteExrPartInput, bufferExrSource, decodeExrNativeRgba, decodeExrPart, decodeExrRgba, encodeExrRgba, expandDecodedPartChannels, expandSampledChannel, getExrRgbaStoragePrecision, inspectExrImage, isExrError, openExr, parseExr, parseExrStructure, readExr, toArrayBuffer, writeExr };