@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.
Files changed (49) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +21 -8
  3. package/dist/QuadRenderer-2NcH1MyZ.js +238 -0
  4. package/dist/{_commonjsHelpers-1789f0cf.js → _commonjsHelpers-A0Fo_jMO.js} +1 -1
  5. package/dist/{compress-a4b59cab.js → compress-nWDFn7nF.js} +1 -1
  6. package/dist/{utils → core}/QuadRenderer.d.ts +3 -1
  7. package/dist/core/types.d.ts +64 -0
  8. package/dist/decode/decode.d.ts +56 -0
  9. package/dist/decode/extract.d.ts +10 -0
  10. package/dist/decode/index.d.ts +8 -0
  11. package/dist/{loaders → decode/loaders}/GainMapLoader.d.ts +1 -1
  12. package/dist/{loaders → decode/loaders}/JPEGRLoader.d.ts +3 -3
  13. package/dist/{loaders → decode/loaders}/LoaderBase.d.ts +2 -2
  14. package/dist/{materials → decode/materials}/GainMapDecoderMaterial.d.ts +3 -2
  15. package/dist/decode/types.d.ts +38 -0
  16. package/dist/decode/utils/MPFExtractor.d.ts +22 -0
  17. package/dist/decode/utils/extract-metadata-from-jpeg.d.ts +7 -0
  18. package/dist/decode.d.ts +1 -56
  19. package/dist/decode.js +735 -0
  20. package/dist/decode.umd.js +975 -0
  21. package/dist/{encode-utils → encode}/compress.d.ts +1 -1
  22. package/dist/encode/encode-and-compress.d.ts +61 -0
  23. package/dist/encode/encode.d.ts +58 -0
  24. package/dist/{encode-utils → encode}/get-gainmap.d.ts +3 -3
  25. package/dist/{encode-utils → encode}/get-sdr-rendition.d.ts +2 -3
  26. package/dist/encode/index.d.ts +10 -0
  27. package/dist/{types.d.ts → encode/types.d.ts} +2 -102
  28. package/dist/encode.d.ts +1 -117
  29. package/dist/{index.js → encode.js} +26 -218
  30. package/dist/encode.umd.js +1032 -0
  31. package/dist/libultrahdr/decode-jpeg-metadata.d.ts +2 -2
  32. package/dist/libultrahdr/encode-jpeg-metadata.d.ts +2 -1
  33. package/dist/libultrahdr.d.ts +0 -1
  34. package/dist/libultrahdr.js +2 -79
  35. package/dist/libultrahdr.umd.js +10 -460
  36. package/dist/worker-interface.js +2 -2
  37. package/dist/worker-interface.umd.js +1 -3
  38. package/dist/worker-types.d.ts +1 -1
  39. package/dist/worker.js +3 -3
  40. package/dist/worker.umd.js +1 -1
  41. package/package.json +36 -29
  42. package/dist/LoaderBase-eee19701.js +0 -382
  43. package/dist/index.d.ts +0 -11
  44. package/dist/index.umd.js +0 -1373
  45. package/dist/materials/index.d.ts +0 -3
  46. /package/dist/{utils → core}/get-data-texture.d.ts +0 -0
  47. /package/dist/{encode-utils → encode}/find-texture-min-max.d.ts +0 -0
  48. /package/dist/{materials → encode/materials}/GainMapEncoderMaterial.d.ts +0 -0
  49. /package/dist/{materials → encode/materials}/SDRMaterial.d.ts +0 -0
@@ -1,4 +1,4 @@
1
- import { GainMapMetadata } from '../types';
1
+ import { GainMapMetadata } from '../core/types';
2
2
  /**
3
3
  * Decodes a JPEG file with an embedded Gainmap and XMP Metadata (aka JPEG-R)
4
4
  *
@@ -23,7 +23,7 @@ export declare const decodeJPEGMetadata: (file: Uint8Array) => Promise<{
23
23
  * Parsed metadata
24
24
  */
25
25
  parsedMetadata: GainMapMetadata;
26
- metadata: string | Uint8ClampedArray | ArrayBuffer | Uint8Array | Int8Array;
26
+ metadata: string | Uint8ClampedArray | Int8Array | ArrayBuffer | Uint8Array;
27
27
  success: boolean;
