@monogrid/gainmap-js 1.1.0 → 2.0.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.
Files changed (51) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +21 -8
  3. package/dist/QuadRenderer-IDZuHqZM.js +178 -0
  4. package/dist/{_commonjsHelpers-1789f0cf.js → _commonjsHelpers-G_2thcKl.js} +1 -1
  5. package/dist/{compress-a4b59cab.js → compress-Cw5IwRTb.js} +1 -1
  6. package/dist/{loaders → core}/LoaderBase.d.ts +3 -3
  7. package/dist/{utils → core}/QuadRenderer.d.ts +6 -0
  8. package/dist/core/types.d.ts +64 -0
  9. package/dist/decode/decode.d.ts +56 -0
  10. package/dist/decode/extract.d.ts +10 -0
  11. package/dist/decode/index.d.ts +8 -0
  12. package/dist/{loaders → decode/loaders}/GainMapLoader.d.ts +4 -4
  13. package/dist/{loaders → decode/loaders}/JPEGRLoader.d.ts +5 -5
  14. package/dist/{materials → decode/materials}/GainMapDecoderMaterial.d.ts +3 -2
  15. package/dist/decode/types.d.ts +38 -0
  16. package/dist/decode/utils/MPFExtractor.d.ts +22 -0
  17. package/dist/decode/utils/extract-metadata-from-jpeg.d.ts +7 -0
  18. package/dist/decode.d.ts +1 -56
  19. package/dist/decode.js +737 -0
  20. package/dist/decode.umd.js +917 -0
  21. package/dist/{encode-utils → encode}/compress.d.ts +1 -1
  22. package/dist/encode/encode-and-compress.d.ts +61 -0
  23. package/dist/encode/encode.d.ts +58 -0
  24. package/dist/{encode-utils → encode}/get-gainmap.d.ts +3 -3
  25. package/dist/{encode-utils → encode}/get-sdr-rendition.d.ts +4 -5
  26. package/dist/encode/index.d.ts +10 -0
  27. package/dist/encode/types.d.ts +172 -0
  28. package/dist/encode.d.ts +1 -117
  29. package/dist/{index.js → encode.js} +42 -230
  30. package/dist/encode.umd.js +972 -0
  31. package/dist/libultrahdr/decode-jpeg-metadata.d.ts +31 -0
  32. package/dist/libultrahdr/encode-jpeg-metadata.d.ts +84 -0
  33. package/dist/libultrahdr/library.d.ts +9 -0
  34. package/dist/libultrahdr.d.ts +3 -123
  35. package/dist/libultrahdr.js +92 -167
  36. package/dist/libultrahdr.umd.js +91 -530
  37. package/dist/worker-interface.js +2 -2
  38. package/dist/worker-interface.umd.js +1 -3
  39. package/dist/worker-types.d.ts +2 -2
  40. package/dist/worker.js +3 -3
  41. package/dist/worker.umd.js +1 -1
  42. package/package.json +36 -29
  43. package/dist/LoaderBase-aa4842c4.js +0 -373
  44. package/dist/index.d.ts +0 -11
  45. package/dist/index.umd.js +0 -1360
  46. package/dist/materials/index.d.ts +0 -3
  47. package/dist/types.d.ts +0 -262
  48. /package/dist/{utils → core}/get-data-texture.d.ts +0 -0
  49. /package/dist/{encode-utils → encode}/find-texture-min-max.d.ts +0 -0
  50. /package/dist/{materials → encode/materials}/GainMapEncoderMaterial.d.ts +0 -0
  51. /package/dist/{materials → encode/materials}/SDRMaterial.d.ts +0 -0
