@monogrid/gainmap-js 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/CODE_OF_CONDUCT.md +128 -0
  3. package/CONTRIBUTING.md +130 -0
  4. package/LICENSE +21 -0
  5. package/README.md +149 -0
  6. package/dist/_commonjsHelpers-1789f0cf.js +12 -0
  7. package/dist/compress-a4b59cab.js +82 -0
  8. package/dist/decode.d.ts +37 -0
  9. package/dist/encode-utils/compress.d.ts +12 -0
  10. package/dist/encode-utils/find-texture-min-max.d.ts +15 -0
  11. package/dist/encode-utils/get-gainmap.d.ts +13 -0
  12. package/dist/encode-utils/get-sdr-rendition.d.ts +16 -0
  13. package/dist/encode.d.ts +117 -0
  14. package/dist/index.d.ts +11 -0
  15. package/dist/index.js +976 -0
  16. package/dist/index.umd.js +1069 -0
  17. package/dist/libultrahdr-esm.wasm +0 -0
  18. package/dist/libultrahdr.d.ts +129 -0
  19. package/dist/libultrahdr.js +6728 -0
  20. package/dist/libultrahdr.umd.js +6740 -0
  21. package/dist/materials/GainMapDecoderMaterial.d.ts +26 -0
  22. package/dist/materials/GainMapEncoderMaterial.d.ts +43 -0
  23. package/dist/materials/SDRMaterial.d.ts +35 -0
  24. package/dist/materials/index.d.ts +3 -0
  25. package/dist/types.d.ts +252 -0
  26. package/dist/utils/QuadRenderer.d.ts +73 -0
  27. package/dist/utils/get-data-texture.d.ts +14 -0
  28. package/dist/worker-interface.d.ts +26 -0
  29. package/dist/worker-interface.js +501 -0
  30. package/dist/worker-interface.umd.js +516 -0
  31. package/dist/worker-types.d.ts +24 -0
  32. package/dist/worker.d.ts +1 -0
  33. package/dist/worker.js +123 -0
  34. package/dist/worker.umd.js +207 -0
  35. package/examples/README.md +3 -0
  36. package/examples/compress.ts +43 -0
  37. package/examples/decode-from-jpeg.ts +40 -0
  38. package/examples/decode-from-separate-data.ts +41 -0
  39. package/examples/decode-to-datatexture.ts +65 -0
  40. package/examples/encode-and-compress.ts +29 -0
  41. package/examples/encode-jpeg-metadata.ts +57 -0
  42. package/examples/encode.ts +28 -0
  43. package/examples/globals.d.ts +6 -0
  44. package/examples/worker.ts +41 -0
  45. package/libultrahdr-wasm/LICENSE +202 -0
  46. package/libultrahdr-wasm/README.md +99 -0
  47. package/libultrahdr-wasm/build/libultrahdr-debug.js +7156 -0
  48. package/libultrahdr-wasm/build/libultrahdr-debug.wasm +0 -0
  49. package/libultrahdr-wasm/build/libultrahdr-esm.js +6633 -0
  50. package/libultrahdr-wasm/build/libultrahdr-esm.wasm +0 -0
  51. package/libultrahdr-wasm/build/libultrahdr.d.ts +30 -0
  52. package/libultrahdr-wasm/build/libultrahdr.js +6591 -0
  53. package/libultrahdr-wasm/build/libultrahdr.wasm +0 -0
  54. package/package.json +143 -0
  55. package/reports/eslint-examples.json +1 -0
  56. package/reports/eslint-src.json +1 -0
  57. package/reports/eslint-tests.json +1 -0
  58. package/reports/junit.xml +35 -0
  59. package/reports/typecheck-examples.log +0 -0
  60. package/reports/typecheck-tests.log +0 -0
  61. package/reports/typecheck.log +0 -0
