@monogrid/gainmap-js 1.0.2 → 1.1.1

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 (54) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +103 -19
  3. package/dist/LoaderBase-eee19701.js +382 -0
  4. package/dist/_commonjsHelpers-1789f0cf.js +1 -1
  5. package/dist/compress-a4b59cab.js +1 -1
  6. package/dist/decode.d.ts +25 -6
  7. package/dist/encode-utils/get-sdr-rendition.d.ts +2 -2
  8. package/dist/encode.d.ts +3 -3
  9. package/dist/index.d.ts +1 -1
  10. package/dist/index.js +189 -258
  11. package/dist/index.umd.js +331 -27
  12. package/dist/libultrahdr/decode-jpeg-metadata.d.ts +31 -0
  13. package/dist/libultrahdr/encode-jpeg-metadata.d.ts +83 -0
  14. package/dist/libultrahdr/library.d.ts +9 -0
  15. package/dist/libultrahdr-esm.wasm +0 -0
  16. package/dist/libultrahdr.d.ts +4 -128
  17. package/dist/libultrahdr.js +322 -278
  18. package/dist/libultrahdr.umd.js +687 -271
  19. package/dist/loaders/GainMapLoader.d.ts +68 -0
  20. package/dist/loaders/JPEGRLoader.d.ts +60 -0
  21. package/dist/loaders/LoaderBase.d.ts +27 -0
  22. package/dist/materials/GainMapDecoderMaterial.d.ts +44 -1
  23. package/dist/materials/GainMapEncoderMaterial.d.ts +29 -2
  24. package/dist/types.d.ts +26 -6
  25. package/dist/utils/QuadRenderer.d.ts +8 -1
  26. package/dist/worker-interface.js +1 -1
  27. package/dist/worker-interface.umd.js +1 -1
  28. package/dist/worker-types.d.ts +1 -1
  29. package/dist/worker.js +1 -1
  30. package/dist/worker.umd.js +1 -1
  31. package/libultrahdr-wasm/build/libultrahdr-debug.js +156 -182
  32. package/libultrahdr-wasm/build/libultrahdr-debug.wasm +0 -0
  33. package/libultrahdr-wasm/build/libultrahdr-esm.js +153 -182
  34. package/libultrahdr-wasm/build/libultrahdr-esm.wasm +0 -0
  35. package/libultrahdr-wasm/build/libultrahdr.js +151 -180
  36. package/libultrahdr-wasm/build/libultrahdr.wasm +0 -0
  37. package/package.json +1 -1
  38. package/examples/README.md +0 -3
  39. package/examples/compress.ts +0 -43
  40. package/examples/decode-from-jpeg.ts +0 -40
  41. package/examples/decode-from-separate-data.ts +0 -41
  42. package/examples/decode-to-datatexture.ts +0 -65
  43. package/examples/encode-and-compress.ts +0 -29
  44. package/examples/encode-jpeg-metadata.ts +0 -57
  45. package/examples/encode.ts +0 -28
  46. package/examples/globals.d.ts +0 -6
  47. package/examples/worker.ts +0 -41
  48. package/reports/eslint-examples.json +0 -1
  49. package/reports/eslint-src.json +0 -1
  50. package/reports/eslint-tests.json +0 -1
  51. package/reports/junit.xml +0 -35
  52. package/reports/typecheck-examples.log +0 -0
  53. package/reports/typecheck-tests.log +0 -0
  54. package/reports/typecheck.log +0 -0
