@geoscene/core 4.33.16 → 4.33.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/geoscene/core/workers/chunks/d9a23fb0c6c936d5e8ec.js +1 -1
- package/layers/support/LercWorker.js +1 -5
- package/layers/support/rasterDatasets/ImageServerRaster.js +1 -1
- package/layers/support/rasterFormats/ImageCanvasDecoder.js +1 -1
- package/layers/support/rasterFormats/RasterCodec.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";(self.webpackChunkRemoteClient=self.webpackChunkRemoteClient||[]).push([[7087],{34727:(e,t,n)=>{n.d(t,{$8:()=>
|
|
1
|
+
"use strict";(self.webpackChunkRemoteClient=self.webpackChunkRemoteClient||[]).push([[7087],{34727:(e,t,n)=>{n.d(t,{$8:()=>V,Cc:()=>l,Hx:()=>g,Io:()=>B,KJ:()=>u,Sp:()=>c,XM:()=>f,YN:()=>m,ZH:()=>d,cU:()=>a,gg:()=>h,hs:()=>s,kU:()=>o,or:()=>v,pF:()=>D,pq:()=>b,qE:()=>r});const i=new Float32Array(1);function a(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}function r(e,t,n){return Math.min(Math.max(e,t),n)}function l(e,t,n){return e+(t-e)*n}function s(e,t,n,i,a){return l(i,a,(e-t)/(n-t))}function o(e){return e*Math.PI/180}function u(e){return 180*e/Math.PI}function f(e){return Math.acos(r(e,-1,1))}function m(e){return Math.asin(r(e,-1,1))}function c(e,t,n=1e-6){return e===t||!(!Number.isFinite(e)||!Number.isFinite(t))&&(e>t?e-t:t-e)<=n}function h(e,t,n=1e-6){return!c(e,t,n)&&e>t}function d(e,t,n=1e-6){return!c(e,t,n)&&e<t}function g(e,t,n=1e-6){return c(e,t,n)||e>t}const w=new DataView(new ArrayBuffer(Float64Array.BYTES_PER_ELEMENT));function k(e){return w.setFloat64(0,e),w.getBigInt64(0)}const x=BigInt("1000000"),p=y(1);function y(e){const t=k(e=Math.abs(e)),n=function(e){return w.setBigInt64(0,e),w.getFloat64(0)}(t<=x?x:t-x);return Math.abs(e-n)}function B(e,t,n=p){if(e===t)return!0;if(!Number.isFinite(e)||!Number.isFinite(t))return!1;if(null!=n&&y(Math.min(Math.abs(e),Math.abs(t)))<n)return Math.abs(e-t)<=n;const i=k(e),a=k(t);return i<0==a<0&&!((i<a?a-i:i-a)>x)}function V(e){return M(Math.max(-b,Math.min(e,b)))}function M(e){return i[0]=e,i[0]}function v(e){const t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],n=e[3]*e[3]+e[4]*e[4]+e[5]*e[5],i=e[6]*e[6]+e[7]*e[7]+e[8]*e[8];return!(c(t,1)&&c(n,1)&&c(i,1))}const b=M(34028234663852886e22);function D(e,t,n){if(void 0===n||0==+n)return Math[e](t);if(t=+t,n=+n,isNaN(t)||"number"!=typeof n||n%1!=0)return NaN;let i=t.toString().split("e");return i=(t=Math[e](+(i[0]+"e"+(i[1]?+i[1]-n:-n)))).toString().split("e"),+(i[0]+"e"+(i[1]?+i[1]+n:n))}},57087:(e,t,n)=>{n.r(t),n.d(t,{default:()=>h});var i=n(34727),a={};a.defaultNoDataValue=(0,i.$8)(-1/0),a.decode=async(e,t)=>{if(-1!==String.fromCharCode.apply(null,new Uint8Array(e,t.inputOffset||0,20)).indexOf("PNG")||-1!==String.fromCharCode.apply(null,new Uint8Array(e,t.inputOffset||0,20)).indexOf("WEBP"))h=await f(e,t);else{var n=(t=t||{}).encodedMaskData||null===t.encodedMaskData,u=o(e,t.inputOffset||0,n),m=null!=t.noDataValue?(0,i.$8)(t.noDataValue):a.defaultNoDataValue,c=r(u,t.pixelType||Float32Array,t.encodedMaskData,m,t.returnMask),h={width:u.width,height:u.height,pixelData:c.resultPixels,minValue:u.pixels.minValue,maxValue:u.pixels.maxValue,noDataValue:m};c.resultMask&&(h.maskData=c.resultMask),t.returnEncodedMask&&u.mask&&(h.encodedMaskData=u.mask.bitset?u.mask.bitset:null),t.returnFileInfo&&(h.fileInfo=l(u,m),t.computeUsedBitDepths&&(h.fileInfo.bitDepths=s(u)))}return h};var r=function(e,t,n,i,a){var r,l,s=0,o=e.pixels.numBlocksX,f=e.pixels.numBlocksY,m=Math.floor(e.width/o),c=Math.floor(e.height/f),h=2*e.maxZError;n=n||(e.mask?e.mask.bitset:null),r=new t(e.width*e.height),a&&n&&(l=new Uint8Array(e.width*e.height));for(var d,g,w=new Float32Array(m*c),k=0;k<=f;k++){var x=k!==f?c:e.height%f;if(0!==x)for(var p=0;p<=o;p++){var y=p!==o?m:e.width%o;if(0!==y){var B,V,M,v,b=k*e.width*c+p*m,D=e.width-y,U=e.pixels.blocks[s];if(U.encoding<2?(0===U.encoding?B=U.rawData:(u(U.stuffedData,U.bitsPerPixel,U.numValidPixels,U.offset,h,w,e.pixels.maxValue),B=w),V=0):M=2===U.encoding?0:U.offset,n)for(g=0;g<x;g++){for(7&b&&(v=n[b>>3],v<<=7&b),d=0;d<y;d++)7&b||(v=n[b>>3]),128&v?(l&&(l[b]=1),r[b++]=U.encoding<2?B[V++]:M):(l&&(l[b]=0),r[b++]=i),v<<=1;b+=D}else if(U.encoding<2)for(g=0;g<x;g++){for(d=0;d<y;d++)r[b++]=B[V++];b+=D}else for(g=0;g<x;g++)if(r.fill)r.fill(M,b,b+y),b+=y+D;else{for(d=0;d<y;d++)r[b++]=M;b+=D}if(1===U.encoding&&V!==U.numValidPixels)throw"Block and Mask do not match";s++}}}return{resultPixels:r,resultMask:l}},l=function(e,t){return{fileIdentifierString:e.fileIdentifierString,fileVersion:e.fileVersion,imageType:e.imageType,height:e.height,width:e.width,maxZError:e.maxZError,eofOffset:e.eofOffset,mask:e.mask?{numBlocksX:e.mask.numBlocksX,numBlocksY:e.mask.numBlocksY,numBytes:e.mask.numBytes,maxValue:e.mask.maxValue}:null,pixels:{numBlocksX:e.pixels.numBlocksX,numBlocksY:e.pixels.numBlocksY,numBytes:e.pixels.numBytes,maxValue:e.pixels.maxValue,minValue:e.pixels.minValue,noDataValue:t}}},s=function(e){for(var t=e.pixels.numBlocksX*e.pixels.numBlocksY,n={},i=0;i<t;i++){var a=e.pixels.blocks[i];0===a.encoding?n.float32=!0:1===a.encoding?n[a.bitsPerPixel]=!0:n[0]=!0}return Object.keys(n)},o=function(e,t,n){var i={},a=new Uint8Array(e,t,10);if(i.fileIdentifierString=String.fromCharCode.apply(null,a),"CntZImage"!=i.fileIdentifierString.trim())throw"Unexpected file identifier string: "+i.fileIdentifierString;t+=10;var r=new DataView(e,t,24);if(i.fileVersion=r.getInt32(0,!0),i.imageType=r.getInt32(4,!0),i.height=r.getUint32(8,!0),i.width=r.getUint32(12,!0),i.maxZError=r.getFloat64(16,!0),t+=24,!n)if(r=new DataView(e,t,16),i.mask={},i.mask.numBlocksY=r.getUint32(0,!0),i.mask.numBlocksX=r.getUint32(4,!0),i.mask.numBytes=r.getUint32(8,!0),i.mask.maxValue=r.getFloat32(12,!0),t+=16,i.mask.numBytes>0){var l=new Uint8Array(Math.ceil(i.width*i.height/8)),s=(r=new DataView(e,t,i.mask.numBytes)).getInt16(0,!0),o=2,u=0;do{if(s>0)for(;s--;)l[u++]=r.getUint8(o++);else{var f=r.getUint8(o++);for(s=-s;s--;)l[u++]=f}s=r.getInt16(o,!0),o+=2}while(o<i.mask.numBytes);if(-32768!==s||u<l.length)throw"Unexpected end of mask RLE encoding";i.mask.bitset=l,t+=i.mask.numBytes}else 0==(i.mask.numBytes|i.mask.numBlocksY|i.mask.maxValue)&&(l=new Uint8Array(Math.ceil(i.width*i.height/8)),i.mask.bitset=l);r=new DataView(e,t,16),i.pixels={},i.pixels.numBlocksY=r.getUint32(0,!0),i.pixels.numBlocksX=r.getUint32(4,!0),i.pixels.numBytes=r.getUint32(8,!0),i.pixels.maxValue=r.getFloat32(12,!0),t+=16;var m=i.pixels.numBlocksX,c=i.pixels.numBlocksY,h=m+(i.width%m>0?1:0),d=c+(i.height%c>0?1:0);i.pixels.blocks=new Array(h*d);for(var g=1e9,w=0,k=0;k<d;k++)for(var x=0;x<h;x++){var p=0,y=e.byteLength-t;r=new DataView(e,t,Math.min(10,y));var B={};i.pixels.blocks[w++]=B;var V=r.getUint8(0);if(p++,B.encoding=63&V,B.encoding>3)throw"Invalid block encoding ("+B.encoding+")";if(2!==B.encoding){if(0!==V&&2!==V){if(V>>=6,B.offsetType=V,2===V)B.offset=r.getInt8(1),p++;else if(1===V)B.offset=r.getInt16(1,!0),p+=2;else{if(0!==V)throw"Invalid block offset type";B.offset=r.getFloat32(1,!0),p+=4}if(g=Math.min(B.offset,g),1===B.encoding)if(V=r.getUint8(p),p++,B.bitsPerPixel=63&V,V>>=6,B.numValidPixelsType=V,2===V)B.numValidPixels=r.getUint8(p),p++;else if(1===V)B.numValidPixels=r.getUint16(p,!0),p+=2;else{if(0!==V)throw"Invalid valid pixel count type";B.numValidPixels=r.getUint32(p,!0),p+=4}}var M;if(t+=p,3!=B.encoding)if(0===B.encoding){var v=(i.pixels.numBytes-1)/4;if(v!==Math.floor(v))throw"uncompressed block has invalid length";M=new ArrayBuffer(4*v),new Uint8Array(M).set(new Uint8Array(e,t,4*v));for(var b=new Float32Array(M),D=0;D<b.length;D++)g=Math.min(g,b[D]);B.rawData=b,t+=4*v}else if(1===B.encoding){var U=Math.ceil(B.numValidPixels*B.bitsPerPixel/8),I=Math.ceil(U/4);M=new ArrayBuffer(4*I),new Uint8Array(M).set(new Uint8Array(e,t,U)),B.stuffedData=new Uint32Array(M),t+=U}}else t++,g=Math.min(g,0)}return i.pixels.minValue=g,i.eofOffset=t,i},u=function(e,t,n,i,a,r,l){var s,o,u,f=(1<<t)-1,m=0,c=0,h=Math.ceil((l-i)/a),d=4*e.length-Math.ceil(t*n/8);for(e[e.length-1]<<=8*d,s=0;s<n;s++){if(0===c&&(u=e[m++],c=32),c>=t)o=u>>>c-t&f,c-=t;else{var g=t-c;o=(u&f)<<g&f,o+=(u=e[m++])>>>(c=32-g)}r[s]=o<h?i+o*a:l}return r},f=async(e,t)=>{const n=new Blob([e]),i=await createImageBitmap(n),a=new OffscreenCanvas(i.width,i.height),r=a.width=i.width,l=a.height=i.height,s=a.getContext("2d",{willReadFrequently:!0});if(!s)throw new Error("无法获取2D上下文");s.drawImage(i,0,0);const o=s.getImageData(0,0,a.width,a.height).data;for(var u=new(t.pixelType||Float32Array)(r*l),f=1/0,m=-1/0,c=0;c<l;c++)for(var h=0;h<r;h++){var d=c*r+h,g=4*d,w=.1*(256*(t=o[g])*256+256*o[g+1]+o[g+2])-1e4;u[d]=w,w<f&&(f=w),w>m&&(m=w)}return f===1/0&&(f=0),m===-1/0&&(m=0),{width:r,height:l,pixelData:u,minValue:f,maxValue:m,noDataValue:t.noDataValue||t.defaultNoDataValue}};const m=a.decode;class c{_decode(e){return m(e.buffer,e.options).then((e=>Promise.resolve({result:e,transferList:[e.pixelData.buffer]})))}}function h(){return new c}}}]);
|
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
|
-
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
|
-
*/
|
|
5
|
-
import{clampFloat32 as e}from"../../core/mathUtils.js";var t={};t.defaultNoDataValue=e(-1/0),t.decode=function(s,r){var o=(r=r||{}).encodedMaskData||null===r.encodedMaskData,f=l(s,r.inputOffset||0,o),u=null!=r.noDataValue?e(r.noDataValue):t.defaultNoDataValue,m=i(f,r.pixelType||Float32Array,r.encodedMaskData,u,r.returnMask),d={width:f.width,height:f.height,pixelData:m.resultPixels,minValue:f.pixels.minValue,maxValue:f.pixels.maxValue,noDataValue:u};return m.resultMask&&(d.maskData=m.resultMask),r.returnEncodedMask&&f.mask&&(d.encodedMaskData=f.mask.bitset?f.mask.bitset:null),r.returnFileInfo&&(d.fileInfo=n(f,u),r.computeUsedBitDepths&&(d.fileInfo.bitDepths=a(f))),d};var i=function(e,t,i,n,a){var l,r,o=0,f=e.pixels.numBlocksX,u=e.pixels.numBlocksY,m=Math.floor(e.width/f),d=Math.floor(e.height/u),c=2*e.maxZError;i=i||(e.mask?e.mask.bitset:null),l=new t(e.width*e.height),a&&i&&(r=new Uint8Array(e.width*e.height));for(var g,h,k=new Float32Array(m*d),x=0;x<=u;x++){var p=x!==u?d:e.height%u;if(0!==p)for(var w=0;w<=f;w++){var y=w!==f?m:e.width%f;if(0!==y){var V,B,v,U,D=x*e.width*d+w*m,M=e.width-y,b=e.pixels.blocks[o];if(b.encoding<2?(0===b.encoding?V=b.rawData:(s(b.stuffedData,b.bitsPerPixel,b.numValidPixels,b.offset,c,k,e.pixels.maxValue),V=k),B=0):v=2===b.encoding?0:b.offset,i)for(h=0;h<p;h++){for(7&D&&(U=i[D>>3],U<<=7&D),g=0;g<y;g++)7&D||(U=i[D>>3]),128&U?(r&&(r[D]=1),l[D++]=b.encoding<2?V[B++]:v):(r&&(r[D]=0),l[D++]=n),U<<=1;D+=M}else if(b.encoding<2)for(h=0;h<p;h++){for(g=0;g<y;g++)l[D++]=V[B++];D+=M}else for(h=0;h<p;h++)if(l.fill)l.fill(v,D,D+y),D+=y+M;else{for(g=0;g<y;g++)l[D++]=v;D+=M}if(1===b.encoding&&B!==b.numValidPixels)throw"Block and Mask do not match";o++}}}return{resultPixels:l,resultMask:r}},n=function(e,t){return{fileIdentifierString:e.fileIdentifierString,fileVersion:e.fileVersion,imageType:e.imageType,height:e.height,width:e.width,maxZError:e.maxZError,eofOffset:e.eofOffset,mask:e.mask?{numBlocksX:e.mask.numBlocksX,numBlocksY:e.mask.numBlocksY,numBytes:e.mask.numBytes,maxValue:e.mask.maxValue}:null,pixels:{numBlocksX:e.pixels.numBlocksX,numBlocksY:e.pixels.numBlocksY,numBytes:e.pixels.numBytes,maxValue:e.pixels.maxValue,minValue:e.pixels.minValue,noDataValue:t}}},a=function(e){for(var t=e.pixels.numBlocksX*e.pixels.numBlocksY,i={},n=0;n<t;n++){var a=e.pixels.blocks[n];0===a.encoding?i.float32=!0:1===a.encoding?i[a.bitsPerPixel]=!0:i[0]=!0}return Object.keys(i)},l=function(e,t,i){var n={},a=new Uint8Array(e,t,10);if(n.fileIdentifierString=String.fromCharCode.apply(null,a),"CntZImage"!=n.fileIdentifierString.trim())throw"Unexpected file identifier string: "+n.fileIdentifierString;t+=10;var l=new DataView(e,t,24);if(n.fileVersion=l.getInt32(0,!0),n.imageType=l.getInt32(4,!0),n.height=l.getUint32(8,!0),n.width=l.getUint32(12,!0),n.maxZError=l.getFloat64(16,!0),t+=24,!i)if(l=new DataView(e,t,16),n.mask={},n.mask.numBlocksY=l.getUint32(0,!0),n.mask.numBlocksX=l.getUint32(4,!0),n.mask.numBytes=l.getUint32(8,!0),n.mask.maxValue=l.getFloat32(12,!0),t+=16,n.mask.numBytes>0){var s=new Uint8Array(Math.ceil(n.width*n.height/8)),r=(l=new DataView(e,t,n.mask.numBytes)).getInt16(0,!0),o=2,f=0;do{if(r>0)for(;r--;)s[f++]=l.getUint8(o++);else{var u=l.getUint8(o++);for(r=-r;r--;)s[f++]=u}r=l.getInt16(o,!0),o+=2}while(o<n.mask.numBytes);if(-32768!==r||f<s.length)throw"Unexpected end of mask RLE encoding";n.mask.bitset=s,t+=n.mask.numBytes}else if(0===(n.mask.numBytes|n.mask.numBlocksY|n.mask.maxValue)){s=new Uint8Array(Math.ceil(n.width*n.height/8));n.mask.bitset=s}l=new DataView(e,t,16),n.pixels={},n.pixels.numBlocksY=l.getUint32(0,!0),n.pixels.numBlocksX=l.getUint32(4,!0),n.pixels.numBytes=l.getUint32(8,!0),n.pixels.maxValue=l.getFloat32(12,!0),t+=16;var m=n.pixels.numBlocksX,d=n.pixels.numBlocksY,c=m+(n.width%m>0?1:0),g=d+(n.height%d>0?1:0);n.pixels.blocks=new Array(c*g);for(var h=1e9,k=0,x=0;x<g;x++)for(var p=0;p<c;p++){var w=0,y=e.byteLength-t;l=new DataView(e,t,Math.min(10,y));var V={};n.pixels.blocks[k++]=V;var B=l.getUint8(0);if(w++,V.encoding=63&B,V.encoding>3)throw"Invalid block encoding ("+V.encoding+")";if(2!==V.encoding){if(0!==B&&2!==B){if(B>>=6,V.offsetType=B,2===B)V.offset=l.getInt8(1),w++;else if(1===B)V.offset=l.getInt16(1,!0),w+=2;else{if(0!==B)throw"Invalid block offset type";V.offset=l.getFloat32(1,!0),w+=4}if(h=Math.min(V.offset,h),1===V.encoding)if(B=l.getUint8(w),w++,V.bitsPerPixel=63&B,B>>=6,V.numValidPixelsType=B,2===B)V.numValidPixels=l.getUint8(w),w++;else if(1===B)V.numValidPixels=l.getUint16(w,!0),w+=2;else{if(0!==B)throw"Invalid valid pixel count type";V.numValidPixels=l.getUint32(w,!0),w+=4}}var v;if(t+=w,3!=V.encoding)if(0===V.encoding){var U=(n.pixels.numBytes-1)/4;if(U!==Math.floor(U))throw"uncompressed block has invalid length";v=new ArrayBuffer(4*U),new Uint8Array(v).set(new Uint8Array(e,t,4*U));for(var D=new Float32Array(v),M=0;M<D.length;M++)h=Math.min(h,D[M]);V.rawData=D,t+=4*U}else if(1===V.encoding){var b=Math.ceil(V.numValidPixels*V.bitsPerPixel/8),I=Math.ceil(b/4);v=new ArrayBuffer(4*I),new Uint8Array(v).set(new Uint8Array(e,t,b)),V.stuffedData=new Uint32Array(v),t+=b}}else t++,h=Math.min(h,0)}return n.pixels.minValue=h,n.eofOffset=t,n},s=function(e,t,i,n,a,l,s){var r,o,f,u=(1<<t)-1,m=0,d=0,c=Math.ceil((s-n)/a),g=4*e.length-Math.ceil(t*i/8);for(e[e.length-1]<<=8*g,r=0;r<i;r++){if(0===d&&(f=e[m++],d=32),d>=t)o=f>>>d-t&u,d-=t;else{var h=t-d;o=(f&u)<<h&u,o+=(f=e[m++])>>>(d=32-h)}l[r]=o<c?n+o*a:s}return l};const r=t.decode;class o{_decode(e){const t=r(e.buffer,e.options);return Promise.resolve({result:t,transferList:[t.pixelData.buffer]})}}function f(){return new o}export{f as default};
|
|
1
|
+
import{clampFloat32 as e}from"../../core/mathUtils.js";var t={};t.defaultNoDataValue=e(-1/0),t.decode=async(r,s)=>{if(-1!==String.fromCharCode.apply(null,new Uint8Array(r,s.inputOffset||0,20)).indexOf("PNG")||-1!==String.fromCharCode.apply(null,new Uint8Array(r,s.inputOffset||0,20)).indexOf("WEBP"))d=await decodeTerrainRGB(r,s);else{var o=(s=s||{}).encodedMaskData||null===s.encodedMaskData,f=l(r,s.inputOffset||0,o),u=null!=s.noDataValue?e(s.noDataValue):t.defaultNoDataValue,m=i(f,s.pixelType||Float32Array,s.encodedMaskData,u,s.returnMask),d={width:f.width,height:f.height,pixelData:m.resultPixels,minValue:f.pixels.minValue,maxValue:f.pixels.maxValue,noDataValue:u};m.resultMask&&(d.maskData=m.resultMask),s.returnEncodedMask&&f.mask&&(d.encodedMaskData=f.mask.bitset?f.mask.bitset:null),s.returnFileInfo&&(d.fileInfo=n(f,u),s.computeUsedBitDepths&&(d.fileInfo.bitDepths=a(f)))}return d};var i=function(e,t,i,a,n){var l,r,o=0,f=e.pixels.numBlocksX,u=e.pixels.numBlocksY,m=Math.floor(e.width/f),d=Math.floor(e.height/u),h=2*e.maxZError;i=i||(e.mask?e.mask.bitset:null),l=new t(e.width*e.height),n&&i&&(r=new Uint8Array(e.width*e.height));for(var c,g,w=new Float32Array(m*d),x=0;x<=u;x++){var k=x!==u?d:e.height%u;if(0!==k)for(var p=0;p<=f;p++){var y=p!==f?m:e.width%f;if(0!==y){var V,B,v,D,U=x*e.width*d+p*m,M=e.width-y,b=e.pixels.blocks[o];if(b.encoding<2?(0===b.encoding?V=b.rawData:(s(b.stuffedData,b.bitsPerPixel,b.numValidPixels,b.offset,h,w,e.pixels.maxValue),V=w),B=0):v=2===b.encoding?0:b.offset,i)for(g=0;g<k;g++){for(7&U&&(D=i[U>>3],D<<=7&U),c=0;c<y;c++)7&U||(D=i[U>>3]),128&D?(r&&(r[U]=1),l[U++]=b.encoding<2?V[B++]:v):(r&&(r[U]=0),l[U++]=a),D<<=1;U+=M}else if(b.encoding<2)for(g=0;g<k;g++){for(c=0;c<y;c++)l[U++]=V[B++];U+=M}else for(g=0;g<k;g++)if(l.fill)l.fill(v,U,U+y),U+=y+M;else{for(c=0;c<y;c++)l[U++]=v;U+=M}if(1===b.encoding&&B!==b.numValidPixels)throw"Block and Mask do not match";o++}}}return{resultPixels:l,resultMask:r}},n=function(e,t){return{fileIdentifierString:e.fileIdentifierString,fileVersion:e.fileVersion,imageType:e.imageType,height:e.height,width:e.width,maxZError:e.maxZError,eofOffset:e.eofOffset,mask:e.mask?{numBlocksX:e.mask.numBlocksX,numBlocksY:e.mask.numBlocksY,numBytes:e.mask.numBytes,maxValue:e.mask.maxValue}:null,pixels:{numBlocksX:e.pixels.numBlocksX,numBlocksY:e.pixels.numBlocksY,numBytes:e.pixels.numBytes,maxValue:e.pixels.maxValue,minValue:e.pixels.minValue,noDataValue:t}}},a=function(e){for(var t=e.pixels.numBlocksX*e.pixels.numBlocksY,i={},a=0;a<t;a++){var n=e.pixels.blocks[a];0===n.encoding?i.float32=!0:1===n.encoding?i[n.bitsPerPixel]=!0:i[0]=!0}return Object.keys(i)},l=function(e,t,i){var a={},n=new Uint8Array(e,t,10);if(a.fileIdentifierString=String.fromCharCode.apply(null,n),"CntZImage"!=a.fileIdentifierString.trim())throw"Unexpected file identifier string: "+a.fileIdentifierString;t+=10;var l=new DataView(e,t,24);if(a.fileVersion=l.getInt32(0,!0),a.imageType=l.getInt32(4,!0),a.height=l.getUint32(8,!0),a.width=l.getUint32(12,!0),a.maxZError=l.getFloat64(16,!0),t+=24,!i)if(l=new DataView(e,t,16),a.mask={},a.mask.numBlocksY=l.getUint32(0,!0),a.mask.numBlocksX=l.getUint32(4,!0),a.mask.numBytes=l.getUint32(8,!0),a.mask.maxValue=l.getFloat32(12,!0),t+=16,a.mask.numBytes>0){var r=new Uint8Array(Math.ceil(a.width*a.height/8)),s=(l=new DataView(e,t,a.mask.numBytes)).getInt16(0,!0),o=2,f=0;do{if(s>0)for(;s--;)r[f++]=l.getUint8(o++);else{var u=l.getUint8(o++);for(s=-s;s--;)r[f++]=u}s=l.getInt16(o,!0),o+=2}while(o<a.mask.numBytes);if(-32768!==s||f<r.length)throw"Unexpected end of mask RLE encoding";a.mask.bitset=r,t+=a.mask.numBytes}else 0==(a.mask.numBytes|a.mask.numBlocksY|a.mask.maxValue)&&(r=new Uint8Array(Math.ceil(a.width*a.height/8)),a.mask.bitset=r);l=new DataView(e,t,16),a.pixels={},a.pixels.numBlocksY=l.getUint32(0,!0),a.pixels.numBlocksX=l.getUint32(4,!0),a.pixels.numBytes=l.getUint32(8,!0),a.pixels.maxValue=l.getFloat32(12,!0),t+=16;var m=a.pixels.numBlocksX,d=a.pixels.numBlocksY,h=m+(a.width%m>0?1:0),c=d+(a.height%d>0?1:0);a.pixels.blocks=new Array(h*c);for(var g=1e9,w=0,x=0;x<c;x++)for(var k=0;k<h;k++){var p=0,y=e.byteLength-t;l=new DataView(e,t,Math.min(10,y));var V={};a.pixels.blocks[w++]=V;var B=l.getUint8(0);if(p++,V.encoding=63&B,V.encoding>3)throw"Invalid block encoding ("+V.encoding+")";if(2!==V.encoding){if(0!==B&&2!==B){if(B>>=6,V.offsetType=B,2===B)V.offset=l.getInt8(1),p++;else if(1===B)V.offset=l.getInt16(1,!0),p+=2;else{if(0!==B)throw"Invalid block offset type";V.offset=l.getFloat32(1,!0),p+=4}if(g=Math.min(V.offset,g),1===V.encoding)if(B=l.getUint8(p),p++,V.bitsPerPixel=63&B,B>>=6,V.numValidPixelsType=B,2===B)V.numValidPixels=l.getUint8(p),p++;else if(1===B)V.numValidPixels=l.getUint16(p,!0),p+=2;else{if(0!==B)throw"Invalid valid pixel count type";V.numValidPixels=l.getUint32(p,!0),p+=4}}var v;if(t+=p,3!=V.encoding)if(0===V.encoding){var D=(a.pixels.numBytes-1)/4;if(D!==Math.floor(D))throw"uncompressed block has invalid length";v=new ArrayBuffer(4*D),new Uint8Array(v).set(new Uint8Array(e,t,4*D));for(var U=new Float32Array(v),M=0;M<U.length;M++)g=Math.min(g,U[M]);V.rawData=U,t+=4*D}else if(1===V.encoding){var b=Math.ceil(V.numValidPixels*V.bitsPerPixel/8),I=Math.ceil(b/4);v=new ArrayBuffer(4*I),new Uint8Array(v).set(new Uint8Array(e,t,b)),V.stuffedData=new Uint32Array(v),t+=b}}else t++,g=Math.min(g,0)}return a.pixels.minValue=g,a.eofOffset=t,a},s=function(e,t,i,a,n,l,r){var s,o,f,u=(1<<t)-1,m=0,d=0,h=Math.ceil((r-a)/n),c=4*e.length-Math.ceil(t*i/8);for(e[e.length-1]<<=8*c,s=0;s<i;s++){if(0===d&&(f=e[m++],d=32),d>=t)o=f>>>d-t&u,d-=t;else{var g=t-d;o=(f&u)<<g&u,o+=(f=e[m++])>>>(d=32-g)}l[s]=o<h?a+o*n:r}return l},decodeTerrainRGB=async(e,t)=>{const i=new Blob([e]),a=await createImageBitmap(i),n=new OffscreenCanvas(a.width,a.height),l=n.width=a.width,r=n.height=a.height,s=n.getContext("2d",{willReadFrequently:!0});if(!s)throw new Error("无法获取2D上下文");s.drawImage(a,0,0);const o=s.getImageData(0,0,n.width,n.height).data;for(var f=new(t.pixelType||Float32Array)(l*r),u=1/0,m=-1/0,d=0;d<r;d++)for(var h=0;h<l;h++){var c=d*l+h,g=4*c,w=.1*(256*(t=o[g])*256+256*o[g+1]+o[g+2])-1e4;f[c]=w,w<u&&(u=w),w>m&&(m=w)}return u===1/0&&(u=0),m===-1/0&&(m=0),{width:l,height:r,pixelData:f,minValue:u,maxValue:m,noDataValue:t.noDataValue||t.defaultNoDataValue}};const r=t.decode;class o{_decode(e){return r(e.buffer,e.options).then((e=>Promise.resolve({result:e,transferList:[e.pixelData.buffer]})))}}function f(){return new o}export{f as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../core/Error.js";import{assertIsSome as i}from"../../../core/maybe.js";import{urlToObject as s}from"../../../core/urlUtils.js";import{property as r}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as a}from"../../../core/accessorSupport/decorators/subclass.js";import l from"../../../geometry/Extent.js";import n from"../../../geometry/Point.js";import o from"../../../geometry/SpatialReference.js";import c from"../RasterInfo.js";import m from"../RasterStorageInfo.js";import u from"../TileInfo.js";import{TilemapCache as h}from"../TilemapCache.js";import f from"./BaseRaster.js";import{setValidBoundary as p}from"../rasterFunctions/pixelUtils.js";import d from"../rasterTransforms/GCSShiftTransform.js";import{patchServiceInfo as y,fetchServiceRasterInfo as x}from"../../../rest/imageService/fetchRasterInfo.js";let g=class extends f{constructor(){super(...arguments),this._levelOffset=0,this._tilemapCache=null,this._slices=null,this.datasetFormat="RasterTileServer",this.tileType=null}async fetchRawTile(e,t,i,s={}){const{storageInfo:r,extent:a}=this.rasterInfo,{transposeInfo:l}=r,n=null!=l&&!!s.transposedVariableName;if(this._slices&&!n&&null==s.sliceId)return null;const o=n?0:r.maximumPyramidLevel-e+this._levelOffset,c=`${this.url}/tile/${o}/${t}/${i}`,m=this._slices?n?{variable:s.transposedVariableName}:{sliceId:s.sliceId||0}:null;let u,h;if(r.isBsqTile){const e=(s.bandIds?.length?s.bandIds:[0,1,2]).map((e=>this.request(c,{query:{...m,bandId:e},responseType:"array-buffer",signal:s.signal}))),t=await Promise.all(e),i=t.map((e=>e.data.byteLength)).reduce(((e,t)=>e+t)),r=new Uint8Array(i);h=[];let a=0;for(const{data:s}of t)h.push(a),r.set(new Uint8Array(s),a),a+=s.byteLength;u=r.buffer}else{u=(await this.request(c,{query:m,responseType:"array-buffer",signal:s.signal})).data}if(!u)return null;const f=n?l.tileSize:r.tileInfo.size,d=await this.decodePixelBlock(u,{width:f[0],height:f[1],planes:h?.length,offsets:h,pixelType:null,isPoint:"Elevation"===this.tileType,returnInterleaved:n,noDataValue:this.rasterInfo.noDataValue});if(null==d)return null;const y=r.blockBoundary[e];if("jpg"!==r.compression||i>y.minCol&&i<y.maxCol&&t>y.minRow&&t<y.maxRow)return d;const{origin:x,blockWidth:g,blockHeight:v}=r,{x:S,y:I}=this.getPyramidPixelSize(e),w=Math.round((a.xmin-x.x)/S)%g,b=Math.round((a.xmax-x.x)/S)%g||g,T=Math.round((x.y-a.ymax)/I)%v,j=Math.round((x.y-a.ymin)/I)%v||v,M=i===y.minCol?w:0,_=t===y.minRow?T:0,O=i===y.maxCol?b:g,R=t===y.maxRow?j:v;return p(d,{x:M,y:_},{width:O-M,height:R-_}),d}getSliceIndex(e){if(!this._slices||null==e||0===e.length)return null;const t=e;for(let i=0;i<this._slices.length;i++){const e=this._slices[i].multidimensionalDefinition;if(e.length===t.length&&!e.some((e=>{const i=t.find((t=>e.variableName===t.variableName&&t.dimensionName===e.dimensionName));if(!i)return!0;return(Array.isArray(e.values[0])?`${e.values[0][0]}-${e.values[0][1]}`:e.values[0])!==(Array.isArray(i.values[0])?`${i.values[0][0]}-${i.values[0][1]}`:i.values[0])})))return i}return null}async fetchVariableStatisticsHistograms(e,t){const i=this.request(this.url+"/statistics",{query:{variable:e,f:"json"},signal:t}).then((e=>e.data?.statistics)),s=this.request(this.url+"/histograms",{query:{variable:e,f:"json"},signal:t}).then((e=>e.data?.histograms)),r=await Promise.all([i,s]);return r[0]&&r[0].forEach((e=>{e.avg=e.mean,e.stddev=e.standardDeviation})),r[1]?.[0]?.counts?.length||(r[1]=null),{statistics:r[0]||null,histograms:r[1]||null}}async computeBestPyramidLevelForLocation(e,t={}){if(!this._tilemapCache)return 0;let i=this.identifyPixelLocation(e,0,t.datumTransformation);if(null===i)return null;let s=0;const{maximumPyramidLevel:r}=this.rasterInfo.storageInfo;let a=r-s+this._levelOffset;const l=i.srcLocation;for(;a>=0;){try{if("available"===await this._tilemapCache.fetchAvailability(a,i.row,i.col,t))break}catch{}if(a--,s++,i=this.identifyPixelLocation(l,s,t.datumTransformation),null===i)return null}return-1===a||null==i?null:s}async _open(e){const r=e?.signal,a=this.sourceJSON?{data:this.sourceJSON}:await this.request(this.url,{query:{f:"json"},signal:r});a.ssl&&(this.url=this.url.replace(/^http:/i,"https:"));const l=a.data;if(this.sourceJSON=l,!l)throw new t("imageserverraster:open","cannot initialize tiled image service, missing service info");if(!l.tileInfo)throw new t("imageserverraster:open","use ImageryLayer to open non-tiled image services");this._fixScaleInServiceInfo();const n=["jpg","jpeg","png","png8","png24","png32","mixed","terrainrgb","terraindem"];this.tileType=l.cacheType,null==this.tileType&&(n.includes(l.tileInfo.format.toLowerCase())?this.tileType="Map":"lerc"===l.tileInfo.format.toLowerCase()?this.tileType="Elevation":this.tileType="Raster"),this.datasetName=l.name?.slice(l.name.indexOf("/")+1)??"";const o=await this._fetchRasterInfo({signal:r});if(null==o)throw new t("image-server-raster:open","cannot initialize image service");y(o,l);const c="Map"===this.tileType?v(l.tileInfo,l):u.fromJSON(l.tileInfo);i(c);const[f,p]=this._computeMinMaxLOD(o,c),{extent:d,pixelSize:x}=o,g=.5/o.width*x.x,I=Math.max(x.x,x.y),{lods:w}=c;("Map"!==this.tileType&&0!==l.maxScale||Math.abs(x.x-x.y)>g||!w.some((e=>Math.abs(e.resolution-I)<g)))&&(x.x=x.y=f.resolution,o.width=Math.ceil((d.xmax-d.xmin)/x.x-.1),o.height=Math.ceil((d.ymax-d.ymin)/x.y-.1));const b=f.level-p.level,[T,j]=c.size,M=[],_=[];w.forEach(((e,t)=>{e.level>=p.level&&e.level<=f.level&&M.push({x:e.resolution,y:e.resolution}),t<w.length-1&&_.push(Math.round(10*e.resolution/w[t+1].resolution)/10)})),M.sort(((e,t)=>e.x-t.x));const O=this.computeBlockBoundary(d,T,j,c.origin,M,b),R=M.length>1?M.slice(1):null;let L;l.transposeInfo&&(L={tileSize:[l.transposeInfo.rows,l.transposeInfo.cols],packetSize:o.keyProperties?._yxs.PacketSize??0});const z=_.length<=1||_.length>=3&&_.slice(0,-1).every((e=>e===_[0]))?_[0]??2:Math.round(10/(p.resolution/f.resolution)**(-1/b))/10;if(o.storageInfo=new m({blockWidth:c.size[0],blockHeight:c.size[1],pyramidBlockWidth:c.size[0],pyramidBlockHeight:c.size[1],pyramidResolutions:R,pyramidScalingFactor:z,compression:c.format,origin:c.origin,firstPyramidLevel:1,maximumPyramidLevel:b,tileInfo:c,isBsqTile:!!l.bsq,transposeInfo:L,blockBoundary:O}),S(o),this._set("rasterInfo",o),l.capabilities.toLowerCase().includes("tilemap")){const e={tileInfo:o.storageInfo.tileInfo,parsedUrl:s(this.url),url:this.url,tileServers:[]};this._tilemapCache=new h({layer:e})}}async _fetchRasterInfo(e){const t=this.sourceJSON;if("Map"===this.tileType){const e=t.fullExtent||t.extent,i=Math.ceil((e.xmax-e.xmin)/t.pixelSizeX-.1),s=Math.ceil((e.ymax-e.ymin)/t.pixelSizeY-.1),r=o.fromJSON(t.spatialReference||e.spatialReference),a=new n({x:t.pixelSizeX,y:t.pixelSizeY,spatialReference:r});return new c({width:i,height:s,bandCount:3,extent:l.fromJSON(e),spatialReference:r,pixelSize:a,pixelType:"u8",statistics:null,keyProperties:{DataType:"processed"}})}const{signal:i}=e,s=x(this.url,this.sourceJSON,{signal:i,query:this.ioConfig.customFetchParameters}),r=t.hasMultidimensions?this.request(`${this.url}/slices`,{query:{f:"json"},signal:i}).then((e=>e.data?.slices)).catch((()=>null)):null,a=await Promise.all([s,r]);return this._slices=a[1],a[0]}_fixScaleInServiceInfo(){const{sourceJSON:e}=this;e.minScale&&e.minScale<0&&(e.minScale=0),e.maxScale&&e.maxScale<0&&(e.maxScale=0)}_computeMinMaxLOD(e,t){const{pixelSize:i}=e,s=.5/e.width*i.x,{lods:r}=t,a=t.lodAt(Math.max.apply(null,r.map((e=>e.level)))),l=t.lodAt(Math.min.apply(null,r.map((e=>e.level)))),{tileType:n}=this;if("Map"===n)return this._levelOffset=r[0].level,[a,l];if("Raster"===n){return[r.find((e=>e.resolution===i.x))??a,l]}const{minScale:o,maxScale:c}=this.sourceJSON;let m=a;c>0&&(m=r.find((e=>Math.abs(e.scale-c)<s)),m||(m=r.filter((e=>e.scale>c)).sort(((e,t)=>e.scale>t.scale?1:-1))[0]??a));let u=l;return o>0&&(u=r.find((e=>Math.abs(e.scale-o)<s))??l,this._levelOffset=u.level-l.level),[m,u]}};function v(e,t){if(!e)return null;const{minScale:i,maxScale:s,minLOD:r,maxLOD:a}=t;if(null!=r&&null!=a)return u.fromJSON({...e,lods:e.lods.filter((({level:e})=>null!=e&&e>=r&&e<=a))});if(0!==i&&0!==s){const t=e=>Math.round(1e4*e)/1e4,r=i?t(i):1/0,a=s?t(s):-1/0;return u.fromJSON({...e,lods:e.lods.filter((e=>{const i=t(e.scale);return i<=r&&i>=a}))})}return u.fromJSON(e)}function S(e){const{extent:t,spatialReference:i}=e;t.xmin>-1&&t.xmax>181&&i?.wkid&&i.isGeographic&&(e.nativeExtent=e.extent,e.transform=new d,e.extent=e.transform.forwardTransform(t))}e([r({type:String,json:{write:!0}})],g.prototype,"datasetFormat",void 0),e([r()],g.prototype,"tileType",void 0),g=e([a("geoscene.layers.support.rasterDatasets.ImageServerRaster")],g);const I=g;export{I as default};
|
|
5
|
+
import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../core/Error.js";import{assertIsSome as i}from"../../../core/maybe.js";import{urlToObject as s}from"../../../core/urlUtils.js";import{property as r}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as a}from"../../../core/accessorSupport/decorators/subclass.js";import l from"../../../geometry/Extent.js";import n from"../../../geometry/Point.js";import o from"../../../geometry/SpatialReference.js";import c from"../RasterInfo.js";import m from"../RasterStorageInfo.js";import u from"../TileInfo.js";import{TilemapCache as h}from"../TilemapCache.js";import f from"./BaseRaster.js";import{setValidBoundary as p}from"../rasterFunctions/pixelUtils.js";import d from"../rasterTransforms/GCSShiftTransform.js";import{patchServiceInfo as y,fetchServiceRasterInfo as x}from"../../../rest/imageService/fetchRasterInfo.js";let g=class extends f{constructor(){super(...arguments),this._levelOffset=0,this._tilemapCache=null,this._slices=null,this.datasetFormat="RasterTileServer",this.tileType=null}async fetchRawTile(e,t,i,s={}){const{storageInfo:r,extent:a}=this.rasterInfo,{transposeInfo:l}=r,n=null!=l&&!!s.transposedVariableName;if(this._slices&&!n&&null==s.sliceId)return null;const o=n?0:r.maximumPyramidLevel-e+this._levelOffset,c=`${this.url}/tile/${o}/${t}/${i}`,m=this._slices?n?{variable:s.transposedVariableName}:{sliceId:s.sliceId||0}:null;let u,h;if(r.isBsqTile){const e=(s.bandIds?.length?s.bandIds:[0,1,2]).map((e=>this.request(c,{query:{...m,bandId:e},responseType:"array-buffer",signal:s.signal}))),t=await Promise.all(e),i=t.map((e=>e.data.byteLength)).reduce(((e,t)=>e+t)),r=new Uint8Array(i);h=[];let a=0;for(const{data:s}of t)h.push(a),r.set(new Uint8Array(s),a),a+=s.byteLength;u=r.buffer}else{u=(await this.request(c,{query:m,responseType:"array-buffer",signal:s.signal})).data}if(!u)return null;const f=n?l.tileSize:r.tileInfo.size,d=await this.decodePixelBlock(u,{width:f[0],height:f[1],planes:h?.length,offsets:h,pixelType:null,isPoint:"Elevation"===this.tileType,returnInterleaved:n,noDataValue:this.rasterInfo.noDataValue,useCanvas: r.tileInfo?.format === "TerrainDEM"});if(null==d)return null;const y=r.blockBoundary[e];if("jpg"!==r.compression||i>y.minCol&&i<y.maxCol&&t>y.minRow&&t<y.maxRow)return d;const{origin:x,blockWidth:g,blockHeight:v}=r,{x:S,y:I}=this.getPyramidPixelSize(e),w=Math.round((a.xmin-x.x)/S)%g,b=Math.round((a.xmax-x.x)/S)%g||g,T=Math.round((x.y-a.ymax)/I)%v,j=Math.round((x.y-a.ymin)/I)%v||v,M=i===y.minCol?w:0,_=t===y.minRow?T:0,O=i===y.maxCol?b:g,R=t===y.maxRow?j:v;return p(d,{x:M,y:_},{width:O-M,height:R-_}),d}getSliceIndex(e){if(!this._slices||null==e||0===e.length)return null;const t=e;for(let i=0;i<this._slices.length;i++){const e=this._slices[i].multidimensionalDefinition;if(e.length===t.length&&!e.some((e=>{const i=t.find((t=>e.variableName===t.variableName&&t.dimensionName===e.dimensionName));if(!i)return!0;return(Array.isArray(e.values[0])?`${e.values[0][0]}-${e.values[0][1]}`:e.values[0])!==(Array.isArray(i.values[0])?`${i.values[0][0]}-${i.values[0][1]}`:i.values[0])})))return i}return null}async fetchVariableStatisticsHistograms(e,t){const i=this.request(this.url+"/statistics",{query:{variable:e,f:"json"},signal:t}).then((e=>e.data?.statistics)),s=this.request(this.url+"/histograms",{query:{variable:e,f:"json"},signal:t}).then((e=>e.data?.histograms)),r=await Promise.all([i,s]);return r[0]&&r[0].forEach((e=>{e.avg=e.mean,e.stddev=e.standardDeviation})),r[1]?.[0]?.counts?.length||(r[1]=null),{statistics:r[0]||null,histograms:r[1]||null}}async computeBestPyramidLevelForLocation(e,t={}){if(!this._tilemapCache)return 0;let i=this.identifyPixelLocation(e,0,t.datumTransformation);if(null===i)return null;let s=0;const{maximumPyramidLevel:r}=this.rasterInfo.storageInfo;let a=r-s+this._levelOffset;const l=i.srcLocation;for(;a>=0;){try{if("available"===await this._tilemapCache.fetchAvailability(a,i.row,i.col,t))break}catch{}if(a--,s++,i=this.identifyPixelLocation(l,s,t.datumTransformation),null===i)return null}return-1===a||null==i?null:s}async _open(e){const r=e?.signal,a=this.sourceJSON?{data:this.sourceJSON}:await this.request(this.url,{query:{f:"json"},signal:r});a.ssl&&(this.url=this.url.replace(/^http:/i,"https:"));const l=a.data;if(this.sourceJSON=l,!l)throw new t("imageserverraster:open","cannot initialize tiled image service, missing service info");if(!l.tileInfo)throw new t("imageserverraster:open","use ImageryLayer to open non-tiled image services");this._fixScaleInServiceInfo();const n=["jpg","jpeg","png","png8","png24","png32","mixed","terrainrgb","terraindem"];this.tileType=l.cacheType,null==this.tileType&&(n.includes(l.tileInfo.format.toLowerCase())?this.tileType="Map":"lerc"===l.tileInfo.format.toLowerCase()?this.tileType="Elevation":this.tileType="Raster"),this.datasetName=l.name?.slice(l.name.indexOf("/")+1)??"";const o=await this._fetchRasterInfo({signal:r});if(null==o)throw new t("image-server-raster:open","cannot initialize image service");y(o,l);const c="Map"===this.tileType?v(l.tileInfo,l):u.fromJSON(l.tileInfo);i(c);const[f,p]=this._computeMinMaxLOD(o,c),{extent:d,pixelSize:x}=o,g=.5/o.width*x.x,I=Math.max(x.x,x.y),{lods:w}=c;("Map"!==this.tileType&&0!==l.maxScale||Math.abs(x.x-x.y)>g||!w.some((e=>Math.abs(e.resolution-I)<g)))&&(x.x=x.y=f.resolution,o.width=Math.ceil((d.xmax-d.xmin)/x.x-.1),o.height=Math.ceil((d.ymax-d.ymin)/x.y-.1));const b=f.level-p.level,[T,j]=c.size,M=[],_=[];w.forEach(((e,t)=>{e.level>=p.level&&e.level<=f.level&&M.push({x:e.resolution,y:e.resolution}),t<w.length-1&&_.push(Math.round(10*e.resolution/w[t+1].resolution)/10)})),M.sort(((e,t)=>e.x-t.x));const O=this.computeBlockBoundary(d,T,j,c.origin,M,b),R=M.length>1?M.slice(1):null;let L;l.transposeInfo&&(L={tileSize:[l.transposeInfo.rows,l.transposeInfo.cols],packetSize:o.keyProperties?._yxs.PacketSize??0});const z=_.length<=1||_.length>=3&&_.slice(0,-1).every((e=>e===_[0]))?_[0]??2:Math.round(10/(p.resolution/f.resolution)**(-1/b))/10;if(o.storageInfo=new m({blockWidth:c.size[0],blockHeight:c.size[1],pyramidBlockWidth:c.size[0],pyramidBlockHeight:c.size[1],pyramidResolutions:R,pyramidScalingFactor:z,compression:c.format,origin:c.origin,firstPyramidLevel:1,maximumPyramidLevel:b,tileInfo:c,isBsqTile:!!l.bsq,transposeInfo:L,blockBoundary:O}),S(o),this._set("rasterInfo",o),l.capabilities.toLowerCase().includes("tilemap")){const e={tileInfo:o.storageInfo.tileInfo,parsedUrl:s(this.url),url:this.url,tileServers:[]};this._tilemapCache=new h({layer:e})}}async _fetchRasterInfo(e){const t=this.sourceJSON;if("Map"===this.tileType){const e=t.fullExtent||t.extent,i=Math.ceil((e.xmax-e.xmin)/t.pixelSizeX-.1),s=Math.ceil((e.ymax-e.ymin)/t.pixelSizeY-.1),r=o.fromJSON(t.spatialReference||e.spatialReference),a=new n({x:t.pixelSizeX,y:t.pixelSizeY,spatialReference:r});return new c({width:i,height:s,bandCount:3,extent:l.fromJSON(e),spatialReference:r,pixelSize:a,pixelType:"u8",statistics:null,keyProperties:{DataType:"processed"}})}const{signal:i}=e,s=x(this.url,this.sourceJSON,{signal:i,query:this.ioConfig.customFetchParameters}),r=t.hasMultidimensions?this.request(`${this.url}/slices`,{query:{f:"json"},signal:i}).then((e=>e.data?.slices)).catch((()=>null)):null,a=await Promise.all([s,r]);return this._slices=a[1],a[0]}_fixScaleInServiceInfo(){const{sourceJSON:e}=this;e.minScale&&e.minScale<0&&(e.minScale=0),e.maxScale&&e.maxScale<0&&(e.maxScale=0)}_computeMinMaxLOD(e,t){const{pixelSize:i}=e,s=.5/e.width*i.x,{lods:r}=t,a=t.lodAt(Math.max.apply(null,r.map((e=>e.level)))),l=t.lodAt(Math.min.apply(null,r.map((e=>e.level)))),{tileType:n}=this;if("Map"===n)return this._levelOffset=r[0].level,[a,l];if("Raster"===n){return[r.find((e=>e.resolution===i.x))??a,l]}const{minScale:o,maxScale:c}=this.sourceJSON;let m=a;c>0&&(m=r.find((e=>Math.abs(e.scale-c)<s)),m||(m=r.filter((e=>e.scale>c)).sort(((e,t)=>e.scale>t.scale?1:-1))[0]??a));let u=l;return o>0&&(u=r.find((e=>Math.abs(e.scale-o)<s))??l,this._levelOffset=u.level-l.level),[m,u]}};function v(e,t){if(!e)return null;const{minScale:i,maxScale:s,minLOD:r,maxLOD:a}=t;if(null!=r&&null!=a)return u.fromJSON({...e,lods:e.lods.filter((({level:e})=>null!=e&&e>=r&&e<=a))});if(0!==i&&0!==s){const t=e=>Math.round(1e4*e)/1e4,r=i?t(i):1/0,a=s?t(s):-1/0;return u.fromJSON({...e,lods:e.lods.filter((e=>{const i=t(e.scale);return i<=r&&i>=a}))})}return u.fromJSON(e)}function S(e){const{extent:t,spatialReference:i}=e;t.xmin>-1&&t.xmax>181&&i?.wkid&&i.isGeographic&&(e.nativeExtent=e.extent,e.transform=new d,e.extent=e.transform.forwardTransform(t))}e([r({type:String,json:{write:!0}})],g.prototype,"datasetFormat",void 0),e([r()],g.prototype,"tileType",void 0),g=e([a("geoscene.layers.support.rasterDatasets.ImageServerRaster")],g);const I=g;export{I as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import t from"../../../core/Error.js";import{isAborted as e,createAbortError as a}from"../../../core/promiseUtils.js";import{Z as n}from"../../../chunks/Zlib.js";class i{constructor(t){this._canvas=null,this._ctx=null,t&&(this._canvas=t.canvas,this._ctx=t.ctx||t.canvas&&t.canvas.getContext("2d"))}decode(n,s,r){if(!n||n.byteLength<10)throw new t("imagecanvasdecoder: decode","required a valid encoded data as input.");let{width:c=0,height:h=0,format:o}=s;const{applyJpegMask:l}=s;if(l&&(!c||!h))throw new t("imagecanvasdecoder: decode","image width and height are needed to apply jpeg mask directly to canvas");return new Promise(((t,d)=>{let g=null;"jpg"===o&&l&&(g=i._getMask(n,{width:c,height:h}));const w=new Blob([new Uint8Array(n)],{type:"image/"+o=="jpg"?"jpeg":o}),v=URL.createObjectURL(w),m=new Image;let _;m.src=v,m.onload=()=>{if(URL.revokeObjectURL(v),e(r))return void d(a());c=m.width,h=m.height,this._canvas&&this._ctx?(this._canvas.width===c&&this._canvas.height===h||(this._canvas.width=c,this._canvas.height=h),this._ctx.clearRect(0,0,c,h)):(this._canvas=document.createElement("canvas"),this._canvas.width=c,this._canvas.height=h,this._ctx=this._canvas.getContext("2d")),this._ctx.drawImage(m,0,0);const n=this._ctx.getImageData(0,0,c,h);let i;if(_=n.data,s.renderOnCanvas){if(g)for(i=0;i<g.length;i++)g[i]?_[4*i+3]=255:_[4*i+3]=0;return this._ctx.putImageData(n,0,0),void t(null)}const o=c*h,l=new Uint8Array(o),w=new Uint8Array(o),p=new Uint8Array(o);if(g)for(i=0;i<o;i++)l[i]=_[4*i],w[i]=_[4*i+1],p[i]=_[4*i+2];else for(g=new Uint8Array(o),i=0;i<o;i++)l[i]=_[4*i],w[i]=_[4*i+1],p[i]=_[4*i+2],g[i]=_[4*i+3];t({width:c,height:h,pixels:[l,w,p],mask:g,pixelType:"u8"})},m.onerror=()=>{URL.revokeObjectURL(v),d("cannot load image")}}))}static _getMask(t,e){let a=null;try{const i=new Uint8Array(t),s=Math.ceil(i.length/2);let r=0;const c=i.length-2;for(r=s;r<c&&(255!==i[r]||217!==i[r+1]);r++);if(r+=2,r<i.length-1){const t=new n(i.subarray(r)).getBytes();a=new Uint8Array(e.width*e.height);let s=0;for(let e=0;e<t.length;e++)for(let n=7;n>=0;n--)a[s++]=t[e]>>n&1}}catch(i){}return a}}export{i as default};
|
|
5
|
+
import t from"../../../core/Error.js";import{isAborted as e,createAbortError as a}from"../../../core/promiseUtils.js";import{Z as n}from"../../../chunks/Zlib.js";class i{constructor(t){this._canvas=null,this._ctx=null,t&&(this._canvas=t.canvas,this._ctx=t.ctx||t.canvas&&t.canvas.getContext("2d"))}decode(n,s,r){if(!n||n.byteLength<10)throw new t("imagecanvasdecoder: decode","required a valid encoded data as input.");let{width:c=0,height:h=0,format:o}=s;const{applyJpegMask:l}=s;if(l&&(!c||!h))throw new t("imagecanvasdecoder: decode","image width and height are needed to apply jpeg mask directly to canvas");return new Promise(((t,d)=>{let g=null;"jpg"===o&&l&&(g=i._getMask(n,{width:c,height:h}));const w=new Blob([new Uint8Array(n)],{type:"image/"+o=="jpg"?"jpeg":o}),v=URL.createObjectURL(w),m=new Image;let _;o==="webp"&&(m.width=c,m.height=h),m.src=v,m.onload=()=>{if(URL.revokeObjectURL(v),e(r))return void d(a());c=m.width,h=m.height,this._canvas&&this._ctx?(this._canvas.width===c&&this._canvas.height===h||(this._canvas.width=c,this._canvas.height=h),this._ctx.clearRect(0,0,c,h)):(this._canvas=document.createElement("canvas"),this._canvas.width=c,this._canvas.height=h,this._ctx=this._canvas.getContext("2d")),this._ctx.drawImage(m,0,0);const n=this._ctx.getImageData(0,0,c,h);let i;if(_=n.data,s.renderOnCanvas){if(g)for(i=0;i<g.length;i++)g[i]?_[4*i+3]=255:_[4*i+3]=0;return this._ctx.putImageData(n,0,0),void t(null)}const o=c*h,l=new Uint8Array(o),w=new Uint8Array(o),p=new Uint8Array(o);if(g)for(i=0;i<o;i++)l[i]=_[4*i],w[i]=_[4*i+1],p[i]=_[4*i+2];else for(g=new Uint8Array(o),i=0;i<o;i++)l[i]=_[4*i],w[i]=_[4*i+1],p[i]=_[4*i+2],g[i]=_[4*i+3];t({width:c,height:h,pixels:[l,w,p],mask:g,pixelType:"u8"})},m.onerror=()=>{URL.revokeObjectURL(v),d("cannot load image")}}))}static _getMask(t,e){let a=null;try{const i=new Uint8Array(t),s=Math.ceil(i.length/2);let r=0;const c=i.length-2;for(r=s;r<c&&(255!==i[r]||217!==i[r+1]);r++);if(r+=2,r<i.length-1){const t=new n(i.subarray(r)).getBytes();a=new Uint8Array(e.width*e.height);let s=0;for(let e=0;e<t.length;e++)for(let n=7;n>=0;n--)a[s++]=t[e]>>n&1}}catch(i){}return a}}export{i as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import t from"../../../core/Error.js";import{assertIsSome as e}from"../../../core/maybe.js";import a from"../PixelBlock.js";import{SimpleBandStatistics as i}from"../SimpleBandStatistics.js";import s from"./ImageCanvasDecoder.js";import r from"./JpgPlus.js";import{load as n,decode as o}from"./Lerc.js";import{decode as h}from"./Lzw.js";import{convertNoDataToMask as c}from"./pixelRangeUtils.js";import{Z as l}from"../../../chunks/Zlib.js";import p from"./Raw.js";import{decodeTileOrStrip as d,decode as u}from"./TiffDecoder.js";import{isPlatformLittleEndian as f}from"./utils.js";var m=function(t){var e,a,i,s,r,n;function o(t){var e,a,i,s,r,n,o,h,c,l,p,d,u;for(this.data=t,this.pos=8,this.palette=[],this.imgData=[],this.transparency={},this.animation=null,this.text={},r=null;;){switch(e=this.readUInt32(),h=function(){var t,e;for(e=[],t=0;t<4;++t)e.push(String.fromCharCode(this.data[this.pos++]));return e}.call(this).join(""),h){case"IHDR":this.width=this.readUInt32(),this.height=this.readUInt32(),this.bits=this.data[this.pos++],this.colorType=this.data[this.pos++],this.compressionMethod=this.data[this.pos++],this.filterMethod=this.data[this.pos++],this.interlaceMethod=this.data[this.pos++];break;case"acTL":this.animation={numFrames:this.readUInt32(),numPlays:this.readUInt32()||1/0,frames:[]};break;case"PLTE":this.palette=this.read(e);break;case"fcTL":r&&this.animation.frames.push(r),this.pos+=4,r={width:this.readUInt32(),height:this.readUInt32(),xOffset:this.readUInt32(),yOffset:this.readUInt32()},s=this.readUInt16(),i=this.readUInt16()||100,r.delay=1e3*s/i,r.disposeOp=this.data[this.pos++],r.blendOp=this.data[this.pos++],r.data=[];break;case"IDAT":case"fdAT":for("fdAT"===h&&(this.pos+=4,e-=4),t=(null!=r?r.data:void 0)||this.imgData,p=0;0<=e?p<e:p>e;0<=e?++p:--p)t.push(this.data[this.pos++]);break;case"tRNS":switch(this.transparency={},this.colorType){case 3:if(this.transparency.indexed=this.read(e),(c=255-this.transparency.indexed.length)>0)for(d=0;0<=c?d<c:d>c;0<=c?++d:--d)this.transparency.indexed.push(255);break;case 0:this.transparency.grayscale=this.read(e)[0];break;case 2:this.transparency.rgb=this.read(e)}break;case"tEXt":n=(l=this.read(e)).indexOf(0),o=String.fromCharCode.apply(String,l.slice(0,n)),this.text[o]=String.fromCharCode.apply(String,l.slice(n+1));break;case"IEND":return r&&this.animation.frames.push(r),this.colors=function(){switch(this.colorType){case 0:case 3:case 4:return 1;case 2:case 6:return 3}}.call(this),this.hasAlphaChannel=4===(u=this.colorType)||6===u,a=this.colors+(this.hasAlphaChannel?1:0),this.pixelBitlength=this.bits*a,this.colorSpace=function(){switch(this.colors){case 1:return"DeviceGray";case 3:return"DeviceRGB"}}.call(this),void(this.imgData=new Uint8Array(this.imgData));default:this.pos+=e}if(this.pos+=4,this.pos>this.data.length)throw new Error("Incomplete or corrupt PNG file")}}return o.load=function(t,e,a){var i;return"function"==typeof e&&(a=e),(i=new XMLHttpRequest).open("GET",t,!0),i.responseType="arraybuffer",i.onload=function(){var t;return t=new o(new Uint8Array(i.response||i.mozResponseArrayBuffer)),"function"==typeof(null!=e?e.getContext:void 0)&&t.render(e),"function"==typeof a?a(t):void 0},i.send(null)},a=1,i=2,e=0,o.prototype.read=function(t){var e,a;for(a=[],e=0;0<=t?e<t:e>t;0<=t?++e:--e)a.push(this.data[this.pos++]);return a},o.prototype.readUInt32=function(){return this.data[this.pos++]<<24|this.data[this.pos++]<<16|this.data[this.pos++]<<8|this.data[this.pos++]},o.prototype.readUInt16=function(){return this.data[this.pos++]<<8|this.data[this.pos++]},o.prototype.decodePixels=function(t){var e,a,i,s,r,n,o,h,c,p,d,u,f,m,g,w,y,x,b,k,T,I,A;if(null==t&&(t=this.imgData),0===t.length)return new Uint8Array(0);for(t=(t=new l(t)).getBytes(),w=(u=this.pixelBitlength/8)*this.width,f=new Uint8Array(w*this.height),n=t.length,g=0,m=0,a=0;m<n;){switch(t[m++]){case 0:for(s=b=0;b<w;s=b+=1)f[a++]=t[m++];break;case 1:for(s=k=0;k<w;s=k+=1)e=t[m++],r=s<u?0:f[a-u],f[a++]=(e+r)%256;break;case 2:for(s=T=0;T<w;s=T+=1)e=t[m++],i=(s-s%u)/u,y=g&&f[(g-1)*w+i*u+s%u],f[a++]=(y+e)%256;break;case 3:for(s=I=0;I<w;s=I+=1)e=t[m++],i=(s-s%u)/u,r=s<u?0:f[a-u],y=g&&f[(g-1)*w+i*u+s%u],f[a++]=(e+Math.floor((r+y)/2))%256;break;case 4:for(s=A=0;A<w;s=A+=1)e=t[m++],i=(s-s%u)/u,r=s<u?0:f[a-u],0===g?y=x=0:(y=f[(g-1)*w+i*u+s%u],x=i&&f[(g-1)*w+(i-1)*u+s%u]),o=r+y-x,h=Math.abs(o-r),p=Math.abs(o-y),d=Math.abs(o-x),c=h<=p&&h<=d?r:p<=d?y:x,f[a++]=(e+c)%256;break;default:throw new Error("Invalid filter algorithm: "+t[m-1])}g++}return f},o.prototype.decodePalette=function(){var t,e,a,i,s,r,n,o,h;for(a=this.palette,r=this.transparency.indexed||[],s=new Uint8Array((r.length||0)+a.length),i=0,a.length,t=0,e=n=0,o=a.length;n<o;e=n+=3)s[i++]=a[e],s[i++]=a[e+1],s[i++]=a[e+2],s[i++]=null!=(h=r[t++])?h:255;return s},o.prototype.copyToImageData=function(t,e){var a,i,s,r,n,o,h,c,l,p,d;if(i=this.colors,l=null,a=this.hasAlphaChannel,this.palette.length&&(l=null!=(d=this._decodedPalette)?d:this._decodedPalette=this.decodePalette(),i=4,a=!0),c=(s=t.data||t).length,n=l||e,r=o=0,1===i)for(;r<c;)h=l?4*e[r/4]:o,p=n[h++],s[r++]=p,s[r++]=p,s[r++]=p,s[r++]=a?n[h++]:this.transparency.grayscale&&this.transparency.grayscale===p?0:255,o=h;else for(;r<c;)h=l?4*e[r/4]:o,s[r++]=n[h++],s[r++]=n[h++],s[r++]=n[h++],s[r++]=a?n[h++]:this.transparency.rgb&&this.transparency.rgb[1]===n[h-3]&&this.transparency.rgb[3]===n[h-2]&&this.transparency.rgb[5]===n[h-1]?0:255,o=h},o.prototype.decode=function(){var t;return t=new Uint8Array(this.width*this.height*4),this.copyToImageData(t,this.decodePixels()),t},r=t.document&&t.document.createElement("canvas"),n=r&&r.getContext("2d"),s=function(t){var e;return n.width=t.width,n.height=t.height,n.clearRect(0,0,t.width,t.height),n.putImageData(t,0,0),(e=new Image).src=r.toDataURL(),e},o.prototype.decodeFrames=function(t){var e,a,i,r,n,o,h,c;if(this.animation){for(c=[],a=n=0,o=(h=this.animation.frames).length;n<o;a=++n)e=h[a],i=t.createImageData(e.width,e.height),r=this.decodePixels(new Uint8Array(e.data)),this.copyToImageData(i,r),e.imageData=i,c.push(e.image=s(i));return c}},o.prototype.renderFrame=function(t,s){var r,n,o;return r=(n=this.animation.frames)[s],o=n[s-1],0===s&&t.clearRect(0,0,this.width,this.height),(null!=o?o.disposeOp:void 0)===a?t.clearRect(o.xOffset,o.yOffset,o.width,o.height):(null!=o?o.disposeOp:void 0)===i&&t.putImageData(o.imageData,o.xOffset,o.yOffset),r.blendOp===e&&t.clearRect(r.xOffset,r.yOffset,r.width,r.height),t.drawImage(r.image,r.xOffset,r.yOffset)},o.prototype.animate=function(t){var e,a,i,s,r,n,o=this;return a=0,n=this.animation,s=n.numFrames,i=n.frames,r=n.numPlays,(e=function(){var n,h;if(n=a++%s,h=i[n],o.renderFrame(t,n),s>1&&a/s<r)return o.animation._timeout=setTimeout(e,h.delay)})()},o.prototype.stopAnimation=function(){var t;return clearTimeout(null!=(t=this.animation)?t._timeout:void 0)},o.prototype.render=function(t){var e,a;return t._png&&t._png.stopAnimation(),t._png=this,t.width=this.width,t.height=this.height,e=t.getContext("2d"),this.animation?(this.decodeFrames(e),this.animate(e)):(a=e.createImageData(this.width,this.height),this.copyToImageData(a,this.decodePixels()),e.putImageData(a,0,0))},o}(self);const g=new Set(["jpg","png","bmp","gif"]);async function w(e,s){if(!f)throw new t("rasterCoded:decode","lerc decoder is not supported on big endian platform");await n();const{offset:r}=s,{width:h,height:c,pixelType:l,statistics:p,depthCount:d,noDataValues:u,bandMasks:m,pixels:g,mask:w}=o(e,{inputOffset:r,returnInterleaved:s.returnInterleaved}),y=new a({width:h,height:c,pixelType:l.toLowerCase(),pixels:g,mask:w,statistics:p.map((({minValue:t,maxValue:e})=>new i(t,e))),bandMasks:m,depthCount:d,noDataValues:u});return p?.length||y.updateStatistics(),y}async function y(t,i){const s=await u(t,{...i,noDataValue:i.tiffNoDataValue,matchAllNoData:i.matchAllNoData});e(s);const r=new a({width:s.width,height:s.height,pixels:s.pixels,pixelType:s.pixelType.toLowerCase(),mask:s.mask,bandMasks:s.bandMasks,statistics:null});return r.updateStatistics(),r}async function x(t,e){const i=await d(t,e.customOptions),s=new a({width:i.width,height:i.height,pixels:i.pixels,pixelType:i.pixelType.toLowerCase(),mask:i.mask,statistics:null});return s.updateStatistics(),s}function b(t,e){const i=e.pixelType||"u8",s=a.getPixelArrayConstructor(i),r="u8"===i?t:new s(t.buffer),n=[],o=e.planes||1;if(1===o)n.push(r);else for(let a=0;a<o;a++){const i=(e.width||1)*(e.height||t.length),h=new s(i);for(let t=0;t<i;t++)h[t]=r[t*o+a];n.push(h)}const h=new a({width:e.width||1,height:e.height||t.length,pixels:n,pixelType:i,statistics:null});return h.updateStatistics(),h}function k(t,e){return b(new l(new Uint8Array(t)).getBytes(),e)}function T(t,e){return b(h(t,e.offset,e.eof,!e.isInputBigEndian),e)}function I(t,e,i){const{pixelTypeCtor:s}=S(e.pixelType),r=(0,p.decode)(t,{width:e.width,height:e.height,pixelType:s,format:i}),n=new a({width:e.width,height:e.height,pixels:r.pixels,pixelType:e.pixelType,mask:r.mask,statistics:null});return n.updateStatistics(),n}function A(t,e){const i=r.decode(t,e.hasNoZlibMask??void 0),s=new a({width:i.width,height:i.height,pixels:i.pixels,pixelType:"u8",mask:i.mask,statistics:null});return s.updateStatistics(),s}function C(t,e){const i=new Uint8Array(t),s=new m(i),{width:r,height:n}=e,o=r*n,h=s.decode();let c,l=0,p=0;const d=new Uint8Array(o);for(l=0;l<o;l++)d[l]=h[4*l+3];const u=new a({width:r,height:n,pixels:[],pixelType:"u8",mask:d,statistics:[]});for(l=0;l<3;l++){for(c=new Uint8Array(o),p=0;p<o;p++)c[p]=h[4*p+l];u.addData({pixels:c})}return u.updateStatistics(),u}async function v(t,e,i,r){const n=new s,o={applyJpegMask:!1,format:e,...i},h=await n.decode(t,o,r),c=new a(h);return c.updateStatistics(),c}function D(e){if(null==e)throw new t("rasterCodec:decode","parameter encodeddata is required.");const a=new Uint8Array(e,0,10);let i="";return 255===a[0]&&216===a[1]?i="jpg":137===a[0]&&80===a[1]&&78===a[2]&&71===a[3]?i="png":67===a[0]&&110===a[1]&&116===a[2]&&90===a[3]&&73===a[4]&&109===a[5]&&97===a[6]&&103===a[7]&&101===a[8]&&32===a[9]?i="lerc":76===a[0]&&101===a[1]&&114===a[2]&&99===a[3]&&50===a[4]&&32===a[5]?i="lerc2":73===a[0]&&73===a[1]&&42===a[2]&&0===a[3]||77===a[0]&&77===a[1]&&0===a[2]&&42===a[3]||73===a[0]&&73===a[1]&&43===a[2]&&0===a[3]||77===a[0]&&77===a[1]&&0===a[2]&&43===a[3]?i="tiff":71===a[0]&&73===a[1]&&70===a[2]?i="gif":66===a[0]&&77===a[1]?i="bmp":String.fromCharCode.apply(null,a).toLowerCase().includes("error")&&(i="error"),i}function U(e){let a=null;switch(e){case"lerc":case"lerc2":a=w;break;case"jpg":a=A;break;case"png":a=C;break;case"bsq":case"bip":a=(t,a)=>I(t,a,e);break;case"tiff":a=y;break;case"deflate":a=k;break;case"lzw":a=T;break;case"error":a=()=>{throw new t("rasterCodec:decode","input data contains error")};break;default:a=()=>{throw new t("rasterCodec:decode","unsupported raster format")}}return a}function S(t){let e=null,a=null;switch(t?t.toLowerCase():"f32"){case"u1":case"u2":case"u4":case"u8":a=255,e=Uint8Array;break;case"u16":a=a||65535,e=Uint16Array;break;case"u32":a=a||2**32-1,e=Uint32Array;break;case"s8":a=a||-128,e=Int8Array;break;case"s16":a=a||-32768,e=Int16Array;break;case"s32":a=a||0-2**31,e=Int32Array;break;default:e=Float32Array}return{pixelTypeCtor:e,noDataValue:a}}function O(t,e=1){if(!t)return;const{pixels:i,width:s,height:r,mask:n}=t;if(!i||0===i.length)return;const o=i.length,h=s-1,c=r-1,l=[];let p,d,u,f,m,g,w=null;const y=a.getPixelArrayConstructor(t.pixelType);if(0===e){for(p=0;p<o;p++){for(m=i[p],g=new y(h*c),d=0;d<c;d++)for(f=d*s,u=0;u<h;u++)g[d*h+u]=m[f+u];l.push(g)}if(null!=n)for(w=new Uint8Array(h*c),d=0;d<c;d++)for(f=d*s,u=0;u<h;u++)w[d*h+u]=n[f+u]}else{for(p=0;p<o;p++){for(m=i[p],g=new y(h*c),d=0;d<c;d++)for(f=d*s,u=0;u<h;u++)g[d*h+u]=(m[f+u]+m[f+u+1]+m[f+s+u]+m[f+s+u+1])/4;l.push(g)}if(n)for(w=new Uint8Array(h*c),d=0;d<c;d++)for(f=d*s,u=0;u<h;u++)w[d*h+u]=Math.min.apply(null,[n[f+u],n[f+u+1],n[f+s+u],n[f+s+u+1]])}t.width=h,t.height=c,t.mask=w,t.pixels=l}function P(t){let e=D(t);return"lerc2"===e?e="lerc":"error"===e&&(e=""),e}async function j(e,i={},s){if(null==e)throw new t("rasterCodec:decode","missing encodeddata parameter.");let r=i.format?.toLowerCase();if(!("bsq"!==r&&"bip"!==r||null!=i.width&&null!=i.height))throw new t("rasterCodec:decode","requires width and height in options parameter.");if("tiff"===r&&i.customOptions)return x(e,i);if((!r||"bsq"!==r&&"bip"!==r&&"deflate"!==r&&"lzw"!==r)&&(r=D(e)),i.useCanvas&&g.has(r))return v(e,r,i,s);const n=U(r);let o;i.isPoint&&(null!=(i={...i}).width&&i.width++,null!=i.height&&i.height++);const{offsets:h}=i;if(h&&h.length>1){const t=h.map(((t,a)=>n(e.slice(t,h[a+1]),i))),s=await Promise.all(t);o=s[0],o.pixels=s.map((t=>t.pixels[0]));const r=s.map((t=>t.mask));s.some((t=>null!=t))&&(r.forEach(((t,e)=>{null==t&&(r[e]=new Uint8Array(o.width*o.height).fill(255))})),o.bandMasks=r,o.mask=a.combineBandMasks(r)),o.updateStatistics()}else o=await n(e,{...i,offset:h?.[0]??i.offset});return"jpg"!==r&&null!=i.noDataValue&&1===o.depthCount&&c(o,i.noDataValue,{customFloatTolerance:i.tolerance}),i.isPoint&&O(o),o}export{j as decode,P as getFormat};
|
|
5
|
+
import t from"../../../core/Error.js";import{assertIsSome as e}from"../../../core/maybe.js";import a from"../PixelBlock.js";import{SimpleBandStatistics as i}from"../SimpleBandStatistics.js";import s from"./ImageCanvasDecoder.js";import r from"./JpgPlus.js";import{load as n,decode as o}from"./Lerc.js";import{decode as h}from"./Lzw.js";import{convertNoDataToMask as c}from"./pixelRangeUtils.js";import{Z as l}from"../../../chunks/Zlib.js";import p from"./Raw.js";import{decodeTileOrStrip as d,decode as u}from"./TiffDecoder.js";import{isPlatformLittleEndian as f}from"./utils.js";var m=function(t){var e,a,i,s,r,n;function o(t){var e,a,i,s,r,n,o,h,c,l,p,d,u;for(this.data=t,this.pos=8,this.palette=[],this.imgData=[],this.transparency={},this.animation=null,this.text={},r=null;;){switch(e=this.readUInt32(),h=function(){var t,e;for(e=[],t=0;t<4;++t)e.push(String.fromCharCode(this.data[this.pos++]));return e}.call(this).join(""),h){case"IHDR":this.width=this.readUInt32(),this.height=this.readUInt32(),this.bits=this.data[this.pos++],this.colorType=this.data[this.pos++],this.compressionMethod=this.data[this.pos++],this.filterMethod=this.data[this.pos++],this.interlaceMethod=this.data[this.pos++];break;case"acTL":this.animation={numFrames:this.readUInt32(),numPlays:this.readUInt32()||1/0,frames:[]};break;case"PLTE":this.palette=this.read(e);break;case"fcTL":r&&this.animation.frames.push(r),this.pos+=4,r={width:this.readUInt32(),height:this.readUInt32(),xOffset:this.readUInt32(),yOffset:this.readUInt32()},s=this.readUInt16(),i=this.readUInt16()||100,r.delay=1e3*s/i,r.disposeOp=this.data[this.pos++],r.blendOp=this.data[this.pos++],r.data=[];break;case"IDAT":case"fdAT":for("fdAT"===h&&(this.pos+=4,e-=4),t=(null!=r?r.data:void 0)||this.imgData,p=0;0<=e?p<e:p>e;0<=e?++p:--p)t.push(this.data[this.pos++]);break;case"tRNS":switch(this.transparency={},this.colorType){case 3:if(this.transparency.indexed=this.read(e),(c=255-this.transparency.indexed.length)>0)for(d=0;0<=c?d<c:d>c;0<=c?++d:--d)this.transparency.indexed.push(255);break;case 0:this.transparency.grayscale=this.read(e)[0];break;case 2:this.transparency.rgb=this.read(e)}break;case"tEXt":n=(l=this.read(e)).indexOf(0),o=String.fromCharCode.apply(String,l.slice(0,n)),this.text[o]=String.fromCharCode.apply(String,l.slice(n+1));break;case"IEND":return r&&this.animation.frames.push(r),this.colors=function(){switch(this.colorType){case 0:case 3:case 4:return 1;case 2:case 6:return 3}}.call(this),this.hasAlphaChannel=4===(u=this.colorType)||6===u,a=this.colors+(this.hasAlphaChannel?1:0),this.pixelBitlength=this.bits*a,this.colorSpace=function(){switch(this.colors){case 1:return"DeviceGray";case 3:return"DeviceRGB"}}.call(this),void(this.imgData=new Uint8Array(this.imgData));default:this.pos+=e}if(this.pos+=4,this.pos>this.data.length)throw new Error("Incomplete or corrupt PNG file")}}return o.load=function(t,e,a){var i;return"function"==typeof e&&(a=e),(i=new XMLHttpRequest).open("GET",t,!0),i.responseType="arraybuffer",i.onload=function(){var t;return t=new o(new Uint8Array(i.response||i.mozResponseArrayBuffer)),"function"==typeof(null!=e?e.getContext:void 0)&&t.render(e),"function"==typeof a?a(t):void 0},i.send(null)},a=1,i=2,e=0,o.prototype.read=function(t){var e,a;for(a=[],e=0;0<=t?e<t:e>t;0<=t?++e:--e)a.push(this.data[this.pos++]);return a},o.prototype.readUInt32=function(){return this.data[this.pos++]<<24|this.data[this.pos++]<<16|this.data[this.pos++]<<8|this.data[this.pos++]},o.prototype.readUInt16=function(){return this.data[this.pos++]<<8|this.data[this.pos++]},o.prototype.decodePixels=function(t){var e,a,i,s,r,n,o,h,c,p,d,u,f,m,g,w,y,x,b,k,T,I,A;if(null==t&&(t=this.imgData),0===t.length)return new Uint8Array(0);for(t=(t=new l(t)).getBytes(),w=(u=this.pixelBitlength/8)*this.width,f=new Uint8Array(w*this.height),n=t.length,g=0,m=0,a=0;m<n;){switch(t[m++]){case 0:for(s=b=0;b<w;s=b+=1)f[a++]=t[m++];break;case 1:for(s=k=0;k<w;s=k+=1)e=t[m++],r=s<u?0:f[a-u],f[a++]=(e+r)%256;break;case 2:for(s=T=0;T<w;s=T+=1)e=t[m++],i=(s-s%u)/u,y=g&&f[(g-1)*w+i*u+s%u],f[a++]=(y+e)%256;break;case 3:for(s=I=0;I<w;s=I+=1)e=t[m++],i=(s-s%u)/u,r=s<u?0:f[a-u],y=g&&f[(g-1)*w+i*u+s%u],f[a++]=(e+Math.floor((r+y)/2))%256;break;case 4:for(s=A=0;A<w;s=A+=1)e=t[m++],i=(s-s%u)/u,r=s<u?0:f[a-u],0===g?y=x=0:(y=f[(g-1)*w+i*u+s%u],x=i&&f[(g-1)*w+(i-1)*u+s%u]),o=r+y-x,h=Math.abs(o-r),p=Math.abs(o-y),d=Math.abs(o-x),c=h<=p&&h<=d?r:p<=d?y:x,f[a++]=(e+c)%256;break;default:throw new Error("Invalid filter algorithm: "+t[m-1])}g++}return f},o.prototype.decodePalette=function(){var t,e,a,i,s,r,n,o,h;for(a=this.palette,r=this.transparency.indexed||[],s=new Uint8Array((r.length||0)+a.length),i=0,a.length,t=0,e=n=0,o=a.length;n<o;e=n+=3)s[i++]=a[e],s[i++]=a[e+1],s[i++]=a[e+2],s[i++]=null!=(h=r[t++])?h:255;return s},o.prototype.copyToImageData=function(t,e){var a,i,s,r,n,o,h,c,l,p,d;if(i=this.colors,l=null,a=this.hasAlphaChannel,this.palette.length&&(l=null!=(d=this._decodedPalette)?d:this._decodedPalette=this.decodePalette(),i=4,a=!0),c=(s=t.data||t).length,n=l||e,r=o=0,1===i)for(;r<c;)h=l?4*e[r/4]:o,p=n[h++],s[r++]=p,s[r++]=p,s[r++]=p,s[r++]=a?n[h++]:this.transparency.grayscale&&this.transparency.grayscale===p?0:255,o=h;else for(;r<c;)h=l?4*e[r/4]:o,s[r++]=n[h++],s[r++]=n[h++],s[r++]=n[h++],s[r++]=a?n[h++]:this.transparency.rgb&&this.transparency.rgb[1]===n[h-3]&&this.transparency.rgb[3]===n[h-2]&&this.transparency.rgb[5]===n[h-1]?0:255,o=h},o.prototype.decode=function(){var t;return t=new Uint8Array(this.width*this.height*4),this.copyToImageData(t,this.decodePixels()),t},r=t.document&&t.document.createElement("canvas"),n=r&&r.getContext("2d"),s=function(t){var e;return n.width=t.width,n.height=t.height,n.clearRect(0,0,t.width,t.height),n.putImageData(t,0,0),(e=new Image).src=r.toDataURL(),e},o.prototype.decodeFrames=function(t){var e,a,i,r,n,o,h,c;if(this.animation){for(c=[],a=n=0,o=(h=this.animation.frames).length;n<o;a=++n)e=h[a],i=t.createImageData(e.width,e.height),r=this.decodePixels(new Uint8Array(e.data)),this.copyToImageData(i,r),e.imageData=i,c.push(e.image=s(i));return c}},o.prototype.renderFrame=function(t,s){var r,n,o;return r=(n=this.animation.frames)[s],o=n[s-1],0===s&&t.clearRect(0,0,this.width,this.height),(null!=o?o.disposeOp:void 0)===a?t.clearRect(o.xOffset,o.yOffset,o.width,o.height):(null!=o?o.disposeOp:void 0)===i&&t.putImageData(o.imageData,o.xOffset,o.yOffset),r.blendOp===e&&t.clearRect(r.xOffset,r.yOffset,r.width,r.height),t.drawImage(r.image,r.xOffset,r.yOffset)},o.prototype.animate=function(t){var e,a,i,s,r,n,o=this;return a=0,n=this.animation,s=n.numFrames,i=n.frames,r=n.numPlays,(e=function(){var n,h;if(n=a++%s,h=i[n],o.renderFrame(t,n),s>1&&a/s<r)return o.animation._timeout=setTimeout(e,h.delay)})()},o.prototype.stopAnimation=function(){var t;return clearTimeout(null!=(t=this.animation)?t._timeout:void 0)},o.prototype.render=function(t){var e,a;return t._png&&t._png.stopAnimation(),t._png=this,t.width=this.width,t.height=this.height,e=t.getContext("2d"),this.animation?(this.decodeFrames(e),this.animate(e)):(a=e.createImageData(this.width,this.height),this.copyToImageData(a,this.decodePixels()),e.putImageData(a,0,0))},o}(self);const g=new Set(["jpg","png","bmp","gif","webp"]);async function w(e,s){if(!f)throw new t("rasterCoded:decode","lerc decoder is not supported on big endian platform");await n();const{offset:r}=s,{width:h,height:c,pixelType:l,statistics:p,depthCount:d,noDataValues:u,bandMasks:m,pixels:g,mask:w}=o(e,{inputOffset:r,returnInterleaved:s.returnInterleaved}),y=new a({width:h,height:c,pixelType:l.toLowerCase(),pixels:g,mask:w,statistics:p.map((({minValue:t,maxValue:e})=>new i(t,e))),bandMasks:m,depthCount:d,noDataValues:u});return p?.length||y.updateStatistics(),y}async function y(t,i){const s=await u(t,{...i,noDataValue:i.tiffNoDataValue,matchAllNoData:i.matchAllNoData});e(s);const r=new a({width:s.width,height:s.height,pixels:s.pixels,pixelType:s.pixelType.toLowerCase(),mask:s.mask,bandMasks:s.bandMasks,statistics:null});return r.updateStatistics(),r}async function x(t,e){const i=await d(t,e.customOptions),s=new a({width:i.width,height:i.height,pixels:i.pixels,pixelType:i.pixelType.toLowerCase(),mask:i.mask,statistics:null});return s.updateStatistics(),s}function b(t,e){const i=e.pixelType||"u8",s=a.getPixelArrayConstructor(i),r="u8"===i?t:new s(t.buffer),n=[],o=e.planes||1;if(1===o)n.push(r);else for(let a=0;a<o;a++){const i=(e.width||1)*(e.height||t.length),h=new s(i);for(let t=0;t<i;t++)h[t]=r[t*o+a];n.push(h)}const h=new a({width:e.width||1,height:e.height||t.length,pixels:n,pixelType:i,statistics:null});return h.updateStatistics(),h}function k(t,e){return b(new l(new Uint8Array(t)).getBytes(),e)}function T(t,e){return b(h(t,e.offset,e.eof,!e.isInputBigEndian),e)}function I(t,e,i){const{pixelTypeCtor:s}=S(e.pixelType),r=(0,p.decode)(t,{width:e.width,height:e.height,pixelType:s,format:i}),n=new a({width:e.width,height:e.height,pixels:r.pixels,pixelType:e.pixelType,mask:r.mask,statistics:null});return n.updateStatistics(),n}function A(t,e){const i=r.decode(t,e.hasNoZlibMask??void 0),s=new a({width:i.width,height:i.height,pixels:i.pixels,pixelType:"u8",mask:i.mask,statistics:null});return s.updateStatistics(),s}function C(t,e){const i=new Uint8Array(t),s=new m(i),{width:r,height:n}=e,o=r*n,h=s.decode();let c,l=0,p=0;const d=new Uint8Array(o);for(l=0;l<o;l++)d[l]=h[4*l+3];const u=new a({width:r,height:n,pixels:[],pixelType:"u8",mask:d,statistics:[]});for(l=0;l<3;l++){for(c=new Uint8Array(o),p=0;p<o;p++)c[p]=h[4*p+l];u.addData({pixels:c})}return u.updateStatistics(),u}async function v(t,e,i,r){const n=new s,o={applyJpegMask:!1,format:e,...i},h=await n.decode(t,o,r),c=new a(h);return c.updateStatistics(),c}function D(e){if(null==e)throw new t("rasterCodec:decode","parameter encodeddata is required.");const headerLength = Math.min(e.byteLength, 12);const a = new Uint8Array(e, 0, headerLength);let i="";if (headerLength >= 12 && 82 === a[0] && 73 === a[1] && 70 === a[2] && 70 === a[3] && 87 === a[8] && 69 === a[9] && 66 === a[10] && 80 === a[11]) {return i = "webp";}return 255===a[0]&&216===a[1]?i="jpg":137===a[0]&&80===a[1]&&78===a[2]&&71===a[3]?i="png":67===a[0]&&110===a[1]&&116===a[2]&&90===a[3]&&73===a[4]&&109===a[5]&&97===a[6]&&103===a[7]&&101===a[8]&&32===a[9]?i="lerc":76===a[0]&&101===a[1]&&114===a[2]&&99===a[3]&&50===a[4]&&32===a[5]?i="lerc2":73===a[0]&&73===a[1]&&42===a[2]&&0===a[3]||77===a[0]&&77===a[1]&&0===a[2]&&42===a[3]||73===a[0]&&73===a[1]&&43===a[2]&&0===a[3]||77===a[0]&&77===a[1]&&0===a[2]&&43===a[3]?i="tiff":71===a[0]&&73===a[1]&&70===a[2]?i="gif":66===a[0]&&77===a[1]?i="bmp":String.fromCharCode.apply(null,a).toLowerCase().includes("error")&&(i="error"),i}function U(e){let a=null;switch(e){case"lerc":case"lerc2":a=w;break;case"jpg":a=A;break;case"png":a=C;break;case"bsq":case"bip":a=(t,a)=>I(t,a,e);break;case"tiff":a=y;break;case"deflate":a=k;break;case"lzw":a=T;break;case"error":a=()=>{throw new t("rasterCodec:decode","input data contains error")};break;default:a=()=>{throw new t("rasterCodec:decode","unsupported raster format")}}return a}function S(t){let e=null,a=null;switch(t?t.toLowerCase():"f32"){case"u1":case"u2":case"u4":case"u8":a=255,e=Uint8Array;break;case"u16":a=a||65535,e=Uint16Array;break;case"u32":a=a||2**32-1,e=Uint32Array;break;case"s8":a=a||-128,e=Int8Array;break;case"s16":a=a||-32768,e=Int16Array;break;case"s32":a=a||0-2**31,e=Int32Array;break;default:e=Float32Array}return{pixelTypeCtor:e,noDataValue:a}}function O(t,e=1){if(!t)return;const{pixels:i,width:s,height:r,mask:n}=t;if(!i||0===i.length)return;const o=i.length,h=s-1,c=r-1,l=[];let p,d,u,f,m,g,w=null;const y=a.getPixelArrayConstructor(t.pixelType);if(0===e){for(p=0;p<o;p++){for(m=i[p],g=new y(h*c),d=0;d<c;d++)for(f=d*s,u=0;u<h;u++)g[d*h+u]=m[f+u];l.push(g)}if(null!=n)for(w=new Uint8Array(h*c),d=0;d<c;d++)for(f=d*s,u=0;u<h;u++)w[d*h+u]=n[f+u]}else{for(p=0;p<o;p++){for(m=i[p],g=new y(h*c),d=0;d<c;d++)for(f=d*s,u=0;u<h;u++)g[d*h+u]=(m[f+u]+m[f+u+1]+m[f+s+u]+m[f+s+u+1])/4;l.push(g)}if(n)for(w=new Uint8Array(h*c),d=0;d<c;d++)for(f=d*s,u=0;u<h;u++)w[d*h+u]=Math.min.apply(null,[n[f+u],n[f+u+1],n[f+s+u],n[f+s+u+1]])}t.width=h,t.height=c,t.mask=w,t.pixels=l}function P(t){let e=D(t);return"lerc2"===e?e="lerc":"error"===e&&(e=""),e}async function j(e,i={},s){if(null==e)throw new t("rasterCodec:decode","missing encodeddata parameter.");let r=i.format?.toLowerCase();if(!("bsq"!==r&&"bip"!==r||null!=i.width&&null!=i.height))throw new t("rasterCodec:decode","requires width and height in options parameter.");if("tiff"===r&&i.customOptions)return x(e,i);if((!r||"bsq"!==r&&"bip"!==r&&"deflate"!==r&&"lzw"!==r)&&(r=D(e)),i.useCanvas&&g.has(r))return v(e,r,i,s);const n=U(r);let o;i.isPoint&&(null!=(i={...i}).width&&i.width++,null!=i.height&&i.height++);const{offsets:h}=i;if(h&&h.length>1){const t=h.map(((t,a)=>n(e.slice(t,h[a+1]),i))),s=await Promise.all(t);o=s[0],o.pixels=s.map((t=>t.pixels[0]));const r=s.map((t=>t.mask));s.some((t=>null!=t))&&(r.forEach(((t,e)=>{null==t&&(r[e]=new Uint8Array(o.width*o.height).fill(255))})),o.bandMasks=r,o.mask=a.combineBandMasks(r)),o.updateStatistics()}else o=await n(e,{...i,offset:h?.[0]??i.offset});return"jpg"!==r&&null!=i.noDataValue&&1===o.depthCount&&c(o,i.noDataValue,{customFloatTolerance:i.tolerance}),i.isPoint&&O(o),o}export{j as decode,P as getFormat};
|
package/package.json
CHANGED