@monogrid/gainmap-js 1.0.2 → 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.
Files changed (54) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +103 -19
  3. package/dist/LoaderBase-eee19701.js +382 -0
  4. package/dist/_commonjsHelpers-1789f0cf.js +1 -1
  5. package/dist/compress-a4b59cab.js +1 -1
  6. package/dist/decode.d.ts +25 -6
  7. package/dist/encode-utils/get-sdr-rendition.d.ts +2 -2
  8. package/dist/encode.d.ts +3 -3
  9. package/dist/index.d.ts +1 -1
  10. package/dist/index.js +189 -258
  11. package/dist/index.umd.js +331 -27
  12. package/dist/libultrahdr/decode-jpeg-metadata.d.ts +31 -0
  13. package/dist/libultrahdr/encode-jpeg-metadata.d.ts +83 -0
  14. package/dist/libultrahdr/library.d.ts +9 -0
  15. package/dist/libultrahdr-esm.wasm +0 -0
  16. package/dist/libultrahdr.d.ts +4 -128
  17. package/dist/libultrahdr.js +322 -278
  18. package/dist/libultrahdr.umd.js +687 -271
  19. package/dist/loaders/GainMapLoader.d.ts +68 -0
  20. package/dist/loaders/JPEGRLoader.d.ts +60 -0
  21. package/dist/loaders/LoaderBase.d.ts +27 -0
  22. package/dist/materials/GainMapDecoderMaterial.d.ts +44 -1
  23. package/dist/materials/GainMapEncoderMaterial.d.ts +29 -2
  24. package/dist/types.d.ts +26 -6
  25. package/dist/utils/QuadRenderer.d.ts +8 -1
  26. package/dist/worker-interface.js +1 -1
  27. package/dist/worker-interface.umd.js +1 -1
  28. package/dist/worker-types.d.ts +1 -1
  29. package/dist/worker.js +1 -1
  30. package/dist/worker.umd.js +1 -1
  31. package/libultrahdr-wasm/build/libultrahdr-debug.js +156 -182
  32. package/libultrahdr-wasm/build/libultrahdr-debug.wasm +0 -0
  33. package/libultrahdr-wasm/build/libultrahdr-esm.js +153 -182
  34. package/libultrahdr-wasm/build/libultrahdr-esm.wasm +0 -0
  35. package/libultrahdr-wasm/build/libultrahdr.js +151 -180
  36. package/libultrahdr-wasm/build/libultrahdr.wasm +0 -0
  37. package/package.json +1 -1
  38. package/examples/README.md +0 -3
  39. package/examples/compress.ts +0 -43
  40. package/examples/decode-from-jpeg.ts +0 -40
  41. package/examples/decode-from-separate-data.ts +0 -41
  42. package/examples/decode-to-datatexture.ts +0 -65
  43. package/examples/encode-and-compress.ts +0 -29
  44. package/examples/encode-jpeg-metadata.ts +0 -57
  45. package/examples/encode.ts +0 -28
  46. package/examples/globals.d.ts +0 -6
  47. package/examples/worker.ts +0 -41
  48. package/reports/eslint-examples.json +0 -1
  49. package/reports/eslint-src.json +0 -1
  50. package/reports/eslint-tests.json +0 -1
  51. package/reports/junit.xml +0 -35
  52. package/reports/typecheck-examples.log +0 -0
  53. package/reports/typecheck-tests.log +0 -0
  54. package/reports/typecheck.log +0 -0