package/dist/index.js CHANGED
@@ -1,247 +1,14 @@
1
1
  /**
2
- * @monogrid/gainmap-js v1.0.1
2
+ * @monogrid/gainmap-js v1.1.0
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
6
- import { ShaderMaterial, Vector3, NoBlending, Scene, OrthographicCamera, Mesh, PlaneGeometry, WebGLRenderTarget, RGBAFormat, LinearFilter, LinearMipMapLinearFilter, RepeatWrapping, WebGLRenderer, FloatType, IntType, ShortType, ByteType, UnsignedIntType, HalfFloatType, UnsignedByteType, SRGBColorSpace, NoColorSpace, DataTexture, UVMapping, ACESFilmicToneMapping, LinearToneMapping, CineonToneMapping, ReinhardToneMapping, Vector2, NearestFilter, ClampToEdgeWrapping, DataUtils } from 'three';
6
+ import { SRGBColorSpace, NoColorSpace, HalfFloatType, ShaderMaterial, Vector3, NoBlending, DataTexture, RGBAFormat, UVMapping, RepeatWrapping, LinearFilter, UnsignedByteType, ACESFilmicToneMapping, LinearToneMapping, CineonToneMapping, ReinhardToneMapping, Vector2, WebGLRenderTarget, NearestFilter, ClampToEdgeWrapping, FloatType, DataUtils, FileLoader } from 'three';
7
+ import { G as GainMapDecoderMaterial, Q as QuadRenderer, L as LoaderBase } from './LoaderBase-eee19701.js';
8
+ export { G as GainMapDecoderMaterial, Q as QuadRenderer } from './LoaderBase-eee19701.js';
7
9
  import { c as compress } from './compress-a4b59cab.js';
8
10
  export { c as compress } from './compress-a4b59cab.js';
9
11
 
10
- const vertexShader$3 = /* glsl */ `
11
- varying vec2 vUv;
12
-
13
- void main() {
14
- vUv = uv;
15
- gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
16
- }
17
- `;
18
- const fragmentShader$3 = /* glsl */ `
19
- uniform sampler2D sdr;
20
- uniform sampler2D gainMap;
21
- uniform vec3 gamma;
22
- uniform vec3 offsetHdr;
23
- uniform vec3 offsetSdr;
24
- uniform vec3 gainMapMin;
25
- uniform vec3 gainMapMax;
26
- uniform float weightFactor;
27
-
28
- varying vec2 vUv;
29
-
30
- void main() {
31
- vec3 rgb = texture2D(sdr, vUv).rgb;
32
- vec3 recovery = texture2D(gainMap, vUv).rgb;
33
- vec3 logRecovery = pow(recovery, gamma);
34
- vec3 logBoost = gainMapMin * (1.0 - logRecovery) + gainMapMax * logRecovery;
35
- vec3 hdrColor = (rgb + offsetSdr) * exp2(logBoost * weightFactor) - offsetHdr;
36
- gl_FragColor = vec4(hdrColor, 1.0);
37
- }
38
- `;
39
- /**
40
- * A Material which is able to decode the Gainmap into a full HDR Representation
41
- *
42
- * @category Materials
43
- * @group Materials
44
- */
45
- class GainMapDecoderMaterial extends ShaderMaterial {
46
- /**
47
- *
48
- * @param params
49
- */
50
- constructor({ gamma, offsetHdr, offsetSdr, gainMapMin, gainMapMax, maxDisplayBoost, hdrCapacityMin, hdrCapacityMax, sdr, gainMap }) {
51
- super({
52
- name: 'GainMapDecoderMaterial',
53
- vertexShader: vertexShader$3,
54
- fragmentShader: fragmentShader$3,
55
- uniforms: {
56
- sdr: { value: sdr },
57
- gainMap: { value: gainMap },
58
- gamma: { value: new Vector3(1.0 / gamma[0], 1.0 / gamma[1], 1.0 / gamma[2]) },
59
- offsetHdr: { value: new Vector3(offsetHdr[0], offsetHdr[1], offsetHdr[2]) },
60
- offsetSdr: { value: new Vector3(offsetSdr[0], offsetSdr[1], offsetSdr[2]) },
61
- gainMapMin: { value: new Vector3(gainMapMin[0], gainMapMin[1], gainMapMin[2]) },
62
- gainMapMax: { value: new Vector3(gainMapMax[0], gainMapMax[1], gainMapMax[2]) },
63
- weightFactor: {
64
- value: (Math.log2(maxDisplayBoost) - hdrCapacityMin) / (hdrCapacityMax - hdrCapacityMin)
65
- }
66
- },
67
- blending: NoBlending,
68
- depthTest: false,
69
- depthWrite: false
70
- });
71
- this._maxDisplayBoost = maxDisplayBoost;
72
- this._hdrCapacityMin = hdrCapacityMin;
73
- this._hdrCapacityMax = hdrCapacityMax;
74
- this.needsUpdate = true;
75
- this.uniformsNeedUpdate = true;
76
- }
77
- /**
78
- * @see {@link GainmapDecodingParameters}
79
- */
80
- get maxDisplayBoost() { return this._maxDisplayBoost; }
81
- set maxDisplayBoost(value) {
82
- this._maxDisplayBoost = value;
83
- this.uniforms.weightFactor.value = (Math.log2(this._maxDisplayBoost) - this._hdrCapacityMin) / (this._hdrCapacityMax - this._hdrCapacityMin);
84
- }
85
- }
86
-
87
- /**
88
- * Utility structure used for rendering a texture with a material
89
- *
90
- * @category General
91
- * @group General
92
- */
93
- class QuadRenderer {
94
- /**
95
- *
96
- * @param sourceTexture
97
- * @param renderer
98
- */
99
- constructor(width, height, type, colorSpace, material, renderer) {
100
- this._rendererIsDisposable = false;
101
- /**
102
- * Renders the input texture using the specified material
103
- */
104
- this.render = () => {
105
- this._renderer.setRenderTarget(this._renderTarget);
106
- try {
107
- this._renderer.render(this._scene, this._camera);
108
- }
109
- catch (e) {
110
- this._renderer.setRenderTarget(null);
111
- throw e;
112
- }
113
- this._renderer.setRenderTarget(null);
114
- };
115
- this._width = width;
116
- this._height = height;
117
- this._type = type;
118
- this._material = material;
119
- if (renderer) {
120
- this._renderer = renderer;
121
- }
122
- else {
123
- this._renderer = QuadRenderer.instantiateRenderer();
124
- this._rendererIsDisposable = true;
125
- }
126
- this._scene = new Scene();
127
- this._camera = new OrthographicCamera();
128
- this._camera.position.set(0, 0, 10);
129
- this._camera.left = -0.5;
130
- this._camera.right = 0.5;
131
- this._camera.top = 0.5;
132
- this._camera.bottom = -0.5;
133
- this._camera.updateProjectionMatrix();
134
- this._quad = new Mesh(new PlaneGeometry(), this._material);
135
- this._quad.geometry.computeBoundingBox();
136
- this._scene.add(this._quad);
137
- this._renderTarget = new WebGLRenderTarget(width, height, {
138
- type,
139
- colorSpace,
140
- format: RGBAFormat,
141
- magFilter: LinearFilter,
142
- minFilter: LinearMipMapLinearFilter,
143
- wrapS: RepeatWrapping,
144
- wrapT: RepeatWrapping,
145
- depthBuffer: false,
146
- stencilBuffer: false,
147
- generateMipmaps: true
148
- });
149
- }
150
- /**
151
- * Instantiates a temporary renderer
152
- *
153
- * @returns
154
- */
155
- static instantiateRenderer() {
156
- const renderer = new WebGLRenderer();
157
- renderer.setSize(128, 128);
158
- // renderer.outputColorSpace = SRGBColorSpace
159
- // renderer.toneMapping = LinearToneMapping
160
- // renderer.debug.checkShaderErrors = false
161
- // this._rendererIsDisposable = true
162
- return renderer;
163
- }
164
- /**
165
- * Obtains a Buffer containing the rendered texture.
166
- *
167
- * @returns
168
- */
169
- toArray() {
170
- let out;
171
- switch (this._type) {
172
- case UnsignedByteType:
173
- out = new Uint8ClampedArray(this._width * this._height * 4);
174
- break;
175
- case HalfFloatType:
176
- out = new Uint16Array(this._width * this._height * 4);
177
- break;
178
- case UnsignedIntType:
179
- out = new Uint32Array(this._width * this._height * 4);
180
- break;
181
- case ByteType:
182
- out = new Int8Array(this._width * this._height * 4);
183
- break;
184
- case ShortType:
185
- out = new Int16Array(this._width * this._height * 4);
186
- break;
187
- case IntType:
188
- out = new Int32Array(this._width * this._height * 4);
189
- break;
190
- case FloatType:
191
- out = new Float32Array(this._width * this._height * 4);
192
- break;
193
- default:
194
- throw new Error('Unsupported data type');
195
- }
196
- this._renderer.readRenderTargetPixels(this._renderTarget, 0, 0, this._width, this._height, out);
197
- return out;
198
- }
199
- /**
200
- * If using a disposable renderer, it will dispose it.
201
- */
202
- dispose() {
203
- this._renderer.setRenderTarget(null);
204
- if (this._rendererIsDisposable) {
205
- this._renderer.dispose();
206
- this._renderer.forceContextLoss();
207
- }
208
- }
209
- /**
210
- * Width of the texture
211
- */
212
- get width() { return this._width; }
213
- set width(value) {
214
- this._width = value;
215
- this._renderTarget.setSize(this._width, this._height);
216
- }
217
- /**
218
- * Height of the texture
219
- */
220
- get height() { return this._height; }
221
- set height(value) {
222
- this._height = value;
223
- this._renderTarget.setSize(this._width, this._height);
224
- }
225
- /**
226
- * The renderer used
227
- */
228
- get renderer() { return this._renderer; }
229
- /**
230
- * The `WebGLRenderTarget` used.
231
- */
232
- get renderTarget() { return this._renderTarget; }
233
- set renderTarget(value) {
234
- this._renderTarget = value;
235
- this._width = value.width;
236
- this._height = value.height;
237
- // this._type = value.texture.type
238
- }
239
- /**
240
- * The `Material` used.
241
- */
242
- get material() { return this._material; }
243
- }
244
-
245
12
  /**
246
13
  * Decodes a gain map using a WebGLRenderTarget
247
14
  *
@@ -249,27 +16,46 @@ class QuadRenderer {
249
16
  * @group Decoding
250
17
  * @example
251
18
  * import { decode } from '@monogrid/gainmap-js'
252
- * import { Mesh, MeshBasicMaterial, PlaneGeometry, TextureLoader } from 'three'
19
+ * import {
20
+ * Mesh,
21
+ * MeshBasicMaterial,
22
+ * PerspectiveCamera,
23
+ * PlaneGeometry,
24
+ * Scene,
25
+ * TextureLoader,
26
+ * WebGLRenderer
27
+ * } from 'three'
253
28
  *
254
- * const loader = new TextureLoader()
29
+ * const renderer = new WebGLRenderer()
30
+ *
31
+ * const textureLoader = new TextureLoader()
255
32
  *
256
33
  * // load SDR Representation
257
- * const sdr = await loader.loadAsync('sdr.jpg')
34
+ * const sdr = await textureLoader.loadAsync('sdr.jpg')
258
35
  * // load Gain map recovery image
259
- * const gainMap = await loader.loadAsync('gainmap.jpg')
36
+ * const gainMap = await textureLoader.loadAsync('gainmap.jpg')
260
37
  * // load metadata
261
38
  * const metadata = await (await fetch('metadata.json')).json()
262
39
  *
263
40
  * const result = await decode({
264
41
  * sdr,
265
42
  * gainMap,
43
+ * // this allows to use `result.renderTarget.texture` directly
44
+ * renderer,
266
45
  * // this will restore the full HDR range
267
46
  * maxDisplayBoost: Math.pow(2, metadata.hdrCapacityMax),
268
47
  * ...metadata
269
48
  * })
270
49
  *
271
- * // result can be used to populate a Texture
272
- * const mesh = new Mesh(new PlaneGeometry(), new MeshBasicMaterial({ map: result.renderTarget.texture }))
50
+ * const scene = new Scene()
51
+ * // `result` can be used to populate a Texture
52
+ * const mesh = new Mesh(
53
+ * new PlaneGeometry(),
54
+ * new MeshBasicMaterial({ map: result.renderTarget.texture })
55
+ * )
56
+ * scene.add(mesh)
57
+ * renderer.render(scene, new PerspectiveCamera())
58
+ *
273
59
  *
274
60
  * @param params
275
61
  * @returns
@@ -380,23 +166,33 @@ class GainMapEncoderMaterial extends ShaderMaterial {
380
166
  this.needsUpdate = true;
381
167
  this.uniformsNeedUpdate = true;
382
168
  }
169
+ /**
170
+ * @see {@link GainmapEncodingParameters.gamma}
171
+ */
383
172
  get gamma() { return this._gamma; }
