@monogrid/gainmap-js 2.0.4 → 2.0.6

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/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ ## [2.0.6](https://github.com/MONOGRID/gainmap-js/compare/v2.0.5...v2.0.6) (2023-11-20)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **decode:** changes usage of `NoColorSpace` to `LinearSRGBColorSpace` ([587dc03](https://github.com/MONOGRID/gainmap-js/commit/587dc0377876533b18b506516d8757e04e830c62))
7
+ * **loaders:** fixes LoadingManager `onLoad` actually waiting for gainmaps to be generated ([77170f5](https://github.com/MONOGRID/gainmap-js/commit/77170f57c5ad277d3e97d1236ab93a29106c4a99))
8
+
9
+ ## [2.0.5](https://github.com/MONOGRID/gainmap-js/compare/v2.0.4...v2.0.5) (2023-11-16)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * **jpegrloader:** rename JPEGRLoader to HDRJPEGLoader, old name kept for compatibility ([ac6e386](https://github.com/MONOGRID/gainmap-js/commit/ac6e38610886b7adec5806a7ad301bff1ec00d62))
15
+
1
16
  ## [2.0.4](https://github.com/MONOGRID/gainmap-js/compare/v2.0.3...v2.0.4) (2023-11-15)
2
17
 
3
18
 
package/README.md CHANGED
@@ -37,7 +37,7 @@ $ npm install @monogrid/gainmap-js three
37
37
  > * The **gain map**. This is a secondary “image” embedded in the file. It is not a real image, but rather contains data to convert each pixel from the base image into the other (SDR or HDR) version of the image.
38
38
  >* Gain map **metadata**. This tells the browser how the gain map is encoded as well as critical information to optimize rendering on any display.
39
39
 
40
- Please note that Google [is adopting the gain map technology in Android 14](https://support.google.com/photos/answer/14159275) but its naming of the technology refers to it as **Ultra HDR Image Format** and a JPEG file with embedded gain map is called `JPEGR` in their terminology.
40
+ Please note that Google [is adopting the gain map technology in Android 14](https://support.google.com/photos/answer/14159275) but its naming of the technology refers to it as **Ultra HDR Image Format** and a JPEG file with embedded gain map is [apparently called JPEGR](https://github.com/google/libultrahdr/blob/3a3a752a5da0b2304b1b6de0ef383bbe41256a67/lib/jpegr.h#L28C16-L28C21) in their terminology, we call it `HDRJPEG` for the moment.
41
41
 
42
42
  ## API
43
43
 
@@ -63,7 +63,7 @@ The disadvantages are:
63
63
  * Photo sharing websites and/or services (i.e. sharing with Slack) will likely strip the Gain map metadata and the HDR information will be lost, leaving you with only the SDR Representation.
64
64
 
65
65
  ```ts
66
- import { JPEGRLoader } from '@monogrid/gainmap-js'
66
+ import { HDRJPGLoader } from '@monogrid/gainmap-js'
67
67
  import {
68
68
  EquirectangularReflectionMapping,
69
69
  LinearFilter,
@@ -77,7 +77,7 @@ import {
77
77
 
78
78
  const renderer = new WebGLRenderer()
79
79
 
80
- const loader = new JPEGRLoader(renderer)
80
+ const loader = new HDRJPGLoader(renderer)
81
81
 
82
82
  const result = loader.load('gainmap.jpeg')
83
83
  // `result` can be used to populate a Texture
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.3
2
+ * @monogrid/gainmap-js v2.0.5
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
6
- import { Scene, OrthographicCamera, HalfFloatType, FloatType, Mesh, PlaneGeometry, WebGLRenderTarget, RGBAFormat, LinearFilter, LinearMipMapLinearFilter, RepeatWrapping, WebGLRenderer, DataTexture, UVMapping, NoColorSpace, IntType, ShortType, ByteType, UnsignedIntType, UnsignedByteType, MeshBasicMaterial } from 'three';
6
+ import { Scene, OrthographicCamera, HalfFloatType, FloatType, Mesh, PlaneGeometry, WebGLRenderTarget, RGBAFormat, LinearFilter, LinearMipMapLinearFilter, RepeatWrapping, WebGLRenderer, DataTexture, UVMapping, LinearSRGBColorSpace, IntType, ShortType, ByteType, UnsignedIntType, UnsignedByteType, MeshBasicMaterial } from 'three';
7
7
 
8
8
  const getBufferForType = (type, width, height) => {
9
9
  let out;
@@ -51,7 +51,7 @@ const canReadPixels = (type, renderer, camera) => {
51
51
  return _canReadPixelsResult;
52
52
  const testRT = new WebGLRenderTarget(1, 1, {
53
53
  type,
54
- colorSpace: NoColorSpace,
54
+ colorSpace: LinearSRGBColorSpace,
55
55
  format: RGBAFormat,
56
56
  magFilter: LinearFilter,
57
57
  minFilter: LinearFilter,
@@ -74,10 +74,10 @@ const canReadPixels = (type, renderer, camera) => {
74
74
  return _canReadPixelsResult;
75
75
  };
76
76
  /**
77
- * Utility structure used for rendering a texture with a material
77
+ * Utility class used for rendering a texture with a material
78
78
  *
79
- * @category General
80
- * @group General
79
+ * @category Core
80
+ * @group Core
81
81
  */
82
82
  class QuadRenderer {
83
83
  /**
@@ -182,7 +182,7 @@ class QuadRenderer {
182
182
  return out;
183
183
  }
184
184
  toDataTexture() {
185
- return new DataTexture(this.toArray(), this.width, this.height, RGBAFormat, this._type, UVMapping, RepeatWrapping, RepeatWrapping, LinearFilter, LinearMipMapLinearFilter, 1, NoColorSpace);
185
+ return new DataTexture(this.toArray(), this.width, this.height, RGBAFormat, this._type, UVMapping, RepeatWrapping, RepeatWrapping, LinearFilter, LinearMipMapLinearFilter, 1, LinearSRGBColorSpace);
186
186
  }
187
187
  /**
188
188
  * If using a disposable renderer, it will dispose it.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.3
2
+ * @monogrid/gainmap-js v2.0.5
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.3
2
+ * @monogrid/gainmap-js v2.0.5
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
@@ -21,7 +21,7 @@ const canvasToBlob = async (canvas, mimeType, quality) => {
21
21
  if (res)
22
22
  resolve(res);
23
23
  else
24
- reject('Failed to convert canvas to blob');
24
+ reject(new Error('Failed to convert canvas to blob'));
25
25
  }, mimeType, quality || 0.9);
26
26
  });
27
27
  };
@@ -1,14 +1,16 @@
1
1
  import { ByteType, ColorSpace, DataTexture, FloatType, HalfFloatType, IntType, Material, ShortType, TextureDataType, UnsignedByteType, UnsignedIntType, WebGLRenderer, WebGLRenderTarget } from 'three';
2
2
  /**
3
- * @category General
4
- * @group General
3
+ * Utility Type that translates `three` texture types to their TypedArray counterparts.
4
+ *
5
+ * @category Utility
6
+ * @group Utility
5
7
  */
6
8
  export type TextureDataTypeToBufferType<TType extends TextureDataType> = TType extends typeof UnsignedByteType ? Uint8ClampedArray : TType extends typeof HalfFloatType ? Uint16Array : TType extends typeof UnsignedIntType ? Uint32Array : TType extends typeof ByteType ? Int8Array : TType extends typeof ShortType ? Int16Array : TType extends typeof IntType ? Int32Array : TType extends typeof FloatType ? Float32Array : never;
7
9
  /**
8
- * Utility structure used for rendering a texture with a material
10
+ * Utility class used for rendering a texture with a material
9
11
  *
10
- * @category General
11
- * @group General
12
+ * @category Core
13
+ * @group Core
12
14
  */
13
15
  export declare class QuadRenderer<TType extends TextureDataType, TMaterial extends Material> {
14
16
  private _renderer;
@@ -5,8 +5,8 @@ import { RGBE } from 'three/examples/jsm/loaders/RGBELoader';
5
5
  /**
6
6
  * Utility function to obtain a `DataTexture` from various input formats
7
7
  *
8
- * @category General
9
- * @group General
8
+ * @category Utility
9
+ * @group Utility
10
10
  *
11
11
  * @param image
12
12
  * @returns
@@ -0,0 +1,3 @@
1
+ export * from './get-data-texture';
2
+ export * from './QuadRenderer';
3
+ export * from './types';
@@ -2,8 +2,8 @@
2
2
  * This is the Metadata stored in an encoded Gainmap which is used
3
3
  * to decode it and return an HDR image
4
4
  *
5
- * @category Gainmap Specifications
6
- * @group Gainmap Specifications
5
+ * @category Specs
6
+ * @group Specs
7
7
  */
8
8
  export type GainMapMetadata = {
9
9
  /**
@@ -4,8 +4,8 @@ import { DecodeParameters } from './types';
4
4
  /**
5
5
  * Decodes a gain map using a WebGLRenderTarget
6
6
  *
7
- * @category Decoding
8
- * @group Decoding
7
+ * @category Decoding Functions
8
+ * @group Decoding Functions
9
9
  * @example
10
10
  * import { decode } from '@monogrid/gainmap-js'
11
11
  * import {
@@ -1,7 +1,22 @@
1
1
  /**
2
+ * Extracts XMP Metadata and the gain map recovery image
3
+ * from a single JPEG file.
2
4
  *
3
- * @param jpegFile
4
- * @returns
5
+ * @category Decoding Functions
6
+ * @group Decoding Functions
7
+ * @param jpegFile an `Uint8Array` containing and encoded JPEG file
8
+ * @returns an sdr `Uint8Array` compressed in JPEG, a gainMap `Uint8Array` compressed in JPEG and the XMP parsed XMP metadata
9
+ * @throws Error if XMP Metadata is not found
10
+ * @throws Error if Gain map image is not found
11
+ * @example
12
+ * import { FileLoader } from 'three'
13
+ * import { extractGainmapFromJPEG } from '@monogrid/gainmap-js'
14
+ *
15
+ * const jpegFile = await new FileLoader()
16
+ * .setResponseType('arraybuffer')
17
+ * .loadAsync('image.jpg')
18
+ *
19
+ * const { sdr, gainMap, metadata } = extractGainmapFromJPEG(jpegFile)
5
20
  */
6
21
  export declare const extractGainmapFromJPEG: (jpegFile: Uint8Array) => Promise<{
7
22
  sdr: Uint8Array;
@@ -3,6 +3,7 @@ export * from '../core/types';
3
3
  export * from './decode';
4
4
  export * from './extract';
5
5
  export * from './loaders/GainMapLoader';
6
- export * from './loaders/JPEGRLoader';
6
+ export * from './loaders/HDRJPGLoader';
7
+ export { HDRJPGLoader as JPEGRLoader } from './loaders/HDRJPGLoader';
7
8
  export * from './materials/GainMapDecoderMaterial';
8
9
  export * from './types';
@@ -45,7 +45,6 @@ import { LoaderBase } from './LoaderBase';
45
45
  * scene.background.mapping = EquirectangularReflectionMapping
46
46
  * scene.background.minFilter = LinearFilter
47
47
  *
48
- *
49
48
  */
50
49
  export declare class GainMapLoader extends LoaderBase<[string, string, string]> {
51
50
  /**
@@ -56,12 +55,10 @@ export declare class GainMapLoader extends LoaderBase<[string, string, string]>
56
55
  *
57
56
  * useful for webp gain maps
58
57
  *
59
- * @param sdrUrl
60
- * @param gainMapUrl
61
- * @param metadataUrl
62
- * @param onLoad
63
- * @param onProgress
64
- * @param onError
58
+ * @param urls An array in the form of [sdr.jpg, gainmap.jpg, metadata.json]
59
+ * @param onLoad Load complete callback, will receive the result
60
+ * @param onProgress Progress callback, will receive a {@link ProgressEvent}
61
+ * @param onError Error callback
65
62
  * @returns
66
63
  */
67
64
  load([sdrUrl, gainMapUrl, metadataUrl]: [string, string, string], onLoad?: (data: QuadRenderer<typeof HalfFloatType, GainMapDecoderMaterial>) => void, onProgress?: (event: ProgressEvent) => void, onError?: (err: unknown) => void): QuadRenderer<typeof HalfFloatType, GainMapDecoderMaterial>;
@@ -1,6 +1,6 @@
1
1
  import { HalfFloatType } from 'three';
2
2
  import { QuadRenderer } from '../../core/QuadRenderer';
3
- import { GainMapDecoderMaterial } from '../../decode/materials/GainMapDecoderMaterial';
3
+ import { GainMapDecoderMaterial } from '../materials/GainMapDecoderMaterial';
4
4
  import { LoaderBase } from './LoaderBase';
5
5
  /**
6
6
  * A Three.js Loader for a JPEG with embedded gainmap metadata.
@@ -47,13 +47,14 @@ import { LoaderBase } from './LoaderBase';
47
47
 
48
48
  *
49
49
  */
50
- export declare class JPEGRLoader extends LoaderBase<string> {
50
+ export declare class HDRJPGLoader extends LoaderBase<string> {
51
51
  /**
52
+ * Loads a JPEGR Image
52
53
  *
53
- * @param url
54
- * @param onLoad
55
- * @param onProgress
56
- * @param onError
54
+ * @param url An array in the form of [sdr.jpg, gainmap.jpg, metadata.json]
55
+ * @param onLoad Load complete callback, will receive the result
56
+ * @param onProgress Progress callback, will receive a {@link ProgressEvent}
57
+ * @param onError Error callback
57
58
  * @returns
58
59
  */
59
60
  load(url: string, onLoad?: (data: QuadRenderer<typeof HalfFloatType, GainMapDecoderMaterial>) => void, onProgress?: (event: ProgressEvent) => void, onError?: (err: unknown) => void): QuadRenderer<typeof HalfFloatType, GainMapDecoderMaterial>;
@@ -3,7 +3,8 @@ import { QuadRenderer } from '../../core/QuadRenderer';
3
3
  import { type GainMapMetadata } from '../../core/types';
4
4
  import { GainMapDecoderMaterial } from '../materials/GainMapDecoderMaterial';
5
5
  export declare class LoaderBase<TUrl = string> extends Loader<QuadRenderer<typeof HalfFloatType, GainMapDecoderMaterial>, TUrl> {
6
- private renderer;
6
+ private _renderer;
7
+ protected _internalLoadingManager: LoadingManager;
7
8
  /**
8
9
  *
9
10
  * @param renderer
@@ -1,10 +1,10 @@
1
1
  import { type Texture, type WebGLRenderer } from 'three';
2
2
  import { type GainMapMetadata } from '../core/types';
3
3
  /**
4
- * Parameters for decoding a Gainmap
4
+ * Necessary parameters for decoding a Gainmap
5
5
  *
6
- * @category Gainmap Specifications
7
- * @group Gainmap Specifications
6
+ * @category Specs
7
+ * @group Specs
8
8
  */
9
9
  export type GainmapDecodingParameters = {
10
10
  /**
@@ -19,8 +19,8 @@ export type GainmapDecodingParameters = {
19
19
  maxDisplayBoost: number;
20
20
  };
21
21
  /**
22
- * @category Decoding
23
- * @group Decoding
22
+ * @category Decoding Functions
23
+ * @group Decoding Functions
24
24
  */
25
25
  export type DecodeParameters = {
26
26
  /**
package/dist/decode.js CHANGED
@@ -1,10 +1,10 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.3
2
+ * @monogrid/gainmap-js v2.0.5
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
6
- import { Q as QuadRenderer } from './QuadRenderer-lU9EAEKl.js';
7
- import { ShaderMaterial, Vector3, NoBlending, SRGBColorSpace, NoColorSpace, HalfFloatType, Loader, Texture, UVMapping, ClampToEdgeWrapping, LinearFilter, LinearMipMapLinearFilter, RGBAFormat, UnsignedByteType, FileLoader } from 'three';
6
+ import { Q as QuadRenderer } from './QuadRenderer-gqnZPNP-.js';
7
+ import { ShaderMaterial, Vector3, NoBlending, SRGBColorSpace, LinearSRGBColorSpace, HalfFloatType, Loader, LoadingManager, Texture, UVMapping, ClampToEdgeWrapping, LinearFilter, LinearMipMapLinearFilter, RGBAFormat, UnsignedByteType, FileLoader } from 'three';
8
8
 
9
9
  const vertexShader = /* glsl */ `
10
10
  varying vec2 vUv;
@@ -152,8 +152,8 @@ class GainMapDecoderMaterial extends ShaderMaterial {
152
152
  /**
153
153
  * Decodes a gain map using a WebGLRenderTarget
154
154
  *
155
- * @category Decoding
156
- * @group Decoding
155
+ * @category Decoding Functions
156
+ * @group Decoding Functions
157
157
  * @example
158
158
  * import { decode } from '@monogrid/gainmap-js'
159
159
  * import {
@@ -208,14 +208,19 @@ const decode = (params) => {
208
208
  sdr.colorSpace = SRGBColorSpace;
209
209
  }
210
210
  sdr.needsUpdate = true;
211
- if (gainMap.colorSpace !== NoColorSpace) {
212
- console.warn('Gainmap Colorspace needs to be *NoColorSpace*');
213
- gainMap.colorSpace = NoColorSpace;
211
+ if (gainMap.colorSpace !== LinearSRGBColorSpace) {
212
+ console.warn('Gainmap Colorspace needs to be *LinearSRGBColorSpace*');
213
+ gainMap.colorSpace = LinearSRGBColorSpace;
214
214
  }
215
215
  gainMap.needsUpdate = true;
216
- const material = new GainMapDecoderMaterial(Object.assign(Object.assign({}, params), { sdr,
217
- gainMap }));
218
- const quadRenderer = new QuadRenderer(sdr.image.width, sdr.image.height, HalfFloatType, NoColorSpace, material, renderer);
216
+ const material = new GainMapDecoderMaterial({
217
+ ...params,
218
+ sdr,
219
+ gainMap
220
+ });
221
+ // TODO: three types are generic, eslint complains here, see how we can solve
222
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
223
+ const quadRenderer = new QuadRenderer(sdr.image.width, sdr.image.height, HalfFloatType, LinearSRGBColorSpace, material, renderer);
219
224
  try {
220
225
  quadRenderer.render();
221
226
  }
@@ -328,7 +333,7 @@ class MPFExtractor {
328
333
  // If you're executing this line on a big endian machine, it'll be reversed.
329
334
  // bigEnd further down though, refers to the endianness of the image itself.
330
335
  if (dataView.getUint16(0) !== 0xffd8) {
331
- reject('Not a valid jpeg');
336
+ reject(new Error('Not a valid jpeg'));
332
337
  return;
333
338
  }
334
339
  const length = dataView.byteLength;
@@ -337,11 +342,11 @@ class MPFExtractor {
337
342
  let marker; // APP# marker
338
343
  while (offset < length) {
339
344
  if (++loops > 250) {
340
- reject(`Found no marker after ${loops} loops 😵`);
345
+ reject(new Error(`Found no marker after ${loops} loops 😵`));
341
346
  return;
342
347
  }
343
348
  if (dataView.getUint8(offset) !== 0xff) {
344
- reject(`Not a valid marker at offset 0x${offset.toString(16)}, found: 0x${dataView.getUint8(offset).toString(16)}`);
349
+ reject(new Error(`Not a valid marker at offset 0x${offset.toString(16)}, found: 0x${dataView.getUint8(offset).toString(16)}`));
345
350
  return;
346
351
  }
347
352
  marker = dataView.getUint8(offset + 1);
@@ -381,18 +386,18 @@ class MPFExtractor {
381
386
  bigEnd = true;
382
387
  }
383
388
  else {
384
- reject('No valid endianness marker found in TIFF header');
389
+ reject(new Error('No valid endianness marker found in TIFF header'));
385
390
  return;
386
391
  }
387
392
  if (dataView.getUint16(tiffOffset + 2, !bigEnd) !== 0x002a) {
388
- reject('Not valid TIFF data! (no 0x002A marker)');
393
+ reject(new Error('Not valid TIFF data! (no 0x002A marker)'));
389
394
  return;
390
395
  }
391
396
  // 32 bit number stating the offset from the start of the 8 Byte MP Header
392
397
  // to MP Index IFD Least possible value is thus 8 (means 0 offset)
393
398
  const firstIFDOffset = dataView.getUint32(tiffOffset + 4, !bigEnd);
394
399
  if (firstIFDOffset < 0x00000008) {
395
- reject('Not valid TIFF data! (First offset less than 8)');
400
+ reject(new Error('Not valid TIFF data! (First offset less than 8)'));
396
401
  return;
397
402
  }
398
403
  // Move ahead to MP Index IFD
@@ -466,9 +471,24 @@ class MPFExtractor {
466
471
  }
467
472
 
468
473
  /**
474
+ * Extracts XMP Metadata and the gain map recovery image
475
+ * from a single JPEG file.
476
+ *
477
+ * @category Decoding Functions
478
+ * @group Decoding Functions
479
+ * @param jpegFile an `Uint8Array` containing and encoded JPEG file
480
+ * @returns an sdr `Uint8Array` compressed in JPEG, a gainMap `Uint8Array` compressed in JPEG and the XMP parsed XMP metadata
481
+ * @throws Error if XMP Metadata is not found
482
+ * @throws Error if Gain map image is not found
483
+ * @example
484
+ * import { FileLoader } from 'three'
485
+ * import { extractGainmapFromJPEG } from '@monogrid/gainmap-js'
469
486
  *
470
- * @param jpegFile
471
- * @returns
487
+ * const jpegFile = await new FileLoader()
488
+ * .setResponseType('arraybuffer')
489
+ * .loadAsync('image.jpg')
490
+ *
491
+ * const { sdr, gainMap, metadata } = extractGainmapFromJPEG(jpegFile)
472
492
  */
473
493
  const extractGainmapFromJPEG = async (jpegFile) => {
474
494
  const metadata = extractXMP(jpegFile);
@@ -507,7 +527,8 @@ class LoaderBase extends Loader {
507
527
  */
508
528
  constructor(renderer, manager) {
509
529
  super(manager);
510
- this.renderer = renderer;
530
+ this._renderer = renderer;
531
+ this._internalLoadingManager = new LoadingManager();
511
532
  }
512
533
  /**
513
534
  * @private
@@ -527,7 +548,7 @@ class LoaderBase extends Loader {
527
548
  gainMap: new Texture(),
528
549
  sdr: new Texture()
529
550
  });
530
- return new QuadRenderer(16, 16, HalfFloatType, NoColorSpace, material, this.renderer);
551
+ return new QuadRenderer(16, 16, HalfFloatType, LinearSRGBColorSpace, material, this._renderer);
531
552
  }
532
553
  /**
533
554
  *
@@ -560,7 +581,7 @@ class LoaderBase extends Loader {
560
581
  gainMapImage = res[0];
561
582
  sdrImage = res[1];
562
583
  }
563
- const gainMap = new Texture(gainMapImage, UVMapping, ClampToEdgeWrapping, ClampToEdgeWrapping, LinearFilter, LinearMipMapLinearFilter, RGBAFormat, UnsignedByteType, 1, NoColorSpace);
584
+ const gainMap = new Texture(gainMapImage, UVMapping, ClampToEdgeWrapping, ClampToEdgeWrapping, LinearFilter, LinearMipMapLinearFilter, RGBAFormat, UnsignedByteType, 1, LinearSRGBColorSpace);
564
585
  gainMap.flipY = needsFlip;
565
586
  gainMap.needsUpdate = true;
566
587
  const sdr = new Texture(sdrImage, UVMapping, ClampToEdgeWrapping, ClampToEdgeWrapping, LinearFilter, LinearMipMapLinearFilter, RGBAFormat, UnsignedByteType, 1, SRGBColorSpace);
@@ -626,7 +647,6 @@ class LoaderBase extends Loader {
626
647
  * scene.background.mapping = EquirectangularReflectionMapping
627
648
  * scene.background.minFilter = LinearFilter
628
649
  *
629
- *
630
650
  */
631
651
  class GainMapLoader extends LoaderBase {
632
652
  /**
@@ -637,12 +657,10 @@ class GainMapLoader extends LoaderBase {
637
657
  *
638
658
  * useful for webp gain maps
639
659
  *
640
- * @param sdrUrl
641
- * @param gainMapUrl
642
- * @param metadataUrl
643
- * @param onLoad
644
- * @param onProgress
645
- * @param onError
660
+ * @param urls An array in the form of [sdr.jpg, gainmap.jpg, metadata.json]
661
+ * @param onLoad Load complete callback, will receive the result
662
+ * @param onProgress Progress callback, will receive a {@link ProgressEvent}
663
+ * @param onError Error callback
646
664
  * @returns
647
665
  */
648
666
  load([sdrUrl, gainMapUrl, metadataUrl], onLoad, onProgress, onError) {
@@ -655,6 +673,9 @@ class GainMapLoader extends LoaderBase {
655
673
  await this.render(quadRenderer, gainMap, sdr, metadata);
656
674
  if (typeof onLoad === 'function')
657
675
  onLoad(quadRenderer);
676
+ this.manager.itemEnd(sdrUrl);
677
+ this.manager.itemEnd(gainMapUrl);
678
+ this.manager.itemEnd(metadataUrl);
658
679
  quadRenderer.dispose();
659
680
  }
660
681
  };
@@ -675,7 +696,10 @@ class GainMapLoader extends LoaderBase {
675
696
  onProgress(new ProgressEvent('progress', { lengthComputable, loaded, total }));
676
697
  }
677
698
  };
678
- const sdrLoader = new FileLoader(this.manager);
699
+ this.manager.itemStart(sdrUrl);
700
+ this.manager.itemStart(gainMapUrl);
701
+ this.manager.itemStart(metadataUrl);
702
+ const sdrLoader = new FileLoader(this._internalLoadingManager);
679
703
  sdrLoader.setResponseType('arraybuffer');
680
704
  sdrLoader.setRequestHeader(this.requestHeader);
681
705
  sdrLoader.setPath(this.path);
@@ -684,14 +708,18 @@ class GainMapLoader extends LoaderBase {
684
708
  if (typeof buffer === 'string')
685
709
  throw new Error('Invalid sdr buffer');
686
710
  sdr = buffer;
687
- loadCheck();
711
+ await loadCheck();
688
712
  }, (e) => {
689
713
  sdrLengthComputable = e.lengthComputable;
690
714
  sdrLoaded = e.loaded;
691
715
  sdrTotal = e.total;
692
716
  progressHandler();
693
- }, onError);
694
- const gainMapLoader = new FileLoader(this.manager);
717
+ }, (error) => {
718
+ this.manager.itemError(sdrUrl);
719
+ if (typeof onError === 'function')
720
+ onError(error);
721
+ });
722
+ const gainMapLoader = new FileLoader(this._internalLoadingManager);
695
723
  gainMapLoader.setResponseType('arraybuffer');
696
724
  gainMapLoader.setRequestHeader(this.requestHeader);
697
725
  gainMapLoader.setPath(this.path);
@@ -700,14 +728,18 @@ class GainMapLoader extends LoaderBase {
700
728
  if (typeof buffer === 'string')
701
729
  throw new Error('Invalid gainmap buffer');
702
730
  gainMap = buffer;
703
- loadCheck();
731
+ await loadCheck();
704
732
  }, (e) => {
705
733
  gainMapLengthComputable = e.lengthComputable;
706
734
  gainMapLoaded = e.loaded;
707
735
  gainMapTotal = e.total;
708
736
  progressHandler();
709
- }, onError);
710
- const metadataLoader = new FileLoader(this.manager);
737
+ }, (error) => {
738
+ this.manager.itemError(gainMapUrl);
739
+ if (typeof onError === 'function')
740
+ onError(error);
741
+ });
742
+ const metadataLoader = new FileLoader(this._internalLoadingManager);
711
743
  // metadataLoader.setResponseType('json')
712
744
  metadataLoader.setRequestHeader(this.requestHeader);
713
745
  metadataLoader.setPath(this.path);
@@ -715,14 +747,20 @@ class GainMapLoader extends LoaderBase {
715
747
  metadataLoader.load(metadataUrl, async (json) => {
716
748
  if (typeof json !== 'string')
717
749
  throw new Error('Invalid metadata string');
750
+ // TODO: implement check on JSON file and remove this eslint disable
751
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
718
752
  metadata = JSON.parse(json);
719
- loadCheck();
753
+ await loadCheck();
720
754
  }, (e) => {
721
755
  metadataLengthComputable = e.lengthComputable;
722
756
  metadataLoaded = e.loaded;
723
757
  metadataTotal = e.total;
724
758
  progressHandler();
725
- }, onError);
759
+ }, (error) => {
760
+ this.manager.itemError(metadataUrl);
761
+ if (typeof onError === 'function')
762
+ onError(error);
763
+ });
726
764
  return quadRenderer;