@@ -0,0 +1,68 @@
1
+ import { HalfFloatType } from 'three';
2
+ import { GainMapDecoderMaterial } from '../materials/GainMapDecoderMaterial';
3
+ import { QuadRenderer } from '../utils/QuadRenderer';
4
+ import { LoaderBase } from './LoaderBase';
5
+ /**
6
+ * A Three.js Loader for the gain map format.
7
+ *
8
+ * @category Loaders
9
+ * @group Loaders
10
+ *
11
+ * @example
12
+ * import { GainMapLoader } from '@monogrid/gainmap-js'
13
+ * import {
14
+ * EquirectangularReflectionMapping,
15
+ * LinearFilter,
16
+ * Mesh,
17
+ * MeshBasicMaterial,
18
+ * PerspectiveCamera,
19
+ * PlaneGeometry,
20
+ * Scene,
21
+ * WebGLRenderer
22
+ * } from 'three'
23
+ *
24
+ * const renderer = new WebGLRenderer()
25
+ *
26
+ * const loader = new GainMapLoader(renderer)
27
+ *
28
+ * const result = loader.load(['sdr.jpeg', 'gainmap.jpeg', 'metadata.json'])
29
+ * // `result` can be used to populate a Texture
30
+ *
31
+ * const scene = new Scene()
32
+ * const mesh = new Mesh(
33
+ * new PlaneGeometry(),
34
+ * new MeshBasicMaterial({ map: result.renderTarget.texture })
35
+ * )
36
+ * scene.add(mesh)
37
+ * renderer.render(scene, new PerspectiveCamera())
38
+ *
39
+ * // `result.renderTarget.texture` must be
40
+ * // converted to `DataTexture` in order
41
+ * // to use it as Equirectangular scene background
42
+ * // if needed
43
+ *
44
+ * scene.background = result.toDataTexture()
45
+ * scene.background.mapping = EquirectangularReflectionMapping
46
+ * scene.background.minFilter = LinearFilter
47
+ *
48
+ *
49
+ */
50
+ export declare class GainMapLoader extends LoaderBase<[string, string, string]> {
51
+ /**
52
+ * Loads a gainmap using separate data
53
+ * * sdr image
54
+ * * gain map image
55
+ * * metadata json
56
+ *
57
+ * useful for webp gain maps
58
+ *
59
+ * @param sdrUrl
60
+ * @param gainMapUrl
61
+ * @param metadataUrl
62
+ * @param onLoad
63
+ * @param onProgress
64
+ * @param onError
65
+ * @returns
66
+ */
67
+ 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>;
68
+ }
@@ -0,0 +1,60 @@
1
+ import { HalfFloatType } from 'three';
2
+ import { GainMapDecoderMaterial } from '../materials/GainMapDecoderMaterial';
3
+ import { QuadRenderer } from '../utils/QuadRenderer';
4
+ import { LoaderBase } from './LoaderBase';
5
+ /**
6
+ * A Three.js Loader for a JPEG with embedded gainmap metadata.
7
+ *
8
+ * @category Loaders
9
+ * @group Loaders
10
+ *
11
+ * @example
12
+ * import { JPEGRLoader } from '@monogrid/gainmap-js/libultrahdr'
13
+ * import {
14
+ * EquirectangularReflectionMapping,
15
+ * LinearFilter,
16
+ * Mesh,
17
+ * MeshBasicMaterial,
18
+ * PerspectiveCamera,
19
+ * PlaneGeometry,
20
+ * Scene,
21
+ * WebGLRenderer
22
+ * } from 'three'
23
+ *
24
+ * const renderer = new WebGLRenderer()
25
+ *
26
+ * const loader = new JPEGRLoader(renderer)
27
+ *
28
+ * const result = loader.load('gainmap.jpeg')
29
+ * // `result` can be used to populate a Texture
30
+ *
31
+ * const scene = new Scene()
32
+ * const mesh = new Mesh(
33
+ * new PlaneGeometry(),
34
+ * new MeshBasicMaterial({ map: result.renderTarget.texture })
35
+ * )
36
+ * scene.add(mesh)
37
+ * renderer.render(scene, new PerspectiveCamera())
38
+ *
39
+ * // `result.renderTarget.texture` must be
40
+ * // converted to `DataTexture` in order
41
+ * // to use it as Equirectangular scene background
42
+ * // if needed
43
+ *
44
+ * scene.background = result.toDataTexture()
45
+ * scene.background.mapping = EquirectangularReflectionMapping
46
+ * scene.background.minFilter = LinearFilter
47
+
48
+ *
49
+ */
50
+ export declare class JPEGRLoader extends LoaderBase<string> {
51
+ /**
52
+ *
53
+ * @param url
54
+ * @param onLoad
55
+ * @param onProgress
56
+ * @param onError
57
+ * @returns
58
+ */
59
+ load(url: string, onLoad?: (data: QuadRenderer<typeof HalfFloatType, GainMapDecoderMaterial>) => void, onProgress?: (event: ProgressEvent) => void, onError?: (err: unknown) => void): QuadRenderer<typeof HalfFloatType, GainMapDecoderMaterial>;
60
+ }
@@ -0,0 +1,27 @@
1
+ import { HalfFloatType, Loader, LoadingManager, WebGLRenderer } from 'three';
2
+ import { GainMapDecoderMaterial } from '../materials/GainMapDecoderMaterial';
3
+ import { GainMapMetadata } from '../types';
4
+ import { QuadRenderer } from '../utils/QuadRenderer';
5
+ export declare class LoaderBase<TUrl = string> extends Loader<QuadRenderer<typeof HalfFloatType, GainMapDecoderMaterial>, TUrl> {
6
+ private renderer;
7
+ /**
8
+ *
9
+ * @param renderer
10
+ * @param manager
11
+ */
12
+ constructor(renderer: WebGLRenderer, manager?: LoadingManager);
13
+ /**
14
+ * @private
15
+ * @returns
16
+ */
17
+ protected prepareQuadRenderer(): QuadRenderer<1016, GainMapDecoderMaterial>;
18
+ /**
19
+ *
20
+ * @private
21
+ * @param quadRenderer
22
+ * @param gainMapBuffer
23
+ * @param sdrBuffer
24
+ * @param metadata
25
+ */
26
+ protected render(quadRenderer: QuadRenderer<typeof HalfFloatType, GainMapDecoderMaterial>, gainMapBuffer: ArrayBuffer | string, sdrBuffer: ArrayBuffer | string, metadata: GainMapMetadata): Promise<void>;
27
+ }
@@ -18,9 +18,52 @@ export declare class GainMapDecoderMaterial extends ShaderMaterial {
18
18
  sdr: Texture;
19
19
  gainMap: Texture;
20
20
  });
