@monogrid/gainmap-js 3.7.3 → 3.7.4

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 (94) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/{GainMapNode-DW8LUMdP.js → GainMapNode-BRDowRvr.js} +1 -1
  3. package/dist/{GainMapNode-BIE27hYG.js → GainMapNode-Bx9ovuy4.js} +1 -1
  4. package/dist/{Loader-DaVmW-sG.js → Loader-BSL15qlg.js} +2 -2
  5. package/dist/{Loader-MfNS_T9s.js → Loader-x_zXVpld.js} +2 -2
  6. package/dist/{QuadRenderer-C99kwfFS.js → QuadRenderer-CFNq6PES.js} +1 -1
  7. package/dist/{QuadRenderer-CM7qiSAI.js → QuadRenderer-LMuyeRzQ.js} +1 -1
  8. package/dist/{_commonjsHelpers-DIhdSoQr.js → _commonjsHelpers-DRi_W9o1.js} +1 -1
  9. package/dist/{_commonjsHelpers-oyWUzYEt.js → _commonjsHelpers-ipRjx41i.js} +1 -1
  10. package/dist/{compress-CSavQQ88.js → compress-DBf4K0k_.js} +1 -1
  11. package/dist/{compress-ChfVEpLY.js → compress-DhuzUwR5.js} +1 -1
  12. package/dist/core/QuadRenderer.d.ts +1 -1
  13. package/dist/core/index.d.ts +3 -3
  14. package/dist/core/iso-gainmap-metadata.d.ts +1 -1
  15. package/dist/decode/index.d.ts +1 -1
  16. package/dist/decode/shared/Loader.d.ts +2 -2
  17. package/dist/decode/shared/decode.d.ts +2 -2
  18. package/dist/decode/shared/extract.d.ts +1 -1
  19. package/dist/decode/shared/index.d.ts +10 -10
  20. package/dist/decode/shared/types.d.ts +1 -1
  21. package/dist/decode/shared/utils/extractISO.d.ts +1 -1
  22. package/dist/decode/shared/utils/extractXMP.d.ts +1 -1
  23. package/dist/decode/webgl/decode.d.ts +3 -3
  24. package/dist/decode/webgl/index.d.ts +8 -8
  25. package/dist/decode/webgl/loaders/GainMapLoader.d.ts +3 -3
  26. package/dist/decode/webgl/loaders/HDRJPGLoader.d.ts +3 -3
  27. package/dist/decode/webgl/loaders/LoaderBaseWebGL.d.ts +4 -4
  28. package/dist/decode/webgl/materials/GainMapDecoderMaterial.d.ts +2 -2
  29. package/dist/decode/webgpu/core/QuadRenderer.d.ts +1 -1
  30. package/dist/decode/webgpu/decode.d.ts +3 -3
  31. package/dist/decode/webgpu/index.d.ts +12 -12
  32. package/dist/decode/webgpu/loaders/GainMapLoader.d.ts +3 -3
  33. package/dist/decode/webgpu/loaders/GainMapNodeLoader.d.ts +2 -2
  34. package/dist/decode/webgpu/loaders/HDRJPGLoader.d.ts +3 -3
  35. package/dist/decode/webgpu/loaders/HDRJPGNodeLoader.d.ts +2 -2
  36. package/dist/decode/webgpu/loaders/LoaderBaseNode.d.ts +2 -2
  37. package/dist/decode/webgpu/loaders/LoaderBaseWebGPU.d.ts +4 -4
  38. package/dist/decode/webgpu/materials/GainMapDecoderMaterial.d.ts +2 -2
  39. package/dist/decode/webgpu/nodes/GainMapNode.d.ts +4 -4
  40. package/dist/decode.d.ts +1 -1
  41. package/dist/decode.js +5 -5
  42. package/dist/decode.min.js +2 -2
  43. package/dist/decode.umd.cjs +1 -1
  44. package/dist/decode.umd.min.cjs +1 -1
  45. package/dist/decode.webgpu.js +6 -6
  46. package/dist/decode.webgpu.min.js +2 -2
  47. package/dist/decode.webgpu.umd.cjs +1 -1
  48. package/dist/decode.webgpu.umd.min.cjs +1 -1
  49. package/dist/encode/compress.d.ts +1 -1
  50. package/dist/encode/encode-and-compress.d.ts +3 -3
  51. package/dist/encode/encode.d.ts +5 -5
  52. package/dist/encode/get-gainmap.d.ts +3 -3
  53. package/dist/encode/get-sdr-rendition.d.ts +3 -3
  54. package/dist/encode/index.d.ts +10 -10
  55. package/dist/encode/materials/GainMapEncoderMaterial.d.ts +1 -1
  56. package/dist/encode/types.d.ts +2 -2
  57. package/dist/encode/webgpu/GainMapEncoder.d.ts +6 -6
  58. package/dist/encode/webgpu/find-texture-min-max.d.ts +1 -1
  59. package/dist/encode/webgpu/index.d.ts +8 -8
  60. package/dist/encode/webgpu/nodes/GainMapEncoderNode.d.ts +4 -4
  61. package/dist/encode/webgpu/nodes/SDRRenditionNode.d.ts +1 -1
  62. package/dist/encode/webgpu/read-render-target-pixels.d.ts +1 -1
  63. package/dist/encode.d.ts +1 -1
  64. package/dist/encode.js +4 -4
  65. package/dist/encode.min.js +2 -2
  66. package/dist/encode.umd.cjs +1 -1
  67. package/dist/encode.umd.min.cjs +1 -1
  68. package/dist/encode.webgpu.js +4 -4
  69. package/dist/encode.webgpu.min.js +2 -2
  70. package/dist/encode.webgpu.umd.cjs +1 -1
  71. package/dist/encode.webgpu.umd.min.cjs +1 -1
  72. package/dist/{get-data-texture-CtrXqvaR.js → get-data-texture-CmfjzIHL.js} +1 -1
  73. package/dist/{get-data-texture-GGd_q2_x.js → get-data-texture-RdAaN_eI.js} +1 -1
  74. package/dist/{iso-gainmap-metadata-CwcJfksX.js → iso-gainmap-metadata-B_FgeS_d.js} +1 -1
  75. package/dist/{iso-gainmap-metadata-BnRsn_xQ.js → iso-gainmap-metadata-bR9G0ypA.js} +1 -1
  76. package/dist/libultrahdr/encode-jpeg-metadata.d.ts +2 -2
  77. package/dist/libultrahdr/jpeg-assembler.d.ts +2 -2
  78. package/dist/libultrahdr/xmp-generator.d.ts +1 -1
  79. package/dist/libultrahdr.d.ts +1 -1
  80. package/dist/libultrahdr.js +2 -2
  81. package/dist/libultrahdr.min.js +2 -2
  82. package/dist/libultrahdr.umd.cjs +1 -1
  83. package/dist/libultrahdr.umd.min.cjs +1 -1
  84. package/dist/worker-interface.d.ts +2 -2
  85. package/dist/worker-interface.js +2 -2
  86. package/dist/worker-interface.min.js +2 -2
  87. package/dist/worker-interface.umd.cjs +1 -1
  88. package/dist/worker-interface.umd.min.cjs +1 -1
  89. package/dist/worker-types.d.ts +1 -1
  90. package/dist/worker.js +3 -3
  91. package/dist/worker.min.js +2 -2
  92. package/dist/worker.umd.cjs +1 -1
  93. package/dist/worker.umd.min.cjs +1 -1
  94. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.7.3
2
+ * @monogrid/gainmap-js v3.7.4
3
3
  * With ❤️, by MONOGRID <gainmap@monogrid.com>
4
4
  */
