UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 2.66 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ const t=9999999e31,n=2e-7,e={u1:[0,1],u2:[0,3],u4:[0,15],u8:[0,255],s8:[-128,127],u16:[0,65535],s16:[-32768,32767],u32:[0,4294967295],s32:[-2147483648,2147483647],f32:[-34028234663852886e22,34028234663852886e22],f64:[-Number.MAX_VALUE,Number.MAX_VALUE],unknown:void 0,c64:void 0,c128:void 0};function u(t){return e[t]??[-34028234663852886e22,34028234663852886e22]}const s={u1:1,u2:1,u4:1,u8:1,s8:1,u16:2,s16:2,u32:4,s32:4,f32:4,f64:8,unknown:4,c64:16,c128:32};function o(t){return s[t]}function l(t){return o(t.pixelType)*t.bandCount}function i(t,n){return null==t||null==n?"s32":t<0?t>=-128&&n<128?"s8":t>=-32768&&n<32768?"s16":"s32":n<256?"u8":n<65536?"u16":"u32"}function r(t){return(t?.startsWith("s")||t?.startsWith("u"))??!1}function c(t,n,e,s){let[o,l]=u(e);const i=r(e);return i&&(o-=1e-5,l+=1e-5),i?e.startsWith("u")?a(t,n,s,[o,l]):h(t,n,s,[o,l]):b(t,n,s,[o,l])}function f(t,n){for(let e=0;e<n.length;e++)n[e]&&isNaN(t[e])&&(n[e]=0,t[e]=0)}function a(t,n,e,u){const[s,o]=u;for(let l=0;l<n.length;l++)if(n[l]){const u=t[l];u<s||u>o?n[l]=0:e[l]=u+.5|0}}function h(t,n,e,u){const[s,o]=u;for(let l=0;l<n.length;l++)if(n[l]){const u=t[l];u<s||u>o?n[l]=0:e[l]=u+(u>0?.5:-.5)|0}}function b(t,n,e,u){const[s,o]=u;for(let l=0;l<n.length;l++)if(n[l]){const u=t[l];u<s||u>o?n[l]=0:e[l]=u}}function g(e,s,o){if(e.depthCount&&e.depthCount>1)return;const{pixels:l,statistics:i,pixelType:r}=e,c=l[0].length,f=e.bandMasks??[],a=e.mask??new Uint8Array(c).fill(255),h="f32"===r||"f64"===r,b=u(r);let g=!1;for(let u=0;u<l.length;u++){const e="number"==typeof s?s:s[u];if(null==e)continue;const c=i?.[u]?.minValue??b[0],m=i?.[u]?.maxValue??b[1];if(c>e+Number.EPSILON||m<e-Number.EPSILON)continue;const p=f[u]||a.slice(),d=l[u],N=o?.customFloatTolerance;if(h&&0!==N){let u=N;u||(u=Math.abs(e)>=t?n*Math.abs(e):"f32"===r?2**-23:Number.EPSILON);for(let t=0;t<d.length;t++)p[t]&&Math.abs(d[t]-e)<u&&(d[t]=0,p[t]=0,a[t]=0,g=!0)}else for(let t=0;t<d.length;t++)p[t]&&d[t]===e&&(d[t]=0,p[t]=0,a[t]=0,g=!0);f[u]=p}if(g){const t=e.bandMasks||e.pixels.length>1?f:null;o?.matchAllNoData?e.mask=t&&t.length>1?m(t):a:(e.bandMasks=t,e.mask=a)}function m(t){if(t.length<2)return t[0];const n=t[0].length,e=new Uint8Array(n).fill(0);for(let u=0;u<t.length;u++){const s=t[u];for(let t=0;t<n;t++)s[t]&&(e[t]=255)}return e}g&&"updateStatistics"in e&&e.updateStatistics()}export{c as clipBandToPixelTypeRange,g as convertNoDataToMask,f as fixNaN,l as getBytesPerPixel,i as getIntegerPixelType,u as getPixelValueRange,r as isIntegerPixelType};