@monogrid/gainmap-js 3.0.6 → 3.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.
Files changed (57) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/CODE_OF_CONDUCT.md +1 -1
  3. package/CONTRIBUTING.md +1 -1
  4. package/README.md +106 -2
  5. package/dist/Loader-BZcKUVaX.js +424 -0
  6. package/dist/{QuadRenderer-B3h-sJtp.js → QuadRenderer-Y5tm-R3m.js} +39 -30
  7. package/dist/{_commonjsHelpers-UqyNh5ZN.js → _commonjsHelpers-CuGYGi_5.js} +2 -2
  8. package/dist/{compress-CAiPfiRr.js → compress-BaKKOAXI.js} +2 -3
  9. package/dist/core/QuadRenderer.d.ts +2 -2
  10. package/dist/core/get-data-texture.d.ts +4 -3
  11. package/dist/core/types.d.ts +2 -1
  12. package/dist/decode/index.d.ts +1 -11
  13. package/dist/decode/shared/Loader.d.ts +59 -0
  14. package/dist/decode/shared/decode.d.ts +24 -0
  15. package/dist/decode/{extract.d.ts → shared/extract.d.ts} +4 -4
  16. package/dist/decode/shared/index.d.ts +8 -0
  17. package/dist/decode/shared/types.d.ts +53 -0
  18. package/dist/decode/{utils → shared/utils}/MPFExtractor.d.ts +1 -1
  19. package/dist/decode/shared/utils/extractXMP.d.ts +2 -0
  20. package/dist/decode/{decode.d.ts → webgl/decode.d.ts} +6 -6
  21. package/dist/decode/webgl/index.d.ts +8 -0
  22. package/dist/decode/{loaders → webgl/loaders}/GainMapLoader.d.ts +5 -6
  23. package/dist/decode/{loaders → webgl/loaders}/HDRJPGLoader.d.ts +6 -7
  24. package/dist/decode/webgl/loaders/LoaderBaseWebGL.d.ts +20 -0
  25. package/dist/decode/{materials → webgl/materials}/GainMapDecoderMaterial.d.ts +2 -2
  26. package/dist/decode/webgpu/core/QuadRenderer.d.ts +153 -0
  27. package/dist/decode/webgpu/decode.d.ts +60 -0
  28. package/dist/decode/webgpu/index.d.ts +8 -0
  29. package/dist/decode/webgpu/loaders/GainMapLoader.d.ts +69 -0
  30. package/dist/decode/webgpu/loaders/HDRJPGLoader.d.ts +65 -0
  31. package/dist/decode/webgpu/loaders/LoaderBaseWebGPU.d.ts +20 -0
  32. package/dist/decode/webgpu/materials/GainMapDecoderMaterial.d.ts +78 -0
  33. package/dist/decode.js +45 -442
  34. package/dist/decode.umd.cjs +388 -358
  35. package/dist/decode.webgpu.js +814 -0
  36. package/dist/decode.webgpu.umd.cjs +1244 -0
  37. package/dist/encode/encode-and-compress.d.ts +3 -3
  38. package/dist/encode/encode.d.ts +3 -3
  39. package/dist/encode/find-texture-min-max.d.ts +4 -3
  40. package/dist/encode/types.d.ts +4 -3
  41. package/dist/encode.js +32 -11
  42. package/dist/encode.umd.cjs +67 -38
  43. package/dist/libultrahdr/decode-jpeg-metadata.d.ts +0 -3
  44. package/dist/libultrahdr/encode-jpeg-metadata.d.ts +2 -2
  45. package/dist/libultrahdr.js +42 -75
  46. package/dist/libultrahdr.umd.cjs +46 -79
  47. package/dist/worker-interface.js +74 -64
  48. package/dist/worker-interface.umd.cjs +73 -63
  49. package/dist/worker.js +103 -88
  50. package/dist/worker.umd.cjs +103 -89
  51. package/package.json +79 -72
  52. package/dist/decode/loaders/LoaderBase.d.ts +0 -45
  53. package/dist/decode/types.d.ts +0 -42
  54. package/dist/decode/utils/extractXMP.d.ts +0 -7
  55. /package/dist/decode/{errors → shared/errors}/GainMapNotFoundError.d.ts +0 -0
  56. /package/dist/decode/{errors → shared/errors}/XMPMetadataNotFoundError.d.ts +0 -0
  57. /package/dist/decode/{utils → shared/utils}/get-html-image-from-blob.d.ts +0 -0
@@ -21,7 +21,7 @@ import { CompressedImage, EncodingParametersWithCompression } from './types';
21
21
  * const image = await loader.loadAsync('image.exr')
22
22
  *
23
23
  * // find RAW RGB Max value of a texture
24
- * const textureMax = await findTextureMinMax(image)
24
+ * const textureMax = findTextureMinMax(image)
25
25
  *
26
26
  * // Encode the gainmap