5
5
  !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("three")):"function"==typeof define&&define.amd?define(["exports","three"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).encode={},e.three)}(this,function(e,t){"use strict";const n=async e=>{if("undefined"==typeof createImageBitmap)throw new Error("createImageBitmap() not supported.");const{source:t,mimeType:n,quality:r,flipY:a}=e;let o;if((t instanceof Uint8Array||t instanceof Uint8ClampedArray)&&"sourceMimeType"in e)o=new Blob([t],{type:e.sourceMimeType});else{if(!(t instanceof ImageData))throw new Error("Invalid source image");o=t}const i=await createImageBitmap(o),s=i.width,p=i.height;let l;"undefined"!=typeof OffscreenCanvas?l=new OffscreenCanvas(s,p):(l=document.createElement("canvas"),l.width=s,l.height=p);const c=l.getContext("2d");if(!c)throw new Error("Failed to create canvas Context");!0===a&&(c.translate(0,p),c.scale(1,-1)),c.drawImage(i,0,0,s,p);const d=await(async(e,t,n)=>{if("undefined"!=typeof OffscreenCanvas&&e instanceof OffscreenCanvas)return e.convertToBlob({type:t,quality:n});if(e instanceof HTMLCanvasElement)return new Promise((r,a)=>{e.toBlob(e=>{e?r(e):a(new Error("Failed to convert canvas to blob"))},t,n)});throw new Error("Unsupported canvas element")})(l,n,r||.9);return{data:new Uint8Array(await d.arrayBuffer()),mimeType:n,width:s,height:p}},r=e=>{let n;if(e instanceof t.DataTexture){if(!(e.image.data instanceof Uint16Array||e.image.data instanceof Float32Array))throw new Error("Provided image is not HDR");n=e}else{if(!e.data||!e.width||!e.height)throw new Error("Provided image has no data or size");n=new t.DataTexture(e.data,e.width,e.height,e.format??t.RGBAFormat,e.type,t.UVMapping,t.RepeatWrapping,t.RepeatWrapping,t.LinearFilter,t.LinearFilter,1,"colorSpace"in e&&"srgb"===e.colorSpace?e.colorSpace:t.LinearSRGBColorSpace),"header"in e&&"gamma"in e&&(n.flipY=!0),n.needsUpdate=!0}return n},a=(e,n,r)=>{let a;switch(e){case t.UnsignedByteType:a=new Uint8ClampedArray(n*r*4);break;case t.HalfFloatType:a=new Uint16Array(n*r*4);break;case t.UnsignedIntType:a=new Uint32Array(n*r*4);break;case t.ByteType:a=new Int8Array(n*r*4);break;case t.ShortType:a=new Int16Array(n*r*4);break;case t.IntType:a=new Int32Array(n*r*4);break;case t.FloatType:a=new Float32Array(n*r*4);break;default:throw new Error("Unsupported data type")}return a};let o;class i{_renderer;_rendererIsDisposable=!1;_material;_scene;_camera;_quad;_renderTarget;_width;_height;_type;_colorSpace;_supportsReadPixels=!0;constructor(e){this._width=e.width,this._height=e.height,this._type=e.type,this._colorSpace=e.colorSpace;const n={format:t.RGBAFormat,depthBuffer:!1,stencilBuffer:!1,type:this._type,colorSpace:this._colorSpace,anisotropy:void 0!==e.renderTargetOptions?.anisotropy?e.renderTargetOptions?.anisotropy:1,generateMipmaps:void 0!==e.renderTargetOptions?.generateMipmaps&&e.renderTargetOptions?.generateMipmaps,magFilter:void 0!==e.renderTargetOptions?.magFilter?e.renderTargetOptions?.magFilter:t.LinearFilter,minFilter:void 0!==e.renderTargetOptions?.minFilter?e.renderTargetOptions?.minFilter:t.LinearFilter,samples:void 0!==e.renderTargetOptions?.samples?e.renderTargetOptions?.samples:void 0,wrapS:void 0!==e.renderTargetOptions?.wrapS?e.renderTargetOptions?.wrapS:t.ClampToEdgeWrapping,wrapT:void 0!==e.renderTargetOptions?.wrapT?e.renderTargetOptions?.wrapT:t.ClampToEdgeWrapping};if(this._material=e.material,e.renderer?this._renderer=e.renderer:(this._renderer=i.instantiateRenderer(),this._rendererIsDisposable=!0),this._scene=new t.Scene,this._camera=new t.OrthographicCamera,this._camera.position.set(0,0,10),this._camera.left=-.5,this._camera.right=.5,this._camera.top=.5,this._camera.bottom=-.5,this._camera.updateProjectionMatrix(),!((e,n,r,i)=>{if(void 0!==o)return o;const s=new t.WebGLRenderTarget(1,1,i);n.setRenderTarget(s);const p=new t.Mesh(new t.PlaneGeometry,new t.MeshBasicMaterial({color:16777215}));n.render(p,r),n.setRenderTarget(null);const l=a(e,s.width,s.height);return n.readRenderTargetPixels(s,0,0,s.width,s.height,l),s.dispose(),p.geometry.dispose(),p.material.dispose(),o=0!==l[0],o})(this._type,this._renderer,this._camera,n)){let e;if(this._type===t.HalfFloatType)e=this._renderer.extensions.has("EXT_color_buffer_float")?t.FloatType:void 0;void 0!==e?(console.warn(`This browser does not support reading pixels from ${this._type} RenderTargets, switching to ${t.FloatType}`),this._type=e):(this._supportsReadPixels=!1,console.warn("This browser dos not support toArray or toDataTexture, calls to those methods will result in an error thrown"))}this._quad=new t.Mesh(new t.PlaneGeometry,this._material),this._quad.geometry.computeBoundingBox(),this._scene.add(this._quad),this._renderTarget=new t.WebGLRenderTarget(this.width,this.height,n),this._renderTarget.texture.mapping=void 0!==e.renderTargetOptions?.mapping?e.renderTargetOptions?.mapping:t.UVMapping}static instantiateRenderer(){const e=new t.WebGLRenderer;return e.setSize(128,128),e}render=()=>{this._renderer.setRenderTarget(this._renderTarget);try{this._renderer.render(this._scene,this._camera)}catch(e){throw this._renderer.setRenderTarget(null),e}this._renderer.setRenderTarget(null)};toArray(){if(!this._supportsReadPixels)throw new Error("Can't read pixels in this browser");const e=a(this._type,this._width,this._height);return this._renderer.readRenderTargetPixels(this._renderTarget,0,0,this._width,this._height,e),e}toDataTexture(e){const n=new t.DataTexture(this.toArray(),this.width,this.height,t.RGBAFormat,this._type,e?.mapping||t.UVMapping,e?.wrapS||t.ClampToEdgeWrapping,e?.wrapT||t.ClampToEdgeWrapping,e?.magFilter||t.LinearFilter,e?.minFilter||t.LinearFilter,e?.anisotropy||1,t.LinearSRGBColorSpace);return n.generateMipmaps=void 0!==e?.generateMipmaps&&e?.generateMipmaps,n}disposeOnDemandRenderer(){this._renderer.setRenderTarget(null),this._rendererIsDisposable&&(this._renderer.dispose(),this._renderer.forceContextLoss())}dispose(e){this.disposeOnDemandRenderer(),e&&this.renderTarget.dispose(),this.material instanceof t.ShaderMaterial&&Object.values(this.material.uniforms).forEach(e=>{e.value instanceof t.Texture&&e.value.dispose()}),Object.values(this.material).forEach(e=>{e instanceof t.Texture&&e.dispose()}),this.material.dispose(),this._quad.geometry.dispose()}get width(){return this._width}set width(e){this._width=e,this._renderTarget.setSize(this._width,this._height)}get height(){return this._height}set height(e){this._height=e,this._renderTarget.setSize(this._width,this._height)}get renderer(){return this._renderer}get renderTarget(){return this._renderTarget}set renderTarget(e){this._renderTarget=e,this._width=e.width,this._height=e.height}get material(){return this._material}get type(){return this._type}get colorSpace(){return this._colorSpace}}const s=1.0001,p=e=>{console.warn(`gainmap-js: maxContentBoost is ${e} (<= 1), the source image has no HDR content. It will be clamped to 1.0001 and the result will be equivalent to an SDR image.`)},l=(e,t)=>{console.warn(`gainmap-js: minContentBoost (${e}) must be lower than maxContentBoost (${t}), the resulting gain map will be invalid.`)};class c extends t.ShaderMaterial{_minContentBoost;_maxContentBoost;_offsetSdr;_offsetHdr;_gamma;constructor({sdr:e,hdr:n,offsetSdr:r,offsetHdr:a,maxContentBoost:o,minContentBoost:i,gamma:c}){if(!o)throw new Error("maxContentBoost is required");if(!e)throw new Error("sdr is required");if(!n)throw new Error("hdr is required");const d=c||[1,1,1],m=r||[1/64,1/64,1/64],h=a||[1/64,1/64,1/64];o<=1&&p(o);const g=i||1,u=Math.max(o,s);g>=u&&l(g,u),super({name:"GainMapEncoderMaterial",vertexShader:"\nvarying vec2 vUv;\n\nvoid main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}\n",fragmentShader:"\n#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\nuniform sampler2D sdr;\nuniform sampler2D hdr;\nuniform vec3 gamma;\nuniform vec3 offsetSdr;\nuniform vec3 offsetHdr;\nuniform float minLog2;\nuniform float maxLog2;\n\nvarying vec2 vUv;\n\nvoid main() {\n vec3 sdrColor = texture2D(sdr, vUv).rgb;\n vec3 hdrColor = texture2D(hdr, vUv).rgb;\n\n vec3 pixelGain = (hdrColor + offsetHdr) / (sdrColor + offsetSdr);\n vec3 logRecovery = (log2(pixelGain) - minLog2) / (maxLog2 - minLog2);\n vec3 clampedRecovery = saturate(logRecovery);\n gl_FragColor = vec4(pow(clampedRecovery, gamma), 1.0);\n}\n",uniforms:{sdr:{value:e},hdr:{value:n},gamma:{value:(new t.Vector3).fromArray(d)},offsetSdr:{value:(new t.Vector3).fromArray(m)},offsetHdr:{value:(new t.Vector3).fromArray(h)},minLog2:{value:Math.log2(g)},maxLog2:{value:Math.log2(u)}},blending:t.NoBlending,depthTest:!1,depthWrite:!1}),this._minContentBoost=g,this._maxContentBoost=u,this._offsetSdr=m,this._offsetHdr=h,this._gamma=d,this.needsUpdate=!0,this.uniformsNeedUpdate=!0}get gamma(){return this._gamma}set gamma(e){this._gamma=e,this.uniforms.gamma.value=(new t.Vector3).fromArray(e)}get offsetHdr(){return this._offsetHdr}set offsetHdr(e){this._offsetHdr=e,this.uniforms.offsetHdr.value=(new t.Vector3).fromArray(e)}get offsetSdr(){return this._offsetSdr}set offsetSdr(e){this._offsetSdr=e,this.uniforms.offsetSdr.value=(new t.Vector3).fromArray(e)}get minContentBoost(){return this._minContentBoost}set minContentBoost(e){e>=this._maxContentBoost&&l(e,this._maxContentBoost),this._minContentBoost=e,this.uniforms.minLog2.value=Math.log2(e)}get maxContentBoost(){return this._maxContentBoost}set maxContentBoost(e){e<=1&&p(e);const t=Math.max(e,s);this._minContentBoost>=t&&l(this._minContentBoost,t),this._maxContentBoost=t,this.uniforms.maxLog2.value=Math.log2(t)}get gainMapMin(){return[Math.log2(this._minContentBoost),Math.log2(this._minContentBoost),Math.log2(this._minContentBoost)]}get gainMapMax(){return[Math.log2(this._maxContentBoost),Math.log2(this._maxContentBoost),Math.log2(this._maxContentBoost)]}get hdrCapacityMin(){return Math.min(Math.max(0,this.gainMapMin[0]),Math.max(0,this.gainMapMin[1]),Math.max(0,this.gainMapMin[2]))}get hdrCapacityMax(){return Math.max(Math.max(0,this.gainMapMax[0]),Math.max(0,this.gainMapMax[1]),Math.max(0,this.gainMapMax[2]))}}const d=e=>{const{image:n,sdr:a,renderer:o}=e,s=r(n),p=new c({...e,sdr:a.renderTarget.texture,hdr:s}),l=new i({width:s.image.width,height:s.image.height,type:t.UnsignedByteType,colorSpace:t.LinearSRGBColorSpace,material:p,renderer:o,renderTargetOptions:e.renderTargetOptions});try{l.render()}catch(e){throw l.disposeOnDemandRenderer(),e}return l};class m extends t.ShaderMaterial{_brightness=0;_contrast=1;_saturation=1;_exposure=1;_toneMapping;_map;constructor({map:e,toneMapping:n}){super({name:"SDRMaterial",vertexShader:"\nvarying vec2 vUv;\n\nvoid main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}\n",fragmentShader:"\n#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\n\nuniform sampler2D map;\nuniform float brightness;\nuniform float contrast;\nuniform float saturation;\nuniform float exposure;\n\nvarying vec2 vUv;\n\nmat4 brightnessMatrix( float brightness ) {\n return mat4(\n 1, 0, 0, 0,\n 0, 1, 0, 0,\n 0, 0, 1, 0,\n brightness, brightness, brightness, 1\n );\n}\n\nmat4 contrastMatrix( float contrast ) {\n float t = ( 1.0 - contrast ) / 2.0;\n return mat4(\n contrast, 0, 0, 0,\n 0, contrast, 0, 0,\n 0, 0, contrast, 0,\n t, t, t, 1\n );\n}\n\nmat4 saturationMatrix( float saturation ) {\n vec3 luminance = vec3( 0.3086, 0.6094, 0.0820 );\n float oneMinusSat = 1.0 - saturation;\n vec3 red = vec3( luminance.x * oneMinusSat );\n red+= vec3( saturation, 0, 0 );\n vec3 green = vec3( luminance.y * oneMinusSat );\n green += vec3( 0, saturation, 0 );\n vec3 blue = vec3( luminance.z * oneMinusSat );\n blue += vec3( 0, 0, saturation );\n return mat4(\n red, 0,\n green, 0,\n blue, 0,\n 0, 0, 0, 1\n );\n}\n\nvec3 RRTAndODTFit( vec3 v ) {\n vec3 a = v * ( v + 0.0245786 ) - 0.000090537;\n vec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;\n return a / b;\n}\n\nvec3 ACESFilmicToneMapping( vec3 color ) {\n // sRGB => XYZ => D65_2_D60 => AP1 => RRT_SAT\n const mat3 ACESInputMat = mat3(\n vec3( 0.59719, 0.07600, 0.02840 ), // transposed from source\n vec3( 0.35458, 0.90834, 0.13383 ),\n vec3( 0.04823, 0.01566, 0.83777 )\n );\n // ODT_SAT => XYZ => D60_2_D65 => sRGB\n const mat3 ACESOutputMat = mat3(\n vec3( 1.60475, -0.10208, -0.00327 ), // transposed from source\n vec3( -0.53108, 1.10813, -0.07276 ),\n vec3( -0.07367, -0.00605, 1.07602 )\n );\n color = ACESInputMat * color;\n // Apply RRT and ODT\n color = RRTAndODTFit( color );\n color = ACESOutputMat * color;\n // Clamp to [0, 1]\n return saturate( color );\n}\n\n// source: https://www.cs.utah.edu/docs/techreports/2002/pdf/UUCS-02-001.pdf\nvec3 ReinhardToneMapping( vec3 color ) {\n return saturate( color / ( vec3( 1.0 ) + color ) );\n}\n\n// source: http://filmicworlds.com/blog/filmic-tonemapping-operators/\nvec3 CineonToneMapping( vec3 color ) {\n // optimized filmic operator by Jim Hejl and Richard Burgess-Dawson\n color = max( vec3( 0.0 ), color - 0.004 );\n return pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\n\n// nothing\nvec3 LinearToneMapping ( vec3 color ) {\n return color;\n}\n\n// Matrices for rec 2020 <> rec 709 color space conversion\n// matrix provided in row-major order so it has been transposed\n// https://www.itu.int/pub/R-REP-BT.2407-2017\nconst mat3 LINEAR_REC2020_TO_LINEAR_SRGB = mat3(\n vec3( 1.6605, - 0.1246, - 0.0182 ),\n vec3( - 0.5876, 1.1329, - 0.1006 ),\n vec3( - 0.0728, - 0.0083, 1.1187 )\n);\n\nconst mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = mat3(\n vec3( 0.6274, 0.0691, 0.0164 ),\n vec3( 0.3293, 0.9195, 0.0880 ),\n vec3( 0.0433, 0.0113, 0.8956 )\n);\n\n// https://iolite-engine.com/blog_posts/minimal_agx_implementation\n// Mean error^2: 3.6705141e-06\nvec3 agxDefaultContrastApprox( vec3 x ) {\n vec3 x2 = x * x;\n vec3 x4 = x2 * x2;\n return + 15.5 * x4 * x2\n - 40.14 * x4 * x\n + 31.96 * x4\n - 6.868 * x2 * x\n + 0.4298 * x2\n + 0.1191 * x\n - 0.00232;\n}\n\n// AgX Tone Mapping implementation based on Filament, which in turn is based\n// on Blender's implementation using rec 2020 primaries\n// https://github.com/google/filament/pull/7236\n// Inputs and outputs are encoded as Linear-sRGB.\n\nvec3 AgXToneMapping( vec3 color ) {\n\n // AgX constants\n const mat3 AgXInsetMatrix = mat3(\n vec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ),\n vec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ),\n vec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 )\n );\n\n // explicit AgXOutsetMatrix generated from Filaments AgXOutsetMatrixInv\n const mat3 AgXOutsetMatrix = mat3(\n vec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ),\n vec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ),\n vec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 )\n );\n\n // LOG2_MIN = -10.0\n // LOG2_MAX = +6.5\n // MIDDLE_GRAY = 0.18\n const float AgxMinEv = - 12.47393; // log2( pow( 2, LOG2_MIN ) * MIDDLE_GRAY )\n const float AgxMaxEv = 4.026069; // log2( pow( 2, LOG2_MAX ) * MIDDLE_GRAY )\n\n color = LINEAR_SRGB_TO_LINEAR_REC2020 * color;\n\n color = AgXInsetMatrix * color;\n\n // Log2 encoding\n color = max( color, 1e-10 ); // avoid 0 or negative numbers for log2\n color = log2( color );\n color = ( color - AgxMinEv ) / ( AgxMaxEv - AgxMinEv );\n\n color = clamp( color, 0.0, 1.0 );\n\n // Apply sigmoid\n color = agxDefaultContrastApprox( color );\n\n // Apply AgX look\n // v = agxLook(v, look);\n\n color = AgXOutsetMatrix * color;\n\n // Linearize\n color = pow( max( vec3( 0.0 ), color ), vec3( 2.2 ) );\n\n color = LINEAR_REC2020_TO_LINEAR_SRGB * color;\n\n // Gamut mapping. Simple clamp for now.\n color = clamp( color, 0.0, 1.0 );\n\n return color;\n\n}\n\n// https://modelviewer.dev/examples/tone-mapping\n\nvec3 NeutralToneMapping( vec3 color ) {\n\n const float StartCompression = 0.8 - 0.04;\n const float Desaturation = 0.15;\n\n float x = min( color.r, min( color.g, color.b ) );\n\n float offset = x < 0.08 ? x - 6.25 * x * x : 0.04;\n\n color -= offset;\n\n float peak = max( color.r, max( color.g, color.b ) );\n\n if ( peak < StartCompression ) return color;\n\n float d = 1. - StartCompression;\n\n float newPeak = 1. - d * d / ( peak + d - StartCompression );\n\n color *= newPeak / peak;\n\n float g = 1. - 1. / ( Desaturation * ( peak - newPeak ) + 1. );\n\n return mix( color, vec3( newPeak ), g );\n\n}\n\n\n\nvoid main() {\n vec4 color = texture2D(map, vUv);\n\n vec4 exposed = vec4(exposure * color.rgb, color.a);\n\n vec4 tonemapped = vec4(TONEMAPPING_FUNCTION(exposed.rgb), color.a);\n\n vec4 adjusted =\n brightnessMatrix( brightness ) *\n contrastMatrix( contrast ) *\n saturationMatrix( saturation ) *\n tonemapped;\n\n gl_FragColor = adjusted;\n}\n",uniforms:{map:{value:e},brightness:{value:0},contrast:{value:1},saturation:{value:1},exposure:{value:1}},blending:t.NoBlending,depthTest:!1,depthWrite:!1}),this._map=e,this.toneMapping=this._toneMapping=n||t.ACESFilmicToneMapping,this.needsUpdate=!0,this.uniformsNeedUpdate=!0}get toneMapping(){return this._toneMapping}set toneMapping(e){let n=!1;switch(e){case t.ACESFilmicToneMapping:this.defines.TONEMAPPING_FUNCTION="ACESFilmicToneMapping",n=!0;break;case t.ReinhardToneMapping:this.defines.TONEMAPPING_FUNCTION="ReinhardToneMapping",n=!0;break;case t.CineonToneMapping:this.defines.TONEMAPPING_FUNCTION="CineonToneMapping",n=!0;break;case t.LinearToneMapping:this.defines.TONEMAPPING_FUNCTION="LinearToneMapping",n=!0;break;case t.AgXToneMapping:this.defines.TONEMAPPING_FUNCTION="AgXToneMapping",n=!0;break;case t.NeutralToneMapping:this.defines.TONEMAPPING_FUNCTION="NeutralToneMapping",n=!0;break;default:console.error(`Unsupported toneMapping: ${e}. Using LinearToneMapping.`),this.defines.TONEMAPPING_FUNCTION="LinearToneMapping",this._toneMapping=t.LinearToneMapping}n&&(this._toneMapping=e),this.needsUpdate=!0}get brightness(){return this._brightness}set brightness(e){this._brightness=e,this.uniforms.brightness.value=e}get contrast(){return this._contrast}set contrast(e){this._contrast=e,this.uniforms.contrast.value=e}get saturation(){return this._saturation}set saturation(e){this._saturation=e,this.uniforms.saturation.value=e}get exposure(){return this._exposure}set exposure(e){this._exposure=e,this.uniforms.exposure.value=e}get map(){return this._map}set map(e){this._map=e,this.uniforms.map.value=e}}const h=(e,n,r,a)=>{e.needsUpdate=!0;const o=new i({width:e.image.width,height:e.image.height,type:t.UnsignedByteType,colorSpace:t.SRGBColorSpace,material:new m({map:e,toneMapping:r}),renderer:n,renderTargetOptions:a});try{o.render()}catch(e){throw o.disposeOnDemandRenderer(),e}return o},g=e=>{const{image:t,renderer:n}=e,a=r(t),o=h(a,n,e.toneMapping,e.renderTargetOptions),i=d({...e,image:a,sdr:o,renderer:o.renderer});return{sdr:o,gainMap:i,hdr:a,getMetadata:()=>({gainMapMax:i.material.gainMapMax,gainMapMin:i.material.gainMapMin,gamma:i.material.gamma,hdrCapacityMax:i.material.hdrCapacityMax,hdrCapacityMin:i.material.hdrCapacityMin,offsetHdr:i.material.offsetHdr,offsetSdr:i.material.offsetSdr})}};e.GainMapEncoderMaterial=c,e.SDRMaterial=m,e.compress=n,e.encode=g,e.encodeAndCompress=async e=>{const t=g(e),{mimeType:r,quality:a,flipY:o,withWorker:i}=e;let s,p,l;const c=new ImageData(t.sdr.toArray(),t.sdr.width,t.sdr.height),d=new ImageData(t.gainMap.toArray(),t.gainMap.width,t.gainMap.height);if(i){const e=await Promise.all([i.compress({source:c,mimeType:r,quality:a,flipY:o}),i.compress({source:d,mimeType:r,quality:a,flipY:o})]);s=e,p=e[0].source,l=e[1].source}else s=await Promise.all([n({source:c,mimeType:r,quality:a,flipY:o}),n({source:d,mimeType:r,quality:a,flipY:o})]),p=c.data,l=d.data;return t.sdr.dispose(),t.gainMap.dispose(),{...t,...t.getMetadata(),sdr:s[0],gainMap:s[1],rawSDR:p,rawGainMap:l}},e.findTextureMinMax=(e,n="max",a)=>{const o=r(e);if(o.format!==t.AlphaFormat&&o.format!==t.RGBFormat&&o.format!==t.RGBAFormat&&o.format!==t.DepthFormat&&o.format!==t.DepthStencilFormat&&o.format!==t.RedFormat&&o.format!==t.RedIntegerFormat&&o.format!==t.RGFormat&&o.format!==t.RGIntegerFormat&&o.format!==t.RGBIntegerFormat&&o.format!==t.RGBAIntegerFormat)throw new Error("Unsupported texture format");const s=new t.ShaderMaterial({vertexShader:"\nvarying vec2 vUv;\nvoid main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}\n",fragmentShader:"\nprecision mediump float;\n\n#ifndef CELL_SIZE\n #define CELL_SIZE 2\n#endif\n\n#ifndef COMPARE_FUNCTION\n #define COMPARE_FUNCTION max\n#endif\n\n#ifndef INITIAL_VALUE\n #define INITIAL_VALUE 0\n#endif\n\nuniform sampler2D map;\nuniform vec2 u_srcResolution;\n\nvarying vec2 vUv;\n\nvoid main() {\n // compute the first pixel the source cell\n vec2 srcPixel = floor(gl_FragCoord.xy) * float(CELL_SIZE);\n\n // one pixel in source\n vec2 onePixel = vec2(1) / u_srcResolution;\n\n // uv for first pixel in cell. +0.5 for center of pixel\n vec2 uv = (srcPixel + 0.5) * onePixel;\n\n vec4 resultColor = vec4(INITIAL_VALUE);\n\n for (int y = 0; y < CELL_SIZE; ++y) {\n for (int x = 0; x < CELL_SIZE; ++x) {\n resultColor = COMPARE_FUNCTION(resultColor, texture2D(map, uv + vec2(x, y) * onePixel));\n }\n }\n\n gl_FragColor = resultColor;\n}\n",uniforms:{u_srcResolution:{value:new t.Vector2(o.image.width,o.image.height)},map:{value:o}},defines:{CELL_SIZE:2,COMPARE_FUNCTION:n,INITIAL_VALUE:"max"===n?0:65504}});o.needsUpdate=!0,s.needsUpdate=!0;let p=o.image.width,l=o.image.height;const c=new i({width:p,height:l,type:o.type,colorSpace:o.colorSpace,material:s,renderer:a}),d=[];for(;p>1||l>1;){p=Math.max(1,(p+2-1)/2|0),l=Math.max(1,(l+2-1)/2|0);const e=new t.WebGLRenderTarget(p,l,{type:c.type,format:o.format,colorSpace:c.colorSpace,minFilter:t.NearestFilter,magFilter:t.NearestFilter,wrapS:t.ClampToEdgeWrapping,wrapT:t.ClampToEdgeWrapping,generateMipmaps:!1,depthBuffer:!1,stencilBuffer:!1});d.push(e)}p=o.image.width,l=o.image.height,d.forEach(e=>{p=Math.max(1,(p+2-1)/2|0),l=Math.max(1,(l+2-1)/2|0),c.renderTarget=e,c.render(),s.uniforms.map.value=e.texture,s.uniforms.u_srcResolution.value.x=p,s.uniforms.u_srcResolution.value.y=l});const m=c.toArray();return c.dispose(),d.forEach(e=>e.dispose()),[c.type===t.FloatType?m[0]:t.DataUtils.fromHalfFloat(m[0]),c.type===t.FloatType?m[1]:t.DataUtils.fromHalfFloat(m[1]),c.type===t.FloatType?m[2]:t.DataUtils.fromHalfFloat(m[2])]},e.getGainMap=d,e.getSDRRendition=h});
@@ -1,13 +1,13 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.7.3
2
+ * @monogrid/gainmap-js v3.7.4
3
3
  * With ❤️, by MONOGRID <gainmap@monogrid.com>
4
4
  */
5
5
 
6
- import { R as RenderTargetNode, G as GainMapNode } from './GainMapNode-BIE27hYG.js';
7
- import { c as compress } from './compress-CSavQQ88.js';
6
+ import { R as RenderTargetNode, G as GainMapNode } from './GainMapNode-Bx9ovuy4.js';
7
+ import { c as compress } from './compress-DBf4K0k_.js';
8
8
  import { vec4, uniform, textureLoad, Fn, screenCoordinate, float, ivec2, min, vec2, max, texture, log2, saturate, pow, toneMapping, mat4, vec3 } from 'three/tsl';