727
765
  }
728
766
  }
@@ -772,22 +810,24 @@ class GainMapLoader extends LoaderBase {
772
810
 
773
811
  *
774
812
  */
775
- class JPEGRLoader extends LoaderBase {
813
+ class HDRJPGLoader extends LoaderBase {
776
814
  /**
815
+ * Loads a JPEGR Image
777
816
  *
778
- * @param url
779
- * @param onLoad
780
- * @param onProgress
781
- * @param onError
817
+ * @param url An array in the form of [sdr.jpg, gainmap.jpg, metadata.json]
818
+ * @param onLoad Load complete callback, will receive the result
819
+ * @param onProgress Progress callback, will receive a {@link ProgressEvent}
820
+ * @param onError Error callback
782
821
  * @returns
783
822
  */
784
823
  load(url, onLoad, onProgress, onError) {
785
824
  const quadRenderer = this.prepareQuadRenderer();
786
- const loader = new FileLoader(this.manager);
825
+ const loader = new FileLoader(this._internalLoadingManager);
787
826
  loader.setResponseType('arraybuffer');
788
827
  loader.setRequestHeader(this.requestHeader);
789
828
  loader.setPath(this.path);
790
829
  loader.setWithCredentials(this.withCredentials);
830
+ this.manager.itemStart(url);
791
831
  loader.load(url, async (jpeg) => {
792
832
  if (typeof jpeg === 'string')
793
833
  throw new Error('Invalid buffer');
@@ -795,10 +835,15 @@ class JPEGRLoader extends LoaderBase {
795
835
  await this.render(quadRenderer, gainMapJPEG, sdrJPEG, metadata);
796
836
  if (typeof onLoad === 'function')
797
837
  onLoad(quadRenderer);
838
+ this.manager.itemEnd(url);
798
839
  quadRenderer.dispose();
799
- }, onProgress, onError);
840
+ }, onProgress, (error) => {
841
+ this.manager.itemError(url);
842
+ if (typeof onError === 'function')
843
+ onError(error);
844
+ });
800
845
  return quadRenderer;
801
846
  }
802
847
  }
803
848
 
804
- export { GainMapDecoderMaterial, GainMapLoader, JPEGRLoader, QuadRenderer, decode, extractGainmapFromJPEG };
849
+ export { GainMapDecoderMaterial, GainMapLoader, HDRJPGLoader, HDRJPGLoader as JPEGRLoader, QuadRenderer, decode, extractGainmapFromJPEG };