384
173
  set gamma(value) {
385
174
  this._gamma = value;
386
175
  this.uniforms.gamma.value = new Vector3().fromArray(value);
387
176
  }
177
+ /**
178
+ * @see {@link GainmapEncodingParameters.offsetHdr}
179
+ */
388
180
  get offsetHdr() { return this._offsetHdr; }
389
181
  set offsetHdr(value) {
390
182
  this._offsetHdr = value;
391
183
  this.uniforms.offsetHdr.value = new Vector3().fromArray(value);
392
184
  }
185
+ /**
186
+ * @see {@link GainmapEncodingParameters.offsetSdr}
187
+ */
393
188
  get offsetSdr() { return this._offsetSdr; }
394
189
  set offsetSdr(value) {
395
190
  this._offsetSdr = value;
396
191
  this.uniforms.offsetSdr.value = new Vector3().fromArray(value);
397
192
  }
398
193
  /**
399
- * Non logarithmic space
194
+ * @see {@link GainmapEncodingParameters.minContentBoost}
195
+ * @remarks Non logarithmic space
400
196
  */
401
197
  get minContentBoost() { return this._minContentBoost; }
402
198
  set minContentBoost(value) {
@@ -404,16 +200,33 @@ class GainMapEncoderMaterial extends ShaderMaterial {
404
200
  this.uniforms.minLog2.value = Math.log2(value);
405
201
  }
406
202
  /**
407
- * Non logarithmic space
203
+ * @see {@link GainmapEncodingParameters.maxContentBoost}
204
+ * @remarks Non logarithmic space
408
205
  */
409
206
  get maxContentBoost() { return this._maxContentBoost; }
410
207
  set maxContentBoost(value) {
411
208
  this._maxContentBoost = value;
412
209
  this.uniforms.maxLog2.value = Math.log2(value);
413
210
  }
211
+ /**
212
+ * @see {@link GainMapMetadata.gainMapMin}
213
+ * @remarks Logarithmic space
214
+ */
414
215
  get gainMapMin() { return [Math.log2(this._minContentBoost), Math.log2(this._minContentBoost), Math.log2(this._minContentBoost)]; }
216
+ /**
217
+ * @see {@link GainMapMetadata.gainMapMax}
218
+ * @remarks Logarithmic space
219
+ */
415
220
  get gainMapMax() { return [Math.log2(this._maxContentBoost), Math.log2(this._maxContentBoost), Math.log2(this._maxContentBoost)]; }
221
+ /**
222
+ * @see {@link GainMapMetadata.hdrCapacityMin}
223
+ * @remarks Logarithmic space
224
+ */
416
225
  get hdrCapacityMin() { return Math.min(Math.max(0, this.gainMapMin[0]), Math.max(0, this.gainMapMin[1]), Math.max(0, this.gainMapMin[2])); }
226
+ /**
227
+ * @see {@link GainMapMetadata.hdrCapacityMax}
228
+ * @remarks Logarithmic space
229
+ */
417
230
  get hdrCapacityMax() { return Math.min(Math.max(0, this.gainMapMax[0]), Math.max(0, this.gainMapMax[1]), Math.max(0, this.gainMapMax[2])); }
418
231
  }
