@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.umd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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
|
|
|
@@ -58,10 +58,10 @@ void main() {
|
|
|
58
58
|
sdr: { value: sdr },
|
|
59
59
|
gainMap: { value: gainMap },
|
|
60
60
|
gamma: { value: new three.Vector3(1.0 / gamma[0], 1.0 / gamma[1], 1.0 / gamma[2]) },
|
|
61
|
-
offsetHdr: { value: new three.Vector3(offsetHdr
|
|
62
|
-
offsetSdr: { value: new three.Vector3(offsetSdr
|
|
63
|
-
gainMapMin: { value: new three.Vector3(gainMapMin
|
|
64
|
-
gainMapMax: { value: new three.Vector3(gainMapMax
|
|
61
|
+
offsetHdr: { value: new three.Vector3().fromArray(offsetHdr) },
|
|
62
|
+
offsetSdr: { value: new three.Vector3().fromArray(offsetSdr) },
|
|
63
|
+
gainMapMin: { value: new three.Vector3().fromArray(gainMapMin) },
|
|
64
|
+
gainMapMax: { value: new three.Vector3().fromArray(gainMapMax) },
|
|
65
65
|
weightFactor: {
|
|
66
66
|
value: (Math.log2(maxDisplayBoost) - hdrCapacityMin) / (hdrCapacityMax - hdrCapacityMin)
|
|
67
67
|
}
|
|
@@ -76,12 +76,71 @@ void main() {
|
|
|
76
76
|
this.needsUpdate = true;
|
|
77
77
|
this.uniformsNeedUpdate = true;
|
|
78
78
|
}
|
|
79
|
+
get sdr() { return this.uniforms.sdr.value; }
|
|
80
|
+
set sdr(value) { this.uniforms.sdr.value = value; }
|
|
81
|
+
get gainMap() { return this.uniforms.gainMap.value; }
|
|
82
|
+
set gainMap(value) { this.uniforms.gainMap.value = value; }
|
|
79
83
|
/**
|
|
80
|
-
* @see {@link
|
|
84
|
+
* @see {@link GainMapMetadata.offsetHdr}
|
|
85
|
+
*/
|
|
86
|
+
get offsetHdr() { return this.uniforms.offsetHdr.value.toArray(); }
|
|
87
|
+
set offsetHdr(value) { this.uniforms.offsetHdr.value.fromArray(value); }
|
|
88
|
+
/**
|
|
89
|
+
* @see {@link GainMapMetadata.offsetSdr}
|
|
90
|
+
*/
|
|
91
|
+
get offsetSdr() { return this.uniforms.offsetSdr.value.toArray(); }
|
|
92
|
+
set offsetSdr(value) { this.uniforms.offsetSdr.value.fromArray(value); }
|
|
93
|
+
/**
|
|
94
|
+
* @see {@link GainMapMetadata.gainMapMin}
|
|
95
|
+
*/
|
|
96
|
+
get gainMapMin() { return this.uniforms.gainMapMin.value.toArray(); }
|
|
97
|
+
set gainMapMin(value) { this.uniforms.gainMapMin.value.fromArray(value); }
|
|
98
|
+
/**
|
|
99
|
+
* @see {@link GainMapMetadata.gainMapMax}
|
|
100
|
+
*/
|
|
101
|
+
get gainMapMax() { return this.uniforms.gainMapMax.value.toArray(); }
|
|
102
|
+
set gainMapMax(value) { this.uniforms.gainMapMax.value.fromArray(value); }
|
|
103
|
+
/**
|
|
104
|
+
* @see {@link GainmapEncodingParameters.gamma}
|
|
105
|
+
*/
|
|
106
|
+
get gamma() {
|
|
107
|
+
const g = this.uniforms.gamma.value;
|
|
108
|
+
return [1 / g.x, 1 / g.y, 1 / g.z];
|
|
109
|
+
}
|
|
110
|
+
set gamma(value) {
|
|
111
|
+
const g = this.uniforms.gamma.value;
|
|
112
|
+
g.x = 1.0 / value[0];
|
|
113
|
+
g.y = 1.0 / value[1];
|
|
114
|
+
g.z = 1.0 / value[2];
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* @see {@link GainMapMetadata.hdrCapacityMin}
|
|
118
|
+
* @remarks Logarithmic space
|
|
119
|
+
*/
|
|
120
|
+
get hdrCapacityMin() { return this._hdrCapacityMin; }
|
|
121
|
+
set hdrCapacityMin(value) {
|
|
122
|
+
this._hdrCapacityMin = value;
|
|
123
|
+
this.calculateWeight();
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* @see {@link GainMapMetadata.hdrCapacityMin}
|
|
127
|
+
* @remarks Logarithmic space
|
|
128
|
+
*/
|
|
129
|
+
get hdrCapacityMax() { return this._hdrCapacityMax; }
|
|
130
|
+
set hdrCapacityMax(value) {
|
|
131
|
+
this._hdrCapacityMax = value;
|
|
132
|
+
this.calculateWeight();
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* @see {@link GainmapDecodingParameters.maxDisplayBoost}
|
|
136
|
+
* @remarks Non Logarithmic space
|
|
81
137
|
*/
|
|
82
138
|
get maxDisplayBoost() { return this._maxDisplayBoost; }
|
|
83
139
|
set maxDisplayBoost(value) {
|
|
84
140
|
this._maxDisplayBoost = value;
|
|
141
|
+
this.calculateWeight();
|
|
142
|
+
}
|
|
143
|
+
calculateWeight() {
|
|
85
144
|
this.uniforms.weightFactor.value = (Math.log2(this._maxDisplayBoost) - this._hdrCapacityMin) / (this._hdrCapacityMax - this._hdrCapacityMin);
|
|
86
145
|
}
|
|
87
146
|
}
|
|
@@ -198,6 +257,9 @@ void main() {
|
|
|
198
257
|
this._renderer.readRenderTargetPixels(this._renderTarget, 0, 0, this._width, this._height, out);
|
|
199
258
|
return out;
|
|
200
259
|
}
|
|
260
|
+
toDataTexture() {
|
|
261
|
+
return new three.DataTexture(this.toArray(), this.width, this.height, three.RGBAFormat, three.HalfFloatType, three.UVMapping, three.RepeatWrapping, three.RepeatWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, 1, three.NoColorSpace);
|
|
262
|
+
}
|
|
201
263
|
/**
|
|
202
264
|
* If using a disposable renderer, it will dispose it.
|
|
203
265
|
*/
|
|
@@ -251,27 +313,46 @@ void main() {
|
|
|
251
313
|
* @group Decoding
|
|
252
314
|
* @example
|
|
253
315
|
* import { decode } from '@monogrid/gainmap-js'
|
|
254
|
-
* import {
|
|
316
|
+
* import {
|
|
317
|
+
* Mesh,
|
|
318
|
+
* MeshBasicMaterial,
|
|
319
|
+
* PerspectiveCamera,
|
|
320
|
+
* PlaneGeometry,
|
|
321
|
+
* Scene,
|
|
322
|
+
* TextureLoader,
|
|
323
|
+
* WebGLRenderer
|
|
324
|
+
* } from 'three'
|
|
325
|
+
*
|
|
326
|
+
* const renderer = new WebGLRenderer()
|
|
255
327
|
*
|
|
256
|
-
* const
|
|
328
|
+
* const textureLoader = new TextureLoader()
|
|
257
329
|
*
|
|
258
330
|
* // load SDR Representation
|
|
259
|
-
* const sdr = await
|
|
331
|
+
* const sdr = await textureLoader.loadAsync('sdr.jpg')
|
|
260
332
|
* // load Gain map recovery image
|
|
261
|
-
* const gainMap = await
|
|
333
|
+
* const gainMap = await textureLoader.loadAsync('gainmap.jpg')
|
|
262
334
|
* // load metadata
|
|
263
335
|
* const metadata = await (await fetch('metadata.json')).json()
|
|
264
336
|
*
|
|
265
337
|
* const result = await decode({
|
|
266
338
|
* sdr,
|
|
267
339
|
* gainMap,
|
|
340
|
+
* // this allows to use `result.renderTarget.texture` directly
|
|
341
|
+
* renderer,
|
|
268
342
|
* // this will restore the full HDR range
|
|
269
343
|
* maxDisplayBoost: Math.pow(2, metadata.hdrCapacityMax),
|
|
270
344
|
* ...metadata
|
|
271
345
|
* })
|
|
272
346
|
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
347
|
+
* const scene = new Scene()
|
|
348
|
+
* // `result` can be used to populate a Texture
|
|
349
|
+
* const mesh = new Mesh(
|
|
350
|
+
* new PlaneGeometry(),
|
|
351
|
+
* new MeshBasicMaterial({ map: result.renderTarget.texture })
|
|
352
|
+
* )
|
|
353
|
+
* scene.add(mesh)
|
|
354
|
+
* renderer.render(scene, new PerspectiveCamera())
|
|
355
|
+
*
|
|
275
356
|
*
|
|
276
357
|
* @param params
|
|
277
358
|
* @returns
|
|
@@ -458,23 +539,33 @@ void main() {
|
|
|
458
539
|
this.needsUpdate = true;
|
|
459
540
|
this.uniformsNeedUpdate = true;
|
|
460
541
|
}
|
|
542
|
+
/**
|
|
543
|
+
* @see {@link GainmapEncodingParameters.gamma}
|
|
544
|
+
*/
|
|
461
545
|
get gamma() { return this._gamma; }
|
|
462
546
|
set gamma(value) {
|
|
463
547
|
this._gamma = value;
|
|
464
548
|
this.uniforms.gamma.value = new three.Vector3().fromArray(value);
|
|
465
549
|
}
|
|
550
|
+
/**
|
|
551
|
+
* @see {@link GainmapEncodingParameters.offsetHdr}
|
|
552
|
+
*/
|
|
466
553
|
get offsetHdr() { return this._offsetHdr; }
|
|
467
554
|
set offsetHdr(value) {
|
|
468
555
|
this._offsetHdr = value;
|
|
469
556
|
this.uniforms.offsetHdr.value = new three.Vector3().fromArray(value);
|
|
470
557
|
}
|
|
558
|
+
/**
|
|
559
|
+
* @see {@link GainmapEncodingParameters.offsetSdr}
|
|
560
|
+
*/
|
|
471
561
|
get offsetSdr() { return this._offsetSdr; }
|
|
472
562
|
set offsetSdr(value) {
|
|
473
563
|
this._offsetSdr = value;
|
|
474
564
|
this.uniforms.offsetSdr.value = new three.Vector3().fromArray(value);
|
|
475
565
|
}
|
|
476
566
|
/**
|
|
477
|
-
*
|
|
567
|
+
* @see {@link GainmapEncodingParameters.minContentBoost}
|
|
568
|
+
* @remarks Non logarithmic space
|
|
478
569
|
*/
|
|
479
570
|
get minContentBoost() { return this._minContentBoost; }
|
|
480
571
|
set minContentBoost(value) {
|
|
@@ -482,16 +573,33 @@ void main() {
|
|
|
482
573
|
this.uniforms.minLog2.value = Math.log2(value);
|
|
483
574
|
}
|
|
484
575
|
/**
|
|
485
|
-
*
|
|
576
|
+
* @see {@link GainmapEncodingParameters.maxContentBoost}
|
|
577
|
+
* @remarks Non logarithmic space
|
|
486
578
|
*/
|
|
487
579
|
get maxContentBoost() { return this._maxContentBoost; }
|
|
488
580
|
set maxContentBoost(value) {
|
|
489
581
|
this._maxContentBoost = value;
|
|
490
582
|
this.uniforms.maxLog2.value = Math.log2(value);
|
|
491
583
|
}
|
|
584
|
+
/**
|
|
585
|
+
* @see {@link GainMapMetadata.gainMapMin}
|
|
586
|
+
* @remarks Logarithmic space
|
|
587
|
+
*/
|
|
492
588
|
get gainMapMin() { return [Math.log2(this._minContentBoost), Math.log2(this._minContentBoost), Math.log2(this._minContentBoost)]; }
|
|
589
|
+
/**
|
|
590
|
+
* @see {@link GainMapMetadata.gainMapMax}
|
|
591
|
+
* @remarks Logarithmic space
|
|
592
|
+
*/
|
|
493
593
|
get gainMapMax() { return [Math.log2(this._maxContentBoost), Math.log2(this._maxContentBoost), Math.log2(this._maxContentBoost)]; }
|
|
594
|
+
/**
|
|
595
|
+
* @see {@link GainMapMetadata.hdrCapacityMin}
|
|
596
|
+
* @remarks Logarithmic space
|
|
597
|
+
*/
|
|
494
598
|
get hdrCapacityMin() { return Math.min(Math.max(0, this.gainMapMin[0]), Math.max(0, this.gainMapMin[1]), Math.max(0, this.gainMapMin[2])); }
|
|
599
|
+
/**
|
|
600
|
+
* @see {@link GainMapMetadata.hdrCapacityMax}
|
|
601
|
+
* @remarks Logarithmic space
|
|
602
|
+
*/
|
|
495
603
|
get hdrCapacityMax() { return Math.min(Math.max(0, this.gainMapMax[0]), Math.max(0, this.gainMapMax[1]), Math.max(0, this.gainMapMax[2])); }
|
|
496
604
|
}
|
|
497
605
|
|
|
@@ -1051,8 +1159,191 @@ void main() {
|
|
|
1051
1159
|
return [three.DataUtils.fromHalfFloat(out[0]), three.DataUtils.fromHalfFloat(out[1]), three.DataUtils.fromHalfFloat(out[2])];
|
|
1052
1160
|
};
|
|
1053
1161
|
|
|
1162
|
+
class LoaderBase extends three.Loader {
|
|
1163
|
+
/**
|
|
1164
|
+
*
|
|
1165
|
+
* @param renderer
|
|
1166
|
+
* @param manager
|
|
1167
|
+
*/
|
|
1168
|
+
constructor(renderer, manager) {
|
|
1169
|
+
super(manager);
|
|
1170
|
+
this.renderer = renderer;
|
|
1171
|
+
}
|
|
1172
|
+
/**
|
|
1173
|
+
* @private
|
|
1174
|
+
* @returns
|
|
1175
|
+
*/
|
|
1176
|
+
prepareQuadRenderer() {
|
|
1177
|
+
// temporary values
|
|
1178
|
+
const material = new GainMapDecoderMaterial({
|
|
1179
|
+
gainMapMax: [1, 1, 1],
|
|
1180
|
+
gainMapMin: [0, 0, 0],
|
|
1181
|
+
gamma: [1, 1, 1],
|
|
1182
|
+
offsetHdr: [1, 1, 1],
|
|
1183
|
+
offsetSdr: [1, 1, 1],
|
|
1184
|
+
hdrCapacityMax: 1,
|
|
1185
|
+
hdrCapacityMin: 0,
|
|
1186
|
+
maxDisplayBoost: 1,
|
|
1187
|
+
gainMap: new three.Texture(),
|
|
1188
|
+
sdr: new three.Texture()
|
|
1189
|
+
});
|
|
1190
|
+
return new QuadRenderer(16, 16, three.HalfFloatType, three.NoColorSpace, material, this.renderer);
|
|
1191
|
+
}
|
|
1192
|
+
/**
|
|
1193
|
+
*
|
|
1194
|
+
* @private
|
|
1195
|
+
* @param quadRenderer
|
|
1196
|
+
* @param gainMapBuffer
|
|
1197
|
+
* @param sdrBuffer
|
|
1198
|
+
* @param metadata
|
|
1199
|
+
*/
|
|
1200
|
+
async render(quadRenderer, gainMapBuffer, sdrBuffer, metadata) {
|
|
1201
|
+
const gainMapBlob = new Blob([gainMapBuffer], { type: 'image/jpeg' });
|
|
1202
|
+
// TODO: figure out why result.sdr is not usable here, problem is in the libultrahdr-wasm repo
|
|
1203
|
+
// we use the original image buffer instead
|
|
1204
|
+
const sdrBlob = new Blob([sdrBuffer], { type: 'image/jpeg' });
|
|
1205
|
+
const [gainMapImageBitmap, sdrImageBitmap] = await Promise.all([
|
|
1206
|
+
createImageBitmap(gainMapBlob, { imageOrientation: 'flipY' }),
|
|
1207
|
+
createImageBitmap(sdrBlob, { imageOrientation: 'flipY' })
|
|
1208
|
+
]);
|
|
1209
|
+
const gainMap = new three.Texture(gainMapImageBitmap, three.UVMapping, three.ClampToEdgeWrapping, three.ClampToEdgeWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, three.RGBAFormat, three.UnsignedByteType, 1, three.NoColorSpace);
|
|
1210
|
+
gainMap.needsUpdate = true;
|
|
1211
|
+
const sdr = new three.Texture(sdrImageBitmap, three.UVMapping, three.ClampToEdgeWrapping, three.ClampToEdgeWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, three.RGBAFormat, three.UnsignedByteType, 1, three.SRGBColorSpace);
|
|
1212
|
+
sdr.needsUpdate = true;
|
|
1213
|
+
quadRenderer.width = sdrImageBitmap.width;
|
|
1214
|
+
quadRenderer.height = sdrImageBitmap.height;
|
|
1215
|
+
quadRenderer.material.gainMap = gainMap;
|
|
1216
|
+
quadRenderer.material.sdr = sdr;
|
|
1217
|
+
quadRenderer.material.gainMapMin = metadata.gainMapMin;
|
|
1218
|
+
quadRenderer.material.gainMapMax = metadata.gainMapMax;
|
|
1219
|
+
quadRenderer.material.offsetHdr = metadata.offsetHdr;
|
|
1220
|
+
quadRenderer.material.offsetSdr = metadata.offsetSdr;
|
|
1221
|
+
quadRenderer.material.gamma = metadata.gamma;
|
|
1222
|
+
quadRenderer.material.hdrCapacityMin = metadata.hdrCapacityMin;
|
|
1223
|
+
quadRenderer.material.hdrCapacityMax = metadata.hdrCapacityMax;
|
|
1224
|
+
quadRenderer.material.maxDisplayBoost = Math.pow(2, metadata.hdrCapacityMax);
|
|
1225
|
+
quadRenderer.material.needsUpdate = true;
|
|
1226
|
+
quadRenderer.render();
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
/**
|
|
1231
|
+
* A Three.js Loader for the gain map format.
|
|
1232
|
+
*
|
|
1233
|
+
* @category Loaders
|
|
1234
|
+
* @group Loaders
|
|
1235
|
+
*
|
|
1236
|
+
* @example
|
|
1237
|
+
* import { GainMapLoader } from '@monogrid/gainmap-js'
|
|
1238
|
+
* import {
|
|
1239
|
+
* EquirectangularReflectionMapping,
|
|
1240
|
+
* LinearFilter,
|
|
1241
|
+
* Mesh,
|
|
1242
|
+
* MeshBasicMaterial,
|
|
1243
|
+
* PerspectiveCamera,
|
|
1244
|
+
* PlaneGeometry,
|
|
1245
|
+
* Scene,
|
|
1246
|
+
* WebGLRenderer
|
|
1247
|
+
* } from 'three'
|
|
1248
|
+
*
|
|
1249
|
+
* const renderer = new WebGLRenderer()
|
|
1250
|
+
*
|
|
1251
|
+
* const loader = new GainMapLoader(renderer)
|
|
1252
|
+
*
|
|
1253
|
+
* const result = loader.load(['sdr.jpeg', 'gainmap.jpeg', 'metadata.json'])
|
|
1254
|
+
* // `result` can be used to populate a Texture
|
|
1255
|
+
*
|
|
1256
|
+
* const scene = new Scene()
|
|
1257
|
+
* const mesh = new Mesh(
|
|
1258
|
+
* new PlaneGeometry(),
|
|
1259
|
+
* new MeshBasicMaterial({ map: result.renderTarget.texture })
|
|
1260
|
+
* )
|
|
1261
|
+
* scene.add(mesh)
|
|
1262
|
+
* renderer.render(scene, new PerspectiveCamera())
|
|
1263
|
+
*
|
|
1264
|
+
* // `result.renderTarget.texture` must be
|
|
1265
|
+
* // converted to `DataTexture` in order
|
|
1266
|
+
* // to use it as Equirectanmgular scene background
|
|
1267
|
+
* // if needed
|
|
1268
|
+
*
|
|
1269
|
+
* scene.background = result.toDataTexture()
|
|
1270
|
+
* scene.background.mapping = EquirectangularReflectionMapping
|
|
1271
|
+
* scene.background.minFilter = LinearFilter
|
|
1272
|
+
*
|
|
1273
|
+
*
|
|
1274
|
+
*/
|
|
1275
|
+
class GainMapLoader extends LoaderBase {
|
|
1276
|
+
/**
|
|
1277
|
+
* Loads a gainmap using separate data
|
|
1278
|
+
* * sdr image
|
|
1279
|
+
* * gain map image
|
|
1280
|
+
* * metadata json
|
|
1281
|
+
*
|
|
1282
|
+
* useful for webp gainmaps
|
|
1283
|
+
*
|
|
1284
|
+
* @param sdrUrl
|
|
1285
|
+
* @param gainMapUrl
|
|
1286
|
+
* @param metadataUrl
|
|
1287
|
+
* @param onLoad
|
|
1288
|
+
* @param onProgress
|
|
1289
|
+
* @param onError
|
|
1290
|
+
* @returns
|
|
1291
|
+
*/
|
|
1292
|
+
load([sdrUrl, gainMapUrl, metadataUrl], onLoad, onProgress, onError) {
|
|
1293
|
+
const quadRenderer = this.prepareQuadRenderer();
|
|
1294
|
+
let sdr;
|
|
1295
|
+
let gainMap;
|
|
1296
|
+
let metadata;
|
|
1297
|
+
const loadCheck = async () => {
|
|
1298
|
+
if (sdr && gainMap && metadata) {
|
|
1299
|
+
await this.render(quadRenderer, gainMap, sdr, metadata);
|
|
1300
|
+
if (typeof onLoad === 'function')
|
|
1301
|
+
onLoad(quadRenderer);
|
|
1302
|
+
quadRenderer.dispose();
|
|
1303
|
+
}
|
|
1304
|
+
};
|
|
1305
|
+
const progressHandler = (e) => {
|
|
1306
|
+
};
|
|
1307
|
+
const sdrLoader = new three.FileLoader(this.manager);
|
|
1308
|
+
sdrLoader.setResponseType('arraybuffer');
|
|
1309
|
+
sdrLoader.setRequestHeader(this.requestHeader);
|
|
1310
|
+
sdrLoader.setPath(this.path);
|
|
1311
|
+
sdrLoader.setWithCredentials(this.withCredentials);
|
|
1312
|
+
sdrLoader.load(sdrUrl, async (buffer) => {
|
|
1313
|
+
if (typeof buffer === 'string')
|
|
1314
|
+
throw new Error('Invalid sdr buffer');
|
|
1315
|
+
sdr = buffer;
|
|
1316
|
+
loadCheck();
|
|
1317
|
+
}, progressHandler, onError);
|
|
1318
|
+
const gainMapLoader = new three.FileLoader(this.manager);
|
|
1319
|
+
gainMapLoader.setResponseType('arraybuffer');
|
|
1320
|
+
gainMapLoader.setRequestHeader(this.requestHeader);
|
|
1321
|
+
gainMapLoader.setPath(this.path);
|
|
1322
|
+
gainMapLoader.setWithCredentials(this.withCredentials);
|
|
1323
|
+
gainMapLoader.load(gainMapUrl, async (buffer) => {
|
|
1324
|
+
if (typeof buffer === 'string')
|
|
1325
|
+
throw new Error('Invalid gainmap buffer');
|
|
1326
|
+
gainMap = buffer;
|
|
1327
|
+
loadCheck();
|
|
1328
|
+
}, progressHandler, onError);
|
|
1329
|
+
const metadataLoader = new three.FileLoader(this.manager);
|
|
1330
|
+
// metadataLoader.setResponseType('json')
|
|
1331
|
+
metadataLoader.setRequestHeader(this.requestHeader);
|
|
1332
|
+
metadataLoader.setPath(this.path);
|
|
1333
|
+
metadataLoader.setWithCredentials(this.withCredentials);
|
|
1334
|
+
metadataLoader.load(metadataUrl, async (json) => {
|
|
1335
|
+
if (typeof json !== 'string')
|
|
1336
|
+
throw new Error('Invalid metadata string');
|
|
1337
|
+
metadata = JSON.parse(json);
|
|
1338
|
+
loadCheck();
|
|
1339
|
+
}, progressHandler, onError);
|
|
1340
|
+
return quadRenderer;
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1054
1344
|
exports.GainMapDecoderMaterial = GainMapDecoderMaterial;
|
|
1055
1345
|
exports.GainMapEncoderMaterial = GainMapEncoderMaterial;
|
|
1346
|
+
exports.GainMapLoader = GainMapLoader;
|
|
1056
1347
|
exports.QuadRenderer = QuadRenderer;
|
|
1057
1348
|
exports.SDRMaterial = SDRMaterial;
|
|
1058
1349
|
exports.compress = compress;
|
|
Binary file
|
package/dist/libultrahdr.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MainModule } from '../libultrahdr-wasm/build/libultrahdr';
|
|
2
2
|
import { CompressedImage, GainMapMetadata } from './types';
|
|
3
3
|
export * from '../libultrahdr-wasm/build/libultrahdr';
|
|
4
|
+
export * from './loaders/JPEGRLoader';
|
|
4
5
|
/**
|
|
5
6
|
* Instances the WASM module and returns it, only one module will be created upon multiple calls.
|
|
6
7
|
* @category General
|
|
@@ -35,9 +36,17 @@ export declare const getLibrary: () => Promise<MainModule>;
|
|
|
35
36
|
* })
|
|
36
37
|
*
|
|
37
38
|
* // obtain the RAW RGBA SDR buffer and create an ImageData
|
|
38
|
-
* const sdrImageData = new ImageData(
|
|
39
|
+
* const sdrImageData = new ImageData(
|
|
40
|
+
* encodingResult.sdr.toArray(),
|
|
41
|
+
* encodingResult.sdr.width,
|
|
42
|
+
* encodingResult.sdr.height
|
|
43
|
+
* )
|
|
39
44
|
* // obtain the RAW RGBA Gain map buffer and create an ImageData
|
|
40
|
-
* const gainMapImageData = new ImageData(
|
|
45
|
+
* const gainMapImageData = new ImageData(
|
|
46
|
+
* encodingResult.gainMap.toArray(),
|
|
47
|
+
* encodingResult.gainMap.width,
|
|
48
|
+
* encodingResult.gainMap.height
|
|
49
|
+
* )
|
|
41
50
|
*
|
|
42
51
|
* // parallel compress the RAW buffers into the specified mimeType
|
|
43
52
|
* const mimeType = 'image/jpeg'
|
|
@@ -90,27 +99,13 @@ export declare const encodeJPEGMetadata: (encodingResult: GainMapMetadata & {
|
|
|
90
99
|
* @group Decoding
|
|
91
100
|
*
|
|
92
101
|
* @example
|
|
93
|
-
* import { decode } from '@monogrid/gainmap-js'
|
|
94
102
|
* import { decodeJPEGMetadata } from '@monogrid/gainmap-js/libultrahdr'
|
|
95
|
-
*
|
|
103
|
+
*
|
|
96
104
|
* // fetch a JPEG image containing a gainmap as ArrayBuffer
|
|
97
|
-
* const gainmap = await (await fetch('gainmap.jpeg')).arrayBuffer()
|
|
105
|
+
* const gainmap = new Uint8Array(await (await fetch('gainmap.jpeg')).arrayBuffer())
|
|
98
106
|
*
|
|
99
107
|
* // extract data from the JPEG
|
|
100
|
-
* const {
|
|
101
|
-
*
|
|
102
|
-
* // restore the HDR texture
|
|
103
|
-
* const result = await decode({
|
|
104
|
-
* sdr,
|
|
105
|
-
* gainMap,
|
|
106
|
-
* // this will restore the full HDR range
|
|
107
|
-
* maxDisplayBoost: Math.pow(2, parsedMetadata.hdrCapacityMax),
|
|
108
|
-
* ...parsedMetadata
|
|
109
|
-
* })
|
|
110
|
-
*
|
|
111
|
-
* // result can be used to populate a Texture
|
|
112
|
-
* const mesh = new Mesh(new PlaneGeometry(), new MeshBasicMaterial({ map: result.renderTarget.texture }))
|
|
113
|
-
*
|
|
108
|
+
* const { gainMap, sdr, parsedMetadata } = await decodeJPEGMetadata(gainmap)
|
|
114
109
|
*
|
|
115
110
|
* @param file A Jpeg file Uint8Array.
|
|
116
111
|
* @returns The decoded data
|