@monogrid/gainmap-js 2.0.1 → 2.0.2

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 CHANGED
@@ -1,3 +1,11 @@
1
+ ## [2.0.2](https://github.com/MONOGRID/gainmap-js/compare/v2.0.1...v2.0.2) (2023-11-14)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **decode:** improves compatibility with browsers with no createImageBitmap ([12c7609](https://github.com/MONOGRID/gainmap-js/commit/12c7609ee815a460f95419aab328b412e759f012))
7
+ * **decoder:** fix bug when using decodeResult.renderTarget.texture as source for PMREMGenerator ([4ebb983](https://github.com/MONOGRID/gainmap-js/commit/4ebb983d5bbc7f524e4b1231f630e3714cf1f870))
8
+
1
9
  ## [2.0.1](https://github.com/MONOGRID/gainmap-js/compare/v2.0.0...v2.0.1) (2023-11-14)
2
10
 
3
11
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.0
2
+ * @monogrid/gainmap-js v2.0.1
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.0
2
+ * @monogrid/gainmap-js v2.0.1
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.0
2
+ * @monogrid/gainmap-js v2.0.1
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
package/dist/decode.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.0
2
+ * @monogrid/gainmap-js v2.0.1
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
6
- import { Q as QuadRenderer } from './QuadRenderer-2NcH1MyZ.js';
6
+ import { Q as QuadRenderer } from './QuadRenderer-XJq0chjd.js';
7
7
  import { ShaderMaterial, Vector3, NoBlending, SRGBColorSpace, NoColorSpace, HalfFloatType, Loader, Texture, UVMapping, ClampToEdgeWrapping, LinearFilter, LinearMipMapLinearFilter, RGBAFormat, UnsignedByteType, FileLoader } from 'three';
8
8
 
9
9
  const vertexShader = /* glsl */ `
@@ -15,6 +15,13 @@ void main() {
15
15
  }
16
16
  `;
17
17
  const fragmentShader = /* glsl */ `
18
+ // this should be the max float value according to https://stackoverflow.com/a/47543127
19
+ // #define FLT_MAX vec3( 3.402823466e+38, 3.402823466e+38, 3.402823466e+38)
20
+
21
+ // in practice, this works for us with iOS problems
22
+ // we encountered
23
+ #define FLT_MAX vec3( 3.402823e+38, 3.402823e+38, 3.402823e+38 )
24
+
18
25
  uniform sampler2D sdr;
19
26
  uniform sampler2D gainMap;
20
27
  uniform vec3 gamma;
@@ -32,7 +39,7 @@ void main() {
32
39
  vec3 logRecovery = pow(recovery, gamma);
33
40
  vec3 logBoost = gainMapMin * (1.0 - logRecovery) + gainMapMax * logRecovery;
34
41
  vec3 hdrColor = (rgb + offsetSdr) * exp2(logBoost * weightFactor) - offsetHdr;
35
- gl_FragColor = vec4(hdrColor, 1.0);
42
+ gl_FragColor = vec4( min(FLT_MAX, hdrColor), 1.0 );
36
43
  }
37
44
  `;
38
45
  /**
@@ -134,11 +141,12 @@ class GainMapDecoderMaterial extends ShaderMaterial {
134
141
  */
135
142
  get maxDisplayBoost() { return this._maxDisplayBoost; }
136
143
  set maxDisplayBoost(value) {
137
- this._maxDisplayBoost = value;
144
+ this._maxDisplayBoost = Math.max(1, Math.min(65504, value));
138
145
  this.calculateWeight();
139
146
  }
140
147
  calculateWeight() {
141
- this.uniforms.weightFactor.value = (Math.log2(this._maxDisplayBoost) - this._hdrCapacityMin) / (this._hdrCapacityMax - this._hdrCapacityMin);
148
+ const val = (Math.log2(this._maxDisplayBoost) - this._hdrCapacityMin) / (this._hdrCapacityMax - this._hdrCapacityMin);
149
+ this.uniforms.weightFactor.value = Math.max(0, Math.min(1, val));
142
150
  }
143
151
  }
144
152
 
@@ -478,6 +486,20 @@ const extractGainmapFromJPEG = async (jpegFile) => {
478
486
  };
479
487
  };
480
488
 
