@monogrid/gainmap-js 2.0.3 → 2.0.5

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,17 @@
1
+ ## [2.0.5](https://github.com/MONOGRID/gainmap-js/compare/v2.0.4...v2.0.5) (2023-11-16)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **jpegrloader:** rename JPEGRLoader to HDRJPEGLoader, old name kept for compatibility ([ac6e386](https://github.com/MONOGRID/gainmap-js/commit/ac6e38610886b7adec5806a7ad301bff1ec00d62))
7
+
8
+ ## [2.0.4](https://github.com/MONOGRID/gainmap-js/compare/v2.0.3...v2.0.4) (2023-11-15)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **decode:** clamp max values in the decode shader to min/max half float ([96986be](https://github.com/MONOGRID/gainmap-js/commit/96986be23dd95825d19fac3b3de520d59d8ad936))
14
+
1
15
  ## [2.0.3](https://github.com/MONOGRID/gainmap-js/compare/v2.0.2...v2.0.3) (2023-11-15)
2
16
 
3
17
 
package/README.md CHANGED
@@ -37,7 +37,7 @@ $ npm install @monogrid/gainmap-js three
37
37
  > * The **gain map**. This is a secondary “image” embedded in the file. It is not a real image, but rather contains data to convert each pixel from the base image into the other (SDR or HDR) version of the image.
38
38
  >* Gain map **metadata**. This tells the browser how the gain map is encoded as well as critical information to optimize rendering on any display.
39
39
 