21
+ get sdr(): Texture;
22
+ set sdr(value: Texture);
23
+ get gainMap(): Texture;
24
+ set gainMap(value: Texture);
21
25
  /**
22
- * @see {@link GainmapDecodingParameters}
26
+ * @see {@link GainMapMetadata.offsetHdr}
27
+ */
28
+ get offsetHdr(): [number, number, number];
29
+ set offsetHdr(value: [number, number, number]);
30
+ /**
31
+ * @see {@link GainMapMetadata.offsetSdr}
32
+ */
33
+ get offsetSdr(): [number, number, number];
34
+ set offsetSdr(value: [number, number, number]);
35
+ /**
36
+ * @see {@link GainMapMetadata.gainMapMin}
37
+ */
38
+ get gainMapMin(): [number, number, number];
39
+ set gainMapMin(value: [number, number, number]);
40
+ /**
41
+ * @see {@link GainMapMetadata.gainMapMax}
42
+ */
43
+ get gainMapMax(): [number, number, number];
44
+ set gainMapMax(value: [number, number, number]);
45
+ /**
46
+ * @see {@link GainmapEncodingParameters.gamma}
47
+ */
48
+ get gamma(): [number, number, number];
49
+ set gamma(value: [number, number, number]);
50
+ /**
51
+ * @see {@link GainMapMetadata.hdrCapacityMin}
52
+ * @remarks Logarithmic space
53
+ */
54
+ get hdrCapacityMin(): number;
55
+ set hdrCapacityMin(value: number);
56
+ /**
57
+ * @see {@link GainMapMetadata.hdrCapacityMin}
58
+ * @remarks Logarithmic space
59
+ */
60
+ get hdrCapacityMax(): number;
61
+ set hdrCapacityMax(value: number);
62
+ /**
63
+ * @see {@link GainmapDecodingParameters.maxDisplayBoost}
64
+ * @remarks Non Logarithmic space
23
65
  */
24
66
  get maxDisplayBoost(): number;
25
67
  set maxDisplayBoost(value: number);
68
+ private calculateWeight;
26
69
  }
@@ -20,24 +20,51 @@ export declare class GainMapEncoderMaterial extends ShaderMaterial {
20
20
  sdr: Texture;
21
21
  hdr: Texture;
22
22
  } & GainmapEncodingParameters);
23
+ /**
24
+ * @see {@link GainmapEncodingParameters.gamma}
25
+ */
23
26
  get gamma(): [number, number, number];
24
27
  set gamma(value: [number, number, number]);
28
+ /**
29
+ * @see {@link GainmapEncodingParameters.offsetHdr}
30
+ */
25
31
  get offsetHdr(): [number, number, number];
26
32
  set offsetHdr(value: [number, number, number]);
33
+ /**
34
+ * @see {@link GainmapEncodingParameters.offsetSdr}
35
+ */
27
36
  get offsetSdr(): [number, number, number];
28
37
  set offsetSdr(value: [number, number, number]);
