@monogrid/gainmap-js 1.1.1 → 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 (49) hide show
  1. package/CHANGELOG.md +14 -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/core/types.d.ts +64 -0
  8. package/dist/decode/decode.d.ts +56 -0
  9. package/dist/decode/extract.d.ts +10 -0
  10. package/dist/decode/index.d.ts +8 -0
  11. package/dist/{loaders → decode/loaders}/GainMapLoader.d.ts +2 -2
  12. package/dist/{loaders → decode/loaders}/JPEGRLoader.d.ts +4 -4
  13. package/dist/{materials → decode/materials}/GainMapDecoderMaterial.d.ts +3 -2
  14. package/dist/decode/types.d.ts +38 -0
  15. package/dist/decode/utils/MPFExtractor.d.ts +22 -0
  16. package/dist/decode/utils/extract-metadata-from-jpeg.d.ts +7 -0
  17. package/dist/decode.d.ts +1 -56
  18. package/dist/decode.js +737 -0
  19. package/dist/decode.umd.js +917 -0
  20. package/dist/{encode-utils → encode}/compress.d.ts +1 -1
  21. package/dist/encode/encode-and-compress.d.ts +61 -0
  22. package/dist/encode/encode.d.ts +58 -0
  23. package/dist/{encode-utils → encode}/get-gainmap.d.ts +3 -3
  24. package/dist/{encode-utils → encode}/get-sdr-rendition.d.ts +2 -3
  25. package/dist/encode/index.d.ts +10 -0
  26. package/dist/{types.d.ts → encode/types.d.ts} +2 -102
  27. package/dist/encode.d.ts +1 -117
  28. package/dist/{index.js → encode.js} +26 -218
  29. package/dist/encode.umd.js +972 -0
  30. package/dist/libultrahdr/decode-jpeg-metadata.d.ts +2 -2
  31. package/dist/libultrahdr/encode-jpeg-metadata.d.ts +2 -1
  32. package/dist/libultrahdr.d.ts +0 -1
  33. package/dist/libultrahdr.js +2 -79
  34. package/dist/libultrahdr.umd.js +10 -460
  35. package/dist/worker-interface.js +2 -2
  36. package/dist/worker-interface.umd.js +1 -3
  37. package/dist/worker-types.d.ts +1 -1
  38. package/dist/worker.js +3 -3
  39. package/dist/worker.umd.js +1 -1
  40. package/package.json +36 -29
  41. package/dist/LoaderBase-eee19701.js +0 -382
  42. package/dist/index.d.ts +0 -11
  43. package/dist/index.umd.js +0 -1373
  44. package/dist/materials/index.d.ts +0 -3
  45. /package/dist/{utils → core}/QuadRenderer.d.ts +0 -0
  46. /package/dist/{utils → core}/get-data-texture.d.ts +0 -0
  47. /package/dist/{encode-utils → encode}/find-texture-min-max.d.ts +0 -0
  48. /package/dist/{materials → encode/materials}/GainMapEncoderMaterial.d.ts +0 -0
  49. /package/dist/{materials → encode/materials}/SDRMaterial.d.ts +0 -0