@@ -1,89 +1,39 @@
1
1
  /**
2
- * @monogrid/gainmap-js v1.0.2
2
+ * @monogrid/gainmap-js v1.1.1
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
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';
9
- import { c as compress } from './compress-a4b59cab.js';
10
- export { c as compress } from './compress-a4b59cab.js';
6
+ import { c as compress } from './compress-Cw5IwRTb.js';
7
+ import { DataTexture, RGBAFormat, UVMapping, RepeatWrapping, LinearFilter, NoColorSpace, ShaderMaterial, Vector3, NoBlending, UnsignedByteType, ACESFilmicToneMapping, LinearToneMapping, CineonToneMapping, ReinhardToneMapping, SRGBColorSpace, Vector2, WebGLRenderTarget, NearestFilter, ClampToEdgeWrapping, FloatType, DataUtils } from 'three';
8
+ import { Q as QuadRenderer } from './QuadRenderer-IDZuHqZM.js';
11
9
 
12
10
  /**
13
- * Decodes a gain map using a WebGLRenderTarget
14
- *
15
- * @category Decoding
16
- * @group Decoding
17
- * @example
18
- * import { decode } from '@monogrid/gainmap-js'
19
- * import {
20
- * Mesh,
21
- * MeshBasicMaterial,
22
- * PerspectiveCamera,
23
- * PlaneGeometry,
24
- * Scene,
25
- * TextureLoader,
26
- * WebGLRenderer
27
- * } from 'three'
28
- *
29
- * const renderer = new WebGLRenderer()
30
- *
31
- * const textureLoader = new TextureLoader()
32
- *
33
- * // load SDR Representation
34
- * const sdr = await textureLoader.loadAsync('sdr.jpg')
35
- * // load Gain map recovery image
36
- * const gainMap = await textureLoader.loadAsync('gainmap.jpg')
37
- * // load metadata
38
- * const metadata = await (await fetch('metadata.json')).json()
39
- *
40
- * const result = await decode({
41
- * sdr,
42
- * gainMap,
43
- * // this allows to use `result.renderTarget.texture` directly
44
- * renderer,
45
- * // this will restore the full HDR range
46
- * maxDisplayBoost: Math.pow(2, metadata.hdrCapacityMax),
47
- * ...metadata
48
- * })
49
- *
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())
11
+ * Utility function to obtain a `DataTexture` from various input formats
58
12
  *
13
+ * @category General
14
+ * @group General
59
15
  *
60
- * @param params
16
+ * @param image
61
17
  * @returns
62
- * @throws {Error} if the WebGLRenderer fails to render the gain map
63
18
  */