40
- Please note that Google [is adopting the gain map technology in Android 14](https://support.google.com/photos/answer/14159275) but its naming of the technology refers to it as **Ultra HDR Image Format** and a JPEG file with embedded gain map is called `JPEGR` in their terminology.
40
+ Please note that Google [is adopting the gain map technology in Android 14](https://support.google.com/photos/answer/14159275) but its naming of the technology refers to it as **Ultra HDR Image Format** and a JPEG file with embedded gain map is [apparently called JPEGR](https://github.com/google/libultrahdr/blob/3a3a752a5da0b2304b1b6de0ef383bbe41256a67/lib/jpegr.h#L28C16-L28C21) in their terminology, we call it `HDRJPEG` for the moment.
41
41
 
42
42
  ## API
43
43
 
@@ -63,7 +63,7 @@ The disadvantages are:
63
63
  * Photo sharing websites and/or services (i.e. sharing with Slack) will likely strip the Gain map metadata and the HDR information will be lost, leaving you with only the SDR Representation.
64
64
 
65
65
  ```ts
66
- import { JPEGRLoader } from '@monogrid/gainmap-js'
66
+ import { HDRJPGLoader } from '@monogrid/gainmap-js'
67
67
  import {
68
68
  EquirectangularReflectionMapping,
69
69
  LinearFilter,
@@ -77,7 +77,7 @@ import {
77
77
 
78
78
  const renderer = new WebGLRenderer()
79
79
 
80
- const loader = new JPEGRLoader(renderer)
80
+ const loader = new HDRJPGLoader(renderer)
81
81
 
82
82
  const result = loader.load('gainmap.jpeg')
83
83
  // `result` can be used to populate a Texture
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.2
2
+ * @monogrid/gainmap-js v2.0.4
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
@@ -74,10 +74,10 @@ const canReadPixels = (type, renderer, camera) => {
74
74
  return _canReadPixelsResult;
75
75
  };
76
76
  /**
77
- * Utility structure used for rendering a texture with a material
77
+ * Utility class used for rendering a texture with a material
78
78
  *
79
- * @category General
80
- * @group General
79
+ * @category Core
80
+ * @group Core
81
81
  */
82
82
  class QuadRenderer {
83
83
  /**
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.2
2
+ * @monogrid/gainmap-js v2.0.4
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.2
2
+ * @monogrid/gainmap-js v2.0.4
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
@@ -1,14 +1,16 @@
1
1
  import { ByteType, ColorSpace, DataTexture, FloatType, HalfFloatType, IntType, Material, ShortType, TextureDataType, UnsignedByteType, UnsignedIntType, WebGLRenderer, WebGLRenderTarget } from 'three';
2
2
  /**
3
- * @category General
4
- * @group General
3
+ * Utility Type that translates `three` texture types to their TypedArray counterparts.
4
+ *
5
+ * @category Utility
6
+ * @group Utility
5
7
  */
6
8
  export type TextureDataTypeToBufferType<TType extends TextureDataType> = TType extends typeof UnsignedByteType ? Uint8ClampedArray : TType extends typeof HalfFloatType ? Uint16Array : TType extends typeof UnsignedIntType ? Uint32Array : TType extends typeof ByteType ? Int8Array : TType extends typeof ShortType ? Int16Array : TType extends typeof IntType ? Int32Array : TType extends typeof FloatType ? Float32Array : never;
7
9
  /**
8
- * Utility structure used for rendering a texture with a material
10
+ * Utility class used for rendering a texture with a material
9
11
  *
10
- * @category General
11
- * @group General
12
+ * @category Core
13
+ * @group Core
12
14
  */
13
15
  export declare class QuadRenderer<TType extends TextureDataType, TMaterial extends Material> {
14
16
  private _renderer;
@@ -5,8 +5,8 @@ import { RGBE } from 'three/examples/jsm/loaders/RGBELoader';
5
5
  /**
6
6
  * Utility function to obtain a `DataTexture` from various input formats
7
7
  *
8
- * @category General
9
- * @group General
8
+ * @category Utility
9
+ * @group Utility
10
10
  *
11
11
  * @param image
12
12
  * @returns
@@ -0,0 +1,3 @@
1
+ export * from './get-data-texture';
2
+ export * from './QuadRenderer';
3
+ export * from './types';
@@ -2,8 +2,8 @@
2
2
  * This is the Metadata stored in an encoded Gainmap which is used
3
3
  * to decode it and return an HDR image
4
4
  *
5
- * @category Gainmap Specifications
6
- * @group Gainmap Specifications
5
+ * @category Specs
6
+ * @group Specs
7
7
  */
8
8
  export type GainMapMetadata = {
9
9
  /**
@@ -4,8 +4,8 @@ import { DecodeParameters } from './types';
4
4
  /**
5
5
  * Decodes a gain map using a WebGLRenderTarget
6
6
  *
7
- * @category Decoding
8
- * @group Decoding
7
+ * @category Decoding Functions
8
+ * @group Decoding Functions
9
9
  * @example
10
10
  * import { decode } from '@monogrid/gainmap-js'
11
11
  * import {
@@ -1,7 +1,22 @@
1
1
  /**
2
+ * Extracts XMP Metadata and the gain map recovery image
3
+ * from a single JPEG file.
2
4
  *
3
- * @param jpegFile
4
- * @returns
5
+ * @category Decoding Functions
6
+ * @group Decoding Functions
7
+ * @param jpegFile an `Uint8Array` containing and encoded JPEG file
8
+ * @returns an sdr `Uint8Array` compressed in JPEG, a gainMap `Uint8Array` compressed in JPEG and the XMP parsed XMP metadata
9
+ * @throws Error if XMP Metadata is not found
10
+ * @throws Error if Gain map image is not found
11
+ * @example
12
+ * import { FileLoader } from 'three'
13
+ * import { extractGainmapFromJPEG } from '@monogrid/gainmap-js'
14
+ *
15
+ * const jpegFile = await new FileLoader()
16
+ * .setResponseType('arraybuffer')
17
+ * .loadAsync('image.jpg')
18
+ *
19
+ * const { sdr, gainMap, metadata } = extractGainmapFromJPEG(jpegFile)
5
20
  */
6
21
  export declare const extractGainmapFromJPEG: (jpegFile: Uint8Array) => Promise<{
7
22
  sdr: Uint8Array;
@@ -3,6 +3,7 @@ export * from '../core/types';
3
3
  export * from './decode';
4
4
  export * from './extract';
5
5
  export * from './loaders/GainMapLoader';
6
- export * from './loaders/JPEGRLoader';
6
+ export * from './loaders/HDRJPGLoader';
7
+ export { HDRJPGLoader as JPEGRLoader } from './loaders/HDRJPGLoader';
7
8
  export * from './materials/GainMapDecoderMaterial';
8
9
  export * from './types';
@@ -45,7 +45,6 @@ import { LoaderBase } from './LoaderBase';
45
45
  * scene.background.mapping = EquirectangularReflectionMapping
46
46
  * scene.background.minFilter = LinearFilter
47
47
  *
48
- *
49
48
  */
50
49
  export declare class GainMapLoader extends LoaderBase<[string, string, string]> {
51
50
  /**
@@ -56,12 +55,10 @@ export declare class GainMapLoader extends LoaderBase<[string, string, string]>
56
55
  *
57
56
  * useful for webp gain maps
58
57
  *
59
- * @param sdrUrl
60
- * @param gainMapUrl
61
- * @param metadataUrl
62
- * @param onLoad
63
- * @param onProgress
64
- * @param onError
58
+ * @param urls An array in the form of [sdr.jpg, gainmap.jpg, metadata.json]
59
+ * @param onLoad Load complete callback, will receive the result
60
+ * @param onProgress Progress callback, will receive a {@link ProgressEvent}
61
+ * @param onError Error callback
65
62
  * @returns
66
63
  */
67
64
  load([sdrUrl, gainMapUrl, metadataUrl]: [string, string, string], onLoad?: (data: QuadRenderer<typeof HalfFloatType, GainMapDecoderMaterial>) => void, onProgress?: (event: ProgressEvent) => void, onError?: (err: unknown) => void): QuadRenderer<typeof HalfFloatType, GainMapDecoderMaterial>;
@@ -1,6 +1,6 @@
1
1
  import { HalfFloatType } from 'three';
2
2
  import { QuadRenderer } from '../../core/QuadRenderer';
3
- import { GainMapDecoderMaterial } from '../../decode/materials/GainMapDecoderMaterial';
3
+ import { GainMapDecoderMaterial } from '../materials/GainMapDecoderMaterial';
4
4
  import { LoaderBase } from './LoaderBase';
5
5
  /**
6
6
  * A Three.js Loader for a JPEG with embedded gainmap metadata.
@@ -47,13 +47,14 @@ import { LoaderBase } from './LoaderBase';
47
47
 
48
48
  *
49
49
  */
50
- export declare class JPEGRLoader extends LoaderBase<string> {
50
+ export declare class HDRJPGLoader extends LoaderBase<string> {
51
51
  /**
52
+ * Loads a JPEGR Image
52
53
  *
53
- * @param url
54
- * @param onLoad
55
- * @param onProgress
56
- * @param onError
54
+ * @param url An array in the form of [sdr.jpg, gainmap.jpg, metadata.json]
55
+ * @param onLoad Load complete callback, will receive the result
56
+ * @param onProgress Progress callback, will receive a {@link ProgressEvent}
57
+ * @param onError Error callback
57
58
  * @returns
58
59
  */
59
60
  load(url: string, onLoad?: (data: QuadRenderer<typeof HalfFloatType, GainMapDecoderMaterial>) => void, onProgress?: (event: ProgressEvent) => void, onError?: (err: unknown) => void): QuadRenderer<typeof HalfFloatType, GainMapDecoderMaterial>;
@@ -1,10 +1,10 @@
1
1
  import { type Texture, type WebGLRenderer } from 'three';
2
2
  import { type GainMapMetadata } from '../core/types';
3
3
  /**
4
- * Parameters for decoding a Gainmap
4
+ * Necessary parameters for decoding a Gainmap
5
5
  *
6
- * @category Gainmap Specifications
7
- * @group Gainmap Specifications
6
+ * @category Specs
7
+ * @group Specs
8
8
  */
9
9
  export type GainmapDecodingParameters = {
10
10
  /**
@@ -19,8 +19,8 @@ export type GainmapDecodingParameters = {
19
19
  maxDisplayBoost: number;
20
20
  };
21
21
  /**
22
- * @category Decoding
23
- * @group Decoding
22
+ * @category Decoding Functions
23
+ * @group Decoding Functions
24
24
  */
25
25
  export type DecodeParameters = {
26
26
  /**
package/dist/decode.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.2
2
+ * @monogrid/gainmap-js v2.0.4
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
6
- import { Q as QuadRenderer } from './QuadRenderer-IyQj4ZsN.js';
6
+ import { Q as QuadRenderer } from './QuadRenderer-bEJB0XFk.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,12 +15,10 @@ 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 )
18
+ // min half float value
19
+ #define HALF_FLOAT_MIN vec3( -65504, -65504, -65504 )
20
+ // max half float value
21
+ #define HALF_FLOAT_MAX vec3( 65504, 65504, 65504 )
24
22
 
25
23
  uniform sampler2D sdr;
26
24
  uniform sampler2D gainMap;
@@ -34,12 +32,13 @@ uniform float weightFactor;
34
32
  varying vec2 vUv;
35
33
 
36
34
  void main() {
37
- vec3 rgb = texture2D(sdr, vUv).rgb;
38
- vec3 recovery = texture2D(gainMap, vUv).rgb;
39
- vec3 logRecovery = pow(recovery, gamma);
40
- vec3 logBoost = gainMapMin * (1.0 - logRecovery) + gainMapMax * logRecovery;
41
- vec3 hdrColor = (rgb + offsetSdr) * exp2(logBoost * weightFactor) - offsetHdr;
42
- gl_FragColor = vec4( min(FLT_MAX, hdrColor), 1.0 );
35
+ vec3 rgb = texture2D( sdr, vUv ).rgb;
36
+ vec3 recovery = texture2D( gainMap, vUv ).rgb;
37
+ vec3 logRecovery = pow( recovery, gamma );
38
+ vec3 logBoost = gainMapMin * ( 1.0 - logRecovery ) + gainMapMax * logRecovery;
39
+ vec3 hdrColor = (rgb + offsetSdr) * exp2( logBoost * weightFactor ) - offsetHdr;
40
+ vec3 clampedHdrColor = max( HALF_FLOAT_MIN, min( HALF_FLOAT_MAX, hdrColor ));
41
+ gl_FragColor = vec4( clampedHdrColor , 1.0 );
43
42
  }
44
43
  `;
45
44
  /**
@@ -153,8 +152,8 @@ class GainMapDecoderMaterial extends ShaderMaterial {
153
152
  /**
154
153
  * Decodes a gain map using a WebGLRenderTarget
155
154
  *
156
- * @category Decoding
157
- * @group Decoding
155
+ * @category Decoding Functions
156
+ * @group Decoding Functions
158
157
  * @example
159
158
  * import { decode } from '@monogrid/gainmap-js'
160
159
  * import {
@@ -216,6 +215,8 @@ const decode = (params) => {
216
215
  gainMap.needsUpdate = true;
217
216
  const material = new GainMapDecoderMaterial(Object.assign(Object.assign({}, params), { sdr,
218
217
  gainMap }));
218
+ // TODO: three types are generic, eslint complains here, see how we can solve
219
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
219
220
  const quadRenderer = new QuadRenderer(sdr.image.width, sdr.image.height, HalfFloatType, NoColorSpace, material, renderer);
220
221
  try {
221
222
  quadRenderer.render();
@@ -467,9 +468,24 @@ class MPFExtractor {
467
468
  }
468
469
 
469
470
  /**
471
+ * Extracts XMP Metadata and the gain map recovery image
472
+ * from a single JPEG file.
473
+ *
474
+ * @category Decoding Functions
475
+ * @group Decoding Functions
476
+ * @param jpegFile an `Uint8Array` containing and encoded JPEG file
477
+ * @returns an sdr `Uint8Array` compressed in JPEG, a gainMap `Uint8Array` compressed in JPEG and the XMP parsed XMP metadata
478
+ * @throws Error if XMP Metadata is not found
479
+ * @throws Error if Gain map image is not found
480
+ * @example
481
+ * import { FileLoader } from 'three'
482
+ * import { extractGainmapFromJPEG } from '@monogrid/gainmap-js'
470
483
  *
471
- * @param jpegFile
472
- * @returns
484
+ * const jpegFile = await new FileLoader()
485
+ * .setResponseType('arraybuffer')
486
+ * .loadAsync('image.jpg')
487
+ *
488
+ * const { sdr, gainMap, metadata } = extractGainmapFromJPEG(jpegFile)
473
489
  */
474
490
  const extractGainmapFromJPEG = async (jpegFile) => {
475
491
  const metadata = extractXMP(jpegFile);
@@ -627,7 +643,6 @@ class LoaderBase extends Loader {
627
643
  * scene.background.mapping = EquirectangularReflectionMapping
628
644
  * scene.background.minFilter = LinearFilter
629
645
  *
630
- *
631
646
  */
632
647
  class GainMapLoader extends LoaderBase {
633
648
  /**
@@ -638,12 +653,10 @@ class GainMapLoader extends LoaderBase {
638
653
  *
639
654
  * useful for webp gain maps
640
655
  *
641
- * @param sdrUrl
642
- * @param gainMapUrl
643
- * @param metadataUrl
644
- * @param onLoad
645
- * @param onProgress
646
- * @param onError
656
+ * @param urls An array in the form of [sdr.jpg, gainmap.jpg, metadata.json]
657
+ * @param onLoad Load complete callback, will receive the result
658
+ * @param onProgress Progress callback, will receive a {@link ProgressEvent}
659
+ * @param onError Error callback
647
660
  * @returns
648
661
  */
649
662
  load([sdrUrl, gainMapUrl, metadataUrl], onLoad, onProgress, onError) {
@@ -685,7 +698,7 @@ class GainMapLoader extends LoaderBase {
685
698
  if (typeof buffer === 'string')
686
699
  throw new Error('Invalid sdr buffer');
687
700
  sdr = buffer;
688
- loadCheck();
701
+ await loadCheck();
689
702
  }, (e) => {
690
703
  sdrLengthComputable = e.lengthComputable;
691
704
  sdrLoaded = e.loaded;
@@ -701,7 +714,7 @@ class GainMapLoader extends LoaderBase {
701
714
  if (typeof buffer === 'string')
702
715
  throw new Error('Invalid gainmap buffer');
703
716
  gainMap = buffer;
704
- loadCheck();
717
+ await loadCheck();
705
718
  }, (e) => {
706
719
  gainMapLengthComputable = e.lengthComputable;
707
720
  gainMapLoaded = e.loaded;
@@ -716,8 +729,10 @@ class GainMapLoader extends LoaderBase {
716
729
  metadataLoader.load(metadataUrl, async (json) => {
717
730
  if (typeof json !== 'string')
718
731
  throw new Error('Invalid metadata string');
732
+ // TODO: implement check on JSON file and remove this eslint disable
733
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
719
734
  metadata = JSON.parse(json);
720
- loadCheck();
735
+ await loadCheck();
721
736
  }, (e) => {
722
737
  metadataLengthComputable = e.lengthComputable;
723
738
  metadataLoaded = e.loaded;
@@ -773,13 +788,14 @@ class GainMapLoader extends LoaderBase {
773
788
 
774
789
  *
775
790
  */
776
- class JPEGRLoader extends LoaderBase {
791
+ class HDRJPGLoader extends LoaderBase {
777
792
  /**
793
+ * Loads a JPEGR Image
778
794
  *
779
- * @param url
780
- * @param onLoad
781
- * @param onProgress
782
- * @param onError
795
+ * @param url An array in the form of [sdr.jpg, gainmap.jpg, metadata.json]
796
+ * @param onLoad Load complete callback, will receive the result
797
+ * @param onProgress Progress callback, will receive a {@link ProgressEvent}
798
+ * @param onError Error callback
783
799
  * @returns
784
800
  */
785
801
  load(url, onLoad, onProgress, onError) {
@@ -802,4 +818,4 @@ class JPEGRLoader extends LoaderBase {
802
818
  }
803
819
  }
804
820
 
805
- export { GainMapDecoderMaterial, GainMapLoader, JPEGRLoader, QuadRenderer, decode, extractGainmapFromJPEG };
821
+ export { GainMapDecoderMaterial, GainMapLoader, HDRJPGLoader, HDRJPGLoader as JPEGRLoader, QuadRenderer, decode, extractGainmapFromJPEG };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.2
2
+ * @monogrid/gainmap-js v2.0.4
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
@@ -78,10 +78,10 @@
78
78
  return _canReadPixelsResult;
79
79
  };
80
80
  /**
81
- * Utility structure used for rendering a texture with a material
81
+ * Utility class used for rendering a texture with a material
82
82
  *
83
- * @category General
84
- * @group General
83
+ * @category Core
84
+ * @group Core
85
85
  */
86
86
  class QuadRenderer {
87
87
  /**
@@ -248,12 +248,10 @@ 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 )
251
+ // min half float value
252
+ #define HALF_FLOAT_MIN vec3( -65504, -65504, -65504 )
253
+ // max half float value
254
+ #define HALF_FLOAT_MAX vec3( 65504, 65504, 65504 )
257
255
 
258
256
  uniform sampler2D sdr;
259
257
  uniform sampler2D gainMap;
@@ -267,12 +265,13 @@ uniform float weightFactor;
267
265
  varying vec2 vUv;
268
266
 
269
267
  void main() {
270
- vec3 rgb = texture2D(sdr, vUv).rgb;
271
- vec3 recovery = texture2D(gainMap, vUv).rgb;
272
- vec3 logRecovery = pow(recovery, gamma);
273
- vec3 logBoost = gainMapMin * (1.0 - logRecovery) + gainMapMax * logRecovery;
274
- vec3 hdrColor = (rgb + offsetSdr) * exp2(logBoost * weightFactor) - offsetHdr;
275
- gl_FragColor = vec4( min(FLT_MAX, hdrColor), 1.0 );
268
+ vec3 rgb = texture2D( sdr, vUv ).rgb;
269
+ vec3 recovery = texture2D( gainMap, vUv ).rgb;
270
+ vec3 logRecovery = pow( recovery, gamma );
271
+ vec3 logBoost = gainMapMin * ( 1.0 - logRecovery ) + gainMapMax * logRecovery;
272
+ vec3 hdrColor = (rgb + offsetSdr) * exp2( logBoost * weightFactor ) - offsetHdr;
273
+ vec3 clampedHdrColor = max( HALF_FLOAT_MIN, min( HALF_FLOAT_MAX, hdrColor ));
274
+ gl_FragColor = vec4( clampedHdrColor , 1.0 );
276
275
  }
277
276
  `;
278
277
  /**
@@ -386,8 +385,8 @@ void main() {
386
385
  /**
387
386
  * Decodes a gain map using a WebGLRenderTarget
388
387
  *
389
- * @category Decoding
390
- * @group Decoding
388
+ * @category Decoding Functions
389
+ * @group Decoding Functions
391
390
  * @example
392
391
  * import { decode } from '@monogrid/gainmap-js'
393
392
  * import {
@@ -449,6 +448,8 @@ void main() {
449
448
  gainMap.needsUpdate = true;
450
449
  const material = new GainMapDecoderMaterial(Object.assign(Object.assign({}, params), { sdr,
451
450
  gainMap }));
451
+ // TODO: three types are generic, eslint complains here, see how we can solve
452
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
452
453
  const quadRenderer = new QuadRenderer(sdr.image.width, sdr.image.height, three.HalfFloatType, three.NoColorSpace, material, renderer);
453
454
  try {
454
455
  quadRenderer.render();
@@ -700,9 +701,24 @@ void main() {
700
701
  }
701
702
 
702
703
  /**
704
+ * Extracts XMP Metadata and the gain map recovery image
705
+ * from a single JPEG file.
703
706
  *
704
- * @param jpegFile
705
- * @returns
707
+ * @category Decoding Functions
708
+ * @group Decoding Functions
709
+ * @param jpegFile an `Uint8Array` containing and encoded JPEG file
710
+ * @returns an sdr `Uint8Array` compressed in JPEG, a gainMap `Uint8Array` compressed in JPEG and the XMP parsed XMP metadata
711
+ * @throws Error if XMP Metadata is not found
712
+ * @throws Error if Gain map image is not found
713
+ * @example
714
+ * import { FileLoader } from 'three'
715
+ * import { extractGainmapFromJPEG } from '@monogrid/gainmap-js'
716
+ *
717
+ * const jpegFile = await new FileLoader()
718
+ * .setResponseType('arraybuffer')
719
+ * .loadAsync('image.jpg')
720
+ *
721
+ * const { sdr, gainMap, metadata } = extractGainmapFromJPEG(jpegFile)
706
722
  */
707
723
  const extractGainmapFromJPEG = async (jpegFile) => {
708
724
  const metadata = extractXMP(jpegFile);
@@ -860,7 +876,6 @@ void main() {
860
876
  * scene.background.mapping = EquirectangularReflectionMapping
861
877
  * scene.background.minFilter = LinearFilter
862
878
  *
863
- *
864
879
  */
865
880
  class GainMapLoader extends LoaderBase {
866
881
  /**
@@ -871,12 +886,10 @@ void main() {
871
886
  *
872
887
  * useful for webp gain maps
873
888
  *
874
- * @param sdrUrl
875
- * @param gainMapUrl
876
- * @param metadataUrl
877
- * @param onLoad
878
- * @param onProgress
879
- * @param onError
889
+ * @param urls An array in the form of [sdr.jpg, gainmap.jpg, metadata.json]
890
+ * @param onLoad Load complete callback, will receive the result
891
+ * @param onProgress Progress callback, will receive a {@link ProgressEvent}
892
+ * @param onError Error callback
880
893
  * @returns
881
894
  */
882
895
  load([sdrUrl, gainMapUrl, metadataUrl], onLoad, onProgress, onError) {
@@ -918,7 +931,7 @@ void main() {
918
931
  if (typeof buffer === 'string')
919
932
  throw new Error('Invalid sdr buffer');
920
933
  sdr = buffer;
921
- loadCheck();
934
+ await loadCheck();
922
935
  }, (e) => {
923
936
  sdrLengthComputable = e.lengthComputable;
924
937
  sdrLoaded = e.loaded;
@@ -934,7 +947,7 @@ void main() {
934
947
  if (typeof buffer === 'string')
935
948
  throw new Error('Invalid gainmap buffer');
936
949
  gainMap = buffer;
937
- loadCheck();
950
+ await loadCheck();
938
951
  }, (e) => {
939
952
  gainMapLengthComputable = e.lengthComputable;
940
953
  gainMapLoaded = e.loaded;
@@ -949,8 +962,10 @@ void main() {
949
962
  metadataLoader.load(metadataUrl, async (json) => {
950
963
  if (typeof json !== 'string')
951
964
  throw new Error('Invalid metadata string');
965
+ // TODO: implement check on JSON file and remove this eslint disable
966
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
952
967
  metadata = JSON.parse(json);
953
- loadCheck();
968
+ await loadCheck();
954
969
  }, (e) => {
955
970
  metadataLengthComputable = e.lengthComputable;
956
971
  metadataLoaded = e.loaded;
@@ -1006,13 +1021,14 @@ void main() {
1006
1021
 
1007
1022
  *
1008
1023
  */
1009
- class JPEGRLoader extends LoaderBase {
1024
+ class HDRJPGLoader extends LoaderBase {
1010
1025
  /**
1026
+ * Loads a JPEGR Image
1011
1027
  *
1012
- * @param url
1013
- * @param onLoad
1014
- * @param onProgress
1015
- * @param onError
1028
+ * @param url An array in the form of [sdr.jpg, gainmap.jpg, metadata.json]
1029
+ * @param onLoad Load complete callback, will receive the result
1030
+ * @param onProgress Progress callback, will receive a {@link ProgressEvent}
1031
+ * @param onError Error callback
1016
1032
  * @returns
1017
1033
  */
1018
1034
  load(url, onLoad, onProgress, onError) {
@@ -1037,7 +1053,8 @@ void main() {
1037
1053
 
1038
1054
  exports.GainMapDecoderMaterial = GainMapDecoderMaterial;
1039
1055
  exports.GainMapLoader = GainMapLoader;
1040
- exports.JPEGRLoader = JPEGRLoader;
1056
+ exports.HDRJPGLoader = HDRJPGLoader;
1057
+ exports.JPEGRLoader = HDRJPGLoader;
1041
1058
  exports.QuadRenderer = QuadRenderer;
1042
1059
  exports.decode = decode;
1043
1060
  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 Encoding Functions
8
- * @group Encoding Functions
7
+ * @category Utility
8
+ * @group Utility
9
9
  *
10
10
  * @param srcTex
11
11
  * @param mode
@@ -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 Gainmap Specifications
9
- * @group Gainmap Specifications
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 General
97
- * @group General
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 General
104
- * @group General
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
2
+ * @monogrid/gainmap-js v2.0.4
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
6
- import { c as compress } from './compress-sMTWjMym.js';
6
+ import { c as compress } from './compress-aBsBfoFB.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-IyQj4ZsN.js';
8
+ import { Q as QuadRenderer } from './QuadRenderer-bEJB0XFk.js';
9
9
 
10
10
  /**
11
11
  * Utility function to obtain a `DataTexture` from various input formats
12
12
  *
13
- * @category General
14
- * @group General
13
+ * @category Utility
14
+ * @group Utility
15
15
  *
16
16
  * @param image
17
17
  * @returns
@@ -645,8 +645,8 @@ void main() {
645
645
  `;
646
646
  /**
647
647
  *
648
- * @category Encoding Functions
649
- * @group Encoding Functions
648
+ * @category Utility
649
+ * @group Utility
650
650
  *
651
651
  * @param srcTex
652
652
  * @param mode
@@ -699,7 +699,9 @@ const findTextureMinMax = (image, mode = 'max', renderer) => {
699
699
  quadRenderer.renderTarget = fbi;
700
700
  quadRenderer.render();
701
701
  mat.uniforms.map.value = fbi.texture;
702
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
702
703
  mat.uniforms.u_srcResolution.value.x = w;
704
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
703
705
  mat.uniforms.u_srcResolution.value.y = h;
704
706
  });
705
707
  const out = quadRenderer.toArray();
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.2
2
+ * @monogrid/gainmap-js v2.0.4
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
@@ -88,8 +88,8 @@
88
88
  /**
89
89
  * Utility function to obtain a `DataTexture` from various input formats
90
90
  *
91
- * @category General
92
- * @group General
91
+ * @category Utility
92
+ * @group Utility
93
93
  *
94
94
  * @param image
95
95
  * @returns
@@ -183,10 +183,10 @@
183
183
  return _canReadPixelsResult;
184
184
  };
185
185
  /**
186
- * Utility structure used for rendering a texture with a material
186
+ * Utility class used for rendering a texture with a material
187
187
  *
188
- * @category General
189
- * @group General
188
+ * @category Core
189
+ * @group Core
190
190
  */
191
191
  class QuadRenderer {
192
192
  /**
@@ -953,8 +953,8 @@ void main() {
953
953
  `;
954
954
  /**
955
955
  *
956
- * @category Encoding Functions
957
- * @group Encoding Functions
956
+ * @category Utility
957
+ * @group Utility
958
958
  *
959
959
  * @param srcTex
960
960
  * @param mode
@@ -1007,7 +1007,9 @@ void main() {
1007
1007
  quadRenderer.renderTarget = fbi;
1008
1008
  quadRenderer.render();
1009
1009
  mat.uniforms.map.value = fbi.texture;
1010
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
1010
1011
  mat.uniforms.u_srcResolution.value.x = w;
1012
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
1011
1013
  mat.uniforms.u_srcResolution.value.y = h;
1012
1014
  });
1013
1015
  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 General
5
- * @group General
4
+ * @category WASM
5
+ * @group WASM
6
6
  *
7
7
  * @returns
8
8
  */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.2
2
+ * @monogrid/gainmap-js v2.0.4
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 General
6537
- * @group General
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];
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.2
2
+ * @monogrid/gainmap-js v2.0.4
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
@@ -6540,8 +6540,8 @@
6540
6540
  let library;
6541
6541
  /**
6542
6542
  * Instances the WASM module and returns it, only one module will be created upon multiple calls.
6543
- * @category General
6544
- * @group General
6543
+ * @category WASM
6544
+ * @group WASM
6545
6545
  *
6546
6546
  * @returns
6547
6547
  */
@@ -6610,7 +6610,7 @@
6610
6610
  const lib = await getLibrary();
6611
6611
  const result = lib.extractJpegR(file, file.length);
6612
6612
  if (!result.success)
6613
- throw new Error(result.errorMessage);
6613
+ throw new Error(`${result.errorMessage}`);
6614
6614
  const parser = new DOMParser();
6615
6615
  const xmlDocument = parser.parseFromString(result.metadata, 'text/xml');
6616
6616
  const description = xmlDocument.getElementsByTagName('rdf:Description')[0];
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.2
2
+ * @monogrid/gainmap-js v2.0.4
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
6
- import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers-sElGEoua.js';
6
+ import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers-bdHH9bEd.js';
7
7
 
8
8
  var lib$1;
9
9
  var hasRequiredLib$1;
@@ -474,6 +474,7 @@ var PromiseWorker$1 = /*@__PURE__*/getDefaultExportFromCjs(promiseWorkerTransfer
474
474
  * @returns
475
475
  */
476
476
  const getPromiseWorker = (worker) => {
477
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
477
478
  return new PromiseWorker$1(worker);
478
479
  };
479
480
  /**
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.2
2
+ * @monogrid/gainmap-js v2.0.4
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
@@ -484,6 +484,7 @@
484
484
  * @returns
485
485
  */
486
486
  const getPromiseWorker = (worker) => {
487
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
487
488
  return new PromiseWorker$1(worker);
488
489
  };
489
490
  /**
package/dist/worker.js CHANGED
@@ -1,10 +1,10 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.2
2
+ * @monogrid/gainmap-js v2.0.4
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
6
- import { g as getDefaultExportFromCjs } from './_commonjsHelpers-sElGEoua.js';
7
- import { c as compress } from './compress-sMTWjMym.js';
6
+ import { g as getDefaultExportFromCjs } from './_commonjsHelpers-bdHH9bEd.js';
7
+ import { c as compress } from './compress-aBsBfoFB.js';
8
8
 
9
9
  var isPromise$2 = {exports: {}};
10
10
 
@@ -113,6 +113,7 @@ const _compress = async (message, withTransferList) => {
113
113
  const result = await compress(message.payload);
114
114
  return withTransferList(Object.assign(Object.assign({}, result), { source: message.payload.source instanceof ImageData ? message.payload.source.data : new Uint8ClampedArray(message.payload.source) }), [result.data.buffer, message.payload.source instanceof ImageData ? message.payload.source.data.buffer : message.payload.source.buffer]);
115
115
  };
116
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
116
117
  registerPromiseWorker$1(async (message, withTransferList) => {
117
118
  switch (message.type) {
118
119
  // case 'encode-gainmap-buffers':
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.2
2
+ * @monogrid/gainmap-js v2.0.4
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
@@ -195,6 +195,7 @@
195
195
  const result = await compress(message.payload);
196
196
  return withTransferList(Object.assign(Object.assign({}, result), { source: message.payload.source instanceof ImageData ? message.payload.source.data : new Uint8ClampedArray(message.payload.source) }), [result.data.buffer, message.payload.source instanceof ImageData ? message.payload.source.data.buffer : message.payload.source.buffer]);
197
197
  };
198
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
198
199
  registerPromiseWorker$1(async (message, withTransferList) => {
199
200
  switch (message.type) {
200
201
  // case 'encode-gainmap-buffers':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monogrid/gainmap-js",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "description": "A Javascript (TypeScript) Port of Adobe Gainmap Technology for storing HDR Images using an SDR Image + a gain map",
5
5
  "homepage": "https://github.com/MONOGRID/gainmap-js#readme",
6
6
  "repository": {
@@ -124,6 +124,7 @@
124
124
  "cz-conventional-changelog": "^3.3.0",
125
125
  "eslint": "^8.53.0",
126
126
  "eslint-config-standard": "^17.0.0",
127
+ "eslint-plugin-html": "^7.1.0",
127
128
  "eslint-plugin-import": "^2.29.0",
128
129
  "eslint-plugin-jest-extended": "^2.0.0",
129
130
  "eslint-plugin-n": "^16.3.1",