@monogrid/gainmap-js 2.0.5 → 2.0.7

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.4
2
+ * @monogrid/gainmap-js v2.0.6
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
@@ -27,7 +27,7 @@
27
27
  if (res)
28
28
  resolve(res);
29
29
  else
30
- reject('Failed to convert canvas to blob');
30
+ reject(new Error('Failed to convert canvas to blob'));
31
31
  }, mimeType, quality || 0.9);
32
32
  });
33
33
  };
@@ -103,7 +103,7 @@
103
103
  dataTexture = image;
104
104
  }
105
105
  else {
106
- dataTexture = new three.DataTexture(image.data, image.width, image.height, 'format' in image ? image.format : three.RGBAFormat, image.type, three.UVMapping, three.RepeatWrapping, three.RepeatWrapping, three.LinearFilter, three.LinearFilter, 1, 'colorSpace' in image && image.colorSpace === 'srgb' ? image.colorSpace : three.NoColorSpace);
106
+ dataTexture = new three.DataTexture(image.data, image.width, image.height, 'format' in image ? image.format : three.RGBAFormat, image.type, three.UVMapping, three.RepeatWrapping, three.RepeatWrapping, three.LinearFilter, three.LinearFilter, 1, 'colorSpace' in image && image.colorSpace === 'srgb' ? image.colorSpace : three.LinearSRGBColorSpace);
107
107
  // TODO: This tries to detect a raw RGBE and applies flipY
108
108
  // see if there's a better way to detect it?
109
109
  if ('header' in image && 'gamma' in image) {
@@ -160,7 +160,7 @@
160
160
  return _canReadPixelsResult;
161
161
  const testRT = new three.WebGLRenderTarget(1, 1, {
162
162
  type,
163
- colorSpace: three.NoColorSpace,
163
+ colorSpace: three.LinearSRGBColorSpace,
164
164
  format: three.RGBAFormat,
165
165
  magFilter: three.LinearFilter,
166
166
  minFilter: three.LinearFilter,
@@ -290,19 +290,75 @@
290
290
  this._renderer.readRenderTargetPixels(this._renderTarget, 0, 0, this._width, this._height, out);
291
291
  return out;
292
292
  }
293
+ /**
294
+ * Performs a readPixel operation in the renderTarget
295
+ * and returns a DataTexture containing the read data
296
+ *
297
+ * @returns
298
+ */
293
299
  toDataTexture() {
294
- return new three.DataTexture(this.toArray(), this.width, this.height, three.RGBAFormat, this._type, three.UVMapping, three.RepeatWrapping, three.RepeatWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, 1, three.NoColorSpace);
300
+ return new three.DataTexture(this.toArray(), this.width, this.height, three.RGBAFormat, this._type, three.UVMapping, three.RepeatWrapping, three.RepeatWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, 1, three.LinearSRGBColorSpace);
295
301
  }
296
302
  /**
297
303
  * If using a disposable renderer, it will dispose it.
298
304
  */
299
- dispose() {
305
+ disposeOnDemandRenderer() {
300
306
  this._renderer.setRenderTarget(null);
301
307
  if (this._rendererIsDisposable) {
302
308
  this._renderer.dispose();
303
309
  this._renderer.forceContextLoss();
304
310
  }
305
311
  }
312
+ /**
313
+ * Will dispose of **all** assets used by this renderer.
314
+ *
315
+ *
316
+ * @param disposeRenderTarget will dispose of the renderTarget which will not be usable later
317
+ * set this to true if you passed the `renderTarget.texture` to a `PMREMGenerator`
318
+ * or are otherwise done with it.
319
+ *
320
+ * @example
321
+ * ```js
322
+ * const loader = new HDRJPGLoader(renderer)
323
+ * const result = await loader.loadAsync('gainmap.jpeg')
324
+ * const mesh = new Mesh(geometry, new MeshBasicMaterial({ map: result.renderTarget.texture }) )
325
+ * // DO NOT dispose the renderTarget here,
326
+ * // it is used directly in the material
327
+ * result.dispose()
328
+ * ```
329
+ *
330
+ * @example
331
+ * ```js
332
+ * const loader = new HDRJPGLoader(renderer)
333
+ * const pmremGenerator = new PMREMGenerator( renderer );
334
+ * const result = await loader.loadAsync('gainmap.jpeg')
335
+ * const envMap = pmremGenerator.fromEquirectangular(result.renderTarget.texture)
336
+ * const mesh = new Mesh(geometry, new MeshStandardMaterial({ envMap }) )
337
+ * // renderTarget can be disposed here
338
+ * // because it was used to generate a PMREM texture
339
+ * result.dispose(true)
340
+ * ```
341
+ */
342
+ dispose(disposeRenderTarget) {
343
+ this.disposeOnDemandRenderer();
344
+ if (disposeRenderTarget) {
345
+ this.renderTarget.dispose();
346
+ }
347
+ // dispose shader material texture uniforms
348
+ if (this.material instanceof three.ShaderMaterial) {
349
+ Object.values(this.material.uniforms).forEach(v => {
350
+ if (v.value instanceof three.Texture)
351
+ v.value.dispose();
352
+ });
353
+ }
354
+ // dispose other material properties
355
+ Object.values(this.material).forEach(value => {
356
+ if (value instanceof three.Texture)
357
+ value.dispose();
358
+ });
359
+ this.material.dispose();
360
+ this._quad.geometry.dispose();
361
+ }
306
362
  /**
307
363
  * Width of the texture
308
364
  */
@@ -498,13 +554,17 @@ void main() {
498
554
  const getGainMap = (params) => {
499
555
  const { image, sdr, renderer } = params;
500
556
  const dataTexture = getDataTexture(image);
501
- const material = new GainMapEncoderMaterial(Object.assign(Object.assign({}, params), { sdr: sdr.renderTarget.texture, hdr: dataTexture }));
502
- const quadRenderer = new QuadRenderer(dataTexture.image.width, dataTexture.image.height, three.UnsignedByteType, three.NoColorSpace, material, renderer);
557
+ const material = new GainMapEncoderMaterial({
558
+ ...params,
559
+ sdr: sdr.renderTarget.texture,
560
+ hdr: dataTexture
561
+ });
562
+ const quadRenderer = new QuadRenderer(dataTexture.image.width, dataTexture.image.height, three.UnsignedByteType, three.LinearSRGBColorSpace, material, renderer);
503
563
  try {
504
564
  quadRenderer.render();
505
565
  }
506
566
  catch (e) {
507
- quadRenderer.dispose();
567
+ quadRenderer.disposeOnDemandRenderer();
508
568
  throw e;
509
569
  }
510
570
  return quadRenderer;
@@ -731,7 +791,7 @@ void main() {
731
791
  quadRenderer.render();
732
792
  }
733
793
  catch (e) {
734
- quadRenderer.dispose();
794
+ quadRenderer.disposeOnDemandRenderer();
735
795
  throw e;
736
796
  }
737
797
  return quadRenderer;
@@ -780,7 +840,10 @@ void main() {
780
840
  * encodingResult.gainMap.material.gamma = [1.1, 1.1, 1.1]
781
841
  * encodingResult.gainMap.render()
782
842
  *
783
- * // must be manually disposed
843
+ * // do something with encodingResult.gainMap.toArray()
844
+ * // and encodingResult.sdr.toArray()
845
+ *
846
+ * // renderers must be manually disposed
784
847
  * encodingResult.sdr.dispose()
785
848
  * encodingResult.gainMap.dispose()
786
849
  *
@@ -791,8 +854,12 @@ void main() {
791
854
  const { image, renderer } = params;
792
855
  const dataTexture = getDataTexture(image);
793
856
  const sdr = getSDRRendition(dataTexture, renderer, params.toneMapping);
794
- const gainMapRenderer = getGainMap(Object.assign(Object.assign({}, params), { image: dataTexture, sdr, renderer: sdr.renderer // reuse the same (maybe disposable?) renderer
795
- }));
857
+ const gainMapRenderer = getGainMap({
858
+ ...params,
859
+ image: dataTexture,
860
+ sdr,
861
+ renderer: sdr.renderer // reuse the same (maybe disposable?) renderer
862
+ });
796
863
  return {
797
864
  sdr,
798
865
  gainMap: gainMapRenderer,
@@ -904,8 +971,14 @@ void main() {
904
971
  }
905
972
  encodingResult.sdr.dispose();
906
973
  encodingResult.gainMap.dispose();
907
- return Object.assign(Object.assign(Object.assign({}, encodingResult), encodingResult.getMetadata()), { sdr: compressResult[0], gainMap: compressResult[1], rawSDR,
908
- rawGainMap });
974
+ return {
975
+ ...encodingResult,
976
+ ...encodingResult.getMetadata(),
977
+ sdr: compressResult[0],
978
+ gainMap: compressResult[1],
979
+ rawSDR,
980
+ rawGainMap
981
+ };
909
982
  };
910
983
 
911
984
  const vertexShader = /* glsl */ `
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.4
2
+ * @monogrid/gainmap-js v2.0.6
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
@@ -6627,11 +6627,13 @@ const decodeJPEGMetadata = async (file) => {
6627
6627
  hdrCapacityMin: parseFloat(hdrCapacityMin),
6628
6628
  hdrCapacityMax: parseFloat(hdrCapacityMax)
6629
6629
  };
6630
- return Object.assign(Object.assign({}, result), {
6630
+ return {
6631
+ ...result,
6631
6632
  /**
6632
6633
  * Parsed metadata
6633
6634
  */
6634
- parsedMetadata });
6635
+ parsedMetadata
6636
+ };
6635
6637
  };
6636
6638
 
6637
6639
  /**
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.4
2
+ * @monogrid/gainmap-js v2.0.6
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
@@ -6634,11 +6634,13 @@
6634
6634
  hdrCapacityMin: parseFloat(hdrCapacityMin),
6635
6635
  hdrCapacityMax: parseFloat(hdrCapacityMax)
6636
6636
  };
6637
- return Object.assign(Object.assign({}, result), {
6637
+ return {
6638
+ ...result,
6638
6639
  /**
6639
6640
  * Parsed metadata
6640
6641
  */
6641
- parsedMetadata });
6642
+ parsedMetadata
6643
+ };
6642
6644
  };
6643
6645
 
6644
6646
  /**
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.4
2
+ * @monogrid/gainmap-js v2.0.6
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
6
- import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers-bdHH9bEd.js';
6
+ import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers-ftl_lJMx.js';
7
7
 
8
8
  var lib$1;
9
9
  var hasRequiredLib$1;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.4
2
+ * @monogrid/gainmap-js v2.0.6
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
package/dist/worker.js CHANGED
@@ -1,10 +1,10 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.4
2
+ * @monogrid/gainmap-js v2.0.6
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
6
- import { g as getDefaultExportFromCjs } from './_commonjsHelpers-bdHH9bEd.js';
7
- import { c as compress } from './compress-aBsBfoFB.js';
6
+ import { g as getDefaultExportFromCjs } from './_commonjsHelpers-ftl_lJMx.js';
7
+ import { c as compress } from './compress-MvOX-rlz.js';
8
8
 
9
9
  var isPromise$2 = {exports: {}};
10
10
 
@@ -111,7 +111,10 @@ var registerPromiseWorker$1 = /*@__PURE__*/getDefaultExportFromCjs(register);
111
111
  // @ts-expect-error untyped lib
112
112
  const _compress = async (message, withTransferList) => {
113
113
  const result = await compress(message.payload);
114
- return withTransferList(Object.assign(Object.assign({}, result), { source: message.payload.source instanceof ImageData ? message.payload.source.data : new Uint8ClampedArray(message.payload.source) }), [result.data.buffer, message.payload.source instanceof ImageData ? message.payload.source.data.buffer : message.payload.source.buffer]);
114
+ return withTransferList({
115
+ ...result,
116
+ source: message.payload.source instanceof ImageData ? message.payload.source.data : new Uint8ClampedArray(message.payload.source)
117
+ }, [result.data.buffer, message.payload.source instanceof ImageData ? message.payload.source.data.buffer : message.payload.source.buffer]);
115
118
  };
116
119
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call
117
120
  registerPromiseWorker$1(async (message, withTransferList) => {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v2.0.4
2
+ * @monogrid/gainmap-js v2.0.6
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
@@ -132,7 +132,7 @@
132
132
  if (res)
133
133
  resolve(res);
134
134
  else
135
- reject('Failed to convert canvas to blob');
135
+ reject(new Error('Failed to convert canvas to blob'));
136
136
  }, mimeType, quality || 0.9);
137
137
  });
138
138
  };
@@ -193,7 +193,10 @@
193
193
  // @ts-expect-error untyped lib
194
194
  const _compress = async (message, withTransferList) => {
195
195
  const result = await compress(message.payload);
196
- return withTransferList(Object.assign(Object.assign({}, result), { source: message.payload.source instanceof ImageData ? message.payload.source.data : new Uint8ClampedArray(message.payload.source) }), [result.data.buffer, message.payload.source instanceof ImageData ? message.payload.source.data.buffer : message.payload.source.buffer]);
196
+ return withTransferList({
197
+ ...result,
198
+ source: message.payload.source instanceof ImageData ? message.payload.source.data : new Uint8ClampedArray(message.payload.source)
199
+ }, [result.data.buffer, message.payload.source instanceof ImageData ? message.payload.source.data.buffer : message.payload.source.buffer]);
197
200
  };
198
201
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call
199
202
  registerPromiseWorker$1(async (message, withTransferList) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monogrid/gainmap-js",
3
- "version": "2.0.5",
3
+ "version": "2.0.7",
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": {
@@ -80,20 +80,20 @@
80
80
  "test": "jest",
81
81
  "pretest": "npm run build",
82
82
  "check": "concurrently -c auto npm:check:*",
83
- "check:typecheck-src": "tsc --noEmit",
83
+ "check:typecheck-src": "tsc -p src",
84
84
  "check:eslint-src": "eslint \"src/**/*.ts\"",
85
- "check:typecheck-examples": "tsc --noEmit -p examples",
86
- "check:eslint-examples": "eslint \"examples/**/*.ts\"",
87
- "check:typecheck-tests": "tsc --noEmit --skipLibCheck -p tests",
88
- "check:eslint-tests": "eslint \"tests/**/*.ts\"",
85
+ "check:typecheck-examples": "tsc -p examples",
86
+ "check:eslint-examples": "eslint \"examples/**/*.{ts,html}\"",
87
+ "check:typecheck-tests": "tsc -p tests",
88
+ "check:eslint-tests": "eslint \"tests/**/*.{ts,html}\"",
89
89
  "ci:test": "JEST_JUNIT_OUTPUT_DIR=reports jest --ci --reporters=default --reporters=jest-junit",
90
90
  "ci:check": "concurrently npm:ci:check:*",
91
- "ci:check:typecheck-src": "tsc --pretty false --noEmit > reports/typecheck.log",
91
+ "ci:check:typecheck-src": "tsc --pretty false > reports/typecheck.log",
92
92
  "ci:check:eslint-src": "eslint --format json --output-file reports/eslint-src.json \"src/**/*.ts\"",
93
- "ci:check:typecheck-examples": "tsc --pretty false --noEmit -p examples > reports/typecheck-examples.log",
94
- "ci:check:eslint-examples": "eslint --format json --output-file reports/eslint-examples.json \"examples/**/*.ts\"",
95
- "ci:check:typecheck-tests": "tsc --pretty false --noEmit --skipLibCheck -p tests > reports/typecheck-tests.log",
96
- "ci:check:eslint-tests": "eslint --format json --output-file reports/eslint-tests.json \"tests/**/*.ts\""
93
+ "ci:check:typecheck-examples": "tsc --pretty false -p examples > reports/typecheck-examples.log",
94
+ "ci:check:eslint-examples": "eslint --format json --output-file reports/eslint-examples.json \"examples/**/*.{ts,html}\"",
95
+ "ci:check:typecheck-tests": "tsc --pretty false -p tests > reports/typecheck-tests.log",
96
+ "ci:check:eslint-tests": "eslint --format json --output-file reports/eslint-tests.json \"tests/**/*.{ts,html}\""
97
97
  },
98
98
  "peerDependencies": {
99
99
  "three": ">= 0.157.0 < 0.159.0"
@@ -116,14 +116,16 @@
116
116
  "@types/jest": "^29.5.8",
117
117
  "@types/node": "^20.9.0",
118
118
  "@types/three": "^0.158.2",
119
- "@typescript-eslint/eslint-plugin": "^6.10.0",
120
- "@typescript-eslint/parser": "^6.10.0",
119
+ "@typescript-eslint/eslint-plugin": "^6.11.0",
120
+ "@typescript-eslint/parser": "^6.11.0",
121
121
  "babel-jest": "^29.7.0",
122
122
  "concurrently": "^8.2.2",
123
123
  "conventional-changelog-conventionalcommits": "^7.0.2",
124
124
  "cz-conventional-changelog": "^3.3.0",
125
- "eslint": "^8.53.0",
125
+ "eslint": "^8.54.0",
126
+ "eslint-config-mdcs": "^5.0.0",
126
127
  "eslint-config-standard": "^17.0.0",
128
+ "eslint-plugin-compat": "^4.2.0",
127
129
  "eslint-plugin-html": "^7.1.0",
128
130
  "eslint-plugin-import": "^2.29.0",
129
131
  "eslint-plugin-jest-extended": "^2.0.0",
@@ -136,16 +138,19 @@
136
138
  "jest-environment-jsdom": "^29.7.0",
137
139
  "jest-extended": "^4.0.2",
138
140
  "jest-junit": "^16.0.0",
139
- "puppeteer": "^21.5.1",
140
- "rollup": "^4.3.0",
141
+ "puppeteer": "^21.5.2",
142
+ "rollup": "^4.5.0",
141
143
  "rollup-plugin-copy": "^3.5.0",
142
144
  "rollup-plugin-license": "^3.2.0",
143
- "semantic-release": "^22.0.7",
145
+ "semantic-release": "^22.0.8",
144
146
  "three": "^0.158.0",
145
147
  "ts-jest": "^29.1.1",
146
148
  "typedoc": "^0.25.3",
147
149
  "typedoc-github-wiki-theme": "^1.1.0",
148
150
  "typedoc-plugin-markdown": "^3.17.1",
149
151
  "typescript": "^5.2.2"
150
- }
152
+ },
153
+ "browserslist": [
154
+ "> 1%, not dead, not ie 11, not op_mini all"
155
+ ]
151
156
  }