@monogrid/gainmap-js 1.1.0 → 1.1.1

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
+ ## [1.1.1](https://github.com/MONOGRID/gainmap-js/compare/v1.1.0...v1.1.1) (2023-11-09)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * fixes Firefox Compatibility ([1cec657](https://github.com/MONOGRID/gainmap-js/commit/1cec65708127b6fd064277f4f923fc0f65610fa2))
7
+ * **libultrahdr:** fixes circular dependency between JPEGRLoader and libultrahdr ([f30f786](https://github.com/MONOGRID/gainmap-js/commit/f30f7865fb27a601635168b8a104a9935653e758))
8
+
1
9
  # [1.1.0](https://github.com/MONOGRID/gainmap-js/compare/v1.0.2...v1.1.0) (2023-11-06)
2
10
 
3
11
 
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @monogrid/gainmap-js v1.0.2
2
+ * @monogrid/gainmap-js v1.1.0
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
6
- import { ShaderMaterial, Vector3, NoBlending, Scene, OrthographicCamera, Mesh, PlaneGeometry, WebGLRenderTarget, RGBAFormat, LinearFilter, LinearMipMapLinearFilter, RepeatWrapping, WebGLRenderer, FloatType, IntType, ShortType, ByteType, UnsignedIntType, HalfFloatType, UnsignedByteType, DataTexture, UVMapping, NoColorSpace, Loader, Texture, ClampToEdgeWrapping, SRGBColorSpace } from 'three';
6
+ import { ShaderMaterial, Vector3, NoBlending, HalfFloatType, FloatType, Scene, OrthographicCamera, Mesh, PlaneGeometry, WebGLRenderTarget, RGBAFormat, LinearFilter, LinearMipMapLinearFilter, RepeatWrapping, WebGLRenderer, IntType, ShortType, ByteType, UnsignedIntType, UnsignedByteType, DataTexture, UVMapping, NoColorSpace, Loader, Texture, ClampToEdgeWrapping, SRGBColorSpace } from 'three';
7
7
 
8
8
  const vertexShader = /* glsl */ `
9
9
  varying vec2 vUv;
@@ -172,6 +172,10 @@ class QuadRenderer {
172
172
  this._width = width;
173
173
  this._height = height;
174
174
  this._type = type;
175
+ this._colorSpace = colorSpace;
176
+ if (type === HalfFloatType && navigator.userAgent.toLowerCase().includes('firefox')) {
177
+ this._type = FloatType;
178
+ }
175
179
  this._material = material;
176
180
  if (renderer) {
177
181
  this._renderer = renderer;
@@ -192,7 +196,7 @@ class QuadRenderer {
192
196
  this._quad.geometry.computeBoundingBox();
193
197
  this._scene.add(this._quad);
194
198
  this._renderTarget = new WebGLRenderTarget(width, height, {
195
- type,
199
+ type: this._type,
196
200
  colorSpace,
197
201
  format: RGBAFormat,
198
202
  magFilter: LinearFilter,
@@ -254,7 +258,7 @@ class QuadRenderer {
254
258
  return out;
255
259
  }
256
260
  toDataTexture() {
257
- return new DataTexture(this.toArray(), this.width, this.height, RGBAFormat, HalfFloatType, UVMapping, RepeatWrapping, RepeatWrapping, LinearFilter, LinearMipMapLinearFilter, 1, NoColorSpace);
261
+ return new DataTexture(this.toArray(), this.width, this.height, RGBAFormat, this._type, UVMapping, RepeatWrapping, RepeatWrapping, LinearFilter, LinearMipMapLinearFilter, 1, NoColorSpace);
258
262
  }
259
263
  /**
260
264
  * If using a disposable renderer, it will dispose it.
@@ -300,6 +304,11 @@ class QuadRenderer {
300
304
  * The `Material` used.
301
305
  */
302
306
  get material() { return this._material; }
307
+ /**
308
+ *
309
+ */
310
+ get type() { return this._type; }
311
+ get colorSpace() { return this._colorSpace; }
303
312
  }
304
313
 
305
314
  class LoaderBase extends Loader {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v1.0.2
2
+ * @monogrid/gainmap-js v1.1.0
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v1.0.2
2
+ * @monogrid/gainmap-js v1.1.0
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
@@ -9,8 +9,8 @@ export { SDRMaterial };
9
9
  * @group Encoding Functions
10
10
  *
11
11
  * @param hdrTexture The HDR image to be rendered
12
- * @param renderer (optional) WebGLRenderer to use diring the rendering, a disposable renderer will be create and destroyed if this is not provided.
13
- * @param toneMapping (optional) Tonemapping to be applied to the SDR Rendition
12
+ * @param renderer (optional) WebGLRenderer to use during the rendering, a disposable renderer will be create and destroyed if this is not provided.
13
+ * @param toneMapping (optional) Tone mapping to be applied to the SDR Rendition
14
14
  * @throws {Error} if the WebGLRenderer fails to render the SDR image
15
15
  */
16
16
  export declare const getSDRRendition: (hdrTexture: DataTexture, renderer?: WebGLRenderer, toneMapping?: ToneMapping) => QuadRenderer<1009, SDRMaterial>;
package/dist/encode.d.ts CHANGED
@@ -46,7 +46,7 @@ import { CompressedImage, EncodingParametersBase, EncodingParametersWithCompress
46
46
  * encodingResult.sdr.dispose()
47
47
  * encodingResult.gainMap.dispose()
48
48
  *
49
- * @param params Encoding Paramaters
49
+ * @param params Encoding Parameters
50
50
  * @returns
51
51
  */
52
52
  export declare const encode: (params: EncodingParametersBase) => {
@@ -63,7 +63,7 @@ export declare const encode: (params: EncodingParametersBase) => {
63
63
  * @remarks
64
64
  * if a `renderer` parameter is not provided
65
65
  * This function will automatically dispose its "disposable"
66
- * renderer, no need to disapose it manually later
66
+ * renderer, no need to dispose it manually later
67
67
  *
68
68
  * @category Encoding Functions
69
69
  * @group Encoding Functions
@@ -97,7 +97,7 @@ export declare const encode: (params: EncodingParametersBase) => {
97
97
  * // `jpeg` will be an `Uint8Array` which can be saved somewhere
98
98
  *
99
99
  *
100
- * @param params Encoding Paramaters
100
+ * @param params Encoding Parameters
101
101
  * @throws {Error} if the browser does not support [createImageBitmap](https://caniuse.com/createimagebitmap)
102
102
  */
103
103
  export declare const encodeAndCompress: (params: EncodingParametersWithCompression) => Promise<{
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  /**
2
- * @monogrid/gainmap-js v1.0.2
2
+ * @monogrid/gainmap-js v1.1.0
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';
6
+ import { SRGBColorSpace, NoColorSpace, HalfFloatType, ShaderMaterial, Vector3, NoBlending, DataTexture, RGBAFormat, UVMapping, RepeatWrapping, LinearFilter, UnsignedByteType, ACESFilmicToneMapping, LinearToneMapping, CineonToneMapping, ReinhardToneMapping, Vector2, WebGLRenderTarget, NearestFilter, ClampToEdgeWrapping, FloatType, DataUtils, FileLoader } from 'three';
7
+ import { G as GainMapDecoderMaterial, Q as QuadRenderer, L as LoaderBase } from './LoaderBase-eee19701.js';
8
+ export { G as GainMapDecoderMaterial, Q as QuadRenderer } from './LoaderBase-eee19701.js';
9
9
  import { c as compress } from './compress-a4b59cab.js';
10
10
  export { c as compress } from './compress-a4b59cab.js';
11
11
 
@@ -491,8 +491,8 @@ class SDRMaterial extends ShaderMaterial {
491
491
  * @group Encoding Functions
492
492
  *
493
493
  * @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
494
+ * @param renderer (optional) WebGLRenderer to use during the rendering, a disposable renderer will be create and destroyed if this is not provided.
495
+ * @param toneMapping (optional) Tone mapping to be applied to the SDR Rendition
496
496
  * @throws {Error} if the WebGLRenderer fails to render the SDR image
497
497
  */
498
498
  const getSDRRendition = (hdrTexture, renderer, toneMapping) => {
@@ -555,7 +555,7 @@ const getSDRRendition = (hdrTexture, renderer, toneMapping) => {
555
555
  * encodingResult.sdr.dispose()
556
556
  * encodingResult.gainMap.dispose()
557
557
  *
558
- * @param params Encoding Paramaters
558
+ * @param params Encoding Parameters
559
559
  * @returns
560
560
  */
561
561
  const encode = (params) => {
@@ -590,7 +590,7 @@ const encode = (params) => {
590
590
  * @remarks
591
591
  * if a `renderer` parameter is not provided
592
592
  * This function will automatically dispose its "disposable"
593
- * renderer, no need to disapose it manually later
593
+ * renderer, no need to dispose it manually later
594
594
  *
595
595
  * @category Encoding Functions
596
596
  * @group Encoding Functions
@@ -624,7 +624,7 @@ const encode = (params) => {
624
624
  * // `jpeg` will be an `Uint8Array` which can be saved somewhere
625
625
  *
626
626
  *
627
- * @param params Encoding Paramaters
627
+ * @param params Encoding Parameters
628
628
  * @throws {Error} if the browser does not support [createImageBitmap](https://caniuse.com/createimagebitmap)
629
629
  */
630
630
  const encodeAndCompress = async (params) => {
@@ -751,14 +751,14 @@ const findTextureMinMax = (image, mode = 'max', renderer) => {
751
751
  let w = srcTex.image.width;
752
752
  let h = srcTex.image.height;
753
753
  const quadRenderer = new QuadRenderer(w, h, srcTex.type, srcTex.colorSpace, mat, renderer);
754
- const framebuffers = [];
754
+ const frameBuffers = [];
755
755
  while (w > 1 || h > 1) {
756
756
  w = Math.max(1, (w + cellSize - 1) / cellSize | 0);
757
757
  h = Math.max(1, (h + cellSize - 1) / cellSize | 0);
758
758
  const fb = new WebGLRenderTarget(w, h, {
759
- type: srcTex.type,
759
+ type: quadRenderer.type,
760
760
  format: srcTex.format,
761
- colorSpace: srcTex.colorSpace,
761
+ colorSpace: quadRenderer.colorSpace,
762
762
  minFilter: NearestFilter,
763
763
  magFilter: NearestFilter,
764
764
  wrapS: ClampToEdgeWrapping,
@@ -767,11 +767,11 @@ const findTextureMinMax = (image, mode = 'max', renderer) => {
767
767
  depthBuffer: false,
768
768
  stencilBuffer: false
769
769
  });
770
- framebuffers.push(fb);
770
+ frameBuffers.push(fb);
771
771
  }
772
772
  w = srcTex.image.width;
773
773
  h = srcTex.image.height;
774
- framebuffers.forEach((fbi) => {
774
+ frameBuffers.forEach((fbi) => {
775
775
  w = Math.max(1, (w + cellSize - 1) / cellSize | 0);
776
776
  h = Math.max(1, (h + cellSize - 1) / cellSize | 0);
777
777
  quadRenderer.renderTarget = fbi;
@@ -782,8 +782,12 @@ const findTextureMinMax = (image, mode = 'max', renderer) => {
782
782
  });
783
783
  const out = quadRenderer.toArray();
784
784
  quadRenderer.dispose();
785
- framebuffers.forEach(fb => fb.dispose());
786
- return [DataUtils.fromHalfFloat(out[0]), DataUtils.fromHalfFloat(out[1]), DataUtils.fromHalfFloat(out[2])];
785
+ frameBuffers.forEach(fb => fb.dispose());
786
+ return [
787
+ quadRenderer.type === FloatType ? out[0] : DataUtils.fromHalfFloat(out[0]),
788
+ quadRenderer.type === FloatType ? out[1] : DataUtils.fromHalfFloat(out[1]),
789
+ quadRenderer.type === FloatType ? out[2] : DataUtils.fromHalfFloat(out[2])
790
+ ];
787
791
  };
788
792
 
789
793
  /**
@@ -822,7 +826,7 @@ const findTextureMinMax = (image, mode = 'max', renderer) => {
822
826
  *
823
827
  * // `result.renderTarget.texture` must be
824
828
  * // converted to `DataTexture` in order
825
- * // to use it as Equirectanmgular scene background
829
+ * // to use it as Equirectangular scene background
826
830
  * // if needed
827
831
  *
828
832
  * scene.background = result.toDataTexture()
@@ -838,7 +842,7 @@ class GainMapLoader extends LoaderBase {
838
842
  * * gain map image
839
843
  * * metadata json
840
844
  *
841
- * useful for webp gainmaps
845
+ * useful for webp gain maps
842
846
  *
843
847
  * @param sdrUrl
844
848
  * @param gainMapUrl
package/dist/index.umd.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v1.0.2
2
+ * @monogrid/gainmap-js v1.1.0
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
@@ -176,6 +176,10 @@ void main() {
176
176
  this._width = width;
177
177
  this._height = height;
178
178
  this._type = type;
179
+ this._colorSpace = colorSpace;
180
+ if (type === three.HalfFloatType && navigator.userAgent.toLowerCase().includes('firefox')) {
181
+ this._type = three.FloatType;
182
+ }
179
183
  this._material = material;
180
184
  if (renderer) {
181
185
  this._renderer = renderer;
@@ -196,7 +200,7 @@ void main() {
196
200
  this._quad.geometry.computeBoundingBox();
197
201
  this._scene.add(this._quad);
198
202
  this._renderTarget = new three.WebGLRenderTarget(width, height, {
199
- type,
203
+ type: this._type,
200
204
  colorSpace,
201
205
  format: three.RGBAFormat,
202
206
  magFilter: three.LinearFilter,
@@ -258,7 +262,7 @@ void main() {
258
262
  return out;
259
263
  }
260
264
  toDataTexture() {
261
- return new three.DataTexture(this.toArray(), this.width, this.height, three.RGBAFormat, three.HalfFloatType, three.UVMapping, three.RepeatWrapping, three.RepeatWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, 1, three.NoColorSpace);
265
+ 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.NoColorSpace);
262
266
  }
263
267
  /**
264
268
  * If using a disposable renderer, it will dispose it.
@@ -304,6 +308,11 @@ void main() {
304
308
  * The `Material` used.
305
309
  */
306
310
  get material() { return this._material; }
311
+ /**
312
+ *
313
+ */
314
+ get type() { return this._type; }
315
+ get colorSpace() { return this._colorSpace; }
307
316
  }
308
317
 
309
318
  /**
@@ -864,8 +873,8 @@ void main() {
864
873
  * @group Encoding Functions
865
874
  *
866
875
  * @param hdrTexture The HDR image to be rendered
867
- * @param renderer (optional) WebGLRenderer to use diring the rendering, a disposable renderer will be create and destroyed if this is not provided.
868
- * @param toneMapping (optional) Tonemapping to be applied to the SDR Rendition
876
+ * @param renderer (optional) WebGLRenderer to use during the rendering, a disposable renderer will be create and destroyed if this is not provided.
877
+ * @param toneMapping (optional) Tone mapping to be applied to the SDR Rendition
869
878
  * @throws {Error} if the WebGLRenderer fails to render the SDR image
870
879
  */
871
880
  const getSDRRendition = (hdrTexture, renderer, toneMapping) => {
@@ -928,7 +937,7 @@ void main() {
928
937
  * encodingResult.sdr.dispose()
929
938
  * encodingResult.gainMap.dispose()
930
939
  *
931
- * @param params Encoding Paramaters
940
+ * @param params Encoding Parameters
932
941
  * @returns
933
942
  */
934
943
  const encode = (params) => {
@@ -963,7 +972,7 @@ void main() {
963
972
  * @remarks
964
973
  * if a `renderer` parameter is not provided
965
974
  * This function will automatically dispose its "disposable"
966
- * renderer, no need to disapose it manually later
975
+ * renderer, no need to dispose it manually later
967
976
  *
968
977
  * @category Encoding Functions
969
978
  * @group Encoding Functions
@@ -997,7 +1006,7 @@ void main() {
997
1006
  * // `jpeg` will be an `Uint8Array` which can be saved somewhere
998
1007
  *
999
1008
  *
1000
- * @param params Encoding Paramaters
1009
+ * @param params Encoding Parameters
1001
1010
  * @throws {Error} if the browser does not support [createImageBitmap](https://caniuse.com/createimagebitmap)
1002
1011
  */
1003
1012
  const encodeAndCompress = async (params) => {
@@ -1124,14 +1133,14 @@ void main() {
1124
1133
  let w = srcTex.image.width;
1125
1134
  let h = srcTex.image.height;
1126
1135
  const quadRenderer = new QuadRenderer(w, h, srcTex.type, srcTex.colorSpace, mat, renderer);
1127
- const framebuffers = [];
1136
+ const frameBuffers = [];
1128
1137
  while (w > 1 || h > 1) {
1129
1138
  w = Math.max(1, (w + cellSize - 1) / cellSize | 0);
1130
1139
  h = Math.max(1, (h + cellSize - 1) / cellSize | 0);
1131
1140
  const fb = new three.WebGLRenderTarget(w, h, {
1132
- type: srcTex.type,
1141
+ type: quadRenderer.type,
1133
1142
  format: srcTex.format,
1134
- colorSpace: srcTex.colorSpace,
1143
+ colorSpace: quadRenderer.colorSpace,
1135
1144
  minFilter: three.NearestFilter,
1136
1145
  magFilter: three.NearestFilter,
1137
1146
  wrapS: three.ClampToEdgeWrapping,
@@ -1140,11 +1149,11 @@ void main() {
1140
1149
  depthBuffer: false,
1141
1150
  stencilBuffer: false
1142
1151
  });
1143
- framebuffers.push(fb);
1152
+ frameBuffers.push(fb);
1144
1153
  }
1145
1154
  w = srcTex.image.width;
1146
1155
  h = srcTex.image.height;
1147
- framebuffers.forEach((fbi) => {
1156
+ frameBuffers.forEach((fbi) => {
1148
1157
  w = Math.max(1, (w + cellSize - 1) / cellSize | 0);
1149
1158
  h = Math.max(1, (h + cellSize - 1) / cellSize | 0);
1150
1159
  quadRenderer.renderTarget = fbi;
@@ -1155,8 +1164,12 @@ void main() {
1155
1164
  });
1156
1165
  const out = quadRenderer.toArray();
1157
1166
  quadRenderer.dispose();
1158
- framebuffers.forEach(fb => fb.dispose());
1159
- return [three.DataUtils.fromHalfFloat(out[0]), three.DataUtils.fromHalfFloat(out[1]), three.DataUtils.fromHalfFloat(out[2])];
1167
+ frameBuffers.forEach(fb => fb.dispose());
1168
+ return [
1169
+ quadRenderer.type === three.FloatType ? out[0] : three.DataUtils.fromHalfFloat(out[0]),
1170
+ quadRenderer.type === three.FloatType ? out[1] : three.DataUtils.fromHalfFloat(out[1]),
1171
+ quadRenderer.type === three.FloatType ? out[2] : three.DataUtils.fromHalfFloat(out[2])
1172
+ ];
1160
1173
  };
1161
1174
 
1162
1175
  class LoaderBase extends three.Loader {
@@ -1263,7 +1276,7 @@ void main() {
1263
1276
  *
1264
1277
  * // `result.renderTarget.texture` must be
1265
1278
  * // converted to `DataTexture` in order
1266
- * // to use it as Equirectanmgular scene background
1279
+ * // to use it as Equirectangular scene background
1267
1280
  * // if needed
1268
1281
  *
1269
1282
  * scene.background = result.toDataTexture()
@@ -1279,7 +1292,7 @@ void main() {
1279
1292
  * * gain map image
1280
1293
  * * metadata json
1281
1294
  *
1282
- * useful for webp gainmaps
1295
+ * useful for webp gain maps
1283
1296
  *
1284
1297
  * @param sdrUrl
1285
1298
  * @param gainMapUrl
@@ -0,0 +1,31 @@
1
+ import { GainMapMetadata } from '../types';
2
+ /**
3
+ * Decodes a JPEG file with an embedded Gainmap and XMP Metadata (aka JPEG-R)
4
+ *
5
+ * @category Decoding
6
+ * @group Decoding
7
+ *
8
+ * @example
9
+ * import { decodeJPEGMetadata } from '@monogrid/gainmap-js/libultrahdr'
10
+ *
11
+ * // fetch a JPEG image containing a gainmap as ArrayBuffer
12
+ * const gainmap = new Uint8Array(await (await fetch('gainmap.jpeg')).arrayBuffer())
13
+ *
14
+ * // extract data from the JPEG
15
+ * const { gainMap, sdr, parsedMetadata } = await decodeJPEGMetadata(gainmap)
16
+ *
17
+ * @param file A Jpeg file Uint8Array.
18
+ * @returns The decoded data
19
+ * @throws {Error} if the provided file cannot be parsed or does not contain a valid Gainmap
20
+ */
21
+ export declare const decodeJPEGMetadata: (file: Uint8Array) => Promise<{
22
+ /**
23
+ * Parsed metadata
24
+ */
25
+ parsedMetadata: GainMapMetadata;
26
+ metadata: string | Uint8ClampedArray | ArrayBuffer | Uint8Array | Int8Array;
27
+ success: boolean;
28
+ errorMessage: any;
29
+ sdr: any;
30
+ gainMap: any;
31
+ }>;
@@ -0,0 +1,83 @@
1
+ import { type CompressedImage, type GainMapMetadata } from '../types';
2
+ /**
3
+ * Encapsulates a Gainmap into a single JPEG file (aka: JPEG-R) with the base map
4
+ * as the sdr visualization and the gainMap encoded into a MPF (Multi-Picture Format) tag.
5
+ *
6
+ * @category Encoding
7
+ * @group Encoding
8
+ *
9
+ * @example
10
+ * import { compress, encode, findTextureMinMax } from '@monogrid/gainmap-js'
11
+ * import { encodeJPEGMetadata } from '@monogrid/gainmap-js/libultrahdr'
12
+ * import { EXRLoader } from 'three/examples/jsm/loaders/EXRLoader.js'
13
+ *
14
+ * // load an HDR file
15
+ * const loader = new EXRLoader()
16
+ * const image = await loader.loadAsync('image.exr')
17
+ *
18
+ * // find RAW RGB Max value of a texture
19
+ * const textureMax = await findTextureMinMax(image)
20
+ *
21
+ * // Encode the gainmap
22
+ * const encodingResult = encode({
23
+ * image,
24
+ * maxContentBoost: Math.max.apply(this, textureMax)
25
+ * })
26
+ *
27
+ * // obtain the RAW RGBA SDR buffer and create an ImageData
28
+ * const sdrImageData = new ImageData(
29
+ * encodingResult.sdr.toArray(),
30
+ * encodingResult.sdr.width,
31
+ * encodingResult.sdr.height
32
+ * )
33
+ * // obtain the RAW RGBA Gain map buffer and create an ImageData
34
+ * const gainMapImageData = new ImageData(
35
+ * encodingResult.gainMap.toArray(),
36
+ * encodingResult.gainMap.width,
37
+ * encodingResult.gainMap.height
38
+ * )
39
+ *
40
+ * // parallel compress the RAW buffers into the specified mimeType
41
+ * const mimeType = 'image/jpeg'
42
+ * const quality = 0.9
43
+ *
44
+ * const [sdr, gainMap] = await Promise.all([
45
+ * compress({
46
+ * source: sdrImageData,
47
+ * mimeType,
48
+ * quality,
49
+ * flipY: true // output needs to be flipped
50
+ * }),
51
+ * compress({
52
+ * source: gainMapImageData,
53
+ * mimeType,
54
+ * quality,
55
+ * flipY: true // output needs to be flipped
56
+ * })
57
+ * ])
58
+ *
59
+ * // obtain the metadata which will be embedded into
60
+ * // and XMP tag inside the final JPEG file
61
+ * const metadata = encodingResult.getMetadata()
62
+ *
63
+ * // embed the compressed images + metadata into a single
64
+ * // JPEG file
65
+ * const jpeg = await encodeJPEGMetadata({
66
+ * ...encodingResult,
67
+ * ...metadata,
68
+ * sdr,
69
+ * gainMap
70
+ * })
71
+ *
72
+ * // `jpeg` will be an `Uint8Array` which can be saved somewhere
73
+ *
74
+ *
75
+ * @param encodingResult
76
+ * @returns an Uint8Array representing a JPEG-R file
77
+ * @throws {Error} If `encodingResult.sdr.mimeType !== 'image/jpeg'`
78
+ * @throws {Error} If `encodingResult.gainMap.mimeType !== 'image/jpeg'`
79
+ */
80
+ export declare const encodeJPEGMetadata: (encodingResult: GainMapMetadata & {
81
+ sdr: CompressedImage;
82
+ gainMap: CompressedImage;
83
+ }) => Promise<Uint8Array>;
@@ -0,0 +1,9 @@
1
+ import { MainModule } from '../../libultrahdr-wasm/build/libultrahdr';
2
+ /**
3
+ * Instances the WASM module and returns it, only one module will be created upon multiple calls.
4
+ * @category General
5
+ * @group General
6
+ *
7
+ * @returns
8
+ */
9
+ export declare const getLibrary: () => Promise<MainModule>;
@@ -1,124 +1,5 @@
1
- import { MainModule } from '../libultrahdr-wasm/build/libultrahdr';
2
- import { CompressedImage, GainMapMetadata } from './types';
3
1
  export * from '../libultrahdr-wasm/build/libultrahdr';
2
+ export * from './libultrahdr/decode-jpeg-metadata';
3
+ export * from './libultrahdr/encode-jpeg-metadata';
4
+ export * from './libultrahdr/library';
4
5
  export * from './loaders/JPEGRLoader';
5
- /**
6
- * Instances the WASM module and returns it, only one module will be created upon multiple calls.
7
- * @category General
8
- * @group General
9
- *
10
- * @returns
11
- */
12
- export declare const getLibrary: () => Promise<MainModule>;
13
- /**
14
- * Encapsulates a Gainmap into a single JPEG file (aka: JPEG-R) with the base map
15
- * as the sdr visualization and the gainMap encoded into a MPF (Multi-Picture Format) tag.
16
- *
17
- * @category Encoding
18
- * @group Encoding
19
- *
20
- * @example
21
- * import { compress, encode, findTextureMinMax } from '@monogrid/gainmap-js'
22
- * import { encodeJPEGMetadata } from '@monogrid/gainmap-js/libultrahdr'
23
- * import { EXRLoader } from 'three/examples/jsm/loaders/EXRLoader.js'
24
- *
25
- * // load an HDR file
26
- * const loader = new EXRLoader()
27
- * const image = await loader.loadAsync('image.exr')
28
- *
29
- * // find RAW RGB Max value of a texture
30
- * const textureMax = await findTextureMinMax(image)
31
- *
32
- * // Encode the gainmap
33
- * const encodingResult = encode({
34
- * image,
35
- * maxContentBoost: Math.max.apply(this, textureMax)
36
- * })
37
- *
38
- * // obtain the RAW RGBA SDR buffer and create an ImageData
39
- * const sdrImageData = new ImageData(
40
- * encodingResult.sdr.toArray(),
41
- * encodingResult.sdr.width,
42
- * encodingResult.sdr.height
43
- * )
44
- * // obtain the RAW RGBA Gain map buffer and create an ImageData
45
- * const gainMapImageData = new ImageData(
46
- * encodingResult.gainMap.toArray(),
47
- * encodingResult.gainMap.width,
48
- * encodingResult.gainMap.height
49
- * )
50
- *
51
- * // parallel compress the RAW buffers into the specified mimeType
52
- * const mimeType = 'image/jpeg'
53
- * const quality = 0.9
54
- *
55
- * const [sdr, gainMap] = await Promise.all([
56
- * compress({
57
- * source: sdrImageData,
58
- * mimeType,
59
- * quality,
60
- * flipY: true // output needs to be flipped
61
- * }),
62
- * compress({
63
- * source: gainMapImageData,
64
- * mimeType,
65
- * quality,
66
- * flipY: true // output needs to be flipped
67
- * })
68
- * ])
69
- *
70
- * // obtain the metadata which will be embedded into
71
- * // and XMP tag inside the final JPEG file
72
- * const metadata = encodingResult.getMetadata()
73
- *
74
- * // embed the compressed images + metadata into a single
75
- * // JPEG file
76
- * const jpeg = await encodeJPEGMetadata({
77
- * ...encodingResult,
78
- * ...metadata,
79
- * sdr,
80
- * gainMap
81
- * })
82
- *
83
- * // `jpeg` will be an `Uint8Array` which can be saved somewhere
84
- *
85
- *
86
- * @param encodingResult
87
- * @returns an Uint8Array representing a JPEG-R file
88
- * @throws {Error} If `encodingResult.sdr.mimeType !== 'image/jpeg'`
89
- * @throws {Error} If `encodingResult.gainMap.mimeType !== 'image/jpeg'`
90
- */
91
- export declare const encodeJPEGMetadata: (encodingResult: GainMapMetadata & {
92
- sdr: CompressedImage;
93
- gainMap: CompressedImage;
94
- }) => Promise<Uint8Array>;
95
- /**
96
- * Decodes a JPEG file with an embedded Gainmap and XMP Metadata (aka JPEG-R)
97
- *
98
- * @category Decoding
99
- * @group Decoding
100
- *
101
- * @example
102
- * import { decodeJPEGMetadata } from '@monogrid/gainmap-js/libultrahdr'
103
- *
104
- * // fetch a JPEG image containing a gainmap as ArrayBuffer
105
- * const gainmap = new Uint8Array(await (await fetch('gainmap.jpeg')).arrayBuffer())
106
- *
107
- * // extract data from the JPEG
108
- * const { gainMap, sdr, parsedMetadata } = await decodeJPEGMetadata(gainmap)
109
- *
110
- * @param file A Jpeg file Uint8Array.
111
- * @returns The decoded data
112
- * @throws {Error} if the provided file cannot be parsed or does not contain a valid Gainmap
113
- */
114
- export declare const decodeJPEGMetadata: (file: Uint8Array) => Promise<{
115
- /**
116
- * Parsed metadata
117
- */
118
- parsedMetadata: GainMapMetadata;
119
- metadata: string | Uint8ClampedArray | ArrayBuffer | Uint8Array | Int8Array;
120
- success: boolean;
121
- errorMessage: any;
122
- sdr: any;
123
- gainMap: any;
124
- }>;