489
+ /**
490
+ * private function, async get image from blob
491
+ *
492
+ * @param blob
493
+ * @returns
494
+ */
495
+ const getImage = (blob) => {
496
+ return new Promise((resolve, reject) => {
497
+ const img = document.createElement('img');
498
+ img.onload = () => { resolve(img); };
499
+ img.onerror = (e) => { reject(e); };
500
+ img.src = URL.createObjectURL(blob);
501
+ });
502
+ };
481
503
  class LoaderBase extends Loader {
482
504
  /**
483
505
  *
@@ -519,16 +541,34 @@ class LoaderBase extends Loader {
519
541
  async render(quadRenderer, gainMapBuffer, sdrBuffer, metadata) {
520
542
  const gainMapBlob = new Blob([gainMapBuffer], { type: 'image/jpeg' });
521
543
  const sdrBlob = new Blob([sdrBuffer], { type: 'image/jpeg' });
522
- const [gainMapImageBitmap, sdrImageBitmap] = await Promise.all([
523
- createImageBitmap(gainMapBlob, { imageOrientation: 'flipY' }),
524
- createImageBitmap(sdrBlob, { imageOrientation: 'flipY' })
525
- ]);
526
- const gainMap = new Texture(gainMapImageBitmap, UVMapping, ClampToEdgeWrapping, ClampToEdgeWrapping, LinearFilter, LinearMipMapLinearFilter, RGBAFormat, UnsignedByteType, 1, NoColorSpace);
544
+ let sdrImage;
545
+ let gainMapImage;
546
+ let needsFlip = false;
547
+ if (typeof createImageBitmap === 'undefined') {
548
+ const res = await Promise.all([
549
+ getImage(gainMapBlob),
550
+ getImage(sdrBlob)
551
+ ]);
552
+ gainMapImage = res[0];
553
+ sdrImage = res[1];
554
+ needsFlip = true;
555
+ }
556
+ else {
557
+ const res = await Promise.all([
558
+ createImageBitmap(gainMapBlob, { imageOrientation: 'flipY' }),
559
+ createImageBitmap(sdrBlob, { imageOrientation: 'flipY' })
560
+ ]);
561
+ gainMapImage = res[0];
562
+ sdrImage = res[1];
563
+ }
564
+ const gainMap = new Texture(gainMapImage, UVMapping, ClampToEdgeWrapping, ClampToEdgeWrapping, LinearFilter, LinearMipMapLinearFilter, RGBAFormat, UnsignedByteType, 1, NoColorSpace);
565
+ gainMap.flipY = needsFlip;
527
566
  gainMap.needsUpdate = true;
528
- const sdr = new Texture(sdrImageBitmap, UVMapping, ClampToEdgeWrapping, ClampToEdgeWrapping, LinearFilter, LinearMipMapLinearFilter, RGBAFormat, UnsignedByteType, 1, SRGBColorSpace);
567
+ const sdr = new Texture(sdrImage, UVMapping, ClampToEdgeWrapping, ClampToEdgeWrapping, LinearFilter, LinearMipMapLinearFilter, RGBAFormat, UnsignedByteType, 1, SRGBColorSpace);
568
+ sdr.flipY = needsFlip;
529
569
  sdr.needsUpdate = true;
530
- quadRenderer.width = sdrImageBitmap.width;
531
- quadRenderer.height = sdrImageBitmap.height;
570
+ quadRenderer.width = sdrImage.width;
571
+ quadRenderer.height = sdrImage.height;
532
572
  quadRenderer.material.gainMap = gainMap;
533
573
  quadRenderer.material.sdr = sdr;
534
574
  quadRenderer.material.gainMapMin = metadata.gainMapMin;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.0
2
+ * @monogrid/gainmap-js v2.0.1
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
@@ -248,6 +248,13 @@ void main() {
248
248
  }
249
249
  `;
250
250
  const fragmentShader = /* glsl */ `
251
+ // this should be the max float value according to https://stackoverflow.com/a/47543127
252
+ // #define FLT_MAX vec3( 3.402823466e+38, 3.402823466e+38, 3.402823466e+38)
253
+
254
+ // in practice, this works for us with iOS problems
255
+ // we encountered
256
+ #define FLT_MAX vec3( 3.402823e+38, 3.402823e+38, 3.402823e+38 )
257
+
251
258
  uniform sampler2D sdr;
252
259
  uniform sampler2D gainMap;
253
260
  uniform vec3 gamma;
@@ -265,7 +272,7 @@ void main() {
265
272
  vec3 logRecovery = pow(recovery, gamma);
266
273
  vec3 logBoost = gainMapMin * (1.0 - logRecovery) + gainMapMax * logRecovery;
267
274
  vec3 hdrColor = (rgb + offsetSdr) * exp2(logBoost * weightFactor) - offsetHdr;
268
- gl_FragColor = vec4(hdrColor, 1.0);
275
+ gl_FragColor = vec4( min(FLT_MAX, hdrColor), 1.0 );
269
276
  }
270
277
  `;
271
278
  /**
@@ -367,11 +374,12 @@ void main() {
367
374
  */
368
375
  get maxDisplayBoost() { return this._maxDisplayBoost; }
369
376
  set maxDisplayBoost(value) {
370
- this._maxDisplayBoost = value;
377
+ this._maxDisplayBoost = Math.max(1, Math.min(65504, value));
371
378
  this.calculateWeight();
372
379
  }
373
380
  calculateWeight() {
374
- this.uniforms.weightFactor.value = (Math.log2(this._maxDisplayBoost) - this._hdrCapacityMin) / (this._hdrCapacityMax - this._hdrCapacityMin);
381
+ const val = (Math.log2(this._maxDisplayBoost) - this._hdrCapacityMin) / (this._hdrCapacityMax - this._hdrCapacityMin);
382
+ this.uniforms.weightFactor.value = Math.max(0, Math.min(1, val));
375
383
  }
376
384
  }