27
27
  * const encodingResult = await encodeAndCompress({
@@ -47,8 +47,8 @@ import { CompressedImage, EncodingParametersWithCompression } from './types';
47
47
  export declare const encodeAndCompress: (params: EncodingParametersWithCompression) => Promise<{
48
48
  sdr: CompressedImage;
49
49
  gainMap: CompressedImage;
50
- rawSDR: Uint8ClampedArray;
51
- rawGainMap: Uint8ClampedArray;
50
+ rawSDR: Uint8ClampedArray<ArrayBufferLike>;
51
+ rawGainMap: Uint8ClampedArray<ArrayBufferLike>;
52
52
  gamma: [number, number, number];
53
53
  hdrCapacityMin: number;
54
54
  hdrCapacityMax: number;
@@ -28,7 +28,7 @@ import { EncodingParametersBase } from './types';
28
28
  * const image = await loader.loadAsync('image.exr')
29
29
  *
30
30
  * // find RAW RGB Max value of a texture
31
- * const textureMax = await findTextureMinMax(image)
31
+ * const textureMax = findTextureMinMax(image)
32
32
  *
33
33
  * // Encode the gainmap
34
34
  * const encodingResult = encode({
@@ -54,8 +54,8 @@ import { EncodingParametersBase } from './types';
54
54
  * @returns
55
55
  */
56
56
  export declare const encode: (params: EncodingParametersBase) => {
57
- sdr: import("../decode").QuadRenderer<1009, import(".").SDRMaterial>;
58
- gainMap: import("../decode").QuadRenderer<1009, import(".").GainMapEncoderMaterial>;
57
+ sdr: import("../core").QuadRenderer<1009, import(".").SDRMaterial>;
58
+ gainMap: import("../core").QuadRenderer<1009, import(".").GainMapEncoderMaterial>;
59
59
  hdr: import("three").DataTexture;
60
60
  getMetadata: () => GainMapMetadata;
61
61
  };
@@ -1,6 +1,7 @@
1
1
  import { DataTexture, WebGLRenderer } from 'three';
2
- import { EXR } from 'three/examples/jsm/loaders/EXRLoader';
3
- import { RGBE } from 'three/examples/jsm/loaders/RGBELoader';
2
+ import { EXR } from 'three/examples/jsm/loaders/EXRLoader.js';
3
+ import { HDR } from 'three/examples/jsm/loaders/HDRLoader.js';
4
+ import { RGBE } from 'three/examples/jsm/loaders/RGBELoader.js';
4
5
  /**
5
6
  *
6
7
  * @category Utility
@@ -11,4 +12,4 @@ import { RGBE } from 'three/examples/jsm/loaders/RGBELoader';
11
12
  * @param renderer
12
13
  * @returns
13
14
  */
14
- export declare const findTextureMinMax: (image: EXR | RGBE | DataTexture, mode?: "min" | "max", renderer?: WebGLRenderer) => number[];
15
+ export declare const findTextureMinMax: (image: EXR | RGBE | HDR | DataTexture, mode?: "min" | "max", renderer?: WebGLRenderer) => number[];
@@ -1,6 +1,7 @@
1
1
  import { type DataTexture, ToneMapping, WebGLRenderer } from 'three';
2
- import { type EXR } from 'three/examples/jsm/loaders/EXRLoader';
3
- import { type RGBE } from 'three/examples/jsm/loaders/RGBELoader';
2
+ import { type EXR } from 'three/examples/jsm/loaders/EXRLoader.js';
3
+ import { type HDR } from 'three/examples/jsm/loaders/HDRLoader.js';
4
+ import { type RGBE } from 'three/examples/jsm/loaders/RGBELoader.js';
4
5
  import { QuadRendererTextureOptions } from '../decode';
5
6
  import { WorkerInterfaceImplementation } from '../worker-types';
6
7
  /**
@@ -70,7 +71,7 @@ export type EncodingParametersBase = GainmapEncodingParameters & {
70
71
  /**
71
72
  * Input image for encoding, must be an HDR image
72
73
  */
73
- image: EXR | RGBE | DataTexture;
74
+ image: EXR | RGBE | HDR | DataTexture;
74
75
  /**
75
76
  * Optional WebGLRenderer
76
77
  * @remarks
package/dist/encode.js CHANGED
@@ -1,11 +1,11 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.0.6
3
- * With ❤️, by MONOGRID <rnd@monogrid.com>
2
+ * @monogrid/gainmap-js v3.2.0
3
+ * With ❤️, by MONOGRID <gainmap@monogrid.com>
4
4
  */
5
5
 
6
- import { c as compress } from './compress-CAiPfiRr.js';
7
- import { DataTexture, RGBAFormat, UVMapping, RepeatWrapping, LinearFilter, LinearSRGBColorSpace, ShaderMaterial, Vector3, NoBlending, UnsignedByteType, ACESFilmicToneMapping, LinearToneMapping, CineonToneMapping, ReinhardToneMapping, SRGBColorSpace, Vector2, WebGLRenderTarget, NearestFilter, ClampToEdgeWrapping, FloatType, DataUtils } from 'three';
8
- import { Q as QuadRenderer } from './QuadRenderer-B3h-sJtp.js';
6
+ import { c as compress } from './compress-BaKKOAXI.js';
7
+ import { DataTexture, RGBAFormat, UVMapping, RepeatWrapping, LinearFilter, LinearSRGBColorSpace, ShaderMaterial, NoBlending, Vector3, UnsignedByteType, ACESFilmicToneMapping, LinearToneMapping, CineonToneMapping, ReinhardToneMapping, SRGBColorSpace, AlphaFormat, RGBFormat, DepthFormat, DepthStencilFormat, RedFormat, RedIntegerFormat, RGFormat, RGIntegerFormat, RGBIntegerFormat, RGBAIntegerFormat, Vector2, WebGLRenderTarget, ClampToEdgeWrapping, NearestFilter, DataUtils, FloatType } from 'three';
8
+ import { Q as QuadRenderer } from './QuadRenderer-Y5tm-R3m.js';
9
9
 
10
10
  /**
11
11
  * Utility function to obtain a `DataTexture` from various input formats
@@ -75,6 +75,11 @@ void main() {
75
75
  * @group Materials
76
76
  */
77
77
  class GainMapEncoderMaterial extends ShaderMaterial {
78
+ _minContentBoost;
79
+ _maxContentBoost;
80
+ _offsetSdr;
81
+ _offsetHdr;
82
+ _gamma;
78
83
  /**
79
84
  *
80
85
  * @param params
@@ -339,6 +344,12 @@ void main() {
339
344
  * @group Materials
340
345
  */
341
346
  class SDRMaterial extends ShaderMaterial {
347
+ _brightness = 0;
348
+ _contrast = 1;
349
+ _saturation = 1;
350
+ _exposure = 1;
351
+ _toneMapping;
352
+ _map;
342
353
  /**
343
354
  *
344
355
  * @param params
@@ -359,10 +370,6 @@ class SDRMaterial extends ShaderMaterial {
359
370
  depthTest: false,
360
371
  depthWrite: false
361
372
  });
362
- this._brightness = 0;
363
- this._contrast = 1;
364
- this._saturation = 1;
365
- this._exposure = 1;
366
373
  this._map = map;
367
374
  this.toneMapping = this._toneMapping = toneMapping || ACESFilmicToneMapping;
368
375
  this.needsUpdate = true;
@@ -486,7 +493,7 @@ const getSDRRendition = (hdrTexture, renderer, toneMapping, renderTargetOptions)
486
493
  * const image = await loader.loadAsync('image.exr')
487
494
  *
488
495
  * // find RAW RGB Max value of a texture
489
- * const textureMax = await findTextureMinMax(image)
496
+ * const textureMax = findTextureMinMax(image)
490
497
  *
491
498
  * // Encode the gainmap
492
499
  * const encodingResult = encode({
@@ -561,7 +568,7 @@ const encode = (params) => {
561
568
  * const image = await loader.loadAsync('image.exr')
562
569
  *
563
570
  * // find RAW RGB Max value of a texture
564
- * const textureMax = await findTextureMinMax(image)
571
+ * const textureMax = findTextureMinMax(image)
565
572
  *
566
573
  * // Encode the gainmap
567
574
  * const encodingResult = await encodeAndCompress({
@@ -701,6 +708,20 @@ void main() {
701
708
  */
702
709
  const findTextureMinMax = (image, mode = 'max', renderer) => {
703
710
  const srcTex = getDataTexture(image);
711
+ // check if texture has a valid format
712
+ if (srcTex.format !== AlphaFormat &&
713
+ srcTex.format !== RGBFormat &&
714
+ srcTex.format !== RGBAFormat &&
715
+ srcTex.format !== DepthFormat &&
716
+ srcTex.format !== DepthStencilFormat &&
717
+ srcTex.format !== RedFormat &&
718
+ srcTex.format !== RedIntegerFormat &&
719
+ srcTex.format !== RGFormat &&
720
+ srcTex.format !== RGIntegerFormat &&
721
+ srcTex.format !== RGBIntegerFormat &&
722
+ srcTex.format !== RGBAIntegerFormat) {
723
+ throw new Error('Unsupported texture format');
724
+ }
704
725
  const cellSize = 2;
705
726
  const mat = new ShaderMaterial({
706
727
  vertexShader,
@@ -1,6 +1,6 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.0.6
3
- * With ❤️, by MONOGRID <rnd@monogrid.com>
2
+ * @monogrid/gainmap-js v3.2.0
3
+ * With ❤️, by MONOGRID <gainmap@monogrid.com>
4
4
  */
5
5
 
6
6
  (function (global, factory) {
@@ -20,7 +20,7 @@
20
20
  */
21
21
  const canvasToBlob = async (canvas, mimeType, quality) => {
22
22
  if (typeof OffscreenCanvas !== 'undefined' && canvas instanceof OffscreenCanvas) {
23
- return canvas.convertToBlob({ type: mimeType, quality: quality || 0.9 });
23
+ return canvas.convertToBlob({ type: mimeType, quality: quality });
24
24
  }
25
25
  else if (canvas instanceof HTMLCanvasElement) {
26
26
  return new Promise((resolve, reject) => {
@@ -29,7 +29,7 @@
29
29
  resolve(res);
30
30
  else
31
31
  reject(new Error('Failed to convert canvas to blob'));
32
- }, mimeType, quality || 0.9);
32
+ }, mimeType, quality);
33
33
  });
34
34
  }
35
35
  /* istanbul ignore next
@@ -52,7 +52,6 @@
52
52
  if (typeof createImageBitmap === 'undefined')
53
53
  throw new Error('createImageBitmap() not supported.');
54
54
  const { source, mimeType, quality, flipY } = params;
55
- // eslint-disable-next-line no-undef
56
55
  let imageBitmapSource;
57
56
  if ((source instanceof Uint8Array || source instanceof Uint8ClampedArray) && 'sourceMimeType' in params) {
58
57
  imageBitmapSource = new Blob([source], { type: params.sourceMimeType });
@@ -188,29 +187,24 @@
188
187
  * @group Core
189
188
  */
190
189
  class QuadRenderer {
190
+ _renderer;
191
+ _rendererIsDisposable = false;
192
+ _material;
193
+ _scene;
194
+ _camera;
195
+ _quad;
196
+ _renderTarget;
197
+ _width;
198
+ _height;
199
+ _type;
200
+ _colorSpace;
201
+ _supportsReadPixels = true;
191
202
  /**
192
203
  * Constructs a new QuadRenderer
193
204
  *
194
205
  * @param options Parameters for this QuadRenderer
195
206
  */
196
207
  constructor(options) {
197
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
198
- this._rendererIsDisposable = false;
199
- this._supportsReadPixels = true;
200
- /**
201
- * Renders the input texture using the specified material
202
- */
203
- this.render = () => {
204
- this._renderer.setRenderTarget(this._renderTarget);
205
- try {
206
- this._renderer.render(this._scene, this._camera);
207
- }
208
- catch (e) {
209
- this._renderer.setRenderTarget(null);
210
- throw e;
211
- }
212
- this._renderer.setRenderTarget(null);
213
- };
214
208
  this._width = options.width;
215
209
  this._height = options.height;
216
210
  this._type = options.type;
@@ -223,13 +217,13 @@
223
217
  // user options
224
218
  type: this._type, // set in class property
225
219
  colorSpace: this._colorSpace, // set in class property
226
- anisotropy: ((_a = options.renderTargetOptions) === null || _a === void 0 ? void 0 : _a.anisotropy) !== undefined ? (_b = options.renderTargetOptions) === null || _b === void 0 ? void 0 : _b.anisotropy : 1,
227
- generateMipmaps: ((_c = options.renderTargetOptions) === null || _c === void 0 ? void 0 : _c.generateMipmaps) !== undefined ? (_d = options.renderTargetOptions) === null || _d === void 0 ? void 0 : _d.generateMipmaps : false,
228
- magFilter: ((_e = options.renderTargetOptions) === null || _e === void 0 ? void 0 : _e.magFilter) !== undefined ? (_f = options.renderTargetOptions) === null || _f === void 0 ? void 0 : _f.magFilter : three.LinearFilter,
229
- minFilter: ((_g = options.renderTargetOptions) === null || _g === void 0 ? void 0 : _g.minFilter) !== undefined ? (_h = options.renderTargetOptions) === null || _h === void 0 ? void 0 : _h.minFilter : three.LinearFilter,
230
- samples: ((_j = options.renderTargetOptions) === null || _j === void 0 ? void 0 : _j.samples) !== undefined ? (_k = options.renderTargetOptions) === null || _k === void 0 ? void 0 : _k.samples : undefined,
231
- wrapS: ((_l = options.renderTargetOptions) === null || _l === void 0 ? void 0 : _l.wrapS) !== undefined ? (_m = options.renderTargetOptions) === null || _m === void 0 ? void 0 : _m.wrapS : three.ClampToEdgeWrapping,
232
- wrapT: ((_o = options.renderTargetOptions) === null || _o === void 0 ? void 0 : _o.wrapT) !== undefined ? (_p = options.renderTargetOptions) === null || _p === void 0 ? void 0 : _p.wrapT : three.ClampToEdgeWrapping
220
+ anisotropy: options.renderTargetOptions?.anisotropy !== undefined ? options.renderTargetOptions?.anisotropy : 1,
221
+ generateMipmaps: options.renderTargetOptions?.generateMipmaps !== undefined ? options.renderTargetOptions?.generateMipmaps : false,
222
+ magFilter: options.renderTargetOptions?.magFilter !== undefined ? options.renderTargetOptions?.magFilter : three.LinearFilter,
223
+ minFilter: options.renderTargetOptions?.minFilter !== undefined ? options.renderTargetOptions?.minFilter : three.LinearFilter,
224
+ samples: options.renderTargetOptions?.samples !== undefined ? options.renderTargetOptions?.samples : undefined,
225
+ wrapS: options.renderTargetOptions?.wrapS !== undefined ? options.renderTargetOptions?.wrapS : three.ClampToEdgeWrapping,
226
+ wrapT: options.renderTargetOptions?.wrapT !== undefined ? options.renderTargetOptions?.wrapT : three.ClampToEdgeWrapping
233
227
  };
234
228
  this._material = options.material;
235
229
  if (options.renderer) {
@@ -267,7 +261,7 @@
267
261
  this._quad.geometry.computeBoundingBox();
268
262
  this._scene.add(this._quad);
269
263
  this._renderTarget = new three.WebGLRenderTarget(this.width, this.height, rtOptions);
270
- this._renderTarget.texture.mapping = ((_q = options.renderTargetOptions) === null || _q === void 0 ? void 0 : _q.mapping) !== undefined ? (_r = options.renderTargetOptions) === null || _r === void 0 ? void 0 : _r.mapping : three.UVMapping;
264
+ this._renderTarget.texture.mapping = options.renderTargetOptions?.mapping !== undefined ? options.renderTargetOptions?.mapping : three.UVMapping;
271
265
  }
272
266
  /**
273
267
  * Instantiates a temporary renderer
@@ -283,6 +277,20 @@
283
277
  // this._rendererIsDisposable = true
284
278
  return renderer;
285
279
  }
280
+ /**
281
+ * Renders the input texture using the specified material
282
+ */
283
+ render = () => {
284
+ this._renderer.setRenderTarget(this._renderTarget);
285
+ try {
286
+ this._renderer.render(this._scene, this._camera);
287
+ }
288
+ catch (e) {
289
+ this._renderer.setRenderTarget(null);
290
+ throw e;
291
+ }
292
+ this._renderer.setRenderTarget(null);
293
+ };
286
294
  /**
287
295
  * Obtains a Buffer containing the rendered texture.
288
296
  *
@@ -308,11 +316,11 @@
308
316
  // fixed values
309
317
  this.toArray(), this.width, this.height, three.RGBAFormat, this._type,
310
318
  // user values
311
- (options === null || options === void 0 ? void 0 : options.mapping) || three.UVMapping, (options === null || options === void 0 ? void 0 : options.wrapS) || three.ClampToEdgeWrapping, (options === null || options === void 0 ? void 0 : options.wrapT) || three.ClampToEdgeWrapping, (options === null || options === void 0 ? void 0 : options.magFilter) || three.LinearFilter, (options === null || options === void 0 ? void 0 : options.minFilter) || three.LinearFilter, (options === null || options === void 0 ? void 0 : options.anisotropy) || 1,
319
+ options?.mapping || three.UVMapping, options?.wrapS || three.ClampToEdgeWrapping, options?.wrapT || three.ClampToEdgeWrapping, options?.magFilter || three.LinearFilter, options?.minFilter || three.LinearFilter, options?.anisotropy || 1,
312
320
  // fixed value
313
321
  three.LinearSRGBColorSpace);
314
322
  // set this afterwards, we can't set it in constructor
315
- returnValue.generateMipmaps = (options === null || options === void 0 ? void 0 : options.generateMipmaps) !== undefined ? options === null || options === void 0 ? void 0 : options.generateMipmaps : false;
323
+ returnValue.generateMipmaps = options?.generateMipmaps !== undefined ? options?.generateMipmaps : false;
316
324
  return returnValue;
317
325
  }
318
326
  /**
@@ -455,6 +463,11 @@ void main() {
455
463
  * @group Materials
456
464
  */
457
465
  class GainMapEncoderMaterial extends three.ShaderMaterial {
466
+ _minContentBoost;
467
+ _maxContentBoost;
468
+ _offsetSdr;
469
+ _offsetHdr;
470
+ _gamma;
458
471
  /**
459
472
  *
460
473
  * @param params
@@ -719,6 +732,12 @@ void main() {
719
732
  * @group Materials
720
733
  */
721
734
  class SDRMaterial extends three.ShaderMaterial {
735
+ _brightness = 0;
736
+ _contrast = 1;
737
+ _saturation = 1;
738
+ _exposure = 1;
739
+ _toneMapping;
740
+ _map;
722
741
  /**
723
742
  *
724
743
  * @param params
@@ -739,10 +758,6 @@ void main() {
739
758
  depthTest: false,
740
759
  depthWrite: false
741
760
  });
742
- this._brightness = 0;
743
- this._contrast = 1;
744
- this._saturation = 1;
745
- this._exposure = 1;
746
761
  this._map = map;
747
762
  this.toneMapping = this._toneMapping = toneMapping || three.ACESFilmicToneMapping;
748
763
  this.needsUpdate = true;
@@ -866,7 +881,7 @@ void main() {
866
881
  * const image = await loader.loadAsync('image.exr')
867
882
  *
868
883
  * // find RAW RGB Max value of a texture
869
- * const textureMax = await findTextureMinMax(image)
884
+ * const textureMax = findTextureMinMax(image)
870
885
  *
871
886
  * // Encode the gainmap
872
887
  * const encodingResult = encode({
@@ -941,7 +956,7 @@ void main() {
941
956
  * const image = await loader.loadAsync('image.exr')
942
957
  *
943
958
  * // find RAW RGB Max value of a texture
944
- * const textureMax = await findTextureMinMax(image)
959
+ * const textureMax = findTextureMinMax(image)
945
960
  *
946
961
  * // Encode the gainmap
947
962
  * const encodingResult = await encodeAndCompress({
@@ -1081,6 +1096,20 @@ void main() {
1081
1096
  */
1082
1097
  const findTextureMinMax = (image, mode = 'max', renderer) => {
1083
1098
  const srcTex = getDataTexture(image);
1099
+ // check if texture has a valid format
1100
+ if (srcTex.format !== three.AlphaFormat &&
1101
+ srcTex.format !== three.RGBFormat &&
1102
+ srcTex.format !== three.RGBAFormat &&
1103
+ srcTex.format !== three.DepthFormat &&
1104
+ srcTex.format !== three.DepthStencilFormat &&
1105
+ srcTex.format !== three.RedFormat &&
1106
+ srcTex.format !== three.RedIntegerFormat &&
1107
+ srcTex.format !== three.RGFormat &&
1108
+ srcTex.format !== three.RGIntegerFormat &&
1109
+ srcTex.format !== three.RGBIntegerFormat &&
1110
+ srcTex.format !== three.RGBAIntegerFormat) {
1111
+ throw new Error('Unsupported texture format');
1112
+ }
1084
1113
  const cellSize = 2;
1085
1114
  const mat = new three.ShaderMaterial({
1086
1115
  vertexShader,
@@ -19,9 +19,6 @@ import { GainMapMetadata } from '../core/types';
19
19
  * @throws {Error} if the provided file cannot be parsed or does not contain a valid Gainmap
20
20
  */
21
21
  export declare const decodeJPEGMetadata: (file: Uint8Array) => Promise<{
22
- /**
23
- * Parsed metadata
24
- */
25
22
  parsedMetadata: GainMapMetadata;
26
23
  metadata: ArrayBuffer | Uint8Array | Uint8ClampedArray | Int8Array | string;
27
24
  success: boolean;
@@ -17,7 +17,7 @@ import { type CompressedImage } from '../encode/types';
17
17
  * const image = await loader.loadAsync('image.exr')
18
18
  *
19
19
  * // find RAW RGB Max value of a texture
20
- * const textureMax = await findTextureMinMax(image)
20
+ * const textureMax = findTextureMinMax(image)
21
21
  *
22
22
  * // Encode the gainmap
23
23
  * const encodingResult = encode({
@@ -81,4 +81,4 @@ import { type CompressedImage } from '../encode/types';
81
81
  export declare const encodeJPEGMetadata: (encodingResult: GainMapMetadata & {
82
82
  sdr: CompressedImage;
83
83
  gainMap: CompressedImage;
84
- }) => Promise<Uint8Array>;
84
+ }) => Promise<Uint8Array<ArrayBufferLike>>;
@@ -1,6 +1,6 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.0.6
3
- * With ❤️, by MONOGRID <rnd@monogrid.com>
2
+ * @monogrid/gainmap-js v3.2.0
3
+ * With ❤️, by MONOGRID <gainmap@monogrid.com>
4
4
  */
5
5
 
6
6
  var Module = (() => {
@@ -986,7 +986,7 @@ function unexportedRuntimeSymbol(sym) {
986
986
  }
987
987
  };
988
988
 
989
- var noExitRuntime = Module['noExitRuntime'] || true;
989
+ Module['noExitRuntime'] || true;
990
990
 
991
991
  var ptrToString = (ptr) => {
992
992
  assert(typeof ptr === 'number');
@@ -1502,7 +1502,7 @@ function unexportedRuntimeSymbol(sym) {
1502
1502
 
1503
1503
  assert(!isAsync, 'Async bindings are only supported with JSPI.');
1504
1504
 
1505
- var isClassMethodFunc = (argTypes[1] !== null && classType !== null);
1505
+ (argTypes[1] !== null && classType !== null);
1506
1506
 
1507
1507
  // Free functions with signature "void function()" do not need an invoker that marshalls between wire types.
1508
1508
  // TODO: This omits argument count check - enable only at -O3 or similar.
@@ -1544,27 +1544,19 @@ function unexportedRuntimeSymbol(sym) {
1544
1544
  var args1 = ["throwBindingError", "invoker", "fn", "runDestructors", "retType", "classParam"];
1545
1545
  var args2 = [throwBindingError, cppInvokerFunc, cppTargetFunc, runDestructors, argTypes[0], argTypes[1]];
1546
1546
 
1547
- if (isClassMethodFunc) {
1548
- invokerFnBody += "var thisWired = classParam.toWireType("+dtorStack+", this);\n";
1549
- }
1550
-
1551
1547
  for (var i = 0; i < argCount - 2; ++i) {
1552
1548
  invokerFnBody += "var arg"+i+"Wired = argType"+i+".toWireType("+dtorStack+", arg"+i+"); // "+argTypes[i+2].name+"\n";
1553
1549
  args1.push("argType"+i);
1554
1550
  args2.push(argTypes[i+2]);
1555
1551
  }
1556
1552
 
1557
- if (isClassMethodFunc) {
1558
- argsListWired = "thisWired" + (argsListWired.length > 0 ? ", " : "") + argsListWired;
1559
- }
1560
-
1561
1553
  invokerFnBody +=
1562
1554
  (returns || isAsync ? "var rv = ":"") + "invoker(fn"+(argsListWired.length>0?", ":"")+argsListWired+");\n";
1563
1555
 
1564
1556
  if (needsDestructorStack) {
1565
1557
  invokerFnBody += "runDestructors(destructors);\n";
1566
1558
  } else {
1567
- for (var i = isClassMethodFunc?1:2; i < argTypes.length; ++i) { // Skip return value at index 0 - it's not deleted here. Also skip class type if not a method.
1559
+ for (var i = 2; i < argTypes.length; ++i) { // Skip return value at index 0 - it's not deleted here. Also skip class type if not a method.
1568
1560
  var paramName = (i === 1 ? "thisWired" : ("arg"+(i - 2)+"Wired"));
1569
1561
  if (argTypes[i].destructorFunction !== null) {
1570
1562
  invokerFnBody += paramName+"_dtor("+paramName+"); // "+argTypes[i].name+"\n";
@@ -4233,7 +4225,7 @@ function unexportedRuntimeSymbol(sym) {
4233
4225
  throw new FS.ErrnoError(63);
4234
4226
  }
4235
4227
  node.node_ops.setattr(node, {
4236
- mode: (mode & 4095) | (node.mode & ~4095),
4228
+ mode: (mode & 4095) | (node.mode & -4096),
4237
4229
  timestamp: Date.now()
4238
4230
  });
4239
4231
  },
@@ -4354,7 +4346,7 @@ function unexportedRuntimeSymbol(sym) {
4354
4346
  }
4355
4347
  // can't truncate a device
4356
4348
  if (FS.isChrdev(node.mode)) {
4357
- flags &= ~512;
4349
+ flags &= -513;
4358
4350
  }
4359
4351
  // if asked only for a directory, then this must be one
4360
4352
  if ((flags & 65536) && !FS.isDir(node.mode)) {
@@ -4374,7 +4366,7 @@ function unexportedRuntimeSymbol(sym) {
4374
4366
  FS.truncate(node, 0);
4375
4367
  }
4376
4368
  // we've already handled these, don't pass down to the underlying vfs
4377
- flags &= ~(128 | 512 | 131072);
4369
+ flags &= -131713;
4378
4370
 
4379
4371
  // register the stream with the filesystem
4380
4372
  var stream = FS.createStream({
@@ -5210,14 +5202,9 @@ function unexportedRuntimeSymbol(sym) {
5210
5202
 
5211
5203
 
5212
5204
  var runtimeKeepaliveCounter = 0;
5213
- var keepRuntimeAlive = () => noExitRuntime || runtimeKeepaliveCounter > 0;
5214
5205
 
5215
5206
  var _proc_exit = (code) => {
5216
5207
  EXITSTATUS = code;
5217
- if (!keepRuntimeAlive()) {
5218
- if (Module['onExit']) Module['onExit'](code);
5219
- ABORT = true;
5220
- }
5221
5208
  quit_(code, new ExitStatus(code));
5222
5209
  };
5223
5210
 
@@ -5229,7 +5216,7 @@ function unexportedRuntimeSymbol(sym) {
5229
5216
  checkUnflushedContent();
5230
5217
 
5231
5218
  // if exit() was called explicitly, warn the user if the runtime isn't actually being shut down
5232
- if (keepRuntimeAlive() && !implicit) {
5219
+ if (!implicit) {
5233
5220
  var msg = `program exited (with status: ${status}), but keepRuntimeAlive() is set (counter=${runtimeKeepaliveCounter}) due to an async operation, so halting execution but not exiting the runtime or preventing further async execution (you can use emscripten_force_exit, if you want to force a true shutdown)`;
5234
5221
  readyPromiseReject(msg);
5235
5222
  err(msg);
@@ -6533,46 +6520,12 @@ let library;
6533
6520
  */
6534
6521
  const getLibrary = async () => {
6535
6522
  if (!library) {
6523
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
6536
6524
  library = await Module();
6537
6525
  }
6538
6526
  return library;
6539
6527
  };
6540
6528
 
6541
- /**
6542
- * @deprecated
6543
- * @param description
6544
- * @param name
6545
- * @param defaultValue
6546
- * @returns
6547
- */
6548
- /* istanbul ignore next */
6549
- const getAttribute = (description, name, defaultValue) => {
6550
- var _a;
6551
- let returnValue;
6552
- const parsedValue = (_a = description.attributes.getNamedItem(name)) === null || _a === void 0 ? void 0 : _a.nodeValue;
6553
- if (!parsedValue) {
6554
- const node = description.getElementsByTagName(name)[0];
6555
- if (node) {
6556
- const values = node.getElementsByTagName('rdf:li');
6557
- if (values.length === 3) {
6558
- returnValue = Array.from(values).map(v => v.innerHTML);
6559
- }
6560
- else {
6561
- throw new Error(`Gainmap metadata contains an array of items for ${name} but its length is not 3`);
6562
- }
6563
- }
6564
- else {
6565
- if (defaultValue)
6566
- return defaultValue;
6567
- else
6568
- throw new Error(`Can't find ${name} in gainmap metadata`);
6569
- }
6570
- }
6571
- else {
6572
- returnValue = parsedValue;
6573
- }
6574
- return returnValue;
6575
- };
6576
6529
  /**
6577
6530
  * Decodes a JPEG file with an embedded Gainmap and XMP Metadata (aka JPEG-R)
6578
6531
  *
@@ -6594,25 +6547,42 @@ const getAttribute = (description, name, defaultValue) => {
6594
6547
  */
6595
6548
  /* istanbul ignore next */
6596
6549
  const decodeJPEGMetadata = async (file) => {
6597
- var _a, _b;
6598
6550
  const lib = await getLibrary();
6599
6551
  const result = lib.extractJpegR(file, file.length);
6600
6552
  if (!result.success)
6601
6553
  throw new Error(`${result.errorMessage}`);
6602
- const parser = new DOMParser();
6603
- const xmlDocument = parser.parseFromString(result.metadata, 'text/xml');
6604
- const description = xmlDocument.getElementsByTagName('rdf:Description')[0];
6605
- const gainMapMin = getAttribute(description, 'hdrgm:GainMapMin', '0');
6606
- const gainMapMax = getAttribute(description, 'hdrgm:GainMapMax');
6607
- const gamma = getAttribute(description, 'hdrgm:Gamma', '1');
6608
- const offsetSDR = getAttribute(description, 'hdrgm:OffsetSDR', '0.015625');
6609
- const offsetHDR = getAttribute(description, 'hdrgm:OffsetHDR', '0.015625');
6610
- let hdrCapacityMin = (_a = description.attributes.getNamedItem('hdrgm:HDRCapacityMin')) === null || _a === void 0 ? void 0 : _a.nodeValue;
6611
- if (!hdrCapacityMin)
6612
- hdrCapacityMin = '0';
6613
- const hdrCapacityMax = (_b = description.attributes.getNamedItem('hdrgm:HDRCapacityMax')) === null || _b === void 0 ? void 0 : _b.nodeValue;
6614
- if (!hdrCapacityMax)
6554
+ const getXMLValue = (xml, tag, defaultValue) => {
6555
+ // Check for attribute format first: tag="value"
6556
+ const attributeMatch = new RegExp(`${tag}="([^"]*)"`, 'i').exec(xml);
6557
+ if (attributeMatch)
6558
+ return attributeMatch[1];
6559
+ // Check for tag format: <tag>value</tag> or <tag><rdf:li>value</rdf:li>...</tag>
6560
+ const tagMatch = new RegExp(`<${tag}[^>]*>([\\s\\S]*?)</${tag}>`, 'i').exec(xml);
6561
+ if (tagMatch) {
6562
+ // Check if it contains rdf:li elements
6563
+ const liValues = tagMatch[1].match(/<rdf:li>([^<]*)<\/rdf:li>/g);
6564
+ if (liValues && liValues.length === 3) {
6565
+ return liValues.map(v => v.replace(/<\/?rdf:li>/g, ''));
6566
+ }
6567
+ return tagMatch[1].trim();
6568
+ }
6569
+ if (defaultValue !== undefined)
6570
+ return defaultValue;
6571
+ throw new Error(`Can't find ${tag} in gainmap metadata`);
6572
+ };
6573
+ const metadata = result.metadata;
6574
+ const gainMapMin = getXMLValue(metadata, 'hdrgm:GainMapMin', '0');
6575
+ const gainMapMax = getXMLValue(metadata, 'hdrgm:GainMapMax');
6576
+ const gamma = getXMLValue(metadata, 'hdrgm:Gamma', '1');
6577
+ const offsetSDR = getXMLValue(metadata, 'hdrgm:OffsetSDR', '0.015625');
6578
+ const offsetHDR = getXMLValue(metadata, 'hdrgm:OffsetHDR', '0.015625');
6579
+ // These are always attributes, so we can use a simpler regex
6580
+ const hdrCapacityMinMatch = /hdrgm:HDRCapacityMin="([^"]*)"/.exec(metadata);
6581
+ const hdrCapacityMin = hdrCapacityMinMatch ? hdrCapacityMinMatch[1] : '0';
6582
+ const hdrCapacityMaxMatch = /hdrgm:HDRCapacityMax="([^"]*)"/.exec(metadata);
6583
+ if (!hdrCapacityMaxMatch)
6615
6584
  throw new Error('Incomplete gainmap metadata');
6585
+ const hdrCapacityMax = hdrCapacityMaxMatch[1];
6616
6586
  const parsedMetadata = {
6617
6587
  gainMapMin: Array.isArray(gainMapMin) ? gainMapMin.map(v => parseFloat(v)) : [parseFloat(gainMapMin), parseFloat(gainMapMin), parseFloat(gainMapMin)],
6618
6588
  gainMapMax: Array.isArray(gainMapMax) ? gainMapMax.map(v => parseFloat(v)) : [parseFloat(gainMapMax), parseFloat(gainMapMax), parseFloat(gainMapMax)],
@@ -6624,9 +6594,6 @@ const decodeJPEGMetadata = async (file) => {
6624
6594
  };
6625
6595
  return {
6626
6596
  ...result,
6627
- /**
6628
- * Parsed metadata
6629
- */
6630
6597
  parsedMetadata
6631
6598
  };
6632
6599
  };
@@ -6648,7 +6615,7 @@ const decodeJPEGMetadata = async (file) => {
6648
6615
  * const image = await loader.loadAsync('image.exr')
6649
6616
  *
6650
6617
  * // find RAW RGB Max value of a texture
6651
- * const textureMax = await findTextureMinMax(image)
6618
+ * const textureMax = findTextureMinMax(image)
6652
6619
  *
6653
6620
  * // Encode the gainmap
6654
6621
  * const encodingResult = encode({