9
9
  import { RendererUtils, QuadMesh, NodeMaterial, Texture, Vector2, RenderTarget, NearestFilter, FloatType, NoBlending, LinearFilter, LinearSRGBColorSpace, UnsignedByteType, Vector3, ACESFilmicToneMapping, SRGBColorSpace, TextureNode } from 'three/webgpu';
10
- import { g as getDataTexture } from './get-data-texture-GGd_q2_x.js';
10
+ import { g as getDataTexture } from './get-data-texture-RdAaN_eI.js';
11
11
  import 'three';
12
12
 
13
13
  /**
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.7.3
2
+ * @monogrid/gainmap-js v3.7.4
3
3
  * With ❤️, by MONOGRID <gainmap@monogrid.com>
4
4
  */
5
- import{R as t,G as e}from"./GainMapNode-DW8LUMdP.js";import{c as a}from"./compress-ChfVEpLY.js";import{vec4 as r,uniform as i,textureLoad as n,Fn as s,screenCoordinate as o,float as h,ivec2 as d,min as u,vec2 as m,max as g,texture as l,log2 as c,saturate as p,pow as f,toneMapping as w,mat4 as M,vec3 as x}from"three/tsl";import{RendererUtils as _,QuadMesh as y,NodeMaterial as v,Texture as C,Vector2 as B,RenderTarget as S,NearestFilter as b,FloatType as T,NoBlending as R,LinearFilter as A,LinearSRGBColorSpace as D,UnsignedByteType as H,Vector3 as G,ACESFilmicToneMapping as N,SRGBColorSpace as j,TextureNode as F}from"three/webgpu";import{g as E}from"./get-data-texture-CtrXqvaR.js";import"three";const P=async(t,e)=>{const{width:a,height:r}=e,i=await t.readRenderTargetPixelsAsync(e,0,0,a,r),n=4*a,s=r>1?(i.length-n)/(r-1):n,o=!0!==t.backend.isWebGLBackend;if(s===n&&!o)return i.length===n*r?i:i.subarray(0,n*r);const h=new i.constructor(n*r);for(let t=0;t<r;t++){const e=o?r-1-t:t;h.set(i.subarray(e*s,e*s+n),t*n)}return h},U=async(t,e,a,l)=>{const c=_.resetRendererState(a,{}),p=[],f=new y(new v),w=(t,e)=>{const a=new S(t,e,{type:T,minFilter:b,magFilter:b,generateMipmaps:!1,depthBuffer:!1});return p.push(a),a},M=(t,e)=>{t.blending=R,t.depthTest=!1,t.depthWrite=!1,f.material=t,a.setRenderTarget(e),f.render(a)};try{let c,p,f;if(t instanceof C||(t=>"object"==typeof t&&null!==t&&"data"in t&&"width"in t&&"height"in t&&!(t instanceof C))(t)){c=t instanceof C?t:E(t);const e=c.image;p=e.width,f=e.height}else{if(!l)throw new Error("findTextureMinMax: size is required when the image is a node");p=l.width,f=l.height;const e=new v;e.fragmentNode=r(t);const a=w(p,f);M(e,a),e.dispose(),c=a.texture}const x=(t,a,l)=>{const c=i(new B(a,l)),p=n(t),f=s(()=>{const t=o.xy.floor().mul(2),a=c.sub(1),i=r(h("max"===e?0:65504)).toVar();for(let r=0;r<2;r++)for(let n=0;n<2;n++){const s=p.load(d(u(t.add(m(n,r)),a)));i.assign("max"===e?g(i,s):u(i,s))}return i}),w=new v;return w.fragmentNode=f(),{material:w,sourceTexture:p,sourceSize:c}};let _,y=x(c,p,f);for(;p>1||f>1||!_;){p=Math.max(1,Math.ceil(p/2)),f=Math.max(1,Math.ceil(f/2));const t=_;_=w(p,f),t&&(y.sourceTexture.value===c?(y.material.dispose(),y=x(t.texture,t.width,t.height)):(y.sourceTexture.value=t.texture,y.sourceSize.value.set(t.width,t.height))),M(y.material,_)}y.material.dispose();const S=await P(a,_);return[S[0],S[1],S[2]]}finally{_.restoreRendererState(a,c),p.forEach(t=>t.dispose())}},W=1.0001;class z extends t{static get type(){return"GainMapEncoderNode"}sdr;uniforms;pixelGain;_warned=[];constructor(t,e={}){super(new v,{type:H,colorSpace:D,minFilter:A,magFilter:A}),this.sdr=t;const a=this.uniforms={gamma:i((new G).fromArray(e.gamma??[1,1,1])),offsetSdr:i((new G).fromArray(e.offsetSdr??[1/64,1/64,1/64])),offsetHdr:i((new G).fromArray(e.offsetHdr??[1/64,1/64,1/64])),minContentBoost:i(e.minContentBoost||1),maxContentBoost:i(e.maxContentBoost??W)},n=i(0).onRenderUpdate(()=>Math.log2(this.metadataMinContentBoost)),s=i(0).onRenderUpdate(()=>Math.log2(this.metadataMaxContentBoost)),o=l(t.value).rgb,h=r(t.hdr).rgb,d=this.pixelGain=h.add(a.offsetHdr).div(o.add(a.offsetSdr)),u=c(d).sub(n).div(s.sub(n)),m=p(u);this._material.name="GainMapEncoder",this._material.blending=R,this._material.depthTest=!1,this._material.depthWrite=!1,this._material.fragmentNode=r(f(m,a.gamma),1)}get gamma(){return this.uniforms.gamma}get offsetSdr(){return this.uniforms.offsetSdr}get offsetHdr(){return this.uniforms.offsetHdr}get minContentBoost(){return this.uniforms.minContentBoost}get maxContentBoost(){return this.uniforms.maxContentBoost}get width(){return this.sdr.width}get height(){return this.sdr.height}get metadataMinContentBoost(){return this.uniforms.minContentBoost.value}get metadataMaxContentBoost(){return Math.max(this.uniforms.maxContentBoost.value,W)}get metadata(){const t=this.uniforms,e=Math.log2(this.metadataMinContentBoost),a=Math.log2(this.metadataMaxContentBoost);return{gamma:t.gamma.value.toArray(),offsetSdr:t.offsetSdr.value.toArray(),offsetHdr:t.offsetHdr.value.toArray(),gainMapMin:[e,e,e],gainMapMax:[a,a,a],hdrCapacityMin:Math.max(0,e),hdrCapacityMax:Math.max(0,a)}}_getState(){const t=this.uniforms;return[...t.gamma.value.toArray(),...t.offsetSdr.value.toArray(),...t.offsetHdr.value.toArray(),t.minContentBoost.value,t.maxContentBoost.value]}_getDependencies(){return[this.sdr]}_onRender(){const{minContentBoost:t,maxContentBoost:e}=this.uniforms,a=[t.value,e.value];a.every((t,e)=>t===this._warned[e])||(this._warned=a,e.value<=1&&console.warn(`gainmap-js: maxContentBoost is ${e.value} (<= 1), the source image has no HDR content. It will be clamped to 1.0001 and the result will be equivalent to an SDR image.`),this.metadataMinContentBoost>=this.metadataMaxContentBoost&&console.warn(`gainmap-js: minContentBoost (${this.metadataMinContentBoost}) must be lower than maxContentBoost (${this.metadataMaxContentBoost}), the resulting gain map will be invalid.`))}}const k=(t,e)=>new z(t,e),q=t=>{const e=t.image;return{width:e?.width??0,height:e?.height??0}};class I extends t{static get type(){return"SDRRenditionNode"}hdr;uniforms;_hdrTexture;_hdrSource;_width;_height;_toneMapping=N;constructor(e,a={}){if(super(new v,{type:H,colorSpace:j,minFilter:A,magFilter:A}),this._hdrTexture=e instanceof C?e:e instanceof F?e.value:null,this._hdrSource=e instanceof t?e:null,this.hdr=e instanceof C?l(e):e,this._width=a.width,this._height=a.height,!(this._hdrTexture||this._width&&this._height))throw new Error("SDRRenditionNode: width and height are required when the HDR input is not a texture");this.uniforms={exposure:i(1),brightness:i(0),contrast:i(1),saturation:i(1)},this._material.name="SDRRendition",this._material.blending=R,this._material.depthTest=!1,this._material.depthWrite=!1,this.setToneMapping(a.toneMapping??N)}get exposure(){return this.uniforms.exposure}get brightness(){return this.uniforms.brightness}get contrast(){return this.uniforms.contrast}get saturation(){return this.uniforms.saturation}getToneMapping(){return this._toneMapping}setToneMapping(t){return this._toneMapping=t,this._material.fragmentNode=this._buildOutput(),this._material.needsUpdate=!0,this}get width(){return this._width?this._width:this._hdrSource?this._hdrSource.width:this._hdrTexture?q(this._hdrTexture).width:0}get height(){return this._height?this._height:this._hdrSource?this._hdrSource.height:this._hdrTexture?q(this._hdrTexture).height:0}_buildOutput(){const t=this.uniforms,e=r(this.hdr),a=r(w(this._toneMapping,h(1),e.rgb.mul(t.exposure)).rgb,e.a),i=t.brightness,n=M(1,0,0,0,0,1,0,0,0,0,1,0,i,i,i,1),s=t.contrast,o=h(1).sub(s).div(2),d=M(s,0,0,0,0,s,0,0,0,0,s,0,o,o,o,1),u=x(.3086,.6094,.082),m=h(1).sub(t.saturation),g=x(u.x.mul(m)).add(x(t.saturation,0,0)),l=x(u.y.mul(m)).add(x(0,t.saturation,0)),c=x(u.z.mul(m)).add(x(0,0,t.saturation)),p=M(r(g,0),r(l,0),r(c,0),r(0,0,0,1));return n.mul(d).mul(p).mul(a)}_getState(){const t=this.uniforms;return[this._hdrTexture?.id,this._hdrTexture?.version,this._toneMapping,t.exposure.value,t.brightness.value,t.contrast.value,t.saturation.value]}_getDependencies(){return this._hdrSource?[this._hdrSource]:[]}}const $=(t,e)=>new I(t,e),O=2**-16;class L extends e{_encoder;constructor(t){super(),this._encoder=t,this.setTextures(t.sdr,t.gainMap).setMetadata(t.metadata)}_getState(){const{gamma:t,offsetSdr:e,offsetHdr:a,gainMapMin:r,gainMapMax:i,hdrCapacityMin:n,hdrCapacityMax:s}=this._encoder.metadata,o=this.uniforms;return o.gamma.value.fromArray(t),o.offsetSdr.value.fromArray(e),o.offsetHdr.value.fromArray(a),o.gainMapMin.value.fromArray(r),o.gainMapMax.value.fromArray(i),o.hdrCapacityMin.value=n,o.hdrCapacityMax.value=s,super._getState()}}class V{sdr;gainMap;_ownedTexture;constructor(t,e={}){let a;t instanceof C||!("data"in t)?(a=t,this._ownedTexture=null):a=this._ownedTexture=E(t),this.sdr=new I(a,e),this.gainMap=new z(this.sdr,e)}get width(){return this.sdr.width}get height(){return this.sdr.height}get metadata(){return this.gainMap.metadata}async fitMaxContentBoost(t){const e=Math.max(...await U(this.sdr.hdr,"max",t,this));return this.gainMap.maxContentBoost.value=e,e}async fitContentBoost(t){this.sdr.render(t);const e=r(this.gainMap.pixelGain,1),a={width:this.width,height:this.height},i=await U(e,"min",t,a),n=await U(e,"max",t,a),s=Math.max(O,Math.min(1,...i)),o=Math.max(1.0001,...n);return this.gainMap.minContentBoost.value=s,this.gainMap.maxContentBoost.value=o,{min:s,max:o}}createPreviewNode(){return new L(this)}render(t){this.gainMap.render(t)}async read(t){this.render(t);const e=this.metadata,[a,r]=await Promise.all([P(t,this.sdr.renderTarget),P(t,this.gainMap.renderTarget)]);return{sdr:new ImageData(new Uint8ClampedArray(a),this.width,this.height),gainMap:new ImageData(new Uint8ClampedArray(r),this.width,this.height),metadata:e}}async compress(t,e){const{sdr:r,gainMap:i,metadata:n}=await this.read(t),{withWorker:s,...o}=e;if(s){const[t,e]=await Promise.all([s.compress({...o,source:r}),s.compress({...o,source:i})]);return{...n,sdr:t,gainMap:e,rawSDR:t.source,rawGainMap:e.source}}const[h,d]=await Promise.all([a({...o,source:r}),a({...o,source:i})]);return{...n,sdr:h,gainMap:d,rawSDR:r.data,rawGainMap:i.data}}dispose(){this.sdr.dispose(),this.gainMap.dispose(),this._ownedTexture?.dispose()}}export{V as GainMapEncoder,z as GainMapEncoderNode,t as RenderTargetNode,I as SDRRenditionNode,a as compress,U as findTextureMinMax,k as gainMapEncoder,$ as sdrRendition};
5
+ import{R as t,G as e}from"./GainMapNode-BRDowRvr.js";import{c as a}from"./compress-DhuzUwR5.js";import{vec4 as r,uniform as i,textureLoad as n,Fn as s,screenCoordinate as o,float as h,ivec2 as d,min as u,vec2 as m,max as g,texture as l,log2 as c,saturate as p,pow as f,toneMapping as w,mat4 as M,vec3 as x}from"three/tsl";import{RendererUtils as _,QuadMesh as y,NodeMaterial as v,Texture as C,Vector2 as B,RenderTarget as S,NearestFilter as b,FloatType as T,NoBlending as R,LinearFilter as A,LinearSRGBColorSpace as D,UnsignedByteType as H,Vector3 as G,ACESFilmicToneMapping as N,SRGBColorSpace as j,TextureNode as F}from"three/webgpu";import{g as E}from"./get-data-texture-CmfjzIHL.js";import"three";const P=async(t,e)=>{const{width:a,height:r}=e,i=await t.readRenderTargetPixelsAsync(e,0,0,a,r),n=4*a,s=r>1?(i.length-n)/(r-1):n,o=!0!==t.backend.isWebGLBackend;if(s===n&&!o)return i.length===n*r?i:i.subarray(0,n*r);const h=new i.constructor(n*r);for(let t=0;t<r;t++){const e=o?r-1-t:t;h.set(i.subarray(e*s,e*s+n),t*n)}return h},U=async(t,e,a,l)=>{const c=_.resetRendererState(a,{}),p=[],f=new y(new v),w=(t,e)=>{const a=new S(t,e,{type:T,minFilter:b,magFilter:b,generateMipmaps:!1,depthBuffer:!1});return p.push(a),a},M=(t,e)=>{t.blending=R,t.depthTest=!1,t.depthWrite=!1,f.material=t,a.setRenderTarget(e),f.render(a)};try{let c,p,f;if(t instanceof C||(t=>"object"==typeof t&&null!==t&&"data"in t&&"width"in t&&"height"in t&&!(t instanceof C))(t)){c=t instanceof C?t:E(t);const e=c.image;p=e.width,f=e.height}else{if(!l)throw new Error("findTextureMinMax: size is required when the image is a node");p=l.width,f=l.height;const e=new v;e.fragmentNode=r(t);const a=w(p,f);M(e,a),e.dispose(),c=a.texture}const x=(t,a,l)=>{const c=i(new B(a,l)),p=n(t),f=s(()=>{const t=o.xy.floor().mul(2),a=c.sub(1),i=r(h("max"===e?0:65504)).toVar();for(let r=0;r<2;r++)for(let n=0;n<2;n++){const s=p.load(d(u(t.add(m(n,r)),a)));i.assign("max"===e?g(i,s):u(i,s))}return i}),w=new v;return w.fragmentNode=f(),{material:w,sourceTexture:p,sourceSize:c}};let _,y=x(c,p,f);for(;p>1||f>1||!_;){p=Math.max(1,Math.ceil(p/2)),f=Math.max(1,Math.ceil(f/2));const t=_;_=w(p,f),t&&(y.sourceTexture.value===c?(y.material.dispose(),y=x(t.texture,t.width,t.height)):(y.sourceTexture.value=t.texture,y.sourceSize.value.set(t.width,t.height))),M(y.material,_)}y.material.dispose();const S=await P(a,_);return[S[0],S[1],S[2]]}finally{_.restoreRendererState(a,c),p.forEach(t=>t.dispose())}},W=1.0001;class z extends t{static get type(){return"GainMapEncoderNode"}sdr;uniforms;pixelGain;_warned=[];constructor(t,e={}){super(new v,{type:H,colorSpace:D,minFilter:A,magFilter:A}),this.sdr=t;const a=this.uniforms={gamma:i((new G).fromArray(e.gamma??[1,1,1])),offsetSdr:i((new G).fromArray(e.offsetSdr??[1/64,1/64,1/64])),offsetHdr:i((new G).fromArray(e.offsetHdr??[1/64,1/64,1/64])),minContentBoost:i(e.minContentBoost||1),maxContentBoost:i(e.maxContentBoost??W)},n=i(0).onRenderUpdate(()=>Math.log2(this.metadataMinContentBoost)),s=i(0).onRenderUpdate(()=>Math.log2(this.metadataMaxContentBoost)),o=l(t.value).rgb,h=r(t.hdr).rgb,d=this.pixelGain=h.add(a.offsetHdr).div(o.add(a.offsetSdr)),u=c(d).sub(n).div(s.sub(n)),m=p(u);this._material.name="GainMapEncoder",this._material.blending=R,this._material.depthTest=!1,this._material.depthWrite=!1,this._material.fragmentNode=r(f(m,a.gamma),1)}get gamma(){return this.uniforms.gamma}get offsetSdr(){return this.uniforms.offsetSdr}get offsetHdr(){return this.uniforms.offsetHdr}get minContentBoost(){return this.uniforms.minContentBoost}get maxContentBoost(){return this.uniforms.maxContentBoost}get width(){return this.sdr.width}get height(){return this.sdr.height}get metadataMinContentBoost(){return this.uniforms.minContentBoost.value}get metadataMaxContentBoost(){return Math.max(this.uniforms.maxContentBoost.value,W)}get metadata(){const t=this.uniforms,e=Math.log2(this.metadataMinContentBoost),a=Math.log2(this.metadataMaxContentBoost);return{gamma:t.gamma.value.toArray(),offsetSdr:t.offsetSdr.value.toArray(),offsetHdr:t.offsetHdr.value.toArray(),gainMapMin:[e,e,e],gainMapMax:[a,a,a],hdrCapacityMin:Math.max(0,e),hdrCapacityMax:Math.max(0,a)}}_getState(){const t=this.uniforms;return[...t.gamma.value.toArray(),...t.offsetSdr.value.toArray(),...t.offsetHdr.value.toArray(),t.minContentBoost.value,t.maxContentBoost.value]}_getDependencies(){return[this.sdr]}_onRender(){const{minContentBoost:t,maxContentBoost:e}=this.uniforms,a=[t.value,e.value];a.every((t,e)=>t===this._warned[e])||(this._warned=a,e.value<=1&&console.warn(`gainmap-js: maxContentBoost is ${e.value} (<= 1), the source image has no HDR content. It will be clamped to 1.0001 and the result will be equivalent to an SDR image.`),this.metadataMinContentBoost>=this.metadataMaxContentBoost&&console.warn(`gainmap-js: minContentBoost (${this.metadataMinContentBoost}) must be lower than maxContentBoost (${this.metadataMaxContentBoost}), the resulting gain map will be invalid.`))}}const k=(t,e)=>new z(t,e),q=t=>{const e=t.image;return{width:e?.width??0,height:e?.height??0}};class I extends t{static get type(){return"SDRRenditionNode"}hdr;uniforms;_hdrTexture;_hdrSource;_width;_height;_toneMapping=N;constructor(e,a={}){if(super(new v,{type:H,colorSpace:j,minFilter:A,magFilter:A}),this._hdrTexture=e instanceof C?e:e instanceof F?e.value:null,this._hdrSource=e instanceof t?e:null,this.hdr=e instanceof C?l(e):e,this._width=a.width,this._height=a.height,!(this._hdrTexture||this._width&&this._height))throw new Error("SDRRenditionNode: width and height are required when the HDR input is not a texture");this.uniforms={exposure:i(1),brightness:i(0),contrast:i(1),saturation:i(1)},this._material.name="SDRRendition",this._material.blending=R,this._material.depthTest=!1,this._material.depthWrite=!1,this.setToneMapping(a.toneMapping??N)}get exposure(){return this.uniforms.exposure}get brightness(){return this.uniforms.brightness}get contrast(){return this.uniforms.contrast}get saturation(){return this.uniforms.saturation}getToneMapping(){return this._toneMapping}setToneMapping(t){return this._toneMapping=t,this._material.fragmentNode=this._buildOutput(),this._material.needsUpdate=!0,this}get width(){return this._width?this._width:this._hdrSource?this._hdrSource.width:this._hdrTexture?q(this._hdrTexture).width:0}get height(){return this._height?this._height:this._hdrSource?this._hdrSource.height:this._hdrTexture?q(this._hdrTexture).height:0}_buildOutput(){const t=this.uniforms,e=r(this.hdr),a=r(w(this._toneMapping,h(1),e.rgb.mul(t.exposure)).rgb,e.a),i=t.brightness,n=M(1,0,0,0,0,1,0,0,0,0,1,0,i,i,i,1),s=t.contrast,o=h(1).sub(s).div(2),d=M(s,0,0,0,0,s,0,0,0,0,s,0,o,o,o,1),u=x(.3086,.6094,.082),m=h(1).sub(t.saturation),g=x(u.x.mul(m)).add(x(t.saturation,0,0)),l=x(u.y.mul(m)).add(x(0,t.saturation,0)),c=x(u.z.mul(m)).add(x(0,0,t.saturation)),p=M(r(g,0),r(l,0),r(c,0),r(0,0,0,1));return n.mul(d).mul(p).mul(a)}_getState(){const t=this.uniforms;return[this._hdrTexture?.id,this._hdrTexture?.version,this._toneMapping,t.exposure.value,t.brightness.value,t.contrast.value,t.saturation.value]}_getDependencies(){return this._hdrSource?[this._hdrSource]:[]}}const $=(t,e)=>new I(t,e),O=2**-16;class L extends e{_encoder;constructor(t){super(),this._encoder=t,this.setTextures(t.sdr,t.gainMap).setMetadata(t.metadata)}_getState(){const{gamma:t,offsetSdr:e,offsetHdr:a,gainMapMin:r,gainMapMax:i,hdrCapacityMin:n,hdrCapacityMax:s}=this._encoder.metadata,o=this.uniforms;return o.gamma.value.fromArray(t),o.offsetSdr.value.fromArray(e),o.offsetHdr.value.fromArray(a),o.gainMapMin.value.fromArray(r),o.gainMapMax.value.fromArray(i),o.hdrCapacityMin.value=n,o.hdrCapacityMax.value=s,super._getState()}}class V{sdr;gainMap;_ownedTexture;constructor(t,e={}){let a;t instanceof C||!("data"in t)?(a=t,this._ownedTexture=null):a=this._ownedTexture=E(t),this.sdr=new I(a,e),this.gainMap=new z(this.sdr,e)}get width(){return this.sdr.width}get height(){return this.sdr.height}get metadata(){return this.gainMap.metadata}async fitMaxContentBoost(t){const e=Math.max(...await U(this.sdr.hdr,"max",t,this));return this.gainMap.maxContentBoost.value=e,e}async fitContentBoost(t){this.sdr.render(t);const e=r(this.gainMap.pixelGain,1),a={width:this.width,height:this.height},i=await U(e,"min",t,a),n=await U(e,"max",t,a),s=Math.max(O,Math.min(1,...i)),o=Math.max(1.0001,...n);return this.gainMap.minContentBoost.value=s,this.gainMap.maxContentBoost.value=o,{min:s,max:o}}createPreviewNode(){return new L(this)}render(t){this.gainMap.render(t)}async read(t){this.render(t);const e=this.metadata,[a,r]=await Promise.all([P(t,this.sdr.renderTarget),P(t,this.gainMap.renderTarget)]);return{sdr:new ImageData(new Uint8ClampedArray(a),this.width,this.height),gainMap:new ImageData(new Uint8ClampedArray(r),this.width,this.height),metadata:e}}async compress(t,e){const{sdr:r,gainMap:i,metadata:n}=await this.read(t),{withWorker:s,...o}=e;if(s){const[t,e]=await Promise.all([s.compress({...o,source:r}),s.compress({...o,source:i})]);return{...n,sdr:t,gainMap:e,rawSDR:t.source,rawGainMap:e.source}}const[h,d]=await Promise.all([a({...o,source:r}),a({...o,source:i})]);return{...n,sdr:h,gainMap:d,rawSDR:r.data,rawGainMap:i.data}}dispose(){this.sdr.dispose(),this.gainMap.dispose(),this._ownedTexture?.dispose()}}export{V as GainMapEncoder,z as GainMapEncoderNode,t as RenderTargetNode,I as SDRRenditionNode,a as compress,U as findTextureMinMax,k as gainMapEncoder,$ as sdrRendition};
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.7.3
2
+ * @monogrid/gainmap-js v3.7.4
3
3
  * With ❤️, by MONOGRID <gainmap@monogrid.com>
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.7.3
2
+ * @monogrid/gainmap-js v3.7.4
3
3
  * With ❤️, by MONOGRID <gainmap@monogrid.com>