28
28
  errorMessage: any;
29
29
  sdr: any;
@@ -1,4 +1,5 @@
1
- import { type CompressedImage, type GainMapMetadata } from '../types';
1
+ import { type GainMapMetadata } from '../core/types';
2
+ import { type CompressedImage } from '../encode/types';
2
3
  /**
3
4
  * Encapsulates a Gainmap into a single JPEG file (aka: JPEG-R) with the base map
4
5
  * as the sdr visualization and the gainMap encoded into a MPF (Multi-Picture Format) tag.
@@ -2,4 +2,3 @@ export * from '../libultrahdr-wasm/build/libultrahdr';
2
2
  export * from './libultrahdr/decode-jpeg-metadata';
3
3
  export * from './libultrahdr/encode-jpeg-metadata';
4
4
  export * from './libultrahdr/library';
5
- export * from './loaders/JPEGRLoader';
@@ -1,11 +1,8 @@
1
1
  /**
2
- * @monogrid/gainmap-js v1.1.0
2
+ * @monogrid/gainmap-js v2.0.0
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
6
- import { FileLoader } from 'three';
7
- import { L as LoaderBase } from './LoaderBase-eee19701.js';
8
-
9
6
  var Module = (() => {
10
7
  var _scriptDir = import.meta.url;
11
8
 
@@ -6695,78 +6692,4 @@ const encodeJPEGMetadata = async (encodingResult) => {
6695
6692
  return lib.appendGainMap(encodingResult.sdr.width, encodingResult.sdr.height, encodingResult.sdr.data, encodingResult.sdr.data.length, encodingResult.gainMap.data, encodingResult.gainMap.data.length, encodingResult.gainMapMax.reduce((p, n) => p + n, 0) / encodingResult.gainMapMax.length, encodingResult.gainMapMin.reduce((p, n) => p + n, 0) / encodingResult.gainMapMin.length, encodingResult.gamma.reduce((p, n) => p + n, 0) / encodingResult.gamma.length, encodingResult.offsetSdr.reduce((p, n) => p + n, 0) / encodingResult.offsetSdr.length, encodingResult.offsetHdr.reduce((p, n) => p + n, 0) / encodingResult.offsetHdr.length, encodingResult.hdrCapacityMin, encodingResult.hdrCapacityMax);
6696
6693
  };
6697
6694
 
6698
- /**
6699
- * A Three.js Loader for a JPEG with embedded gainmap metadata.
6700
- *
6701
- * @category Loaders
6702
- * @group Loaders
6703
- *
6704
- * @example
6705
- * import { JPEGRLoader } from '@monogrid/gainmap-js/libultrahdr'
6706
- * import {
6707
- * EquirectangularReflectionMapping,
6708
- * LinearFilter,
6709
- * Mesh,
6710
- * MeshBasicMaterial,
6711
- * PerspectiveCamera,
6712
- * PlaneGeometry,
6713
- * Scene,
6714
- * WebGLRenderer
6715
- * } from 'three'
6716
- *
6717
- * const renderer = new WebGLRenderer()
6718
- *
6719
- * const loader = new JPEGRLoader(renderer)
6720
- *
6721
- * const result = loader.load('gainmap.jpeg')
6722
- * // `result` can be used to populate a Texture
6723
- *
6724
- * const scene = new Scene()
6725
- * const mesh = new Mesh(
6726
- * new PlaneGeometry(),
6727
- * new MeshBasicMaterial({ map: result.renderTarget.texture })
6728
- * )
6729
- * scene.add(mesh)
6730
- * renderer.render(scene, new PerspectiveCamera())
6731
- *
6732
- * // `result.renderTarget.texture` must be
6733
- * // converted to `DataTexture` in order
6734
- * // to use it as Equirectangular scene background
6735
- * // if needed
6736
- *
6737
- * scene.background = result.toDataTexture()
6738
- * scene.background.mapping = EquirectangularReflectionMapping
6739
- * scene.background.minFilter = LinearFilter
6740
-
6741
- *
6742
- */
6743
- class JPEGRLoader extends LoaderBase {
6744
- /**
6745
- *
6746
- * @param url
6747
- * @param onLoad
6748
- * @param onProgress
6749
- * @param onError
6750
- * @returns
6751
- */
6752
- load(url, onLoad, onProgress, onError) {
6753
- const quadRenderer = this.prepareQuadRenderer();
6754
- const loader = new FileLoader(this.manager);
6755
- loader.setResponseType('arraybuffer');
6756
- loader.setRequestHeader(this.requestHeader);
6757
- loader.setPath(this.path);
6758
- loader.setWithCredentials(this.withCredentials);
6759
- loader.load(url, async (jpeg) => {
6760
- if (typeof jpeg === 'string')
6761
- throw new Error('Invalid buffer');
6762
- const { gainMap: gainMapJPEG, parsedMetadata } = await decodeJPEGMetadata(new Uint8Array(jpeg));
6763
- await this.render(quadRenderer, gainMapJPEG, jpeg, parsedMetadata);
6764
- if (typeof onLoad === 'function')
6765
- onLoad(quadRenderer);
6766
- quadRenderer.dispose();
6767
- }, onProgress, onError);
6768
- return quadRenderer;
6769
- }
6770
- }
6771
-
6772
- export { JPEGRLoader, decodeJPEGMetadata, encodeJPEGMetadata, getLibrary };
6695
+ export { decodeJPEGMetadata, encodeJPEGMetadata, getLibrary };
@@ -1,16 +1,17 @@
1
1
  /**
2
- * @monogrid/gainmap-js v1.1.0
2
+ * @monogrid/gainmap-js v2.0.0
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
6
6
  (function (global, factory) {
7
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('three')) :
8
- typeof define === 'function' && define.amd ? define(['exports', 'three'], factory) :
9
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.libultrahdr = {}, global.three));
10
- })(this, (function (exports, three) { 'use strict';
7
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
8
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
9
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.libultrahdr = {}));
10
+ })(this, (function (exports) { 'use strict';
11
11
 
12
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
12
13
  var Module = (() => {
13
- var _scriptDir = (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('libultrahdr.umd.js', document.baseURI).href));
14
+ var _scriptDir = (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.src || new URL('libultrahdr.umd.js', document.baseURI).href));
14
15
 
15
16
  return (
16
17
  async function(moduleArg = {}) {
@@ -106,7 +107,7 @@
106
107
  // TODO: Swap all `require()`'s with `import()`'s?
107
108
  const { createRequire } = await import('module');
108
109
  /** @suppress{duplicate} */
