@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 1.14 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
const e=(e,r)=>{const a=r.width*r.height,n=r.pixelType;return Math.floor(e.byteLength/(a*t(n)))},t=e=>{let t=1;switch(e){case Uint8Array:case Int8Array:t=1;break;case Uint16Array:case Int16Array:t=2;break;case Uint32Array:case Int32Array:case Float32Array:t=4;break;case Float64Array:t=8}return t},r=(e,t)=>{if(8*e.byteLength<t)return null;const r=new Uint8Array(e,0,Math.ceil(t/8)),a=new Uint8Array(t);let n=0,s=0,l=0,i=0;for(l=0;l<r.length-1;l++)for(s=r[l],i=7;i>=0;i--)a[n++]=s>>i&1;for(i=7;n<t-1;)s=r[r.length-1],a[n++]=s>>i&1,i--;return a};class a{static decode(a,n){const s=n.pixelType,l=[],i=n.width*n.height,h=e(a,n),{bandIds:c,format:y}=n,o=c?.length||e(a,n),b=a.byteLength-a.byteLength%(i*t(s)),f=new s(a,0,i*h);let u,g,A,p,d=null;if("bip"===y)for(u=0;u<o;u++){for(A=new s(i),p=c?c[u]:u,g=0;g<i;g++)A[g]=f[g*h+p];l.push(A)}else if("bsq"===y)for(u=0;u<o;u++)p=c?c[u]:u,l.push(f.subarray(p*i,(p+1)*i));return b<a.byteLength-1&&(d=r(a.slice(b),i)),{pixels:l,mask:d}}}export{a as default};