@monogrid/gainmap-js 1.1.0 → 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 (51) hide show
  1. package/CHANGELOG.md +22 -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/{utils → core}/QuadRenderer.d.ts +6 -0
  8. package/dist/core/types.d.ts +64 -0
  9. package/dist/decode/decode.d.ts +56 -0
  10. package/dist/decode/extract.d.ts +10 -0
  11. package/dist/decode/index.d.ts +8 -0
  12. package/dist/{loaders → decode/loaders}/GainMapLoader.d.ts +4 -4
  13. package/dist/{loaders → decode/loaders}/JPEGRLoader.d.ts +5 -5
  14. package/dist/{materials → decode/materials}/GainMapDecoderMaterial.d.ts +3 -2
  15. package/dist/decode/types.d.ts +38 -0
  16. package/dist/decode/utils/MPFExtractor.d.ts +22 -0
  17. package/dist/decode/utils/extract-metadata-from-jpeg.d.ts +7 -0
  18. package/dist/decode.d.ts +1 -56
  19. package/dist/decode.js +737 -0
  20. package/dist/decode.umd.js +917 -0
  21. package/dist/{encode-utils → encode}/compress.d.ts +1 -1
  22. package/dist/encode/encode-and-compress.d.ts +61 -0
  23. package/dist/encode/encode.d.ts +58 -0
  24. package/dist/{encode-utils → encode}/get-gainmap.d.ts +3 -3
  25. package/dist/{encode-utils → encode}/get-sdr-rendition.d.ts +4 -5
  26. package/dist/encode/index.d.ts +10 -0
  27. package/dist/encode/types.d.ts +172 -0
  28. package/dist/encode.d.ts +1 -117
  29. package/dist/{index.js → encode.js} +42 -230
  30. package/dist/encode.umd.js +972 -0
  31. package/dist/libultrahdr/decode-jpeg-metadata.d.ts +31 -0
  32. package/dist/libultrahdr/encode-jpeg-metadata.d.ts +84 -0
  33. package/dist/libultrahdr/library.d.ts +9 -0
  34. package/dist/libultrahdr.d.ts +3 -123
  35. package/dist/libultrahdr.js +92 -167
  36. package/dist/libultrahdr.umd.js +91 -530
  37. package/dist/worker-interface.js +2 -2
  38. package/dist/worker-interface.umd.js +1 -3
  39. package/dist/worker-types.d.ts +2 -2
  40. package/dist/worker.js +3 -3
  41. package/dist/worker.umd.js +1 -1
  42. package/package.json +36 -29
  43. package/dist/LoaderBase-aa4842c4.js +0 -373
  44. package/dist/index.d.ts +0 -11
  45. package/dist/index.umd.js +0 -1360
  46. package/dist/materials/index.d.ts +0 -3
  47. package/dist/types.d.ts +0 -262
  48. /package/dist/{utils → core}/get-data-texture.d.ts +0 -0
  49. /package/dist/{encode-utils → encode}/find-texture-min-max.d.ts +0 -0
  50. /package/dist/{materials → encode/materials}/GainMapEncoderMaterial.d.ts +0 -0
  51. /package/dist/{materials → encode/materials}/SDRMaterial.d.ts +0 -0