4
4
  */
5
5
  !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("three/webgpu"),require("three/tsl"),require("three")):"function"==typeof define&&define.amd?define(["exports","three/webgpu","three/tsl","three"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).encode={},e["three/webgpu"],e["three/tsl"],e.three)}(this,function(e,t,r,a){"use strict";class i extends t.TextureNode{renderTarget;revision=0;_quadMesh;_material;_rendererState={};_state=[];constructor(e,r){const a=new t.RenderTarget(1,1,{depthBuffer:!1,...r});super(a.texture),this.renderTarget=a,this.updateBeforeType=t.NodeUpdateType.RENDER,this._material=e,this._quadMesh=new t.QuadMesh(e)}_getDependencies(){return[]}_onRender(){}invalidate(){return this._state=[],this}render(e){const r=this._getDependencies();for(const t of r)t.render(e);const{width:a,height:i}=this;if(0===a||0===i)return!1;const n=[a,i,...r.map(e=>e.revision),...this._getState()];return(n.length!==this._state.length||!n.every((e,t)=>e===this._state[t]))&&(this._state=n,this.renderTarget.width===a&&this.renderTarget.height===i||this.renderTarget.setSize(a,i),t.RendererUtils.resetRendererState(e,this._rendererState),e.setRenderTarget(this.renderTarget),this._quadMesh.render(e),t.RendererUtils.restoreRendererState(e,this._rendererState),this.revision++,this._onRender(),!0)}updateBefore(e){e.renderer&&this.render(e.renderer)}set value(e){if(this.renderTarget&&e!==this.renderTarget.texture)throw new Error(`${this.constructor.name}: the value of this node is its render target texture and can't be replaced`)}get value(){return this.renderTarget?.texture}clone(){const e=new t.TextureNode(this.value,this.uvNode,this.levelNode,this.biasNode);return e.sampler=this.sampler,e.updateBeforeType=t.NodeUpdateType.RENDER,e.updateBefore=e=>this.updateBefore(e),e}dispose(){this.renderTarget.dispose(),this._material.dispose(),super.dispose()}}const n=async e=>{if("undefined"==typeof createImageBitmap)throw new Error("createImageBitmap() not supported.");const{source:t,mimeType:r,quality:a,flipY:i}=e;let n;if((t instanceof Uint8Array||t instanceof Uint8ClampedArray)&&"sourceMimeType"in e)n=new Blob([t],{type:e.sourceMimeType});else{if(!(t instanceof ImageData))throw new Error("Invalid source image");n=t}const s=await createImageBitmap(n),o=s.width,d=s.height;let h;"undefined"!=typeof OffscreenCanvas?h=new OffscreenCanvas(o,d):(h=document.createElement("canvas"),h.width=o,h.height=d);const u=h.getContext("2d");if(!u)throw new Error("Failed to create canvas Context");!0===i&&(u.translate(0,d),u.scale(1,-1)),u.drawImage(s,0,0,o,d);const m=await(async(e,t,r)=>{if("undefined"!=typeof OffscreenCanvas&&e instanceof OffscreenCanvas)return e.convertToBlob({type:t,quality:r});if(e instanceof HTMLCanvasElement)return new Promise((a,i)=>{e.toBlob(e=>{e?a(e):i(new Error("Failed to convert canvas to blob"))},t,r)});throw new Error("Unsupported canvas element")})(h,r,a||.9);return{data:new Uint8Array(await m.arrayBuffer()),mimeType:r,width:o,height:d}},s=e=>{let t;if(e instanceof a.DataTexture){if(!(e.image.data instanceof Uint16Array||e.image.data instanceof Float32Array))throw new Error("Provided image is not HDR");t=e}else{if(!e.data||!e.width||!e.height)throw new Error("Provided image has no data or size");t=new a.DataTexture(e.data,e.width,e.height,e.format??a.RGBAFormat,e.type,a.UVMapping,a.RepeatWrapping,a.RepeatWrapping,a.LinearFilter,a.LinearFilter,1,"colorSpace"in e&&"srgb"===e.colorSpace?e.colorSpace:a.LinearSRGBColorSpace),"header"in e&&"gamma"in e&&(t.flipY=!0),t.needsUpdate=!0}return t},o=async(e,t)=>{const{width:r,height:a}=t,i=await e.readRenderTargetPixelsAsync(t,0,0,r,a),n=4*r,s=a>1?(i.length-n)/(a-1):n,o=!0!==e.backend.isWebGLBackend;if(s===n&&!o)return i.length===n*a?i:i.subarray(0,n*a);const d=new i.constructor(n*a);for(let e=0;e<a;e++){const t=o?a-1-e:e;d.set(i.subarray(t*s,t*s+n),e*n)}return d},d=async(e,a,i,n)=>{const d=t.RendererUtils.resetRendererState(i,{}),h=[],u=new t.QuadMesh(new t.NodeMaterial),m=(e,r)=>{const a=new t.RenderTarget(e,r,{type:t.FloatType,minFilter:t.NearestFilter,magFilter:t.NearestFilter,generateMipmaps:!1,depthBuffer:!1});return h.push(a),a},c=(e,r)=>{e.blending=t.NoBlending,e.depthTest=!1,e.depthWrite=!1,u.material=e,i.setRenderTarget(r),u.render(i)};try{let d,h,u;if(e instanceof t.Texture||(e=>"object"==typeof e&&null!==e&&"data"in e&&"width"in e&&"height"in e&&!(e instanceof t.Texture))(e)){d=e instanceof t.Texture?e:s(e);const r=d.image;h=r.width,u=r.height}else{if(!n)throw new Error("findTextureMinMax: size is required when the image is a node");h=n.width,u=n.height;const a=new t.NodeMaterial;a.fragmentNode=r.vec4(e);const i=m(h,u);c(a,i),a.dispose(),d=i.texture}const l=(e,i,n)=>{const s=r.uniform(new t.Vector2(i,n)),o=r.textureLoad(e),d=r.Fn(()=>{const e=r.screenCoordinate.xy.floor().mul(2),t=s.sub(1),i=r.vec4(r.float("max"===a?0:65504)).toVar();for(let n=0;n<2;n++)for(let s=0;s<2;s++){const d=o.load(r.ivec2(r.min(e.add(r.vec2(s,n)),t)));i.assign("max"===a?r.max(i,d):r.min(i,d))}return i}),h=new t.NodeMaterial;return h.fragmentNode=d(),{material:h,sourceTexture:o,sourceSize:s}};let p,g=l(d,h,u);for(;h>1||u>1||!p;){h=Math.max(1,Math.ceil(h/2)),u=Math.max(1,Math.ceil(u/2));const e=p;p=m(h,u),e&&(g.sourceTexture.value===d?(g.material.dispose(),g=l(e.texture,e.width,e.height)):(g.sourceTexture.value=e.texture,g.sourceSize.value.set(e.width,e.height))),c(g.material,p)}g.material.dispose();const f=await o(i,p);return[f[0],f[1],f[2]]}finally{t.RendererUtils.restoreRendererState(i,d),h.forEach(e=>e.dispose())}};class h extends i{static get type(){return"GainMapNode"}uniforms;_sdrSource=null;_gainMapSource=null;constructor(){const e=new t.MeshBasicNodeMaterial;e.name="GainMapDecoder",super(e,{type:t.HalfFloatType,colorSpace:t.LinearSRGBColorSpace,generateMipmaps:!0,minFilter:t.LinearMipmapLinearFilter,magFilter:t.LinearFilter});const a=this.uniforms={sdr:r.texture(new t.Texture),gainMap:r.texture(new t.Texture),gamma:r.uniform(new t.Vector3(1,1,1)),offsetSdr:r.uniform(new t.Vector3),offsetHdr:r.uniform(new t.Vector3),gainMapMin:r.uniform(new t.Vector3),gainMapMax:r.uniform(new t.Vector3(1,1,1)),hdrCapacityMin:r.uniform(0),hdrCapacityMax:r.uniform(1),maxDisplayBoost:r.uniform(1)},i=a.gainMap.rgb.pow(r.vec3(1).div(a.gamma)),n=r.mix(a.gainMapMin,a.gainMapMax,i),s=r.saturate(r.log2(a.maxDisplayBoost).sub(a.hdrCapacityMin).div(a.hdrCapacityMax.sub(a.hdrCapacityMin))),o=a.sdr.rgb.add(a.offsetSdr).mul(r.exp2(n.mul(s))).sub(a.offsetHdr);e.colorNode=r.vec4(o.clamp(-65504,65504),1)}get sdr(){return this.uniforms.sdr.value}get gainMap(){return this.uniforms.gainMap.value}get gamma(){return this.uniforms.gamma}get offsetSdr(){return this.uniforms.offsetSdr}get offsetHdr(){return this.uniforms.offsetHdr}get gainMapMin(){return this.uniforms.gainMapMin}get gainMapMax(){return this.uniforms.gainMapMax}get hdrCapacityMin(){return this.uniforms.hdrCapacityMin}get hdrCapacityMax(){return this.uniforms.hdrCapacityMax}get maxDisplayBoost(){return this.uniforms.maxDisplayBoost}get width(){return this._sdrSource?this._sdrSource.width:this.sdr.image?.width??0}get height(){return this._sdrSource?this._sdrSource.height:this.sdr.image?.height??0}setTextures(e,t){return this._sdrSource=e instanceof i?e:null,this._gainMapSource=t instanceof i?t:null,this.uniforms.sdr.value=e instanceof i?e.value:e,this.uniforms.gainMap.value=t instanceof i?t.value:t,this.width>0&&this.height>0&&this.renderTarget.setSize(this.width,this.height),this}setMetadata(e){const t=this.uniforms;return t.gamma.value.fromArray(e.gamma),t.offsetSdr.value.fromArray(e.offsetSdr),t.offsetHdr.value.fromArray(e.offsetHdr),t.gainMapMin.value.fromArray(e.gainMapMin),t.gainMapMax.value.fromArray(e.gainMapMax),t.hdrCapacityMin.value=e.hdrCapacityMin,t.hdrCapacityMax.value=e.hdrCapacityMax,t.maxDisplayBoost.value=Math.pow(2,e.hdrCapacityMax),this}_getState(){const e=this.uniforms;return[this.sdr.id,this.sdr.version,this.gainMap.id,this.gainMap.version,...e.gamma.value.toArray(),...e.offsetSdr.value.toArray(),...e.offsetHdr.value.toArray(),...e.gainMapMin.value.toArray(),...e.gainMapMax.value.toArray(),e.hdrCapacityMin.value,e.hdrCapacityMax.value,e.maxDisplayBoost.value]}_getDependencies(){const e=[];return this._sdrSource&&e.push(this._sdrSource),this._gainMapSource&&e.push(this._gainMapSource),e}_onRender(){this.value.needsPMREMUpdate=!0}decode(e){return this.render(e)}updateBefore(e){e.renderer&&this.decode(e.renderer)}dispose(){this._sdrSource||this.sdr.dispose(),this._gainMapSource||this.gainMap.dispose(),super.dispose()}}const u=1.0001;class m extends i{static get type(){return"GainMapEncoderNode"}sdr;uniforms;pixelGain;_warned=[];constructor(e,a={}){super(new t.NodeMaterial,{type:t.UnsignedByteType,colorSpace:t.LinearSRGBColorSpace,minFilter:t.LinearFilter,magFilter:t.LinearFilter}),this.sdr=e;const i=this.uniforms={gamma:r.uniform((new t.Vector3).fromArray(a.gamma??[1,1,1])),offsetSdr:r.uniform((new t.Vector3).fromArray(a.offsetSdr??[1/64,1/64,1/64])),offsetHdr:r.uniform((new t.Vector3).fromArray(a.offsetHdr??[1/64,1/64,1/64])),minContentBoost:r.uniform(a.minContentBoost||1),maxContentBoost:r.uniform(a.maxContentBoost??u)},n=r.uniform(0).onRenderUpdate(()=>Math.log2(this.metadataMinContentBoost)),s=r.uniform(0).onRenderUpdate(()=>Math.log2(this.metadataMaxContentBoost)),o=r.texture(e.value).rgb,d=r.vec4(e.hdr).rgb,h=this.pixelGain=d.add(i.offsetHdr).div(o.add(i.offsetSdr)),m=r.log2(h).sub(n).div(s.sub(n)),c=r.saturate(m);this._material.name="GainMapEncoder",this._material.blending=t.NoBlending,this._material.depthTest=!1,this._material.depthWrite=!1,this._material.fragmentNode=r.vec4(r.pow(c,i.gamma),1)}get gamma(){return this.uniforms.gamma}get offsetSdr(){return this.uniforms.offsetSdr}get offsetHdr(){return this.uniforms.offsetHdr}get minContentBoost(){return this.uniforms.minContentBoost}get maxContentBoost(){return this.uniforms.maxContentBoost}get width(){return this.sdr.width}get height(){return this.sdr.height}get metadataMinContentBoost(){return this.uniforms.minContentBoost.value}get metadataMaxContentBoost(){return Math.max(this.uniforms.maxContentBoost.value,u)}get metadata(){const e=this.uniforms,t=Math.log2(this.metadataMinContentBoost),r=Math.log2(this.metadataMaxContentBoost);return{gamma:e.gamma.value.toArray(),offsetSdr:e.offsetSdr.value.toArray(),offsetHdr:e.offsetHdr.value.toArray(),gainMapMin:[t,t,t],gainMapMax:[r,r,r],hdrCapacityMin:Math.max(0,t),hdrCapacityMax:Math.max(0,r)}}_getState(){const e=this.uniforms;return[...e.gamma.value.toArray(),...e.offsetSdr.value.toArray(),...e.offsetHdr.value.toArray(),e.minContentBoost.value,e.maxContentBoost.value]}_getDependencies(){return[this.sdr]}_onRender(){const{minContentBoost:e,maxContentBoost:t}=this.uniforms,r=[e.value,t.value];r.every((e,t)=>e===this._warned[t])||(this._warned=r,t.value<=1&&console.warn(`gainmap-js: maxContentBoost is ${t.value} (<= 1), the source image has no HDR content. It will be clamped to 1.0001 and the result will be equivalent to an SDR image.`),this.metadataMinContentBoost>=this.metadataMaxContentBoost&&console.warn(`gainmap-js: minContentBoost (${this.metadataMinContentBoost}) must be lower than maxContentBoost (${this.metadataMaxContentBoost}), the resulting gain map will be invalid.`))}}const c=e=>{const t=e.image;return{width:t?.width??0,height:t?.height??0}};class l extends i{static get type(){return"SDRRenditionNode"}hdr;uniforms;_hdrTexture;_hdrSource;_width;_height;_toneMapping=t.ACESFilmicToneMapping;constructor(e,a={}){if(super(new t.NodeMaterial,{type:t.UnsignedByteType,colorSpace:t.SRGBColorSpace,minFilter:t.LinearFilter,magFilter:t.LinearFilter}),this._hdrTexture=e instanceof t.Texture?e:e instanceof t.TextureNode?e.value:null,this._hdrSource=e instanceof i?e:null,this.hdr=e instanceof t.Texture?r.texture(e):e,this._width=a.width,this._height=a.height,!(this._hdrTexture||this._width&&this._height))throw new Error("SDRRenditionNode: width and height are required when the HDR input is not a texture");this.uniforms={exposure:r.uniform(1),brightness:r.uniform(0),contrast:r.uniform(1),saturation:r.uniform(1)},this._material.name="SDRRendition",this._material.blending=t.NoBlending,this._material.depthTest=!1,this._material.depthWrite=!1,this.setToneMapping(a.toneMapping??t.ACESFilmicToneMapping)}get exposure(){return this.uniforms.exposure}get brightness(){return this.uniforms.brightness}get contrast(){return this.uniforms.contrast}get saturation(){return this.uniforms.saturation}getToneMapping(){return this._toneMapping}setToneMapping(e){return this._toneMapping=e,this._material.fragmentNode=this._buildOutput(),this._material.needsUpdate=!0,this}get width(){return this._width?this._width:this._hdrSource?this._hdrSource.width:this._hdrTexture?c(this._hdrTexture).width:0}get height(){return this._height?this._height:this._hdrSource?this._hdrSource.height:this._hdrTexture?c(this._hdrTexture).height:0}_buildOutput(){const e=this.uniforms,t=r.vec4(this.hdr),a=r.vec4(r.toneMapping(this._toneMapping,r.float(1),t.rgb.mul(e.exposure)).rgb,t.a),i=e.brightness,n=r.mat4(1,0,0,0,0,1,0,0,0,0,1,0,i,i,i,1),s=e.contrast,o=r.float(1).sub(s).div(2),d=r.mat4(s,0,0,0,0,s,0,0,0,0,s,0,o,o,o,1),h=r.vec3(.3086,.6094,.082),u=r.float(1).sub(e.saturation),m=r.vec3(h.x.mul(u)).add(r.vec3(e.saturation,0,0)),c=r.vec3(h.y.mul(u)).add(r.vec3(0,e.saturation,0)),l=r.vec3(h.z.mul(u)).add(r.vec3(0,0,e.saturation)),p=r.mat4(r.vec4(m,0),r.vec4(c,0),r.vec4(l,0),r.vec4(0,0,0,1));return n.mul(d).mul(p).mul(a)}_getState(){const e=this.uniforms;return[this._hdrTexture?.id,this._hdrTexture?.version,this._toneMapping,e.exposure.value,e.brightness.value,e.contrast.value,e.saturation.value]}_getDependencies(){return this._hdrSource?[this._hdrSource]:[]}}const p=2**-16;class g extends h{_encoder;constructor(e){super(),this._encoder=e,this.setTextures(e.sdr,e.gainMap).setMetadata(e.metadata)}_getState(){const{gamma:e,offsetSdr:t,offsetHdr:r,gainMapMin:a,gainMapMax:i,hdrCapacityMin:n,hdrCapacityMax:s}=this._encoder.metadata,o=this.uniforms;return o.gamma.value.fromArray(e),o.offsetSdr.value.fromArray(t),o.offsetHdr.value.fromArray(r),o.gainMapMin.value.fromArray(a),o.gainMapMax.value.fromArray(i),o.hdrCapacityMin.value=n,o.hdrCapacityMax.value=s,super._getState()}}e.GainMapEncoder=class{sdr;gainMap;_ownedTexture;constructor(e,r={}){let a;e instanceof t.Texture||!("data"in e)?(a=e,this._ownedTexture=null):a=this._ownedTexture=s(e),this.sdr=new l(a,r),this.gainMap=new m(this.sdr,r)}get width(){return this.sdr.width}get height(){return this.sdr.height}get metadata(){return this.gainMap.metadata}async fitMaxContentBoost(e){const t=Math.max(...await d(this.sdr.hdr,"max",e,this));return this.gainMap.maxContentBoost.value=t,t}async fitContentBoost(e){this.sdr.render(e);const t=r.vec4(this.gainMap.pixelGain,1),a={width:this.width,height:this.height},i=await d(t,"min",e,a),n=await d(t,"max",e,a),s=Math.max(p,Math.min(1,...i)),o=Math.max(1.0001,...n);return this.gainMap.minContentBoost.value=s,this.gainMap.maxContentBoost.value=o,{min:s,max:o}}createPreviewNode(){return new g(this)}render(e){this.gainMap.render(e)}async read(e){this.render(e);const t=this.metadata,[r,a]=await Promise.all([o(e,this.sdr.renderTarget),o(e,this.gainMap.renderTarget)]);return{sdr:new ImageData(new Uint8ClampedArray(r),this.width,this.height),gainMap:new ImageData(new Uint8ClampedArray(a),this.width,this.height),metadata:t}}async compress(e,t){const{sdr:r,gainMap:a,metadata:i}=await this.read(e),{withWorker:s,...o}=t;if(s){const[e,t]=await Promise.all([s.compress({...o,source:r}),s.compress({...o,source:a})]);return{...i,sdr:e,gainMap:t,rawSDR:e.source,rawGainMap:t.source}}const[d,h]=await Promise.all([n({...o,source:r}),n({...o,source:a})]);return{...i,sdr:d,gainMap:h,rawSDR:r.data,rawGainMap:a.data}}dispose(){this.sdr.dispose(),this.gainMap.dispose(),this._ownedTexture?.dispose()}},e.GainMapEncoderNode=m,e.RenderTargetNode=i,e.SDRRenditionNode=l,e.compress=n,e.findTextureMinMax=d,e.gainMapEncoder=(e,t)=>new m(e,t),e.sdrRendition=(e,t)=>new l(e,t)});
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.7.3
2
+ * @monogrid/gainmap-js v3.7.4
3
3
  * With ❤️, by MONOGRID <gainmap@monogrid.com>