29
38
  /**
30
- * Non logarithmic space
39
+ * @see {@link GainmapEncodingParameters.minContentBoost}
40
+ * @remarks Non logarithmic space
31
41
  */
32
42
  get minContentBoost(): number;
33
43
  set minContentBoost(value: number);
34
44
  /**
35
- * Non logarithmic space
45
+ * @see {@link GainmapEncodingParameters.maxContentBoost}
46
+ * @remarks Non logarithmic space
36
47
  */
37
48
  get maxContentBoost(): number;
38
49
  set maxContentBoost(value: number);
50
+ /**
51
+ * @see {@link GainMapMetadata.gainMapMin}
52
+ * @remarks Logarithmic space
53
+ */
39
54
  get gainMapMin(): [number, number, number];
55
+ /**
56
+ * @see {@link GainMapMetadata.gainMapMax}
57
+ * @remarks Logarithmic space
58
+ */
40
59
  get gainMapMax(): [number, number, number];
60
+ /**
61
+ * @see {@link GainMapMetadata.hdrCapacityMin}
62
+ * @remarks Logarithmic space
63
+ */
41
64
  get hdrCapacityMin(): number;
65
+ /**
66
+ * @see {@link GainMapMetadata.hdrCapacityMax}
67
+ * @remarks Logarithmic space
68
+ */
42
69
  get hdrCapacityMax(): number;
43
70
  }
package/dist/types.d.ts CHANGED
@@ -18,7 +18,9 @@ export type GainMapMetadata = {
18
18
  * * Typically you can use a gamma of 1.0.
19
19
  * * You can use a different value if your gain map has a very uneven distribution of log_recovery(x, y) values.
20
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), 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). 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).
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).
22
24
  */
23
25
  gamma: [number, number, number];
24
26
  /**
@@ -27,6 +29,8 @@ export type GainMapMetadata = {
27
29
  * @remarks
28
30
  * * This value also affects how much to apply the gain map based on the display boost.
29
31
  * * Must be 0.0 or greater.
32
+ *
33
+ * Logarithmic space
30
34
  */
31
35
  hdrCapacityMin: number;
32
36
  /**
@@ -36,6 +40,8 @@ export type GainMapMetadata = {
36
40
  * * This value also affects how much to apply the gain map based on the display boost.
37
41
  * * Must be greater than hdrCapacityMin.
38
42
  * * Required.
43
+ *
44
+ * Logarithmic space
39
45
  */
40
46
  hdrCapacityMax: number;
41
47
  /**
@@ -78,21 +84,29 @@ export type GainmapEncodingParameters = {
78
84
  */
79
85
  offsetSdr?: [number, number, number];
80
86
  /**
81
- * This value lets the content creator constrain how much darker an image can get, when shown on an HDR display, relative to the SDR rendition. This value is a constant for a particular image.
87
+ * This value lets the content creator constrain how much darker an image can get, when shown on an HDR display, relative to the SDR rendition.
88
+ * This value is a constant for a particular image.
82
89
  * @defaultValue 1
83
90
  * @remarks
84
91
  * * If, for example, the value is 0.5, then for any given pixel, the linear luminance of the displayed HDR rendition must be (at the least) 0.5x the linear luminance of the SDR rendition.
85
92
  * * In practice, this value is typically equal to or just less than 1.0.
86
93
  * * Always less than or equal to Max content boost.
94
+ *
95
+ * Non Logarithmic space
87
96
  */
88
97
  minContentBoost?: number;
89
98
  /**
90
99
  * This value lets the content creator constrain how much brighter an image can get, when shown on an HDR display, relative to the SDR rendition.
91
100
  *
92
101
  * @remarks
93
- * * This value is a constant for a particular image. For example, if the value is four, then for any given pixel, the linear luminance of the displayed HDR rendition must be, at the most, 4x the linear luminance of the SDR rendition. In practice, this means that the brighter parts of the scene can be shown up to 4x brighter.
102
+ * * This value is a constant for a particular image.
103
+ * For example, if the value is four, then for any given pixel, the linear luminance of the
104
+ * displayed HDR rendition must be, at the most, 4x the linear luminance of the SDR rendition.
105
+ * In practice, this means that the brighter parts of the scene can be shown up to 4x brighter.
94
106
  * * In practice, this value is typically greater than 1.0.
95
107
  * * Always greater than or equal to Min content boost.
108
+ *
109
+ * Non Logarithmic space
96
110
  */
97
111
  maxContentBoost: number;
