@monogrid/gainmap-js 2.0.5 → 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,19 @@
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
+
9
+ ## [2.0.6](https://github.com/MONOGRID/gainmap-js/compare/v2.0.5...v2.0.6) (2023-11-20)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * **decode:** changes usage of `NoColorSpace` to `LinearSRGBColorSpace` ([587dc03](https://github.com/MONOGRID/gainmap-js/commit/587dc0377876533b18b506516d8757e04e830c62))
15
+ * **loaders:** fixes LoadingManager `onLoad` actually waiting for gainmaps to be generated ([77170f5](https://github.com/MONOGRID/gainmap-js/commit/77170f57c5ad277d3e97d1236ab93a29106c4a99))
16
+
1
17
  ## [2.0.5](https://github.com/MONOGRID/gainmap-js/compare/v2.0.4...v2.0.5) (2023-11-16)
2
18
 
3
19
 
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.4
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, 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, ShaderMaterial, Texture, 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,
@@ -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
- return new DataTexture(this.toArray(), this.width, this.height, RGBAFormat, this._type, UVMapping, RepeatWrapping, RepeatWrapping, LinearFilter, LinearMipMapLinearFilter, 1, NoColorSpace);
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.4
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.4
2
+ * @monogrid/gainmap-js v2.0.6
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
  };
@@ -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
@@ -3,7 +3,11 @@ 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
+ /**
8
+ * @private
9
+ */
10
+ protected _internalLoadingManager: LoadingManager;
7
11
  /**
8
12
  *
9
13
  * @param renderer
@@ -16,12 +20,11 @@ export declare class LoaderBase<TUrl = string> extends Loader<QuadRenderer<typeo
16
20
  */
17
21
  protected prepareQuadRenderer(): QuadRenderer<1016, GainMapDecoderMaterial>;
18
22
  /**
19
- *
20
- * @private
21
- * @param quadRenderer
22
- * @param gainMapBuffer
23
- * @param sdrBuffer
24
- * @param metadata
25
- */
26
- 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>;
27
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>;