package/CHANGELOG.md CHANGED
@@ -1,3 +1,25 @@
1
+ # [2.0.0](https://github.com/MONOGRID/gainmap-js/compare/v1.1.1...v2.0.0) (2023-11-13)
2
+
3
+
4
+ ### Features
5
+
6
+ * removes libultrahdr wasm from the decoding part of the library, allows users to load JPEGR files using pure js ([#9](https://github.com/MONOGRID/gainmap-js/issues/9)) ([3ad16f9](https://github.com/MONOGRID/gainmap-js/commit/3ad16f97fec6040fdfdfb4cd5e71b1ac8e504e28))
7
+
8
+
9
+ ### BREAKING CHANGES
10
+
11
+ * The encoder portion of the library has been separated and moved to `@monogrid/gainmap-js/encode`, in order to save file size on user's bundles, all encoding functions must now be imported with that path.
12
+
13
+ `JPEGRLoader` has been moved from `@monogrid/gainmap-js/libultrahdr` to `@monogrid/gainmap-js` because it now uses a pure js approach
14
+
15
+ ## [1.1.1](https://github.com/MONOGRID/gainmap-js/compare/v1.1.0...v1.1.1) (2023-11-09)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * fixes Firefox Compatibility ([1cec657](https://github.com/MONOGRID/gainmap-js/commit/1cec65708127b6fd064277f4f923fc0f65610fa2))
21
+ * **libultrahdr:** fixes circular dependency between JPEGRLoader and libultrahdr ([f30f786](https://github.com/MONOGRID/gainmap-js/commit/f30f7865fb27a601635168b8a104a9935653e758))
22
+
1
23
  # [1.1.0](https://github.com/MONOGRID/gainmap-js/compare/v1.0.2...v1.1.0) (2023-11-06)
2
24
 
3
25
 
package/README.md CHANGED
@@ -1,13 +1,26 @@
1
1
  # gainmap-js
2
2
  A Javascript (TypeScript) Encoder/Decoder Implementation of Adobe's Gain Map Technology for storing HDR Images using an SDR Image + a "Gain map"
3
3
 
4
- > :warning: This library **is primarly intended** for encoding and decoding gain map images for the [three.js](https://github.com/mrdoob/three.js/) 3D Library
4
+ > :warning: This library **is primarily intended** for encoding and decoding gain map images for the [three.js](https://github.com/mrdoob/three.js/) 3D Library
5
5
  >
6
- > It can be used for general encode/decode of gain maps but it depends on the three.js library which, in itself, is quite heavy if you only use it to encode/decode gainmaps.
6
+ > It can be used for general encode/decode of gain maps but it depends on the three.js library which, in itself, is quite heavy if you only use it to encode/decode gain maps.
7
+
8
+ ## Live Demo
9
+
10
+ https://monogrid.github.io/gainmap-js/
11
+
12
+ Compares loading:
13
+ 1. a `JPEG` file with embedded gain map data
14
+ 2. a `webp` sdr file + a `webp` gain map + metadata JSON
15
+ 3. a comparable size `.hdr` file for comparison
16
+
17
+ ## [Free online encoder](https://gainmap-creator.mono-grid.com)
18
+
19
+ Use it to convert `.hdr` and `.exr` files into gain maps. It's free and the whole process happens in your browser.
7
20
 
8
21
  ## Installing
9
22
  ```bash
10
- $ npm install @monogrid/gainmap-js threejs
23
+ $ npm install @monogrid/gainmap-js three
11
24
  ```
12
25
 
13
26
  ## What is a Gain map?
@@ -24,6 +37,8 @@ $ npm install @monogrid/gainmap-js threejs
24
37
  > * The **gain map**. This is a secondary “image” embedded in the file. It is not a real image, but rather contains data to convert each pixel from the base image into the other (SDR or HDR) version of the image.
25
38
  >* Gain map **metadata**. This tells the browser how the gain map is encoded as well as critical information to optimize rendering on any display.
26
39
 
40
+ Please note that Google [is adopting the gain map technology in Android 14](https://support.google.com/photos/answer/14159275) but its naming of the technology refers to it as **Ultra HDR Image Format** and a JPEG file with embedded gain map is called `JPEGR` in their terminology.
41
+
27
42
  ## API
28
43
 
29
44
  Refer to the [WIKI](https://github.com/MONOGRID/gainmap-js/wiki) for detailed documentation about the API.
@@ -44,12 +59,11 @@ The advantage is to have a single file to load.
44
59
 
45
60
  The disadvantages are:
46
61
  * No WEBP compression
47
- * Uses the `@monogrid/gainmap-js/libultrahdr` package which is heavier and requires loading a `wasm` in order to extract the gainmap from the JPEG.
48
62
  * The JPEG cannot be manipulated in Photoshop, GIMP, or any other software that does not support the gain map technology (no photo editing software supports it at the time of writing 06-11-2023).
49
63
  * Photo sharing websites and/or services (i.e. sharing with Slack) will likely strip the Gain map metadata and the HDR information will be lost, leaving you with only the SDR Representation.
50
64
 
51
65
  ```ts
52
- import { JPEGRLoader } from '@monogrid/gainmap-js/libultrahdr'
66
+ import { JPEGRLoader } from '@monogrid/gainmap-js'
53
67
  import {
54
68
  EquirectangularReflectionMapping,
55
69
  LinearFilter,
@@ -78,7 +92,7 @@ renderer.render(scene, new PerspectiveCamera())
78
92
 
79
93
  // `result.renderTarget.texture` must be
80
94
  // converted to `DataTexture` in order
81
- // to use it as Equirectanmgular scene background
95
+ // to use it as Equirectangular scene background
82
96
  // if needed
83
97
 
84
98
  scene.background = result.toDataTexture()
@@ -95,7 +109,6 @@ Using separate files will get rid of the limitations of using a single JPEG file
95
109
  2. A Gainmap file
96
110
  3. A JSON containing the gainmap metadata used for decoding
97
111
 
98
- This solution will use the lighter `@monogrid/gainmap-js` package which will not load a `wasm` file and contains less code.
99
112
 
100
113
  ```ts
101
114
  import { GainMapLoader } from '@monogrid/gainmap-js'
@@ -127,7 +140,7 @@ renderer.render(scene, new PerspectiveCamera())
127
140
 
128
141
  // `result.renderTarget.texture` must be
129
142
  // converted to `DataTexture` in order
130
- // to use it as Equirectanmgular scene background
143
+ // to use it as Equirectangular scene background
131
144
  // if needed
132
145
 
133
146
  scene.background = result.toDataTexture()
@@ -0,0 +1,178 @@
1
+ /**
2
+ * @monogrid/gainmap-js v1.1.1
3
+ * With ❤️, by MONOGRID <hello@mono-grid.com>
4
+ */
5
+
6
+ import { HalfFloatType, FloatType, Scene, OrthographicCamera, Mesh, PlaneGeometry, WebGLRenderTarget, RGBAFormat, LinearFilter, LinearMipMapLinearFilter, RepeatWrapping, WebGLRenderer, IntType, ShortType, ByteType, UnsignedIntType, UnsignedByteType, DataTexture, UVMapping, NoColorSpace } from 'three';
7
+
8
+ /**
9
+ * Utility structure used for rendering a texture with a material
10
+ *
11
+ * @category General
12
+ * @group General
13
+ */
14
+ class QuadRenderer {
15
+ /**
16
+ *
17
+ * @param sourceTexture
18
+ * @param renderer
19
+ */
20
+ constructor(width, height, type, colorSpace, material, renderer) {
21
+ this._rendererIsDisposable = false;
22
+ /**
23
+ * Renders the input texture using the specified material
24
+ */
25
+ this.render = () => {
26
+ this._renderer.setRenderTarget(this._renderTarget);
27
+ try {
28
+ this._renderer.render(this._scene, this._camera);
29
+ }
30
+ catch (e) {
31
+ this._renderer.setRenderTarget(null);
32
+ throw e;
33
+ }
34
+ this._renderer.setRenderTarget(null);
35
+ };
36
+ this._width = width;
37
+ this._height = height;
38
+ this._type = type;
39
+ this._colorSpace = colorSpace;
40
+ if (type === HalfFloatType && navigator.userAgent.toLowerCase().includes('firefox')) {
41
+ this._type = FloatType;
42
+ }
43
+ this._material = material;
44
+ if (renderer) {
45
+ this._renderer = renderer;
46
+ }
47
+ else {
48
+ this._renderer = QuadRenderer.instantiateRenderer();
49
+ this._rendererIsDisposable = true;
50
+ }
51
+ this._scene = new Scene();
52
+ this._camera = new OrthographicCamera();
53
+ this._camera.position.set(0, 0, 10);
54
+ this._camera.left = -0.5;
55
+ this._camera.right = 0.5;
56
+ this._camera.top = 0.5;
57
+ this._camera.bottom = -0.5;
58
+ this._camera.updateProjectionMatrix();
59
+ this._quad = new Mesh(new PlaneGeometry(), this._material);
60
+ this._quad.geometry.computeBoundingBox();
61
+ this._scene.add(this._quad);
62
+ this._renderTarget = new WebGLRenderTarget(width, height, {
63
+ type: this._type,
64
+ colorSpace,
65
+ format: RGBAFormat,
66
+ magFilter: LinearFilter,
67
+ minFilter: LinearMipMapLinearFilter,
68
+ wrapS: RepeatWrapping,
69
+ wrapT: RepeatWrapping,
70
+ depthBuffer: false,
71
+ stencilBuffer: false,
72
+ generateMipmaps: true
73
+ });
74
+ }
75
+ /**
76
+ * Instantiates a temporary renderer
77
+ *
78
+ * @returns
79
+ */
80
+ static instantiateRenderer() {
81
+ const renderer = new WebGLRenderer();
82
+ renderer.setSize(128, 128);
83
+ // renderer.outputColorSpace = SRGBColorSpace
84
+ // renderer.toneMapping = LinearToneMapping
85
+ // renderer.debug.checkShaderErrors = false
86
+ // this._rendererIsDisposable = true
87
+ return renderer;
88
+ }
89
+ /**
90
+ * Obtains a Buffer containing the rendered texture.
91
+ *
92
+ * @returns
93
+ */
94
+ toArray() {
95
+ let out;
96
+ switch (this._type) {
97
+ case UnsignedByteType:
98
+ out = new Uint8ClampedArray(this._width * this._height * 4);
99
+ break;
100
+ case HalfFloatType:
101
+ out = new Uint16Array(this._width * this._height * 4);
102
+ break;
103
+ case UnsignedIntType:
104
+ out = new Uint32Array(this._width * this._height * 4);
105
+ break;
106
+ case ByteType:
107
+ out = new Int8Array(this._width * this._height * 4);
108
+ break;
109
+ case ShortType:
110
+ out = new Int16Array(this._width * this._height * 4);
111
+ break;
112
+ case IntType:
113
+ out = new Int32Array(this._width * this._height * 4);
114
+ break;
115
+ case FloatType:
116
+ out = new Float32Array(this._width * this._height * 4);
117
+ break;
118
+ default:
119
+ throw new Error('Unsupported data type');
120
+ }
121
+ this._renderer.readRenderTargetPixels(this._renderTarget, 0, 0, this._width, this._height, out);
122
+ return out;
123
+ }
124
+ toDataTexture() {
125
+ return new DataTexture(this.toArray(), this.width, this.height, RGBAFormat, this._type, UVMapping, RepeatWrapping, RepeatWrapping, LinearFilter, LinearMipMapLinearFilter, 1, NoColorSpace);
126
+ }
127
+ /**
128
+ * If using a disposable renderer, it will dispose it.
129
+ */
130
+ dispose() {
131
+ this._renderer.setRenderTarget(null);
132
+ if (this._rendererIsDisposable) {
133
+ this._renderer.dispose();
134
+ this._renderer.forceContextLoss();
135
+ }
136
+ }
137
+ /**
138
+ * Width of the texture
139
+ */
140
+ get width() { return this._width; }
141
+ set width(value) {
142
+ this._width = value;
143
+ this._renderTarget.setSize(this._width, this._height);
144
+ }
145
+ /**
146
+ * Height of the texture
147
+ */
148
+ get height() { return this._height; }
149
+ set height(value) {
150
+ this._height = value;
151
+ this._renderTarget.setSize(this._width, this._height);
152
+ }
153
+ /**
154
+ * The renderer used
155
+ */
156
+ get renderer() { return this._renderer; }
157
+ /**
158
+ * The `WebGLRenderTarget` used.
159
+ */
160
+ get renderTarget() { return this._renderTarget; }
161
+ set renderTarget(value) {
162
+ this._renderTarget = value;
163
+ this._width = value.width;
164
+ this._height = value.height;
165
+ // this._type = value.texture.type
166
+ }
167
+ /**
168
+ * The `Material` used.
169
+ */
170
+ get material() { return this._material; }
171
+ /**
172
+ *
173
+ */
174
+ get type() { return this._type; }
175
+ get colorSpace() { return this._colorSpace; }
176
+ }
177
+
178
+ export { QuadRenderer as Q };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v1.0.2
2
+ * @monogrid/gainmap-js v1.1.1
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.1
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
@@ -1,7 +1,7 @@
1
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';
2
+ import { type GainMapMetadata } from '../core/types';
3
+ import { GainMapDecoderMaterial } from '../decode/materials/GainMapDecoderMaterial';
4
+ import { QuadRenderer } from './QuadRenderer';
5
5
  export declare class LoaderBase<TUrl = string> extends Loader<QuadRenderer<typeof HalfFloatType, GainMapDecoderMaterial>, TUrl> {
6
6
  private renderer;
7
7
  /**
@@ -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
@@ -71,4 +72,9 @@ export declare class QuadRenderer<TType extends TextureDataType, TMaterial exten
71
72
  * The `Material` used.
72
73
  */
73
74
  get material(): TMaterial;
75
+ /**
76
+ *
77
+ */
78
+ get type(): TType;
79
+ get colorSpace(): ColorSpace;
74
80
  }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * This is the Metadata stored in an encoded Gainmap which is used
3
+ * to decode it and return an HDR image
4
+ *
5
+ * @category Gainmap Specifications
6
+ * @group Gainmap Specifications
7
+ */
8
+ export type GainMapMetadata = {
9
+ /**
10
+ * This is the gamma to apply to the stored map values.
11
+ * @defaultValue [1, 1, 1]
12
+ * @remarks
13
+ * * Typically you can use a gamma of 1.0.
14
+ * * You can use a different value if your gain map has a very uneven distribution of log_recovery(x, y) values.
15
+ *
16
+ * 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),
17
+ * 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).
18
+ * 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).
19
+ */
20
+ gamma: [number, number, number];
21
+ /**
22
+ * This is log2 of the minimum display boost value for which the map is applied at all.
23
+ *
24
+ * @remarks
25
+ * * This value also affects how much to apply the gain map based on the display boost.
26
+ * * Must be 0.0 or greater.
27
+ *
28
+ * Logarithmic space
29
+ */
30
+ hdrCapacityMin: number;
31
+ /**
32
+ * Stores the value of hdr_capacity_max. This is log2 of the maximum display boost value for which the map is applied completely.
33
+ *
34
+ * @remarks
35
+ * * This value also affects how much to apply the gain map based on the display boost.
36
+ * * Must be greater than hdrCapacityMin.
37
+ * * Required.
38
+ *
39
+ * Logarithmic space
40
+ */
41
+ hdrCapacityMax: number;
42
+ /**
43
+ * This is the offset to apply to the SDR pixel values during gain map generation and application
44
+ * @defaultValue [1/64, 1/64, 1/64]
45
+ */
46
+ offsetSdr: [number, number, number];
47
+ /**
48
+ * This is the offset to apply to the HDR pixel values during gain map generation and application.
49
+ * @defaultValue [1/64, 1/64, 1/64]
50
+ */
51
+ offsetHdr: [number, number, number];
52
+ /**
53
+ * This is log2 of min content boost, which is the minimum allowed ratio of
54
+ * the linear luminance for the target HDR rendition relative to
55
+ * (divided by) that of the SDR image, at a given pixel.
56
+ */
57
+ gainMapMin: [number, number, number];
58
+ /**
59
+ * This is log2 of max content boost, which is the maximum allowed ratio of
60
+ * the linear luminance for the Target HDR rendition relative to
61
+ * (divided by) that of the SDR image, at a given pixel.
62
+ */
63
+ gainMapMax: [number, number, number];
64
+ };
@@ -0,0 +1,56 @@
1
+ import { QuadRenderer } from '../core/QuadRenderer';
2
+ import { GainMapDecoderMaterial } from './materials/GainMapDecoderMaterial';
3
+ import { DecodeParameters } from './types';
4
+ /**
5
+ * Decodes a gain map using a WebGLRenderTarget
6
+ *
7
+ * @category Decoding
8
+ * @group Decoding
9
+ * @example
10
+ * import { decode } from '@monogrid/gainmap-js'
11
+ * import {
12
+ * Mesh,
13
+ * MeshBasicMaterial,
14
+ * PerspectiveCamera,
15
+ * PlaneGeometry,
16
+ * Scene,
17
+ * TextureLoader,
18
+ * WebGLRenderer
19
+ * } from 'three'
20
+ *
21
+ * const renderer = new WebGLRenderer()
22
+ *
23
+ * const textureLoader = new TextureLoader()
24
+ *
25
+ * // load SDR Representation
26
+ * const sdr = await textureLoader.loadAsync('sdr.jpg')
27
+ * // load Gain map recovery image
28
+ * const gainMap = await textureLoader.loadAsync('gainmap.jpg')
29
+ * // load metadata
30
+ * const metadata = await (await fetch('metadata.json')).json()
31
+ *
32
+ * const result = await decode({
33
+ * sdr,
34
+ * gainMap,
35
+ * // this allows to use `result.renderTarget.texture` directly
36
+ * renderer,
37
+ * // this will restore the full HDR range
38
+ * maxDisplayBoost: Math.pow(2, metadata.hdrCapacityMax),
39
+ * ...metadata
40
+ * })
41
+ *
42
+ * const scene = new Scene()
43
+ * // `result` can be used to populate a Texture
44
+ * const mesh = new Mesh(
45
+ * new PlaneGeometry(),
46
+ * new MeshBasicMaterial({ map: result.renderTarget.texture })
47
+ * )
48
+ * scene.add(mesh)
49
+ * renderer.render(scene, new PerspectiveCamera())
50
+ *
51
+ *
52
+ * @param params
53
+ * @returns
54
+ * @throws {Error} if the WebGLRenderer fails to render the gain map
55
+ */
56
+ export declare const decode: (params: DecodeParameters) => QuadRenderer<1016, GainMapDecoderMaterial>;
@@ -0,0 +1,10 @@
1
+ /**
2
+ *
3
+ * @param jpegFile
4
+ * @returns
5
+ */
6
+ export declare const extractGainmapFromJPEG: (jpegFile: Uint8Array) => Promise<{
7
+ sdr: Uint8Array;
8
+ gainMap: Uint8Array;
9
+ metadata: import(".").GainMapMetadata;
10
+ }>;
@@ -0,0 +1,8 @@
1
+ export * from '../core/QuadRenderer';
2
+ export * from '../core/types';
3
+ export * from './decode';
4
+ export * from './extract';
5
+ export * from './loaders/GainMapLoader';
6
+ export * from './loaders/JPEGRLoader';
7
+ export * from './materials/GainMapDecoderMaterial';
8
+ export * from './types';
@@ -1,7 +1,7 @@
1
1
  import { HalfFloatType } from 'three';
2
+ import { LoaderBase } from '../../core/LoaderBase';
3
+ import { QuadRenderer } from '../../core/QuadRenderer';
2
4
  import { GainMapDecoderMaterial } from '../materials/GainMapDecoderMaterial';
3
- import { QuadRenderer } from '../utils/QuadRenderer';
4
- import { LoaderBase } from './LoaderBase';
5
5
  /**
6
6
  * A Three.js Loader for the gain map format.
7
7
  *
@@ -38,7 +38,7 @@ import { LoaderBase } from './LoaderBase';
38
38
  *
39
39
  * // `result.renderTarget.texture` must be
40
40
  * // converted to `DataTexture` in order
41
- * // to use it as Equirectanmgular scene background
41
+ * // to use it as Equirectangular scene background
42
42
  * // if needed
43
43
  *
44
44
  * scene.background = result.toDataTexture()
@@ -54,7 +54,7 @@ export declare class GainMapLoader extends LoaderBase<[string, string, string]>
54
54
  * * gain map image
55
55
  * * metadata json
56
56
  *
57
- * useful for webp gainmaps
57
+ * useful for webp gain maps
58
58
  *
59
59
  * @param sdrUrl
60
60
  * @param gainMapUrl
@@ -1,7 +1,7 @@
1
1
  import { HalfFloatType } from 'three';
2
- import { GainMapDecoderMaterial } from '../materials/GainMapDecoderMaterial';
3
- import { QuadRenderer } from '../utils/QuadRenderer';
4
- import { LoaderBase } from './LoaderBase';
2
+ import { LoaderBase } from '../../core/LoaderBase';
3
+ import { QuadRenderer } from '../../core/QuadRenderer';
4
+ import { GainMapDecoderMaterial } from '../../decode/materials/GainMapDecoderMaterial';
5
5
  /**
6
6
  * A Three.js Loader for a JPEG with embedded gainmap metadata.
7
7
  *
@@ -9,7 +9,7 @@ import { LoaderBase } from './LoaderBase';
9
9
  * @group Loaders
10
10
  *
11
11
  * @example
12
- * import { JPEGRLoader } from '@monogrid/gainmap-js/libultrahdr'
12
+ * import { JPEGRLoader } from '@monogrid/gainmap-js'
13
13
  * import {
14
14
  * EquirectangularReflectionMapping,
15
15
  * LinearFilter,
@@ -38,7 +38,7 @@ import { LoaderBase } from './LoaderBase';
38
38
  *
39
39
  * // `result.renderTarget.texture` must be
40
40
  * // converted to `DataTexture` in order
41
- * // to use it as Equirectanmgular scene background
41
+ * // to use it as Equirectangular scene background
42
42
  * // if needed
43
43
  *
44
44
  * scene.background = result.toDataTexture()
@@ -1,5 +1,6 @@
1
1
  import { ShaderMaterial, Texture } from 'three';
2
- import { GainmapDecodingParameters, GainMapMetadata } from '../types';
2
+ import { GainMapMetadata } from '../../core/types';
3
+ import { GainmapDecodingParameters } from '../types';
3
4
  /**
4
5
  * A Material which is able to decode the Gainmap into a full HDR Representation
5
6
  *
@@ -43,7 +44,7 @@ export declare class GainMapDecoderMaterial extends ShaderMaterial {
43
44
  get gainMapMax(): [number, number, number];
44
45
  set gainMapMax(value: [number, number, number]);
45
46
  /**
46
- * @see {@link GainmapEncodingParameters.gamma}
47
+ * @see {@link GainMapMetadata.gamma}
47
48
  */
48
49
  get gamma(): [number, number, number];
49
50
  set gamma(value: [number, number, number]);
@@ -0,0 +1,38 @@
1
+ import { type Texture, type WebGLRenderer } from 'three';
2
+ import { type GainMapMetadata } from '../core/types';
3
+ /**
4
+ * Parameters for decoding a Gainmap
5
+ *
6
+ * @category Gainmap Specifications
7
+ * @group Gainmap Specifications
8
+ */
9
+ export type GainmapDecodingParameters = {
10
+ /**
11
+ * The maximum available boost supported by a display, at a given point in time.
12
+ *
13
+ * @remarks
14
+ * This value can change over time based on device settings and other factors,
15
+ * such as ambient light conditions, or how many bright pixels are on the screen.
16
+ *
17
+ * Non Logarithmic space
18
+ */
19
+ maxDisplayBoost: number;
20
+ };
21
+ /**
22
+ * @category Decoding
23
+ * @group Decoding
24
+ */
25
+ export type DecodeParameters = {
26
+ /**
27
+ * An Texture containing the SDR Rendition
28
+ */
29
+ sdr: Texture;
30
+ /**
31
+ * An Texture containing the GainMap recovery image
32
+ */
33
+ gainMap: Texture;
34
+ /**
35
+ * WebGLRenderer used to decode the GainMap
36
+ */
37
+ renderer?: WebGLRenderer;
38
+ } & GainmapDecodingParameters & GainMapMetadata;
@@ -0,0 +1,22 @@
1
+ type MPFExtractorOptions = {
2
+ debug: boolean;
3
+ extractFII: boolean;
4
+ extractNonFII: boolean;
5
+ };
6
+ /**
7
+ * MPF Extractor (Multi Picture Format Extractor)
8
+ * By Henrik S Nilsson 2019
9
+ *
10
+ * Extracts images stored in images based on the MPF format (found here: https://www.cipa.jp/e/std/std-sec.html
11
+ * under "CIPA DC-007-Translation-2021 Multi-Picture Format"
12
+ *
13
+ * Overly commented, and without intention of being complete or production ready.
14
+ * Created to extract depth maps from iPhone images, and to learn about image metadata.
15
+ * Kudos to: Phil Harvey (exiftool), Jaume Sanchez (android-lens-blur-depth-extractor)
16
+ */
17
+ export declare class MPFExtractor {
18
+ options: MPFExtractorOptions;
19
+ constructor(options?: Partial<MPFExtractorOptions>);
20
+ extract(imageArrayBuffer: Uint8Array): Promise<Blob[]>;
21
+ }
22
+ export {};
@@ -0,0 +1,7 @@
1
+ import { GainMapMetadata } from '../../core/types';
2
+ /**
3
+ *
4
+ * @param input
5
+ * @returns
6
+ */
7
+ export declare const extractXMP: (input: Uint8Array) => GainMapMetadata | undefined;
package/dist/decode.d.ts CHANGED
@@ -1,56 +1 @@
1
- import { GainMapDecoderMaterial } from './materials/GainMapDecoderMaterial';
2
- import { DecodeParameters } from './types';
3
- import { QuadRenderer } from './utils/QuadRenderer';
4
- /**
5
- * Decodes a gain map using a WebGLRenderTarget
6
- *
7
- * @category Decoding
8
- * @group Decoding
9
- * @example
10
- * import { decode } from '@monogrid/gainmap-js'
11
- * import {
12
- * Mesh,
13
- * MeshBasicMaterial,
14
- * PerspectiveCamera,
15
- * PlaneGeometry,
16
- * Scene,
17
- * TextureLoader,
18
- * WebGLRenderer
19
- * } from 'three'
20
- *
21
- * const renderer = new WebGLRenderer()
22
- *
23
- * const textureLoader = new TextureLoader()
24
- *
25
- * // load SDR Representation
26
- * const sdr = await textureLoader.loadAsync('sdr.jpg')
27
- * // load Gain map recovery image
28
- * const gainMap = await textureLoader.loadAsync('gainmap.jpg')
29
- * // load metadata
30
- * const metadata = await (await fetch('metadata.json')).json()
31
- *
32
- * const result = await decode({
33
- * sdr,
34
- * gainMap,
35
- * // this allows to use `result.renderTarget.texture` directly
36
- * renderer,
37
- * // this will restore the full HDR range
38
- * maxDisplayBoost: Math.pow(2, metadata.hdrCapacityMax),
39
- * ...metadata
40
- * })
41
- *
42
- * const scene = new Scene()
43
- * // `result` can be used to populate a Texture
44
- * const mesh = new Mesh(
45
- * new PlaneGeometry(),
46
- * new MeshBasicMaterial({ map: result.renderTarget.texture })
47
- * )
48
- * scene.add(mesh)
49
- * renderer.render(scene, new PerspectiveCamera())
50
- *
51
- *
52
- * @param params
53
- * @returns
54
- * @throws {Error} if the WebGLRenderer fails to render the gain map
55
- */
56
- export declare const decode: (params: DecodeParameters) => QuadRenderer<1016, GainMapDecoderMaterial>;
1
+ export * from './decode/index';