@monogrid/gainmap-js 1.1.1 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/README.md +21 -8
- package/dist/QuadRenderer-2NcH1MyZ.js +238 -0
- package/dist/{_commonjsHelpers-1789f0cf.js → _commonjsHelpers-A0Fo_jMO.js} +1 -1
- package/dist/{compress-a4b59cab.js → compress-nWDFn7nF.js} +1 -1
- package/dist/{utils → core}/QuadRenderer.d.ts +3 -1
- package/dist/core/types.d.ts +64 -0
- package/dist/decode/decode.d.ts +56 -0
- package/dist/decode/extract.d.ts +10 -0
- package/dist/decode/index.d.ts +8 -0
- package/dist/{loaders → decode/loaders}/GainMapLoader.d.ts +1 -1
- package/dist/{loaders → decode/loaders}/JPEGRLoader.d.ts +3 -3
- package/dist/{loaders → decode/loaders}/LoaderBase.d.ts +2 -2
- package/dist/{materials → decode/materials}/GainMapDecoderMaterial.d.ts +3 -2
- package/dist/decode/types.d.ts +38 -0
- package/dist/decode/utils/MPFExtractor.d.ts +22 -0
- package/dist/decode/utils/extract-metadata-from-jpeg.d.ts +7 -0
- package/dist/decode.d.ts +1 -56
- package/dist/decode.js +735 -0
- package/dist/decode.umd.js +975 -0
- package/dist/{encode-utils → encode}/compress.d.ts +1 -1
- package/dist/encode/encode-and-compress.d.ts +61 -0
- package/dist/encode/encode.d.ts +58 -0
- package/dist/{encode-utils → encode}/get-gainmap.d.ts +3 -3
- package/dist/{encode-utils → encode}/get-sdr-rendition.d.ts +2 -3
- package/dist/encode/index.d.ts +10 -0
- package/dist/{types.d.ts → encode/types.d.ts} +2 -102
- package/dist/encode.d.ts +1 -117
- package/dist/{index.js → encode.js} +26 -218
- package/dist/encode.umd.js +1032 -0
- package/dist/libultrahdr/decode-jpeg-metadata.d.ts +2 -2
- package/dist/libultrahdr/encode-jpeg-metadata.d.ts +2 -1
- package/dist/libultrahdr.d.ts +0 -1
- package/dist/libultrahdr.js +2 -79
- package/dist/libultrahdr.umd.js +10 -460
- package/dist/worker-interface.js +2 -2
- package/dist/worker-interface.umd.js +1 -3
- package/dist/worker-types.d.ts +1 -1
- package/dist/worker.js +3 -3
- package/dist/worker.umd.js +1 -1
- package/package.json +36 -29
- package/dist/LoaderBase-eee19701.js +0 -382
- package/dist/index.d.ts +0 -11
- package/dist/index.umd.js +0 -1373
- package/dist/materials/index.d.ts +0 -3
- /package/dist/{utils → core}/get-data-texture.d.ts +0 -0
- /package/dist/{encode-utils → encode}/find-texture-min-max.d.ts +0 -0
- /package/dist/{materials → encode/materials}/GainMapEncoderMaterial.d.ts +0 -0
- /package/dist/{materials → encode/materials}/SDRMaterial.d.ts +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## [2.0.1](https://github.com/MONOGRID/gainmap-js/compare/v2.0.0...v2.0.1) (2023-11-14)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **decode:** implements proper feature testing for QuadRenderer.toArray ([20109ad](https://github.com/MONOGRID/gainmap-js/commit/20109ad31977124c1169f096e8ccd36628599f89))
|
|
7
|
+
|
|
8
|
+
# [2.0.0](https://github.com/MONOGRID/gainmap-js/compare/v1.1.1...v2.0.0) (2023-11-13)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* 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))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### BREAKING CHANGES
|
|
17
|
+
|
|
18
|
+
* 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.
|
|
19
|
+
|
|
20
|
+
`JPEGRLoader` has been moved from `@monogrid/gainmap-js/libultrahdr` to `@monogrid/gainmap-js` because it now uses a pure js approach
|
|
21
|
+
|
|
1
22
|
## [1.1.1](https://github.com/MONOGRID/gainmap-js/compare/v1.1.0...v1.1.1) (2023-11-09)
|
|
2
23
|
|
|
3
24
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
143
|
+
// to use it as Equirectangular scene background
|
|
131
144
|
// if needed
|
|
132
145
|
|
|
133
146
|
scene.background = result.toDataTexture()
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @monogrid/gainmap-js v2.0.0
|
|
3
|
+
* With ❤️, by MONOGRID <hello@mono-grid.com>
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { Scene, OrthographicCamera, HalfFloatType, FloatType, Mesh, PlaneGeometry, WebGLRenderTarget, RGBAFormat, LinearFilter, LinearMipMapLinearFilter, RepeatWrapping, WebGLRenderer, DataTexture, UVMapping, NoColorSpace, IntType, ShortType, ByteType, UnsignedIntType, UnsignedByteType, MeshBasicMaterial } from 'three';
|
|
7
|
+
|
|
8
|
+
const getBufferForType = (type, width, height) => {
|
|
9
|
+
let out;
|
|
10
|
+
switch (type) {
|
|
11
|
+
case UnsignedByteType:
|
|
12
|
+
out = new Uint8ClampedArray(width * height * 4);
|
|
13
|
+
break;
|
|
14
|
+
case HalfFloatType:
|
|
15
|
+
out = new Uint16Array(width * height * 4);
|
|
16
|
+
break;
|
|
17
|
+
case UnsignedIntType:
|
|
18
|
+
out = new Uint32Array(width * height * 4);
|
|
19
|
+
break;
|
|
20
|
+
case ByteType:
|
|
21
|
+
out = new Int8Array(width * height * 4);
|
|
22
|
+
break;
|
|
23
|
+
case ShortType:
|
|
24
|
+
out = new Int16Array(width * height * 4);
|
|
25
|
+
break;
|
|
26
|
+
case IntType:
|
|
27
|
+
out = new Int32Array(width * height * 4);
|
|
28
|
+
break;
|
|
29
|
+
case FloatType:
|
|
30
|
+
out = new Float32Array(width * height * 4);
|
|
31
|
+
break;
|
|
32
|
+
default:
|
|
33
|
+
throw new Error('Unsupported data type');
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
};
|
|
37
|
+
let _canReadPixelsResult;
|
|
38
|
+
/**
|
|
39
|
+
* Test if this browser implementation can correctly read pixels from the specified
|
|
40
|
+
* Render target type.
|
|
41
|
+
*
|
|
42
|
+
* Runs only once
|
|
43
|
+
*
|
|
44
|
+
* @param type
|
|
45
|
+
* @param renderer
|
|
46
|
+
* @param camera
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
const canReadPixels = (type, renderer, camera) => {
|
|
50
|
+
if (_canReadPixelsResult !== undefined)
|
|
51
|
+
return _canReadPixelsResult;
|
|
52
|
+
const testRT = new WebGLRenderTarget(1, 1, {
|
|
53
|
+
type,
|
|
54
|
+
colorSpace: NoColorSpace,
|
|
55
|
+
format: RGBAFormat,
|
|
56
|
+
magFilter: LinearFilter,
|
|
57
|
+
minFilter: LinearFilter,
|
|
58
|
+
wrapS: RepeatWrapping,
|
|
59
|
+
wrapT: RepeatWrapping,
|
|
60
|
+
depthBuffer: false,
|
|
61
|
+
stencilBuffer: false,
|
|
62
|
+
generateMipmaps: true
|
|
63
|
+
});
|
|
64
|
+
renderer.setRenderTarget(testRT);
|
|
65
|
+
const mesh = new Mesh(new PlaneGeometry(), new MeshBasicMaterial({ color: 0xffffff }));
|
|
66
|
+
renderer.render(mesh, camera);
|
|
67
|
+
renderer.setRenderTarget(null);
|
|
68
|
+
const out = getBufferForType(type, testRT.width, testRT.height);
|
|
69
|
+
renderer.readRenderTargetPixels(testRT, 0, 0, testRT.width, testRT.height, out);
|
|
70
|
+
testRT.dispose();
|
|
71
|
+
mesh.geometry.dispose();
|
|
72
|
+
mesh.material.dispose();
|
|
73
|
+
_canReadPixelsResult = out[0] !== 0;
|
|
74
|
+
return _canReadPixelsResult;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Utility structure used for rendering a texture with a material
|
|
78
|
+
*
|
|
79
|
+
* @category General
|
|
80
|
+
* @group General
|
|
81
|
+
*/
|
|
82
|
+
class QuadRenderer {
|
|
83
|
+
/**
|
|
84
|
+
*
|
|
85
|
+
* @param sourceTexture
|
|
86
|
+
* @param renderer
|
|
87
|
+
*/
|
|
88
|
+
constructor(width, height, type, colorSpace, material, renderer) {
|
|
89
|
+
this._rendererIsDisposable = false;
|
|
90
|
+
this._supportsReadPixels = true;
|
|
91
|
+
/**
|
|
92
|
+
* Renders the input texture using the specified material
|
|
93
|
+
*/
|
|
94
|
+
this.render = () => {
|
|
95
|
+
this._renderer.setRenderTarget(this._renderTarget);
|
|
96
|
+
try {
|
|
97
|
+
this._renderer.render(this._scene, this._camera);
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
this._renderer.setRenderTarget(null);
|
|
101
|
+
throw e;
|
|
102
|
+
}
|
|
103
|
+
this._renderer.setRenderTarget(null);
|
|
104
|
+
};
|
|
105
|
+
this._width = width;
|
|
106
|
+
this._height = height;
|
|
107
|
+
this._type = type;
|
|
108
|
+
this._colorSpace = colorSpace;
|
|
109
|
+
this._material = material;
|
|
110
|
+
if (renderer) {
|
|
111
|
+
this._renderer = renderer;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
this._renderer = QuadRenderer.instantiateRenderer();
|
|
115
|
+
this._rendererIsDisposable = true;
|
|
116
|
+
}
|
|
117
|
+
this._scene = new Scene();
|
|
118
|
+
this._camera = new OrthographicCamera();
|
|
119
|
+
this._camera.position.set(0, 0, 10);
|
|
120
|
+
this._camera.left = -0.5;
|
|
121
|
+
this._camera.right = 0.5;
|
|
122
|
+
this._camera.top = 0.5;
|
|
123
|
+
this._camera.bottom = -0.5;
|
|
124
|
+
this._camera.updateProjectionMatrix();
|
|
125
|
+
if (!canReadPixels(this._type, this._renderer, this._camera)) {
|
|
126
|
+
let alternativeType;
|
|
127
|
+
switch (this._type) {
|
|
128
|
+
case HalfFloatType:
|
|
129
|
+
alternativeType = this._renderer.extensions.has('EXT_color_buffer_float') ? FloatType : undefined;
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
if (alternativeType !== undefined) {
|
|
133
|
+
console.warn(`This browser does not support reading pixels from ${this._type} RenderTargets, switching to ${FloatType}`);
|
|
134
|
+
this._type = alternativeType;
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
this._supportsReadPixels = false;
|
|
138
|
+
console.warn('This browser dos not support toArray or toDataTexture, calls to those methods will result in an error thrown');
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
this._quad = new Mesh(new PlaneGeometry(), this._material);
|
|
142
|
+
this._quad.geometry.computeBoundingBox();
|
|
143
|
+
this._scene.add(this._quad);
|
|
144
|
+
this._renderTarget = new WebGLRenderTarget(width, height, {
|
|
145
|
+
type: this._type,
|
|
146
|
+
colorSpace,
|
|
147
|
+
format: RGBAFormat,
|
|
148
|
+
magFilter: LinearFilter,
|
|
149
|
+
minFilter: LinearMipMapLinearFilter,
|
|
150
|
+
wrapS: RepeatWrapping,
|
|
151
|
+
wrapT: RepeatWrapping,
|
|
152
|
+
depthBuffer: false,
|
|
153
|
+
stencilBuffer: false,
|
|
154
|
+
generateMipmaps: true
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Instantiates a temporary renderer
|
|
159
|
+
*
|
|
160
|
+
* @returns
|
|
161
|
+
*/
|
|
162
|
+
static instantiateRenderer() {
|
|
163
|
+
const renderer = new WebGLRenderer();
|
|
164
|
+
renderer.setSize(128, 128);
|
|
165
|
+
// renderer.outputColorSpace = SRGBColorSpace
|
|
166
|
+
// renderer.toneMapping = LinearToneMapping
|
|
167
|
+
// renderer.debug.checkShaderErrors = false
|
|
168
|
+
// this._rendererIsDisposable = true
|
|
169
|
+
return renderer;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Obtains a Buffer containing the rendered texture.
|
|
173
|
+
*
|
|
174
|
+
* @throws Error if the browser cannot read pixels from this RenderTarget type.
|
|
175
|
+
* @returns a TypedArray containing RGBA values from this renderer
|
|
176
|
+
*/
|
|
177
|
+
toArray() {
|
|
178
|
+
if (!this._supportsReadPixels)
|
|
179
|
+
throw new Error('Can\'t read pixels in this browser');
|
|
180
|
+
const out = getBufferForType(this._type, this._width, this._height);
|
|
181
|
+
this._renderer.readRenderTargetPixels(this._renderTarget, 0, 0, this._width, this._height, out);
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
toDataTexture() {
|
|
185
|
+
return new DataTexture(this.toArray(), this.width, this.height, RGBAFormat, this._type, UVMapping, RepeatWrapping, RepeatWrapping, LinearFilter, LinearMipMapLinearFilter, 1, NoColorSpace);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* If using a disposable renderer, it will dispose it.
|
|
189
|
+
*/
|
|
190
|
+
dispose() {
|
|
191
|
+
this._renderer.setRenderTarget(null);
|
|
192
|
+
if (this._rendererIsDisposable) {
|
|
193
|
+
this._renderer.dispose();
|
|
194
|
+
this._renderer.forceContextLoss();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Width of the texture
|
|
199
|
+
*/
|
|
200
|
+
get width() { return this._width; }
|
|
201
|
+
set width(value) {
|
|
202
|
+
this._width = value;
|
|
203
|
+
this._renderTarget.setSize(this._width, this._height);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Height of the texture
|
|
207
|
+
*/
|
|
208
|
+
get height() { return this._height; }
|
|
209
|
+
set height(value) {
|
|
210
|
+
this._height = value;
|
|
211
|
+
this._renderTarget.setSize(this._width, this._height);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* The renderer used
|
|
215
|
+
*/
|
|
216
|
+
get renderer() { return this._renderer; }
|
|
217
|
+
/**
|
|
218
|
+
* The `WebGLRenderTarget` used.
|
|
219
|
+
*/
|
|
220
|
+
get renderTarget() { return this._renderTarget; }
|
|
221
|
+
set renderTarget(value) {
|
|
222
|
+
this._renderTarget = value;
|
|
223
|
+
this._width = value.width;
|
|
224
|
+
this._height = value.height;
|
|
225
|
+
// this._type = value.texture.type
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* The `Material` used.
|
|
229
|
+
*/
|
|
230
|
+
get material() { return this._material; }
|
|
231
|
+
/**
|
|
232
|
+
*
|
|
233
|
+
*/
|
|
234
|
+
get type() { return this._type; }
|
|
235
|
+
get colorSpace() { return this._colorSpace; }
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export { QuadRenderer as Q };
|
|
@@ -22,6 +22,7 @@ export declare class QuadRenderer<TType extends TextureDataType, TMaterial exten
|
|
|
22
22
|
private _height;
|
|
23
23
|
private _type;
|
|
24
24
|
private _colorSpace;
|
|
25
|
+
private _supportsReadPixels;
|
|
25
26
|
/**
|
|
26
27
|
*
|
|
27
28
|
* @param sourceTexture
|
|
@@ -41,7 +42,8 @@ export declare class QuadRenderer<TType extends TextureDataType, TMaterial exten
|
|
|
41
42
|
/**
|
|
42
43
|
* Obtains a Buffer containing the rendered texture.
|
|
43
44
|
*
|
|
44
|
-
* @
|
|
45
|
+
* @throws Error if the browser cannot read pixels from this RenderTarget type.
|
|
46
|
+
* @returns a TypedArray containing RGBA values from this renderer
|
|
45
47
|
*/
|
|
46
48
|
toArray(): TextureDataTypeToBufferType<TType>;
|
|
47
49
|
toDataTexture(): DataTexture;
|
|
@@ -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,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,6 +1,6 @@
|
|
|
1
1
|
import { HalfFloatType } from 'three';
|
|
2
|
+
import { QuadRenderer } from '../../core/QuadRenderer';
|
|
2
3
|
import { GainMapDecoderMaterial } from '../materials/GainMapDecoderMaterial';
|
|
3
|
-
import { QuadRenderer } from '../utils/QuadRenderer';
|
|
4
4
|
import { LoaderBase } from './LoaderBase';
|
|
5
5
|
/**
|
|
6
6
|
* A Three.js Loader for the gain map format.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HalfFloatType } from 'three';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { QuadRenderer } from '../../core/QuadRenderer';
|
|
3
|
+
import { GainMapDecoderMaterial } from '../../decode/materials/GainMapDecoderMaterial';
|
|
4
4
|
import { LoaderBase } from './LoaderBase';
|
|
5
5
|
/**
|
|
6
6
|
* A Three.js Loader for a JPEG with embedded gainmap metadata.
|
|
@@ -9,7 +9,7 @@ import { LoaderBase } from './LoaderBase';
|
|
|
9
9
|
* @group Loaders
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
|
-
* import { JPEGRLoader } from '@monogrid/gainmap-js
|
|
12
|
+
* import { JPEGRLoader } from '@monogrid/gainmap-js'
|
|
13
13
|
* import {
|
|
14
14
|
* EquirectangularReflectionMapping,
|
|
15
15
|
* LinearFilter,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HalfFloatType, Loader, LoadingManager, WebGLRenderer } from 'three';
|
|
2
|
+
import { QuadRenderer } from '../../core/QuadRenderer';
|
|
3
|
+
import { type GainMapMetadata } from '../../core/types';
|
|
2
4
|
import { GainMapDecoderMaterial } from '../materials/GainMapDecoderMaterial';
|
|
3
|
-
import { GainMapMetadata } from '../types';
|
|
4
|
-
import { QuadRenderer } from '../utils/QuadRenderer';
|
|
5
5
|
export declare class LoaderBase<TUrl = string> extends Loader<QuadRenderer<typeof HalfFloatType, GainMapDecoderMaterial>, TUrl> {
|
|
6
6
|
private renderer;
|
|
7
7
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ShaderMaterial, Texture } from 'three';
|
|
2
|
-
import {
|
|
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
|
|
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 {};
|