4
4
  */
5
5
  import{DataTexture as e,RGBAFormat as a,UVMapping as r,RepeatWrapping as t,LinearFilter as i,LinearSRGBColorSpace as o}from"three";const n=n=>{let d;if(n instanceof e){if(!(n.image.data instanceof Uint16Array||n.image.data instanceof Float32Array))throw new Error("Provided image is not HDR");d=n}else{if(!n.data||!n.width||!n.height)throw new Error("Provided image has no data or size");d=new e(n.data,n.width,n.height,n.format??a,n.type,r,t,t,i,i,1,"colorSpace"in n&&"srgb"===n.colorSpace?n.colorSpace:o),"header"in n&&"gamma"in n&&(d.flipY=!0),d.needsUpdate=!0}return d};export{n as g};
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.7.3
2
+ * @monogrid/gainmap-js v3.7.4
3
3
  * With ❤️, by MONOGRID <gainmap@monogrid.com>
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.7.3
2
+ * @monogrid/gainmap-js v3.7.4
3
3
  * With ❤️, by MONOGRID <gainmap@monogrid.com>
4
4
  */
5
5
  const t="urn:iso:std:iso:ts:21496:-1\0",n=4294967295,r=new Uint8Array(4),e=t=>{const r=[0,1,2].map(n=>[t.gainMapMin[n],t.gainMapMax[n],t.gamma[n],t.offsetSdr[n],t.offsetHdr[n]]),e=r.some(t=>t.some((t,n)=>t!==r[0][n])),a=e?3:1,s=new Uint8Array(21+40*a),o=new DataView(s.buffer);let i=4;o.setUint8(i++,64|(e?128:0));const f=(t,r)=>{const[e,a]=((t,r)=>{const e=r?2147483647:n;if(!Number.isFinite(t)||!r&&t<0||Math.abs(t)>e)throw new Error(`Cannot represent ${t} as an ${r?"signed":"unsigned"} ISO 21496-1 fraction`);const a=Math.min(n,Math.floor(e/Math.max(1,Math.abs(t))));return[Math.round(t*a),a]})(t,r);r?o.setInt32(i,e):o.setUint32(i,e),o.setUint32(i+4,a),i+=8};f(t.hdrCapacityMin,!1),f(t.hdrCapacityMax,!1);for(let t=0;t<a;t++){const[n,e,a,s,o]=r[t];f(n,!0),f(e,!0),f(a,!1),f(s,!0),f(o,!0)}return s},a=t=>{const n=new DataView(t.buffer,t.byteOffset,t.byteLength);let r=0;const e=()=>{const t=n.getUint16(r);return r+=2,t},a=()=>{const t=n.getUint32(r);return r+=4,t},s=e();if(0!==s)throw new Error(`Unsupported ISO 21496-1 minimum_version ${s}`);e();const o=n.getUint8(r++);if(4&o)throw new Error("ISO 21496-1 metadata with HDR base image is not supported");const i=128&o?3:1,f=8&o?a():void 0,h=t=>{const e=t?(()=>{const t=n.getInt32(r);return r+=4,t})():a(),s=f??a();if(0===s)throw new Error("Invalid ISO 21496-1 fraction with zero denominator");return e/s},c=h(!1),p=h(!1);if(c>p)throw new Error("ISO 21496-1 metadata with HDR base image is not supported");const u=[],d=[],w=[],m=[],M=[];for(let t=0;t<i;t++)u.push(h(!0)),d.push(h(!0)),w.push(h(!1)),m.push(h(!0)),M.push(h(!0));const g=t=>3===i?t:[t[0],t[0],t[0]];return{gainMapMin:g(u),gainMapMax:g(d),gamma:g(w),offsetSdr:g(m),offsetHdr:g(M),hdrCapacityMin:c,hdrCapacityMax:p}};export{t as I,r as a,a as d,e};
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.7.3
2
+ * @monogrid/gainmap-js v3.7.4
3
3
  * With ❤️, by MONOGRID <gainmap@monogrid.com>
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
- import { GainMapMetadata } from '../core/types';
2
- import { type CompressedImage } from '../encode/types';
1
+ import { GainMapMetadata } from '../core/types.js';
2
+ import { type CompressedImage } from '../encode/types.js';
3
3
  /**
4
4
  * Encapsulates a Gainmap into a single JPEG file (aka: JPEG-R) with the base map
5
5
  * as the sdr visualization and the gainMap encoded into a MPF (Multi-Picture Format) tag.
@@ -2,8 +2,8 @@
2
2
  * JPEG assembler for creating JPEG-R (JPEG with gain map) files
3
3
  * Based on libultrahdr jpegr.cpp implementation
4
4
  */
5
- import { GainMapMetadataExtended } from '../core/types';
6
- import { type CompressedImage } from '../encode/types';
5
+ import { GainMapMetadataExtended } from '../core/types.js';
6
+ import { type CompressedImage } from '../encode/types.js';
7
7
  /**
8
8
  * Options for assembling a JPEG with gain map
9
9
  */
@@ -2,7 +2,7 @@
2
2
  * XMP metadata generator for gain map images
3
3
  * Based on libultrahdr jpegrutils.cpp implementation
4
4
  */
5
- import { type GainMapMetadataExtended } from '../core/types';
5
+ import { type GainMapMetadataExtended } from '../core/types.js';
6
6
  /**
7
7
  * Generate XMP metadata for the primary image
8
8
  *
@@ -1 +1 @@
1
- export * from './libultrahdr/encode-jpeg-metadata';
1
+ export * from './libultrahdr/encode-jpeg-metadata.js';
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.7.3
2
+ * @monogrid/gainmap-js v3.7.4
3
3
  * With ❤️, by MONOGRID <gainmap@monogrid.com>
4
4
  */
5
5
 
6
- import { I as ISO_NAMESPACE, e as encodeISOGainMapMetadata, a as ISO_VERSION_ONLY } from './iso-gainmap-metadata-BnRsn_xQ.js';
6
+ import { I as ISO_NAMESPACE, e as encodeISOGainMapMetadata, a as ISO_VERSION_ONLY } from './iso-gainmap-metadata-bR9G0ypA.js';
7
7
 
8
8
  /**
9
9
  * JPEG marker constants
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.7.3
2
+ * @monogrid/gainmap-js v3.7.4
3
3
  * With ❤️, by MONOGRID <gainmap@monogrid.com>
4
4
  */