419
232
 
@@ -678,8 +491,8 @@ class SDRMaterial extends ShaderMaterial {
678
491
  * @group Encoding Functions
679
492
  *
680
493
  * @param hdrTexture The HDR image to be rendered
681
- * @param renderer (optional) WebGLRenderer to use diring the rendering, a disposable renderer will be create and destroyed if this is not provided.
682
- * @param toneMapping (optional) Tonemapping to be applied to the SDR Rendition
494
+ * @param renderer (optional) WebGLRenderer to use during the rendering, a disposable renderer will be create and destroyed if this is not provided.
495
+ * @param toneMapping (optional) Tone mapping to be applied to the SDR Rendition
683
496
  * @throws {Error} if the WebGLRenderer fails to render the SDR image
684
497
  */
685
498
  const getSDRRendition = (hdrTexture, renderer, toneMapping) => {
@@ -742,7 +555,7 @@ const getSDRRendition = (hdrTexture, renderer, toneMapping) => {
742
555
  * encodingResult.sdr.dispose()
743
556
  * encodingResult.gainMap.dispose()
744
557
  *
745
- * @param params Encoding Paramaters
558
+ * @param params Encoding Parameters
746
559
  * @returns
747
560
  */
748
561
  const encode = (params) => {
@@ -777,7 +590,7 @@ const encode = (params) => {
777
590
  * @remarks
778
591
  * if a `renderer` parameter is not provided
779
592
  * This function will automatically dispose its "disposable"
780
- * renderer, no need to disapose it manually later
593
+ * renderer, no need to dispose it manually later
781
594
  *
782
595
  * @category Encoding Functions
783
596
  * @group Encoding Functions
@@ -811,7 +624,7 @@ const encode = (params) => {
811
624
  * // `jpeg` will be an `Uint8Array` which can be saved somewhere
812
625
  *
813
626
  *
814
- * @param params Encoding Paramaters
627
+ * @param params Encoding Parameters
815
628
  * @throws {Error} if the browser does not support [createImageBitmap](https://caniuse.com/createimagebitmap)
816
629
  */
817
630
  const encodeAndCompress = async (params) => {
@@ -938,14 +751,14 @@ const findTextureMinMax = (image, mode = 'max', renderer) => {
938
751
  let w = srcTex.image.width;
939
752
  let h = srcTex.image.height;
940
753
  const quadRenderer = new QuadRenderer(w, h, srcTex.type, srcTex.colorSpace, mat, renderer);
941
- const framebuffers = [];
754
+ const frameBuffers = [];
942
755
  while (w > 1 || h > 1) {
943
756
  w = Math.max(1, (w + cellSize - 1) / cellSize | 0);
944
757
  h = Math.max(1, (h + cellSize - 1) / cellSize | 0);
945
758
  const fb = new WebGLRenderTarget(w, h, {
946
- type: srcTex.type,
759
+ type: quadRenderer.type,
947
760
  format: srcTex.format,
948
- colorSpace: srcTex.colorSpace,
761
+ colorSpace: quadRenderer.colorSpace,
949
762
  minFilter: NearestFilter,
950
763
  magFilter: NearestFilter,
951
764
  wrapS: ClampToEdgeWrapping,
@@ -954,11 +767,11 @@ const findTextureMinMax = (image, mode = 'max', renderer) => {
954
767
  depthBuffer: false,
955
768
  stencilBuffer: false
956
769
  });
957
- framebuffers.push(fb);
770
+ frameBuffers.push(fb);
958
771
  }
959
772
  w = srcTex.image.width;
960
773
  h = srcTex.image.height;
961
- framebuffers.forEach((fbi) => {
774
+ frameBuffers.forEach((fbi) => {
962
775
  w = Math.max(1, (w + cellSize - 1) / cellSize | 0);
963
776
  h = Math.max(1, (h + cellSize - 1) / cellSize | 0);
964
777
  quadRenderer.renderTarget = fbi;
@@ -969,8 +782,126 @@ const findTextureMinMax = (image, mode = 'max', renderer) => {
969
782
  });
970
783
  const out = quadRenderer.toArray();
971
784
  quadRenderer.dispose();
972
- framebuffers.forEach(fb => fb.dispose());
973
- return [DataUtils.fromHalfFloat(out[0]), DataUtils.fromHalfFloat(out[1]), DataUtils.fromHalfFloat(out[2])];
785
+ frameBuffers.forEach(fb => fb.dispose());
786
+ return [
787
+ quadRenderer.type === FloatType ? out[0] : DataUtils.fromHalfFloat(out[0]),
788
+ quadRenderer.type === FloatType ? out[1] : DataUtils.fromHalfFloat(out[1]),
789
+ quadRenderer.type === FloatType ? out[2] : DataUtils.fromHalfFloat(out[2])
790
+ ];
974
791
  };
975
792
 
976
- export { GainMapDecoderMaterial, GainMapEncoderMaterial, QuadRenderer, SDRMaterial, decode, encode, encodeAndCompress, findTextureMinMax, getDataTexture, getGainMap, getSDRRendition };
793
+ /**
794
+ * A Three.js Loader for the gain map format.
795
+ *
796
+ * @category Loaders
797
+ * @group Loaders
798
+ *
799
+ * @example
800
+ * import { GainMapLoader } from '@monogrid/gainmap-js'
801
+ * import {
802
+ * EquirectangularReflectionMapping,
803
+ * LinearFilter,
804
+ * Mesh,
805
+ * MeshBasicMaterial,
806
+ * PerspectiveCamera,
807
+ * PlaneGeometry,
808
+ * Scene,
809
+ * WebGLRenderer
810
+ * } from 'three'
811
+ *
812
+ * const renderer = new WebGLRenderer()
813
+ *
814
+ * const loader = new GainMapLoader(renderer)
815
+ *
816
+ * const result = loader.load(['sdr.jpeg', 'gainmap.jpeg', 'metadata.json'])
817
+ * // `result` can be used to populate a Texture
818
+ *
819
+ * const scene = new Scene()
820
+ * const mesh = new Mesh(
821
+ * new PlaneGeometry(),
822
+ * new MeshBasicMaterial({ map: result.renderTarget.texture })
823
+ * )
824
+ * scene.add(mesh)
825
+ * renderer.render(scene, new PerspectiveCamera())
826
+ *
827
+ * // `result.renderTarget.texture` must be
828
+ * // converted to `DataTexture` in order
829
+ * // to use it as Equirectangular scene background
830
+ * // if needed
831
+ *
832
+ * scene.background = result.toDataTexture()
833
+ * scene.background.mapping = EquirectangularReflectionMapping
834
+ * scene.background.minFilter = LinearFilter
835
+ *
836
+ *
837
+ */
838
+ class GainMapLoader extends LoaderBase {
839
+ /**
840
+ * Loads a gainmap using separate data
841
+ * * sdr image
842
+ * * gain map image
843
+ * * metadata json
844
+ *
845
+ * useful for webp gain maps
846
+ *
847
+ * @param sdrUrl
848
+ * @param gainMapUrl
849
+ * @param metadataUrl
850
+ * @param onLoad
851
+ * @param onProgress
852
+ * @param onError
853
+ * @returns
854
+ */
855
+ load([sdrUrl, gainMapUrl, metadataUrl], onLoad, onProgress, onError) {
856
+ const quadRenderer = this.prepareQuadRenderer();
857
+ let sdr;
858
+ let gainMap;
859
+ let metadata;
860
+ const loadCheck = async () => {
861
+ if (sdr && gainMap && metadata) {
862
+ await this.render(quadRenderer, gainMap, sdr, metadata);
863
+ if (typeof onLoad === 'function')
864
+ onLoad(quadRenderer);
865
+ quadRenderer.dispose();
866
+ }
867
+ };
868
+ const progressHandler = (e) => {
869
+ };
870
+ const sdrLoader = new FileLoader(this.manager);
871
+ sdrLoader.setResponseType('arraybuffer');
872
+ sdrLoader.setRequestHeader(this.requestHeader);
873
+ sdrLoader.setPath(this.path);
874
+ sdrLoader.setWithCredentials(this.withCredentials);
875
+ sdrLoader.load(sdrUrl, async (buffer) => {
876
+ if (typeof buffer === 'string')
877
+ throw new Error('Invalid sdr buffer');
878
+ sdr = buffer;
879
+ loadCheck();
880
+ }, progressHandler, onError);
881
+ const gainMapLoader = new FileLoader(this.manager);
882
+ gainMapLoader.setResponseType('arraybuffer');
883
+ gainMapLoader.setRequestHeader(this.requestHeader);
884
+ gainMapLoader.setPath(this.path);
885
+ gainMapLoader.setWithCredentials(this.withCredentials);
886
+ gainMapLoader.load(gainMapUrl, async (buffer) => {
887
+ if (typeof buffer === 'string')
888
+ throw new Error('Invalid gainmap buffer');
889
+ gainMap = buffer;
890
+ loadCheck();
891
+ }, progressHandler, onError);
892
+ const metadataLoader = new FileLoader(this.manager);
893
+ // metadataLoader.setResponseType('json')
894
+ metadataLoader.setRequestHeader(this.requestHeader);
895
+ metadataLoader.setPath(this.path);
896
+ metadataLoader.setWithCredentials(this.withCredentials);
897
+ metadataLoader.load(metadataUrl, async (json) => {
898
+ if (typeof json !== 'string')
899
+ throw new Error('Invalid metadata string');
900
+ metadata = JSON.parse(json);
901
+ loadCheck();
902
+ }, progressHandler, onError);
903
+ return quadRenderer;
904
+ }
905
+ }
906
+
907
+ export { GainMapEncoderMaterial, GainMapLoader, SDRMaterial, decode, encode, encodeAndCompress, findTextureMinMax, getDataTexture, getGainMap, getSDRRendition };