@@ -1,4 +1,4 @@
1
- import { CompressedImage, CompressParameters } from '../types';
1
+ import { CompressedImage, CompressParameters } from './types';
2
2
  /**
3
3
  * Converts a RAW RGBA image buffer into the provided `mimeType` using the provided `quality`
4
4
  *
@@ -0,0 +1,61 @@
1
+ import { CompressedImage, EncodingParametersWithCompression } from './types';
2
+ /**
3
+ * Encodes a Gainmap starting from an HDR file into compressed file formats (`image/jpeg`, `image/webp` or `image/png`).
4
+ *
5
+ * Uses {@link encode} internally, then pipes the results to {@link compress}.
6
+ *
7
+ * @remarks
8
+ * if a `renderer` parameter is not provided
9
+ * This function will automatically dispose its "disposable"
10
+ * renderer, no need to dispose it manually later
11
+ *
12
+ * @category Encoding Functions
13
+ * @group Encoding Functions
14
+ * @example
15
+ * import { encodeAndCompress, findTextureMinMax } from '@monogrid/gainmap-js'
16
+ * import { encodeJPEGMetadata } from '@monogrid/gainmap-js/libultrahdr'
17
+ * import { EXRLoader } from 'three/examples/jsm/loaders/EXRLoader.js'
18
+ *
19
+ * // load an HDR file
20
+ * const loader = new EXRLoader()
21
+ * const image = await loader.loadAsync('image.exr')
22
+ *
23
+ * // find RAW RGB Max value of a texture
24
+ * const textureMax = await findTextureMinMax(image)
25
+ *
26
+ * // Encode the gainmap
27
+ * const encodingResult = await encodeAndCompress({
28
+ * image,
29
+ * maxContentBoost: Math.max.apply(this, textureMax),
30
+ * mimeType: 'image/jpeg'
31
+ * })
32
+ *
33
+ * // embed the compressed images + metadata into a single
34
+ * // JPEG file
35
+ * const jpeg = await encodeJPEGMetadata({
36
+ * ...encodingResult,
37
+ * sdr: encodingResult.sdr,
38
+ * gainMap: encodingResult.gainMap
39
+ * })
40
+ *
41
+ * // `jpeg` will be an `Uint8Array` which can be saved somewhere
42
+ *
43
+ *
44
+ * @param params Encoding Parameters
45
+ * @throws {Error} if the browser does not support [createImageBitmap](https://caniuse.com/createimagebitmap)
46
+ */
47
+ export declare const encodeAndCompress: (params: EncodingParametersWithCompression) => Promise<{
48
+ sdr: CompressedImage;
49
+ gainMap: CompressedImage;
50
+ rawSDR: Uint8ClampedArray;
51
+ rawGainMap: Uint8ClampedArray;
52
+ gamma: [number, number, number];
53
+ hdrCapacityMin: number;
54
+ hdrCapacityMax: number;
55
+ offsetSdr: [number, number, number];
56
+ offsetHdr: [number, number, number];
57
+ gainMapMin: [number, number, number];
58
+ gainMapMax: [number, number, number];
59
+ hdr: import("three").DataTexture;
60
+ getMetadata: () => import(".").GainMapMetadata;
61
+ }>;
@@ -0,0 +1,58 @@
1
+ import { GainMapMetadata } from '../core/types';
2
+ import { EncodingParametersBase } from './types';
3
+ /**
4
+ * Encodes a Gainmap starting from an HDR file.
5
+ *
6
+ * @remarks
7
+ * if you do not pass a `renderer` parameter
8
+ * you must manually dispose the result
9
+ * ```js
10
+ * const encodingResult = await encode({ ... })
11
+ * // do something with the buffers
12
+ * const sdr = encodingResult.sdr.getArray()
13
+ * const gainMap = encodingResult.gainMap.getArray()
14
+ * // after that
15
+ * encodingResult.sdr.dispose()
16
+ * encodingResult.gainMap.dispose()
17
+ * ```
18
+ *
19
+ * @category Encoding Functions
20
+ * @group Encoding Functions
21
+ *
22
+ * @example
23
+ * import { encode, findTextureMinMax } from '@monogrid/gainmap-js'
24
+ * import { EXRLoader } from 'three/examples/jsm/loaders/EXRLoader.js'
25
+ *
26
+ * // load an HDR file
27
+ * const loader = new EXRLoader()
28
+ * const image = await loader.loadAsync('image.exr')
29
+ *
30
+ * // find RAW RGB Max value of a texture
31
+ * const textureMax = await findTextureMinMax(image)
32
+ *
33
+ * // Encode the gainmap
34
+ * const encodingResult = encode({
35
+ * image,
36
+ * // this will encode the full HDR range
37
+ * maxContentBoost: Math.max.apply(this, textureMax)
38
+ * })
39
+ * // can be re-encoded after changing parameters
40
+ * encodingResult.sdr.material.exposure = 0.9
41
+ * encodingResult.sdr.render()
42
+ * // or
43
+ * encodingResult.gainMap.material.gamma = [1.1, 1.1, 1.1]
44
+ * encodingResult.gainMap.render()
45
+ *
46
+ * // must be manually disposed
47
+ * encodingResult.sdr.dispose()
48
+ * encodingResult.gainMap.dispose()
49
+ *
50
+ * @param params Encoding Parameters
51
+ * @returns
52
+ */
53
+ export declare const encode: (params: EncodingParametersBase) => {
54
+ sdr: import("../decode").QuadRenderer<1009, import(".").SDRMaterial>;
55
+ gainMap: import("../decode").QuadRenderer<1009, import(".").GainMapEncoderMaterial>;
56
+ hdr: import("three").DataTexture;
57
+ getMetadata: () => GainMapMetadata;
58
+ };
@@ -1,6 +1,6 @@
1
- import { GainMapEncoderMaterial } from '../materials/GainMapEncoderMaterial';
2
- import { EncodingParametersBase } from '../types';
3
- import { QuadRenderer } from '../utils/QuadRenderer';
1
+ import { QuadRenderer } from '../core/QuadRenderer';
2
+ import { GainMapEncoderMaterial } from './materials/GainMapEncoderMaterial';
3
+ import { EncodingParametersBase } from './types';
4
4
  /**
5
5
  *
6
6
  * @param params
@@ -1,7 +1,6 @@
1
1
  import { DataTexture, ToneMapping, WebGLRenderer } from 'three';
2
- import { SDRMaterial } from '../materials/SDRMaterial';
3
- import { QuadRenderer } from '../utils/QuadRenderer';
4
- export { SDRMaterial };
2
+ import { QuadRenderer } from '../core/QuadRenderer';
3
+ import { SDRMaterial } from './materials/SDRMaterial';
5
4
  /**
6
5
  * Renders an SDR Representation of an HDR Image
7
6
  *
@@ -0,0 +1,10 @@
1
+ export * from '../core/types';
2
+ export * from './compress';
3
+ export * from './encode';
4
+ export * from './encode-and-compress';
5
+ export * from './find-texture-min-max';
6
+ export * from './get-gainmap';
7
+ export * from './get-sdr-rendition';
8
+ export * from './materials/GainMapEncoderMaterial';
9
+ export * from './materials/SDRMaterial';
10
+ export * from './types';
@@ -1,72 +1,8 @@
1
- import { type DataTexture, Texture, ToneMapping, type WebGLRenderer } from 'three';
1
+ import { type DataTexture, ToneMapping, WebGLRenderer } from 'three';
2
2
  import { type EXR } from 'three/examples/jsm/loaders/EXRLoader';
3
3
  import { type LogLuv } from 'three/examples/jsm/loaders/LogLuvLoader';
4
4
  import { type RGBE } from 'three/examples/jsm/loaders/RGBELoader';
5
- import { type WorkerInterfaceImplementation } from './worker-types';
6
- /**
7
- * This is the Metadata stored in an encoded Gainmap which is used
8
- * to decode it and return an HDR image
9
- *
10
- * @category Gainmap Specifications
11
- * @group Gainmap Specifications
12
- */
13
- export type GainMapMetadata = {
14
- /**
15
- * This is the gamma to apply to the stored map values.
16
- * @defaultValue [1, 1, 1]
17
- * @remarks
18
- * * Typically you can use a gamma of 1.0.
19
- * * You can use a different value if your gain map has a very uneven distribution of log_recovery(x, y) values.
20
- *
21
- * For example, this might apply if a gain map has a lot of detail just above SDR range (represented as small log_recovery(x, y) values),
22
- * and a very large map_max_log2 for the top end of the HDR rendition's desired brightness (represented by large log_recovery(x, y) values).
23
- * In this case, you can use a map_gamma higher than 1.0 so that recovery(x, y) can precisely encode the detail in both the low end and high end of log_recovery(x, y).
24
- */
25
- gamma: [number, number, number];
26
- /**
27
- * This is log2 of the minimum display boost value for which the map is applied at all.
28
- *
29
- * @remarks
30
- * * This value also affects how much to apply the gain map based on the display boost.
31
- * * Must be 0.0 or greater.
32
- *
33
- * Logarithmic space
34
- */
35
- hdrCapacityMin: number;
36
- /**
37
- * Stores the value of hdr_capacity_max. This is log2 of the maximum display boost value for which the map is applied completely.
38
- *
39
- * @remarks
40
- * * This value also affects how much to apply the gain map based on the display boost.
41
- * * Must be greater than hdrCapacityMin.
42
- * * Required.
43
- *
44
- * Logarithmic space
45
- */
46
- hdrCapacityMax: number;
47
- /**
48
- * This is the offset to apply to the SDR pixel values during gain map generation and application
49
- * @defaultValue [1/64, 1/64, 1/64]
50
- */
51
- offsetSdr: [number, number, number];
52
- /**
53
- * This is the offset to apply to the HDR pixel values during gain map generation and application.
54
- * @defaultValue [1/64, 1/64, 1/64]
55
- */
56
- offsetHdr: [number, number, number];
57
- /**
58
- * This is log2 of min content boost, which is the minimum allowed ratio of
59
- * the linear luminance for the target HDR rendition relative to
60
- * (divided by) that of the SDR image, at a given pixel.
61
- */
62
- gainMapMin: [number, number, number];
63
- /**
64
- * This is log2 of max content boost, which is the maximum allowed ratio of
65
- * the linear luminance for the Target HDR rendition relative to
66
- * (divided by) that of the SDR image, at a given pixel.
67
- */
68
- gainMapMax: [number, number, number];
69
- };
5
+ import { WorkerInterfaceImplementation } from '../worker-types';
70
6
  /**
71
7
  * Parameters used by content Creators in order to create a GainMap
72
8
  * @category Gainmap Specifications
@@ -124,24 +60,6 @@ export type GainmapEncodingParameters = {
124
60
  */
