UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 4.71 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{getAssetUrl as e}from"../../../assets.js";const t=[{pixelType:"S8",size:1,ctor:Int8Array,range:[-128,127]},{pixelType:"U8",size:1,ctor:Uint8Array,range:[0,255]},{pixelType:"S16",size:2,ctor:Int16Array,range:[-32768,32767]},{pixelType:"U16",size:2,ctor:Uint16Array,range:[0,65536]},{pixelType:"S32",size:4,ctor:Int32Array,range:[-2147483648,2147483647]},{pixelType:"U32",size:4,ctor:Uint32Array,range:[0,4294967296]},{pixelType:"F32",size:4,ctor:Float32Array,range:[-34027999387901484e22,34027999387901484e22]},{pixelType:"F64",size:8,ctor:Float64Array,range:[-17976931348623157e292,17976931348623157e292]}];let n=null;function r(){return n||(n=import("../../../chunks/lerc-wasm.js").then((e=>e.l)).then((({default:t})=>t({locateFile:t=>e(`esri/layers/support/rasterFormats/${t}`)}))).then((e=>{l(e)})),n)}const a={getBlobInfo:null,decode:null};function o(e){return 16+(e>>3<<3)}function s(e,t,n){n.set(e.slice(t,t+n.length))}function l(e){const{_malloc:n,_free:r,_lerc_getBlobInfo:l,_lerc_getDataRanges:i,_lerc_decode_4D:u,asm:f}=e;let c;const h=Object.values(f).find((t=>t&&"buffer"in t&&t.buffer===e.HEAPU8.buffer)),y=e=>{const t=e.map((e=>o(e))),r=t.reduce(((e,t)=>e+t)),a=n(r);c=new Uint8Array(h.buffer);let s=t[0];t[0]=a;for(let n=1;n<t.length;n++){const e=t[n];t[n]=t[n-1]+s,s=e}return t};a.getBlobInfo=e=>{const t=12,n=3,a=new Uint8Array(4*t),o=new Uint8Array(8*n),[u,f,p]=y([e.length,a.length,o.length]);c.set(e,u),c.set(a,f),c.set(o,p);let g=l(u,e.length,f,p,t,n);if(g)throw r(u),new Error(`lerc-getBlobInfo: error code is ${g}`);c=new Uint8Array(h.buffer),s(c,f,a),s(c,p,o);const d=new Uint32Array(a.buffer),b=new Float64Array(o.buffer),[w,A,,m,U,x,C,V,T,D,z]=d,F={version:w,depthCount:D,width:m,height:U,validPixelCount:C,bandCount:x,blobSize:V,maskCount:T,dataType:A,minValue:b[0],maxValue:b[1],maxZerror:b[2],statistics:[],bandCountWithNoData:z};if(z&&D>1)return r(u),F;if(1===D&&1===x)return r(u),F.statistics.push({minValue:b[0],maxValue:b[1]}),F;const I=D*x*8,_=new Uint8Array(I),k=new Uint8Array(I);let B=u,S=0,v=0,E=!1;if(c.byteLength<u+2*I?(r(u),E=!0,[B,S,v]=y([e.length,I,I]),c.set(e,B)):[S,v]=y([I,I]),c.set(_,S),c.set(k,v),g=i(B,e.length,D,x,S,v),g)throw r(B),E||r(S),new Error(`lerc-getDataRanges: error code is ${g}`);c=new Uint8Array(h.buffer),s(c,S,_),s(c,v,k);const O=new Float64Array(_.buffer),$=new Float64Array(k.buffer),j=F.statistics;for(let r=0;r<x;r++)if(D>1){const e=O.slice(r*D,(r+1)*D),t=$.slice(r*D,(r+1)*D),n=Math.min.apply(null,e),a=Math.max.apply(null,t);j.push({minValue:n,maxValue:a,depthStats:{minValues:e,maxValues:t}})}else j.push({minValue:O[r],maxValue:$[r]});return r(B),E||r(S),F},a.decode=(e,n)=>{const{maskCount:a,depthCount:o,bandCount:l,width:i,height:f,dataType:p,bandCountWithNoData:g}=n,d=t[p],b=i*f,w=new Uint8Array(b*l),A=b*o*l*d.size,m=new Uint8Array(A),U=new Uint8Array(l),x=new Uint8Array(8*l),[C,V,T,D,z]=y([e.length,w.length,m.length,U.length,x.length]);c.set(e,C),c.set(w,V),c.set(m,T),c.set(U,D),c.set(x,z);const F=u(C,e.length,a,V,o,i,f,l,p,T,D,z);if(F)throw r(C),new Error(`lerc-decode: error code is ${F}`);c=new Uint8Array(h.buffer),s(c,T,m),s(c,V,w);let I=null;if(g){s(c,D,U),s(c,z,x),I=[];const e=new Float64Array(x.buffer);for(let t=0;t<U.length;t++)I.push(U[t]?e[t]:null)}return r(C),{data:m,maskData:w,noDataValues:I}}}function i(e,t,n,r,a){if(n<2)return e;const o=new r(t*n);for(let s=0,l=0;s<t;s++)for(let r=0,a=s;r<n;r++,a+=t)o[a]=e[l++];return o}function u(e,n={}){const r=n.inputOffset??0,o=e instanceof Uint8Array?e.subarray(r):new Uint8Array(e,r),s=a.getBlobInfo(o),{data:l,maskData:u,noDataValues:f}=a.decode(o,s),{width:c,height:h,bandCount:y,depthCount:p,dataType:g,maskCount:d,statistics:b}=s,w=t[g],A=new w.ctor(l.buffer),m=[],U=[],x=c*h,C=x*p;for(let t=0;t<y;t++){const e=A.subarray(t*C,(t+1)*C);if(n.returnInterleaved)m.push(e);else{const t=i(e,x,p,w.ctor);m.push(t)}U.push(u.subarray(t*C,(t+1)*C))}const V=0===d?null:1===d?U[0]:new Uint8Array(x);if(d>1){V.set(U[0]);for(let e=1;e<U.length;e++){const t=U[e];for(let e=0;e<x;e++)V[e]=V[e]&t[e]}}const{noDataValue:T}=n,D=null!=T&&w.range[0]<=T&&w.range[1]>=T;if(d>0&&D)for(let t=0;t<y;t++){const e=m[t],n=U[t]||V;for(let t=0;t<x;t++)0===n[t]&&(e[t]=T)}const z=d===y&&y>1?U:null,{pixelType:F}=w;return{width:c,height:h,bandCount:y,pixelType:F,depthCount:p,statistics:b,pixels:m,mask:V,bandMasks:z,noDataValues:f}}function f(e,t={}){const n=e instanceof Uint8Array?e.subarray(t.inputOffset??0):new Uint8Array(e,t.inputOffset??0);return a.getBlobInfo(n)}export{u as decode,f as getBlobInfo,r as load,t as pixelTypeInfoMap};