@monogrid/gainmap-js 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/README.md +103 -19
- package/dist/LoaderBase-aa4842c4.js +373 -0
- package/dist/_commonjsHelpers-1789f0cf.js +1 -1
- package/dist/compress-a4b59cab.js +1 -1
- package/dist/decode.d.ts +25 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +173 -246
- package/dist/index.umd.js +305 -14
- package/dist/libultrahdr-esm.wasm +0 -0
- package/dist/libultrahdr.d.ts +14 -19
- package/dist/libultrahdr.js +245 -203
- package/dist/libultrahdr.umd.js +611 -206
- package/dist/loaders/GainMapLoader.d.ts +68 -0
- package/dist/loaders/JPEGRLoader.d.ts +60 -0
- package/dist/loaders/LoaderBase.d.ts +27 -0
- package/dist/materials/GainMapDecoderMaterial.d.ts +44 -1
- package/dist/materials/GainMapEncoderMaterial.d.ts +29 -2
- package/dist/types.d.ts +10 -0
- package/dist/utils/QuadRenderer.d.ts +2 -1
- package/dist/worker-interface.js +1 -1
- package/dist/worker-interface.umd.js +1 -1
- package/dist/worker.js +1 -1
- package/dist/worker.umd.js +1 -1
- package/libultrahdr-wasm/build/libultrahdr-debug.js +156 -182
- package/libultrahdr-wasm/build/libultrahdr-debug.wasm +0 -0
- package/libultrahdr-wasm/build/libultrahdr-esm.js +153 -182
- package/libultrahdr-wasm/build/libultrahdr-esm.wasm +0 -0
- package/libultrahdr-wasm/build/libultrahdr.js +151 -180
- package/libultrahdr-wasm/build/libultrahdr.wasm +0 -0
- package/package.json +1 -1
- package/examples/README.md +0 -3
- package/examples/compress.ts +0 -43
- package/examples/decode-from-jpeg.ts +0 -40
- package/examples/decode-from-separate-data.ts +0 -41
- package/examples/decode-to-datatexture.ts +0 -65
- package/examples/encode-and-compress.ts +0 -29
- package/examples/encode-jpeg-metadata.ts +0 -57
- package/examples/encode.ts +0 -28
- package/examples/globals.d.ts +0 -6
- package/examples/worker.ts +0 -41
- package/reports/eslint-examples.json +0 -1
- package/reports/eslint-src.json +0 -1
- package/reports/eslint-tests.json +0 -1
- package/reports/junit.xml +0 -35
- package/reports/typecheck-examples.log +0 -0
- package/reports/typecheck-tests.log +0 -0
- package/reports/typecheck.log +0 -0
package/dist/index.js
CHANGED
|
@@ -1,247 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @monogrid/gainmap-js v1.0.
|
|
2
|
+
* @monogrid/gainmap-js v1.0.2
|
|
3
3
|
* With ❤️, by MONOGRID <hello@mono-grid.com>
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { SRGBColorSpace, NoColorSpace, HalfFloatType, ShaderMaterial, Vector3, NoBlending, DataTexture, RGBAFormat, UVMapping, RepeatWrapping, LinearFilter, UnsignedByteType, ACESFilmicToneMapping, LinearToneMapping, CineonToneMapping, ReinhardToneMapping, Vector2, WebGLRenderTarget, NearestFilter, ClampToEdgeWrapping, DataUtils, FileLoader } from 'three';
|
|
7
|
+
import { G as GainMapDecoderMaterial, Q as QuadRenderer, L as LoaderBase } from './LoaderBase-aa4842c4.js';
|
|
8
|
+
export { G as GainMapDecoderMaterial, Q as QuadRenderer } from './LoaderBase-aa4842c4.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 {
|
|
19
|
+
* import {
|
|
20
|
+
* Mesh,
|
|
21
|
+
* MeshBasicMaterial,
|
|
22
|
+
* PerspectiveCamera,
|
|
23
|
+
* PlaneGeometry,
|
|
24
|
+
* Scene,
|
|
25
|
+
* TextureLoader,
|
|
26
|
+
* WebGLRenderer
|
|
27
|
+
* } from 'three'
|
|
253
28
|
*
|
|
254
|
-
* const
|
|
29
|
+
* const renderer = new WebGLRenderer()
|
|
30
|
+
*
|
|
31
|
+
* const textureLoader = new TextureLoader()
|
|
255
32
|
*
|
|
256
33
|
* // load SDR Representation
|
|
257
|
-
* const sdr = await
|
|
34
|
+
* const sdr = await textureLoader.loadAsync('sdr.jpg')
|
|
258
35
|
* // load Gain map recovery image
|
|
259
|
-
* const gainMap = await
|
|
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
|
-
*
|
|
272
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
|
|
@@ -973,4 +786,118 @@ const findTextureMinMax = (image, mode = 'max', renderer) => {
|
|
|
973
786
|
return [DataUtils.fromHalfFloat(out[0]), DataUtils.fromHalfFloat(out[1]), DataUtils.fromHalfFloat(out[2])];
|
|
974
787
|
};
|
|
975
788
|
|
|
976
|
-
|
|
789
|
+
/**
|
|
790
|
+
* A Three.js Loader for the gain map format.
|
|
791
|
+
*
|
|
792
|
+
* @category Loaders
|
|
793
|
+
* @group Loaders
|
|
794
|
+
*
|
|
795
|
+
* @example
|
|
796
|
+
* import { GainMapLoader } from '@monogrid/gainmap-js'
|
|
797
|
+
* import {
|
|
798
|
+
* EquirectangularReflectionMapping,
|
|
799
|
+
* LinearFilter,
|
|
800
|
+
* Mesh,
|
|
801
|
+
* MeshBasicMaterial,
|
|
802
|
+
* PerspectiveCamera,
|
|
803
|
+
* PlaneGeometry,
|
|
804
|
+
* Scene,
|
|
805
|
+
* WebGLRenderer
|
|
806
|
+
* } from 'three'
|
|
807
|
+
*
|
|
808
|
+
* const renderer = new WebGLRenderer()
|
|
809
|
+
*
|
|
810
|
+
* const loader = new GainMapLoader(renderer)
|
|
811
|
+
*
|
|
812
|
+
* const result = loader.load(['sdr.jpeg', 'gainmap.jpeg', 'metadata.json'])
|
|
813
|
+
* // `result` can be used to populate a Texture
|
|
814
|
+
*
|
|
815
|
+
* const scene = new Scene()
|
|
816
|
+
* const mesh = new Mesh(
|
|
817
|
+
* new PlaneGeometry(),
|
|
818
|
+
* new MeshBasicMaterial({ map: result.renderTarget.texture })
|
|
819
|
+
* )
|
|
820
|
+
* scene.add(mesh)
|
|
821
|
+
* renderer.render(scene, new PerspectiveCamera())
|
|
822
|
+
*
|
|
823
|
+
* // `result.renderTarget.texture` must be
|
|
824
|
+
* // converted to `DataTexture` in order
|
|
825
|
+
* // to use it as Equirectanmgular scene background
|
|
826
|
+
* // if needed
|
|
827
|
+
*
|
|
828
|
+
* scene.background = result.toDataTexture()
|
|
829
|
+
* scene.background.mapping = EquirectangularReflectionMapping
|
|
830
|
+
* scene.background.minFilter = LinearFilter
|
|
831
|
+
*
|
|
832
|
+
*
|
|
833
|
+
*/
|
|
834
|
+
class GainMapLoader extends LoaderBase {
|
|
835
|
+
/**
|
|
836
|
+
* Loads a gainmap using separate data
|
|
837
|
+
* * sdr image
|
|
838
|
+
* * gain map image
|
|
839
|
+
* * metadata json
|
|
840
|
+
*
|
|
841
|
+
* useful for webp gainmaps
|
|
842
|
+
*
|
|
843
|
+
* @param sdrUrl
|
|
844
|
+
* @param gainMapUrl
|
|
845
|
+
* @param metadataUrl
|
|
846
|
+
* @param onLoad
|
|
847
|
+
* @param onProgress
|
|
848
|
+
* @param onError
|
|
849
|
+
* @returns
|
|
850
|
+
*/
|
|
851
|
+
load([sdrUrl, gainMapUrl, metadataUrl], onLoad, onProgress, onError) {
|
|
852
|
+
const quadRenderer = this.prepareQuadRenderer();
|
|
853
|
+
let sdr;
|
|
854
|
+
let gainMap;
|
|
855
|
+
let metadata;
|
|
856
|
+
const loadCheck = async () => {
|
|
857
|
+
if (sdr && gainMap && metadata) {
|
|
858
|
+
await this.render(quadRenderer, gainMap, sdr, metadata);
|
|
859
|
+
if (typeof onLoad === 'function')
|
|
860
|
+
onLoad(quadRenderer);
|
|
861
|
+
quadRenderer.dispose();
|
|
862
|
+
}
|
|
863
|
+
};
|
|
864
|
+
const progressHandler = (e) => {
|
|
865
|
+
};
|
|
866
|
+
const sdrLoader = new FileLoader(this.manager);
|
|
867
|
+
sdrLoader.setResponseType('arraybuffer');
|
|
868
|
+
sdrLoader.setRequestHeader(this.requestHeader);
|
|
869
|
+
sdrLoader.setPath(this.path);
|
|
870
|
+
sdrLoader.setWithCredentials(this.withCredentials);
|
|
871
|
+
sdrLoader.load(sdrUrl, async (buffer) => {
|
|
872
|
+
if (typeof buffer === 'string')
|
|
873
|
+
throw new Error('Invalid sdr buffer');
|
|
874
|
+
sdr = buffer;
|
|
875
|
+
loadCheck();
|
|
876
|
+
}, progressHandler, onError);
|
|
877
|
+
const gainMapLoader = new FileLoader(this.manager);
|
|
878
|
+
gainMapLoader.setResponseType('arraybuffer');
|
|
879
|
+
gainMapLoader.setRequestHeader(this.requestHeader);
|
|
880
|
+
gainMapLoader.setPath(this.path);
|
|
881
|
+
gainMapLoader.setWithCredentials(this.withCredentials);
|
|
882
|
+
gainMapLoader.load(gainMapUrl, async (buffer) => {
|
|
883
|
+
if (typeof buffer === 'string')
|
|
884
|
+
throw new Error('Invalid gainmap buffer');
|
|
885
|
+
gainMap = buffer;
|
|
886
|
+
loadCheck();
|
|
887
|
+
}, progressHandler, onError);
|
|
888
|
+
const metadataLoader = new FileLoader(this.manager);
|
|
889
|
+
// metadataLoader.setResponseType('json')
|
|
890
|
+
metadataLoader.setRequestHeader(this.requestHeader);
|
|
891
|
+
metadataLoader.setPath(this.path);
|
|
892
|
+
metadataLoader.setWithCredentials(this.withCredentials);
|
|
893
|
+
metadataLoader.load(metadataUrl, async (json) => {
|
|
894
|
+
if (typeof json !== 'string')
|
|
895
|
+
throw new Error('Invalid metadata string');
|
|
896
|
+
metadata = JSON.parse(json);
|
|
897
|
+
loadCheck();
|
|
898
|
+
}, progressHandler, onError);
|
|
899
|
+
return quadRenderer;
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
export { GainMapEncoderMaterial, GainMapLoader, SDRMaterial, decode, encode, encodeAndCompress, findTextureMinMax, getDataTexture, getGainMap, getSDRRendition };
|