UNPKG

@dp_unity/dpu-gis-viewer

Version:

DPU GIS Viewer version Beta

2 lines 26.6 kB
/*! For license information please see createVerticesFromHeightmap.js.LICENSE.txt */ import{a as sr,b as fr}from"./chunk-PJQ53UQY.js";import{a as tr}from"./chunk-4BYMTYMT.js";import{a as Ue}from"./chunk-UJMUN4NO.js";import{a as ar}from"./chunk-SOCYD7RP.js";import"./chunk-Q5MYX5A2.js";import"./chunk-CTRWX4F5.js";import{a as nr}from"./chunk-Z7BLUZ7R.js";import"./chunk-PY4CW263.js";import"./chunk-RRZIPF5C.js";import{d as ir}from"./chunk-K2M3OJ7Z.js";import{b as xe,g as rr,h as ae}from"./chunk-M3A6SPGI.js";import"./chunk-D5HNP2LB.js";import{a as ie,c as er,d as Ie}from"./chunk-S4VBGY2U.js";import{a as ge}from"./chunk-UCTPWOTZ.js";import"./chunk-54PMPXZ4.js";import{a as He}from"./chunk-R62IKKEC.js";import{a as Y}from"./chunk-N3A5CZ2S.js";import{a as he}from"./chunk-G75U3WZT.js";import{c as Ir,d as xr,e as G}from"./chunk-3THTQ4QB.js";var ur=Ir(((e,t)=>{!function(){var e,i,r,a,n,s,l=(e={defaultNoDataValue:-34027999387901484e22,decode:function(t,s){var l=(s=s||{}).encodedMaskData||null===s.encodedMaskData,o=n(t,s.inputOffset||0,l),f=null!==s.noDataValue?s.noDataValue:e.defaultNoDataValue,u=i(o,s.pixelType||Float32Array,s.encodedMaskData,f,s.returnMask),h={width:o.width,height:o.height,pixelData:u.resultPixels,minValue:u.minValue,maxValue:o.pixels.maxValue,noDataValue:f};return u.resultMask&&(h.maskData=u.resultMask),s.returnEncodedMask&&o.mask&&(h.encodedMaskData=o.mask.bitset?o.mask.bitset:null),s.returnFileInfo&&(h.fileInfo=r(o),s.computeUsedBitDepths&&(h.fileInfo.bitDepths=a(o))),h}},i=function(e,t,i,r,a){var n,l,o,f=0,u=e.pixels.numBlocksX,h=e.pixels.numBlocksY,c=Math.floor(e.width/u),m=Math.floor(e.height/h),d=2*e.maxZError,g=Number.MAX_VALUE;i=i||(e.mask?e.mask.bitset:null),l=new t(e.width*e.height),a&&i&&(o=new Uint8Array(e.width*e.height));for(var p,w,x=new Float32Array(c*m),k=0;k<=h;k++){var y=k!==h?m:e.height%h;if(0!==y)for(var I=0;I<=u;I++){var U=I!==u?c:e.width%u;if(0!==U){var b,T,v,M,A=k*e.width*m+I*c,V=e.width-U,D=e.pixels.blocks[f];if(D.encoding<2?(0===D.encoding?b=D.rawData:(s(D.stuffedData,D.bitsPerPixel,D.numValidPixels,D.offset,d,x,e.pixels.maxValue),b=x),T=0):v=2===D.encoding?0:D.offset,i)for(w=0;w<y;w++){for(7&A&&(M=i[A>>3],M<<=7&A),p=0;p<U;p++)7&A||(M=i[A>>3]),128&M?(o&&(o[A]=1),g=g>(n=D.encoding<2?b[T++]:v)?n:g,l[A++]=n):(o&&(o[A]=0),l[A++]=r),M<<=1;A+=V}else if(D.encoding<2)for(w=0;w<y;w++){for(p=0;p<U;p++)g=g>(n=b[T++])?n:g,l[A++]=n;A+=V}else for(g=g>v?v:g,w=0;w<y;w++){for(p=0;p<U;p++)l[A++]=v;A+=V}if(1===D.encoding&&T!==D.numValidPixels)throw"Block and Mask do not match";f++}}}return{resultPixels:l,resultMask:o,minValue:g}},r=function(e){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,noDataValue:e.noDataValue}}},a=function(e){for(var t=e.pixels.numBlocksX*e.pixels.numBlocksY,i={},r=0;r<t;r++){var a=e.pixels.blocks[r];0===a.encoding?i.float32=!0:1===a.encoding?i[a.bitsPerPixel]=!0:i[0]=!0}return Object.keys(i)},n=function(e,t,i){var r={},a=new Uint8Array(e,t,10);if(r.fileIdentifierString=String.fromCharCode.apply(null,a),"CntZImage"!==r.fileIdentifierString.trim())throw"Unexpected file identifier string: "+r.fileIdentifierString;t+=10;var n=new DataView(e,t,24);if(r.fileVersion=n.getInt32(0,!0),r.imageType=n.getInt32(4,!0),r.height=n.getUint32(8,!0),r.width=n.getUint32(12,!0),r.maxZError=n.getFloat64(16,!0),t+=24,!i)if(n=new DataView(e,t,16),r.mask={},r.mask.numBlocksY=n.getUint32(0,!0),r.mask.numBlocksX=n.getUint32(4,!0),r.mask.numBytes=n.getUint32(8,!0),r.mask.maxValue=n.getFloat32(12,!0),t+=16,r.mask.numBytes>0){var s=new Uint8Array(Math.ceil(r.width*r.height/8)),l=(n=new DataView(e,t,r.mask.numBytes)).getInt16(0,!0),o=2,f=0;do{if(l>0)for(;l--;)s[f++]=n.getUint8(o++);else{var u=n.getUint8(o++);for(l=-l;l--;)s[f++]=u}l=n.getInt16(o,!0),o+=2}while(o<r.mask.numBytes);if(-32768!==l||f<s.length)throw"Unexpected end of mask RLE encoding";r.mask.bitset=s,t+=r.mask.numBytes}else r.mask.numBytes|r.mask.numBlocksY|r.mask.maxValue||(r.mask.bitset=new Uint8Array(Math.ceil(r.width*r.height/8)));n=new DataView(e,t,16),r.pixels={},r.pixels.numBlocksY=n.getUint32(0,!0),r.pixels.numBlocksX=n.getUint32(4,!0),r.pixels.numBytes=n.getUint32(8,!0),r.pixels.maxValue=n.getFloat32(12,!0),t+=16;var h=r.pixels.numBlocksX,c=r.pixels.numBlocksY,m=h+(r.width%h>0?1:0),d=c+(r.height%c>0?1:0);r.pixels.blocks=new Array(m*d);for(var g=0,p=0;p<d;p++)for(var w=0;w<m;w++){var x=0,k=e.byteLength-t;n=new DataView(e,t,Math.min(10,k));var y={};r.pixels.blocks[g++]=y;var I=n.getUint8(0);if(x++,y.encoding=63&I,y.encoding>3)throw"Invalid block encoding ("+y.encoding+")";if(2!==y.encoding){if(0!==I&&2!==I){if(I>>=6,y.offsetType=I,2===I)y.offset=n.getInt8(1),x++;else if(1===I)y.offset=n.getInt16(1,!0),x+=2;else{if(0!==I)throw"Invalid block offset type";y.offset=n.getFloat32(1,!0),x+=4}if(1===y.encoding)if(I=n.getUint8(x),x++,y.bitsPerPixel=63&I,I>>=6,y.numValidPixelsType=I,2===I)y.numValidPixels=n.getUint8(x),x++;else if(1===I)y.numValidPixels=n.getUint16(x,!0),x+=2;else{if(0!==I)throw"Invalid valid pixel count type";y.numValidPixels=n.getUint32(x,!0),x+=4}}var U;if(t+=x,3!==y.encoding)if(0===y.encoding){var b=(r.pixels.numBytes-1)/4;if(b!==Math.floor(b))throw"uncompressed block has invalid length";U=new ArrayBuffer(4*b),new Uint8Array(U).set(new Uint8Array(e,t,4*b));var T=new Float32Array(U);y.rawData=T,t+=4*b}else if(1===y.encoding){var v=Math.ceil(y.numValidPixels*y.bitsPerPixel/8),M=Math.ceil(v/4);U=new ArrayBuffer(4*M),new Uint8Array(U).set(new Uint8Array(e,t,v)),y.stuffedData=new Uint32Array(U),t+=v}}else t++}return r.eofOffset=t,r},s=function(e,t,i,r,a,n,s){var l,o,f,u=(1<<t)-1,h=0,c=0,m=Math.ceil((s-r)/a),d=4*e.length-Math.ceil(t*i/8);for(e[e.length-1]<<=8*d,l=0;l<i;l++){if(0===c&&(f=e[h++],c=32),c>=t)o=f>>>c-t&u,c-=t;else{var g=t-c;o=(f&u)<<g&u,o+=(f=e[h++])>>>(c=32-g)}n[l]=o<m?r+o*a:s}return n},e),o=function(){"use strict";var e=function(e,t,i,r,a,n,s,l){var o,f,u,h,c,m=(1<<i)-1,d=0,g=0,p=4*e.length-Math.ceil(i*r/8);if(e[e.length-1]<<=8*p,a)for(o=0;o<r;o++)0===g&&(u=e[d++],g=32),g>=i?(f=u>>>g-i&m,g-=i):(f=(u&m)<<(h=i-g)&m,f+=(u=e[d++])>>>(g=32-h)),t[o]=a[f];else for(c=Math.ceil((l-n)/s),o=0;o<r;o++)0===g&&(u=e[d++],g=32),g>=i?(f=u>>>g-i&m,g-=i):(f=(u&m)<<(h=i-g)&m,f+=(u=e[d++])>>>(g=32-h)),t[o]=f<c?n+f*s:l},t=function(e,t,i,r,a,n,s,l){var o,f,u,h,c=(1<<i)-1,m=0,d=0,g=0;if(a)for(o=0;o<r;o++)0===d&&(u=e[m++],d=32,g=0),d>=i?(f=u>>>g&c,d-=i,g+=i):(f=u>>>g&c,d=32-(h=i-d),f|=((u=e[m++])&(1<<h)-1)<<i-h,g=h),t[o]=a[f];else{var p=Math.ceil((l-n)/s);for(o=0;o<r;o++)0===d&&(u=e[m++],d=32,g=0),d>=i?(f=u>>>g&c,d-=i,g+=i):(f=u>>>g&c,d=32-(h=i-d),f|=((u=e[m++])&(1<<h)-1)<<i-h,g=h),t[o]=f<p?n+f*s:l}return t},i={HUFFMAN_LUT_BITS_MAX:12,computeChecksumFletcher32:function(e){for(var t=65535,i=65535,r=e.length,a=Math.floor(r/2),n=0;a;){var s=a>=359?359:a;a-=s;do{t+=e[n++]<<8,i+=t+=e[n++]}while(--s);t=(65535&t)+(t>>>16),i=(65535&i)+(i>>>16)}return 1&r&&(i+=t+=e[n]<<8),((i=(65535&i)+(i>>>16))<<16|(t=(65535&t)+(t>>>16)))>>>0},readHeaderInfo:function(e,t){var i=t.ptr,r=new Uint8Array(e,i,6),a={};if(a.fileIdentifierString=String.fromCharCode.apply(null,r),0!==a.fileIdentifierString.lastIndexOf("Lerc2",0))throw"Unexpected file identifier string (expect Lerc2 ): "+a.fileIdentifierString;i+=6;var n,s=new DataView(e,i,8),l=s.getInt32(0,!0);if(a.fileVersion=l,i+=4,l>=3&&(a.checksum=s.getUint32(4,!0),i+=4),s=new DataView(e,i,12),a.height=s.getUint32(0,!0),a.width=s.getUint32(4,!0),i+=8,l>=4?(a.numDims=s.getUint32(8,!0),i+=4):a.numDims=1,s=new DataView(e,i,40),a.numValidPixel=s.getUint32(0,!0),a.microBlockSize=s.getInt32(4,!0),a.blobSize=s.getInt32(8,!0),a.imageType=s.getInt32(12,!0),a.maxZError=s.getFloat64(16,!0),a.zMin=s.getFloat64(24,!0),a.zMax=s.getFloat64(32,!0),i+=40,t.headerInfo=a,t.ptr=i,l>=3&&(n=l>=4?52:48,this.computeChecksumFletcher32(new Uint8Array(e,i-n,a.blobSize-14))!==a.checksum))throw"Checksum failed.";return!0},checkMinMaxRanges:function(e,t){var i=t.headerInfo,r=this.getDataTypeArray(i.imageType),a=i.numDims*this.getDataTypeSize(i.imageType),n=this.readSubArray(e,t.ptr,r,a),s=this.readSubArray(e,t.ptr+a,r,a);t.ptr+=2*a;var l,o=!0;for(l=0;l<i.numDims;l++)if(n[l]!==s[l]){o=!1;break}return i.minValues=n,i.maxValues=s,o},readSubArray:function(e,t,i,r){var a;if(i===Uint8Array)a=new Uint8Array(e,t,r);else{var n=new ArrayBuffer(r);new Uint8Array(n).set(new Uint8Array(e,t,r)),a=new i(n)}return a},readMask:function(e,t){var i,r,a=t.ptr,n=t.headerInfo,s=n.width*n.height,l=n.numValidPixel,o=new DataView(e,a,4),f={};if(f.numBytes=o.getUint32(0,!0),a+=4,(0===l||s===l)&&0!==f.numBytes)throw"invalid mask";if(0===l)i=new Uint8Array(Math.ceil(s/8)),f.bitset=i,r=new Uint8Array(s),t.pixels.resultMask=r,a+=f.numBytes;else if(f.numBytes>0){i=new Uint8Array(Math.ceil(s/8));var u=(o=new DataView(e,a,f.numBytes)).getInt16(0,!0),h=2,c=0,m=0;do{if(u>0)for(;u--;)i[c++]=o.getUint8(h++);else for(m=o.getUint8(h++),u=-u;u--;)i[c++]=m;u=o.getInt16(h,!0),h+=2}while(h<f.numBytes);if(-32768!==u||c<i.length)throw"Unexpected end of mask RLE encoding";r=new Uint8Array(s);var d=0,g=0;for(g=0;g<s;g++)7&g?(d=i[g>>3],d<<=7&g):d=i[g>>3],128&d&&(r[g]=1);t.pixels.resultMask=r,f.bitset=i,a+=f.numBytes}return t.ptr=a,t.mask=f,!0},readDataOneSweep:function(e,t,r){var a,n=t.ptr,s=t.headerInfo,l=s.numDims,o=s.width*s.height,f=s.imageType,u=s.numValidPixel*i.getDataTypeSize(f)*l,h=t.pixels.resultMask;if(r===Uint8Array)a=new Uint8Array(e,n,u);else{var c=new ArrayBuffer(u);new Uint8Array(c).set(new Uint8Array(e,n,u)),a=new r(c)}if(a.length===o*l)t.pixels.resultPixels=a;else{t.pixels.resultPixels=new r(o*l);var m=0,d=0,g=0,p=0;if(l>1)for(g=0;g<l;g++)for(p=g*o,d=0;d<o;d++)h[d]&&(t.pixels.resultPixels[p+d]=a[m++]);else for(d=0;d<o;d++)h[d]&&(t.pixels.resultPixels[d]=a[m++])}return n+=u,t.ptr=n,!0},readHuffmanTree:function(e,t){var a=this.HUFFMAN_LUT_BITS_MAX,n=new DataView(e,t.ptr,16);if(t.ptr+=16,n.getInt32(0,!0)<2)throw"unsupported Huffman version";var s=n.getInt32(4,!0),l=n.getInt32(8,!0),o=n.getInt32(12,!0);if(l>=o)return!1;var f=new Uint32Array(o-l);i.decodeBits(e,t,f);var u,h,c,m,d=[];for(u=l;u<o;u++)d[h=u-(u<s?0:s)]={first:f[u-l],second:null};var g=e.byteLength-t.ptr,p=Math.ceil(g/4),w=new ArrayBuffer(4*p);new Uint8Array(w).set(new Uint8Array(e,t.ptr,g));var x,k=new Uint32Array(w),y=0,I=0;for(x=k[0],u=l;u<o;u++)(m=d[h=u-(u<s?0:s)].first)>0&&(d[h].second=x<<y>>>32-m,32-y>=m?32===(y+=m)&&(y=0,x=k[++I]):(y+=m-32,x=k[++I],d[h].second|=x>>>32-y));var U,b=0,T=new r;for(u=0;u<d.length;u++)void 0!==d[u]&&(b=Math.max(b,d[u].first));U=b>=a?a:b,b>=30&&console.log("WARning, large NUM LUT BITS IS "+b);var v,M,A,V,D,B=[];for(u=l;u<o;u++)if((m=d[h=u-(u<s?0:s)].first)>0)if(v=[m,h],m<=U)for(M=d[h].second<<U-m,A=1<<U-m,c=0;c<A;c++)B[M|c]=v;else for(M=d[h].second,D=T,V=m-1;V>=0;V--)M>>>V&1?(D.right||(D.right=new r),D=D.right):(D.left||(D.left=new r),D=D.left),0===V&&!D.val&&(D.val=v[1]);return{decodeLut:B,numBitsLUTQick:U,numBitsLUT:b,tree:T,stuffedData:k,srcPtr:I,bitPos:y}},readHuffman:function(e,t,i){var r,a,n,s,l,o,f,u,h,c=t.headerInfo,m=c.numDims,d=t.headerInfo.height,g=t.headerInfo.width,p=g*d,w=this.readHuffmanTree(e,t),x=w.decodeLut,k=w.tree,y=w.stuffedData,I=w.srcPtr,U=w.bitPos,b=w.numBitsLUTQick,T=w.numBitsLUT,v=0===t.headerInfo.imageType?128:0,M=t.pixels.resultMask,A=0;U>0&&(I++,U=0);var V,D=y[I],B=1===t.encodeMode,S=new i(p*m),P=S;for(V=0;V<c.numDims;V++){if(m>1&&(P=new i(S.buffer,p*V,p),A=0),t.headerInfo.numValidPixel===g*d)for(u=0,o=0;o<d;o++)for(f=0;f<g;f++,u++){if(a=0,l=s=D<<U>>>32-b,32-U<b&&(l=s|=y[I+1]>>>64-U-b),x[l])a=x[l][1],U+=x[l][0];else for(l=s=D<<U>>>32-T,32-U<T&&(l=s|=y[I+1]>>>64-U-T),r=k,h=0;h<T;h++)if(!(r=s>>>T-h-1&1?r.right:r.left).left&&!r.right){a=r.val,U=U+h+1;break}U>=32&&(U-=32,D=y[++I]),n=a-v,B?(n+=f>0?A:o>0?P[u-g]:A,n&=255,P[u]=n,A=n):P[u]=n}else for(u=0,o=0;o<d;o++)for(f=0;f<g;f++,u++)if(M[u]){if(a=0,l=s=D<<U>>>32-b,32-U<b&&(l=s|=y[I+1]>>>64-U-b),x[l])a=x[l][1],U+=x[l][0];else for(l=s=D<<U>>>32-T,32-U<T&&(l=s|=y[I+1]>>>64-U-T),r=k,h=0;h<T;h++)if(!(r=s>>>T-h-1&1?r.right:r.left).left&&!r.right){a=r.val,U=U+h+1;break}U>=32&&(U-=32,D=y[++I]),n=a-v,B?(f>0&&M[u-1]?n+=A:o>0&&M[u-g]?n+=P[u-g]:n+=A,n&=255,P[u]=n,A=n):P[u]=n}t.ptr=t.ptr+4*(I+1)+(U>0?4:0)}t.pixels.resultPixels=S},decodeBits:function(i,r,a,n,s){var l=r.headerInfo,o=l.fileVersion,f=0,u=new DataView(i,r.ptr,5),h=u.getUint8(0);f++;var c=h>>6,m=0===c?4:3-c,d=(32&h)>0,g=31&h,p=0;if(1===m)p=u.getUint8(f),f++;else if(2===m)p=u.getUint16(f,!0),f+=2;else{if(4!==m)throw"Invalid valid pixel count type";p=u.getUint32(f,!0),f+=4}var w,x,k,y,I,U,b,T,v,M=2*l.maxZError,A=l.numDims>1?l.maxValues[s]:l.zMax;if(d){for(r.counter.lut++,T=u.getUint8(f),f++,y=Math.ceil((T-1)*g/8),I=Math.ceil(y/4),x=new ArrayBuffer(4*I),k=new Uint8Array(x),r.ptr+=f,k.set(new Uint8Array(i,r.ptr,y)),b=new Uint32Array(x),r.ptr+=y,v=0;T-1>>>v;)v++;y=Math.ceil(p*v/8),I=Math.ceil(y/4),x=new ArrayBuffer(4*I),(k=new Uint8Array(x)).set(new Uint8Array(i,r.ptr,y)),w=new Uint32Array(x),r.ptr+=y,U=o>=3?function(e,t,i,r,a,n){var s,l=(1<<t)-1,o=0,f=0,u=0,h=0,c=0,m=0,d=[],g=Math.ceil((n-r)/a);for(f=0;f<i;f++)0===h&&(s=e[o++],h=32,m=0),h>=t?(c=s>>>m&l,h-=t,m+=t):(c=s>>>m&l,h=32-(u=t-h),c|=((s=e[o++])&(1<<u)-1)<<t-u,m=u),d[f]=c<g?r+c*a:n;return d.unshift(r),d}(b,g,T-1,n,M,A):function(e,t,i,r,a,n){var s,l=(1<<t)-1,o=0,f=0,u=0,h=0,c=0,m=[],d=4*e.length-Math.ceil(t*i/8);e[e.length-1]<<=8*d;var g=Math.ceil((n-r)/a);for(f=0;f<i;f++)0===h&&(s=e[o++],h=32),h>=t?(c=s>>>h-t&l,h-=t):(c=(s&l)<<(u=t-h)&l,c+=(s=e[o++])>>>(h=32-u)),m[f]=c<g?r+c*a:n;return m.unshift(r),m}(b,g,T-1,n,M,A),o>=3?t(w,a,v,p,U):e(w,a,v,p,U)}else r.counter.bitstuffer++,v=g,r.ptr+=f,v>0&&(y=Math.ceil(p*v/8),I=Math.ceil(y/4),x=new ArrayBuffer(4*I),(k=new Uint8Array(x)).set(new Uint8Array(i,r.ptr,y)),w=new Uint32Array(x),r.ptr+=y,o>=3?null==n?function(e,t,i,r){var a,n,s,l,o=(1<<i)-1,f=0,u=0,h=0;for(a=0;a<r;a++)0===u&&(s=e[f++],u=32,h=0),u>=i?(n=s>>>h&o,u-=i,h+=i):(n=s>>>h&o,u=32-(l=i-u),n|=((s=e[f++])&(1<<l)-1)<<i-l,h=l),t[a]=n}(w,a,v,p):t(w,a,v,p,!1,n,M,A):null==n?function(e,t,i,r){var a,n,s,l,o=(1<<i)-1,f=0,u=0,h=4*e.length-Math.ceil(i*r/8);for(e[e.length-1]<<=8*h,a=0;a<r;a++)0===u&&(s=e[f++],u=32),u>=i?(n=s>>>u-i&o,u-=i):(n=(s&o)<<(l=i-u)&o,n+=(s=e[f++])>>>(u=32-l)),t[a]=n}(w,a,v,p):e(w,a,v,p,!1,n,M,A))},readTiles:function(e,t,r){var a=t.headerInfo,n=a.width,s=a.height,l=a.microBlockSize,o=a.imageType,f=i.getDataTypeSize(o),u=Math.ceil(n/l),h=Math.ceil(s/l);t.pixels.numBlocksY=h,t.pixels.numBlocksX=u,t.pixels.ptr=0;var c,m,d,g,p,w,x,k,y=0,I=0,U=0,b=0,T=0,v=0,M=0,A=0,V=0,D=0,B=0,S=0,P=0,E=0,F=0,Y=new r(l*l),N=s%l||l,C=n%l||l,O=a.numDims,L=t.pixels.resultMask,R=t.pixels.resultPixels;for(U=0;U<h;U++)for(T=U!==h-1?l:N,b=0;b<u;b++)for(D=U*n*l+b*l,B=n-(v=b!==u-1?l:C),k=0;k<O;k++){if(O>1&&(R=new r(t.pixels.resultPixels.buffer,n*s*k*f,n*s)),M=e.byteLength-t.ptr,m={},F=0,F++,V=(A=(c=new DataView(e,t.ptr,Math.min(10,M))).getUint8(0))>>6&255,(A>>2&15)!=(b*l>>3&15))throw"integrity issue";if((p=3&A)>3)throw t.ptr+=F,"Invalid block encoding ("+p+")";if(2!==p)if(0===p){if(t.counter.uncompressed++,t.ptr+=F,S=(S=T*v*f)<(P=e.byteLength-t.ptr)?S:P,d=new ArrayBuffer(S%f==0?S:S+f-S%f),new Uint8Array(d).set(new Uint8Array(e,t.ptr,S)),g=new r(d),E=0,L)for(y=0;y<T;y++){for(I=0;I<v;I++)L[D]&&(R[D]=g[E++]),D++;D+=B}else for(y=0;y<T;y++){for(I=0;I<v;I++)R[D++]=g[E++];D+=B}t.ptr+=E*f}else if(w=i.getDataTypeUsed(o,V),x=i.getOnePixel(m,F,w,c),F+=i.getDataTypeSize(w),3===p)if(t.ptr+=F,t.counter.constantoffset++,L)for(y=0;y<T;y++){for(I=0;I<v;I++)L[D]&&(R[D]=x),D++;D+=B}else for(y=0;y<T;y++){for(I=0;I<v;I++)R[D++]=x;D+=B}else if(t.ptr+=F,i.decodeBits(e,t,Y,x,k),F=0,L)for(y=0;y<T;y++){for(I=0;I<v;I++)L[D]&&(R[D]=Y[F++]),D++;D+=B}else for(y=0;y<T;y++){for(I=0;I<v;I++)R[D++]=Y[F++];D+=B}else t.counter.constant++,t.ptr+=F}},formatFileInfo:function(e){return{fileIdentifierString:e.headerInfo.fileIdentifierString,fileVersion:e.headerInfo.fileVersion,imageType:e.headerInfo.imageType,height:e.headerInfo.height,width:e.headerInfo.width,numValidPixel:e.headerInfo.numValidPixel,microBlockSize:e.headerInfo.microBlockSize,blobSize:e.headerInfo.blobSize,maxZError:e.headerInfo.maxZError,pixelType:i.getPixelType(e.headerInfo.imageType),eofOffset:e.eofOffset,mask:e.mask?{numBytes:e.mask.numBytes}:null,pixels:{numBlocksX:e.pixels.numBlocksX,numBlocksY:e.pixels.numBlocksY,maxValue:e.headerInfo.zMax,minValue:e.headerInfo.zMin,noDataValue:e.noDataValue}}},constructConstantSurface:function(e){var t=e.headerInfo.zMax,i=e.headerInfo.numDims,r=e.headerInfo.height*e.headerInfo.width,a=r*i,n=0,s=0,l=0,o=e.pixels.resultMask;if(o)if(i>1)for(n=0;n<i;n++)for(l=n*r,s=0;s<r;s++)o[s]&&(e.pixels.resultPixels[l+s]=t);else for(s=0;s<r;s++)o[s]&&(e.pixels.resultPixels[s]=t);else if(e.pixels.resultPixels.fill)e.pixels.resultPixels.fill(t);else for(s=0;s<a;s++)e.pixels.resultPixels[s]=t},getDataTypeArray:function(e){var t;switch(e){case 0:t=Int8Array;break;case 1:t=Uint8Array;break;case 2:t=Int16Array;break;case 3:t=Uint16Array;break;case 4:t=Int32Array;break;case 5:t=Uint32Array;break;case 6:default:t=Float32Array;break;case 7:t=Float64Array}return t},getPixelType:function(e){var t;switch(e){case 0:t="S8";break;case 1:t="U8";break;case 2:t="S16";break;case 3:t="U16";break;case 4:t="S32";break;case 5:t="U32";break;case 6:default:t="F32";break;case 7:t="F64"}return t},isValidPixelValue:function(e,t){if(null==t)return!1;var i;switch(e){case 0:i=t>=-128&&t<=127;break;case 1:i=t>=0&&t<=255;break;case 2:i=t>=-32768&&t<=32767;break;case 3:i=t>=0&&t<=65536;break;case 4:i=t>=-2147483648&&t<=2147483647;break;case 5:i=t>=0&&t<=4294967296;break;case 6:i=t>=-34027999387901484e22&&t<=34027999387901484e22;break;case 7:i=t>=5e-324&&t<=17976931348623157e292;break;default:i=!1}return i},getDataTypeSize:function(e){var t=0;switch(e){case 0:case 1:t=1;break;case 2:case 3:t=2;break;case 4:case 5:case 6:t=4;break;case 7:t=8;break;default:t=e}return t},getDataTypeUsed:function(e,t){var i=e;switch(e){case 2:case 4:i=e-t;break;case 3:case 5:i=e-2*t;break;case 6:i=0===t?e:1===t?2:1;break;case 7:i=0===t?e:e-2*t+1;break;default:i=e}return i},getOnePixel:function(e,t,i,r){var a=0;switch(i){case 0:a=r.getInt8(t);break;case 1:a=r.getUint8(t);break;case 2:a=r.getInt16(t,!0);break;case 3:a=r.getUint16(t,!0);break;case 4:a=r.getInt32(t,!0);break;case 5:a=r.getUInt32(t,!0);break;case 6:a=r.getFloat32(t,!0);break;case 7:a=r.getFloat64(t,!0);break;default:throw"the decoder does not understand this pixel type"}return a}},r=function(e,t,i){this.val=e,this.left=t,this.right=i},a={decode:function(e,t){var r=(t=t||{}).noDataValue,a=0,n={};if(n.ptr=t.inputOffset||0,n.pixels={},i.readHeaderInfo(e,n)){var s=n.headerInfo,l=s.fileVersion,o=i.getDataTypeArray(s.imageType);i.readMask(e,n),s.numValidPixel!==s.width*s.height&&!n.pixels.resultMask&&(n.pixels.resultMask=t.maskData);var f,u=s.width*s.height;if(n.pixels.resultPixels=new o(u*s.numDims),n.counter={onesweep:0,uncompressed:0,lut:0,bitstuffer:0,constant:0,constantoffset:0},0!==s.numValidPixel)if(s.zMax===s.zMin)i.constructConstantSurface(n);else if(l>=4&&i.checkMinMaxRanges(e,n))i.constructConstantSurface(n);else{var h=new DataView(e,n.ptr,2),c=h.getUint8(0);if(n.ptr++,c)i.readDataOneSweep(e,n,o);else if(l>1&&s.imageType<=1&&Math.abs(s.maxZError-.5)<1e-5){var m=h.getUint8(1);if(n.ptr++,n.encodeMode=m,m>2||l<4&&m>1)throw"Invalid Huffman flag "+m;m?i.readHuffman(e,n,o):i.readTiles(e,n,o)}else i.readTiles(e,n,o)}n.eofOffset=n.ptr,t.inputOffset?(f=n.headerInfo.blobSize+t.inputOffset-n.ptr,Math.abs(f)>=1&&(n.eofOffset=t.inputOffset+n.headerInfo.blobSize)):(f=n.headerInfo.blobSize-n.ptr,Math.abs(f)>=1&&(n.eofOffset=n.headerInfo.blobSize));var d={width:s.width,height:s.height,pixelData:n.pixels.resultPixels,minValue:s.zMin,maxValue:s.zMax,validPixelCount:s.numValidPixel,dimCount:s.numDims,dimStats:{minValues:s.minValues,maxValues:s.maxValues},maskData:n.pixels.resultMask};if(n.pixels.resultMask&&i.isValidPixelValue(s.imageType,r)){var g=n.pixels.resultMask;for(a=0;a<u;a++)g[a]||(d.pixelData[a]=r);d.noDataValue=r}return n.noDataValue=r,t.returnFileInfo&&(d.fileInfo=i.formatFileInfo(n)),d}},getBandCount:function(e){for(var t=0,r=0,a={ptr:0,pixels:{}};r<e.byteLength-58;)i.readHeaderInfo(e,a),r+=a.headerInfo.blobSize,t++,a.ptr=r;return t}};return a}(),f=function(){var e=new ArrayBuffer(4),t=new Uint8Array(e);return new Uint32Array(e)[0]=1,1===t[0]}(),u={decode:function(e,t){if(!f)throw"Big endian system is not supported.";var i,r,a,n,s,u=(t=t||{}).inputOffset||0,h=new Uint8Array(e,u,10),c=String.fromCharCode.apply(null,h);if("CntZImage"===c.trim())i=l,r=1;else{if("Lerc2"!==c.substring(0,5))throw"Unexpected file identifier string: "+c;i=o,r=2}for(var m,d,g,p=0,w=e.byteLength-10,x=[],k={width:0,height:0,pixels:[],pixelType:t.pixelType,mask:null,statistics:[]};u<w;){var y=i.decode(e,{inputOffset:u,encodedMaskData:m,maskData:g,returnMask:0===p,returnEncodedMask:0===p,returnFileInfo:!0,pixelType:t.pixelType||null,noDataValue:t.noDataValue||null});u=y.fileInfo.eofOffset,0===p&&(m=y.encodedMaskData,g=y.maskData,k.width=y.width,k.height=y.height,k.dimCount=y.dimCount||1,k.pixelType=y.pixelType||y.fileInfo.pixelType,k.mask=y.maskData),r>1&&y.fileInfo.mask&&y.fileInfo.mask.numBytes>0&&x.push(y.maskData),p++,k.pixels.push(y.pixelData),k.statistics.push({minValue:y.minValue,maxValue:y.maxValue,noDataValue:y.noDataValue,dimStats:y.dimStats})}if(r>1&&x.length>1){for(s=k.width*k.height,k.bandMasks=x,(g=new Uint8Array(s)).set(x[0]),a=1;a<x.length;a++)for(d=x[a],n=0;n<s;n++)g[n]=g[n]&d[n];k.maskData=g}return k}};"function"==typeof define&&define.amd?define([],(function(){return u})):typeof t<"u"&&t.exports?t.exports=u:this.Lerc=u}()})),Ur={NONE:0,LERC:1},or=Object.freeze(Ur),Q={};Q.DEFAULT_STRUCTURE=Object.freeze({heightScale:1,heightOffset:0,elementsPerHeight:1,stride:1,elementMultiplier:256,isBigEndian:!1});var Ye=new ie,Tr=new xe,kr=new ie,yr=new ie;Q.computeVertices=function(e){if(!G(e)||!G(e.heightmap))throw new he("options.heightmap is required.");if(!G(e.width)||!G(e.height))throw new he("options.width and options.height are required.");if(!G(e.nativeRectangle))throw new he("options.nativeRectangle is required.");if(!G(e.skirtHeight))throw new he("options.skirtHeight is required.");let t,i,r,a,n=Math.cos,s=Math.sin,l=Math.sqrt,o=Math.atan,f=Math.exp,u=ge.PI_OVER_TWO,h=ge.toRadians,c=e.heightmap,m=e.width,d=e.height,g=e.skirtHeight,p=g>0,w=Y(e.isGeographic,!0),x=Y(e.ellipsoid,Ie.default),k=1/x.maximumRadius,y=ae.clone(e.nativeRectangle),I=ae.clone(e.rectangle);G(I)?(t=I.west,i=I.south,r=I.east,a=I.north):w?(t=h(y.west),i=h(y.south),r=h(y.east),a=h(y.north)):(t=y.west*k,i=u-2*o(f(-y.south*k)),r=y.east*k,a=u-2*o(f(-y.north*k)));let U=e.relativeToCenter,b=G(U);U=b?U:ie.ZERO;let T=Y(e.includeWebMercatorT,!1),v=Y(e.exaggeration,1),M=Y(e.exaggerationRelativeHeight,0),A=1!==v,V=Y(e.structure,Q.DEFAULT_STRUCTURE),D=Y(V.heightScale,Q.DEFAULT_STRUCTURE.heightScale),B=Y(V.heightOffset,Q.DEFAULT_STRUCTURE.heightOffset),S=Y(V.elementsPerHeight,Q.DEFAULT_STRUCTURE.elementsPerHeight),P=Y(V.stride,Q.DEFAULT_STRUCTURE.stride),E=Y(V.elementMultiplier,Q.DEFAULT_STRUCTURE.elementMultiplier),F=Y(V.isBigEndian,Q.DEFAULT_STRUCTURE.isBigEndian),N=ae.computeWidth(y),C=ae.computeHeight(y),O=N/(m-1),L=C/(d-1);w||(N*=k,C*=k);let R,z,H=x.radiiSquared,_=H.x,j=H.y,Z=H.z,X=65536,W=-65536,q=rr.eastNorthUpToFixedFrame(U,x),J=xe.inverseTransformation(q,Tr);T&&(R=Ue.geodeticLatitudeToMercatorAngle(i),z=1/(Ue.geodeticLatitudeToMercatorAngle(a)-R));let K=kr;K.x=Number.POSITIVE_INFINITY,K.y=Number.POSITIVE_INFINITY,K.z=Number.POSITIVE_INFINITY;let $=yr;$.x=Number.NEGATIVE_INFINITY,$.y=Number.NEGATIVE_INFINITY,$.z=Number.NEGATIVE_INFINITY;let ee=Number.POSITIVE_INFINITY,te=m*d,re=te+(g>0?2*m+2*d:0),ne=new Array(re),se=new Array(re),le=new Array(re),oe=T?new Array(re):[],fe=A?new Array(re):[],ue=0,ce=d,me=0,de=m;p&&(--ue,++ce,--me,++de);let pe=1e-5;for(let e=ue;e<ce;++e){let p=e;p<0&&(p=0),p>=d&&(p=d-1);let I=y.north-L*p;I=w?h(I):u-2*o(f(-I*k));let U=(I-i)/(a-i);U=ge.clamp(U,0,1);let b=e===ue,v=e===ce-1;g>0&&(b?I+=pe*C:v&&(I-=pe*C));let M,V=n(I),Y=s(I),H=Z*Y;T&&(M=(Ue.geodeticLatitudeToMercatorAngle(I)-R)*z);for(let e=me;e<de;++e){let i=e;i<0&&(i=0),i>=m&&(i=m-1);let a,o=p*(m*P)+i*P;if(1===S)a=c[o];else{let e;if(a=0,F)for(e=0;e<S;++e)a=a*E+c[o+e];else for(e=S-1;e>=0;--e)a=a*E+c[o+e]}a=a*D+B,W=Math.max(W,a),X=Math.min(X,a);let f=y.west+O*i;w?f=h(f):f*=k;let u=(f-t)/(r-t);u=ge.clamp(u,0,1);let I=p*m+i;if(g>0){let t=e===me,r=e===de-1,n=b||v||t||r;if((b||v)&&(t||r))continue;n&&(a-=g,t?(I=te+(d-p-1),f-=pe*N):v?I=te+d+(m-i-1):r?(I=te+d+m+p,f+=pe*N):b&&(I=te+d+m+d+i))}let C=V*n(f),L=V*s(f),R=_*C,z=j*L,Z=1/l(R*C+z*L+H*Y),Q=R*Z,G=z*Z,q=H*Z,re=new ie;re.x=Q+C*a,re.y=G+L*a,re.z=q+Y*a,xe.multiplyByPoint(J,re,Ye),ie.minimumByComponent(Ye,K,K),ie.maximumByComponent(Ye,$,$),ee=Math.min(ee,a),ne[I]=re,le[I]=new er(u,U),se[I]=a,T&&(oe[I]=M),A&&(fe[I]=x.geodeticSurfaceNormal(re))}}let we,ke,ye=ir.fromPoints(ne);G(I)&&(we=ar.fromRectangle(I,X,W,x)),b&&(ke=new sr(x).computeHorizonCullingPointPossiblyUnderEllipsoid(U,ne,X));let be=new nr(K,$,U),Te=new fr(U,be,ee,W,q,!1,T,A,v,M),ve=new Float32Array(re*Te.stride),Me=0;for(let e=0;e<re;++e)Me=Te.encode(ve,Me,ne[e],le[e],se[e],void 0,oe[e],fe[e]);return{vertices:ve,maximumHeight:W,minimumHeight:X,encoding:Te,boundingSphere3D:ye,orientedBoundingBox:we,occludeePointInScaledSpace:ke}};var lr=Q,cr=xr(ur(),1);function Mr(e,t){if(e.encoding===or.LERC){let t;try{t=cr.default.decode(e.heightmap)}catch(e){throw new He(e)}if(t.statistics[0].minValue===Number.MAX_VALUE)throw new He("Invalid tile data");e.heightmap=t.pixels[0],e.width=t.width,e.height=t.height}e.ellipsoid=Ie.clone(e.ellipsoid),e.rectangle=ae.clone(e.rectangle);let i=lr.computeVertices(e),r=i.vertices;return t.push(r.buffer),{vertices:r.buffer,numberOfAttributes:i.encoding.stride,minimumHeight:i.minimumHeight,maximumHeight:i.maximumHeight,gridWidth:e.width,gridHeight:e.height,boundingSphere3D:i.boundingSphere3D,orientedBoundingBox:i.orientedBoundingBox,occludeePointInScaledSpace:i.occludeePointInScaledSpace,encoding:i.encoding,westIndicesSouthToNorth:i.westIndicesSouthToNorth,southIndicesEastToWest:i.southIndicesEastToWest,eastIndicesNorthToSouth:i.eastIndicesNorthToSouth,northIndicesWestToEast:i.northIndicesWestToEast}}var Pr=tr(Mr);export{Pr as default};