98
112
  /**
@@ -102,7 +116,11 @@ export type GainmapEncodingParameters = {
102
116
  * @remarks
103
117
  * * Typically you can use a gamma of 1.0.
104
118
  * * You can use a different value if your gain map has a very uneven distribution of log_recovery(x, y) values.
105
- * 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), 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). 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).
119
+ * For example, this might apply if a gain map has a lot of detail just above SDR range
120
+ * (represented as small log_recovery(x, y) values), and a very large map_max_log2 for the top
121
+ * end of the HDR rendition's desired brightness (represented by large log_recovery(x, y) values).
122
+ * In this case, you can use a map_gamma higher than 1.0 so that recovery(x, y)
123
+ * can precisely encode the detail in both the low end and high end of log_recovery(x, y).
106
124
  */
107
125
  gamma?: [number, number, number];
108
126
  };
@@ -119,11 +137,13 @@ export type GainmapDecodingParameters = {
119
137
  * @remarks
120
138
  * This value can change over time based on device settings and other factors,
121
139
  * such as ambient light conditions, or how many bright pixels are on the screen.
140
+ *
141
+ * Non Logarithmic space
122
142
  */
123
143
  maxDisplayBoost: number;
124
144
  };
125
145
  /**
126
- * Paramaters used to Encode a GainMap
146
+ * Parameters used to Encode a GainMap
127
147
  *
128
148
  * @category Encoding Parameters
129
149
  * @group Encoding Parameters
@@ -140,7 +160,7 @@ export type EncodingParametersBase = GainmapEncodingParameters & {
140
160
  */
141
161
  renderer?: WebGLRenderer;
142
162
  /**
143
- * Optional tonemapping to apply to the SDR Rendition
163
+ * Optional tone mapping to apply to the SDR Rendition
144
164
  * @defaultValue `ACESFilmicToneMapping`
145
165
  */
146
166
  toneMapping?: ToneMapping;
@@ -1,4 +1,4 @@
1
- import { ByteType, ColorSpace, FloatType, HalfFloatType, IntType, Material, ShortType, TextureDataType, UnsignedByteType, UnsignedIntType, WebGLRenderer, WebGLRenderTarget } from 'three';
1
+ import { ByteType, ColorSpace, DataTexture, FloatType, HalfFloatType, IntType, Material, ShortType, TextureDataType, UnsignedByteType, UnsignedIntType, WebGLRenderer, WebGLRenderTarget } from 'three';
2
2
  /**
3
3
  * @category General
4
4
  * @group General
@@ -21,6 +21,7 @@ export declare class QuadRenderer<TType extends TextureDataType, TMaterial exten
21
21
  private _width;
22
22
  private _height;
23
23
  private _type;
24
+ private _colorSpace;
24
25
  /**
25
26
  *
26
27
  * @param sourceTexture
@@ -43,6 +44,7 @@ export declare class QuadRenderer<TType extends TextureDataType, TMaterial exten
43
44
  * @returns
44
45
  */
45
46
  toArray(): TextureDataTypeToBufferType<TType>;
47
+ toDataTexture(): DataTexture;
46
48
  /**
47
49
  * If using a disposable renderer, it will dispose it.
48
50
  */
@@ -70,4 +72,9 @@ export declare class QuadRenderer<TType extends TextureDataType, TMaterial exten
70
72
  * The `Material` used.
71
73
  */
72
74
  get material(): TMaterial;
75
+ /**
76
+ *
77
+ */
78
+ get type(): TType;
79
+ get colorSpace(): ColorSpace;
73
80
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v1.0.1
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.1
2
+ * @monogrid/gainmap-js v1.1.0
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
@@ -18,7 +18,7 @@ export type WorkerInterfaceImplementation = {
18
18
  [k in keyof WorkerInterface]: (payload: WorkerInterface[k]['request']['payload']) => Promise<WorkerInterface[k]['result']>;
19
19
  };
20
20
  export type WorkerRequest = WorkerInterface[keyof WorkerInterface]['request'];
21
- export type WithTranferListFunction = <T>(payload: T, transferList: Transferable[]) => T;
21
+ export type WithTransferListFunction = <T>(payload: T, transferList: Transferable[]) => T;
22
22
  export type PromiseWorkerType = {
23
23
  postMessage: (message: any, transferables?: Transferable[]) => Promise<any>;
24
24
  };
package/dist/worker.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v1.0.1
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.1
2
+ * @monogrid/gainmap-js v1.1.0
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5