@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 +16 -0
- package/README.md +10 -2
- package/dist/{QuadRenderer-bEJB0XFk.js → QuadRenderer-QXcVmgNm.js} +61 -5
- package/dist/{_commonjsHelpers-bdHH9bEd.js → _commonjsHelpers-ftl_lJMx.js} +1 -1
- package/dist/{compress-aBsBfoFB.js → compress-MvOX-rlz.js} +2 -2
- package/dist/core/QuadRenderer.d.ts +38 -1
- package/dist/decode/decode.d.ts +3 -0
- package/dist/decode/errors/GainMapNotFoundError.d.ts +2 -0
- package/dist/decode/errors/XMPMetadataNotFoundError.d.ts +2 -0
- package/dist/decode/loaders/GainMapLoader.d.ts +5 -1
- package/dist/decode/loaders/HDRJPGLoader.d.ts +9 -5
- package/dist/decode/loaders/LoaderBase.d.ts +12 -9
- package/dist/decode/utils/get-html-image-from-blob.d.ts +7 -0
- package/dist/decode.js +130 -55
- package/dist/decode.umd.js +187 -56
- package/dist/encode/encode.d.ts +4 -1
- package/dist/encode.js +31 -14
- package/dist/encode.umd.js +88 -15
- package/dist/libultrahdr.js +5 -3
- package/dist/libultrahdr.umd.js +5 -3
- package/dist/worker-interface.js +2 -2
- package/dist/worker-interface.umd.js +1 -1
- package/dist/worker.js +7 -4
- package/dist/worker.umd.js +6 -3
- package/package.json +23 -18
package/dist/decode.umd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @monogrid/gainmap-js v2.0.
|
|
2
|
+
* @monogrid/gainmap-js v2.0.6
|
|
3
3
|
* With ❤️, by MONOGRID <hello@mono-grid.com>
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
return _canReadPixelsResult;
|
|
56
56
|
const testRT = new three.WebGLRenderTarget(1, 1, {
|
|
57
57
|
type,
|
|
58
|
-
colorSpace: three.
|
|
58
|
+
colorSpace: three.LinearSRGBColorSpace,
|
|
59
59
|
format: three.RGBAFormat,
|
|
60
60
|
magFilter: three.LinearFilter,
|
|
61
61
|
minFilter: three.LinearFilter,
|
|
@@ -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
|
-
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.
|
|
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
|
-
|
|
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
|
|
@@ -441,26 +500,35 @@ void main() {
|
|
|
441
500
|
sdr.colorSpace = three.SRGBColorSpace;
|
|
442
501
|
}
|
|
443
502
|
sdr.needsUpdate = true;
|
|
444
|
-
if (gainMap.colorSpace !== three.
|
|
445
|
-
console.warn('Gainmap Colorspace needs to be *
|
|
446
|
-
gainMap.colorSpace = three.
|
|
503
|
+
if (gainMap.colorSpace !== three.LinearSRGBColorSpace) {
|
|
504
|
+
console.warn('Gainmap Colorspace needs to be *LinearSRGBColorSpace*');
|
|
505
|
+
gainMap.colorSpace = three.LinearSRGBColorSpace;
|
|
447
506
|
}
|
|
448
507
|
gainMap.needsUpdate = true;
|
|
449
|
-
const material = new GainMapDecoderMaterial(
|
|
450
|
-
|
|
508
|
+
const material = new GainMapDecoderMaterial({
|
|
509
|
+
...params,
|
|
510
|
+
sdr,
|
|
511
|
+
gainMap
|
|
512
|
+
});
|
|
451
513
|
// TODO: three types are generic, eslint complains here, see how we can solve
|
|
452
514
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
|
|
453
|
-
const quadRenderer = new QuadRenderer(sdr.image.width, sdr.image.height, three.HalfFloatType, three.
|
|
515
|
+
const quadRenderer = new QuadRenderer(sdr.image.width, sdr.image.height, three.HalfFloatType, three.LinearSRGBColorSpace, material, renderer);
|
|
454
516
|
try {
|
|
455
517
|
quadRenderer.render();
|
|
456
518
|
}
|
|
457
519
|
catch (e) {
|
|
458
|
-
quadRenderer.
|
|
520
|
+
quadRenderer.disposeOnDemandRenderer();
|
|
459
521
|
throw e;
|
|
460
522
|
}
|
|
461
523
|
return quadRenderer;
|
|
462
524
|
};
|
|
463
525
|
|
|
526
|
+
class GainMapNotFoundError extends Error {
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
class XMPMetadataNotFoundError extends Error {
|
|
530
|
+
}
|
|
531
|
+
|
|
464
532
|
const getAttribute = (description, name, defaultValue) => {
|
|
465
533
|
var _a;
|
|
466
534
|
let returnValue;
|
|
@@ -496,7 +564,7 @@ void main() {
|
|
|
496
564
|
const extractXMP = (input) => {
|
|
497
565
|
var _a, _b;
|
|
498
566
|
let str;
|
|
499
|
-
// support node test
|
|
567
|
+
// support node test environment
|
|
500
568
|
if (typeof TextDecoder !== 'undefined')
|
|
501
569
|
str = new TextDecoder().decode(input);
|
|
502
570
|
else
|
|
@@ -563,7 +631,7 @@ void main() {
|
|
|
563
631
|
// If you're executing this line on a big endian machine, it'll be reversed.
|
|
564
632
|
// bigEnd further down though, refers to the endianness of the image itself.
|
|
565
633
|
if (dataView.getUint16(0) !== 0xffd8) {
|
|
566
|
-
reject('Not a valid jpeg');
|
|
634
|
+
reject(new Error('Not a valid jpeg'));
|
|
567
635
|
return;
|
|
568
636
|
}
|
|
569
637
|
const length = dataView.byteLength;
|
|
@@ -572,11 +640,11 @@ void main() {
|
|
|
572
640
|
let marker; // APP# marker
|
|
573
641
|
while (offset < length) {
|
|
574
642
|
if (++loops > 250) {
|
|
575
|
-
reject(`Found no marker after ${loops} loops 😵`);
|
|
643
|
+
reject(new Error(`Found no marker after ${loops} loops 😵`));
|
|
576
644
|
return;
|
|
577
645
|
}
|
|
578
646
|
if (dataView.getUint8(offset) !== 0xff) {
|
|
579
|
-
reject(`Not a valid marker at offset 0x${offset.toString(16)}, found: 0x${dataView.getUint8(offset).toString(16)}`);
|
|
647
|
+
reject(new Error(`Not a valid marker at offset 0x${offset.toString(16)}, found: 0x${dataView.getUint8(offset).toString(16)}`));
|
|
580
648
|
return;
|
|
581
649
|
}
|
|
582
650
|
marker = dataView.getUint8(offset + 1);
|
|
@@ -616,18 +684,18 @@ void main() {
|
|
|
616
684
|
bigEnd = true;
|
|
617
685
|
}
|
|
618
686
|
else {
|
|
619
|
-
reject('No valid endianness marker found in TIFF header');
|
|
687
|
+
reject(new Error('No valid endianness marker found in TIFF header'));
|
|
620
688
|
return;
|
|
621
689
|
}
|
|
622
690
|
if (dataView.getUint16(tiffOffset + 2, !bigEnd) !== 0x002a) {
|
|
623
|
-
reject('Not valid TIFF data! (no 0x002A marker)');
|
|
691
|
+
reject(new Error('Not valid TIFF data! (no 0x002A marker)'));
|
|
624
692
|
return;
|
|
625
693
|
}
|
|
626
694
|
// 32 bit number stating the offset from the start of the 8 Byte MP Header
|
|
627
695
|
// to MP Index IFD Least possible value is thus 8 (means 0 offset)
|
|
628
696
|
const firstIFDOffset = dataView.getUint32(tiffOffset + 4, !bigEnd);
|
|
629
697
|
if (firstIFDOffset < 0x00000008) {
|
|
630
|
-
reject('Not valid TIFF data! (First offset less than 8)');
|
|
698
|
+
reject(new Error('Not valid TIFF data! (First offset less than 8)'));
|
|
631
699
|
return;
|
|
632
700
|
}
|
|
633
701
|
// Move ahead to MP Index IFD
|
|
@@ -723,11 +791,11 @@ void main() {
|
|
|
723
791
|
const extractGainmapFromJPEG = async (jpegFile) => {
|
|
724
792
|
const metadata = extractXMP(jpegFile);
|
|
725
793
|
if (!metadata)
|
|
726
|
-
throw new
|
|
794
|
+
throw new XMPMetadataNotFoundError('Gain map XMP metadata not found');
|
|
727
795
|
const mpfExtractor = new MPFExtractor({ extractFII: true, extractNonFII: true });
|
|
728
796
|
const images = await mpfExtractor.extract(jpegFile);
|
|
729
797
|
if (images.length !== 2)
|
|
730
|
-
throw new
|
|
798
|
+
throw new GainMapNotFoundError('Gain map recovery image not found');
|
|
731
799
|
return {
|
|
732
800
|
sdr: new Uint8Array(await images[0].arrayBuffer()),
|
|
733
801
|
gainMap: new Uint8Array(await images[1].arrayBuffer()),
|
|
@@ -741,7 +809,7 @@ void main() {
|
|
|
741
809
|
* @param blob
|
|
742
810
|
* @returns
|
|
743
811
|
*/
|
|
744
|
-
const
|
|
812
|
+
const getHTMLImageFromBlob = (blob) => {
|
|
745
813
|
return new Promise((resolve, reject) => {
|
|
746
814
|
const img = document.createElement('img');
|
|
747
815
|
img.onload = () => { resolve(img); };
|
|
@@ -749,6 +817,7 @@ void main() {
|
|
|
749
817
|
img.src = URL.createObjectURL(blob);
|
|
750
818
|
});
|
|
751
819
|
};
|
|
820
|
+
|
|
752
821
|
class LoaderBase extends three.Loader {
|
|
753
822
|
/**
|
|
754
823
|
*
|
|
@@ -757,7 +826,8 @@ void main() {
|
|
|
757
826
|
*/
|
|
758
827
|
constructor(renderer, manager) {
|
|
759
828
|
super(manager);
|
|
760
|
-
this.
|
|
829
|
+
this._renderer = renderer;
|
|
830
|
+
this._internalLoadingManager = new three.LoadingManager();
|
|
761
831
|
}
|
|
762
832
|
/**
|
|
763
833
|
* @private
|
|
@@ -777,26 +847,26 @@ void main() {
|
|
|
777
847
|
gainMap: new three.Texture(),
|
|
778
848
|
sdr: new three.Texture()
|
|
779
849
|
});
|
|
780
|
-
return new QuadRenderer(16, 16, three.HalfFloatType, three.
|
|
850
|
+
return new QuadRenderer(16, 16, three.HalfFloatType, three.LinearSRGBColorSpace, material, this._renderer);
|
|
781
851
|
}
|
|
782
852
|
/**
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
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;
|
|
792
862
|
const sdrBlob = new Blob([sdrBuffer], { type: 'image/jpeg' });
|
|
793
863
|
let sdrImage;
|
|
794
864
|
let gainMapImage;
|
|
795
865
|
let needsFlip = false;
|
|
796
866
|
if (typeof createImageBitmap === 'undefined') {
|
|
797
867
|
const res = await Promise.all([
|
|
798
|
-
|
|
799
|
-
|
|
868
|
+
gainMapBlob ? getHTMLImageFromBlob(gainMapBlob) : Promise.resolve(undefined),
|
|
869
|
+
getHTMLImageFromBlob(sdrBlob)
|
|
800
870
|
]);
|
|
801
871
|
gainMapImage = res[0];
|
|
802
872
|
sdrImage = res[1];
|
|
@@ -804,13 +874,13 @@ void main() {
|
|
|
804
874
|
}
|
|
805
875
|
else {
|
|
806
876
|
const res = await Promise.all([
|
|
807
|
-
createImageBitmap(gainMapBlob, { imageOrientation: 'flipY' }),
|
|
877
|
+
gainMapBlob ? createImageBitmap(gainMapBlob, { imageOrientation: 'flipY' }) : Promise.resolve(undefined),
|
|
808
878
|
createImageBitmap(sdrBlob, { imageOrientation: 'flipY' })
|
|
809
879
|
]);
|
|
810
880
|
gainMapImage = res[0];
|
|
811
881
|
sdrImage = res[1];
|
|
812
882
|
}
|
|
813
|
-
const gainMap = new three.Texture(gainMapImage, three.UVMapping, three.ClampToEdgeWrapping, three.ClampToEdgeWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, three.RGBAFormat, three.UnsignedByteType, 1, three.
|
|
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);
|
|
814
884
|
gainMap.flipY = needsFlip;
|
|
815
885
|
gainMap.needsUpdate = true;
|
|
816
886
|
const sdr = new three.Texture(sdrImage, three.UVMapping, three.ClampToEdgeWrapping, three.ClampToEdgeWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, three.RGBAFormat, three.UnsignedByteType, 1, three.SRGBColorSpace);
|
|
@@ -856,7 +926,7 @@ void main() {
|
|
|
856
926
|
*
|
|
857
927
|
* const loader = new GainMapLoader(renderer)
|
|
858
928
|
*
|
|
859
|
-
* const result = loader.
|
|
929
|
+
* const result = await loader.loadAsync(['sdr.jpeg', 'gainmap.jpeg', 'metadata.json'])
|
|
860
930
|
* // `result` can be used to populate a Texture
|
|
861
931
|
*
|
|
862
932
|
* const scene = new Scene()
|
|
@@ -876,6 +946,10 @@ void main() {
|
|
|
876
946
|
* scene.background.mapping = EquirectangularReflectionMapping
|
|
877
947
|
* scene.background.minFilter = LinearFilter
|
|
878
948
|
*
|
|
949
|
+
* // result must be manually disposed
|
|
950
|
+
* // when you are done using it
|
|
951
|
+
* result.dispose()
|
|
952
|
+
*
|
|
879
953
|
*/
|
|
880
954
|
class GainMapLoader extends LoaderBase {
|
|
881
955
|
/**
|
|
@@ -899,10 +973,13 @@ void main() {
|
|
|
899
973
|
let metadata;
|
|
900
974
|
const loadCheck = async () => {
|
|
901
975
|
if (sdr && gainMap && metadata) {
|
|
902
|
-
await this.render(quadRenderer,
|
|
976
|
+
await this.render(quadRenderer, metadata, sdr, gainMap);
|
|
903
977
|
if (typeof onLoad === 'function')
|
|
904
978
|
onLoad(quadRenderer);
|
|
905
|
-
|
|
979
|
+
this.manager.itemEnd(sdrUrl);
|
|
980
|
+
this.manager.itemEnd(gainMapUrl);
|
|
981
|
+
this.manager.itemEnd(metadataUrl);
|
|
982
|
+
quadRenderer.disposeOnDemandRenderer();
|
|
906
983
|
}
|
|
907
984
|
};
|
|
908
985
|
let sdrLengthComputable = true;
|
|
@@ -922,7 +999,10 @@ void main() {
|
|
|
922
999
|
onProgress(new ProgressEvent('progress', { lengthComputable, loaded, total }));
|
|
923
1000
|
}
|
|
924
1001
|
};
|
|
925
|
-
|
|
1002
|
+
this.manager.itemStart(sdrUrl);
|
|
1003
|
+
this.manager.itemStart(gainMapUrl);
|
|
1004
|
+
this.manager.itemStart(metadataUrl);
|
|
1005
|
+
const sdrLoader = new three.FileLoader(this._internalLoadingManager);
|
|
926
1006
|
sdrLoader.setResponseType('arraybuffer');
|
|
927
1007
|
sdrLoader.setRequestHeader(this.requestHeader);
|
|
928
1008
|
sdrLoader.setPath(this.path);
|
|
@@ -937,8 +1017,12 @@ void main() {
|
|
|
937
1017
|
sdrLoaded = e.loaded;
|
|
938
1018
|
sdrTotal = e.total;
|
|
939
1019
|
progressHandler();
|
|
940
|
-
},
|
|
941
|
-
|
|
1020
|
+
}, (error) => {
|
|
1021
|
+
this.manager.itemError(sdrUrl);
|
|
1022
|
+
if (typeof onError === 'function')
|
|
1023
|
+
onError(error);
|
|
1024
|
+
});
|
|
1025
|
+
const gainMapLoader = new three.FileLoader(this._internalLoadingManager);
|
|
942
1026
|
gainMapLoader.setResponseType('arraybuffer');
|
|
943
1027
|
gainMapLoader.setRequestHeader(this.requestHeader);
|
|
944
1028
|
gainMapLoader.setPath(this.path);
|
|
@@ -953,8 +1037,12 @@ void main() {
|
|
|
953
1037
|
gainMapLoaded = e.loaded;
|
|
954
1038
|
gainMapTotal = e.total;
|
|
955
1039
|
progressHandler();
|
|
956
|
-
},
|
|
957
|
-
|
|
1040
|
+
}, (error) => {
|
|
1041
|
+
this.manager.itemError(gainMapUrl);
|
|
1042
|
+
if (typeof onError === 'function')
|
|
1043
|
+
onError(error);
|
|
1044
|
+
});
|
|
1045
|
+
const metadataLoader = new three.FileLoader(this._internalLoadingManager);
|
|
958
1046
|
// metadataLoader.setResponseType('json')
|
|
959
1047
|
metadataLoader.setRequestHeader(this.requestHeader);
|
|
960
1048
|
metadataLoader.setPath(this.path);
|
|
@@ -971,7 +1059,11 @@ void main() {
|
|
|
971
1059
|
metadataLoaded = e.loaded;
|
|
972
1060
|
metadataTotal = e.total;
|
|
973
1061
|
progressHandler();
|
|
974
|
-
},
|
|
1062
|
+
}, (error) => {
|
|
1063
|
+
this.manager.itemError(metadataUrl);
|
|
1064
|
+
if (typeof onError === 'function')
|
|
1065
|
+
onError(error);
|
|
1066
|
+
});
|
|
975
1067
|
return quadRenderer;
|
|
976
1068
|
}
|
|
977
1069
|
}
|
|
@@ -983,7 +1075,7 @@ void main() {
|
|
|
983
1075
|
* @group Loaders
|
|
984
1076
|
*
|
|
985
1077
|
* @example
|
|
986
|
-
* import {
|
|
1078
|
+
* import { HDRJPGLoader } from '@monogrid/gainmap-js'
|
|
987
1079
|
* import {
|
|
988
1080
|
* EquirectangularReflectionMapping,
|
|
989
1081
|
* LinearFilter,
|
|
@@ -997,9 +1089,9 @@ void main() {
|
|
|
997
1089
|
*
|
|
998
1090
|
* const renderer = new WebGLRenderer()
|
|
999
1091
|
*
|
|
1000
|
-
* const loader = new
|
|
1092
|
+
* const loader = new HDRJPGLoader(renderer)
|
|
1001
1093
|
*
|
|
1002
|
-
* const result = loader.
|
|
1094
|
+
* const result = await loader.loadAsync('gainmap.jpeg')
|
|
1003
1095
|
* // `result` can be used to populate a Texture
|
|
1004
1096
|
*
|
|
1005
1097
|
* const scene = new Scene()
|
|
@@ -1018,12 +1110,16 @@ void main() {
|
|
|
1018
1110
|
* scene.background = result.toDataTexture()
|
|
1019
1111
|
* scene.background.mapping = EquirectangularReflectionMapping
|
|
1020
1112
|
* scene.background.minFilter = LinearFilter
|
|
1021
|
-
|
|
1113
|
+
*
|
|
1114
|
+
* // result must be manually disposed
|
|
1115
|
+
* // when you are done using it
|
|
1116
|
+
* result.dispose()
|
|
1022
1117
|
*
|
|
1023
1118
|
*/
|
|
1024
1119
|
class HDRJPGLoader extends LoaderBase {
|
|
1025
1120
|
/**
|
|
1026
|
-
* Loads a
|
|
1121
|
+
* Loads a JPEG containing gain map metadata
|
|
1122
|
+
* Renders a normal SDR image if gainmap data is not found
|
|
1027
1123
|
*
|
|
1028
1124
|
* @param url An array in the form of [sdr.jpg, gainmap.jpg, metadata.json]
|
|
1029
1125
|
* @param onLoad Load complete callback, will receive the result
|
|
@@ -1033,20 +1129,55 @@ void main() {
|
|
|
1033
1129
|
*/
|
|
1034
1130
|
load(url, onLoad, onProgress, onError) {
|
|
1035
1131
|
const quadRenderer = this.prepareQuadRenderer();
|
|
1036
|
-
const loader = new three.FileLoader(this.
|
|
1132
|
+
const loader = new three.FileLoader(this._internalLoadingManager);
|
|
1037
1133
|
loader.setResponseType('arraybuffer');
|
|
1038
1134
|
loader.setRequestHeader(this.requestHeader);
|
|
1039
1135
|
loader.setPath(this.path);
|
|
1040
1136
|
loader.setWithCredentials(this.withCredentials);
|
|
1137
|
+
this.manager.itemStart(url);
|
|
1041
1138
|
loader.load(url, async (jpeg) => {
|
|
1042
1139
|
if (typeof jpeg === 'string')
|
|
1043
|
-
throw new Error('Invalid buffer');
|
|
1044
|
-
const
|
|
1045
|
-
|
|
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);
|
|
1046
1172
|
if (typeof onLoad === 'function')
|
|
1047
1173
|
onLoad(quadRenderer);
|
|
1048
|
-
|
|
1049
|
-
|
|
1174
|
+
this.manager.itemEnd(url);
|
|
1175
|
+
quadRenderer.disposeOnDemandRenderer();
|
|
1176
|
+
}, onProgress, (error) => {
|
|
1177
|
+
this.manager.itemError(url);
|
|
1178
|
+
if (typeof onError === 'function')
|
|
1179
|
+
onError(error);
|
|
1180
|
+
});
|
|
1050
1181
|
return quadRenderer;
|
|
1051
1182
|
}
|
|
1052
1183
|
}
|
package/dist/encode/encode.d.ts
CHANGED
|
@@ -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
|
-
* //
|
|
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.
|
|
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-
|
|
7
|
-
import { DataTexture, RGBAFormat, UVMapping, RepeatWrapping, LinearFilter,
|
|
8
|
-
import { Q as QuadRenderer } from './QuadRenderer-
|
|
6
|
+
import { c as compress } from './compress-MvOX-rlz.js';
|
|
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-QXcVmgNm.js';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Utility function to obtain a `DataTexture` from various input formats
|
|
@@ -25,7 +25,7 @@ const getDataTexture = (image) => {
|
|
|
25
25
|
dataTexture = image;
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
|
-
dataTexture = new DataTexture(image.data, image.width, image.height, 'format' in image ? image.format : RGBAFormat, image.type, UVMapping, RepeatWrapping, RepeatWrapping, LinearFilter, LinearFilter, 1, 'colorSpace' in image && image.colorSpace === 'srgb' ? image.colorSpace :
|
|
28
|
+
dataTexture = new DataTexture(image.data, image.width, image.height, 'format' in image ? image.format : RGBAFormat, image.type, UVMapping, RepeatWrapping, RepeatWrapping, LinearFilter, LinearFilter, 1, 'colorSpace' in image && image.colorSpace === 'srgb' ? image.colorSpace : LinearSRGBColorSpace);
|
|
29
29
|
// TODO: This tries to detect a raw RGBE and applies flipY
|
|
30
30
|
// see if there's a better way to detect it?
|
|
31
31
|
if ('header' in image && 'gamma' in image) {
|
|
@@ -190,13 +190,17 @@ class GainMapEncoderMaterial extends ShaderMaterial {
|
|
|
190
190
|
const getGainMap = (params) => {
|
|
191
191
|
const { image, sdr, renderer } = params;
|
|
192
192
|
const dataTexture = getDataTexture(image);
|
|
193
|
-
const material = new GainMapEncoderMaterial(
|
|
194
|
-
|
|
193
|
+
const material = new GainMapEncoderMaterial({
|
|
194
|
+
...params,
|
|
195
|
+
sdr: sdr.renderTarget.texture,
|
|
196
|
+
hdr: dataTexture
|
|
197
|
+
});
|
|
198
|
+
const quadRenderer = new QuadRenderer(dataTexture.image.width, dataTexture.image.height, UnsignedByteType, LinearSRGBColorSpace, material, renderer);
|
|
195
199
|
try {
|
|
196
200
|
quadRenderer.render();
|
|
197
201
|
}
|
|
198
202
|
catch (e) {
|
|
199
|
-
quadRenderer.
|
|
203
|
+
quadRenderer.disposeOnDemandRenderer();
|
|
200
204
|
throw e;
|
|
201
205
|
}
|
|
202
206
|
return quadRenderer;
|
|
@@ -423,7 +427,7 @@ const getSDRRendition = (hdrTexture, renderer, toneMapping) => {
|
|
|
423
427
|
quadRenderer.render();
|
|
424
428
|
}
|
|
425
429
|
catch (e) {
|
|
426
|
-
quadRenderer.
|
|
430
|
+
quadRenderer.disposeOnDemandRenderer();
|
|
427
431
|
throw e;
|
|
428
432
|
}
|
|
429
433
|
return quadRenderer;
|
|
@@ -472,7 +476,10 @@ const getSDRRendition = (hdrTexture, renderer, toneMapping) => {
|
|
|
472
476
|
* encodingResult.gainMap.material.gamma = [1.1, 1.1, 1.1]
|
|
473
477
|
* encodingResult.gainMap.render()
|
|
474
478
|
*
|
|
475
|
-
* //
|
|
479
|
+
* // do something with encodingResult.gainMap.toArray()
|
|
480
|
+
* // and encodingResult.sdr.toArray()
|
|
481
|
+
*
|
|
482
|
+
* // renderers must be manually disposed
|
|
476
483
|
* encodingResult.sdr.dispose()
|
|
477
484
|
* encodingResult.gainMap.dispose()
|
|
478
485
|
*
|
|
@@ -483,8 +490,12 @@ const encode = (params) => {
|
|
|
483
490
|
const { image, renderer } = params;
|
|
484
491
|
const dataTexture = getDataTexture(image);
|
|
485
492
|
const sdr = getSDRRendition(dataTexture, renderer, params.toneMapping);
|
|
486
|
-
const gainMapRenderer = getGainMap(
|
|
487
|
-
|
|
493
|
+
const gainMapRenderer = getGainMap({
|
|
494
|
+
...params,
|
|
495
|
+
image: dataTexture,
|
|
496
|
+
sdr,
|
|
497
|
+
renderer: sdr.renderer // reuse the same (maybe disposable?) renderer
|
|
498
|
+
});
|
|
488
499
|
return {
|
|
489
500
|
sdr,
|
|
490
501
|
gainMap: gainMapRenderer,
|
|
@@ -596,8 +607,14 @@ const encodeAndCompress = async (params) => {
|
|
|
596
607
|
}
|
|
597
608
|
encodingResult.sdr.dispose();
|
|
598
609
|
encodingResult.gainMap.dispose();
|
|
599
|
-
return
|
|
600
|
-
|
|
610
|
+
return {
|
|
611
|
+
...encodingResult,
|
|
612
|
+
...encodingResult.getMetadata(),
|
|
613
|
+
sdr: compressResult[0],
|
|
614
|
+
gainMap: compressResult[1],
|
|
615
|
+
rawSDR,
|
|
616
|
+
rawGainMap
|
|
617
|
+
};
|
|
601
618
|
};
|
|
602
619
|
|
|
603
620
|
const vertexShader = /* glsl */ `
|