377
385
 
@@ -711,6 +719,20 @@ void main() {
711
719
  };
712
720
  };
713
721
 
722
+ /**
723
+ * private function, async get image from blob
724
+ *
725
+ * @param blob
726
+ * @returns
727
+ */
728
+ const getImage = (blob) => {
729
+ return new Promise((resolve, reject) => {
730
+ const img = document.createElement('img');
731
+ img.onload = () => { resolve(img); };
732
+ img.onerror = (e) => { reject(e); };
733
+ img.src = URL.createObjectURL(blob);
734
+ });
735
+ };
714
736
  class LoaderBase extends three.Loader {
715
737
  /**
716
738
  *
@@ -752,16 +774,34 @@ void main() {
752
774
  async render(quadRenderer, gainMapBuffer, sdrBuffer, metadata) {
753
775
  const gainMapBlob = new Blob([gainMapBuffer], { type: 'image/jpeg' });
754
776
  const sdrBlob = new Blob([sdrBuffer], { type: 'image/jpeg' });
755
- const [gainMapImageBitmap, sdrImageBitmap] = await Promise.all([
756
- createImageBitmap(gainMapBlob, { imageOrientation: 'flipY' }),
757
- createImageBitmap(sdrBlob, { imageOrientation: 'flipY' })
758
- ]);
759
- const gainMap = new three.Texture(gainMapImageBitmap, three.UVMapping, three.ClampToEdgeWrapping, three.ClampToEdgeWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, three.RGBAFormat, three.UnsignedByteType, 1, three.NoColorSpace);
777
+ let sdrImage;
778
+ let gainMapImage;
779
+ let needsFlip = false;
780
+ if (typeof createImageBitmap === 'undefined') {
781
+ const res = await Promise.all([
782
+ getImage(gainMapBlob),
783
+ getImage(sdrBlob)
784
+ ]);
785
+ gainMapImage = res[0];
786
+ sdrImage = res[1];
787
+ needsFlip = true;
788
+ }
789
+ else {
790
+ const res = await Promise.all([
791
+ createImageBitmap(gainMapBlob, { imageOrientation: 'flipY' }),
792
+ createImageBitmap(sdrBlob, { imageOrientation: 'flipY' })
793
+ ]);
794
+ gainMapImage = res[0];
795
+ sdrImage = res[1];
796
+ }
797
+ const gainMap = new three.Texture(gainMapImage, three.UVMapping, three.ClampToEdgeWrapping, three.ClampToEdgeWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, three.RGBAFormat, three.UnsignedByteType, 1, three.NoColorSpace);
798
+ gainMap.flipY = needsFlip;
760
799
  gainMap.needsUpdate = true;
761
- const sdr = new three.Texture(sdrImageBitmap, three.UVMapping, three.ClampToEdgeWrapping, three.ClampToEdgeWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, three.RGBAFormat, three.UnsignedByteType, 1, three.SRGBColorSpace);
800
+ const sdr = new three.Texture(sdrImage, three.UVMapping, three.ClampToEdgeWrapping, three.ClampToEdgeWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, three.RGBAFormat, three.UnsignedByteType, 1, three.SRGBColorSpace);
801
+ sdr.flipY = needsFlip;
762
802
  sdr.needsUpdate = true;
763
- quadRenderer.width = sdrImageBitmap.width;
764
- quadRenderer.height = sdrImageBitmap.height;
803
+ quadRenderer.width = sdrImage.width;
804
+ quadRenderer.height = sdrImage.height;
765
805
  quadRenderer.material.gainMap = gainMap;
766
806
  quadRenderer.material.sdr = sdr;
767
807
  quadRenderer.material.gainMapMin = metadata.gainMapMin;
package/dist/encode.js CHANGED
@@ -1,11 +1,11 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.0
2
+ * @monogrid/gainmap-js v2.0.1
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
6
- import { c as compress } from './compress-nWDFn7nF.js';
6
+ import { c as compress } from './compress-OWkN-Bv4.js';
7
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-2NcH1MyZ.js';
8
+ import { Q as QuadRenderer } from './QuadRenderer-XJq0chjd.js';
9
9
 
10
10
  /**
11
11
  * Utility function to obtain a `DataTexture` from various input formats
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.0
2
+ * @monogrid/gainmap-js v2.0.1
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
Binary file