125
61
  gamma?: [number, number, number];
126
62
  };
127
- /**
128
- * Parameters for decoding a Gainmap
129
- *
130
- * @category Gainmap Specifications
131
- * @group Gainmap Specifications
132
- */
133
- export type GainmapDecodingParameters = {
134
- /**
135
- * The maximum available boost supported by a display, at a given point in time.
136
- *
137
- * @remarks
138
- * This value can change over time based on device settings and other factors,
139
- * such as ambient light conditions, or how many bright pixels are on the screen.
140
- *
141
- * Non Logarithmic space
142
- */
143
- maxDisplayBoost: number;
144
- };
145
63
  /**
146
64
  * Parameters used to Encode a GainMap
147
65
  *
@@ -252,21 +170,3 @@ export type EncodingParametersWithCompression = EncodingParametersBase & Compres
252
170
  */
253
171
  withWorker?: WorkerInterfaceImplementation;
254
172
  };
255
- /**
256
- * @category Decoding
257
- * @group Decoding
258
- */
259
- export type DecodeParameters = {
260
- /**
261
- * An Texture containing the SDR Rendition
262
- */
263
- sdr: Texture;
264
- /**
265
- * An Texture containing the GainMap recovery image
266
- */
267
- gainMap: Texture;
268
- /**
269
- * WebGLRenderer used to decode the GainMap
270
- */
271
- renderer?: WebGLRenderer;
272
- } & GainmapDecodingParameters & GainMapMetadata;
package/dist/encode.d.ts CHANGED
@@ -1,117 +1 @@
1
- import { CompressedImage, EncodingParametersBase, EncodingParametersWithCompression, GainMapMetadata } from './types';
2
- /**
3
- * Encodes a Gainmap starting from an HDR file.
4
- *
5
- * @remarks
6
- * if you do not pass a `renderer` parameter
7
- * you must manually dispose the result
8
- * ```js
9
- * const encodingResult = await encode({ ... })
10
- * // do something with the buffers
11
- * const sdr = encodingResult.sdr.getArray()
12
- * const gainMap = encodingResult.gainMap.getArray()
13
- * // after that
14
- * encodingResult.sdr.dispose()
15
- * encodingResult.gainMap.dispose()
16
- * ```
17
- *
18
- * @category Encoding Functions
19
- * @group Encoding Functions
20
- *
21
- * @example
22
- * import { encode, findTextureMinMax } from '@monogrid/gainmap-js'
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
- * // this will encode the full HDR range
36
- * maxContentBoost: Math.max.apply(this, textureMax)
37
- * })
38
- * // can be re-encoded after changing parameters
39
- * encodingResult.sdr.material.exposure = 0.9
40
- * encodingResult.sdr.render()
41
- * // or
42
- * encodingResult.gainMap.material.gamma = [1.1, 1.1, 1.1]
43
- * encodingResult.gainMap.render()
44
- *
45
- * // must be manually disposed
46
- * encodingResult.sdr.dispose()
47
- * encodingResult.gainMap.dispose()
48
- *
49
- * @param params Encoding Parameters
50
- * @returns
51
- */
52
- export declare const encode: (params: EncodingParametersBase) => {
53
- sdr: import(".").QuadRenderer<1009, import("./materials/SDRMaterial").SDRMaterial>;
54
- gainMap: import(".").QuadRenderer<1009, import("./materials").GainMapEncoderMaterial>;
55
- hdr: import("three").DataTexture;
56
- getMetadata: () => GainMapMetadata;
57
- };
58
- /**
59
- * Encodes a Gainmap starting from an HDR file into compressed file formats (`image/jpeg`, `image/webp` or `image/png`).
60
- *
61
- * Uses {@link encode} internally, then pipes the results to {@link compress}.
62
- *
63
- * @remarks
64
- * if a `renderer` parameter is not provided
65
- * This function will automatically dispose its "disposable"
66
- * renderer, no need to dispose it manually later
67
- *
68
- * @category Encoding Functions
69
- * @group Encoding Functions
70
- * @example
71
- * import { encodeAndCompress, findTextureMinMax } from '@monogrid/gainmap-js'
72
- * import { encodeJPEGMetadata } from '@monogrid/gainmap-js/libultrahdr'
73
- * import { EXRLoader } from 'three/examples/jsm/loaders/EXRLoader.js'
74
- *
75
- * // load an HDR file
76
- * const loader = new EXRLoader()
77
- * const image = await loader.loadAsync('image.exr')
78
- *
79
- * // find RAW RGB Max value of a texture
80
- * const textureMax = await findTextureMinMax(image)
81
- *
82
- * // Encode the gainmap
83
- * const encodingResult = await encodeAndCompress({
84
- * image,
85
- * maxContentBoost: Math.max.apply(this, textureMax),
86
- * mimeType: 'image/jpeg'
87
- * })
88
- *
89
- * // embed the compressed images + metadata into a single
90
- * // JPEG file
91
- * const jpeg = await encodeJPEGMetadata({
92
- * ...encodingResult,
93
- * sdr: encodingResult.sdr,
94
- * gainMap: encodingResult.gainMap
95
- * })
96
- *
97
- * // `jpeg` will be an `Uint8Array` which can be saved somewhere
98
- *
99
- *
100
- * @param params Encoding Parameters
101
- * @throws {Error} if the browser does not support [createImageBitmap](https://caniuse.com/createimagebitmap)
102
- */
103
- export declare const encodeAndCompress: (params: EncodingParametersWithCompression) => Promise<{
104
- sdr: CompressedImage;
105
- gainMap: CompressedImage;
106
- rawSDR: Uint8ClampedArray;
107
- rawGainMap: Uint8ClampedArray;
108
- gamma: [number, number, number];
109
- hdrCapacityMin: number;
110
- hdrCapacityMax: number;
111
- offsetSdr: [number, number, number];
112
- offsetHdr: [number, number, number];
113
- gainMapMin: [number, number, number];
114
- gainMapMax: [number, number, number];
115
- hdr: import("three").DataTexture;
116
- getMetadata: () => GainMapMetadata;
117
- }>;
1
+ export * from './encode/index';
@@ -1,89 +1,39 @@
1
1
  /**
2
- * @monogrid/gainmap-js v1.1.0
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, 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
- 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
@@ -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
  *
@@ -790,118 +712,4 @@ const findTextureMinMax = (image, mode = 'max', renderer) => {
790
712
  ];
791
713
  };
792
714
 
793
- /**
794
- * A Three.js Loader for the gain map format.
795
- *
796
- * @category Loaders
797
- * @group Loaders
798
- *
799
- * @example
800
- * import { GainMapLoader } from '@monogrid/gainmap-js'
801
- * import {
802
- * EquirectangularReflectionMapping,
803
- * LinearFilter,
804
- * Mesh,
805
- * MeshBasicMaterial,
806
- * PerspectiveCamera,
807
- * PlaneGeometry,
808
- * Scene,
809
- * WebGLRenderer
810
- * } from 'three'
811
- *
812
- * const renderer = new WebGLRenderer()
813
- *
814
- * const loader = new GainMapLoader(renderer)
815
- *
816
- * const result = loader.load(['sdr.jpeg', 'gainmap.jpeg', 'metadata.json'])
817
- * // `result` can be used to populate a Texture
818
- *
819
- * const scene = new Scene()
820
- * const mesh = new Mesh(
821
- * new PlaneGeometry(),
822
- * new MeshBasicMaterial({ map: result.renderTarget.texture })
823
- * )
824
- * scene.add(mesh)
825
- * renderer.render(scene, new PerspectiveCamera())
826
- *
827
- * // `result.renderTarget.texture` must be
828
- * // converted to `DataTexture` in order
829
- * // to use it as Equirectangular scene background
830
- * // if needed
831
- *
832
- * scene.background = result.toDataTexture()
833
- * scene.background.mapping = EquirectangularReflectionMapping
834
- * scene.background.minFilter = LinearFilter
835
- *
836
- *
837
- */
838
- class GainMapLoader extends LoaderBase {
839
- /**
840
- * Loads a gainmap using separate data
841
- * * sdr image
842
- * * gain map image
843
- * * metadata json
844
- *
845
- * useful for webp gain maps
846
- *
847
- * @param sdrUrl
848
- * @param gainMapUrl
849
- * @param metadataUrl
850
- * @param onLoad
851
- * @param onProgress
852
- * @param onError
853
- * @returns
854
- */
855
- load([sdrUrl, gainMapUrl, metadataUrl], onLoad, onProgress, onError) {
856
- const quadRenderer = this.prepareQuadRenderer();
857
- let sdr;
858
- let gainMap;
859
- let metadata;
860
- const loadCheck = async () => {
861
- if (sdr && gainMap && metadata) {
862
- await this.render(quadRenderer, gainMap, sdr, metadata);
863
- if (typeof onLoad === 'function')
864
- onLoad(quadRenderer);
865
- quadRenderer.dispose();
866
- }
867
- };
868
- const progressHandler = (e) => {
869
- };
870
- const sdrLoader = new FileLoader(this.manager);
871
- sdrLoader.setResponseType('arraybuffer');
872
- sdrLoader.setRequestHeader(this.requestHeader);
873
- sdrLoader.setPath(this.path);
874
- sdrLoader.setWithCredentials(this.withCredentials);
875
- sdrLoader.load(sdrUrl, async (buffer) => {
876
- if (typeof buffer === 'string')
877
- throw new Error('Invalid sdr buffer');
878
- sdr = buffer;
879
- loadCheck();
880
- }, progressHandler, onError);
881
- const gainMapLoader = new FileLoader(this.manager);
882
- gainMapLoader.setResponseType('arraybuffer');
883
- gainMapLoader.setRequestHeader(this.requestHeader);
884
- gainMapLoader.setPath(this.path);
885
- gainMapLoader.setWithCredentials(this.withCredentials);
886
- gainMapLoader.load(gainMapUrl, async (buffer) => {
887
- if (typeof buffer === 'string')
888
- throw new Error('Invalid gainmap buffer');
889
- gainMap = buffer;
890
- loadCheck();
891
- }, progressHandler, onError);
892
- const metadataLoader = new FileLoader(this.manager);
893
- // metadataLoader.setResponseType('json')
894
- metadataLoader.setRequestHeader(this.requestHeader);
895
- metadataLoader.setPath(this.path);
896
- metadataLoader.setWithCredentials(this.withCredentials);
897
- metadataLoader.load(metadataUrl, async (json) => {
898
- if (typeof json !== 'string')
899
- throw new Error('Invalid metadata string');
900
- metadata = JSON.parse(json);
901
- loadCheck();
902
- }, progressHandler, onError);
903
- return quadRenderer;
904
- }
905
- }
906
-
907
- export { GainMapEncoderMaterial, GainMapLoader, SDRMaterial, decode, encode, encodeAndCompress, findTextureMinMax, getDataTexture, getGainMap, getSDRRendition };
715
+ export { GainMapEncoderMaterial, SDRMaterial, compress, encode, encodeAndCompress, findTextureMinMax, getGainMap, getSDRRendition };