5
- import{I as t,e,a as n}from"./iso-gainmap-metadata-CwcJfksX.js";const a=216,r=225,s=226,i=218,p={SIGNATURE:new Uint8Array([77,80,70,0]),BIG_ENDIAN:new Uint8Array([77,77]),TIFF_MAGIC:42,NUM_PICTURES:2,TAG_COUNT:3,TAG_SIZE:12,MP_ENTRY_SIZE:16},o=45056,h=45057,g=45058,m=7,c=4,d=0,u=196608,f=new Uint8Array([48,49,48,48]);function l(){return p.SIGNATURE.length+2+2+4+2+p.TAG_COUNT*p.TAG_SIZE+4+p.NUM_PICTURES*p.MP_ENTRY_SIZE}const M="Primary",U="GainMap",x="image/jpeg";function y(t){return String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}function w(t,e){const n=new Uint8Array(t.length+e.length);return n.set(t,0),n.set(e,t.length),n}function T(t,e,n,a){const r=new DataView(t.buffer,t.byteOffset,t.byteLength);if(r.setUint8(e++,255),r.setUint8(e++,n),a&&a.length>0){const n=a.length+2;r.setUint16(e,n,!1),e+=2,t.set(a,e),e+=a.length}return e}function I(I){const{sdr:A,gainMap:E,metadata:C,exif:S,icc:R}=I;if("image/jpeg"!==A.mimeType)throw new Error("SDR image must be JPEG format");if("image/jpeg"!==E.mimeType)throw new Error("Gain map image must be JPEG format");const b=function(t){const e=new DataView(t.buffer,t.byteOffset,t.byteLength);if(255!==e.getUint8(0)||e.getUint8(1)!==a)return null;let n=2;const s="Exif\0\0";for(;n<t.length-1&&255===e.getUint8(n);){const a=e.getUint8(n+1);if(a===i)break;if(a===r){const a=e.getUint16(n+2,!1),r=n+4;let i=!0;for(let e=0;e<6;e++)if(r+e>=t.length||t[r+e]!==s.charCodeAt(e)){i=!1;break}if(i){const e=a-2;return{data:t.slice(r,r+e),pos:n,size:a+2}}}n+=2+e.getUint16(n+2,!1)}return null}(A.data);if(b&&S)throw new Error("Primary image already contains EXIF data, cannot add external EXIF");let G=A.data,D=S;b&&(G=function(t,e,n){const a=t.length-n,r=new Uint8Array(a);return r.set(t.subarray(0,e),0),r.set(t.subarray(e+n),e),r}(A.data,b.pos,b.size),D=b.data);const N=function(t){const e=[],n=t.hdrCapacityMin,a=t.hdrCapacityMax,r=t=>Array.isArray(t)?t.reduce((t,e)=>t+e,0)/t.length:t,s=r(t.gainMapMin),i=r(t.gainMapMax),p=r(t.gamma),o=r(t.offsetSdr),h=r(t.offsetHdr);return e.push('<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>'),e.push('<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.1.2">'),e.push(' <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'),e.push(" <rdf:Description"),e.push(' xmlns:hdrgm="http://ns.adobe.com/hdr-gain-map/1.0/"'),e.push(` hdrgm:Version="${y(t.version)}"`),e.push(` hdrgm:GainMapMin="${y(s)}"`),e.push(` hdrgm:GainMapMax="${y(i)}"`),e.push(` hdrgm:Gamma="${y(p)}"`),e.push(` hdrgm:OffsetSDR="${y(o)}"`),e.push(` hdrgm:OffsetHDR="${y(h)}"`),e.push(` hdrgm:HDRCapacityMin="${y(n)}"`),e.push(` hdrgm:HDRCapacityMax="${y(a)}"`),e.push(' hdrgm:BaseRenditionIsHDR="False"'),e.push(' rdf:about=""/>'),e.push(" </rdf:RDF>"),e.push("</x:xmpmeta>"),e.push('<?xpacket end="w"?>'),e.join("\n")}(C),_=(new TextEncoder).encode(N),$=(new TextEncoder).encode("http://ns.adobe.com/xap/1.0/\0"),P=new Uint8Array($.length+_.length);P.set($,0),P.set(_,$.length);const F=(new TextEncoder).encode(t),j=w(F,n),k=w(F,e(C)),H=6+P.length+2+2+k.length+(E.data.length-2),z=function(t,e){const n=[];return n.push('<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>'),n.push('<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.1.2">'),n.push(' <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'),n.push(" <rdf:Description"),n.push(' xmlns:Container="http://ns.google.com/photos/1.0/container/"'),n.push(' xmlns:Item="http://ns.google.com/photos/1.0/container/item/"'),n.push(' xmlns:hdrgm="http://ns.adobe.com/hdr-gain-map/1.0/"'),n.push(` hdrgm:Version="${y(e.version)}"`),n.push(' rdf:about="">'),n.push(" <Container:Directory>"),n.push(" <rdf:Seq>"),n.push(' <rdf:li rdf:parseType="Resource">'),n.push(" <Container:Item"),n.push(` Item:Semantic="${M}"`),n.push(` Item:Mime="${x}"/>`),n.push(" </rdf:li>"),n.push(' <rdf:li rdf:parseType="Resource">'),n.push(" <Container:Item"),n.push(` Item:Semantic="${U}"`),n.push(` Item:Mime="${x}"`),n.push(` Item:Length="${t}"/>`),n.push(" </rdf:li>"),n.push(" </rdf:Seq>"),n.push(" </Container:Directory>"),n.push(" </rdf:Description>"),n.push(" </rdf:RDF>"),n.push("</x:xmpmeta>"),n.push('<?xpacket end="w"?>'),n.join("\n")}(H,C),O=(new TextEncoder).encode(z),B=new Uint8Array($.length+O.length);B.set($,0),B.set(O,$.length);const V=l();let Z=2;D&&(Z+=4+D.length),Z+=4+B.length,R&&(Z+=4+R.length),Z+=4+j.length,Z+=4+V,Z+=G.length-2,Z+=H;const X=Z-H,q=function(t,e,n,a){const r=l(),s=new ArrayBuffer(r),i=new DataView(s),M=new Uint8Array(s);let U=0;M.set(p.SIGNATURE,U),U+=p.SIGNATURE.length,M.set(p.BIG_ENDIAN,U);const x=!1;U+=2,i.setUint16(U,p.TIFF_MAGIC,x),U+=2,i.setUint32(U,8,x),U+=4,i.setUint16(U,p.TAG_COUNT,x),U+=2,i.setUint16(U,o,x),U+=2,i.setUint16(U,m,x),U+=2,i.setUint32(U,f.length,x),U+=4,M.set(f,U),U+=4,i.setUint16(U,h,x),U+=2,i.setUint16(U,c,x),U+=2,i.setUint32(U,1,x),U+=4,i.setUint32(U,p.NUM_PICTURES,x),U+=4,i.setUint16(U,g,x),U+=2,i.setUint16(U,m,x),U+=2,i.setUint32(U,p.MP_ENTRY_SIZE*p.NUM_PICTURES,x),U+=4;const y=U-p.SIGNATURE.length+4+4;return i.setUint32(U,y,x),U+=4,i.setUint32(U,0,x),U+=4,i.setUint32(U,d|u,x),U+=4,i.setUint32(U,t,x),U+=4,i.setUint32(U,e,x),U+=4,i.setUint16(U,0,x),U+=2,i.setUint16(U,0,x),U+=2,i.setUint32(U,d,x),U+=4,i.setUint32(U,n,x),U+=4,i.setUint32(U,a,x),U+=4,i.setUint16(U,0,x),U+=2,i.setUint16(U,0,x),M}(X,0,H,X-(2+(D?4+D.length:0)+2+2+B.length+(R?4+R.length:0)+2+2+j.length+2+2+4)),v=new Uint8Array(Z);let L=0;return L=T(v,L,a),D&&(L=T(v,L,r,D)),L=T(v,L,r,B),R&&(L=T(v,L,s,R)),L=T(v,L,s,j),L=T(v,L,s,q),v.set(G.subarray(2),L),L+=G.length-2,L=T(v,L,a),L=T(v,L,r,P),L=T(v,L,s,k),v.set(E.data.subarray(2),L),v}const A=t=>{if("image/jpeg"!==t.sdr.mimeType)throw new Error("This function expects an SDR image compressed in jpeg");if("image/jpeg"!==t.gainMap.mimeType)throw new Error("This function expects a GainMap image compressed in jpeg");const e={version:"1.0",gainMapMin:t.gainMapMin,gainMapMax:t.gainMapMax,gamma:t.gamma,offsetSdr:t.offsetSdr,offsetHdr:t.offsetHdr,hdrCapacityMin:t.hdrCapacityMin,hdrCapacityMax:t.hdrCapacityMax,minContentBoost:Array.isArray(t.gainMapMin)?Math.pow(2,t.gainMapMin.reduce((t,e)=>t+e,0)/t.gainMapMin.length):Math.pow(2,t.gainMapMin),maxContentBoost:Array.isArray(t.gainMapMax)?Math.pow(2,t.gainMapMax.reduce((t,e)=>t+e,0)/t.gainMapMax.length):Math.pow(2,t.gainMapMax)};return I({sdr:t.sdr,gainMap:t.gainMap,metadata:e})};export{A as encodeJPEGMetadata};
5
+ import{I as t,e,a as n}from"./iso-gainmap-metadata-B_FgeS_d.js";const a=216,r=225,s=226,i=218,p={SIGNATURE:new Uint8Array([77,80,70,0]),BIG_ENDIAN:new Uint8Array([77,77]),TIFF_MAGIC:42,NUM_PICTURES:2,TAG_COUNT:3,TAG_SIZE:12,MP_ENTRY_SIZE:16},o=45056,h=45057,g=45058,m=7,c=4,d=0,u=196608,f=new Uint8Array([48,49,48,48]);function l(){return p.SIGNATURE.length+2+2+4+2+p.TAG_COUNT*p.TAG_SIZE+4+p.NUM_PICTURES*p.MP_ENTRY_SIZE}const M="Primary",U="GainMap",x="image/jpeg";function y(t){return String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}function w(t,e){const n=new Uint8Array(t.length+e.length);return n.set(t,0),n.set(e,t.length),n}function T(t,e,n,a){const r=new DataView(t.buffer,t.byteOffset,t.byteLength);if(r.setUint8(e++,255),r.setUint8(e++,n),a&&a.length>0){const n=a.length+2;r.setUint16(e,n,!1),e+=2,t.set(a,e),e+=a.length}return e}function I(I){const{sdr:A,gainMap:E,metadata:C,exif:S,icc:R}=I;if("image/jpeg"!==A.mimeType)throw new Error("SDR image must be JPEG format");if("image/jpeg"!==E.mimeType)throw new Error("Gain map image must be JPEG format");const b=function(t){const e=new DataView(t.buffer,t.byteOffset,t.byteLength);if(255!==e.getUint8(0)||e.getUint8(1)!==a)return null;let n=2;const s="Exif\0\0";for(;n<t.length-1&&255===e.getUint8(n);){const a=e.getUint8(n+1);if(a===i)break;if(a===r){const a=e.getUint16(n+2,!1),r=n+4;let i=!0;for(let e=0;e<6;e++)if(r+e>=t.length||t[r+e]!==s.charCodeAt(e)){i=!1;break}if(i){const e=a-2;return{data:t.slice(r,r+e),pos:n,size:a+2}}}n+=2+e.getUint16(n+2,!1)}return null}(A.data);if(b&&S)throw new Error("Primary image already contains EXIF data, cannot add external EXIF");let G=A.data,D=S;b&&(G=function(t,e,n){const a=t.length-n,r=new Uint8Array(a);return r.set(t.subarray(0,e),0),r.set(t.subarray(e+n),e),r}(A.data,b.pos,b.size),D=b.data);const N=function(t){const e=[],n=t.hdrCapacityMin,a=t.hdrCapacityMax,r=t=>Array.isArray(t)?t.reduce((t,e)=>t+e,0)/t.length:t,s=r(t.gainMapMin),i=r(t.gainMapMax),p=r(t.gamma),o=r(t.offsetSdr),h=r(t.offsetHdr);return e.push('<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>'),e.push('<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.1.2">'),e.push(' <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'),e.push(" <rdf:Description"),e.push(' xmlns:hdrgm="http://ns.adobe.com/hdr-gain-map/1.0/"'),e.push(` hdrgm:Version="${y(t.version)}"`),e.push(` hdrgm:GainMapMin="${y(s)}"`),e.push(` hdrgm:GainMapMax="${y(i)}"`),e.push(` hdrgm:Gamma="${y(p)}"`),e.push(` hdrgm:OffsetSDR="${y(o)}"`),e.push(` hdrgm:OffsetHDR="${y(h)}"`),e.push(` hdrgm:HDRCapacityMin="${y(n)}"`),e.push(` hdrgm:HDRCapacityMax="${y(a)}"`),e.push(' hdrgm:BaseRenditionIsHDR="False"'),e.push(' rdf:about=""/>'),e.push(" </rdf:RDF>"),e.push("</x:xmpmeta>"),e.push('<?xpacket end="w"?>'),e.join("\n")}(C),_=(new TextEncoder).encode(N),$=(new TextEncoder).encode("http://ns.adobe.com/xap/1.0/\0"),P=new Uint8Array($.length+_.length);P.set($,0),P.set(_,$.length);const F=(new TextEncoder).encode(t),j=w(F,n),k=w(F,e(C)),H=6+P.length+2+2+k.length+(E.data.length-2),z=function(t,e){const n=[];return n.push('<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>'),n.push('<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.1.2">'),n.push(' <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'),n.push(" <rdf:Description"),n.push(' xmlns:Container="http://ns.google.com/photos/1.0/container/"'),n.push(' xmlns:Item="http://ns.google.com/photos/1.0/container/item/"'),n.push(' xmlns:hdrgm="http://ns.adobe.com/hdr-gain-map/1.0/"'),n.push(` hdrgm:Version="${y(e.version)}"`),n.push(' rdf:about="">'),n.push(" <Container:Directory>"),n.push(" <rdf:Seq>"),n.push(' <rdf:li rdf:parseType="Resource">'),n.push(" <Container:Item"),n.push(` Item:Semantic="${M}"`),n.push(` Item:Mime="${x}"/>`),n.push(" </rdf:li>"),n.push(' <rdf:li rdf:parseType="Resource">'),n.push(" <Container:Item"),n.push(` Item:Semantic="${U}"`),n.push(` Item:Mime="${x}"`),n.push(` Item:Length="${t}"/>`),n.push(" </rdf:li>"),n.push(" </rdf:Seq>"),n.push(" </Container:Directory>"),n.push(" </rdf:Description>"),n.push(" </rdf:RDF>"),n.push("</x:xmpmeta>"),n.push('<?xpacket end="w"?>'),n.join("\n")}(H,C),O=(new TextEncoder).encode(z),B=new Uint8Array($.length+O.length);B.set($,0),B.set(O,$.length);const V=l();let Z=2;D&&(Z+=4+D.length),Z+=4+B.length,R&&(Z+=4+R.length),Z+=4+j.length,Z+=4+V,Z+=G.length-2,Z+=H;const X=Z-H,q=function(t,e,n,a){const r=l(),s=new ArrayBuffer(r),i=new DataView(s),M=new Uint8Array(s);let U=0;M.set(p.SIGNATURE,U),U+=p.SIGNATURE.length,M.set(p.BIG_ENDIAN,U);const x=!1;U+=2,i.setUint16(U,p.TIFF_MAGIC,x),U+=2,i.setUint32(U,8,x),U+=4,i.setUint16(U,p.TAG_COUNT,x),U+=2,i.setUint16(U,o,x),U+=2,i.setUint16(U,m,x),U+=2,i.setUint32(U,f.length,x),U+=4,M.set(f,U),U+=4,i.setUint16(U,h,x),U+=2,i.setUint16(U,c,x),U+=2,i.setUint32(U,1,x),U+=4,i.setUint32(U,p.NUM_PICTURES,x),U+=4,i.setUint16(U,g,x),U+=2,i.setUint16(U,m,x),U+=2,i.setUint32(U,p.MP_ENTRY_SIZE*p.NUM_PICTURES,x),U+=4;const y=U-p.SIGNATURE.length+4+4;return i.setUint32(U,y,x),U+=4,i.setUint32(U,0,x),U+=4,i.setUint32(U,d|u,x),U+=4,i.setUint32(U,t,x),U+=4,i.setUint32(U,e,x),U+=4,i.setUint16(U,0,x),U+=2,i.setUint16(U,0,x),U+=2,i.setUint32(U,d,x),U+=4,i.setUint32(U,n,x),U+=4,i.setUint32(U,a,x),U+=4,i.setUint16(U,0,x),U+=2,i.setUint16(U,0,x),M}(X,0,H,X-(2+(D?4+D.length:0)+2+2+B.length+(R?4+R.length:0)+2+2+j.length+2+2+4)),v=new Uint8Array(Z);let L=0;return L=T(v,L,a),D&&(L=T(v,L,r,D)),L=T(v,L,r,B),R&&(L=T(v,L,s,R)),L=T(v,L,s,j),L=T(v,L,s,q),v.set(G.subarray(2),L),L+=G.length-2,L=T(v,L,a),L=T(v,L,r,P),L=T(v,L,s,k),v.set(E.data.subarray(2),L),v}const A=t=>{if("image/jpeg"!==t.sdr.mimeType)throw new Error("This function expects an SDR image compressed in jpeg");if("image/jpeg"!==t.gainMap.mimeType)throw new Error("This function expects a GainMap image compressed in jpeg");const e={version:"1.0",gainMapMin:t.gainMapMin,gainMapMax:t.gainMapMax,gamma:t.gamma,offsetSdr:t.offsetSdr,offsetHdr:t.offsetHdr,hdrCapacityMin:t.hdrCapacityMin,hdrCapacityMax:t.hdrCapacityMax,minContentBoost:Array.isArray(t.gainMapMin)?Math.pow(2,t.gainMapMin.reduce((t,e)=>t+e,0)/t.gainMapMin.length):Math.pow(2,t.gainMapMin),maxContentBoost:Array.isArray(t.gainMapMax)?Math.pow(2,t.gainMapMax.reduce((t,e)=>t+e,0)/t.gainMapMax.length):Math.pow(2,t.gainMapMax)};return I({sdr:t.sdr,gainMap:t.gainMap,metadata:e})};export{A as encodeJPEGMetadata};
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.7.3
2
+ * @monogrid/gainmap-js v3.7.4
3
3
  * With ❤️, by MONOGRID <gainmap@monogrid.com>
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.7.3
2
+ * @monogrid/gainmap-js v3.7.4
3
3
  * With ❤️, by MONOGRID <gainmap@monogrid.com>
4
4
  */