109
- var require$1 = createRequire((typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('libultrahdr.umd.js', document.baseURI).href)));
110
+ var require$1 = createRequire((typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.src || new URL('libultrahdr.umd.js', document.baseURI).href)));
110
111
  // These modules will usually be used on Node.js. Load them eagerly to avoid
111
112
  // the complexity of lazy-loading.
112
113
  var fs = require$1('fs');
@@ -118,7 +119,7 @@
118
119
  // EXPORT_ES6 + ENVIRONMENT_IS_NODE always requires use of import.meta.url,
119
120
  // since there's no way getting the current absolute path of the module when
120
121
  // support for that is not available.
121
- scriptDirectory = require$1('url').fileURLToPath(new URL('./', (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('libultrahdr.umd.js', document.baseURI).href)))); // includes trailing slash
122
+ scriptDirectory = require$1('url').fileURLToPath(new URL('./', (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.src || new URL('libultrahdr.umd.js', document.baseURI).href)))); // includes trailing slash
122
123
  }
123
124
 
124
125
  // include: node_shell_read.js
@@ -712,7 +713,7 @@
712
713
  }
713
714
  } else {
714
715
  // Use bundler-friendly `new URL(..., import.meta.url)` pattern; works in browsers too.
715
- wasmBinaryFile = new URL('libultrahdr-esm.wasm', (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('libultrahdr.umd.js', document.baseURI).href))).href;
716
+ wasmBinaryFile = new URL('libultrahdr-esm.wasm', (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.src || new URL('libultrahdr.umd.js', document.baseURI).href))).href;
716
717
  }
717
718
 