@@ -0,0 +1,26 @@
1
+ import { ShaderMaterial, Texture } from 'three';
2
+ import { GainmapDecodingParameters, GainMapMetadata } from '../types';
3
+ /**
4
+ * A Material which is able to decode the Gainmap into a full HDR Representation
5
+ *
6
+ * @category Materials
7
+ * @group Materials
8
+ */
9
+ export declare class GainMapDecoderMaterial extends ShaderMaterial {
10
+ private _maxDisplayBoost;
11
+ private _hdrCapacityMin;
12
+ private _hdrCapacityMax;
13
+ /**
14
+ *
15
+ * @param params
16
+ */
17
+ constructor({ gamma, offsetHdr, offsetSdr, gainMapMin, gainMapMax, maxDisplayBoost, hdrCapacityMin, hdrCapacityMax, sdr, gainMap }: GainMapMetadata & GainmapDecodingParameters & {
18
+ sdr: Texture;
19
+ gainMap: Texture;
20
+ });
21
+ /**
22
+ * @see {@link GainmapDecodingParameters}
23
+ */
24
+ get maxDisplayBoost(): number;
25
+ set maxDisplayBoost(value: number);
26
+ }
@@ -0,0 +1,43 @@
1
+ import { ShaderMaterial, Texture } from 'three';
2
+ import { GainmapEncodingParameters } from '../types';
3
+ /**
4
+ * A Material which is able to encode a gainmap
5
+ *
6
+ * @category Materials
7
+ * @group Materials
8
+ */
9
+ export declare class GainMapEncoderMaterial extends ShaderMaterial {
10
+ private _minContentBoost;
11
+ private _maxContentBoost;
12
+ private _offsetSdr;
13
+ private _offsetHdr;
14
+ private _gamma;
15
+ /**
16
+ *
17
+ * @param params
18
+ */
19
+ constructor({ sdr, hdr, offsetSdr, offsetHdr, maxContentBoost, minContentBoost, gamma }: {
20
+ sdr: Texture;
21
+ hdr: Texture;
22
+ } & GainmapEncodingParameters);
23
+ get gamma(): [number, number, number];
24
+ set gamma(value: [number, number, number]);
25
+ get offsetHdr(): [number, number, number];
26
+ set offsetHdr(value: [number, number, number]);
27
+ get offsetSdr(): [number, number, number];
28
+ set offsetSdr(value: [number, number, number]);
29
+ /**
30
+ * Non logarithmic space
31
+ */
32
+ get minContentBoost(): number;
33
+ set minContentBoost(value: number);
34
+ /**
35
+ * Non logarithmic space
36
+ */
37
+ get maxContentBoost(): number;
38
+ set maxContentBoost(value: number);
39
+ get gainMapMin(): [number, number, number];
40
+ get gainMapMax(): [number, number, number];
41
+ get hdrCapacityMin(): number;
42
+ get hdrCapacityMax(): number;
43
+ }
@@ -0,0 +1,35 @@
1
+ import { ShaderMaterial, Texture, ToneMapping } from 'three';
2
+ /**
3
+ * A Material used to adjust the SDR representation of an HDR image
4
+ *
5
+ * @category Materials
6
+ * @group Materials
7
+ */
8
+ export declare class SDRMaterial extends ShaderMaterial {
9
+ private _brightness;
10
+ private _contrast;
11
+ private _saturation;
12
+ private _exposure;
13
+ private _toneMapping;
14
+ private _map;
15
+ /**
16
+ *
17
+ * @param params
18
+ */
19
+ constructor({ map, toneMapping }: {
20
+ map: Texture;
21
+ toneMapping?: ToneMapping;
22
+ });
23
+ get toneMapping(): ToneMapping;
24
+ set toneMapping(value: ToneMapping);
25
+ get brightness(): number;
26
+ set brightness(value: number);
27
+ get contrast(): number;
28
+ set contrast(value: number);
29
+ get saturation(): number;
30
+ set saturation(value: number);
31
+ get exposure(): number;
32
+ set exposure(value: number);
33
+ get map(): Texture;
34
+ set map(value: Texture);
35
+ }
@@ -0,0 +1,3 @@
1
+ export * from './GainMapDecoderMaterial';
2
+ export * from './GainMapEncoderMaterial';
3
+ export * from './SDRMaterial';
@@ -0,0 +1,252 @@
1
+ import { type DataTexture, Texture, ToneMapping, type WebGLRenderer } from 'three';
2
+ import { type EXR } from 'three/examples/jsm/loaders/EXRLoader';
3
+ import { type LogLuv } from 'three/examples/jsm/loaders/LogLuvLoader';
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), 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).
22
+ */
23
+ gamma: [number, number, number];
24
+ /**
25
+ * This is log2 of the minimum display boost value for which the map is applied at all.
26
+ *
27
+ * @remarks
28
+ * * This value also affects how much to apply the gain map based on the display boost.
29
+ * * Must be 0.0 or greater.
30
+ */
31
+ hdrCapacityMin: number;
32
+ /**
33
+ * Stores the value of hdr_capacity_max. This is log2 of the maximum display boost value for which the map is applied completely.
34
+ *
35
+ * @remarks
36
+ * * This value also affects how much to apply the gain map based on the display boost.
37
+ * * Must be greater than hdrCapacityMin.
38
+ * * Required.
39
+ */
40
+ hdrCapacityMax: number;
41
+ /**
42
+ * This is the offset to apply to the SDR pixel values during gain map generation and application
43
+ * @defaultValue [1/64, 1/64, 1/64]
44
+ */
45
+ offsetSdr: [number, number, number];
46
+ /**
47
+ * This is the offset to apply to the HDR pixel values during gain map generation and application.
48
+ * @defaultValue [1/64, 1/64, 1/64]
49
+ */
50
+ offsetHdr: [number, number, number];
51
+ /**
52
+ * This is log2 of min content boost, which is the minimum allowed ratio of
53
+ * the linear luminance for the target HDR rendition relative to
54
+ * (divided by) that of the SDR image, at a given pixel.
55
+ */
56
+ gainMapMin: [number, number, number];
57
+ /**
58
+ * This is log2 of max content boost, which is the maximum 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
+ gainMapMax: [number, number, number];
63
+ };
64
+ /**
65
+ * Parameters used by content Creators in order to create a GainMap
66
+ * @category Gainmap Specifications
67
+ * @group Gainmap Specifications
68
+ */
69
+ export type GainmapEncodingParameters = {
70
+ /**
71
+ * This is the offset to apply to the HDR pixel values during gain map generation and application.
72
+ * @defaultValue [1/64, 1/64, 1/64]
73
+ */
74
+ offsetHdr?: [number, number, number];
75
+ /**
76
+ * This is the offset to apply to the SDR pixel values during gain map generation and application
77
+ * @defaultValue [1/64, 1/64, 1/64]
78
+ */
79
+ offsetSdr?: [number, number, number];
80
+ /**
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.
82
+ * @defaultValue 1
83
+ * @remarks
84
+ * * 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
+ * * In practice, this value is typically equal to or just less than 1.0.
86
+ * * Always less than or equal to Max content boost.
87
+ */
88
+ minContentBoost?: number;
89
+ /**
90
+ * 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
+ *
92
+ * @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.
94
+ * * In practice, this value is typically greater than 1.0.
95
+ * * Always greater than or equal to Min content boost.
96
+ */
97
+ maxContentBoost: number;
98
+ /**
99
+ * This is the gamma to apply to the stored map values.
100
+ *
101
+ * @defaultValue [1, 1, 1]
102
+ * @remarks
103
+ * * Typically you can use a gamma of 1.0.
104
+ * * 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).
106
+ */
107
+ gamma?: [number, number, number];
108
+ };
109
+ /**
110
+ * Parameters for decoding a Gainmap
111
+ *
112
+ * @category Gainmap Specifications
113
+ * @group Gainmap Specifications
114
+ */
115
+ export type GainmapDecodingParameters = {
116
+ /**
117
+ * The maximum available boost supported by a display, at a given point in time.
118
+ *
119
+ * @remarks
120
+ * This value can change over time based on device settings and other factors,
121
+ * such as ambient light conditions, or how many bright pixels are on the screen.
122
+ */
123
+ maxDisplayBoost: number;
124
+ };
125
+ /**
126
+ * Paramaters used to Encode a GainMap
127
+ *
128
+ * @category Encoding Parameters
129
+ * @group Encoding Parameters
130
+ */
131
+ export type EncodingParametersBase = GainmapEncodingParameters & {
132
+ /**
133
+ * Input image for encoding, must be an HDR image
134
+ */
135
+ image: EXR | RGBE | LogLuv | DataTexture;
136
+ /**
137
+ * Optional WebGLRenderer
138
+ * @remarks
139
+ * will be created and destroyed on demand if not provided.
140
+ */
141
+ renderer?: WebGLRenderer;
142
+ /**
143
+ * Optional tonemapping to apply to the SDR Rendition
144
+ * @defaultValue `ACESFilmicToneMapping`
145
+ */
146
+ toneMapping?: ToneMapping;
147
+ };
148
+ /**
149
+ * This library can provide gainmap compressed in these mimeTypes
150
+ *
151
+ * @category Compression
152
+ * @group Compression
153
+ */
154
+ export type CompressionMimeType = 'image/png' | 'image/jpeg' | 'image/webp';
155
+ /**
156
+ * Accepted HDR image buffers, definitions coming from the THREE.js Library types
157
+ *
158
+ * @category General
159
+ * @group General
160
+ */
161
+ export type HDRRawImageBuffer = EXR['data'] | RGBE['data'] | LogLuv['data'];
162
+ /**
163
+ * Raw HDR image data
164
+ *
165
+ * @category General
166
+ * @group General
167
+ */
168
+ export type HDRRawImage = {
169
+ data: HDRRawImageBuffer;
170
+ width: number;
171
+ height: number;
172
+ };
173
+ /**
174
+ * Options for compressing a RAW RGBA image into the specified mimeType
175
+ *
176
+ * @category Compression
177
+ * @group Compression
178
+ */
179
+ export type CompressOptions = {
180
+ /**
181
+ * The mimeType of the output
182
+ */
183
+ mimeType: CompressionMimeType;
184
+ /**
185
+ * Encoding quality [0-1]
186
+ */
187
+ quality?: number;
188
+ /**
189
+ * FlipY of the encoding process
190
+ */
191
+ flipY?: boolean;
192
+ };
193
+ /**
194
+ * Data structure representing a compressed image with a mimeType
195
+ *
196
+ * @category Compression
197
+ * @group Compression
198
+ */
199
+ export type CompressedImage = {
200
+ data: Uint8Array;
201
+ mimeType: CompressionMimeType;
202
+ width: number;
203
+ height: number;
204
+ };
205
+ /**
206
+ * @category Compression
207
+ * @group Compression
208
+ */
209
+ export type CompressParameters = CompressOptions & ({
210
+ /**
211
+ * RAW RGBA Image Data
212
+ */
213
+ source: ImageData;
214
+ } | {
215
+ /**
216
+ * Encoded Image Data with a mimeType
217
+ */
218
+ source: Uint8Array | Uint8ClampedArray;
219
+ /**
220
+ * mimeType of the encoded input
221
+ */
222
+ sourceMimeType: string;
223
+ });
224
+ /**
225
+ * Additional parameters to encode a GainMap compressed with a mimeType
226
+ * @category Encoding Parameters
227
+ * @group Encoding Parameters
228
+ */
229
+ export type EncodingParametersWithCompression = EncodingParametersBase & CompressOptions & {
230
+ /**
231
+ * Encodes the Gainmap using a Web Worker
232
+ */
233
+ withWorker?: WorkerInterfaceImplementation;
234
+ };
235
+ /**
236
+ * @category Decoding
237
+ * @group Decoding
238
+ */
239
+ export type DecodeParameters = {
240
+ /**
241
+ * An Texture containing the SDR Rendition
242
+ */
243
+ sdr: Texture;
244
+ /**
245
+ * An Texture containing the GainMap recovery image
246
+ */
247
+ gainMap: Texture;
248
+ /**
249
+ * WebGLRenderer used to decode the GainMap
250
+ */
251
+ renderer?: WebGLRenderer;
252
+ } & GainmapDecodingParameters & GainMapMetadata;
@@ -0,0 +1,73 @@
1
+ import { ByteType, ColorSpace, FloatType, HalfFloatType, IntType, Material, ShortType, TextureDataType, UnsignedByteType, UnsignedIntType, WebGLRenderer, WebGLRenderTarget } from 'three';
2
+ /**
3
+ * @category General
4
+ * @group General
5
+ */
6
+ 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
+ /**
8
+ * Utility structure used for rendering a texture with a material
9
+ *
10
+ * @category General
11
+ * @group General
12
+ */
13
+ export declare class QuadRenderer<TType extends TextureDataType, TMaterial extends Material> {
14
+ private _renderer;
15
+ private _rendererIsDisposable;
16
+ private _material;
17
+ private _scene;
18
+ private _camera;
19
+ private _quad;
20
+ private _renderTarget;
21
+ private _width;
22
+ private _height;
23
+ private _type;
24
+ /**
25
+ *
26
+ * @param sourceTexture
27
+ * @param renderer
28
+ */
29
+ constructor(width: number, height: number, type: TType, colorSpace: ColorSpace, material: TMaterial, renderer?: WebGLRenderer);
30
+ /**
31
+ * Instantiates a temporary renderer
32
+ *
33
+ * @returns
34
+ */
35
+ static instantiateRenderer(): WebGLRenderer;
36
+ /**
37
+ * Renders the input texture using the specified material
38
+ */
39
+ render: () => void;
40
+ /**
41
+ * Obtains a Buffer containing the rendered texture.
42
+ *
43
+ * @returns
44
+ */
45
+ toArray(): TextureDataTypeToBufferType<TType>;
46
+ /**
47
+ * If using a disposable renderer, it will dispose it.
48
+ */
49
+ dispose(): void;
50
+ /**
51
+ * Width of the texture
52
+ */
53
+ get width(): number;
54
+ set width(value: number);
55
+ /**
56
+ * Height of the texture
57
+ */
58
+ get height(): number;
59
+ set height(value: number);
60
+ /**
61
+ * The renderer used
62
+ */
63
+ get renderer(): WebGLRenderer;
64
+ /**
65
+ * The `WebGLRenderTarget` used.
66
+ */
67
+ get renderTarget(): WebGLRenderTarget;
68
+ set renderTarget(value: WebGLRenderTarget);
69
+ /**
70
+ * The `Material` used.
71
+ */
72
+ get material(): TMaterial;
73
+ }
@@ -0,0 +1,14 @@
1
+ import { DataTexture } from 'three';
2
+ import { EXR } from 'three/examples/jsm/loaders/EXRLoader';
3
+ import { LogLuv } from 'three/examples/jsm/loaders/LogLuvLoader';
4
+ import { RGBE } from 'three/examples/jsm/loaders/RGBELoader';
5
+ /**
6
+ * Utility function to obtain a `DataTexture` from various input formats
7
+ *
8
+ * @category General
9
+ * @group General
10
+ *
11
+ * @param image
12
+ * @returns
13
+ */
14
+ export declare const getDataTexture: (image: EXR | RGBE | LogLuv | DataTexture) => DataTexture;
@@ -0,0 +1,26 @@
1
+ import { type PromiseWorkerType, type WorkerInterfaceImplementation } from './worker-types';
2
+ export * from './worker-types';
3
+ /**
4
+ * Wraps a Regular worker into a `PromiseWorker`
5
+ *
6
+ * @param worker
7
+ * @returns
8
+ */
9
+ export declare const getPromiseWorker: (worker: Worker) => PromiseWorkerType;
10
+ /**
11
+ * Returns an interface where methods of the worker can be called by the host site
12
+ *
13
+ * @example
14
+ * // this assumes a vite-like bundler understands the `?worker` import
15
+ * import GainMapWorker from '@monogrid/gainmap-js/worker?worker'
16
+ * import { getPromiseWorker, getWorkerInterface } from '@monogrid/gainmap-js/worker-interface'
17
+ *
18
+ * // turn our Worker into a PromiseWorker
19
+ * const promiseWorker = getPromiseWorker(new GainMapWorker())
20
+ * // get the interface
21
+ * const workerInterface = getWorkerInterface(promiseWorker)
22
+ *
23
+ * @param worker
24
+ * @returns
25
+ */
26
+ export declare const getWorkerInterface: (worker: PromiseWorkerType) => WorkerInterfaceImplementation;