5
5
  !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).libultrahdr={})}(this,function(t){"use strict";const e=4294967295,n=new Uint8Array(4),a=t=>{const n=[0,1,2].map(e=>[t.gainMapMin[e],t.gainMapMax[e],t.gamma[e],t.offsetSdr[e],t.offsetHdr[e]]),a=n.some(t=>t.some((t,e)=>t!==n[0][e])),r=a?3:1,s=new Uint8Array(21+40*r),i=new DataView(s.buffer);let o=4;i.setUint8(o++,64|(a?128:0));const p=(t,n)=>{const[a,r]=((t,n)=>{const a=n?2147483647:e;if(!Number.isFinite(t)||!n&&t<0||Math.abs(t)>a)throw new Error(`Cannot represent ${t} as an ${n?"signed":"unsigned"} ISO 21496-1 fraction`);const r=Math.min(e,Math.floor(a/Math.max(1,Math.abs(t))));return[Math.round(t*r),r]})(t,n);n?i.setInt32(o,a):i.setUint32(o,a),i.setUint32(o+4,r),o+=8};p(t.hdrCapacityMin,!1),p(t.hdrCapacityMax,!1);for(let t=0;t<r;t++){const[e,a,r,s,i]=n[t];p(e,!0),p(a,!0),p(r,!1),p(s,!0),p(i,!0)}return s},r=216,s=225,i=226,o=218,p={SIGNATURE:new Uint8Array([77,80,70,0]),BIG_ENDIAN:new Uint8Array([77,77]),TIFF_MAGIC:42,NUM_PICTURES:2,TAG_COUNT:3,TAG_SIZE:12,MP_ENTRY_SIZE:16},h=45056,g=45057,d=45058,c=7,u=4,m=0,f=196608,l=new Uint8Array([48,49,48,48]);function M(){return p.SIGNATURE.length+2+2+4+2+p.TAG_COUNT*p.TAG_SIZE+4+p.NUM_PICTURES*p.MP_ENTRY_SIZE}const U="Primary",x="GainMap",y="image/jpeg";function w(t){return String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}function T(t,e){const n=new Uint8Array(t.length+e.length);return n.set(t,0),n.set(e,t.length),n}function A(t,e,n,a){const r=new DataView(t.buffer,t.byteOffset,t.byteLength);if(r.setUint8(e++,255),r.setUint8(e++,n),a&&a.length>0){const n=a.length+2;r.setUint16(e,n,!1),e+=2,t.set(a,e),e+=a.length}return e}function E(t){const{sdr:e,gainMap:E,metadata:I,exif:b,icc:C}=t;if("image/jpeg"!==e.mimeType)throw new Error("SDR image must be JPEG format");if("image/jpeg"!==E.mimeType)throw new Error("Gain map image must be JPEG format");const S=function(t){const e=new DataView(t.buffer,t.byteOffset,t.byteLength);if(255!==e.getUint8(0)||e.getUint8(1)!==r)return null;let n=2;const a="Exif\0\0";for(;n<t.length-1&&255===e.getUint8(n);){const r=e.getUint8(n+1);if(r===o)break;if(r===s){const r=e.getUint16(n+2,!1),s=n+4;let i=!0;for(let e=0;e<6;e++)if(s+e>=t.length||t[s+e]!==a.charCodeAt(e)){i=!1;break}if(i){const e=r-2;return{data:t.slice(s,s+e),pos:n,size:r+2}}}n+=2+e.getUint16(n+2,!1)}return null}(e.data);if(S&&b)throw new Error("Primary image already contains EXIF data, cannot add external EXIF");let R=e.data,G=b;S&&(R=function(t,e,n){const a=t.length-n,r=new Uint8Array(a);return r.set(t.subarray(0,e),0),r.set(t.subarray(e+n),e),r}(e.data,S.pos,S.size),G=S.data);const D=function(t){const e=[],n=t.hdrCapacityMin,a=t.hdrCapacityMax,r=t=>Array.isArray(t)?t.reduce((t,e)=>t+e,0)/t.length:t,s=r(t.gainMapMin),i=r(t.gainMapMax),o=r(t.gamma),p=r(t.offsetSdr),h=r(t.offsetHdr);return e.push('<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>'),e.push('<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.1.2">'),e.push(' <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'),e.push(" <rdf:Description"),e.push(' xmlns:hdrgm="http://ns.adobe.com/hdr-gain-map/1.0/"'),e.push(` hdrgm:Version="${w(t.version)}"`),e.push(` hdrgm:GainMapMin="${w(s)}"`),e.push(` hdrgm:GainMapMax="${w(i)}"`),e.push(` hdrgm:Gamma="${w(o)}"`),e.push(` hdrgm:OffsetSDR="${w(p)}"`),e.push(` hdrgm:OffsetHDR="${w(h)}"`),e.push(` hdrgm:HDRCapacityMin="${w(n)}"`),e.push(` hdrgm:HDRCapacityMax="${w(a)}"`),e.push(' hdrgm:BaseRenditionIsHDR="False"'),e.push(' rdf:about=""/>'),e.push(" </rdf:RDF>"),e.push("</x:xmpmeta>"),e.push('<?xpacket end="w"?>'),e.join("\n")}(I),N=(new TextEncoder).encode(D),_=(new TextEncoder).encode("http://ns.adobe.com/xap/1.0/\0"),$=new Uint8Array(_.length+N.length);$.set(_,0),$.set(N,_.length);const P=(new TextEncoder).encode("urn:iso:std:iso:ts:21496:-1\0"),F=T(P,n),j=T(P,a(I)),k=6+$.length+2+2+j.length+(E.data.length-2),H=function(t,e){const n=[];return n.push('<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>'),n.push('<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.1.2">'),n.push(' <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'),n.push(" <rdf:Description"),n.push(' xmlns:Container="http://ns.google.com/photos/1.0/container/"'),n.push(' xmlns:Item="http://ns.google.com/photos/1.0/container/item/"'),n.push(' xmlns:hdrgm="http://ns.adobe.com/hdr-gain-map/1.0/"'),n.push(` hdrgm:Version="${w(e.version)}"`),n.push(' rdf:about="">'),n.push(" <Container:Directory>"),n.push(" <rdf:Seq>"),n.push(' <rdf:li rdf:parseType="Resource">'),n.push(" <Container:Item"),n.push(` Item:Semantic="${U}"`),n.push(` Item:Mime="${y}"/>`),n.push(" </rdf:li>"),n.push(' <rdf:li rdf:parseType="Resource">'),n.push(" <Container:Item"),n.push(` Item:Semantic="${x}"`),n.push(` Item:Mime="${y}"`),n.push(` Item:Length="${t}"/>`),n.push(" </rdf:li>"),n.push(" </rdf:Seq>"),n.push(" </Container:Directory>"),n.push(" </rdf:Description>"),n.push(" </rdf:RDF>"),n.push("</x:xmpmeta>"),n.push('<?xpacket end="w"?>'),n.join("\n")}(k,I),z=(new TextEncoder).encode(H),O=new Uint8Array(_.length+z.length);O.set(_,0),O.set(z,_.length);const B=M();let V=2;G&&(V+=4+G.length),V+=4+O.length,C&&(V+=4+C.length),V+=4+F.length,V+=4+B,V+=R.length-2,V+=k;const Z=V-k,X=function(t,e,n,a){const r=M(),s=new ArrayBuffer(r),i=new DataView(s),o=new Uint8Array(s);let U=0;o.set(p.SIGNATURE,U),U+=p.SIGNATURE.length,o.set(p.BIG_ENDIAN,U);const x=!1;U+=2,i.setUint16(U,p.TIFF_MAGIC,x),U+=2,i.setUint32(U,8,x),U+=4,i.setUint16(U,p.TAG_COUNT,x),U+=2,i.setUint16(U,h,x),U+=2,i.setUint16(U,c,x),U+=2,i.setUint32(U,l.length,x),U+=4,o.set(l,U),U+=4,i.setUint16(U,g,x),U+=2,i.setUint16(U,u,x),U+=2,i.setUint32(U,1,x),U+=4,i.setUint32(U,p.NUM_PICTURES,x),U+=4,i.setUint16(U,d,x),U+=2,i.setUint16(U,c,x),U+=2,i.setUint32(U,p.MP_ENTRY_SIZE*p.NUM_PICTURES,x),U+=4;const y=U-p.SIGNATURE.length+4+4;return i.setUint32(U,y,x),U+=4,i.setUint32(U,0,x),U+=4,i.setUint32(U,m|f,x),U+=4,i.setUint32(U,t,x),U+=4,i.setUint32(U,e,x),U+=4,i.setUint16(U,0,x),U+=2,i.setUint16(U,0,x),U+=2,i.setUint32(U,m,x),U+=4,i.setUint32(U,n,x),U+=4,i.setUint32(U,a,x),U+=4,i.setUint16(U,0,x),U+=2,i.setUint16(U,0,x),o}(Z,0,k,Z-(2+(G?4+G.length:0)+2+2+O.length+(C?4+C.length:0)+2+2+F.length+2+2+4)),q=new Uint8Array(V);let v=0;return v=A(q,v,r),G&&(v=A(q,v,s,G)),v=A(q,v,s,O),C&&(v=A(q,v,i,C)),v=A(q,v,i,F),v=A(q,v,i,X),q.set(R.subarray(2),v),v+=R.length-2,v=A(q,v,r),v=A(q,v,s,$),v=A(q,v,i,j),q.set(E.data.subarray(2),v),q}t.encodeJPEGMetadata=t=>{if("image/jpeg"!==t.sdr.mimeType)throw new Error("This function expects an SDR image compressed in jpeg");if("image/jpeg"!==t.gainMap.mimeType)throw new Error("This function expects a GainMap image compressed in jpeg");const e={version:"1.0",gainMapMin:t.gainMapMin,gainMapMax:t.gainMapMax,gamma:t.gamma,offsetSdr:t.offsetSdr,offsetHdr:t.offsetHdr,hdrCapacityMin:t.hdrCapacityMin,hdrCapacityMax:t.hdrCapacityMax,minContentBoost:Array.isArray(t.gainMapMin)?Math.pow(2,t.gainMapMin.reduce((t,e)=>t+e,0)/t.gainMapMin.length):Math.pow(2,t.gainMapMin),maxContentBoost:Array.isArray(t.gainMapMax)?Math.pow(2,t.gainMapMax.reduce((t,e)=>t+e,0)/t.gainMapMax.length):Math.pow(2,t.gainMapMax)};return E({sdr:t.sdr,gainMap:t.gainMap,metadata:e})}});
@@ -1,5 +1,5 @@
1
- import { type PromiseWorkerType, type WorkerInterfaceImplementation } from './worker-types';
2
- export * from './worker-types';
1
+ import { type PromiseWorkerType, type WorkerInterfaceImplementation } from './worker-types.js';
2
+ export * from './worker-types.js';
3
3
  /**
4
4
  * Wraps a Regular worker into a `PromiseWorker`
5
5
  *
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.7.3
2
+ * @monogrid/gainmap-js v3.7.4
3
3
  * With ❤️, by MONOGRID <gainmap@monogrid.com>
4
4
  */
5
5
 
6
- import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers-oyWUzYEt.js';
6
+ import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers-ipRjx41i.js';
7
7
 
8
8
  var lib$1;
9
9
  var hasRequiredLib$1;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.7.3
2
+ * @monogrid/gainmap-js v3.7.4
3
3
  * With ❤️, by MONOGRID <gainmap@monogrid.com>
4
4
  */
5
- import{c as e,g as t}from"./_commonjsHelpers-DIhdSoQr.js";var r,n,o,s,i,c;function u(){if(s)return o;s=1;var t=function(){if(n)return r;n=1;var t,o,s=e.MutationObserver||e.WebKitMutationObserver;if(process.browser)if(s){var i=0,c=new s(f),u=e.document.createTextNode("");c.observe(u,{characterData:!0}),t=function(){u.data=i=++i%2}}else if(e.setImmediate||void 0===e.MessageChannel)t="document"in e&&"onreadystatechange"in e.document.createElement("script")?function(){var t=e.document.createElement("script");t.onreadystatechange=function(){f(),t.onreadystatechange=null,t.parentNode.removeChild(t),t=null},e.document.documentElement.appendChild(t)}:function(){setTimeout(f,0)};else{var a=new e.MessageChannel;a.port1.onmessage=f,t=function(){a.port2.postMessage(0)}}else t=function(){process.nextTick(f)};var l=[];function f(){var e,t;o=!0;for(var r=l.length;r;){for(t=l,l=[],e=-1;++e<r;)t[e]();r=l.length}o=!1}return r=function(e){1!==l.push(e)||o||t()}}();function i(){}var c={},u=["REJECTED"],a=["FULFILLED"],l=["PENDING"];if(!process.browser)var f=["UNHANDLED"];function h(e){if("function"!=typeof e)throw new TypeError("resolver must be a function");this.state=l,this.queue=[],this.outcome=void 0,process.browser||(this.handled=f),e!==i&&m(this,e)}function p(e,t,r){this.promise=e,"function"==typeof t&&(this.onFulfilled=t,this.callFulfilled=this.otherCallFulfilled),"function"==typeof r&&(this.onRejected=r,this.callRejected=this.otherCallRejected)}function v(e,r,n){t(function(){var t;try{t=r(n)}catch(t){return c.reject(e,t)}t===e?c.reject(e,new TypeError("Cannot resolve promise with itself")):c.resolve(e,t)})}function d(e){var t=e&&e.then;if(e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof t)return function(){t.apply(e,arguments)}}function m(e,t){var r=!1;function n(t){r||(r=!0,c.reject(e,t))}function o(t){r||(r=!0,c.resolve(e,t))}var s=y(function(){t(o,n)});"error"===s.status&&n(s.value)}function y(e,t){var r={};try{r.value=e(t),r.status="success"}catch(e){r.status="error",r.value=e}return r}return o=h,h.prototype.finally=function(e){if("function"!=typeof e)return this;var t=this.constructor;return this.then(function(r){return t.resolve(e()).then(function(){return r})},function(r){return t.resolve(e()).then(function(){throw r})})},h.prototype.catch=function(e){return this.then(null,e)},h.prototype.then=function(e,t){if("function"!=typeof e&&this.state===a||"function"!=typeof t&&this.state===u)return this;var r=new this.constructor(i);(process.browser||this.handled===f&&(this.handled=null),this.state!==l)?v(r,this.state===a?e:t,this.outcome):this.queue.push(new p(r,e,t));return r},p.prototype.callFulfilled=function(e){c.resolve(this.promise,e)},p.prototype.otherCallFulfilled=function(e){v(this.promise,this.onFulfilled,e)},p.prototype.callRejected=function(e){c.reject(this.promise,e)},p.prototype.otherCallRejected=function(e){v(this.promise,this.onRejected,e)},c.resolve=function(e,t){var r=y(d,t);if("error"===r.status)return c.reject(e,r.value);var n=r.value;if(n)m(e,n);else{e.state=a,e.outcome=t;for(var o=-1,s=e.queue.length;++o<s;)e.queue[o].callFulfilled(t)}return e},c.reject=function(e,r){e.state=u,e.outcome=r,process.browser||e.handled===f&&t(function(){e.handled===f&&process.emit("unhandledRejection",r,e)});for(var n=-1,o=e.queue.length;++n<o;)e.queue[n].callRejected(r);return e},h.resolve=function(e){if(e instanceof this)return e;return c.resolve(new this(i),e)},h.reject=function(e){var t=new this(i);return c.reject(t,e)},h.all=function(e){var t=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var r=e.length,n=!1;if(!r)return this.resolve([]);var o=new Array(r),s=0,u=-1,a=new this(i);for(;++u<r;)l(e[u],u);return a;function l(e,i){t.resolve(e).then(function(e){o[i]=e,++s!==r||n||(n=!0,c.resolve(a,o))},function(e){n||(n=!0,c.reject(a,e))})}},h.race=function(e){var t=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var r=e.length,n=!1;if(!r)return this.resolve([]);var o=-1,s=new this(i);for(;++o<r;)u(e[o]);return s;function u(e){t.resolve(e).then(function(e){n||(n=!0,c.resolve(s,e))},function(e){n||(n=!0,c.reject(s,e))})}},o}var a=function(){if(c)return i;c=1;var e="undefined"!=typeof Promise?Promise:u(),t=0;function r(e,t){var r=t.data;if(Array.isArray(r)&&!(r.length<2)){var n=r[0],o=r[1],s=r[2],i=e._callbacks[n];i&&(delete e._callbacks[n],i(o,s))}}function n(e){var t=this;t._worker=e,t._callbacks={},e.addEventListener("message",function(e){r(t,e)})}return n.prototype.postMessage=function(n,o){var s=this,i=t++,c=[i,n];return new e(function(e,t){if(s._callbacks[i]=function(r,n){if(r)return t(new Error(r.message));e(n)},void 0!==s._worker.controller){var n=new MessageChannel;n.port1.onmessage=function(e){r(s,e)},s._worker.controller.postMessage(c,[n.port2].concat(o))}else s._worker.postMessage(c,o)})},n.prototype.terminate=function(){this._worker.terminate()},i=n}(),l=t(a);const f=e=>new l(e),h=e=>({compress:t=>e.postMessage({type:"compress",payload:t})});export{f as getPromiseWorker,h as getWorkerInterface};
5
+ import{c as e,g as t}from"./_commonjsHelpers-DRi_W9o1.js";var r,n,o,s,i,c;function u(){if(s)return o;s=1;var t=function(){if(n)return r;n=1;var t,o,s=e.MutationObserver||e.WebKitMutationObserver;if(process.browser)if(s){var i=0,c=new s(f),u=e.document.createTextNode("");c.observe(u,{characterData:!0}),t=function(){u.data=i=++i%2}}else if(e.setImmediate||void 0===e.MessageChannel)t="document"in e&&"onreadystatechange"in e.document.createElement("script")?function(){var t=e.document.createElement("script");t.onreadystatechange=function(){f(),t.onreadystatechange=null,t.parentNode.removeChild(t),t=null},e.document.documentElement.appendChild(t)}:function(){setTimeout(f,0)};else{var a=new e.MessageChannel;a.port1.onmessage=f,t=function(){a.port2.postMessage(0)}}else t=function(){process.nextTick(f)};var l=[];function f(){var e,t;o=!0;for(var r=l.length;r;){for(t=l,l=[],e=-1;++e<r;)t[e]();r=l.length}o=!1}return r=function(e){1!==l.push(e)||o||t()}}();function i(){}var c={},u=["REJECTED"],a=["FULFILLED"],l=["PENDING"];if(!process.browser)var f=["UNHANDLED"];function h(e){if("function"!=typeof e)throw new TypeError("resolver must be a function");this.state=l,this.queue=[],this.outcome=void 0,process.browser||(this.handled=f),e!==i&&m(this,e)}function p(e,t,r){this.promise=e,"function"==typeof t&&(this.onFulfilled=t,this.callFulfilled=this.otherCallFulfilled),"function"==typeof r&&(this.onRejected=r,this.callRejected=this.otherCallRejected)}function v(e,r,n){t(function(){var t;try{t=r(n)}catch(t){return c.reject(e,t)}t===e?c.reject(e,new TypeError("Cannot resolve promise with itself")):c.resolve(e,t)})}function d(e){var t=e&&e.then;if(e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof t)return function(){t.apply(e,arguments)}}function m(e,t){var r=!1;function n(t){r||(r=!0,c.reject(e,t))}function o(t){r||(r=!0,c.resolve(e,t))}var s=y(function(){t(o,n)});"error"===s.status&&n(s.value)}function y(e,t){var r={};try{r.value=e(t),r.status="success"}catch(e){r.status="error",r.value=e}return r}return o=h,h.prototype.finally=function(e){if("function"!=typeof e)return this;var t=this.constructor;return this.then(function(r){return t.resolve(e()).then(function(){return r})},function(r){return t.resolve(e()).then(function(){throw r})})},h.prototype.catch=function(e){return this.then(null,e)},h.prototype.then=function(e,t){if("function"!=typeof e&&this.state===a||"function"!=typeof t&&this.state===u)return this;var r=new this.constructor(i);(process.browser||this.handled===f&&(this.handled=null),this.state!==l)?v(r,this.state===a?e:t,this.outcome):this.queue.push(new p(r,e,t));return r},p.prototype.callFulfilled=function(e){c.resolve(this.promise,e)},p.prototype.otherCallFulfilled=function(e){v(this.promise,this.onFulfilled,e)},p.prototype.callRejected=function(e){c.reject(this.promise,e)},p.prototype.otherCallRejected=function(e){v(this.promise,this.onRejected,e)},c.resolve=function(e,t){var r=y(d,t);if("error"===r.status)return c.reject(e,r.value);var n=r.value;if(n)m(e,n);else{e.state=a,e.outcome=t;for(var o=-1,s=e.queue.length;++o<s;)e.queue[o].callFulfilled(t)}return e},c.reject=function(e,r){e.state=u,e.outcome=r,process.browser||e.handled===f&&t(function(){e.handled===f&&process.emit("unhandledRejection",r,e)});for(var n=-1,o=e.queue.length;++n<o;)e.queue[n].callRejected(r);return e},h.resolve=function(e){if(e instanceof this)return e;return c.resolve(new this(i),e)},h.reject=function(e){var t=new this(i);return c.reject(t,e)},h.all=function(e){var t=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var r=e.length,n=!1;if(!r)return this.resolve([]);var o=new Array(r),s=0,u=-1,a=new this(i);for(;++u<r;)l(e[u],u);return a;function l(e,i){t.resolve(e).then(function(e){o[i]=e,++s!==r||n||(n=!0,c.resolve(a,o))},function(e){n||(n=!0,c.reject(a,e))})}},h.race=function(e){var t=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var r=e.length,n=!1;if(!r)return this.resolve([]);var o=-1,s=new this(i);for(;++o<r;)u(e[o]);return s;function u(e){t.resolve(e).then(function(e){n||(n=!0,c.resolve(s,e))},function(e){n||(n=!0,c.reject(s,e))})}},o}var a=function(){if(c)return i;c=1;var e="undefined"!=typeof Promise?Promise:u(),t=0;function r(e,t){var r=t.data;if(Array.isArray(r)&&!(r.length<2)){var n=r[0],o=r[1],s=r[2],i=e._callbacks[n];i&&(delete e._callbacks[n],i(o,s))}}function n(e){var t=this;t._worker=e,t._callbacks={},e.addEventListener("message",function(e){r(t,e)})}return n.prototype.postMessage=function(n,o){var s=this,i=t++,c=[i,n];return new e(function(e,t){if(s._callbacks[i]=function(r,n){if(r)return t(new Error(r.message));e(n)},void 0!==s._worker.controller){var n=new MessageChannel;n.port1.onmessage=function(e){r(s,e)},s._worker.controller.postMessage(c,[n.port2].concat(o))}else s._worker.postMessage(c,o)})},n.prototype.terminate=function(){this._worker.terminate()},i=n}(),l=t(a);const f=e=>new l(e),h=e=>({compress:t=>e.postMessage({type:"compress",payload:t})});export{f as getPromiseWorker,h as getWorkerInterface};
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.7.3
2
+ * @monogrid/gainmap-js v3.7.4
3
3
  * With ❤️, by MONOGRID <gainmap@monogrid.com>
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.7.3
2
+ * @monogrid/gainmap-js v3.7.4
3
3
  * With ❤️, by MONOGRID <gainmap@monogrid.com>
