@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/dist/worker.umd.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monogrid/gainmap-js",
|
|
3
|
-
"version": "
|
|
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": {
|
|
@@ -28,15 +28,19 @@
|
|
|
28
28
|
"path": "./node_modules/cz-conventional-changelog"
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
|
-
"main": "dist/
|
|
32
|
-
"module": "dist/
|
|
33
|
-
"types": "dist/
|
|
31
|
+
"main": "dist/decode.umd.js",
|
|
32
|
+
"module": "dist/decode.js",
|
|
33
|
+
"types": "dist/decode.d.ts",
|
|
34
34
|
"sideEffects": false,
|
|
35
35
|
"type": "module",
|
|
36
36
|
"exports": {
|
|
37
37
|
".": {
|
|
38
|
-
"import": "./dist/
|
|
39
|
-
"types": "./dist/
|
|
38
|
+
"import": "./dist/decode.js",
|
|
39
|
+
"types": "./dist/decode.d.ts"
|
|
40
|
+
},
|
|
41
|
+
"./encode": {
|
|
42
|
+
"import": "./dist/encode.js",
|
|
43
|
+
"types": "./dist/encode.d.ts"
|
|
40
44
|
},
|
|
41
45
|
"./libultrahdr": {
|
|
42
46
|
"import": "./dist/libultrahdr.js",
|
|
@@ -54,7 +58,10 @@
|
|
|
54
58
|
"typesVersions": {
|
|
55
59
|
"*": {
|
|
56
60
|
".": [
|
|
57
|
-
"./dist/
|
|
61
|
+
"./dist/decode.d.ts"
|
|
62
|
+
],
|
|
63
|
+
"encode": [
|
|
64
|
+
"./dist/encode.d.ts"
|
|
58
65
|
],
|
|
59
66
|
"libultrahdr": [
|
|
60
67
|
"./dist/libultrahdr.d.ts"
|
|
@@ -89,55 +96,55 @@
|
|
|
89
96
|
"ci:check:eslint-tests": "eslint --format json --output-file reports/eslint-tests.json \"tests/**/*.ts\""
|
|
90
97
|
},
|
|
91
98
|
"peerDependencies": {
|
|
92
|
-
"three": "
|
|
99
|
+
"three": ">= 0.157.0 < 0.159.0"
|
|
93
100
|
},
|
|
94
101
|
"dependencies": {
|
|
95
102
|
"promise-worker-transferable": "^1.0.4"
|
|
96
103
|
},
|
|
97
104
|
"devDependencies": {
|
|
98
|
-
"@
|
|
99
|
-
"@rollup/plugin-commonjs": "^25.0.5",
|
|
105
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
100
106
|
"@rollup/plugin-json": "^6.0.1",
|
|
101
107
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
102
108
|
"@rollup/plugin-terser": "^0.4.4",
|
|
103
109
|
"@rollup/plugin-typescript": "^11.1.5",
|
|
104
110
|
"@semantic-release/changelog": "^6.0.3",
|
|
105
|
-
"@semantic-release/commit-analyzer": "^11.
|
|
111
|
+
"@semantic-release/commit-analyzer": "^11.1.0",
|
|
106
112
|
"@semantic-release/git": "github:semantic-release/git",
|
|
107
|
-
"@semantic-release/github": "^9.2.
|
|
108
|
-
"@semantic-release/npm": "^11.0.
|
|
109
|
-
"@semantic-release/release-notes-generator": "^12.
|
|
110
|
-
"@types/jest": "^29.5.
|
|
111
|
-
"@types/node": "^20.
|
|
112
|
-
"@types/three": "^0.
|
|
113
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
114
|
-
"@typescript-eslint/parser": "^6.
|
|
113
|
+
"@semantic-release/github": "^9.2.3",
|
|
114
|
+
"@semantic-release/npm": "^11.0.1",
|
|
115
|
+
"@semantic-release/release-notes-generator": "^12.1.0",
|
|
116
|
+
"@types/jest": "^29.5.8",
|
|
117
|
+
"@types/node": "^20.9.0",
|
|
118
|
+
"@types/three": "^0.158.2",
|
|
119
|
+
"@typescript-eslint/eslint-plugin": "^6.10.0",
|
|
120
|
+
"@typescript-eslint/parser": "^6.10.0",
|
|
115
121
|
"babel-jest": "^29.7.0",
|
|
116
122
|
"concurrently": "^8.2.2",
|
|
117
123
|
"conventional-changelog-conventionalcommits": "^7.0.2",
|
|
118
124
|
"cz-conventional-changelog": "^3.3.0",
|
|
119
|
-
"eslint": "^8.
|
|
125
|
+
"eslint": "^8.53.0",
|
|
120
126
|
"eslint-config-standard": "^17.0.0",
|
|
121
|
-
"eslint-plugin-import": "^2.
|
|
127
|
+
"eslint-plugin-import": "^2.29.0",
|
|
122
128
|
"eslint-plugin-jest-extended": "^2.0.0",
|
|
123
|
-
"eslint-plugin-n": "^16.
|
|
129
|
+
"eslint-plugin-n": "^16.3.1",
|
|
124
130
|
"eslint-plugin-promise": "^6.0.0",
|
|
125
131
|
"eslint-plugin-quasar": "^1.1.0",
|
|
126
132
|
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
127
133
|
"eslint-plugin-unused-imports": "^3.0.0",
|
|
128
134
|
"jest": "^29.7.0",
|
|
135
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
129
136
|
"jest-extended": "^4.0.2",
|
|
130
137
|
"jest-junit": "^16.0.0",
|
|
131
|
-
"puppeteer": "^21.
|
|
132
|
-
"rollup": "^
|
|
138
|
+
"puppeteer": "^21.5.1",
|
|
139
|
+
"rollup": "^4.3.0",
|
|
133
140
|
"rollup-plugin-copy": "^3.5.0",
|
|
134
|
-
"rollup-plugin-license": "^3.
|
|
135
|
-
"semantic-release": "^22.0.
|
|
136
|
-
"three": "^0.
|
|
141
|
+
"rollup-plugin-license": "^3.2.0",
|
|
142
|
+
"semantic-release": "^22.0.7",
|
|
143
|
+
"three": "^0.158.0",
|
|
137
144
|
"ts-jest": "^29.1.1",
|
|
138
|
-
"typedoc": "^0.25.
|
|
145
|
+
"typedoc": "^0.25.3",
|
|
139
146
|
"typedoc-github-wiki-theme": "^1.1.0",
|
|
140
|
-
"typedoc-plugin-markdown": "^3.
|
|
147
|
+
"typedoc-plugin-markdown": "^3.17.1",
|
|
141
148
|
"typescript": "^5.2.2"
|
|
142
149
|
}
|
|
143
150
|
}
|
|
@@ -1,382 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @monogrid/gainmap-js v1.1.0
|
|
3
|
-
* With ❤️, by MONOGRID <hello@mono-grid.com>
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { ShaderMaterial, Vector3, NoBlending, HalfFloatType, FloatType, Scene, OrthographicCamera, Mesh, PlaneGeometry, WebGLRenderTarget, RGBAFormat, LinearFilter, LinearMipMapLinearFilter, RepeatWrapping, WebGLRenderer, IntType, ShortType, ByteType, UnsignedIntType, 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._colorSpace = colorSpace;
|
|
176
|
-
if (type === HalfFloatType && navigator.userAgent.toLowerCase().includes('firefox')) {
|
|
177
|
-
this._type = FloatType;
|
|
178
|
-
}
|
|
179
|
-
this._material = material;
|
|
180
|
-
if (renderer) {
|
|
181
|
-
this._renderer = renderer;
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
this._renderer = QuadRenderer.instantiateRenderer();
|
|
185
|
-
this._rendererIsDisposable = true;
|
|
186
|
-
}
|
|
187
|
-
this._scene = new Scene();
|
|
188
|
-
this._camera = new OrthographicCamera();
|
|
189
|
-
this._camera.position.set(0, 0, 10);
|
|
190
|
-
this._camera.left = -0.5;
|
|
191
|
-
this._camera.right = 0.5;
|
|
192
|
-
this._camera.top = 0.5;
|
|
193
|
-
this._camera.bottom = -0.5;
|
|
194
|
-
this._camera.updateProjectionMatrix();
|
|
195
|
-
this._quad = new Mesh(new PlaneGeometry(), this._material);
|
|
196
|
-
this._quad.geometry.computeBoundingBox();
|
|
197
|
-
this._scene.add(this._quad);
|
|
198
|
-
this._renderTarget = new WebGLRenderTarget(width, height, {
|
|
199
|
-
type: this._type,
|
|
200
|
-
colorSpace,
|
|
201
|
-
format: RGBAFormat,
|
|
202
|
-
magFilter: LinearFilter,
|
|
203
|
-
minFilter: LinearMipMapLinearFilter,
|
|
204
|
-
wrapS: RepeatWrapping,
|
|
205
|
-
wrapT: RepeatWrapping,
|
|
206
|
-
depthBuffer: false,
|
|
207
|
-
stencilBuffer: false,
|
|
208
|
-
generateMipmaps: true
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* Instantiates a temporary renderer
|
|
213
|
-
*
|
|
214
|
-
* @returns
|
|
215
|
-
*/
|
|
216
|
-
static instantiateRenderer() {
|
|
217
|
-
const renderer = new WebGLRenderer();
|
|
218
|
-
renderer.setSize(128, 128);
|
|
219
|
-
// renderer.outputColorSpace = SRGBColorSpace
|
|
220
|
-
// renderer.toneMapping = LinearToneMapping
|
|
221
|
-
// renderer.debug.checkShaderErrors = false
|
|
222
|
-
// this._rendererIsDisposable = true
|
|
223
|
-
return renderer;
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Obtains a Buffer containing the rendered texture.
|
|
227
|
-
*
|
|
228
|
-
* @returns
|
|
229
|
-
*/
|
|
230
|
-
toArray() {
|
|
231
|
-
let out;
|
|
232
|
-
switch (this._type) {
|
|
233
|
-
case UnsignedByteType:
|
|
234
|
-
out = new Uint8ClampedArray(this._width * this._height * 4);
|
|
235
|
-
break;
|
|
236
|
-
case HalfFloatType:
|
|
237
|
-
out = new Uint16Array(this._width * this._height * 4);
|
|
238
|
-
break;
|
|
239
|
-
case UnsignedIntType:
|
|
240
|
-
out = new Uint32Array(this._width * this._height * 4);
|
|
241
|
-
break;
|
|
242
|
-
case ByteType:
|
|
243
|
-
out = new Int8Array(this._width * this._height * 4);
|
|
244
|
-
break;
|
|
245
|
-
case ShortType:
|
|
246
|
-
out = new Int16Array(this._width * this._height * 4);
|
|
247
|
-
break;
|
|
248
|
-
case IntType:
|
|
249
|
-
out = new Int32Array(this._width * this._height * 4);
|
|
250
|
-
break;
|
|
251
|
-
case FloatType:
|
|
252
|
-
out = new Float32Array(this._width * this._height * 4);
|
|
253
|
-
break;
|
|
254
|
-
default:
|
|
255
|
-
throw new Error('Unsupported data type');
|
|
256
|
-
}
|
|
257
|
-
this._renderer.readRenderTargetPixels(this._renderTarget, 0, 0, this._width, this._height, out);
|
|
258
|
-
return out;
|
|
259
|
-
}
|
|
260
|
-
toDataTexture() {
|
|
261
|
-
return new DataTexture(this.toArray(), this.width, this.height, RGBAFormat, this._type, UVMapping, RepeatWrapping, RepeatWrapping, LinearFilter, LinearMipMapLinearFilter, 1, NoColorSpace);
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* If using a disposable renderer, it will dispose it.
|
|
265
|
-
*/
|
|
266
|
-
dispose() {
|
|
267
|
-
this._renderer.setRenderTarget(null);
|
|
268
|
-
if (this._rendererIsDisposable) {
|
|
269
|
-
this._renderer.dispose();
|
|
270
|
-
this._renderer.forceContextLoss();
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Width of the texture
|
|
275
|
-
*/
|
|
276
|
-
get width() { return this._width; }
|
|
277
|
-
set width(value) {
|
|
278
|
-
this._width = value;
|
|
279
|
-
this._renderTarget.setSize(this._width, this._height);
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Height of the texture
|
|
283
|
-
*/
|
|
284
|
-
get height() { return this._height; }
|
|
285
|
-
set height(value) {
|
|
286
|
-
this._height = value;
|
|
287
|
-
this._renderTarget.setSize(this._width, this._height);
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* The renderer used
|
|
291
|
-
*/
|
|
292
|
-
get renderer() { return this._renderer; }
|
|
293
|
-
/**
|
|
294
|
-
* The `WebGLRenderTarget` used.
|
|
295
|
-
*/
|
|
296
|
-
get renderTarget() { return this._renderTarget; }
|
|
297
|
-
set renderTarget(value) {
|
|
298
|
-
this._renderTarget = value;
|
|
299
|
-
this._width = value.width;
|
|
300
|
-
this._height = value.height;
|
|
301
|
-
// this._type = value.texture.type
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* The `Material` used.
|
|
305
|
-
*/
|
|
306
|
-
get material() { return this._material; }
|
|
307
|
-
/**
|
|
308
|
-
*
|
|
309
|
-
*/
|
|
310
|
-
get type() { return this._type; }
|
|
311
|
-
get colorSpace() { return this._colorSpace; }
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
class LoaderBase extends Loader {
|
|
315
|
-
/**
|
|
316
|
-
*
|
|
317
|
-
* @param renderer
|
|
318
|
-
* @param manager
|
|
319
|
-
*/
|
|
320
|
-
constructor(renderer, manager) {
|
|
321
|
-
super(manager);
|
|
322
|
-
this.renderer = renderer;
|
|
323
|
-
}
|
|
324
|
-
/**
|
|
325
|
-
* @private
|
|
326
|
-
* @returns
|
|
327
|
-
*/
|
|
328
|
-
prepareQuadRenderer() {
|
|
329
|
-
// temporary values
|
|
330
|
-
const material = new GainMapDecoderMaterial({
|
|
331
|
-
gainMapMax: [1, 1, 1],
|
|
332
|
-
gainMapMin: [0, 0, 0],
|
|
333
|
-
gamma: [1, 1, 1],
|
|
334
|
-
offsetHdr: [1, 1, 1],
|
|
335
|
-
offsetSdr: [1, 1, 1],
|
|
336
|
-
hdrCapacityMax: 1,
|
|
337
|
-
hdrCapacityMin: 0,
|
|
338
|
-
maxDisplayBoost: 1,
|
|
339
|
-
gainMap: new Texture(),
|
|
340
|
-
sdr: new Texture()
|
|
341
|
-
});
|
|
342
|
-
return new QuadRenderer(16, 16, HalfFloatType, NoColorSpace, material, this.renderer);
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
*
|
|
346
|
-
* @private
|
|
347
|
-
* @param quadRenderer
|
|
348
|
-
* @param gainMapBuffer
|
|
349
|
-
* @param sdrBuffer
|
|
350
|
-
* @param metadata
|
|
351
|
-
*/
|
|
352
|
-
async render(quadRenderer, gainMapBuffer, sdrBuffer, metadata) {
|
|
353
|
-
const gainMapBlob = new Blob([gainMapBuffer], { type: 'image/jpeg' });
|
|
354
|
-
// TODO: figure out why result.sdr is not usable here, problem is in the libultrahdr-wasm repo
|
|
355
|
-
// we use the original image buffer instead
|
|
356
|
-
const sdrBlob = new Blob([sdrBuffer], { type: 'image/jpeg' });
|
|
357
|
-
const [gainMapImageBitmap, sdrImageBitmap] = await Promise.all([
|
|
358
|
-
createImageBitmap(gainMapBlob, { imageOrientation: 'flipY' }),
|
|
359
|
-
createImageBitmap(sdrBlob, { imageOrientation: 'flipY' })
|
|
360
|
-
]);
|
|
361
|
-
const gainMap = new Texture(gainMapImageBitmap, UVMapping, ClampToEdgeWrapping, ClampToEdgeWrapping, LinearFilter, LinearMipMapLinearFilter, RGBAFormat, UnsignedByteType, 1, NoColorSpace);
|
|
362
|
-
gainMap.needsUpdate = true;
|
|
363
|
-
const sdr = new Texture(sdrImageBitmap, UVMapping, ClampToEdgeWrapping, ClampToEdgeWrapping, LinearFilter, LinearMipMapLinearFilter, RGBAFormat, UnsignedByteType, 1, SRGBColorSpace);
|
|
364
|
-
sdr.needsUpdate = true;
|
|
365
|
-
quadRenderer.width = sdrImageBitmap.width;
|
|
366
|
-
quadRenderer.height = sdrImageBitmap.height;
|
|
367
|
-
quadRenderer.material.gainMap = gainMap;
|
|
368
|
-
quadRenderer.material.sdr = sdr;
|
|
369
|
-
quadRenderer.material.gainMapMin = metadata.gainMapMin;
|
|
370
|
-
quadRenderer.material.gainMapMax = metadata.gainMapMax;
|
|
371
|
-
quadRenderer.material.offsetHdr = metadata.offsetHdr;
|
|
372
|
-
quadRenderer.material.offsetSdr = metadata.offsetSdr;
|
|
373
|
-
quadRenderer.material.gamma = metadata.gamma;
|
|
374
|
-
quadRenderer.material.hdrCapacityMin = metadata.hdrCapacityMin;
|
|
375
|
-
quadRenderer.material.hdrCapacityMax = metadata.hdrCapacityMax;
|
|
376
|
-
quadRenderer.material.maxDisplayBoost = Math.pow(2, metadata.hdrCapacityMax);
|
|
377
|
-
quadRenderer.material.needsUpdate = true;
|
|
378
|
-
quadRenderer.render();
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
export { GainMapDecoderMaterial as G, LoaderBase as L, QuadRenderer as Q };
|
package/dist/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export * from './decode';
|
|
2
|
-
export * from './encode';
|
|
3
|
-
export * from './encode-utils/compress';
|
|
4
|
-
export * from './encode-utils/find-texture-min-max';
|
|
5
|
-
export * from './encode-utils/get-gainmap';
|
|
6
|
-
export * from './encode-utils/get-sdr-rendition';
|
|
7
|
-
export * from './loaders/GainMapLoader';
|
|
8
|
-
export * from './materials/index';
|
|
9
|
-
export * from './types';
|
|
10
|
-
export * from './utils/get-data-texture';
|
|
11
|
-
export * from './utils/QuadRenderer';
|