@monogrid/gainmap-js 1.0.2 → 1.1.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 (48) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +103 -19
  3. package/dist/LoaderBase-aa4842c4.js +373 -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/index.d.ts +1 -1
  8. package/dist/index.js +173 -246
  9. package/dist/index.umd.js +305 -14
  10. package/dist/libultrahdr-esm.wasm +0 -0
  11. package/dist/libultrahdr.d.ts +14 -19
  12. package/dist/libultrahdr.js +245 -203
  13. package/dist/libultrahdr.umd.js +611 -206
  14. package/dist/loaders/GainMapLoader.d.ts +68 -0
  15. package/dist/loaders/JPEGRLoader.d.ts +60 -0
  16. package/dist/loaders/LoaderBase.d.ts +27 -0
  17. package/dist/materials/GainMapDecoderMaterial.d.ts +44 -1
  18. package/dist/materials/GainMapEncoderMaterial.d.ts +29 -2
  19. package/dist/types.d.ts +10 -0
  20. package/dist/utils/QuadRenderer.d.ts +2 -1
  21. package/dist/worker-interface.js +1 -1
  22. package/dist/worker-interface.umd.js +1 -1
  23. package/dist/worker.js +1 -1
  24. package/dist/worker.umd.js +1 -1
  25. package/libultrahdr-wasm/build/libultrahdr-debug.js +156 -182
  26. package/libultrahdr-wasm/build/libultrahdr-debug.wasm +0 -0
  27. package/libultrahdr-wasm/build/libultrahdr-esm.js +153 -182
  28. package/libultrahdr-wasm/build/libultrahdr-esm.wasm +0 -0
  29. package/libultrahdr-wasm/build/libultrahdr.js +151 -180
  30. package/libultrahdr-wasm/build/libultrahdr.wasm +0 -0
  31. package/package.json +1 -1
  32. package/examples/README.md +0 -3
  33. package/examples/compress.ts +0 -43
  34. package/examples/decode-from-jpeg.ts +0 -40
  35. package/examples/decode-from-separate-data.ts +0 -41
  36. package/examples/decode-to-datatexture.ts +0 -65
  37. package/examples/encode-and-compress.ts +0 -29
  38. package/examples/encode-jpeg-metadata.ts +0 -57
  39. package/examples/encode.ts +0 -28
  40. package/examples/globals.d.ts +0 -6
  41. package/examples/worker.ts +0 -41
  42. package/reports/eslint-examples.json +0 -1
  43. package/reports/eslint-src.json +0 -1
  44. package/reports/eslint-tests.json +0 -1
  45. package/reports/junit.xml +0 -35
  46. package/reports/typecheck-examples.log +0 -0
  47. package/reports/typecheck-tests.log +0 -0
  48. package/reports/typecheck.log +0 -0
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [1.1.0](https://github.com/MONOGRID/gainmap-js/compare/v1.0.2...v1.1.0) (2023-11-06)
2
+
3
+
4
+ ### Features
5
+
6
+ * **decode:** adds threejs loaders ([b32f02a](https://github.com/MONOGRID/gainmap-js/commit/b32f02a09d20fbd9d17b35c65cf4dba8aafc9ed5))
7
+
1
8
  ## [1.0.2](https://github.com/MONOGRID/gainmap-js/compare/v1.0.1...v1.0.2) (2023-11-03)
2
9
 
3
10
 
package/README.md CHANGED
@@ -35,10 +35,24 @@ Refer to the [WIKI](https://github.com/MONOGRID/gainmap-js/wiki) for detailed do
35
35
  The main use case of this library is to decode a JPEG file that contains gain map data
36
36
  and use it instead of a traditional `.exr` or `.hdr` image.
37
37
 
38
+
39
+ ### Using a single JPEG with embedded Gain map Metadata
40
+
41
+ This approach lets you load a single file with an embedded Gain Map.
42
+
43
+ The advantage is to have a single file to load.
44
+
45
+ The disadvantages are:
46
+ * 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
+ * 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
+ * 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
+
38
51
  ```ts
39
- import { decode } from '@monogrid/gainmap-js'
40
- import { decodeJPEGMetadata } from '@monogrid/gainmap-js/libultrahdr'
52
+ import { JPEGRLoader } from '@monogrid/gainmap-js/libultrahdr'
41
53
  import {
54
+ EquirectangularReflectionMapping,
55
+ LinearFilter,
42
56
  Mesh,
43
57
  MeshBasicMaterial,
44
58
  PerspectiveCamera,
@@ -49,31 +63,77 @@ import {
49
63
 
50
64
  const renderer = new WebGLRenderer()
51
65
 
52
- // fetch a JPEG image containing a gainmap as ArrayBuffer
53
- const gainmap = await (await fetch('gainmap.jpeg')).arrayBuffer()
54
-
55
- // extract data from the JPEG
56
- const { sdr, gainMap, parsedMetadata } = await decodeJPEGMetadata(new Uint8Array(gainmap))
66
+ const loader = new JPEGRLoader(renderer)
57
67
 
58
- // restore the HDR texture
59
- const result = await decode({
60
- sdr,
61
- gainMap,
62
- // this allows to use `result.renderTarget.texture` directly
63
- renderer,
64
- // this will restore the full HDR range
65
- maxDisplayBoost: Math.pow(2, parsedMetadata.hdrCapacityMax),
66
- ...parsedMetadata
67
- })
68
+ const result = loader.load('gainmap.jpeg')
69
+ // `result` can be used to populate a Texture
68
70
 
69
71
  const scene = new Scene()
72
+ const mesh = new Mesh(
73
+ new PlaneGeometry(),
74
+ new MeshBasicMaterial({ map: result.renderTarget.texture })
75
+ )
76
+ scene.add(mesh)
77
+ renderer.render(scene, new PerspectiveCamera())
78
+
79
+ // `result.renderTarget.texture` must be
80
+ // converted to `DataTexture` in order
81
+ // to use it as Equirectanmgular scene background
82
+ // if needed
83
+
84
+ scene.background = result.toDataTexture()
85
+ scene.background.mapping = EquirectangularReflectionMapping
86
+ scene.background.minFilter = LinearFilter
87
+
88
+ ```
89
+
90
+ ### Using separate files
91
+
92
+ Using separate files will get rid of the limitations of using a single JPEG file but it will force to use three separate files
93
+
94
+ 1. An SDR Representation file
95
+ 2. A Gainmap file
96
+ 3. A JSON containing the gainmap metadata used for decoding
97
+
98
+ This solution will use the lighter `@monogrid/gainmap-js` package which will not load a `wasm` file and contains less code.
99
+
100
+ ```ts
101
+ import { GainMapLoader } from '@monogrid/gainmap-js'
102
+ import {
103
+ EquirectangularReflectionMapping,
104
+ LinearFilter,
105
+ Mesh,
106
+ MeshBasicMaterial,
107
+ PerspectiveCamera,
108
+ PlaneGeometry,
109
+ Scene,
110
+ WebGLRenderer
111
+ } from 'three'
112
+
113
+ const renderer = new WebGLRenderer()
114
+
115
+ const loader = new GainMapLoader(renderer)
116
+
117
+ const result = loader.load(['sdr.jpeg', 'gainmap.jpeg', 'metadata.json'])
70
118
  // `result` can be used to populate a Texture
119
+
120
+ const scene = new Scene()
71
121
  const mesh = new Mesh(
72
122
  new PlaneGeometry(),
73
123
  new MeshBasicMaterial({ map: result.renderTarget.texture })
74
124
  )
75
125
  scene.add(mesh)
76
126
  renderer.render(scene, new PerspectiveCamera())
127
+
128
+ // `result.renderTarget.texture` must be
129
+ // converted to `DataTexture` in order
130
+ // to use it as Equirectanmgular scene background
131
+ // if needed
132
+
133
+ scene.background = result.toDataTexture()
134
+ scene.background.mapping = EquirectangularReflectionMapping
135
+ scene.background.minFilter = LinearFilter
136
+
77
137
  ```
78
138
 
79
139
  ### Encoding
@@ -103,9 +163,17 @@ const encodingResult = encode({
103
163
  })
104
164
 
105
165
  // obtain the RAW RGBA SDR buffer and create an ImageData
106
- const sdrImageData = new ImageData(encodingResult.sdr.toArray(), encodingResult.sdr.width, encodingResult.sdr.height)
166
+ const sdrImageData = new ImageData(
167
+ encodingResult.sdr.toArray(),
168
+ encodingResult.sdr.width,
169
+ encodingResult.sdr.height
170
+ )
107
171
  // obtain the RAW RGBA Gain map buffer and create an ImageData
108
- const gainMapImageData = new ImageData(encodingResult.gainMap.toArray(), encodingResult.gainMap.width, encodingResult.gainMap.height)
172
+ const gainMapImageData = new ImageData(
173
+ encodingResult.gainMap.toArray(),
174
+ encodingResult.gainMap.width,
175
+ encodingResult.gainMap.height
176
+ )
109
177
 
110
178
  // parallel compress the RAW buffers into the specified mimeType
111
179
  const mimeType = 'image/jpeg'
@@ -142,6 +210,22 @@ const jpeg = await encodeJPEGMetadata({
142
210
  // `jpeg` will be an `Uint8Array` which can be saved somewhere
143
211
  ```
144
212
 
213
+ ## Libultrahdr in Vite
214
+
215
+ If you import `@monogrid/gainmap-js/libultrahdr`
216
+ You will need to exclude it from Vite optimizations.
217
+
218
+ ```js
219
+ // vite.config.js
220
+
221
+ module.exports = defineConfig({
222
+ ...
223
+ optimizeDeps: {
224
+ exclude: ['@monogrid/gainmap-js/libultrahdr']
225
+ },
226
+ ...
227
+ })
228
+ ```
145
229
 
146
230
  ## References
147
231
 
@@ -0,0 +1,373 @@
1
+ /**
2
+ * @monogrid/gainmap-js v1.0.2
3
+ * With ❤️, by MONOGRID <hello@mono-grid.com>
4
+ */
5
+
6
+ import { ShaderMaterial, Vector3, NoBlending, Scene, OrthographicCamera, Mesh, PlaneGeometry, WebGLRenderTarget, RGBAFormat, LinearFilter, LinearMipMapLinearFilter, RepeatWrapping, WebGLRenderer, FloatType, IntType, ShortType, ByteType, UnsignedIntType, HalfFloatType, UnsignedByteType, DataTexture, UVMapping, NoColorSpace, Loader, Texture, ClampToEdgeWrapping, SRGBColorSpace } from 'three';
7
+
8
+ const vertexShader = /* glsl */ `
9
+ varying vec2 vUv;
10
+
11
+ void main() {
12
+ vUv = uv;
13
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
14
+ }
15
+ `;
16
+ const fragmentShader = /* glsl */ `
17
+ uniform sampler2D sdr;
18
+ uniform sampler2D gainMap;
19
+ uniform vec3 gamma;
20
+ uniform vec3 offsetHdr;
21
+ uniform vec3 offsetSdr;
22
+ uniform vec3 gainMapMin;
23
+ uniform vec3 gainMapMax;
24
+ uniform float weightFactor;
25
+
26
+ varying vec2 vUv;
27
+
28
+ void main() {
29
+ vec3 rgb = texture2D(sdr, vUv).rgb;
30
+ vec3 recovery = texture2D(gainMap, vUv).rgb;
31
+ vec3 logRecovery = pow(recovery, gamma);
32
+ vec3 logBoost = gainMapMin * (1.0 - logRecovery) + gainMapMax * logRecovery;
33
+ vec3 hdrColor = (rgb + offsetSdr) * exp2(logBoost * weightFactor) - offsetHdr;
34
+ gl_FragColor = vec4(hdrColor, 1.0);
35
+ }
36
+ `;
37
+ /**
38
+ * A Material which is able to decode the Gainmap into a full HDR Representation
39
+ *
40
+ * @category Materials
41
+ * @group Materials
42
+ */
43
+ class GainMapDecoderMaterial extends ShaderMaterial {
44
+ /**
45
+ *
46
+ * @param params
47
+ */
48
+ constructor({ gamma, offsetHdr, offsetSdr, gainMapMin, gainMapMax, maxDisplayBoost, hdrCapacityMin, hdrCapacityMax, sdr, gainMap }) {
49
+ super({
50
+ name: 'GainMapDecoderMaterial',
51
+ vertexShader,
52
+ fragmentShader,
53
+ uniforms: {
54
+ sdr: { value: sdr },
55
+ gainMap: { value: gainMap },
56
+ gamma: { value: new Vector3(1.0 / gamma[0], 1.0 / gamma[1], 1.0 / gamma[2]) },
57
+ offsetHdr: { value: new Vector3().fromArray(offsetHdr) },
58
+ offsetSdr: { value: new Vector3().fromArray(offsetSdr) },
59
+ gainMapMin: { value: new Vector3().fromArray(gainMapMin) },
60
+ gainMapMax: { value: new Vector3().fromArray(gainMapMax) },
61
+ weightFactor: {
62
+ value: (Math.log2(maxDisplayBoost) - hdrCapacityMin) / (hdrCapacityMax - hdrCapacityMin)
63
+ }
64
+ },
65
+ blending: NoBlending,
66
+ depthTest: false,
67
+ depthWrite: false
68
+ });
69
+ this._maxDisplayBoost = maxDisplayBoost;
70
+ this._hdrCapacityMin = hdrCapacityMin;
71
+ this._hdrCapacityMax = hdrCapacityMax;
72
+ this.needsUpdate = true;
73
+ this.uniformsNeedUpdate = true;
74
+ }
75
+ get sdr() { return this.uniforms.sdr.value; }
76
+ set sdr(value) { this.uniforms.sdr.value = value; }
77
+ get gainMap() { return this.uniforms.gainMap.value; }
78
+ set gainMap(value) { this.uniforms.gainMap.value = value; }
79
+ /**
80
+ * @see {@link GainMapMetadata.offsetHdr}
81
+ */
82
+ get offsetHdr() { return this.uniforms.offsetHdr.value.toArray(); }
83
+ set offsetHdr(value) { this.uniforms.offsetHdr.value.fromArray(value); }
84
+ /**
85
+ * @see {@link GainMapMetadata.offsetSdr}
86
+ */
87
+ get offsetSdr() { return this.uniforms.offsetSdr.value.toArray(); }
88
+ set offsetSdr(value) { this.uniforms.offsetSdr.value.fromArray(value); }
89
+ /**
90
+ * @see {@link GainMapMetadata.gainMapMin}
91
+ */
92
+ get gainMapMin() { return this.uniforms.gainMapMin.value.toArray(); }
93
+ set gainMapMin(value) { this.uniforms.gainMapMin.value.fromArray(value); }
94
+ /**
95
+ * @see {@link GainMapMetadata.gainMapMax}
96
+ */
97
+ get gainMapMax() { return this.uniforms.gainMapMax.value.toArray(); }
98
+ set gainMapMax(value) { this.uniforms.gainMapMax.value.fromArray(value); }
99
+ /**
100
+ * @see {@link GainmapEncodingParameters.gamma}
101
+ */
102
+ get gamma() {
103
+ const g = this.uniforms.gamma.value;
104
+ return [1 / g.x, 1 / g.y, 1 / g.z];
105
+ }
106
+ set gamma(value) {
107
+ const g = this.uniforms.gamma.value;
108
+ g.x = 1.0 / value[0];
109
+ g.y = 1.0 / value[1];
110
+ g.z = 1.0 / value[2];
111
+ }
112
+ /**
113
+ * @see {@link GainMapMetadata.hdrCapacityMin}
114
+ * @remarks Logarithmic space
115
+ */
116
+ get hdrCapacityMin() { return this._hdrCapacityMin; }
117
+ set hdrCapacityMin(value) {
118
+ this._hdrCapacityMin = value;
119
+ this.calculateWeight();
120
+ }
121
+ /**
122
+ * @see {@link GainMapMetadata.hdrCapacityMin}
123
+ * @remarks Logarithmic space
124
+ */
125
+ get hdrCapacityMax() { return this._hdrCapacityMax; }
126
+ set hdrCapacityMax(value) {
127
+ this._hdrCapacityMax = value;
128
+ this.calculateWeight();
129
+ }
130
+ /**
131
+ * @see {@link GainmapDecodingParameters.maxDisplayBoost}
132
+ * @remarks Non Logarithmic space
133
+ */
134
+ get maxDisplayBoost() { return this._maxDisplayBoost; }
135
+ set maxDisplayBoost(value) {
136
+ this._maxDisplayBoost = value;
137
+ this.calculateWeight();
138
+ }
139
+ calculateWeight() {
140
+ this.uniforms.weightFactor.value = (Math.log2(this._maxDisplayBoost) - this._hdrCapacityMin) / (this._hdrCapacityMax - this._hdrCapacityMin);
141
+ }
142
+ }
143
+
144
+ /**
145
+ * Utility structure used for rendering a texture with a material
146
+ *
147
+ * @category General
148
+ * @group General
149
+ */
150
+ class QuadRenderer {
151
+ /**
152
+ *
153
+ * @param sourceTexture
154
+ * @param renderer
155
+ */
156
+ constructor(width, height, type, colorSpace, material, renderer) {
157
+ this._rendererIsDisposable = false;
158
+ /**
159
+ * Renders the input texture using the specified material
160
+ */
161
+ this.render = () => {
162
+ this._renderer.setRenderTarget(this._renderTarget);
163
+ try {
164
+ this._renderer.render(this._scene, this._camera);
165
+ }
166
+ catch (e) {
167
+ this._renderer.setRenderTarget(null);
168
+ throw e;
169
+ }
170
+ this._renderer.setRenderTarget(null);
171
+ };
172
+ this._width = width;
173
+ this._height = height;
174
+ this._type = type;
175
+ this._material = material;
176
+ if (renderer) {
177
+ this._renderer = renderer;
178
+ }
179
+ else {
180
+ this._renderer = QuadRenderer.instantiateRenderer();
181
+ this._rendererIsDisposable = true;
182
+ }
183
+ this._scene = new Scene();
184
+ this._camera = new OrthographicCamera();
185
+ this._camera.position.set(0, 0, 10);
186
+ this._camera.left = -0.5;
187
+ this._camera.right = 0.5;
188
+ this._camera.top = 0.5;
189
+ this._camera.bottom = -0.5;
190
+ this._camera.updateProjectionMatrix();
191
+ this._quad = new Mesh(new PlaneGeometry(), this._material);
192
+ this._quad.geometry.computeBoundingBox();
193
+ this._scene.add(this._quad);
194
+ this._renderTarget = new WebGLRenderTarget(width, height, {
195
+ type,
196
+ colorSpace,
197
+ format: RGBAFormat,
198
+ magFilter: LinearFilter,
199
+ minFilter: LinearMipMapLinearFilter,
200
+ wrapS: RepeatWrapping,
201
+ wrapT: RepeatWrapping,
202
+ depthBuffer: false,
203
+ stencilBuffer: false,
204
+ generateMipmaps: true
205
+ });
206
+ }
207
+ /**
208
+ * Instantiates a temporary renderer
209
+ *
210
+ * @returns
211
+ */
212
+ static instantiateRenderer() {
213
+ const renderer = new WebGLRenderer();
214
+ renderer.setSize(128, 128);
215
+ // renderer.outputColorSpace = SRGBColorSpace
216
+ // renderer.toneMapping = LinearToneMapping
217
+ // renderer.debug.checkShaderErrors = false
218
+ // this._rendererIsDisposable = true
219
+ return renderer;
220
+ }
221
+ /**
222
+ * Obtains a Buffer containing the rendered texture.
223
+ *
224
+ * @returns
225
+ */
226
+ toArray() {
227
+ let out;
228
+ switch (this._type) {
229
+ case UnsignedByteType:
230
+ out = new Uint8ClampedArray(this._width * this._height * 4);
231
+ break;
232
+ case HalfFloatType:
233
+ out = new Uint16Array(this._width * this._height * 4);
234
+ break;
235
+ case UnsignedIntType:
236
+ out = new Uint32Array(this._width * this._height * 4);
237
+ break;
238
+ case ByteType:
239
+ out = new Int8Array(this._width * this._height * 4);
240
+ break;
241
+ case ShortType:
242
+ out = new Int16Array(this._width * this._height * 4);
243
+ break;
244
+ case IntType:
245
+ out = new Int32Array(this._width * this._height * 4);
246
+ break;
247
+ case FloatType:
248
+ out = new Float32Array(this._width * this._height * 4);
249
+ break;
250
+ default:
251
+ throw new Error('Unsupported data type');
252
+ }
253
+ this._renderer.readRenderTargetPixels(this._renderTarget, 0, 0, this._width, this._height, out);
254
+ return out;
255
+ }
256
+ toDataTexture() {
257
+ return new DataTexture(this.toArray(), this.width, this.height, RGBAFormat, HalfFloatType, UVMapping, RepeatWrapping, RepeatWrapping, LinearFilter, LinearMipMapLinearFilter, 1, NoColorSpace);
258
+ }
259
+ /**
260
+ * If using a disposable renderer, it will dispose it.
261
+ */
262
+ dispose() {
263
+ this._renderer.setRenderTarget(null);
264
+ if (this._rendererIsDisposable) {
265
+ this._renderer.dispose();
266
+ this._renderer.forceContextLoss();
267
+ }
268
+ }
269
+ /**
270
+ * Width of the texture
271
+ */
272
+ get width() { return this._width; }
273
+ set width(value) {
274
+ this._width = value;
275
+ this._renderTarget.setSize(this._width, this._height);
276
+ }
277
+ /**
278
+ * Height of the texture
279
+ */
280
+ get height() { return this._height; }
281
+ set height(value) {
282
+ this._height = value;
283
+ this._renderTarget.setSize(this._width, this._height);
284
+ }
285
+ /**
286
+ * The renderer used
287
+ */
288
+ get renderer() { return this._renderer; }
289
+ /**
290
+ * The `WebGLRenderTarget` used.
291
+ */
292
+ get renderTarget() { return this._renderTarget; }
293
+ set renderTarget(value) {
294
+ this._renderTarget = value;
295
+ this._width = value.width;
296
+ this._height = value.height;
297
+ // this._type = value.texture.type
298
+ }
299
+ /**
300
+ * The `Material` used.
301
+ */
302
+ get material() { return this._material; }
303
+ }
304
+
305
+ class LoaderBase extends Loader {
306
+ /**
307
+ *
308
+ * @param renderer
309
+ * @param manager
310
+ */
311
+ constructor(renderer, manager) {
312
+ super(manager);
313
+ this.renderer = renderer;
314
+ }
315
+ /**
316
+ * @private
317
+ * @returns
318
+ */
319
+ prepareQuadRenderer() {
320
+ // temporary values
321
+ const material = new GainMapDecoderMaterial({
322
+ gainMapMax: [1, 1, 1],
323
+ gainMapMin: [0, 0, 0],
324
+ gamma: [1, 1, 1],
325
+ offsetHdr: [1, 1, 1],
326
+ offsetSdr: [1, 1, 1],
327
+ hdrCapacityMax: 1,
328
+ hdrCapacityMin: 0,
329
+ maxDisplayBoost: 1,
330
+ gainMap: new Texture(),
331
+ sdr: new Texture()
332
+ });
333
+ return new QuadRenderer(16, 16, HalfFloatType, NoColorSpace, material, this.renderer);
334
+ }
335
+ /**
336
+ *
337
+ * @private
338
+ * @param quadRenderer
339
+ * @param gainMapBuffer
340
+ * @param sdrBuffer
341
+ * @param metadata
342
+ */
343
+ async render(quadRenderer, gainMapBuffer, sdrBuffer, metadata) {
344
+ const gainMapBlob = new Blob([gainMapBuffer], { type: 'image/jpeg' });
345
+ // TODO: figure out why result.sdr is not usable here, problem is in the libultrahdr-wasm repo
346
+ // we use the original image buffer instead
347
+ const sdrBlob = new Blob([sdrBuffer], { type: 'image/jpeg' });
348
+ const [gainMapImageBitmap, sdrImageBitmap] = await Promise.all([
349
+ createImageBitmap(gainMapBlob, { imageOrientation: 'flipY' }),
350
+ createImageBitmap(sdrBlob, { imageOrientation: 'flipY' })
351
+ ]);
352
+ const gainMap = new Texture(gainMapImageBitmap, UVMapping, ClampToEdgeWrapping, ClampToEdgeWrapping, LinearFilter, LinearMipMapLinearFilter, RGBAFormat, UnsignedByteType, 1, NoColorSpace);
353
+ gainMap.needsUpdate = true;
354
+ const sdr = new Texture(sdrImageBitmap, UVMapping, ClampToEdgeWrapping, ClampToEdgeWrapping, LinearFilter, LinearMipMapLinearFilter, RGBAFormat, UnsignedByteType, 1, SRGBColorSpace);
355
+ sdr.needsUpdate = true;
356
+ quadRenderer.width = sdrImageBitmap.width;
357
+ quadRenderer.height = sdrImageBitmap.height;
358
+ quadRenderer.material.gainMap = gainMap;
359
+ quadRenderer.material.sdr = sdr;
360
+ quadRenderer.material.gainMapMin = metadata.gainMapMin;
361
+ quadRenderer.material.gainMapMax = metadata.gainMapMax;
362
+ quadRenderer.material.offsetHdr = metadata.offsetHdr;
363
+ quadRenderer.material.offsetSdr = metadata.offsetSdr;
364
+ quadRenderer.material.gamma = metadata.gamma;
365
+ quadRenderer.material.hdrCapacityMin = metadata.hdrCapacityMin;
366
+ quadRenderer.material.hdrCapacityMax = metadata.hdrCapacityMax;
367
+ quadRenderer.material.maxDisplayBoost = Math.pow(2, metadata.hdrCapacityMax);
368
+ quadRenderer.material.needsUpdate = true;
369
+ quadRenderer.render();
370
+ }
371
+ }
372
+
373
+ export { GainMapDecoderMaterial as G, LoaderBase as L, QuadRenderer as Q };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v1.0.1
2
+ * @monogrid/gainmap-js v1.0.2
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.0.2
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
package/dist/decode.d.ts CHANGED
@@ -8,27 +8,46 @@ import { QuadRenderer } from './utils/QuadRenderer';
8
8
  * @group Decoding
9
9
  * @example
10
10
  * import { decode } from '@monogrid/gainmap-js'
11
- * import { Mesh, MeshBasicMaterial, PlaneGeometry, TextureLoader } from 'three'
11
+ * import {
12
+ * Mesh,
13
+ * MeshBasicMaterial,
14
+ * PerspectiveCamera,
15
+ * PlaneGeometry,
16
+ * Scene,
17
+ * TextureLoader,
18
+ * WebGLRenderer
19
+ * } from 'three'
12
20
  *
13
- * const loader = new TextureLoader()
21
+ * const renderer = new WebGLRenderer()
22
+ *
23
+ * const textureLoader = new TextureLoader()
14
24
  *
15
25
  * // load SDR Representation
16
- * const sdr = await loader.loadAsync('sdr.jpg')
26
+ * const sdr = await textureLoader.loadAsync('sdr.jpg')
17
27
  * // load Gain map recovery image
18
- * const gainMap = await loader.loadAsync('gainmap.jpg')
28
+ * const gainMap = await textureLoader.loadAsync('gainmap.jpg')
19
29
  * // load metadata
20
30
  * const metadata = await (await fetch('metadata.json')).json()
21
31
  *
22
32
  * const result = await decode({
23
33
  * sdr,
24
34
  * gainMap,
35
+ * // this allows to use `result.renderTarget.texture` directly
36
+ * renderer,
25
37
  * // this will restore the full HDR range
26
38
  * maxDisplayBoost: Math.pow(2, metadata.hdrCapacityMax),
27
39
  * ...metadata
28
40
  * })
29
41
  *
30
- * // result can be used to populate a Texture
31
- * const mesh = new Mesh(new PlaneGeometry(), new MeshBasicMaterial({ map: result.renderTarget.texture }))
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
+ *
32
51
  *
33
52
  * @param params
34
53
  * @returns
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export * from './encode-utils/compress';
4
4
  export * from './encode-utils/find-texture-min-max';
5
5
  export * from './encode-utils/get-gainmap';
6
6
  export * from './encode-utils/get-sdr-rendition';
7
- export * from './materials/index';
7
+ export * from './loaders/GainMapLoader';
8
8
  export * from './materials/index';
9
9
  export * from './types';
10
10
  export * from './utils/get-data-texture';