718
719
  function getBinarySync(file) {
@@ -6698,459 +6699,8 @@
6698
6699
  return lib.appendGainMap(encodingResult.sdr.width, encodingResult.sdr.height, encodingResult.sdr.data, encodingResult.sdr.data.length, encodingResult.gainMap.data, encodingResult.gainMap.data.length, encodingResult.gainMapMax.reduce((p, n) => p + n, 0) / encodingResult.gainMapMax.length, encodingResult.gainMapMin.reduce((p, n) => p + n, 0) / encodingResult.gainMapMin.length, encodingResult.gamma.reduce((p, n) => p + n, 0) / encodingResult.gamma.length, encodingResult.offsetSdr.reduce((p, n) => p + n, 0) / encodingResult.offsetSdr.length, encodingResult.offsetHdr.reduce((p, n) => p + n, 0) / encodingResult.offsetHdr.length, encodingResult.hdrCapacityMin, encodingResult.hdrCapacityMax);
6699
6700
  };
6700
6701
 
6701
- const vertexShader = /* glsl */ `
6702
- varying vec2 vUv;
6703
-
6704
- void main() {
6705
- vUv = uv;
6706
- gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
6707
- }
6708
- `;
6709
- const fragmentShader = /* glsl */ `
6710
- uniform sampler2D sdr;
6711
- uniform sampler2D gainMap;
6712
- uniform vec3 gamma;
6713
- uniform vec3 offsetHdr;
6714
- uniform vec3 offsetSdr;
6715
- uniform vec3 gainMapMin;
6716
- uniform vec3 gainMapMax;
6717
- uniform float weightFactor;
6718
-
6719
- varying vec2 vUv;
6720
-
6721
- void main() {
6722
- vec3 rgb = texture2D(sdr, vUv).rgb;
6723
- vec3 recovery = texture2D(gainMap, vUv).rgb;
6724
- vec3 logRecovery = pow(recovery, gamma);
6725
- vec3 logBoost = gainMapMin * (1.0 - logRecovery) + gainMapMax * logRecovery;
6726
- vec3 hdrColor = (rgb + offsetSdr) * exp2(logBoost * weightFactor) - offsetHdr;
6727
- gl_FragColor = vec4(hdrColor, 1.0);
6728
- }
6729
- `;
6730
- /**
6731
- * A Material which is able to decode the Gainmap into a full HDR Representation
6732
- *
6733
- * @category Materials
6734
- * @group Materials
6735
- */
6736
- class GainMapDecoderMaterial extends three.ShaderMaterial {
6737
- /**
6738
- *
6739
- * @param params
6740
- */
6741
- constructor({ gamma, offsetHdr, offsetSdr, gainMapMin, gainMapMax, maxDisplayBoost, hdrCapacityMin, hdrCapacityMax, sdr, gainMap }) {
6742
- super({
6743
- name: 'GainMapDecoderMaterial',
6744
- vertexShader,
6745
- fragmentShader,
6746
- uniforms: {
6747
- sdr: { value: sdr },
6748
- gainMap: { value: gainMap },
6749
- gamma: { value: new three.Vector3(1.0 / gamma[0], 1.0 / gamma[1], 1.0 / gamma[2]) },
6750
- offsetHdr: { value: new three.Vector3().fromArray(offsetHdr) },
6751
- offsetSdr: { value: new three.Vector3().fromArray(offsetSdr) },
6752
- gainMapMin: { value: new three.Vector3().fromArray(gainMapMin) },
6753
- gainMapMax: { value: new three.Vector3().fromArray(gainMapMax) },
6754
- weightFactor: {
6755
- value: (Math.log2(maxDisplayBoost) - hdrCapacityMin) / (hdrCapacityMax - hdrCapacityMin)
6756
- }
6757
- },
6758
- blending: three.NoBlending,
6759
- depthTest: false,
6760
- depthWrite: false
6761
- });
6762
- this._maxDisplayBoost = maxDisplayBoost;
6763
- this._hdrCapacityMin = hdrCapacityMin;
6764
- this._hdrCapacityMax = hdrCapacityMax;
6765
- this.needsUpdate = true;
6766
- this.uniformsNeedUpdate = true;
6767
- }
6768
- get sdr() { return this.uniforms.sdr.value; }
6769
- set sdr(value) { this.uniforms.sdr.value = value; }
6770
- get gainMap() { return this.uniforms.gainMap.value; }
6771
- set gainMap(value) { this.uniforms.gainMap.value = value; }
6772
- /**
6773
- * @see {@link GainMapMetadata.offsetHdr}
6774
- */
6775
- get offsetHdr() { return this.uniforms.offsetHdr.value.toArray(); }
6776
- set offsetHdr(value) { this.uniforms.offsetHdr.value.fromArray(value); }
6777
- /**
6778
- * @see {@link GainMapMetadata.offsetSdr}
6779
- */
6780
- get offsetSdr() { return this.uniforms.offsetSdr.value.toArray(); }
6781
- set offsetSdr(value) { this.uniforms.offsetSdr.value.fromArray(value); }
6782
- /**
6783
- * @see {@link GainMapMetadata.gainMapMin}
6784
- */
6785
- get gainMapMin() { return this.uniforms.gainMapMin.value.toArray(); }
6786
- set gainMapMin(value) { this.uniforms.gainMapMin.value.fromArray(value); }
6787
- /**
6788
- * @see {@link GainMapMetadata.gainMapMax}
6789
- */
6790
- get gainMapMax() { return this.uniforms.gainMapMax.value.toArray(); }
6791
- set gainMapMax(value) { this.uniforms.gainMapMax.value.fromArray(value); }
6792
- /**
6793
- * @see {@link GainmapEncodingParameters.gamma}
6794
- */
6795
- get gamma() {
6796
- const g = this.uniforms.gamma.value;
6797
- return [1 / g.x, 1 / g.y, 1 / g.z];
6798
- }
6799
- set gamma(value) {
6800
- const g = this.uniforms.gamma.value;
6801
- g.x = 1.0 / value[0];
6802
- g.y = 1.0 / value[1];
6803
- g.z = 1.0 / value[2];
6804
- }
6805
- /**
6806
- * @see {@link GainMapMetadata.hdrCapacityMin}
6807
- * @remarks Logarithmic space
6808
- */
6809
- get hdrCapacityMin() { return this._hdrCapacityMin; }
6810
- set hdrCapacityMin(value) {
6811
- this._hdrCapacityMin = value;
6812
- this.calculateWeight();
6813
- }
6814
- /**
6815
- * @see {@link GainMapMetadata.hdrCapacityMin}
6816
- * @remarks Logarithmic space
6817
- */
6818
- get hdrCapacityMax() { return this._hdrCapacityMax; }
6819
- set hdrCapacityMax(value) {
6820
- this._hdrCapacityMax = value;
6821
- this.calculateWeight();
6822
- }
6823
- /**
6824
- * @see {@link GainmapDecodingParameters.maxDisplayBoost}
6825
- * @remarks Non Logarithmic space
6826
- */
6827
- get maxDisplayBoost() { return this._maxDisplayBoost; }
6828
- set maxDisplayBoost(value) {
6829
- this._maxDisplayBoost = value;
6830
- this.calculateWeight();
6831
- }
6832
- calculateWeight() {
6833
- this.uniforms.weightFactor.value = (Math.log2(this._maxDisplayBoost) - this._hdrCapacityMin) / (this._hdrCapacityMax - this._hdrCapacityMin);
6834
- }
6835
- }
6836
-
6837
- /**
6838
- * Utility structure used for rendering a texture with a material
6839
- *
6840
- * @category General
6841
- * @group General
6842
- */
6843
- class QuadRenderer {
6844
- /**
6845
- *
6846
- * @param sourceTexture
6847
- * @param renderer
6848
- */
6849
- constructor(width, height, type, colorSpace, material, renderer) {
6850
- this._rendererIsDisposable = false;
6851
- /**
6852
- * Renders the input texture using the specified material
6853
- */
6854
- this.render = () => {
6855
- this._renderer.setRenderTarget(this._renderTarget);
6856
- try {
6857
- this._renderer.render(this._scene, this._camera);
6858
- }
6859
- catch (e) {
6860
- this._renderer.setRenderTarget(null);
6861
- throw e;
6862
- }
6863
- this._renderer.setRenderTarget(null);
6864
- };
6865
- this._width = width;
6866
- this._height = height;
6867
- this._type = type;
6868
- this._colorSpace = colorSpace;
6869
- if (type === three.HalfFloatType && navigator.userAgent.toLowerCase().includes('firefox')) {
6870
- this._type = three.FloatType;
6871
- }
6872
- this._material = material;
6873
- if (renderer) {
6874
- this._renderer = renderer;
6875
- }
6876
- else {
6877
- this._renderer = QuadRenderer.instantiateRenderer();
6878
- this._rendererIsDisposable = true;
6879
- }
6880
- this._scene = new three.Scene();
6881
- this._camera = new three.OrthographicCamera();
6882
- this._camera.position.set(0, 0, 10);
6883
- this._camera.left = -0.5;
6884
- this._camera.right = 0.5;
6885
- this._camera.top = 0.5;
6886
- this._camera.bottom = -0.5;
6887
- this._camera.updateProjectionMatrix();
6888
- this._quad = new three.Mesh(new three.PlaneGeometry(), this._material);
6889
- this._quad.geometry.computeBoundingBox();
6890
- this._scene.add(this._quad);
6891
- this._renderTarget = new three.WebGLRenderTarget(width, height, {
6892
- type: this._type,
6893
- colorSpace,
6894
- format: three.RGBAFormat,
6895
- magFilter: three.LinearFilter,
6896
- minFilter: three.LinearMipMapLinearFilter,
6897
- wrapS: three.RepeatWrapping,
6898
- wrapT: three.RepeatWrapping,
6899
- depthBuffer: false,
6900
- stencilBuffer: false,
6901
- generateMipmaps: true
6902
- });
6903
- }
6904
- /**
6905
- * Instantiates a temporary renderer
6906
- *
6907
- * @returns
6908
- */
6909
- static instantiateRenderer() {
6910
- const renderer = new three.WebGLRenderer();
6911
- renderer.setSize(128, 128);
6912
- // renderer.outputColorSpace = SRGBColorSpace
6913
- // renderer.toneMapping = LinearToneMapping
6914
- // renderer.debug.checkShaderErrors = false
6915
- // this._rendererIsDisposable = true
6916
- return renderer;
6917
- }
6918
- /**
6919
- * Obtains a Buffer containing the rendered texture.
6920
- *
6921
- * @returns
6922
- */
6923
- toArray() {
6924
- let out;
6925
- switch (this._type) {
6926
- case three.UnsignedByteType:
6927
- out = new Uint8ClampedArray(this._width * this._height * 4);
6928
- break;
6929
- case three.HalfFloatType:
6930
- out = new Uint16Array(this._width * this._height * 4);
6931
- break;
6932
- case three.UnsignedIntType:
6933
- out = new Uint32Array(this._width * this._height * 4);
6934
- break;
6935
- case three.ByteType:
6936
- out = new Int8Array(this._width * this._height * 4);
6937
- break;
6938
- case three.ShortType:
6939
- out = new Int16Array(this._width * this._height * 4);
6940
- break;
6941
- case three.IntType:
6942
- out = new Int32Array(this._width * this._height * 4);
6943
- break;
6944
- case three.FloatType:
6945
- out = new Float32Array(this._width * this._height * 4);
6946
- break;
6947
- default:
6948
- throw new Error('Unsupported data type');
6949
- }
6950
- this._renderer.readRenderTargetPixels(this._renderTarget, 0, 0, this._width, this._height, out);
6951
- return out;
6952
- }
6953
- toDataTexture() {
6954
- 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);
6955
- }
6956
- /**
6957
- * If using a disposable renderer, it will dispose it.
6958
- */
6959
- dispose() {
6960
- this._renderer.setRenderTarget(null);
6961
- if (this._rendererIsDisposable) {
6962
- this._renderer.dispose();
6963
- this._renderer.forceContextLoss();
6964
- }
6965
- }
6966
- /**
6967
- * Width of the texture
6968
- */
6969
- get width() { return this._width; }
6970
- set width(value) {
6971
- this._width = value;
6972
- this._renderTarget.setSize(this._width, this._height);
6973
- }
6974
- /**
6975
- * Height of the texture
6976
- */
6977
- get height() { return this._height; }
6978
- set height(value) {
6979
- this._height = value;
6980
- this._renderTarget.setSize(this._width, this._height);
6981
- }
6982
- /**
6983
- * The renderer used
6984
- */
6985
- get renderer() { return this._renderer; }
6986
- /**
6987
- * The `WebGLRenderTarget` used.
6988
- */
6989
- get renderTarget() { return this._renderTarget; }
6990
- set renderTarget(value) {
6991
- this._renderTarget = value;
6992
- this._width = value.width;
6993
- this._height = value.height;
6994
- // this._type = value.texture.type
6995
- }
6996
- /**
6997
- * The `Material` used.
6998
- */
6999
- get material() { return this._material; }
7000
- /**
7001
- *
7002
- */
7003
- get type() { return this._type; }
7004
- get colorSpace() { return this._colorSpace; }
7005
- }
7006
-
7007
- class LoaderBase extends three.Loader {
7008
- /**
7009
- *
7010
- * @param renderer
7011
- * @param manager
7012
- */
7013
- constructor(renderer, manager) {
7014
- super(manager);
7015
- this.renderer = renderer;
7016
- }
7017
- /**
7018
- * @private
7019
- * @returns
7020
- */
7021
- prepareQuadRenderer() {
7022
- // temporary values
7023
- const material = new GainMapDecoderMaterial({
7024
- gainMapMax: [1, 1, 1],
7025
- gainMapMin: [0, 0, 0],
7026
- gamma: [1, 1, 1],
7027
- offsetHdr: [1, 1, 1],
7028
- offsetSdr: [1, 1, 1],
7029
- hdrCapacityMax: 1,
7030
- hdrCapacityMin: 0,
7031
- maxDisplayBoost: 1,
7032
- gainMap: new three.Texture(),
7033
- sdr: new three.Texture()
7034
- });
7035
- return new QuadRenderer(16, 16, three.HalfFloatType, three.NoColorSpace, material, this.renderer);
7036
- }
7037
- /**
7038
- *
7039
- * @private
7040
- * @param quadRenderer
7041
- * @param gainMapBuffer
7042
- * @param sdrBuffer
7043
- * @param metadata
7044
- */
7045
- async render(quadRenderer, gainMapBuffer, sdrBuffer, metadata) {
7046
- const gainMapBlob = new Blob([gainMapBuffer], { type: 'image/jpeg' });
7047
- // TODO: figure out why result.sdr is not usable here, problem is in the libultrahdr-wasm repo
7048
- // we use the original image buffer instead
7049
- const sdrBlob = new Blob([sdrBuffer], { type: 'image/jpeg' });
7050
- const [gainMapImageBitmap, sdrImageBitmap] = await Promise.all([
7051
- createImageBitmap(gainMapBlob, { imageOrientation: 'flipY' }),
7052
- createImageBitmap(sdrBlob, { imageOrientation: 'flipY' })
7053
- ]);
7054
- const gainMap = new three.Texture(gainMapImageBitmap, three.UVMapping, three.ClampToEdgeWrapping, three.ClampToEdgeWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, three.RGBAFormat, three.UnsignedByteType, 1, three.NoColorSpace);
7055
- gainMap.needsUpdate = true;
7056
- const sdr = new three.Texture(sdrImageBitmap, three.UVMapping, three.ClampToEdgeWrapping, three.ClampToEdgeWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, three.RGBAFormat, three.UnsignedByteType, 1, three.SRGBColorSpace);
7057
- sdr.needsUpdate = true;
7058
- quadRenderer.width = sdrImageBitmap.width;
7059
- quadRenderer.height = sdrImageBitmap.height;
7060
- quadRenderer.material.gainMap = gainMap;
7061
- quadRenderer.material.sdr = sdr;
7062
- quadRenderer.material.gainMapMin = metadata.gainMapMin;
7063
- quadRenderer.material.gainMapMax = metadata.gainMapMax;
7064
- quadRenderer.material.offsetHdr = metadata.offsetHdr;
7065
- quadRenderer.material.offsetSdr = metadata.offsetSdr;
7066
- quadRenderer.material.gamma = metadata.gamma;
7067
- quadRenderer.material.hdrCapacityMin = metadata.hdrCapacityMin;
7068
- quadRenderer.material.hdrCapacityMax = metadata.hdrCapacityMax;
7069
- quadRenderer.material.maxDisplayBoost = Math.pow(2, metadata.hdrCapacityMax);
7070
- quadRenderer.material.needsUpdate = true;
7071
- quadRenderer.render();
7072
- }
7073
- }
7074
-
7075
- /**
7076
- * A Three.js Loader for a JPEG with embedded gainmap metadata.
7077
- *
7078
- * @category Loaders
7079
- * @group Loaders
7080
- *
7081
- * @example
7082
- * import { JPEGRLoader } from '@monogrid/gainmap-js/libultrahdr'
7083
- * import {
7084
- * EquirectangularReflectionMapping,
7085
- * LinearFilter,
7086
- * Mesh,
7087
- * MeshBasicMaterial,
7088
- * PerspectiveCamera,
7089
- * PlaneGeometry,
7090
- * Scene,
7091
- * WebGLRenderer
7092
- * } from 'three'
7093
- *
7094
- * const renderer = new WebGLRenderer()
7095
- *
7096
- * const loader = new JPEGRLoader(renderer)
7097
- *
7098
- * const result = loader.load('gainmap.jpeg')
7099
- * // `result` can be used to populate a Texture
7100
- *
7101
- * const scene = new Scene()
7102
- * const mesh = new Mesh(
7103
- * new PlaneGeometry(),
7104
- * new MeshBasicMaterial({ map: result.renderTarget.texture })
7105
- * )
7106
- * scene.add(mesh)
7107
- * renderer.render(scene, new PerspectiveCamera())
7108
- *
7109
- * // `result.renderTarget.texture` must be
7110
- * // converted to `DataTexture` in order
7111
- * // to use it as Equirectangular scene background
7112
- * // if needed
7113
- *
7114
- * scene.background = result.toDataTexture()
7115
- * scene.background.mapping = EquirectangularReflectionMapping
7116
- * scene.background.minFilter = LinearFilter
7117
-
7118
- *
7119
- */
7120
- class JPEGRLoader extends LoaderBase {
7121
- /**
7122
- *
7123
- * @param url
7124
- * @param onLoad
7125
- * @param onProgress
7126
- * @param onError
7127
- * @returns
7128
- */
7129
- load(url, onLoad, onProgress, onError) {
7130
- const quadRenderer = this.prepareQuadRenderer();
7131
- const loader = new three.FileLoader(this.manager);
7132
- loader.setResponseType('arraybuffer');
7133
- loader.setRequestHeader(this.requestHeader);
7134
- loader.setPath(this.path);
7135
- loader.setWithCredentials(this.withCredentials);
7136
- loader.load(url, async (jpeg) => {
7137
- if (typeof jpeg === 'string')
7138
- throw new Error('Invalid buffer');
7139
- const { gainMap: gainMapJPEG, parsedMetadata } = await decodeJPEGMetadata(new Uint8Array(jpeg));
7140
- await this.render(quadRenderer, gainMapJPEG, jpeg, parsedMetadata);
7141
- if (typeof onLoad === 'function')
7142
- onLoad(quadRenderer);
7143
- quadRenderer.dispose();
7144
- }, onProgress, onError);
7145
- return quadRenderer;
7146
- }
7147
- }
7148
-
7149
- exports.JPEGRLoader = JPEGRLoader;
7150
6702
  exports.decodeJPEGMetadata = decodeJPEGMetadata;