64
- const decode = (params) => {
65
- const { sdr, gainMap, renderer } = params;
66
- if (sdr.colorSpace !== SRGBColorSpace) {
67
- console.warn('SDR Colorspace needs to be *SRGBColorSpace*, setting it automatically');
68
- sdr.colorSpace = SRGBColorSpace;
69
- }
70
- sdr.needsUpdate = true;
71
- if (gainMap.colorSpace !== NoColorSpace) {
72
- console.warn('Gainmap Colorspace needs to be *NoColorSpace*');
73
- gainMap.colorSpace = NoColorSpace;
74
- }
75
- gainMap.needsUpdate = true;
76
- const material = new GainMapDecoderMaterial(Object.assign(Object.assign({}, params), { sdr,
77
- gainMap }));
78
- const quadRenderer = new QuadRenderer(sdr.image.width, sdr.image.height, HalfFloatType, NoColorSpace, material, renderer);
79
- try {
80
- quadRenderer.render();
19
+ const getDataTexture = (image) => {
20
+ let dataTexture;
21
+ if (image instanceof DataTexture) {
22
+ if (!(image.image.data instanceof Uint16Array) && !(image.image.data instanceof Float32Array)) {
23
+ throw new Error('Provided image is not HDR');
24
+ }
25
+ dataTexture = image;
81
26
  }
82
- catch (e) {
83
- quadRenderer.dispose();
84
- throw e;
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 : NoColorSpace);
29
+ // TODO: This tries to detect a raw RGBE and applies flipY
30
+ // see if there's a better way to detect it?
31
+ if ('header' in image && 'gamma' in image) {
32
+ dataTexture.flipY = true;
33
+ }
34
+ dataTexture.needsUpdate = true;
85
35
  }
86
- return quadRenderer;
36
+ return dataTexture;
87
37
  };
88
38
 
89
39
  const vertexShader$2 = /* glsl */ `
@@ -230,35 +180,6 @@ class GainMapEncoderMaterial extends ShaderMaterial {
230
180
  get hdrCapacityMax() { return Math.min(Math.max(0, this.gainMapMax[0]), Math.max(0, this.gainMapMax[1]), Math.max(0, this.gainMapMax[2])); }
231
181
  }
232
182
 
233
- /**
234
- * Utility function to obtain a `DataTexture` from various input formats
235
- *
236
- * @category General
237
- * @group General
238
- *
239
- * @param image
240
- * @returns
241
- */
242
- const getDataTexture = (image) => {
243
- let dataTexture;
244
- if (image instanceof DataTexture) {
245
- if (!(image.image.data instanceof Uint16Array) && !(image.image.data instanceof Float32Array)) {
246
- throw new Error('Provided image is not HDR');
247
- }
248
- dataTexture = image;
249
- }
250
- else {
251
- 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 : NoColorSpace);
252
- // TODO: This tries to detect a raw RGBE and applies flipY
253
- // see if there's a better way to detect it?
254
- if ('header' in image && 'gamma' in image) {
255
- dataTexture.flipY = true;
256
- }
257
- dataTexture.needsUpdate = true;
258
- }
259
- return dataTexture;
260
- };
261
-
262
183
  /**
263
184
  *
264
185
  * @param params
@@ -491,8 +412,8 @@ class SDRMaterial extends ShaderMaterial {
491
412
  * @group Encoding Functions
492
413
  *
493
414
  * @param hdrTexture The HDR image to be rendered
494
- * @param renderer (optional) WebGLRenderer to use diring the rendering, a disposable renderer will be create and destroyed if this is not provided.
495
- * @param toneMapping (optional) Tonemapping to be applied to the SDR Rendition
415
+ * @param renderer (optional) WebGLRenderer to use during the rendering, a disposable renderer will be create and destroyed if this is not provided.
416
+ * @param toneMapping (optional) Tone mapping to be applied to the SDR Rendition
496
417
  * @throws {Error} if the WebGLRenderer fails to render the SDR image
497
418
  */
498
419
  const getSDRRendition = (hdrTexture, renderer, toneMapping) => {
@@ -555,7 +476,7 @@ const getSDRRendition = (hdrTexture, renderer, toneMapping) => {
555
476
  * encodingResult.sdr.dispose()
556
477
  * encodingResult.gainMap.dispose()
557
478
  *
558
- * @param params Encoding Paramaters
479
+ * @param params Encoding Parameters
559
480
  * @returns
560
481
  */
561
482
  const encode = (params) => {
@@ -582,6 +503,7 @@ const encode = (params) => {
582
503
  }
583
504
  };
584
505
  };
506
+
585
507
  /**
586
508
  * Encodes a Gainmap starting from an HDR file into compressed file formats (`image/jpeg`, `image/webp` or `image/png`).
587
509
  *
@@ -590,7 +512,7 @@ const encode = (params) => {
590
512
  * @remarks
591
513
  * if a `renderer` parameter is not provided
592
514
  * This function will automatically dispose its "disposable"
593
- * renderer, no need to disapose it manually later
515
+ * renderer, no need to dispose it manually later
594
516
  *
595
517
  * @category Encoding Functions
596
518
  * @group Encoding Functions
@@ -624,7 +546,7 @@ const encode = (params) => {
624
546
  * // `jpeg` will be an `Uint8Array` which can be saved somewhere
625
547
  *
626
548
  *
627
- * @param params Encoding Paramaters
549
+ * @param params Encoding Parameters
628
550
  * @throws {Error} if the browser does not support [createImageBitmap](https://caniuse.com/createimagebitmap)
629
551
  */
630
552
  const encodeAndCompress = async (params) => {
@@ -751,14 +673,14 @@ const findTextureMinMax = (image, mode = 'max', renderer) => {
751
673
  let w = srcTex.image.width;
752
674
  let h = srcTex.image.height;
753
675
  const quadRenderer = new QuadRenderer(w, h, srcTex.type, srcTex.colorSpace, mat, renderer);
754
- const framebuffers = [];
676
+ const frameBuffers = [];
755
677
  while (w > 1 || h > 1) {
756
678
  w = Math.max(1, (w + cellSize - 1) / cellSize | 0);
757
679
  h = Math.max(1, (h + cellSize - 1) / cellSize | 0);
758
680
  const fb = new WebGLRenderTarget(w, h, {
759
- type: srcTex.type,
681
+ type: quadRenderer.type,
760
682
  format: srcTex.format,
761
- colorSpace: srcTex.colorSpace,
683
+ colorSpace: quadRenderer.colorSpace,
762
684
  minFilter: NearestFilter,
763
685
  magFilter: NearestFilter,
764
686
  wrapS: ClampToEdgeWrapping,
@@ -767,11 +689,11 @@ const findTextureMinMax = (image, mode = 'max', renderer) => {
767
689
  depthBuffer: false,
768
690
  stencilBuffer: false
769
691
  });
770
- framebuffers.push(fb);
692
+ frameBuffers.push(fb);
771
693
  }
772
694
  w = srcTex.image.width;
773
695
  h = srcTex.image.height;
774
- framebuffers.forEach((fbi) => {
696
+ frameBuffers.forEach((fbi) => {
775
697
  w = Math.max(1, (w + cellSize - 1) / cellSize | 0);
776
698
  h = Math.max(1, (h + cellSize - 1) / cellSize | 0);
777
699
  quadRenderer.renderTarget = fbi;
@@ -782,122 +704,12 @@ const findTextureMinMax = (image, mode = 'max', renderer) => {
782
704
  });
783
705
  const out = quadRenderer.toArray();
784
706
  quadRenderer.dispose();
785
- framebuffers.forEach(fb => fb.dispose());
786
- return [DataUtils.fromHalfFloat(out[0]), DataUtils.fromHalfFloat(out[1]), DataUtils.fromHalfFloat(out[2])];
707
+ frameBuffers.forEach(fb => fb.dispose());
708
+ return [
709
+ quadRenderer.type === FloatType ? out[0] : DataUtils.fromHalfFloat(out[0]),
710
+ quadRenderer.type === FloatType ? out[1] : DataUtils.fromHalfFloat(out[1]),
711
+ quadRenderer.type === FloatType ? out[2] : DataUtils.fromHalfFloat(out[2])
712
+ ];
787
713
  };
788
714
 
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 };
715
+ export { GainMapEncoderMaterial, SDRMaterial, compress, encode, encodeAndCompress, findTextureMinMax, getGainMap, getSDRRendition };