@monogrid/gainmap-js 2.0.0 → 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 +7 -0
- package/dist/{QuadRenderer-IDZuHqZM.js → QuadRenderer-2NcH1MyZ.js} +92 -32
- package/dist/{_commonjsHelpers-G_2thcKl.js → _commonjsHelpers-A0Fo_jMO.js} +1 -1
- package/dist/{compress-Cw5IwRTb.js → compress-nWDFn7nF.js} +1 -1
- package/dist/core/QuadRenderer.d.ts +3 -1
- package/dist/decode/loaders/GainMapLoader.d.ts +1 -1
- package/dist/decode/loaders/JPEGRLoader.d.ts +1 -1
- package/dist/{core → decode/loaders}/LoaderBase.d.ts +3 -3
- package/dist/decode.js +2 -4
- package/dist/decode.umd.js +91 -33
- package/dist/encode.js +3 -3
- package/dist/encode.umd.js +91 -31
- package/dist/libultrahdr.js +1 -1
- package/dist/libultrahdr.umd.js +1 -1
- package/dist/worker-interface.js +2 -2
- package/dist/worker-interface.umd.js +1 -1
- package/dist/worker.js +3 -3
- package/dist/worker.umd.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
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
|
+
|
|
1
8
|
# [2.0.0](https://github.com/MONOGRID/gainmap-js/compare/v1.1.1...v2.0.0) (2023-11-13)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -1,10 +1,78 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @monogrid/gainmap-js
|
|
2
|
+
* @monogrid/gainmap-js v2.0.0
|
|
3
3
|
* With ❤️, by MONOGRID <hello@mono-grid.com>
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
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
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
|
+
};
|
|
8
76
|
/**
|
|
9
77
|
* Utility structure used for rendering a texture with a material
|
|
10
78
|
*
|
|
@@ -19,6 +87,7 @@ class QuadRenderer {
|
|
|
19
87
|
*/
|
|
20
88
|
constructor(width, height, type, colorSpace, material, renderer) {
|
|
21
89
|
this._rendererIsDisposable = false;
|
|
90
|
+
this._supportsReadPixels = true;
|
|
22
91
|
/**
|
|
23
92
|
* Renders the input texture using the specified material
|
|
24
93
|
*/
|
|
@@ -37,9 +106,6 @@ class QuadRenderer {
|
|
|
37
106
|
this._height = height;
|
|
38
107
|
this._type = type;
|
|
39
108
|
this._colorSpace = colorSpace;
|
|
40
|
-
if (type === HalfFloatType && navigator.userAgent.toLowerCase().includes('firefox')) {
|
|
41
|
-
this._type = FloatType;
|
|
42
|
-
}
|
|
43
109
|
this._material = material;
|
|
44
110
|
if (renderer) {
|
|
45
111
|
this._renderer = renderer;
|
|
@@ -56,6 +122,22 @@ class QuadRenderer {
|
|
|
56
122
|
this._camera.top = 0.5;
|
|
57
123
|
this._camera.bottom = -0.5;
|
|
58
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
|
+
}
|
|
59
141
|
this._quad = new Mesh(new PlaneGeometry(), this._material);
|
|
60
142
|
this._quad.geometry.computeBoundingBox();
|
|
61
143
|
this._scene.add(this._quad);
|
|
@@ -89,35 +171,13 @@ class QuadRenderer {
|
|
|
89
171
|
/**
|
|
90
172
|
* Obtains a Buffer containing the rendered texture.
|
|
91
173
|
*
|
|
92
|
-
* @
|
|
174
|
+
* @throws Error if the browser cannot read pixels from this RenderTarget type.
|
|
175
|
+
* @returns a TypedArray containing RGBA values from this renderer
|
|
93
176
|
*/
|
|
94
177
|
toArray() {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
}
|
|
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);
|
|
121
181
|
this._renderer.readRenderTargetPixels(this._renderTarget, 0, 0, this._width, this._height, out);
|
|
122
182
|
return out;
|
|
123
183
|
}
|
|
@@ -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;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HalfFloatType } from 'three';
|
|
2
|
-
import { LoaderBase } from '../../core/LoaderBase';
|
|
3
2
|
import { QuadRenderer } from '../../core/QuadRenderer';
|
|
4
3
|
import { GainMapDecoderMaterial } from '../materials/GainMapDecoderMaterial';
|
|
4
|
+
import { LoaderBase } from './LoaderBase';
|
|
5
5
|
/**
|
|
6
6
|
* A Three.js Loader for the gain map format.
|
|
7
7
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HalfFloatType } from 'three';
|
|
2
|
-
import { LoaderBase } from '../../core/LoaderBase';
|
|
3
2
|
import { QuadRenderer } from '../../core/QuadRenderer';
|
|
4
3
|
import { GainMapDecoderMaterial } from '../../decode/materials/GainMapDecoderMaterial';
|
|
4
|
+
import { LoaderBase } from './LoaderBase';
|
|
5
5
|
/**
|
|
6
6
|
* A Three.js Loader for a JPEG with embedded gainmap metadata.
|
|
7
7
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HalfFloatType, Loader, LoadingManager, WebGLRenderer } from 'three';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { QuadRenderer } from '../../core/QuadRenderer';
|
|
3
|
+
import { type GainMapMetadata } from '../../core/types';
|
|
4
|
+
import { GainMapDecoderMaterial } from '../materials/GainMapDecoderMaterial';
|
|
5
5
|
export declare class LoaderBase<TUrl = string> extends Loader<QuadRenderer<typeof HalfFloatType, GainMapDecoderMaterial>, TUrl> {
|
|
6
6
|
private renderer;
|
|
7
7
|
/**
|
package/dist/decode.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @monogrid/gainmap-js
|
|
2
|
+
* @monogrid/gainmap-js v2.0.0
|
|
3
3
|
* With ❤️, by MONOGRID <hello@mono-grid.com>
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { Q as QuadRenderer } from './QuadRenderer-
|
|
6
|
+
import { Q as QuadRenderer } from './QuadRenderer-2NcH1MyZ.js';
|
|
7
7
|
import { ShaderMaterial, Vector3, NoBlending, SRGBColorSpace, NoColorSpace, HalfFloatType, Loader, Texture, UVMapping, ClampToEdgeWrapping, LinearFilter, LinearMipMapLinearFilter, RGBAFormat, UnsignedByteType, FileLoader } from 'three';
|
|
8
8
|
|
|
9
9
|
const vertexShader = /* glsl */ `
|
|
@@ -518,8 +518,6 @@ class LoaderBase extends Loader {
|
|
|
518
518
|
*/
|
|
519
519
|
async render(quadRenderer, gainMapBuffer, sdrBuffer, metadata) {
|
|
520
520
|
const gainMapBlob = new Blob([gainMapBuffer], { type: 'image/jpeg' });
|
|
521
|
-
// TODO: figure out why result.sdr is not usable here, problem is in the libultrahdr-wasm repo
|
|
522
|
-
// we use the original image buffer instead
|
|
523
521
|
const sdrBlob = new Blob([sdrBuffer], { type: 'image/jpeg' });
|
|
524
522
|
const [gainMapImageBitmap, sdrImageBitmap] = await Promise.all([
|
|
525
523
|
createImageBitmap(gainMapBlob, { imageOrientation: 'flipY' }),
|
package/dist/decode.umd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @monogrid/gainmap-js
|
|
2
|
+
* @monogrid/gainmap-js v2.0.0
|
|
3
3
|
* With ❤️, by MONOGRID <hello@mono-grid.com>
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -9,6 +9,74 @@
|
|
|
9
9
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@monogrid/gainmap-js"] = {}, global.three));
|
|
10
10
|
})(this, (function (exports, three) { 'use strict';
|
|
11
11
|
|
|
12
|
+
const getBufferForType = (type, width, height) => {
|
|
13
|
+
let out;
|
|
14
|
+
switch (type) {
|
|
15
|
+
case three.UnsignedByteType:
|
|
16
|
+
out = new Uint8ClampedArray(width * height * 4);
|
|
17
|
+
break;
|
|
18
|
+
case three.HalfFloatType:
|
|
19
|
+
out = new Uint16Array(width * height * 4);
|
|
20
|
+
break;
|
|
21
|
+
case three.UnsignedIntType:
|
|
22
|
+
out = new Uint32Array(width * height * 4);
|
|
23
|
+
break;
|
|
24
|
+
case three.ByteType:
|
|
25
|
+
out = new Int8Array(width * height * 4);
|
|
26
|
+
break;
|
|
27
|
+
case three.ShortType:
|
|
28
|
+
out = new Int16Array(width * height * 4);
|
|
29
|
+
break;
|
|
30
|
+
case three.IntType:
|
|
31
|
+
out = new Int32Array(width * height * 4);
|
|
32
|
+
break;
|
|
33
|
+
case three.FloatType:
|
|
34
|
+
out = new Float32Array(width * height * 4);
|
|
35
|
+
break;
|
|
36
|
+
default:
|
|
37
|
+
throw new Error('Unsupported data type');
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
};
|
|
41
|
+
let _canReadPixelsResult;
|
|
42
|
+
/**
|
|
43
|
+
* Test if this browser implementation can correctly read pixels from the specified
|
|
44
|
+
* Render target type.
|
|
45
|
+
*
|
|
46
|
+
* Runs only once
|
|
47
|
+
*
|
|
48
|
+
* @param type
|
|
49
|
+
* @param renderer
|
|
50
|
+
* @param camera
|
|
51
|
+
* @returns
|
|
52
|
+
*/
|
|
53
|
+
const canReadPixels = (type, renderer, camera) => {
|
|
54
|
+
if (_canReadPixelsResult !== undefined)
|
|
55
|
+
return _canReadPixelsResult;
|
|
56
|
+
const testRT = new three.WebGLRenderTarget(1, 1, {
|
|
57
|
+
type,
|
|
58
|
+
colorSpace: three.NoColorSpace,
|
|
59
|
+
format: three.RGBAFormat,
|
|
60
|
+
magFilter: three.LinearFilter,
|
|
61
|
+
minFilter: three.LinearFilter,
|
|
62
|
+
wrapS: three.RepeatWrapping,
|
|
63
|
+
wrapT: three.RepeatWrapping,
|
|
64
|
+
depthBuffer: false,
|
|
65
|
+
stencilBuffer: false,
|
|
66
|
+
generateMipmaps: true
|
|
67
|
+
});
|
|
68
|
+
renderer.setRenderTarget(testRT);
|
|
69
|
+
const mesh = new three.Mesh(new three.PlaneGeometry(), new three.MeshBasicMaterial({ color: 0xffffff }));
|
|
70
|
+
renderer.render(mesh, camera);
|
|
71
|
+
renderer.setRenderTarget(null);
|
|
72
|
+
const out = getBufferForType(type, testRT.width, testRT.height);
|
|
73
|
+
renderer.readRenderTargetPixels(testRT, 0, 0, testRT.width, testRT.height, out);
|
|
74
|
+
testRT.dispose();
|
|
75
|
+
mesh.geometry.dispose();
|
|
76
|
+
mesh.material.dispose();
|
|
77
|
+
_canReadPixelsResult = out[0] !== 0;
|
|
78
|
+
return _canReadPixelsResult;
|
|
79
|
+
};
|
|
12
80
|
/**
|
|
13
81
|
* Utility structure used for rendering a texture with a material
|
|
14
82
|
*
|
|
@@ -23,6 +91,7 @@
|
|
|
23
91
|
*/
|
|
24
92
|
constructor(width, height, type, colorSpace, material, renderer) {
|
|
25
93
|
this._rendererIsDisposable = false;
|
|
94
|
+
this._supportsReadPixels = true;
|
|
26
95
|
/**
|
|
27
96
|
* Renders the input texture using the specified material
|
|
28
97
|
*/
|
|
@@ -41,9 +110,6 @@
|
|
|
41
110
|
this._height = height;
|
|
42
111
|
this._type = type;
|
|
43
112
|
this._colorSpace = colorSpace;
|
|
44
|
-
if (type === three.HalfFloatType && navigator.userAgent.toLowerCase().includes('firefox')) {
|
|
45
|
-
this._type = three.FloatType;
|
|
46
|
-
}
|
|
47
113
|
this._material = material;
|
|
48
114
|
if (renderer) {
|
|
49
115
|
this._renderer = renderer;
|
|
@@ -60,6 +126,22 @@
|
|
|
60
126
|
this._camera.top = 0.5;
|
|
61
127
|
this._camera.bottom = -0.5;
|
|
62
128
|
this._camera.updateProjectionMatrix();
|
|
129
|
+
if (!canReadPixels(this._type, this._renderer, this._camera)) {
|
|
130
|
+
let alternativeType;
|
|
131
|
+
switch (this._type) {
|
|
132
|
+
case three.HalfFloatType:
|
|
133
|
+
alternativeType = this._renderer.extensions.has('EXT_color_buffer_float') ? three.FloatType : undefined;
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
if (alternativeType !== undefined) {
|
|
137
|
+
console.warn(`This browser does not support reading pixels from ${this._type} RenderTargets, switching to ${three.FloatType}`);
|
|
138
|
+
this._type = alternativeType;
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
this._supportsReadPixels = false;
|
|
142
|
+
console.warn('This browser dos not support toArray or toDataTexture, calls to those methods will result in an error thrown');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
63
145
|
this._quad = new three.Mesh(new three.PlaneGeometry(), this._material);
|
|
64
146
|
this._quad.geometry.computeBoundingBox();
|
|
65
147
|
this._scene.add(this._quad);
|
|
@@ -93,35 +175,13 @@
|
|
|
93
175
|
/**
|
|
94
176
|
* Obtains a Buffer containing the rendered texture.
|
|
95
177
|
*
|
|
96
|
-
* @
|
|
178
|
+
* @throws Error if the browser cannot read pixels from this RenderTarget type.
|
|
179
|
+
* @returns a TypedArray containing RGBA values from this renderer
|
|
97
180
|
*/
|
|
98
181
|
toArray() {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
out = new Uint8ClampedArray(this._width * this._height * 4);
|
|
103
|
-
break;
|
|
104
|
-
case three.HalfFloatType:
|
|
105
|
-
out = new Uint16Array(this._width * this._height * 4);
|
|
106
|
-
break;
|
|
107
|
-
case three.UnsignedIntType:
|
|
108
|
-
out = new Uint32Array(this._width * this._height * 4);
|
|
109
|
-
break;
|
|
110
|
-
case three.ByteType:
|
|
111
|
-
out = new Int8Array(this._width * this._height * 4);
|
|
112
|
-
break;
|
|
113
|
-
case three.ShortType:
|
|
114
|
-
out = new Int16Array(this._width * this._height * 4);
|
|
115
|
-
break;
|
|
116
|
-
case three.IntType:
|
|
117
|
-
out = new Int32Array(this._width * this._height * 4);
|
|
118
|
-
break;
|
|
119
|
-
case three.FloatType:
|
|
120
|
-
out = new Float32Array(this._width * this._height * 4);
|
|
121
|
-
break;
|
|
122
|
-
default:
|
|
123
|
-
throw new Error('Unsupported data type');
|
|
124
|
-
}
|
|
182
|
+
if (!this._supportsReadPixels)
|
|
183
|
+
throw new Error('Can\'t read pixels in this browser');
|
|
184
|
+
const out = getBufferForType(this._type, this._width, this._height);
|
|
125
185
|
this._renderer.readRenderTargetPixels(this._renderTarget, 0, 0, this._width, this._height, out);
|
|
126
186
|
return out;
|
|
127
187
|
}
|
|
@@ -691,8 +751,6 @@ void main() {
|
|
|
691
751
|
*/
|
|
692
752
|
async render(quadRenderer, gainMapBuffer, sdrBuffer, metadata) {
|
|
693
753
|
const gainMapBlob = new Blob([gainMapBuffer], { type: 'image/jpeg' });
|
|
694
|
-
// TODO: figure out why result.sdr is not usable here, problem is in the libultrahdr-wasm repo
|
|
695
|
-
// we use the original image buffer instead
|
|
696
754
|
const sdrBlob = new Blob([sdrBuffer], { type: 'image/jpeg' });
|
|
697
755
|
const [gainMapImageBitmap, sdrImageBitmap] = await Promise.all([
|
|
698
756
|
createImageBitmap(gainMapBlob, { imageOrientation: 'flipY' }),
|
package/dist/encode.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @monogrid/gainmap-js
|
|
2
|
+
* @monogrid/gainmap-js v2.0.0
|
|
3
3
|
* With ❤️, by MONOGRID <hello@mono-grid.com>
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { c as compress } from './compress-
|
|
6
|
+
import { c as compress } from './compress-nWDFn7nF.js';
|
|
7
7
|
import { DataTexture, RGBAFormat, UVMapping, RepeatWrapping, LinearFilter, NoColorSpace, ShaderMaterial, Vector3, NoBlending, UnsignedByteType, ACESFilmicToneMapping, LinearToneMapping, CineonToneMapping, ReinhardToneMapping, SRGBColorSpace, Vector2, WebGLRenderTarget, NearestFilter, ClampToEdgeWrapping, FloatType, DataUtils } from 'three';
|
|
8
|
-
import { Q as QuadRenderer } from './QuadRenderer-
|
|
8
|
+
import { Q as QuadRenderer } from './QuadRenderer-2NcH1MyZ.js';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Utility function to obtain a `DataTexture` from various input formats
|
package/dist/encode.umd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @monogrid/gainmap-js
|
|
2
|
+
* @monogrid/gainmap-js v2.0.0
|
|
3
3
|
* With ❤️, by MONOGRID <hello@mono-grid.com>
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -114,6 +114,74 @@
|
|
|
114
114
|
return dataTexture;
|
|
115
115
|
};
|
|
116
116
|
|
|
117
|
+
const getBufferForType = (type, width, height) => {
|
|
118
|
+
let out;
|
|
119
|
+
switch (type) {
|
|
120
|
+
case three.UnsignedByteType:
|
|
121
|
+
out = new Uint8ClampedArray(width * height * 4);
|
|
122
|
+
break;
|
|
123
|
+
case three.HalfFloatType:
|
|
124
|
+
out = new Uint16Array(width * height * 4);
|
|
125
|
+
break;
|
|
126
|
+
case three.UnsignedIntType:
|
|
127
|
+
out = new Uint32Array(width * height * 4);
|
|
128
|
+
break;
|
|
129
|
+
case three.ByteType:
|
|
130
|
+
out = new Int8Array(width * height * 4);
|
|
131
|
+
break;
|
|
132
|
+
case three.ShortType:
|
|
133
|
+
out = new Int16Array(width * height * 4);
|
|
134
|
+
break;
|
|
135
|
+
case three.IntType:
|
|
136
|
+
out = new Int32Array(width * height * 4);
|
|
137
|
+
break;
|
|
138
|
+
case three.FloatType:
|
|
139
|
+
out = new Float32Array(width * height * 4);
|
|
140
|
+
break;
|
|
141
|
+
default:
|
|
142
|
+
throw new Error('Unsupported data type');
|
|
143
|
+
}
|
|
144
|
+
return out;
|
|
145
|
+
};
|
|
146
|
+
let _canReadPixelsResult;
|
|
147
|
+
/**
|
|
148
|
+
* Test if this browser implementation can correctly read pixels from the specified
|
|
149
|
+
* Render target type.
|
|
150
|
+
*
|
|
151
|
+
* Runs only once
|
|
152
|
+
*
|
|
153
|
+
* @param type
|
|
154
|
+
* @param renderer
|
|
155
|
+
* @param camera
|
|
156
|
+
* @returns
|
|
157
|
+
*/
|
|
158
|
+
const canReadPixels = (type, renderer, camera) => {
|
|
159
|
+
if (_canReadPixelsResult !== undefined)
|
|
160
|
+
return _canReadPixelsResult;
|
|
161
|
+
const testRT = new three.WebGLRenderTarget(1, 1, {
|
|
162
|
+
type,
|
|
163
|
+
colorSpace: three.NoColorSpace,
|
|
164
|
+
format: three.RGBAFormat,
|
|
165
|
+
magFilter: three.LinearFilter,
|
|
166
|
+
minFilter: three.LinearFilter,
|
|
167
|
+
wrapS: three.RepeatWrapping,
|
|
168
|
+
wrapT: three.RepeatWrapping,
|
|
169
|
+
depthBuffer: false,
|
|
170
|
+
stencilBuffer: false,
|
|
171
|
+
generateMipmaps: true
|
|
172
|
+
});
|
|
173
|
+
renderer.setRenderTarget(testRT);
|
|
174
|
+
const mesh = new three.Mesh(new three.PlaneGeometry(), new three.MeshBasicMaterial({ color: 0xffffff }));
|
|
175
|
+
renderer.render(mesh, camera);
|
|
176
|
+
renderer.setRenderTarget(null);
|
|
177
|
+
const out = getBufferForType(type, testRT.width, testRT.height);
|
|
178
|
+
renderer.readRenderTargetPixels(testRT, 0, 0, testRT.width, testRT.height, out);
|
|
179
|
+
testRT.dispose();
|
|
180
|
+
mesh.geometry.dispose();
|
|
181
|
+
mesh.material.dispose();
|
|
182
|
+
_canReadPixelsResult = out[0] !== 0;
|
|
183
|
+
return _canReadPixelsResult;
|
|
184
|
+
};
|
|
117
185
|
/**
|
|
118
186
|
* Utility structure used for rendering a texture with a material
|
|
119
187
|
*
|
|
@@ -128,6 +196,7 @@
|
|
|
128
196
|
*/
|
|
129
197
|
constructor(width, height, type, colorSpace, material, renderer) {
|
|
130
198
|
this._rendererIsDisposable = false;
|
|
199
|
+
this._supportsReadPixels = true;
|
|
131
200
|
/**
|
|
132
201
|
* Renders the input texture using the specified material
|
|
133
202
|
*/
|
|
@@ -146,9 +215,6 @@
|
|
|
146
215
|
this._height = height;
|
|
147
216
|
this._type = type;
|
|
148
217
|
this._colorSpace = colorSpace;
|
|
149
|
-
if (type === three.HalfFloatType && navigator.userAgent.toLowerCase().includes('firefox')) {
|
|
150
|
-
this._type = three.FloatType;
|
|
151
|
-
}
|
|
152
218
|
this._material = material;
|
|
153
219
|
if (renderer) {
|
|
154
220
|
this._renderer = renderer;
|
|
@@ -165,6 +231,22 @@
|
|
|
165
231
|
this._camera.top = 0.5;
|
|
166
232
|
this._camera.bottom = -0.5;
|
|
167
233
|
this._camera.updateProjectionMatrix();
|
|
234
|
+
if (!canReadPixels(this._type, this._renderer, this._camera)) {
|
|
235
|
+
let alternativeType;
|
|
236
|
+
switch (this._type) {
|
|
237
|
+
case three.HalfFloatType:
|
|
238
|
+
alternativeType = this._renderer.extensions.has('EXT_color_buffer_float') ? three.FloatType : undefined;
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
if (alternativeType !== undefined) {
|
|
242
|
+
console.warn(`This browser does not support reading pixels from ${this._type} RenderTargets, switching to ${three.FloatType}`);
|
|
243
|
+
this._type = alternativeType;
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
this._supportsReadPixels = false;
|
|
247
|
+
console.warn('This browser dos not support toArray or toDataTexture, calls to those methods will result in an error thrown');
|
|
248
|
+
}
|
|
249
|
+
}
|
|
168
250
|
this._quad = new three.Mesh(new three.PlaneGeometry(), this._material);
|
|
169
251
|
this._quad.geometry.computeBoundingBox();
|
|
170
252
|
this._scene.add(this._quad);
|
|
@@ -198,35 +280,13 @@
|
|
|
198
280
|
/**
|
|
199
281
|
* Obtains a Buffer containing the rendered texture.
|
|
200
282
|
*
|
|
201
|
-
* @
|
|
283
|
+
* @throws Error if the browser cannot read pixels from this RenderTarget type.
|
|
284
|
+
* @returns a TypedArray containing RGBA values from this renderer
|
|
202
285
|
*/
|
|
203
286
|
toArray() {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
out = new Uint8ClampedArray(this._width * this._height * 4);
|
|
208
|
-
break;
|
|
209
|
-
case three.HalfFloatType:
|
|
210
|
-
out = new Uint16Array(this._width * this._height * 4);
|
|
211
|
-
break;
|
|
212
|
-
case three.UnsignedIntType:
|
|
213
|
-
out = new Uint32Array(this._width * this._height * 4);
|
|
214
|
-
break;
|
|
215
|
-
case three.ByteType:
|
|
216
|
-
out = new Int8Array(this._width * this._height * 4);
|
|
217
|
-
break;
|
|
218
|
-
case three.ShortType:
|
|
219
|
-
out = new Int16Array(this._width * this._height * 4);
|
|
220
|
-
break;
|
|
221
|
-
case three.IntType:
|
|
222
|
-
out = new Int32Array(this._width * this._height * 4);
|
|
223
|
-
break;
|
|
224
|
-
case three.FloatType:
|
|
225
|
-
out = new Float32Array(this._width * this._height * 4);
|
|
226
|
-
break;
|
|
227
|
-
default:
|
|
228
|
-
throw new Error('Unsupported data type');
|
|
229
|
-
}
|
|
287
|
+
if (!this._supportsReadPixels)
|
|
288
|
+
throw new Error('Can\'t read pixels in this browser');
|
|
289
|
+
const out = getBufferForType(this._type, this._width, this._height);
|
|
230
290
|
this._renderer.readRenderTargetPixels(this._renderTarget, 0, 0, this._width, this._height, out);
|
|
231
291
|
return out;
|
|
232
292
|
}
|
package/dist/libultrahdr.js
CHANGED
package/dist/libultrahdr.umd.js
CHANGED
package/dist/worker-interface.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @monogrid/gainmap-js
|
|
2
|
+
* @monogrid/gainmap-js v2.0.0
|
|
3
3
|
* With ❤️, by MONOGRID <hello@mono-grid.com>
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers-
|
|
6
|
+
import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers-A0Fo_jMO.js';
|
|
7
7
|
|
|
8
8
|
var lib$1;
|
|
9
9
|
var hasRequiredLib$1;
|
package/dist/worker.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @monogrid/gainmap-js
|
|
2
|
+
* @monogrid/gainmap-js v2.0.0
|
|
3
3
|
* With ❤️, by MONOGRID <hello@mono-grid.com>
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { g as getDefaultExportFromCjs } from './_commonjsHelpers-
|
|
7
|
-
import { c as compress } from './compress-
|
|
6
|
+
import { g as getDefaultExportFromCjs } from './_commonjsHelpers-A0Fo_jMO.js';
|
|
7
|
+
import { c as compress } from './compress-nWDFn7nF.js';
|
|
8
8
|
|
|
9
9
|
var isPromise$2 = {exports: {}};
|
|
10
10
|
|
package/dist/worker.umd.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monogrid/gainmap-js",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "A Javascript (TypeScript) Port of Adobe Gainmap Technology for storing HDR Images using an SDR Image + a gain map",
|
|
5
5
|
"homepage": "https://github.com/MONOGRID/gainmap-js#readme",
|
|
6
6
|
"repository": {
|