@monogrid/gainmap-js 2.0.4 → 2.0.6
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 +15 -0
- package/README.md +3 -3
- package/dist/{QuadRenderer-lU9EAEKl.js → QuadRenderer-gqnZPNP-.js} +7 -7
- package/dist/{_commonjsHelpers-n2Ng5lYw.js → _commonjsHelpers-iRbo2TdN.js} +1 -1
- package/dist/{compress-RL9UE9ww.js → compress-_4jEQonS.js} +2 -2
- package/dist/core/QuadRenderer.d.ts +7 -5
- package/dist/core/get-data-texture.d.ts +2 -2
- package/dist/core/index.d.ts +3 -0
- package/dist/core/types.d.ts +2 -2
- package/dist/decode/decode.d.ts +2 -2
- package/dist/decode/extract.d.ts +17 -2
- package/dist/decode/index.d.ts +2 -1
- package/dist/decode/loaders/GainMapLoader.d.ts +4 -7
- package/dist/decode/loaders/{JPEGRLoader.d.ts → HDRJPGLoader.d.ts} +7 -6
- package/dist/decode/loaders/LoaderBase.d.ts +2 -1
- package/dist/decode/types.d.ts +5 -5
- package/dist/decode.js +91 -46
- package/dist/decode.umd.js +95 -49
- package/dist/encode/find-texture-min-max.d.ts +2 -2
- package/dist/encode/types.d.ts +6 -6
- package/dist/encode.js +31 -15
- package/dist/encode.umd.js +34 -18
- package/dist/libultrahdr/library.d.ts +2 -2
- package/dist/libultrahdr.js +8 -6
- package/dist/libultrahdr.umd.js +8 -6
- package/dist/worker-interface.js +3 -2
- package/dist/worker-interface.umd.js +2 -1
- package/dist/worker.js +8 -4
- package/dist/worker.umd.js +7 -3
- package/package.json +24 -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.5
|
|
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,
|
|
@@ -78,10 +78,10 @@
|
|
|
78
78
|
return _canReadPixelsResult;
|
|
79
79
|
};
|
|
80
80
|
/**
|
|
81
|
-
* Utility
|
|
81
|
+
* Utility class used for rendering a texture with a material
|
|
82
82
|
*
|
|
83
|
-
* @category
|
|
84
|
-
* @group
|
|
83
|
+
* @category Core
|
|
84
|
+
* @group Core
|
|
85
85
|
*/
|
|
86
86
|
class QuadRenderer {
|
|
87
87
|
/**
|
|
@@ -186,7 +186,7 @@
|
|
|
186
186
|
return out;
|
|
187
187
|
}
|
|
188
188
|
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.
|
|
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.LinearSRGBColorSpace);
|
|
190
190
|
}
|
|
191
191
|
/**
|
|
192
192
|
* If using a disposable renderer, it will dispose it.
|
|
@@ -385,8 +385,8 @@ void main() {
|
|
|
385
385
|
/**
|
|
386
386
|
* Decodes a gain map using a WebGLRenderTarget
|
|
387
387
|
*
|
|
388
|
-
* @category Decoding
|
|
389
|
-
* @group Decoding
|
|
388
|
+
* @category Decoding Functions
|
|
389
|
+
* @group Decoding Functions
|
|
390
390
|
* @example
|
|
391
391
|
* import { decode } from '@monogrid/gainmap-js'
|
|
392
392
|
* import {
|
|
@@ -441,14 +441,19 @@ void main() {
|
|
|
441
441
|
sdr.colorSpace = three.SRGBColorSpace;
|
|
442
442
|
}
|
|
443
443
|
sdr.needsUpdate = true;
|
|
444
|
-
if (gainMap.colorSpace !== three.
|
|
445
|
-
console.warn('Gainmap Colorspace needs to be *
|
|
446
|
-
gainMap.colorSpace = three.
|
|
444
|
+
if (gainMap.colorSpace !== three.LinearSRGBColorSpace) {
|
|
445
|
+
console.warn('Gainmap Colorspace needs to be *LinearSRGBColorSpace*');
|
|
446
|
+
gainMap.colorSpace = three.LinearSRGBColorSpace;
|
|
447
447
|
}
|
|
448
448
|
gainMap.needsUpdate = true;
|
|
449
|
-
const material = new GainMapDecoderMaterial(
|
|
450
|
-
|
|
451
|
-
|
|
449
|
+
const material = new GainMapDecoderMaterial({
|
|
450
|
+
...params,
|
|
451
|
+
sdr,
|
|
452
|
+
gainMap
|
|
453
|
+
});
|
|
454
|
+
// TODO: three types are generic, eslint complains here, see how we can solve
|
|
455
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
|
|
456
|
+
const quadRenderer = new QuadRenderer(sdr.image.width, sdr.image.height, three.HalfFloatType, three.LinearSRGBColorSpace, material, renderer);
|
|
452
457
|
try {
|
|
453
458
|
quadRenderer.render();
|
|
454
459
|
}
|
|
@@ -561,7 +566,7 @@ void main() {
|
|
|
561
566
|
// If you're executing this line on a big endian machine, it'll be reversed.
|
|
562
567
|
// bigEnd further down though, refers to the endianness of the image itself.
|
|
563
568
|
if (dataView.getUint16(0) !== 0xffd8) {
|
|
564
|
-
reject('Not a valid jpeg');
|
|
569
|
+
reject(new Error('Not a valid jpeg'));
|
|
565
570
|
return;
|
|
566
571
|
}
|
|
567
572
|
const length = dataView.byteLength;
|
|
@@ -570,11 +575,11 @@ void main() {
|
|
|
570
575
|
let marker; // APP# marker
|
|
571
576
|
while (offset < length) {
|
|
572
577
|
if (++loops > 250) {
|
|
573
|
-
reject(`Found no marker after ${loops} loops 😵`);
|
|
578
|
+
reject(new Error(`Found no marker after ${loops} loops 😵`));
|
|
574
579
|
return;
|
|
575
580
|
}
|
|
576
581
|
if (dataView.getUint8(offset) !== 0xff) {
|
|
577
|
-
reject(`Not a valid marker at offset 0x${offset.toString(16)}, found: 0x${dataView.getUint8(offset).toString(16)}`);
|
|
582
|
+
reject(new Error(`Not a valid marker at offset 0x${offset.toString(16)}, found: 0x${dataView.getUint8(offset).toString(16)}`));
|
|
578
583
|
return;
|
|
579
584
|
}
|
|
580
585
|
marker = dataView.getUint8(offset + 1);
|
|
@@ -614,18 +619,18 @@ void main() {
|
|
|
614
619
|
bigEnd = true;
|
|
615
620
|
}
|
|
616
621
|
else {
|
|
617
|
-
reject('No valid endianness marker found in TIFF header');
|
|
622
|
+
reject(new Error('No valid endianness marker found in TIFF header'));
|
|
618
623
|
return;
|
|
619
624
|
}
|
|
620
625
|
if (dataView.getUint16(tiffOffset + 2, !bigEnd) !== 0x002a) {
|
|
621
|
-
reject('Not valid TIFF data! (no 0x002A marker)');
|
|
626
|
+
reject(new Error('Not valid TIFF data! (no 0x002A marker)'));
|
|
622
627
|
return;
|
|
623
628
|
}
|
|
624
629
|
// 32 bit number stating the offset from the start of the 8 Byte MP Header
|
|
625
630
|
// to MP Index IFD Least possible value is thus 8 (means 0 offset)
|
|
626
631
|
const firstIFDOffset = dataView.getUint32(tiffOffset + 4, !bigEnd);
|
|
627
632
|
if (firstIFDOffset < 0x00000008) {
|
|
628
|
-
reject('Not valid TIFF data! (First offset less than 8)');
|
|
633
|
+
reject(new Error('Not valid TIFF data! (First offset less than 8)'));
|
|
629
634
|
return;
|
|
630
635
|
}
|
|
631
636
|
// Move ahead to MP Index IFD
|
|
@@ -699,9 +704,24 @@ void main() {
|
|
|
699
704
|
}
|
|
700
705
|
|
|
701
706
|
/**
|
|
707
|
+
* Extracts XMP Metadata and the gain map recovery image
|
|
708
|
+
* from a single JPEG file.
|
|
702
709
|
*
|
|
703
|
-
* @
|
|
704
|
-
* @
|
|
710
|
+
* @category Decoding Functions
|
|
711
|
+
* @group Decoding Functions
|
|
712
|
+
* @param jpegFile an `Uint8Array` containing and encoded JPEG file
|
|
713
|
+
* @returns an sdr `Uint8Array` compressed in JPEG, a gainMap `Uint8Array` compressed in JPEG and the XMP parsed XMP metadata
|
|
714
|
+
* @throws Error if XMP Metadata is not found
|
|
715
|
+
* @throws Error if Gain map image is not found
|
|
716
|
+
* @example
|
|
717
|
+
* import { FileLoader } from 'three'
|
|
718
|
+
* import { extractGainmapFromJPEG } from '@monogrid/gainmap-js'
|
|
719
|
+
*
|
|
720
|
+
* const jpegFile = await new FileLoader()
|
|
721
|
+
* .setResponseType('arraybuffer')
|
|
722
|
+
* .loadAsync('image.jpg')
|
|
723
|
+
*
|
|
724
|
+
* const { sdr, gainMap, metadata } = extractGainmapFromJPEG(jpegFile)
|
|
705
725
|
*/
|
|
706
726
|
const extractGainmapFromJPEG = async (jpegFile) => {
|
|
707
727
|
const metadata = extractXMP(jpegFile);
|
|
@@ -740,7 +760,8 @@ void main() {
|
|
|
740
760
|
*/
|
|
741
761
|
constructor(renderer, manager) {
|
|
742
762
|
super(manager);
|
|
743
|
-
this.
|
|
763
|
+
this._renderer = renderer;
|
|
764
|
+
this._internalLoadingManager = new three.LoadingManager();
|
|
744
765
|
}
|
|
745
766
|
/**
|
|
746
767
|
* @private
|
|
@@ -760,7 +781,7 @@ void main() {
|
|
|
760
781
|
gainMap: new three.Texture(),
|
|
761
782
|
sdr: new three.Texture()
|
|
762
783
|
});
|
|
763
|
-
return new QuadRenderer(16, 16, three.HalfFloatType, three.
|
|
784
|
+
return new QuadRenderer(16, 16, three.HalfFloatType, three.LinearSRGBColorSpace, material, this._renderer);
|
|
764
785
|
}
|
|
765
786
|
/**
|
|
766
787
|
*
|
|
@@ -793,7 +814,7 @@ void main() {
|
|
|
793
814
|
gainMapImage = res[0];
|
|
794
815
|
sdrImage = res[1];
|
|
795
816
|
}
|
|
796
|
-
const gainMap = new three.Texture(gainMapImage, three.UVMapping, three.ClampToEdgeWrapping, three.ClampToEdgeWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, three.RGBAFormat, three.UnsignedByteType, 1, three.
|
|
817
|
+
const gainMap = new three.Texture(gainMapImage, three.UVMapping, three.ClampToEdgeWrapping, three.ClampToEdgeWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, three.RGBAFormat, three.UnsignedByteType, 1, three.LinearSRGBColorSpace);
|
|
797
818
|
gainMap.flipY = needsFlip;
|
|
798
819
|
gainMap.needsUpdate = true;
|
|
799
820
|
const sdr = new three.Texture(sdrImage, three.UVMapping, three.ClampToEdgeWrapping, three.ClampToEdgeWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, three.RGBAFormat, three.UnsignedByteType, 1, three.SRGBColorSpace);
|
|
@@ -859,7 +880,6 @@ void main() {
|
|
|
859
880
|
* scene.background.mapping = EquirectangularReflectionMapping
|
|
860
881
|
* scene.background.minFilter = LinearFilter
|
|
861
882
|
*
|
|
862
|
-
*
|
|
863
883
|
*/
|
|
864
884
|
class GainMapLoader extends LoaderBase {
|
|
865
885
|
/**
|
|
@@ -870,12 +890,10 @@ void main() {
|
|
|
870
890
|
*
|
|
871
891
|
* useful for webp gain maps
|
|
872
892
|
*
|
|
873
|
-
* @param
|
|
874
|
-
* @param
|
|
875
|
-
* @param
|
|
876
|
-
* @param
|
|
877
|
-
* @param onProgress
|
|
878
|
-
* @param onError
|
|
893
|
+
* @param urls An array in the form of [sdr.jpg, gainmap.jpg, metadata.json]
|
|
894
|
+
* @param onLoad Load complete callback, will receive the result
|
|
895
|
+
* @param onProgress Progress callback, will receive a {@link ProgressEvent}
|
|
896
|
+
* @param onError Error callback
|
|
879
897
|
* @returns
|
|
880
898
|
*/
|
|
881
899
|
load([sdrUrl, gainMapUrl, metadataUrl], onLoad, onProgress, onError) {
|
|
@@ -888,6 +906,9 @@ void main() {
|
|
|
888
906
|
await this.render(quadRenderer, gainMap, sdr, metadata);
|
|
889
907
|
if (typeof onLoad === 'function')
|
|
890
908
|
onLoad(quadRenderer);
|
|
909
|
+
this.manager.itemEnd(sdrUrl);
|
|
910
|
+
this.manager.itemEnd(gainMapUrl);
|
|
911
|
+
this.manager.itemEnd(metadataUrl);
|
|
891
912
|
quadRenderer.dispose();
|
|
892
913
|
}
|
|
893
914
|
};
|
|
@@ -908,7 +929,10 @@ void main() {
|
|
|
908
929
|
onProgress(new ProgressEvent('progress', { lengthComputable, loaded, total }));
|
|
909
930
|
}
|
|
910
931
|
};
|
|
911
|
-
|
|
932
|
+
this.manager.itemStart(sdrUrl);
|
|
933
|
+
this.manager.itemStart(gainMapUrl);
|
|
934
|
+
this.manager.itemStart(metadataUrl);
|
|
935
|
+
const sdrLoader = new three.FileLoader(this._internalLoadingManager);
|
|
912
936
|
sdrLoader.setResponseType('arraybuffer');
|
|
913
937
|
sdrLoader.setRequestHeader(this.requestHeader);
|
|
914
938
|
sdrLoader.setPath(this.path);
|
|
@@ -917,14 +941,18 @@ void main() {
|
|
|
917
941
|
if (typeof buffer === 'string')
|
|
918
942
|
throw new Error('Invalid sdr buffer');
|
|
919
943
|
sdr = buffer;
|
|
920
|
-
loadCheck();
|
|
944
|
+
await loadCheck();
|
|
921
945
|
}, (e) => {
|
|
922
946
|
sdrLengthComputable = e.lengthComputable;
|
|
923
947
|
sdrLoaded = e.loaded;
|
|
924
948
|
sdrTotal = e.total;
|
|
925
949
|
progressHandler();
|
|
926
|
-
},
|
|
927
|
-
|
|
950
|
+
}, (error) => {
|
|
951
|
+
this.manager.itemError(sdrUrl);
|
|
952
|
+
if (typeof onError === 'function')
|
|
953
|
+
onError(error);
|
|
954
|
+
});
|
|
955
|
+
const gainMapLoader = new three.FileLoader(this._internalLoadingManager);
|
|
928
956
|
gainMapLoader.setResponseType('arraybuffer');
|
|
929
957
|
gainMapLoader.setRequestHeader(this.requestHeader);
|
|
930
958
|
gainMapLoader.setPath(this.path);
|
|
@@ -933,14 +961,18 @@ void main() {
|
|
|
933
961
|
if (typeof buffer === 'string')
|
|
934
962
|
throw new Error('Invalid gainmap buffer');
|
|
935
963
|
gainMap = buffer;
|
|
936
|
-
loadCheck();
|
|
964
|
+
await loadCheck();
|
|
937
965
|
}, (e) => {
|
|
938
966
|
gainMapLengthComputable = e.lengthComputable;
|
|
939
967
|
gainMapLoaded = e.loaded;
|
|
940
968
|
gainMapTotal = e.total;
|
|
941
969
|
progressHandler();
|
|
942
|
-
},
|
|
943
|
-
|
|
970
|
+
}, (error) => {
|
|
971
|
+
this.manager.itemError(gainMapUrl);
|
|
972
|
+
if (typeof onError === 'function')
|
|
973
|
+
onError(error);
|
|
974
|
+
});
|
|
975
|
+
const metadataLoader = new three.FileLoader(this._internalLoadingManager);
|
|
944
976
|
// metadataLoader.setResponseType('json')
|
|
945
977
|
metadataLoader.setRequestHeader(this.requestHeader);
|
|
946
978
|
metadataLoader.setPath(this.path);
|
|
@@ -948,14 +980,20 @@ void main() {
|
|
|
948
980
|
metadataLoader.load(metadataUrl, async (json) => {
|
|
949
981
|
if (typeof json !== 'string')
|
|
950
982
|
throw new Error('Invalid metadata string');
|
|
983
|
+
// TODO: implement check on JSON file and remove this eslint disable
|
|
984
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
951
985
|
metadata = JSON.parse(json);
|
|
952
|
-
loadCheck();
|
|
986
|
+
await loadCheck();
|
|
953
987
|
}, (e) => {
|
|
954
988
|
metadataLengthComputable = e.lengthComputable;
|
|
955
989
|
metadataLoaded = e.loaded;
|
|
956
990
|
metadataTotal = e.total;
|
|
957
991
|
progressHandler();
|
|
958
|
-
},
|
|
992
|
+
}, (error) => {
|
|
993
|
+
this.manager.itemError(metadataUrl);
|
|
994
|
+
if (typeof onError === 'function')
|
|
995
|
+
onError(error);
|
|
996
|
+
});
|
|
959
997
|
return quadRenderer;
|
|
960
998
|
}
|
|
961
999
|
}
|
|
@@ -1005,22 +1043,24 @@ void main() {
|
|
|
1005
1043
|
|
|
1006
1044
|
*
|
|
1007
1045
|
*/
|
|
1008
|
-
class
|
|
1046
|
+
class HDRJPGLoader extends LoaderBase {
|
|
1009
1047
|
/**
|
|
1048
|
+
* Loads a JPEGR Image
|
|
1010
1049
|
*
|
|
1011
|
-
* @param url
|
|
1012
|
-
* @param onLoad
|
|
1013
|
-
* @param onProgress
|
|
1014
|
-
* @param onError
|
|
1050
|
+
* @param url An array in the form of [sdr.jpg, gainmap.jpg, metadata.json]
|
|
1051
|
+
* @param onLoad Load complete callback, will receive the result
|
|
1052
|
+
* @param onProgress Progress callback, will receive a {@link ProgressEvent}
|
|
1053
|
+
* @param onError Error callback
|
|
1015
1054
|
* @returns
|
|
1016
1055
|
*/
|
|
1017
1056
|
load(url, onLoad, onProgress, onError) {
|
|
1018
1057
|
const quadRenderer = this.prepareQuadRenderer();
|
|
1019
|
-
const loader = new three.FileLoader(this.
|
|
1058
|
+
const loader = new three.FileLoader(this._internalLoadingManager);
|
|
1020
1059
|
loader.setResponseType('arraybuffer');
|
|
1021
1060
|
loader.setRequestHeader(this.requestHeader);
|
|
1022
1061
|
loader.setPath(this.path);
|
|
1023
1062
|
loader.setWithCredentials(this.withCredentials);
|
|
1063
|
+
this.manager.itemStart(url);
|
|
1024
1064
|
loader.load(url, async (jpeg) => {
|
|
1025
1065
|
if (typeof jpeg === 'string')
|
|
1026
1066
|
throw new Error('Invalid buffer');
|
|
@@ -1028,15 +1068,21 @@ void main() {
|
|
|
1028
1068
|
await this.render(quadRenderer, gainMapJPEG, sdrJPEG, metadata);
|
|
1029
1069
|
if (typeof onLoad === 'function')
|
|
1030
1070
|
onLoad(quadRenderer);
|
|
1071
|
+
this.manager.itemEnd(url);
|
|
1031
1072
|
quadRenderer.dispose();
|
|
1032
|
-
}, onProgress,
|
|
1073
|
+
}, onProgress, (error) => {
|
|
1074
|
+
this.manager.itemError(url);
|
|
1075
|
+
if (typeof onError === 'function')
|
|
1076
|
+
onError(error);
|
|
1077
|
+
});
|
|
1033
1078
|
return quadRenderer;
|
|
1034
1079
|
}
|
|
1035
1080
|
}
|
|
1036
1081
|
|
|
1037
1082
|
exports.GainMapDecoderMaterial = GainMapDecoderMaterial;
|
|
1038
1083
|
exports.GainMapLoader = GainMapLoader;
|
|
1039
|
-
exports.
|
|
1084
|
+
exports.HDRJPGLoader = HDRJPGLoader;
|
|
1085
|
+
exports.JPEGRLoader = HDRJPGLoader;
|
|
1040
1086
|
exports.QuadRenderer = QuadRenderer;
|
|
1041
1087
|
exports.decode = decode;
|
|
1042
1088
|
exports.extractGainmapFromJPEG = extractGainmapFromJPEG;
|
|
@@ -4,8 +4,8 @@ import { LogLuv } from 'three/examples/jsm/loaders/LogLuvLoader';
|
|
|
4
4
|
import { RGBE } from 'three/examples/jsm/loaders/RGBELoader';
|
|
5
5
|
/**
|
|
6
6
|
*
|
|
7
|
-
* @category
|
|
8
|
-
* @group
|
|
7
|
+
* @category Utility
|
|
8
|
+
* @group Utility
|
|
9
9
|
*
|
|
10
10
|
* @param srcTex
|
|
11
11
|
* @param mode
|
package/dist/encode/types.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ import { type RGBE } from 'three/examples/jsm/loaders/RGBELoader';
|
|
|
5
5
|
import { WorkerInterfaceImplementation } from '../worker-types';
|
|
6
6
|
/**
|
|
7
7
|
* Parameters used by content Creators in order to create a GainMap
|
|
8
|
-
* @category
|
|
9
|
-
* @group
|
|
8
|
+
* @category Specs
|
|
9
|
+
* @group Specs
|
|
10
10
|
*/
|
|
11
11
|
export type GainmapEncodingParameters = {
|
|
12
12
|
/**
|
|
@@ -93,15 +93,15 @@ export type CompressionMimeType = 'image/png' | 'image/jpeg' | 'image/webp';
|
|
|
93
93
|
/**
|
|
94
94
|
* Accepted HDR image buffers, definitions coming from the THREE.js Library types
|
|
95
95
|
*
|
|
96
|
-
* @category
|
|
97
|
-
* @group
|
|
96
|
+
* @category Utility
|
|
97
|
+
* @group Utility
|
|
98
98
|
*/
|
|
99
99
|
export type HDRRawImageBuffer = EXR['data'] | RGBE['data'] | LogLuv['data'];
|
|
100
100
|
/**
|
|
101
101
|
* Raw HDR image data
|
|
102
102
|
*
|
|
103
|
-
* @category
|
|
104
|
-
* @group
|
|
103
|
+
* @category Utility
|
|
104
|
+
* @group Utility
|
|
105
105
|
*/
|
|
106
106
|
export type HDRRawImage = {
|
|
107
107
|
data: HDRRawImageBuffer;
|
package/dist/encode.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @monogrid/gainmap-js v2.0.
|
|
2
|
+
* @monogrid/gainmap-js v2.0.5
|
|
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-_4jEQonS.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-gqnZPNP-.js';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Utility function to obtain a `DataTexture` from various input formats
|
|
12
12
|
*
|
|
13
|
-
* @category
|
|
14
|
-
* @group
|
|
13
|
+
* @category Utility
|
|
14
|
+
* @group Utility
|
|
15
15
|
*
|
|
16
16
|
* @param image
|
|
17
17
|
* @returns
|
|
@@ -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,8 +190,12 @@ 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
|
}
|
|
@@ -483,8 +487,12 @@ const encode = (params) => {
|
|
|
483
487
|
const { image, renderer } = params;
|
|
484
488
|
const dataTexture = getDataTexture(image);
|
|
485
489
|
const sdr = getSDRRendition(dataTexture, renderer, params.toneMapping);
|
|
486
|
-
const gainMapRenderer = getGainMap(
|
|
487
|
-
|
|
490
|
+
const gainMapRenderer = getGainMap({
|
|
491
|
+
...params,
|
|
492
|
+
image: dataTexture,
|
|
493
|
+
sdr,
|
|
494
|
+
renderer: sdr.renderer // reuse the same (maybe disposable?) renderer
|
|
495
|
+
});
|
|
488
496
|
return {
|
|
489
497
|
sdr,
|
|
490
498
|
gainMap: gainMapRenderer,
|
|
@@ -596,8 +604,14 @@ const encodeAndCompress = async (params) => {
|
|
|
596
604
|
}
|
|
597
605
|
encodingResult.sdr.dispose();
|
|
598
606
|
encodingResult.gainMap.dispose();
|
|
599
|
-
return
|
|
600
|
-
|
|
607
|
+
return {
|
|
608
|
+
...encodingResult,
|
|
609
|
+
...encodingResult.getMetadata(),
|
|
610
|
+
sdr: compressResult[0],
|
|
611
|
+
gainMap: compressResult[1],
|
|
612
|
+
rawSDR,
|
|
613
|
+
rawGainMap
|
|
614
|
+
};
|
|
601
615
|
};
|
|
602
616
|
|
|
603
617
|
const vertexShader = /* glsl */ `
|
|
@@ -645,8 +659,8 @@ void main() {
|
|
|
645
659
|
`;
|
|
646
660
|
/**
|
|
647
661
|
*
|
|
648
|
-
* @category
|
|
649
|
-
* @group
|
|
662
|
+
* @category Utility
|
|
663
|
+
* @group Utility
|
|
650
664
|
*
|
|
651
665
|
* @param srcTex
|
|
652
666
|
* @param mode
|
|
@@ -699,7 +713,9 @@ const findTextureMinMax = (image, mode = 'max', renderer) => {
|
|
|
699
713
|
quadRenderer.renderTarget = fbi;
|
|
700
714
|
quadRenderer.render();
|
|
701
715
|
mat.uniforms.map.value = fbi.texture;
|
|
716
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
702
717
|
mat.uniforms.u_srcResolution.value.x = w;
|
|
718
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
703
719
|
mat.uniforms.u_srcResolution.value.y = h;
|
|
704
720
|
});
|
|
705
721
|
const out = quadRenderer.toArray();
|
package/dist/encode.umd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @monogrid/gainmap-js v2.0.
|
|
2
|
+
* @monogrid/gainmap-js v2.0.5
|
|
3
3
|
* With ❤️, by MONOGRID <hello@mono-grid.com>
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
if (res)
|
|
28
28
|
resolve(res);
|
|
29
29
|
else
|
|
30
|
-
reject('Failed to convert canvas to blob');
|
|
30
|
+
reject(new Error('Failed to convert canvas to blob'));
|
|
31
31
|
}, mimeType, quality || 0.9);
|
|
32
32
|
});
|
|
33
33
|
};
|
|
@@ -88,8 +88,8 @@
|
|
|
88
88
|
/**
|
|
89
89
|
* Utility function to obtain a `DataTexture` from various input formats
|
|
90
90
|
*
|
|
91
|
-
* @category
|
|
92
|
-
* @group
|
|
91
|
+
* @category Utility
|
|
92
|
+
* @group Utility
|
|
93
93
|
*
|
|
94
94
|
* @param image
|
|
95
95
|
* @returns
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
dataTexture = image;
|
|
104
104
|
}
|
|
105
105
|
else {
|
|
106
|
-
dataTexture = new three.DataTexture(image.data, image.width, image.height, 'format' in image ? image.format : three.RGBAFormat, image.type, three.UVMapping, three.RepeatWrapping, three.RepeatWrapping, three.LinearFilter, three.LinearFilter, 1, 'colorSpace' in image && image.colorSpace === 'srgb' ? image.colorSpace : three.
|
|
106
|
+
dataTexture = new three.DataTexture(image.data, image.width, image.height, 'format' in image ? image.format : three.RGBAFormat, image.type, three.UVMapping, three.RepeatWrapping, three.RepeatWrapping, three.LinearFilter, three.LinearFilter, 1, 'colorSpace' in image && image.colorSpace === 'srgb' ? image.colorSpace : three.LinearSRGBColorSpace);
|
|
107
107
|
// TODO: This tries to detect a raw RGBE and applies flipY
|
|
108
108
|
// see if there's a better way to detect it?
|
|
109
109
|
if ('header' in image && 'gamma' in image) {
|
|
@@ -160,7 +160,7 @@
|
|
|
160
160
|
return _canReadPixelsResult;
|
|
161
161
|
const testRT = new three.WebGLRenderTarget(1, 1, {
|
|
162
162
|
type,
|
|
163
|
-
colorSpace: three.
|
|
163
|
+
colorSpace: three.LinearSRGBColorSpace,
|
|
164
164
|
format: three.RGBAFormat,
|
|
165
165
|
magFilter: three.LinearFilter,
|
|
166
166
|
minFilter: three.LinearFilter,
|
|
@@ -183,10 +183,10 @@
|
|
|
183
183
|
return _canReadPixelsResult;
|
|
184
184
|
};
|
|
185
185
|
/**
|
|
186
|
-
* Utility
|
|
186
|
+
* Utility class used for rendering a texture with a material
|
|
187
187
|
*
|
|
188
|
-
* @category
|
|
189
|
-
* @group
|
|
188
|
+
* @category Core
|
|
189
|
+
* @group Core
|
|
190
190
|
*/
|
|
191
191
|
class QuadRenderer {
|
|
192
192
|
/**
|
|
@@ -291,7 +291,7 @@
|
|
|
291
291
|
return out;
|
|
292
292
|
}
|
|
293
293
|
toDataTexture() {
|
|
294
|
-
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.
|
|
294
|
+
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);
|
|
295
295
|
}
|
|
296
296
|
/**
|
|
297
297
|
* If using a disposable renderer, it will dispose it.
|
|
@@ -498,8 +498,12 @@ void main() {
|
|
|
498
498
|
const getGainMap = (params) => {
|
|
499
499
|
const { image, sdr, renderer } = params;
|
|
500
500
|
const dataTexture = getDataTexture(image);
|
|
501
|
-
const material = new GainMapEncoderMaterial(
|
|
502
|
-
|
|
501
|
+
const material = new GainMapEncoderMaterial({
|
|
502
|
+
...params,
|
|
503
|
+
sdr: sdr.renderTarget.texture,
|
|
504
|
+
hdr: dataTexture
|
|
505
|
+
});
|
|
506
|
+
const quadRenderer = new QuadRenderer(dataTexture.image.width, dataTexture.image.height, three.UnsignedByteType, three.LinearSRGBColorSpace, material, renderer);
|
|
503
507
|
try {
|
|
504
508
|
quadRenderer.render();
|
|
505
509
|
}
|
|
@@ -791,8 +795,12 @@ void main() {
|
|
|
791
795
|
const { image, renderer } = params;
|
|
792
796
|
const dataTexture = getDataTexture(image);
|
|
793
797
|
const sdr = getSDRRendition(dataTexture, renderer, params.toneMapping);
|
|
794
|
-
const gainMapRenderer = getGainMap(
|
|
795
|
-
|
|
798
|
+
const gainMapRenderer = getGainMap({
|
|
799
|
+
...params,
|
|
800
|
+
image: dataTexture,
|
|
801
|
+
sdr,
|
|
802
|
+
renderer: sdr.renderer // reuse the same (maybe disposable?) renderer
|
|
803
|
+
});
|
|
796
804
|
return {
|
|
797
805
|
sdr,
|
|
798
806
|
gainMap: gainMapRenderer,
|
|
@@ -904,8 +912,14 @@ void main() {
|
|
|
904
912
|
}
|
|
905
913
|
encodingResult.sdr.dispose();
|
|
906
914
|
encodingResult.gainMap.dispose();
|
|
907
|
-
return
|
|
908
|
-
|
|
915
|
+
return {
|
|
916
|
+
...encodingResult,
|
|
917
|
+
...encodingResult.getMetadata(),
|
|
918
|
+
sdr: compressResult[0],
|
|
919
|
+
gainMap: compressResult[1],
|
|
920
|
+
rawSDR,
|
|
921
|
+
rawGainMap
|
|
922
|
+
};
|
|
909
923
|
};
|
|
910
924
|
|
|
911
925
|
const vertexShader = /* glsl */ `
|
|
@@ -953,8 +967,8 @@ void main() {
|
|
|
953
967
|
`;
|
|
954
968
|
/**
|
|
955
969
|
*
|
|
956
|
-
* @category
|
|
957
|
-
* @group
|
|
970
|
+
* @category Utility
|
|
971
|
+
* @group Utility
|
|
958
972
|
*
|
|
959
973
|
* @param srcTex
|
|
960
974
|
* @param mode
|
|
@@ -1007,7 +1021,9 @@ void main() {
|
|
|
1007
1021
|
quadRenderer.renderTarget = fbi;
|
|
1008
1022
|
quadRenderer.render();
|
|
1009
1023
|
mat.uniforms.map.value = fbi.texture;
|
|
1024
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
1010
1025
|
mat.uniforms.u_srcResolution.value.x = w;
|
|
1026
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
1011
1027
|
mat.uniforms.u_srcResolution.value.y = h;
|
|
1012
1028
|
});
|
|
1013
1029
|
const out = quadRenderer.toArray();
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { MainModule } from '../../libultrahdr-wasm/build/libultrahdr';
|
|
2
2
|
/**
|
|
3
3
|
* Instances the WASM module and returns it, only one module will be created upon multiple calls.
|
|
4
|
-
* @category
|
|
5
|
-
* @group
|
|
4
|
+
* @category WASM
|
|
5
|
+
* @group WASM
|
|
6
6
|
*
|
|
7
7
|
* @returns
|
|
8
8
|
*/
|
package/dist/libultrahdr.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @monogrid/gainmap-js v2.0.
|
|
2
|
+
* @monogrid/gainmap-js v2.0.5
|
|
3
3
|
* With ❤️, by MONOGRID <hello@mono-grid.com>
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -6533,8 +6533,8 @@ var libultrahdr = Module;
|
|
|
6533
6533
|
let library;
|
|
6534
6534
|
/**
|
|
6535
6535
|
* Instances the WASM module and returns it, only one module will be created upon multiple calls.
|
|
6536
|
-
* @category
|
|
6537
|
-
* @group
|
|
6536
|
+
* @category WASM
|
|
6537
|
+
* @group WASM
|
|
6538
6538
|
*
|
|
6539
6539
|
* @returns
|
|
6540
6540
|
*/
|
|
@@ -6603,7 +6603,7 @@ const decodeJPEGMetadata = async (file) => {
|
|
|
6603
6603
|
const lib = await getLibrary();
|
|
6604
6604
|
const result = lib.extractJpegR(file, file.length);
|
|
6605
6605
|
if (!result.success)
|
|
6606
|
-
throw new Error(result.errorMessage);
|
|
6606
|
+
throw new Error(`${result.errorMessage}`);
|
|
6607
6607
|
const parser = new DOMParser();
|
|
6608
6608
|
const xmlDocument = parser.parseFromString(result.metadata, 'text/xml');
|
|
6609
6609
|
const description = xmlDocument.getElementsByTagName('rdf:Description')[0];
|
|
@@ -6627,11 +6627,13 @@ const decodeJPEGMetadata = async (file) => {
|
|
|
6627
6627
|
hdrCapacityMin: parseFloat(hdrCapacityMin),
|
|
6628
6628
|
hdrCapacityMax: parseFloat(hdrCapacityMax)
|
|
6629
6629
|
};
|
|
6630
|
-
return
|
|
6630
|
+
return {
|
|
6631
|
+
...result,
|
|
6631
6632
|
/**
|
|
6632
6633
|
* Parsed metadata
|
|
6633
6634
|
*/
|
|
6634
|
-
parsedMetadata
|
|
6635
|
+
parsedMetadata
|
|
6636
|
+
};
|
|
6635
6637
|
};
|
|
6636
6638
|
|
|
6637
6639
|
/**
|