7151
6703
  exports.encodeJPEGMetadata = encodeJPEGMetadata;
7152
6704
  exports.getLibrary = getLibrary;
7153
6705
 
7154
- Object.defineProperty(exports, '__esModule', { value: true });
7155
-
7156
6706
  }));
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @monogrid/gainmap-js v1.1.0
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-1789f0cf.js';
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;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v1.1.0
2
+ * @monogrid/gainmap-js v2.0.0
3
3
  * With ❤️, by MONOGRID <hello@mono-grid.com>
4
4
  */
5
5
 
@@ -511,6 +511,4 @@
511
511
  exports.getPromiseWorker = getPromiseWorker;
512
512
  exports.getWorkerInterface = getWorkerInterface;
513
513
 
514
- Object.defineProperty(exports, '__esModule', { value: true });
515
-
516
514
  }));
@@ -1,4 +1,4 @@
1
- import { CompressedImage, type CompressParameters } from './types';
1
+ import { CompressedImage, type CompressParameters } from './encode/types';
2
2
  export type WorkerInterface = {
3
3
  compress: {
4
4
  request: {
package/dist/worker.js CHANGED
@@ -1,10 +1,10 @@
1
1
  /**
2
- * @monogrid/gainmap-js v1.1.0
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-1789f0cf.js';
7
- import { c as compress } from './compress-a4b59cab.js';
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