@monogrid/gainmap-js 2.0.6 → 2.0.7

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,11 @@
1
+ ## [2.0.7](https://github.com/MONOGRID/gainmap-js/compare/v2.0.6...v2.0.7) (2023-11-23)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **core:** QuadRenderer dispose method now properly disposes of its internal resources ([#13](https://github.com/MONOGRID/gainmap-js/issues/13)) ([8e4473d](https://github.com/MONOGRID/gainmap-js/commit/8e4473da77732080de24f98dd271fecda06f9e53))
7
+ * **HDRJPGLoader:** renders (and returns) an SDR image when provided with a normal jpeg file ([#12](https://github.com/MONOGRID/gainmap-js/issues/12)) ([5222151](https://github.com/MONOGRID/gainmap-js/commit/5222151e6b5c95df79f1c4085cf36f30bd9c2dc4))
8
+
1
9
  ## [2.0.6](https://github.com/MONOGRID/gainmap-js/compare/v2.0.5...v2.0.6) (2023-11-20)
2
10
 
3
11
 
package/README.md CHANGED
@@ -79,7 +79,7 @@ const renderer = new WebGLRenderer()
79
79
 
80
80
  const loader = new HDRJPGLoader(renderer)
81
81
 
82
- const result = loader.load('gainmap.jpeg')
82
+ const result = await loader.loadAsync('gainmap.jpeg')
83
83
  // `result` can be used to populate a Texture
84
84
 
85
85
  const scene = new Scene()
@@ -99,6 +99,11 @@ scene.background = result.toDataTexture()
99
99
  scene.background.mapping = EquirectangularReflectionMapping
100
100
  scene.background.minFilter = LinearFilter
101
101
 
102
+
103
+ // result must be manually disposed
104
+ // when you are done using it
105
+ result.dispose()
106
+
102
107
  ```
103
108
 
104
109
  ### Using separate files
@@ -127,7 +132,7 @@ const renderer = new WebGLRenderer()
127
132
 
128
133
  const loader = new GainMapLoader(renderer)
129
134
 
130
- const result = loader.load(['sdr.jpeg', 'gainmap.jpeg', 'metadata.json'])
135
+ const result = await loader.loadAsync(['sdr.jpeg', 'gainmap.jpeg', 'metadata.json'])
131
136
  // `result` can be used to populate a Texture
132
137
 
133
138
  const scene = new Scene()
@@ -147,6 +152,9 @@ scene.background = result.toDataTexture()
147
152
  scene.background.mapping = EquirectangularReflectionMapping
148
153
  scene.background.minFilter = LinearFilter
149
154
 
155
+ // result must be manually disposed
156
+ // when you are done using it
157
+ result.dispose()
150
158
  ```
151
159
 
152
160
  ### Encoding
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.5
2
+ * @monogrid/gainmap-js v2.0.6
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, LinearSRGBColorSpace, 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, ShaderMaterial, Texture, IntType, ShortType, ByteType, UnsignedIntType, UnsignedByteType, MeshBasicMaterial } from 'three';
7
7
 
8
8
  const getBufferForType = (type, width, height) => {
9
9
  let out;
@@ -181,19 +181,75 @@ class QuadRenderer {
181
181
  this._renderer.readRenderTargetPixels(this._renderTarget, 0, 0, this._width, this._height, out);
182
182
  return out;
183
183
  }
184
+ /**
185
+ * Performs a readPixel operation in the renderTarget
186
+ * and returns a DataTexture containing the read data
187
+ *
188
+ * @returns
189
+ */
184
190
  toDataTexture() {
185
191
  return new DataTexture(this.toArray(), this.width, this.height, RGBAFormat, this._type, UVMapping, RepeatWrapping, RepeatWrapping, LinearFilter, LinearMipMapLinearFilter, 1, LinearSRGBColorSpace);
186
192
  }
187
193
  /**
188
194
  * If using a disposable renderer, it will dispose it.
189
195
  */
190
- dispose() {
196
+ disposeOnDemandRenderer() {
191
197
  this._renderer.setRenderTarget(null);
192
198
  if (this._rendererIsDisposable) {
193
199
  this._renderer.dispose();
194
200
  this._renderer.forceContextLoss();
195
201
  }
196
202
  }
203
+ /**
204
+ * Will dispose of **all** assets used by this renderer.
205
+ *
206
+ *
207
+ * @param disposeRenderTarget will dispose of the renderTarget which will not be usable later
208
+ * set this to true if you passed the `renderTarget.texture` to a `PMREMGenerator`
209
+ * or are otherwise done with it.
210
+ *
211
+ * @example
212
+ * ```js
213
+ * const loader = new HDRJPGLoader(renderer)
214
+ * const result = await loader.loadAsync('gainmap.jpeg')
215
+ * const mesh = new Mesh(geometry, new MeshBasicMaterial({ map: result.renderTarget.texture }) )
216
+ * // DO NOT dispose the renderTarget here,
217
+ * // it is used directly in the material
218
+ * result.dispose()
219
+ * ```
220
+ *
221
+ * @example
222
+ * ```js
223
+ * const loader = new HDRJPGLoader(renderer)
224
+ * const pmremGenerator = new PMREMGenerator( renderer );
225
+ * const result = await loader.loadAsync('gainmap.jpeg')
226
+ * const envMap = pmremGenerator.fromEquirectangular(result.renderTarget.texture)
227
+ * const mesh = new Mesh(geometry, new MeshStandardMaterial({ envMap }) )
228
+ * // renderTarget can be disposed here
229
+ * // because it was used to generate a PMREM texture
230
+ * result.dispose(true)
231
+ * ```
232
+ */
233
+ dispose(disposeRenderTarget) {
234
+ this.disposeOnDemandRenderer();
235
+ if (disposeRenderTarget) {
236
+ this.renderTarget.dispose();
237
+ }
238
+ // dispose shader material texture uniforms
239
+ if (this.material instanceof ShaderMaterial) {
240
+ Object.values(this.material.uniforms).forEach(v => {
241
+ if (v.value instanceof Texture)
242
+ v.value.dispose();
243
+ });
244
+ }
245
+ // dispose other material properties
246
+ Object.values(this.material).forEach(value => {
247
+ if (value instanceof Texture)
248
+ value.dispose();
249
+ });
250
+ this.material.dispose();
251
+ this._quad.geometry.dispose();
252
+ }
197
253
  /**
198
254
  * Width of the texture
199
255
  */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.5
2
+ * @monogrid/gainmap-js v2.0.6
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.5
2
+ * @monogrid/gainmap-js v2.0.6
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
@@ -48,11 +48,48 @@ export declare class QuadRenderer<TType extends TextureDataType, TMaterial exten
48
48
  * @returns a TypedArray containing RGBA values from this renderer
49
49
  */
50
50
  toArray(): TextureDataTypeToBufferType<TType>;
51
+ /**
52
+ * Performs a readPixel operation in the renderTarget
53
+ * and returns a DataTexture containing the read data
54
+ *
55
+ * @returns
56
+ */
51
57
  toDataTexture(): DataTexture;
52
58
  /**
53
59
  * If using a disposable renderer, it will dispose it.
54
60
  */
55
- dispose(): void;
61
+ disposeOnDemandRenderer(): void;
62
+ /**
63
+ * Will dispose of **all** assets used by this renderer.
64
+ *
65
+ *
66
+ * @param disposeRenderTarget will dispose of the renderTarget which will not be usable later
67
+ * set this to true if you passed the `renderTarget.texture` to a `PMREMGenerator`
68
+ * or are otherwise done with it.
69
+ *
70
+ * @example
71
+ * ```js
72
+ * const loader = new HDRJPGLoader(renderer)
73
+ * const result = await loader.loadAsync('gainmap.jpeg')
74
+ * const mesh = new Mesh(geometry, new MeshBasicMaterial({ map: result.renderTarget.texture }) )
75
+ * // DO NOT dispose the renderTarget here,
76
+ * // it is used directly in the material
77
+ * result.dispose()
78
+ * ```
79
+ *
80
+ * @example
81
+ * ```js
82
+ * const loader = new HDRJPGLoader(renderer)
83
+ * const pmremGenerator = new PMREMGenerator( renderer );
84
+ * const result = await loader.loadAsync('gainmap.jpeg')
85
+ * const envMap = pmremGenerator.fromEquirectangular(result.renderTarget.texture)
86
+ * const mesh = new Mesh(geometry, new MeshStandardMaterial({ envMap }) )
87
+ * // renderTarget can be disposed here
88
+ * // because it was used to generate a PMREM texture
89
+ * result.dispose(true)
90
+ * ```
91
+ */
92
+ dispose(disposeRenderTarget?: boolean): void;
56
93
  /**
57
94
  * Width of the texture
58
95
  */
@@ -48,6 +48,9 @@ import { DecodeParameters } from './types';
48
48
  * scene.add(mesh)
49
49
  * renderer.render(scene, new PerspectiveCamera())
50
50
  *
51
+ * // result must be manually disposed
52
+ * // when you are done using it
53
+ * result.dispose()
51
54
  *
52
55
  * @param params
53
56
  * @returns
@@ -0,0 +1,2 @@
1
+ export declare class GainMapNotFoundError extends Error {
2
+ }
@@ -0,0 +1,2 @@
1
+ export declare class XMPMetadataNotFoundError extends Error {
2
+ }
@@ -25,7 +25,7 @@ import { LoaderBase } from './LoaderBase';
25
25
  *
26
26
  * const loader = new GainMapLoader(renderer)
27
27
  *
28
- * const result = loader.load(['sdr.jpeg', 'gainmap.jpeg', 'metadata.json'])
28
+ * const result = await loader.loadAsync(['sdr.jpeg', 'gainmap.jpeg', 'metadata.json'])
29
29
  * // `result` can be used to populate a Texture
30
30
  *
31
31
  * const scene = new Scene()
@@ -45,6 +45,10 @@ import { LoaderBase } from './LoaderBase';
45
45
  * scene.background.mapping = EquirectangularReflectionMapping
46
46
  * scene.background.minFilter = LinearFilter
47
47
  *
48
+ * // result must be manually disposed
49
+ * // when you are done using it
50
+ * result.dispose()
51
+ *
48
52
  */
49
53
  export declare class GainMapLoader extends LoaderBase<[string, string, string]> {
50
54
  /**
@@ -9,7 +9,7 @@ import { LoaderBase } from './LoaderBase';
9
9
  * @group Loaders
10
10
  *
11
11
  * @example
12
- * import { JPEGRLoader } from '@monogrid/gainmap-js'
12
+ * import { HDRJPGLoader } from '@monogrid/gainmap-js'
13
13
  * import {
14
14
  * EquirectangularReflectionMapping,
15
15
  * LinearFilter,
@@ -23,9 +23,9 @@ import { LoaderBase } from './LoaderBase';
23
23
  *
24
24
  * const renderer = new WebGLRenderer()
25
25
  *
26
- * const loader = new JPEGRLoader(renderer)
26
+ * const loader = new HDRJPGLoader(renderer)
27
27
  *
28
- * const result = loader.load('gainmap.jpeg')
28
+ * const result = await loader.loadAsync('gainmap.jpeg')
29
29
  * // `result` can be used to populate a Texture
30
30
  *
31
31
  * const scene = new Scene()
@@ -44,12 +44,16 @@ import { LoaderBase } from './LoaderBase';
44
44
  * scene.background = result.toDataTexture()
45
45
  * scene.background.mapping = EquirectangularReflectionMapping
46
46
  * scene.background.minFilter = LinearFilter
47
-
47
+ *
48
+ * // result must be manually disposed
49
+ * // when you are done using it
50
+ * result.dispose()
48
51
  *
49
52
  */
50
53
  export declare class HDRJPGLoader extends LoaderBase<string> {
51
54
  /**
52
- * Loads a JPEGR Image
55
+ * Loads a JPEG containing gain map metadata
56
+ * Renders a normal SDR image if gainmap data is not found
53
57
  *
54
58
  * @param url An array in the form of [sdr.jpg, gainmap.jpg, metadata.json]
55
59
  * @param onLoad Load complete callback, will receive the result
@@ -4,6 +4,9 @@ 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
6
  private _renderer;
7
+ /**
8
+ * @private
9
+ */
7
10
  protected _internalLoadingManager: LoadingManager;
8
11
  /**
9
12
  *
@@ -17,12 +20,11 @@ export declare class LoaderBase<TUrl = string> extends Loader<QuadRenderer<typeo
17
20
  */
18
21
  protected prepareQuadRenderer(): QuadRenderer<1016, GainMapDecoderMaterial>;
19
22
  /**
20
- *
21
- * @private
22
- * @param quadRenderer
23
- * @param gainMapBuffer
24
- * @param sdrBuffer
25
- * @param metadata
26
- */
27
- protected render(quadRenderer: QuadRenderer<typeof HalfFloatType, GainMapDecoderMaterial>, gainMapBuffer: ArrayBuffer | string, sdrBuffer: ArrayBuffer | string, metadata: GainMapMetadata): Promise<void>;
23
+ * @private
24
+ * @param quadRenderer
25
+ * @param metadata
26
+ * @param sdrBuffer
27
+ * @param gainMapBuffer
28
+ */
29
+ protected render(quadRenderer: QuadRenderer<typeof HalfFloatType, GainMapDecoderMaterial>, metadata: GainMapMetadata, sdrBuffer: ArrayBuffer, gainMapBuffer?: ArrayBuffer): Promise<void>;
28
30
  }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * private function, async get image from blob
3
+ *
4
+ * @param blob
5
+ * @returns
6
+ */
7
+ export declare const getHTMLImageFromBlob: (blob: Blob) => Promise<HTMLImageElement>;
package/dist/decode.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.5
2
+ * @monogrid/gainmap-js v2.0.6
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
6
- import { Q as QuadRenderer } from './QuadRenderer-gqnZPNP-.js';
6
+ import { Q as QuadRenderer } from './QuadRenderer-QXcVmgNm.js';
7
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 */ `
@@ -196,6 +196,9 @@ class GainMapDecoderMaterial extends ShaderMaterial {
196
196
  * scene.add(mesh)
197
197
  * renderer.render(scene, new PerspectiveCamera())
198
198
  *
199
+ * // result must be manually disposed
200
+ * // when you are done using it
201
+ * result.dispose()
199
202
  *
200
203
  * @param params
201
204
  * @returns
@@ -225,12 +228,18 @@ const decode = (params) => {
225
228
  quadRenderer.render();
226
229
  }
227
230
  catch (e) {
228
- quadRenderer.dispose();
231
+ quadRenderer.disposeOnDemandRenderer();
229
232
  throw e;
230
233
  }
231
234
  return quadRenderer;
232
235
  };
233
236
 
237
+ class GainMapNotFoundError extends Error {
238
+ }
239
+
240
+ class XMPMetadataNotFoundError extends Error {
241
+ }
242
+
234
243
  const getAttribute = (description, name, defaultValue) => {
235
244
  var _a;
236
245
  let returnValue;
@@ -266,7 +275,7 @@ const getAttribute = (description, name, defaultValue) => {
266
275
  const extractXMP = (input) => {
267
276
  var _a, _b;
268
277
  let str;
269
- // support node test evnvironment
278
+ // support node test environment
270
279
  if (typeof TextDecoder !== 'undefined')
271
280
  str = new TextDecoder().decode(input);
272
281
  else
@@ -493,11 +502,11 @@ class MPFExtractor {
493
502
  const extractGainmapFromJPEG = async (jpegFile) => {
494
503
  const metadata = extractXMP(jpegFile);
495
504
  if (!metadata)
496
- throw new Error('Gain map XMP metadata not found');
505
+ throw new XMPMetadataNotFoundError('Gain map XMP metadata not found');
497
506
  const mpfExtractor = new MPFExtractor({ extractFII: true, extractNonFII: true });
498
507
  const images = await mpfExtractor.extract(jpegFile);
499
508
  if (images.length !== 2)
500
- throw new Error('Gain map recovery image not found');
509
+ throw new GainMapNotFoundError('Gain map recovery image not found');
501
510
  return {
502
511
  sdr: new Uint8Array(await images[0].arrayBuffer()),
503
512
  gainMap: new Uint8Array(await images[1].arrayBuffer()),
@@ -511,7 +520,7 @@ const extractGainmapFromJPEG = async (jpegFile) => {
511
520
  * @param blob
512
521
  * @returns
513
522
  */
514
- const getImage = (blob) => {
523
+ const getHTMLImageFromBlob = (blob) => {
515
524
  return new Promise((resolve, reject) => {
516
525
  const img = document.createElement('img');
517
526
  img.onload = () => { resolve(img); };
@@ -519,6 +528,7 @@ const getImage = (blob) => {
519
528
  img.src = URL.createObjectURL(blob);
520
529
  });
521
530
  };
531
+
522
532
  class LoaderBase extends Loader {
523
533
  /**
524
534
  *
@@ -551,23 +561,23 @@ class LoaderBase extends Loader {
551
561
  return new QuadRenderer(16, 16, HalfFloatType, LinearSRGBColorSpace, material, this._renderer);
552
562
  }
553
563
  /**
554
- *
555
- * @private
556
- * @param quadRenderer
557
- * @param gainMapBuffer
558
- * @param sdrBuffer
559
- * @param metadata
560
- */
561
- async render(quadRenderer, gainMapBuffer, sdrBuffer, metadata) {
562
- const gainMapBlob = new Blob([gainMapBuffer], { type: 'image/jpeg' });
564
+ * @private
565
+ * @param quadRenderer
566
+ * @param metadata
567
+ * @param sdrBuffer
568
+ * @param gainMapBuffer
569
+ */
570
+ async render(quadRenderer, metadata, sdrBuffer, gainMapBuffer) {
571
+ // this is optional, will render a black gain-map if not present
572
+ const gainMapBlob = gainMapBuffer ? new Blob([gainMapBuffer], { type: 'image/jpeg' }) : undefined;
563
573
  const sdrBlob = new Blob([sdrBuffer], { type: 'image/jpeg' });
564
574
  let sdrImage;
565
575
  let gainMapImage;
566
576
  let needsFlip = false;
567
577
  if (typeof createImageBitmap === 'undefined') {
568
578
  const res = await Promise.all([
569
- getImage(gainMapBlob),
570
- getImage(sdrBlob)
579
+ gainMapBlob ? getHTMLImageFromBlob(gainMapBlob) : Promise.resolve(undefined),
580
+ getHTMLImageFromBlob(sdrBlob)
571
581
  ]);
572
582
  gainMapImage = res[0];
573
583
  sdrImage = res[1];
@@ -575,13 +585,13 @@ class LoaderBase extends Loader {
575
585
  }
576
586
  else {
577
587
  const res = await Promise.all([
578
- createImageBitmap(gainMapBlob, { imageOrientation: 'flipY' }),
588
+ gainMapBlob ? createImageBitmap(gainMapBlob, { imageOrientation: 'flipY' }) : Promise.resolve(undefined),
579
589
  createImageBitmap(sdrBlob, { imageOrientation: 'flipY' })
580
590
  ]);
581
591
  gainMapImage = res[0];
582
592
  sdrImage = res[1];
583
593
  }
584
- const gainMap = new Texture(gainMapImage, UVMapping, ClampToEdgeWrapping, ClampToEdgeWrapping, LinearFilter, LinearMipMapLinearFilter, RGBAFormat, UnsignedByteType, 1, LinearSRGBColorSpace);
594
+ const gainMap = new Texture(gainMapImage || new ImageData(2, 2), UVMapping, ClampToEdgeWrapping, ClampToEdgeWrapping, LinearFilter, LinearMipMapLinearFilter, RGBAFormat, UnsignedByteType, 1, LinearSRGBColorSpace);
585
595
  gainMap.flipY = needsFlip;
586
596
  gainMap.needsUpdate = true;
587
597
  const sdr = new Texture(sdrImage, UVMapping, ClampToEdgeWrapping, ClampToEdgeWrapping, LinearFilter, LinearMipMapLinearFilter, RGBAFormat, UnsignedByteType, 1, SRGBColorSpace);
@@ -627,7 +637,7 @@ class LoaderBase extends Loader {
627
637
  *
628
638
  * const loader = new GainMapLoader(renderer)
629
639
  *
630
- * const result = loader.load(['sdr.jpeg', 'gainmap.jpeg', 'metadata.json'])
640
+ * const result = await loader.loadAsync(['sdr.jpeg', 'gainmap.jpeg', 'metadata.json'])
631
641
  * // `result` can be used to populate a Texture
632
642
  *
633
643
  * const scene = new Scene()
@@ -647,6 +657,10 @@ class LoaderBase extends Loader {
647
657
  * scene.background.mapping = EquirectangularReflectionMapping
648
658
  * scene.background.minFilter = LinearFilter
649
659
  *
660
+ * // result must be manually disposed
661
+ * // when you are done using it
662
+ * result.dispose()
663
+ *
650
664
  */
651
665
  class GainMapLoader extends LoaderBase {
652
666
  /**
@@ -670,13 +684,13 @@ class GainMapLoader extends LoaderBase {
670
684
  let metadata;
671
685
  const loadCheck = async () => {
672
686
  if (sdr && gainMap && metadata) {
673
- await this.render(quadRenderer, gainMap, sdr, metadata);
687
+ await this.render(quadRenderer, metadata, sdr, gainMap);
674
688
  if (typeof onLoad === 'function')
675
689
  onLoad(quadRenderer);
676
690
  this.manager.itemEnd(sdrUrl);
677
691
  this.manager.itemEnd(gainMapUrl);
678
692
  this.manager.itemEnd(metadataUrl);
679
- quadRenderer.dispose();
693
+ quadRenderer.disposeOnDemandRenderer();
680
694
  }
681
695
  };
682
696
  let sdrLengthComputable = true;
@@ -772,7 +786,7 @@ class GainMapLoader extends LoaderBase {
772
786
  * @group Loaders
773
787
  *
774
788
  * @example
775
- * import { JPEGRLoader } from '@monogrid/gainmap-js'
789
+ * import { HDRJPGLoader } from '@monogrid/gainmap-js'
776
790
  * import {
777
791
  * EquirectangularReflectionMapping,
778
792
  * LinearFilter,
@@ -786,9 +800,9 @@ class GainMapLoader extends LoaderBase {
786
800
  *
787
801
  * const renderer = new WebGLRenderer()
788
802
  *
789
- * const loader = new JPEGRLoader(renderer)
803
+ * const loader = new HDRJPGLoader(renderer)
790
804
  *
791
- * const result = loader.load('gainmap.jpeg')
805
+ * const result = await loader.loadAsync('gainmap.jpeg')
792
806
  * // `result` can be used to populate a Texture
793
807
  *
794
808
  * const scene = new Scene()
@@ -807,12 +821,16 @@ class GainMapLoader extends LoaderBase {
807
821
  * scene.background = result.toDataTexture()
808
822
  * scene.background.mapping = EquirectangularReflectionMapping
809
823
  * scene.background.minFilter = LinearFilter
810
-
824
+ *
825
+ * // result must be manually disposed
826
+ * // when you are done using it
827
+ * result.dispose()
811
828
  *
812
829
  */
813
830
  class HDRJPGLoader extends LoaderBase {
814
831
  /**
815
- * Loads a JPEGR Image
832
+ * Loads a JPEG containing gain map metadata
833
+ * Renders a normal SDR image if gainmap data is not found
816
834
  *
817
835
  * @param url An array in the form of [sdr.jpg, gainmap.jpg, metadata.json]
818
836
  * @param onLoad Load complete callback, will receive the result
@@ -830,13 +848,42 @@ class HDRJPGLoader extends LoaderBase {
830
848
  this.manager.itemStart(url);
831
849
  loader.load(url, async (jpeg) => {
832
850
  if (typeof jpeg === 'string')
833
- throw new Error('Invalid buffer');
834
- const { gainMap: gainMapJPEG, sdr: sdrJPEG, metadata } = await extractGainmapFromJPEG(new Uint8Array(jpeg));
835
- await this.render(quadRenderer, gainMapJPEG, sdrJPEG, metadata);
851
+ throw new Error('Invalid buffer, received [string], was expecting [ArrayBuffer]');
852
+ const jpegBuffer = new Uint8Array(jpeg);
853
+ let sdrJPEG;
854
+ let gainMapJPEG;
855
+ let metadata;
856
+ try {
857
+ const extractionResult = await extractGainmapFromJPEG(jpegBuffer);
858
+ // gain map is successfully reconstructed
859
+ sdrJPEG = extractionResult.sdr;
860
+ gainMapJPEG = extractionResult.gainMap;
861
+ metadata = extractionResult.metadata;
862
+ }
863
+ catch (e) {
864
+ // render the SDR version if this is not a gainmap
865
+ if (e instanceof XMPMetadataNotFoundError || e instanceof GainMapNotFoundError) {
866
+ console.warn(`Failure to reconstruct an HDR image from ${url}: Gain map metadata not found in the file, HDRJPGLoader will render the SDR jpeg`);
867
+ metadata = {
868
+ gainMapMin: [0, 0, 0],
869
+ gainMapMax: [1, 1, 1],
870
+ gamma: [1, 1, 1],
871
+ hdrCapacityMin: 0,
872
+ hdrCapacityMax: 1,
873
+ offsetHdr: [0, 0, 0],
874
+ offsetSdr: [0, 0, 0]
875
+ };
876
+ sdrJPEG = jpegBuffer;
877
+ }
878
+ else {
879
+ throw e;
880
+ }
881
+ }
882
+ await this.render(quadRenderer, metadata, sdrJPEG, gainMapJPEG);
836
883
  if (typeof onLoad === 'function')
837
884
  onLoad(quadRenderer);
838
885
  this.manager.itemEnd(url);
839
- quadRenderer.dispose();
886
+ quadRenderer.disposeOnDemandRenderer();
840
887
  }, onProgress, (error) => {
841
888
  this.manager.itemError(url);
842
889
  if (typeof onError === 'function')
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.5
2
+ * @monogrid/gainmap-js v2.0.6
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
@@ -185,19 +185,75 @@
185
185
  this._renderer.readRenderTargetPixels(this._renderTarget, 0, 0, this._width, this._height, out);
186
186
  return out;
187
187
  }
188
+ /**
189
+ * Performs a readPixel operation in the renderTarget
190
+ * and returns a DataTexture containing the read data
191
+ *
192
+ * @returns
193
+ */
188
194
  toDataTexture() {
189
195
  return new three.DataTexture(this.toArray(), this.width, this.height, three.RGBAFormat, this._type, three.UVMapping, three.RepeatWrapping, three.RepeatWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, 1, three.LinearSRGBColorSpace);
190
196
  }
191
197
  /**
192
198
  * If using a disposable renderer, it will dispose it.
193
199
  */
194
- dispose() {
200
+ disposeOnDemandRenderer() {
195
201
  this._renderer.setRenderTarget(null);
196
202
  if (this._rendererIsDisposable) {
197
203
  this._renderer.dispose();
198
204
  this._renderer.forceContextLoss();
199
205
  }
200
206
  }
207
+ /**
208
+ * Will dispose of **all** assets used by this renderer.
209
+ *
210
+ *
211
+ * @param disposeRenderTarget will dispose of the renderTarget which will not be usable later
212
+ * set this to true if you passed the `renderTarget.texture` to a `PMREMGenerator`
213
+ * or are otherwise done with it.
214
+ *
215
+ * @example
216
+ * ```js
217
+ * const loader = new HDRJPGLoader(renderer)
218
+ * const result = await loader.loadAsync('gainmap.jpeg')
219
+ * const mesh = new Mesh(geometry, new MeshBasicMaterial({ map: result.renderTarget.texture }) )
220
+ * // DO NOT dispose the renderTarget here,
221
+ * // it is used directly in the material
222
+ * result.dispose()
223
+ * ```
224
+ *
225
+ * @example
226
+ * ```js
227
+ * const loader = new HDRJPGLoader(renderer)
228
+ * const pmremGenerator = new PMREMGenerator( renderer );
229
+ * const result = await loader.loadAsync('gainmap.jpeg')
230
+ * const envMap = pmremGenerator.fromEquirectangular(result.renderTarget.texture)
231
+ * const mesh = new Mesh(geometry, new MeshStandardMaterial({ envMap }) )
232
+ * // renderTarget can be disposed here
233
+ * // because it was used to generate a PMREM texture
234
+ * result.dispose(true)
235
+ * ```
236
+ */
237
+ dispose(disposeRenderTarget) {
238
+ this.disposeOnDemandRenderer();
239
+ if (disposeRenderTarget) {
240
+ this.renderTarget.dispose();
241
+ }
242
+ // dispose shader material texture uniforms
243
+ if (this.material instanceof three.ShaderMaterial) {
244
+ Object.values(this.material.uniforms).forEach(v => {
245
+ if (v.value instanceof three.Texture)
246
+ v.value.dispose();
247
+ });
248
+ }
249
+ // dispose other material properties
250
+ Object.values(this.material).forEach(value => {
251
+ if (value instanceof three.Texture)
252
+ value.dispose();
253
+ });
254
+ this.material.dispose();
255
+ this._quad.geometry.dispose();
256
+ }
201
257
  /**
202
258
  * Width of the texture
203
259
  */
@@ -429,6 +485,9 @@ void main() {
429
485
  * scene.add(mesh)
430
486
  * renderer.render(scene, new PerspectiveCamera())
431
487
  *
488
+ * // result must be manually disposed
489
+ * // when you are done using it
490
+ * result.dispose()
432
491
  *
433
492
  * @param params
434
493
  * @returns
@@ -458,12 +517,18 @@ void main() {
458
517
  quadRenderer.render();
459
518
  }
460
519
  catch (e) {
461
- quadRenderer.dispose();
520
+ quadRenderer.disposeOnDemandRenderer();
462
521
  throw e;
463
522
  }
464
523
  return quadRenderer;
465
524
  };
466
525
 
526
+ class GainMapNotFoundError extends Error {
527
+ }
528
+
529
+ class XMPMetadataNotFoundError extends Error {
530
+ }
531
+
467
532
  const getAttribute = (description, name, defaultValue) => {
468
533
  var _a;
469
534
  let returnValue;
@@ -499,7 +564,7 @@ void main() {
499
564
  const extractXMP = (input) => {
500
565
  var _a, _b;
501
566
  let str;
502
- // support node test evnvironment
567
+ // support node test environment
503
568
  if (typeof TextDecoder !== 'undefined')
504
569
  str = new TextDecoder().decode(input);
505
570
  else
@@ -726,11 +791,11 @@ void main() {
726
791
  const extractGainmapFromJPEG = async (jpegFile) => {
727
792
  const metadata = extractXMP(jpegFile);
728
793
  if (!metadata)
729
- throw new Error('Gain map XMP metadata not found');
794
+ throw new XMPMetadataNotFoundError('Gain map XMP metadata not found');
730
795
  const mpfExtractor = new MPFExtractor({ extractFII: true, extractNonFII: true });
731
796
  const images = await mpfExtractor.extract(jpegFile);
732
797
  if (images.length !== 2)
733
- throw new Error('Gain map recovery image not found');
798
+ throw new GainMapNotFoundError('Gain map recovery image not found');
734
799
  return {
735
800
  sdr: new Uint8Array(await images[0].arrayBuffer()),
736
801
  gainMap: new Uint8Array(await images[1].arrayBuffer()),
@@ -744,7 +809,7 @@ void main() {
744
809
  * @param blob
745
810
  * @returns
746
811
  */
747
- const getImage = (blob) => {
812
+ const getHTMLImageFromBlob = (blob) => {
748
813
  return new Promise((resolve, reject) => {
749
814
  const img = document.createElement('img');
750
815
  img.onload = () => { resolve(img); };
@@ -752,6 +817,7 @@ void main() {
752
817
  img.src = URL.createObjectURL(blob);
753
818
  });
754
819
  };
820
+
755
821
  class LoaderBase extends three.Loader {
756
822
  /**
757
823
  *
@@ -784,23 +850,23 @@ void main() {
784
850
  return new QuadRenderer(16, 16, three.HalfFloatType, three.LinearSRGBColorSpace, material, this._renderer);
785
851
  }
786
852
  /**
787
- *
788
- * @private
789
- * @param quadRenderer
790
- * @param gainMapBuffer
791
- * @param sdrBuffer
792
- * @param metadata
793
- */
794
- async render(quadRenderer, gainMapBuffer, sdrBuffer, metadata) {
795
- const gainMapBlob = new Blob([gainMapBuffer], { type: 'image/jpeg' });
853
+ * @private
854
+ * @param quadRenderer
855
+ * @param metadata
856
+ * @param sdrBuffer
857
+ * @param gainMapBuffer
858
+ */
859
+ async render(quadRenderer, metadata, sdrBuffer, gainMapBuffer) {
860
+ // this is optional, will render a black gain-map if not present
861
+ const gainMapBlob = gainMapBuffer ? new Blob([gainMapBuffer], { type: 'image/jpeg' }) : undefined;
796
862
  const sdrBlob = new Blob([sdrBuffer], { type: 'image/jpeg' });
797
863
  let sdrImage;
798
864
  let gainMapImage;
799
865
  let needsFlip = false;
800
866
  if (typeof createImageBitmap === 'undefined') {
801
867
  const res = await Promise.all([
802
- getImage(gainMapBlob),
803
- getImage(sdrBlob)
868
+ gainMapBlob ? getHTMLImageFromBlob(gainMapBlob) : Promise.resolve(undefined),
869
+ getHTMLImageFromBlob(sdrBlob)
804
870
  ]);
805
871
  gainMapImage = res[0];
806
872
  sdrImage = res[1];
@@ -808,13 +874,13 @@ void main() {
808
874
  }
809
875
  else {
810
876
  const res = await Promise.all([
811
- createImageBitmap(gainMapBlob, { imageOrientation: 'flipY' }),
877
+ gainMapBlob ? createImageBitmap(gainMapBlob, { imageOrientation: 'flipY' }) : Promise.resolve(undefined),
812
878
  createImageBitmap(sdrBlob, { imageOrientation: 'flipY' })
813
879
  ]);
814
880
  gainMapImage = res[0];
815
881
  sdrImage = res[1];
816
882
  }
817
- const gainMap = new three.Texture(gainMapImage, three.UVMapping, three.ClampToEdgeWrapping, three.ClampToEdgeWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, three.RGBAFormat, three.UnsignedByteType, 1, three.LinearSRGBColorSpace);
883
+ const gainMap = new three.Texture(gainMapImage || new ImageData(2, 2), three.UVMapping, three.ClampToEdgeWrapping, three.ClampToEdgeWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, three.RGBAFormat, three.UnsignedByteType, 1, three.LinearSRGBColorSpace);
818
884
  gainMap.flipY = needsFlip;
819
885
  gainMap.needsUpdate = true;
820
886
  const sdr = new three.Texture(sdrImage, three.UVMapping, three.ClampToEdgeWrapping, three.ClampToEdgeWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, three.RGBAFormat, three.UnsignedByteType, 1, three.SRGBColorSpace);
@@ -860,7 +926,7 @@ void main() {
860
926
  *
861
927
  * const loader = new GainMapLoader(renderer)
862
928
  *
863
- * const result = loader.load(['sdr.jpeg', 'gainmap.jpeg', 'metadata.json'])
929
+ * const result = await loader.loadAsync(['sdr.jpeg', 'gainmap.jpeg', 'metadata.json'])
864
930
  * // `result` can be used to populate a Texture
865
931
  *
866
932
  * const scene = new Scene()
@@ -880,6 +946,10 @@ void main() {
880
946
  * scene.background.mapping = EquirectangularReflectionMapping
881
947
  * scene.background.minFilter = LinearFilter
882
948
  *
949
+ * // result must be manually disposed
950
+ * // when you are done using it
951
+ * result.dispose()
952
+ *
883
953
  */
884
954
  class GainMapLoader extends LoaderBase {
885
955
  /**
@@ -903,13 +973,13 @@ void main() {
903
973
  let metadata;
904
974
  const loadCheck = async () => {
905
975
  if (sdr && gainMap && metadata) {
906
- await this.render(quadRenderer, gainMap, sdr, metadata);
976
+ await this.render(quadRenderer, metadata, sdr, gainMap);
907
977
  if (typeof onLoad === 'function')
908
978
  onLoad(quadRenderer);
909
979
  this.manager.itemEnd(sdrUrl);
910
980
  this.manager.itemEnd(gainMapUrl);
911
981
  this.manager.itemEnd(metadataUrl);
912
- quadRenderer.dispose();
982
+ quadRenderer.disposeOnDemandRenderer();
913
983
  }
914
984
  };
915
985
  let sdrLengthComputable = true;
@@ -1005,7 +1075,7 @@ void main() {
1005
1075
  * @group Loaders
1006
1076
  *
1007
1077
  * @example
1008
- * import { JPEGRLoader } from '@monogrid/gainmap-js'
1078
+ * import { HDRJPGLoader } from '@monogrid/gainmap-js'
1009
1079
  * import {
1010
1080
  * EquirectangularReflectionMapping,
1011
1081
  * LinearFilter,
@@ -1019,9 +1089,9 @@ void main() {
1019
1089
  *
1020
1090
  * const renderer = new WebGLRenderer()
1021
1091
  *
1022
- * const loader = new JPEGRLoader(renderer)
1092
+ * const loader = new HDRJPGLoader(renderer)
1023
1093
  *
1024
- * const result = loader.load('gainmap.jpeg')
1094
+ * const result = await loader.loadAsync('gainmap.jpeg')
1025
1095
  * // `result` can be used to populate a Texture
1026
1096
  *
1027
1097
  * const scene = new Scene()
@@ -1040,12 +1110,16 @@ void main() {
1040
1110
  * scene.background = result.toDataTexture()
1041
1111
  * scene.background.mapping = EquirectangularReflectionMapping
1042
1112
  * scene.background.minFilter = LinearFilter
1043
-
1113
+ *
1114
+ * // result must be manually disposed
1115
+ * // when you are done using it
1116
+ * result.dispose()
1044
1117
  *
1045
1118
  */
1046
1119
  class HDRJPGLoader extends LoaderBase {
1047
1120
  /**
1048
- * Loads a JPEGR Image
1121
+ * Loads a JPEG containing gain map metadata
1122
+ * Renders a normal SDR image if gainmap data is not found
1049
1123
  *
1050
1124
  * @param url An array in the form of [sdr.jpg, gainmap.jpg, metadata.json]
1051
1125
  * @param onLoad Load complete callback, will receive the result
@@ -1063,13 +1137,42 @@ void main() {
1063
1137
  this.manager.itemStart(url);
1064
1138
  loader.load(url, async (jpeg) => {
1065
1139
  if (typeof jpeg === 'string')
1066
- throw new Error('Invalid buffer');
1067
- const { gainMap: gainMapJPEG, sdr: sdrJPEG, metadata } = await extractGainmapFromJPEG(new Uint8Array(jpeg));
1068
- await this.render(quadRenderer, gainMapJPEG, sdrJPEG, metadata);
1140
+ throw new Error('Invalid buffer, received [string], was expecting [ArrayBuffer]');
1141
+ const jpegBuffer = new Uint8Array(jpeg);
1142
+ let sdrJPEG;
1143
+ let gainMapJPEG;
1144
+ let metadata;
1145
+ try {
1146
+ const extractionResult = await extractGainmapFromJPEG(jpegBuffer);
1147
+ // gain map is successfully reconstructed
1148
+ sdrJPEG = extractionResult.sdr;
1149
+ gainMapJPEG = extractionResult.gainMap;
1150
+ metadata = extractionResult.metadata;
1151
+ }
1152
+ catch (e) {
1153
+ // render the SDR version if this is not a gainmap
1154
+ if (e instanceof XMPMetadataNotFoundError || e instanceof GainMapNotFoundError) {
1155
+ console.warn(`Failure to reconstruct an HDR image from ${url}: Gain map metadata not found in the file, HDRJPGLoader will render the SDR jpeg`);
1156
+ metadata = {
1157
+ gainMapMin: [0, 0, 0],
1158
+ gainMapMax: [1, 1, 1],
1159
+ gamma: [1, 1, 1],
1160
+ hdrCapacityMin: 0,
1161
+ hdrCapacityMax: 1,
1162
+ offsetHdr: [0, 0, 0],
1163
+ offsetSdr: [0, 0, 0]
1164
+ };
1165
+ sdrJPEG = jpegBuffer;
1166
+ }
1167
+ else {
1168
+ throw e;
1169
+ }
1170
+ }
1171
+ await this.render(quadRenderer, metadata, sdrJPEG, gainMapJPEG);
1069
1172
  if (typeof onLoad === 'function')
1070
1173
  onLoad(quadRenderer);
1071
1174
  this.manager.itemEnd(url);
1072
- quadRenderer.dispose();
1175
+ quadRenderer.disposeOnDemandRenderer();
1073
1176
  }, onProgress, (error) => {
1074
1177
  this.manager.itemError(url);
1075
1178
  if (typeof onError === 'function')
@@ -43,7 +43,10 @@ import { EncodingParametersBase } from './types';
43
43
  * encodingResult.gainMap.material.gamma = [1.1, 1.1, 1.1]
44
44
  * encodingResult.gainMap.render()
45
45
  *
46
- * // must be manually disposed
46
+ * // do something with encodingResult.gainMap.toArray()
47
+ * // and encodingResult.sdr.toArray()
48
+ *
49
+ * // renderers must be manually disposed
47
50
  * encodingResult.sdr.dispose()
48
51
  * encodingResult.gainMap.dispose()
49
52
  *
package/dist/encode.js CHANGED
@@ -1,11 +1,11 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.5
2
+ * @monogrid/gainmap-js v2.0.6
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
6
- import { c as compress } from './compress-_4jEQonS.js';
6
+ import { c as compress } from './compress-MvOX-rlz.js';
7
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-gqnZPNP-.js';
8
+ import { Q as QuadRenderer } from './QuadRenderer-QXcVmgNm.js';
9
9
 
10
10
  /**
11
11
  * Utility function to obtain a `DataTexture` from various input formats
@@ -200,7 +200,7 @@ const getGainMap = (params) => {
200
200
  quadRenderer.render();
201
201
  }
202
202
  catch (e) {
203
- quadRenderer.dispose();
203
+ quadRenderer.disposeOnDemandRenderer();
204
204
  throw e;
205
205
  }
206
206
  return quadRenderer;
@@ -427,7 +427,7 @@ const getSDRRendition = (hdrTexture, renderer, toneMapping) => {
427
427
  quadRenderer.render();
428
428
  }
429
429
  catch (e) {
430
- quadRenderer.dispose();
430
+ quadRenderer.disposeOnDemandRenderer();
431
431
  throw e;
432
432
  }
433
433
  return quadRenderer;
@@ -476,7 +476,10 @@ const getSDRRendition = (hdrTexture, renderer, toneMapping) => {
476
476
  * encodingResult.gainMap.material.gamma = [1.1, 1.1, 1.1]
477
477
  * encodingResult.gainMap.render()
478
478
  *
479
- * // must be manually disposed
479
+ * // do something with encodingResult.gainMap.toArray()
480
+ * // and encodingResult.sdr.toArray()
481
+ *
482
+ * // renderers must be manually disposed
480
483
  * encodingResult.sdr.dispose()
481
484
  * encodingResult.gainMap.dispose()
482
485
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.5
2
+ * @monogrid/gainmap-js v2.0.6
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
@@ -290,19 +290,75 @@
290
290
  this._renderer.readRenderTargetPixels(this._renderTarget, 0, 0, this._width, this._height, out);
291
291
  return out;
292
292
  }
293
+ /**
294
+ * Performs a readPixel operation in the renderTarget
295
+ * and returns a DataTexture containing the read data
296
+ *
297
+ * @returns
298
+ */
293
299
  toDataTexture() {
294
300
  return new three.DataTexture(this.toArray(), this.width, this.height, three.RGBAFormat, this._type, three.UVMapping, three.RepeatWrapping, three.RepeatWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, 1, three.LinearSRGBColorSpace);
295
301
  }
296
302
  /**
297
303
  * If using a disposable renderer, it will dispose it.
298
304
  */
299
- dispose() {
305
+ disposeOnDemandRenderer() {
300
306
  this._renderer.setRenderTarget(null);
301
307
  if (this._rendererIsDisposable) {
302
308
  this._renderer.dispose();
303
309
  this._renderer.forceContextLoss();
304
310
  }
305
311
  }
312
+ /**
313
+ * Will dispose of **all** assets used by this renderer.
314
+ *
315
+ *
316
+ * @param disposeRenderTarget will dispose of the renderTarget which will not be usable later
317
+ * set this to true if you passed the `renderTarget.texture` to a `PMREMGenerator`
318
+ * or are otherwise done with it.
319
+ *
320
+ * @example
321
+ * ```js
322
+ * const loader = new HDRJPGLoader(renderer)
323
+ * const result = await loader.loadAsync('gainmap.jpeg')
324
+ * const mesh = new Mesh(geometry, new MeshBasicMaterial({ map: result.renderTarget.texture }) )
325
+ * // DO NOT dispose the renderTarget here,
326
+ * // it is used directly in the material
327
+ * result.dispose()
328
+ * ```
329
+ *
330
+ * @example
331
+ * ```js
332
+ * const loader = new HDRJPGLoader(renderer)
333
+ * const pmremGenerator = new PMREMGenerator( renderer );
334
+ * const result = await loader.loadAsync('gainmap.jpeg')
335
+ * const envMap = pmremGenerator.fromEquirectangular(result.renderTarget.texture)
336
+ * const mesh = new Mesh(geometry, new MeshStandardMaterial({ envMap }) )
337
+ * // renderTarget can be disposed here
338
+ * // because it was used to generate a PMREM texture
339
+ * result.dispose(true)
340
+ * ```
341
+ */
342
+ dispose(disposeRenderTarget) {
343
+ this.disposeOnDemandRenderer();
344
+ if (disposeRenderTarget) {
345
+ this.renderTarget.dispose();
346
+ }
347
+ // dispose shader material texture uniforms
348
+ if (this.material instanceof three.ShaderMaterial) {
349
+ Object.values(this.material.uniforms).forEach(v => {
350
+ if (v.value instanceof three.Texture)
351
+ v.value.dispose();
352
+ });
353
+ }
354
+ // dispose other material properties
355
+ Object.values(this.material).forEach(value => {
356
+ if (value instanceof three.Texture)
357
+ value.dispose();
358
+ });
359
+ this.material.dispose();
360
+ this._quad.geometry.dispose();
361
+ }
306
362
  /**
307
363
  * Width of the texture
308
364
  */
@@ -508,7 +564,7 @@ void main() {
508
564
  quadRenderer.render();
509
565
  }
510
566
  catch (e) {
511
- quadRenderer.dispose();
567
+ quadRenderer.disposeOnDemandRenderer();
512
568
  throw e;
513
569
  }
514
570
  return quadRenderer;
@@ -735,7 +791,7 @@ void main() {
735
791
  quadRenderer.render();
736
792
  }
737
793
  catch (e) {
738
- quadRenderer.dispose();
794
+ quadRenderer.disposeOnDemandRenderer();
739
795
  throw e;
740
796
  }
741
797
  return quadRenderer;
@@ -784,7 +840,10 @@ void main() {
784
840
  * encodingResult.gainMap.material.gamma = [1.1, 1.1, 1.1]
785
841
  * encodingResult.gainMap.render()
786
842
  *
787
- * // must be manually disposed
843
+ * // do something with encodingResult.gainMap.toArray()
844
+ * // and encodingResult.sdr.toArray()
845
+ *
846
+ * // renderers must be manually disposed
788
847
  * encodingResult.sdr.dispose()
789
848
  * encodingResult.gainMap.dispose()
790
849
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.5
2
+ * @monogrid/gainmap-js v2.0.6
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.5
2
+ * @monogrid/gainmap-js v2.0.6
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.5
2
+ * @monogrid/gainmap-js v2.0.6
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
6
- import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers-iRbo2TdN.js';
6
+ import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers-ftl_lJMx.js';
7
7
 
8
8
  var lib$1;
9
9
  var hasRequiredLib$1;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.5
2
+ * @monogrid/gainmap-js v2.0.6
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
package/dist/worker.js CHANGED
@@ -1,10 +1,10 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.5
2
+ * @monogrid/gainmap-js v2.0.6
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
6
- import { g as getDefaultExportFromCjs } from './_commonjsHelpers-iRbo2TdN.js';
7
- import { c as compress } from './compress-_4jEQonS.js';
6
+ import { g as getDefaultExportFromCjs } from './_commonjsHelpers-ftl_lJMx.js';
7
+ import { c as compress } from './compress-MvOX-rlz.js';
8
8
 
9
9
  var isPromise$2 = {exports: {}};
10
10
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.5
2
+ * @monogrid/gainmap-js v2.0.6
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monogrid/gainmap-js",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "description": "A Javascript (TypeScript) Port of Adobe Gainmap Technology for storing HDR Images using an SDR Image + a gain map",
5
5
  "homepage": "https://github.com/MONOGRID/gainmap-js#readme",
6
6
  "repository": {