@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 1.08 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
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;for(let c=0;c<r.length-1;c++){s=r[c];for(let e=7;e>=0;e--)a[n++]=s>>e&1}let l=7;for(;n<t-1;)s=r[r.length-1],a[n++]=s>>l&1,l--;return a};class a{static decode(a,n){const s=n.pixelType,l=[],c=n.width*n.height,i=e(a,n),{bandIds:h,format:o}=n,y=h?.length||e(a,n),b=a.byteLength-a.byteLength%(c*t(s)),f=new s(a,0,c*i);if("bip"===o)for(let e=0;e<y;e++){const t=new s(c),r=h?h[e]:e;for(let e=0;e<c;e++)t[e]=f[e*i+r];l.push(t)}else if("bsq"===o)for(let e=0;e<y;e++){const t=h?h[e]:e;l.push(f.subarray(t*c,(t+1)*c))}let u=null;return b<a.byteLength-1&&(u=r(a.slice(b),c)),{pixels:l,mask:u}}}export{a as default};