4
4
  */
5
5
  !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["worker-interface"]={})}(this,function(e){"use strict";var t,n,r,o,i,s,u="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function c(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function a(){if(o)return r;o=1;var e=function(){if(n)return t;n=1;var e,r,o=u.MutationObserver||u.WebKitMutationObserver;if(process.browser)if(o){var i=0,s=new o(f),c=u.document.createTextNode("");s.observe(c,{characterData:!0}),e=function(){c.data=i=++i%2}}else if(u.setImmediate||void 0===u.MessageChannel)e="document"in u&&"onreadystatechange"in u.document.createElement("script")?function(){var e=u.document.createElement("script");e.onreadystatechange=function(){f(),e.onreadystatechange=null,e.parentNode.removeChild(e),e=null},u.document.documentElement.appendChild(e)}:function(){setTimeout(f,0)};else{var a=new u.MessageChannel;a.port1.onmessage=f,e=function(){a.port2.postMessage(0)}}else e=function(){process.nextTick(f)};var l=[];function f(){var e,t;r=!0;for(var n=l.length;n;){for(t=l,l=[],e=-1;++e<n;)t[e]();n=l.length}r=!1}return t=function(t){1!==l.push(t)||r||e()}}();function i(){}var s={},c=["REJECTED"],a=["FULFILLED"],l=["PENDING"];if(!process.browser)var f=["UNHANDLED"];function h(e){if("function"!=typeof e)throw new TypeError("resolver must be a function");this.state=l,this.queue=[],this.outcome=void 0,process.browser||(this.handled=f),e!==i&&y(this,e)}function p(e,t,n){this.promise=e,"function"==typeof t&&(this.onFulfilled=t,this.callFulfilled=this.otherCallFulfilled),"function"==typeof n&&(this.onRejected=n,this.callRejected=this.otherCallRejected)}function d(t,n,r){e(function(){var e;try{e=n(r)}catch(e){return s.reject(t,e)}e===t?s.reject(t,new TypeError("Cannot resolve promise with itself")):s.resolve(t,e)})}function v(e){var t=e&&e.then;if(e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof t)return function(){t.apply(e,arguments)}}function y(e,t){var n=!1;function r(t){n||(n=!0,s.reject(e,t))}function o(t){n||(n=!0,s.resolve(e,t))}var i=m(function(){t(o,r)});"error"===i.status&&r(i.value)}function m(e,t){var n={};try{n.value=e(t),n.status="success"}catch(e){n.status="error",n.value=e}return n}return r=h,h.prototype.finally=function(e){if("function"!=typeof e)return this;var t=this.constructor;return this.then(function(n){return t.resolve(e()).then(function(){return n})},function(n){return t.resolve(e()).then(function(){throw n})})},h.prototype.catch=function(e){return this.then(null,e)},h.prototype.then=function(e,t){if("function"!=typeof e&&this.state===a||"function"!=typeof t&&this.state===c)return this;var n=new this.constructor(i);(process.browser||this.handled===f&&(this.handled=null),this.state!==l)?d(n,this.state===a?e:t,this.outcome):this.queue.push(new p(n,e,t));return n},p.prototype.callFulfilled=function(e){s.resolve(this.promise,e)},p.prototype.otherCallFulfilled=function(e){d(this.promise,this.onFulfilled,e)},p.prototype.callRejected=function(e){s.reject(this.promise,e)},p.prototype.otherCallRejected=function(e){d(this.promise,this.onRejected,e)},s.resolve=function(e,t){var n=m(v,t);if("error"===n.status)return s.reject(e,n.value);var r=n.value;if(r)y(e,r);else{e.state=a,e.outcome=t;for(var o=-1,i=e.queue.length;++o<i;)e.queue[o].callFulfilled(t)}return e},s.reject=function(t,n){t.state=c,t.outcome=n,process.browser||t.handled===f&&e(function(){t.handled===f&&process.emit("unhandledRejection",n,t)});for(var r=-1,o=t.queue.length;++r<o;)t.queue[r].callRejected(n);return t},h.resolve=function(e){if(e instanceof this)return e;return s.resolve(new this(i),e)},h.reject=function(e){var t=new this(i);return s.reject(t,e)},h.all=function(e){var t=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var n=e.length,r=!1;if(!n)return this.resolve([]);var o=new Array(n),u=0,c=-1,a=new this(i);for(;++c<n;)l(e[c],c);return a;function l(e,i){t.resolve(e).then(function(e){o[i]=e,++u!==n||r||(r=!0,s.resolve(a,o))},function(e){r||(r=!0,s.reject(a,e))})}},h.race=function(e){var t=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var n=e.length,r=!1;if(!n)return this.resolve([]);var o=-1,u=new this(i);for(;++o<n;)c(e[o]);return u;function c(e){t.resolve(e).then(function(e){r||(r=!0,s.resolve(u,e))},function(e){r||(r=!0,s.reject(u,e))})}},r}var l=function(){if(s)return i;s=1;var e="undefined"!=typeof Promise?Promise:a(),t=0;function n(e,t){var n=t.data;if(Array.isArray(n)&&!(n.length<2)){var r=n[0],o=n[1],i=n[2],s=e._callbacks[r];s&&(delete e._callbacks[r],s(o,i))}}function r(e){var t=this;t._worker=e,t._callbacks={},e.addEventListener("message",function(e){n(t,e)})}return r.prototype.postMessage=function(r,o){var i=this,s=t++,u=[s,r];return new e(function(e,t){if(i._callbacks[s]=function(n,r){if(n)return t(new Error(n.message));e(r)},void 0!==i._worker.controller){var r=new MessageChannel;r.port1.onmessage=function(e){n(i,e)},i._worker.controller.postMessage(u,[r.port2].concat(o))}else i._worker.postMessage(u,o)})},r.prototype.terminate=function(){this._worker.terminate()},i=r}(),f=c(l);e.getPromiseWorker=e=>new f(e),e.getWorkerInterface=e=>({compress:t=>e.postMessage({type:"compress",payload:t})})});
@@ -1,4 +1,4 @@
1
- import { CompressedImage, type CompressParameters } from './encode/types';
1
+ import { CompressedImage, type CompressParameters } from './encode/types.js';
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 v3.7.3
2
+ * @monogrid/gainmap-js v3.7.4
3
3
  * With ❤️, by MONOGRID <gainmap@monogrid.com>
4
4
  */
5
5
 
6
- import { g as getDefaultExportFromCjs } from './_commonjsHelpers-oyWUzYEt.js';
7
- import { c as compress } from './compress-CSavQQ88.js';
6
+ import { g as getDefaultExportFromCjs } from './_commonjsHelpers-ipRjx41i.js';
7
+ import { c as compress } from './compress-DBf4K0k_.js';
8
8
 
9
9
  var isPromise = {exports: {}};
10
10
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.7.3
2
+ * @monogrid/gainmap-js v3.7.4
3
3
  * With ❤️, by MONOGRID <gainmap@monogrid.com>
4
4
  */
5
- import{g as e}from"./_commonjsHelpers-DIhdSoQr.js";import{c as r}from"./compress-ChfVEpLY.js";var n,t,o,s={exports:{}};function a(){if(n)return s.exports;function e(e){return!!e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof e.then}return n=1,s.exports=e,s.exports.default=e,s.exports}var f=function(){if(o)return t;o=1;var e=a();return t=function(r){function n(e,r,n,t){function o(r,n){"function"!=typeof self.postMessage?e.ports[0].postMessage(r,n):self.postMessage(r,n)}n?("undefined"!=typeof console&&"error"in console&&console.error("Worker caught an error:",n),o([r,{message:n.message}])):t instanceof s?o([r,null,t.message],t.transferList):o([r,null,t])}function t(e,r){return new s(e,r)}function o(r,o,s,a){var f=function(e,r){try{return{res:e(r,t)}}catch(e){return{err:e}}}(o,a);f.err?n(r,s,f.err):e(f.res)?f.res.then(function(e){n(r,s,null,e)},function(e){n(r,s,e)}):n(r,s,null,f.res)}function s(e,r){this.message=e,this.transferList=r}self.addEventListener("message",function(e){var t=e.data;if(Array.isArray(t)&&2===t.length){var s=t[0],a=t[1];"function"!=typeof r?n(e,s,new Error("Please pass a function into register().")):o(e,r,s,a)}})}}();e(f)(async(e,n)=>{if("compress"===e.type)return(async(e,n)=>{const t=await r(e.payload);return n({...t,source:e.payload.source instanceof ImageData?e.payload.source.data:new Uint8ClampedArray(e.payload.source)},[t.data.buffer,e.payload.source instanceof ImageData?e.payload.source.data.buffer:e.payload.source.buffer])})(e,n)});
5
+ import{g as e}from"./_commonjsHelpers-DRi_W9o1.js";import{c as r}from"./compress-DhuzUwR5.js";var n,t,o,s={exports:{}};function a(){if(n)return s.exports;function e(e){return!!e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof e.then}return n=1,s.exports=e,s.exports.default=e,s.exports}var f=function(){if(o)return t;o=1;var e=a();return t=function(r){function n(e,r,n,t){function o(r,n){"function"!=typeof self.postMessage?e.ports[0].postMessage(r,n):self.postMessage(r,n)}n?("undefined"!=typeof console&&"error"in console&&console.error("Worker caught an error:",n),o([r,{message:n.message}])):t instanceof s?o([r,null,t.message],t.transferList):o([r,null,t])}function t(e,r){return new s(e,r)}function o(r,o,s,a){var f=function(e,r){try{return{res:e(r,t)}}catch(e){return{err:e}}}(o,a);f.err?n(r,s,f.err):e(f.res)?f.res.then(function(e){n(r,s,null,e)},function(e){n(r,s,e)}):n(r,s,null,f.res)}function s(e,r){this.message=e,this.transferList=r}self.addEventListener("message",function(e){var t=e.data;if(Array.isArray(t)&&2===t.length){var s=t[0],a=t[1];"function"!=typeof r?n(e,s,new Error("Please pass a function into register().")):o(e,r,s,a)}})}}();e(f)(async(e,n)=>{if("compress"===e.type)return(async(e,n)=>{const t=await r(e.payload);return n({...t,source:e.payload.source instanceof ImageData?e.payload.source.data:new Uint8ClampedArray(e.payload.source)},[t.data.buffer,e.payload.source instanceof ImageData?e.payload.source.data.buffer:e.payload.source.buffer])})(e,n)});
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.7.3
2
+ * @monogrid/gainmap-js v3.7.4
3
3
  * With ❤️, by MONOGRID <gainmap@monogrid.com>
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.7.3
2
+ * @monogrid/gainmap-js v3.7.4
3
3
  * With ❤️, by MONOGRID <gainmap@monogrid.com>
4
4
  */
5
5
  !function(e){"function"==typeof define&&define.amd?define(e):e()}(function(){"use strict";function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var t,n,r,a={exports:{}};function o(){if(t)return a.exports;function e(e){return!!e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof e.then}return t=1,a.exports=e,a.exports.default=e,a.exports}var s=function(){if(r)return n;r=1;var e=o();return n=function(t){function n(e,t,n,r){function a(t,n){"function"!=typeof self.postMessage?e.ports[0].postMessage(t,n):self.postMessage(t,n)}n?("undefined"!=typeof console&&"error"in console&&console.error("Worker caught an error:",n),a([t,{message:n.message}])):r instanceof o?a([t,null,r.message],r.transferList):a([t,null,r])}function r(e,t){return new o(e,t)}function a(t,a,o,s){var i=function(e,t){try{return{res:e(t,r)}}catch(e){return{err:e}}}(a,s);i.err?n(t,o,i.err):e(i.res)?i.res.then(function(e){n(t,o,null,e)},function(e){n(t,o,e)}):n(t,o,null,i.res)}function o(e,t){this.message=e,this.transferList=t}self.addEventListener("message",function(e){var r=e.data;if(Array.isArray(r)&&2===r.length){var o=r[0],s=r[1];"function"!=typeof t?n(e,o,new Error("Please pass a function into register().")):a(e,t,o,s)}})}}();const i=async e=>{if("undefined"==typeof createImageBitmap)throw new Error("createImageBitmap() not supported.");const{source:t,mimeType:n,quality:r,flipY:a}=e;let o;if((t instanceof Uint8Array||t instanceof Uint8ClampedArray)&&"sourceMimeType"in e)o=new Blob([t],{type:e.sourceMimeType});else{if(!(t instanceof ImageData))throw new Error("Invalid source image");o=t}const s=await createImageBitmap(o),i=s.width,f=s.height;let c;"undefined"!=typeof OffscreenCanvas?c=new OffscreenCanvas(i,f):(c=document.createElement("canvas"),c.width=i,c.height=f);const u=c.getContext("2d");if(!u)throw new Error("Failed to create canvas Context");!0===a&&(u.translate(0,f),u.scale(1,-1)),u.drawImage(s,0,0,i,f);const l=await(async(e,t,n)=>{if("undefined"!=typeof OffscreenCanvas&&e instanceof OffscreenCanvas)return e.convertToBlob({type:t,quality:n});if(e instanceof HTMLCanvasElement)return new Promise((r,a)=>{e.toBlob(e=>{e?r(e):a(new Error("Failed to convert canvas to blob"))},t,n)});throw new Error("Unsupported canvas element")})(c,n,r||.9);return{data:new Uint8Array(await l.arrayBuffer()),mimeType:n,width:i,height:f}};e(s)(async(e,t)=>{if("compress"===e.type)return(async(e,t)=>{const n=await i(e.payload);return t({...n,source:e.payload.source instanceof ImageData?e.payload.source.data:new Uint8ClampedArray(e.payload.source)},[n.data.buffer,e.payload.source instanceof ImageData?e.payload.source.data.buffer:e.payload.source.buffer])})(e,t)})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monogrid/gainmap-js",
3
- "version": "3.7.3",
3
+ "version": "3.7.4",
4
4
  "description": "A Javascript (TypeScript) Port of Adobe Gainmap Technology for storing HDR Images using an SDR Image + a gain map",
5
5
  "keywords": [
6
6
  "hdr",