@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 17.5 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import t from"../PixelBlock.js";import{getPixelValueRange as e}from"../rasterFormats/pixelRangeUtils.js";var n,l;!function(t){t[t.matchAny=0]="matchAny",t[t.matchAll=1]="matchAll"}(n||(n={})),function(t){t[t.bestMatch=0]="bestMatch",t[t.fail=1]="fail"}(l||(l={}));const i=6;function o(t){return null!=t&&"esri.layers.support.PixelBlock"===t.declaredClass&&t.pixels&&t.pixels.length>0}function s(t,e){return e?.length&&o(t)?t.extractBands(e):t}function r(e){if(!e?.length||e.some((t=>!o(t))))return null;if(1===e.length)return e[0]?.clone()??null;const n=e,{width:l,height:i,pixelType:s}=n[0];if(n.some((t=>t.width!==l||t.height!==i)))return null;const r=n.map((({mask:t})=>t)).filter((t=>null!=t));let a=null;r.length&&(a=new Uint8Array(l*i),a.set(r[0]),r.length>1&&m(r.slice(1),a));const h=[];n.forEach((({pixels:t})=>h.push(...t)));const f=n.map((({statistics:t})=>t)).filter((t=>t?.length)),c=[];return f.forEach((t=>c.push(...t))),new t({pixelType:s,width:l,height:i,mask:a,pixels:h,statistics:c.length?c:null})}function a(t){if(!t)return;const e=t.colormap;if(!e||0===e.length)return;const n=e.sort(((t,e)=>t[0]-e[0]));let l=0;n[0][0]<0&&(l=n[0][0]);const i=Math.max(256,n[n.length-1][0]-l+1),o=new Uint8Array(4*i),s=[];let r,a=0,h=0;const f=5===n[0].length;if(i>65536)return n.forEach((t=>{s[t[0]-l]=f?t.slice(1):t.slice(1).concat([255])})),{indexed2DColormap:s,offset:l,alphaSpecified:f};if(t.fillUnspecified)for(r=n[h],a=r[0]-l;a<i;a++)o[4*a]=r[1],o[4*a+1]=r[2],o[4*a+2]=r[3],o[4*a+3]=f?r[4]:255,a===r[0]-l&&(r=h===n.length-1?r:n[++h]);else for(a=0;a<n.length;a++)r=n[a],h=4*(r[0]-l),o[h]=r[1],o[h+1]=r[2],o[h+2]=r[3],o[h+3]=f?r[4]:255;return{indexedColormap:o,offset:l,alphaSpecified:f}}function h(t,e){if(!o(t))return t;if(!e||!e.indexedColormap&&!e.indexed2DColormap)return t;const n=t.clone(),l=n.pixels;let i=n.mask;const s=n.width*n.height;if(1!==l.length)return t;const{indexedColormap:r,indexed2DColormap:a,offset:h,alphaSpecified:f}=e;let c=0;const u=l[0],p=new Uint8Array(u.length),x=new Uint8Array(u.length),d=new Uint8Array(u.length);let m,g=0;if(r){const t=r.length-1;if(null!=i)for(c=0;c<s;c++)i[c]&&(g=4*(u[c]-h),g<h||g>t?i[c]=0:(p[c]=r[g],x[c]=r[g+1],d[c]=r[g+2],i[c]=r[g+3]));else{for(i=new Uint8Array(s),c=0;c<s;c++)g=4*(u[c]-h),g<h||g>t?i[c]=0:(p[c]=r[g],x[c]=r[g+1],d[c]=r[g+2],i[c]=r[g+3]);n.mask=i}}else if(a)if(null!=i)for(c=0;c<s;c++)i[c]&&(m=a[u[c]],p[c]=m[0],x[c]=m[1],d[c]=m[2],i[c]=m[3]);else{for(i=new Uint8Array(s),c=0;c<s;c++)m=a[u[c]],p[c]=m[0],x[c]=m[1],d[c]=m[2],i[c]=m[3];n.mask=i}return n.pixels=[p,x,d],n.statistics=null,n.pixelType="u8",n.maskIsAlpha=f,n}function f(e,n){if(!o(e))return null;const{pixels:l,mask:i}=e,s=l.length;let r=n.lut;const{offset:a}=n;r&&1===r[0].length&&(r=l.map((()=>r)));const h=[],f=n.outputPixelType||"u8";for(let t=0;t<s;t++){const e=c(l[t],i,r[t],a||0,f);h.push(e)}const u=new t({width:e.width,height:e.height,pixels:h,mask:i,pixelType:f});return u.updateStatistics(),u}function c(e,n,l,i,o){const s=e.length,r=t.createEmptyBand(o,s);if(n)for(let t=0;t<s;t++)n[t]&&(r[t]=l[e[t]-i]);else for(let t=0;t<s;t++)r[t]=l[e[t]-i];return r}function u(t,e){if(!o(t))return null;const n=t.clone(),{pixels:l}=n,i=n.width*n.height,s=e.length,r=Math.floor(s/2),a=e[Math.floor(r)],h=l[0];let f,c,u,p,x,d,m=!1;const g=new Uint8Array(i),y=new Uint8Array(i),w=new Uint8Array(i);let k=n.mask;const M=4===e[0].mappedColor.length;for(k||(k=new Uint8Array(i),k.fill(M?255:1),n.mask=k),x=0;x<i;x++)if(k[x]){for(f=h[x],m=!1,d=r,c=a,u=0,p=s-1;p-u>1;){if(f===c.value){m=!0;break}f>c.value?u=d:p=d,d=Math.floor((u+p)/2),c=e[Math.floor(d)]}m||(f===e[u].value?(c=e[u],m=!0):f===e[p].value?(c=e[p],m=!0):f<e[u].value?(m=!1,c=null):f>e[u].value&&(f<e[p].value?(c=e[u],m=!0):p===s-1?(m=!1,c=null):(c=e[p],m=!0))),m?(g[x]=c.mappedColor[0],y[x]=c.mappedColor[1],w[x]=c.mappedColor[2],k[x]=c.mappedColor[3]):g[x]=y[x]=w[x]=k[x]=0}return n.pixels=[g,y,w],n.mask=k,n.pixelType="u8",n.maskIsAlpha=M,n}function p(n,l){if(!o(n))return null;const{width:i,height:s}=n,{inputRanges:r,outputValues:a,outputPixelType:h,noDataRanges:f,allowUnmatched:c,isLastInputRangeInclusive:u}=l,p=n.pixels[0],x=t.createEmptyBand(h,p.length),d=n.mask,m=new Uint8Array(i*s);d?m.set(d):m.fill(255);const g=n.pixelType.startsWith("f")?1e-6:0,y=r.map((t=>t-g));y[0]=r[0],y[y.length-1]=r[r.length-1]+(u?1e-6:0);const w=r.length/2,[k,M]=e(h);for(let t=0;t<s;t++)for(let e=0;e<i;e++){const n=t*i+e;if(m[n]){const t=p[n];let e=!1;for(let l=w-1;l>=0;l--)if(t===y[2*l]||t>y[2*l]&&t<y[2*l+1]){x[n]=a[l],e=!0;break}e||(c?x[n]=t>M?M:t<k?k:t:m[n]=0)}}const A=f?.length;if(A)for(let t=0;t<s;t++)for(let e=0;e<i;e++){const n=t*i+e;if(!d||d[n]){const t=p[n];for(let e=0;e<A;e+=2)if(t>=f[e]&&t<=f[e+1]){x[n]=0,m[n]=0;break}}}return new t({width:i,height:s,pixelType:h,pixels:[x],mask:m})}function x(t,e,n,l){const i=null!=n&&n.length>=2?new Set(n):null,o=1===n?.length?n[0]:null,s=!!e?.length;for(let r=0;r<t.length;r++)if(l[r]){const n=t[r];if(s){let t=!1;for(let l=0;l<e.length;l+=2)if(n>=e[l]&&n<=e[l+1]){t=!0;break}t||(l[r]=0)}l[r]&&(n===o||i?.has(n))&&(l[r]=0)}}function d(t,e){const n=t[0].length;for(let l=0;l<n;l++)if(e[l]){let n=!1;for(let e=0;e<t.length;e++)if(t[e][l]){n=!0;break}n||(e[l]=0)}}function m(t,e){const n=t[0].length;for(let l=0;l<n;l++)if(e[l]){let n=!1;for(let e=0;e<t.length;e++)if(0===t[e][l]){n=!0;break}n&&(e[l]=0)}}function g(e,n){if(!o(e))return null;const{width:l,height:i,pixels:s}=e,r=l*i,a=new Uint8Array(r);e.mask?a.set(e.mask):a.fill(255);const h=s.length,{includedRanges:f,noDataValues:u,outputPixelType:p,matchAll:g,lookups:y}=n;if(y){const t=[];for(let e=0;e<h;e++){const n=y[e],l=c(s[e],a,n.lut,n.offset||0,"u8");t.push(l)}1===t.length?a.set(t[0]):g?d(t,a):m(t,a)}else if(g){const t=[];for(let e=0;e<h;e++){const n=new Uint8Array(r);n.set(a),x(s[e],f?.slice(2*e,2*e+2),u?.[e],n),t.push(n)}1===t.length?a.set(t[0]):d(t,a)}else for(let t=0;t<h;t++)x(s[t],f?.slice(2*t,2*t+2),u?.[t],a);return new t({width:l,height:i,pixelType:p,pixels:s,mask:a})}function y(n){const{srcPixelType:l,inputRanges:i,outputValues:o,allowUnmatched:s,noDataRanges:r,isLastInputRangeInclusive:a,outputPixelType:h}=n;if("u8"!==l&&"s8"!==l&&"u16"!==l&&"s16"!==l)return null;const f=l.includes("16")?65536:256,c=l.includes("s")?-f/2:0,u=t.createEmptyBand(h,f),p=new Uint8Array(f);s&&p.fill(255);const[x,d]=e(h);if(i?.length&&o?.length){const t=1e-6,e=i.map((e=>e-t));e[0]=i[0],a&&(e[e.length-1]=i[i.length-1]);for(let n=0;n<e.length;n++){const t=o[n]>d?d:o[n]<x?x:o[n],l=Math.ceil(e[2*n]-c),i=Math.floor(e[2*n+1]-c);for(let e=l;e<=i;e++)u[e]=t,p[e]=255}}if(r?.length)for(let t=0;t<r.length;t++){const e=Math.ceil(r[2*t]-c),n=Math.floor(r[2*t+1]-c);for(let t=e;t<=n;t++)p[t]=0}return{lut:u,offset:c,mask:p}}function w(t,e,n){if("u8"!==t&&"s8"!==t&&"u16"!==t&&"s16"!==t)return null;const l=t.includes("16")?65536:256,i=t.includes("s")?-l/2:0,o=new Uint8Array(l);if(e)for(let s=0;s<e.length;s++){const t=Math.ceil(e[2*s]-i),n=Math.floor(e[2*s+1]-i);for(let e=t;e<=n;e++)o[e]=255}else o.fill(255);if(n)for(let s=0;s<n.length;s++)o[n[s]-i]=0;return{lut:o,offset:i}}function k(t,e,n,l,i,o,s,r){return{xmin:i<=n*t?0:i<n*t+t?i-n*t:t,ymin:o<=l*e?0:o<l*e+e?o-l*e:e,xmax:i+s<=n*t?0:i+s<n*t+t?i+s-n*t:t,ymax:o+r<=l*e?0:o+r<l*e+e?o+r-l*e:e}}function M(t,e){if(!t||0===t.length)return null;const n=t.find((t=>t.pixelBlock));if(null==n?.pixelBlock)return null;const l=(n.extent.xmax-n.extent.xmin)/n.pixelBlock.width,i=(n.extent.ymax-n.extent.ymin)/n.pixelBlock.height,o=.01*Math.min(l,i),s=t.sort(((t,e)=>Math.abs(t.extent.ymax-e.extent.ymax)>o?e.extent.ymax-t.extent.ymax:Math.abs(t.extent.xmin-e.extent.xmin)>o?t.extent.xmin-e.extent.xmin:0)),r=Math.min.apply(null,s.map((t=>t.extent.xmin))),a=Math.min.apply(null,s.map((t=>t.extent.ymin))),h=Math.max.apply(null,s.map((t=>t.extent.xmax))),f=Math.max.apply(null,s.map((t=>t.extent.ymax))),c={x:Math.round((e.xmin-r)/l),y:Math.round((f-e.ymax)/i)},u={width:Math.round((h-r)/l),height:Math.round((f-a)/i)},p={width:Math.round((e.xmax-e.xmin)/l),height:Math.round((e.ymax-e.ymin)/i)};if(Math.round(u.width/n.pixelBlock.width)*Math.round(u.height/n.pixelBlock.height)!==s.length||c.x<0||c.y<0||u.width<p.width||u.height<p.height)return null;return{extent:e,pixelBlock:U(s.map((t=>t.pixelBlock)),u,{clipOffset:c,clipSize:p})}}function A(t,e,n,l,i,o){const{width:s,height:r}=n.block,{x:a,y:h}=n.offset,{width:f,height:c}=n.mosaic,u=k(s,r,l,i,a,h,f,c);let p=0,x=0;if(o){const t=o.hasGCSSShiftTransform?360:o.halfWorldWidth??0,e=s*o.resolutionX,n=o.startX+l*e;n<t&&n+e>t?x=o.rightPadding:n>=t&&(p=o.leftMargin-o.rightPadding,x=0)}if(u.xmax-=x,"number"!=typeof e)for(let d=u.ymin;d<u.ymax;d++){const n=(i*r+d-h)*f+(l*s-a)+p,o=d*s;for(let l=u.xmin;l<u.xmax;l++)t[n+l]=e[o+l]}else for(let d=u.ymin;d<u.ymax;d++){const n=(i*r+d-h)*f+(l*s-a)+p;for(let l=u.xmin;l<u.xmax;l++)t[n+l]=e}}function U(e,n,l={}){const{clipOffset:i,clipSize:s,alignmentInfo:r,blockWidths:a}=l;if(a)return b(e,n,{blockWidths:a});const h=e.find((t=>o(t)));if(null==h)return null;const f=s?s.width:n.width,c=s?s.height:n.height,u=h.width,p=h.height,x=n.width/u,d=n.height/p,m={offset:i||{x:0,y:0},mosaic:s||n,block:{width:u,height:p}},g=h.pixelType,y=t.getPixelArrayConstructor(g),w=h.pixels.length,k=[];let M,U;for(let t=0;t<w;t++){U=new y(f*c);for(let n=0;n<d;n++)for(let l=0;l<x;l++){const i=e[n*x+l];o(i)&&(M=i.pixels[t],A(U,M,m,l,n,r))}k.push(U)}const T=e.some((t=>null==t||null!=t.mask&&t.mask.length>0)),v=e.some((t=>t?.bandMasks&&t.bandMasks.length>1)),B=T?new Uint8Array(f*c):void 0,C=v?[]:void 0;if(B){for(let t=0;t<d;t++)for(let n=0;n<x;n++){const l=e[t*x+n],i=null!=l?l.mask:null;A(B,null!=i?i:l?255:0,m,n,t,r)}if(C)for(let t=0;t<w;t++){const n=new Uint8Array(f*c);for(let l=0;l<d;l++)for(let i=0;i<x;i++){const o=e[l*x+i],s=o?.bandMasks?.[t]??o?.mask;A(n,null!=s?s:o?255:0,m,i,l,r)}C.push(n)}}const S=new t({width:f,height:c,pixels:k,pixelType:g,bandMasks:C,mask:B});return S.updateStatistics(),S}function b(e,n,l){const i=e.find((t=>null!=t));if(null==i)return null;const s=e.some((t=>null==t||!!t.mask)),{width:r,height:a}=n,h=s?new Uint8Array(r*a):null,{blockWidths:f}=l,c=[],u=i.getPlaneCount(),p=t.getPixelArrayConstructor(i.pixelType);if(s)for(let t=0,y=0;t<e.length;y+=f[t],t++){const n=e[t];if(!o(n))continue;const l=n.mask;for(let e=0;e<a;e++)for(let i=0;i<f[t];i++)h[e*r+i+y]=null==l?255:l[e*n.width+i]}const x=e.some((t=>t?.bandMasks&&t.bandMasks.length>1)),d=x?[]:void 0,m=r*a;for(let t=0;t<u;t++){const n=new p(m),l=x?new Uint8Array(m):void 0;for(let i=0,s=0;i<e.length;s+=f[i],i++){const h=e[i];if(!o(h))continue;const c=h.pixels[t];if(null!=c){for(let t=0;t<a;t++)for(let e=0;e<f[i];e++)n[t*r+e+s]=c[t*h.width+e];if(l){const e=h.bandMasks?.[t]??h.mask;for(let t=0;t<a;t++)for(let n=0;n<f[i];n++)l[t*r+n+s]=e?e[t*h.width+n]:255}}}c.push(n),d&&l&&d.push(l)}const g=new t({width:r,height:a,mask:h,bandMasks:d,pixels:c,pixelType:i.pixelType});return g.updateStatistics(),g}function T(t,e,n){if(!o(t))return null;const{width:l,height:i}=t,s=e.x,r=e.y,a=n.width+s,h=n.height+r;if(s<0||r<0||a>l||h>i)return t;if(0===s&&0===r&&a===l&&h===i)return t;t.mask||(t.mask=new Uint8Array(l*i));const f=t.mask;for(let o=0;o<i;o++){const t=o*l;for(let e=0;e<l;e++)f[t+e]=o<r||o>=h||e<s||e>=a?0:1}return t.updateStatistics(),t}function v(t){if(!o(t))return null;const e=t.clone(),{width:n,height:l,pixels:i}=t,s=i[0],r=e.pixels[0],a=t.mask;for(let o=2;o<l-1;o++){const t=new Map;for(let l=o-2;l<o+2;l++)for(let e=0;e<4;e++){const i=l*n+e;S(t,s[i],a?a[i]:1)}r[o*n]=B(t),r[o*n+1]=r[o*n+2]=r[o*n];let e=3;for(;e<n-1;e++){let l=(o-2)*n+e+1;S(t,s[l],a?a[l]:1),l=(o-1)*n+e+1,S(t,s[l],a?a[l]:1),l=o*n+e+1,S(t,s[l],a?a[l]:1),l=(o+1)*n+e+1,S(t,s[l],a?a[l]:1),l=(o-2)*n+e-3,C(t,s[l],a?a[l]:1),l=(o-1)*n+e-3,C(t,s[l],a?a[l]:1),l=o*n+e-3,C(t,s[l],a?a[l]:1),l=(o+1)*n+e-3,C(t,s[l],a?a[l]:1),r[o*n+e]=B(t)}r[o*n+e+1]=r[o*n+e]}for(let o=0;o<n;o++)r[o]=r[n+o]=r[2*n+o],r[(l-1)*n+o]=r[(l-2)*n+o];return e.updateStatistics(),e}function B(t){if(0===t.size)return 0;let e=0,n=-1,l=0;const i=t.keys();let o=i.next();for(;!o.done;)l=t.get(o.value),l>e&&(n=o.value,e=l),o=i.next();return n}function C(t,e,n){if(0===n)return;const l=t.get(e);1===l?t.delete(e):t.set(e,l-1)}function S(t,e,n){0!==n&&t.set(e,t.has(e)?t.get(e)+1:1)}function P(e,n,l){let{x:i,y:s}=n;const{width:r,height:a}=l;if(0===i&&0===s&&a===e.height&&r===e.width)return e;const{width:h,height:f}=e,c=Math.max(0,s),u=Math.max(0,i),p=Math.min(i+r,h),x=Math.min(s+a,f);if(p<0||x<0||!o(e))return null;i=Math.max(0,-i),s=Math.max(0,-s);const{pixels:d}=e,m=r*a,g=d.length,y=[];for(let o=0;o<g;o++){const n=d[o],l=t.createEmptyBand(e.pixelType,m);for(let t=c;t<x;t++){const e=t*h;let o=(t+s-c)*r+i;for(let t=u;t<p;t++)l[o++]=n[e+t]}y.push(l)}const w=new Uint8Array(m),k=e.mask;for(let t=c;t<x;t++){const e=t*h;let n=(t+s-c)*r+i;for(let t=u;t<p;t++)w[n++]=k?k[e+t]:1}const M=new t({width:l.width,height:l.height,pixelType:e.pixelType,pixels:y,mask:w});return M.updateStatistics(),M}function _(e,n=!0){if(!o(e))return null;const{pixels:l,width:i,height:s,mask:r,pixelType:a}=e,h=[],f=Math.round(i/2),c=Math.round(s/2),u=s-1,p=i-1;for(let o=0;o<l.length;o++){const e=l[o],r=t.createEmptyBand(a,f*c);let x=0;for(let t=0;t<s;t+=2)for(let l=0;l<i;l+=2){const o=e[t*i+l];if(n){const n=l===p?o:e[t*i+l+1],s=t===u?o:e[t*i+l+i],a=l===p?s:t===u?n:e[t*i+l+i+1];r[x++]=(o+n+s+a)/4}else r[x++]=o}h.push(r)}let x=null;if(null!=r){x=new Uint8Array(f*c);let t=0;for(let e=0;e<s;e+=2)for(let l=0;l<i;l+=2){const o=r[e*i+l];if(n){const n=l===p?o:r[e*i+l+1],s=e===u?o:r[e*i+l+i],a=l===p?s:e===u?n:r[e*i+l+i+1];x[t++]=o*n*s*a?1:0}else x[t++]=o}}return new t({width:f,height:c,pixelType:a,pixels:h,mask:x})}function W(t,e,n=0,l=!0){if(!o(t))return null;const{width:i,height:s}=e;let{width:r,height:a}=t;const h=new Map,f={x:0,y:0},c=1+n;let u=t;for(let o=0;o<c;o++){const t=Math.ceil(r/i),n=Math.ceil(a/s);for(let l=0;l<n;l++){f.y=l*s;for(let n=0;n<t;n++){f.x=n*i;const t=P(u,f,e);h.set(`${o}/${l}/${n}`,t)}}o<c-1&&(u=_(u,l)),r=Math.round(r/2),a=Math.round(a/2)}return h}function E(t){const{pixelBlock:e,tileSize:n,level:l,row:i,col:s,useBilinear:r}=t;if(!o(e))return null;const{width:a,height:h}=n,f=2**l,c=f*a,u=f*h;let p=P(e,{y:i*u,x:s*c},{width:c,height:u});if(!p)return null;for(let o=l;o>0;o--)p=_(p,r);return p}function I(t,e,n,l,i=0){const{width:o,height:s}=t,{width:r,height:a}=e,h=l.cols,f=l.rows,c=Math.ceil(r/h-.1/h),u=Math.ceil(a/f-.1/f);let p,x,d,m,g,y,w;const k=c*h,M=k*u*f,A=new Float32Array(M),U=new Float32Array(M),b=new Uint32Array(M),T=new Uint32Array(M);let v,B,C=0;for(let S=0;S<u;S++)for(let t=0;t<c;t++){p=12*(S*c+t),x=n[p],d=n[p+1],m=n[p+2],g=n[p+3],y=n[p+4],w=n[p+5];for(let e=0;e<f;e++){C=(S*f+e)*k+t*h,B=(e+.5)/f;for(let t=0;t<e;t++)v=(t+.5)/h,A[C+t]=(x*v+d*B+m)*o+i,U[C+t]=(g*v+y*B+w)*s+i,b[C+t]=Math.floor(A[C+t]),T[C+t]=Math.floor(U[C+t])}p+=6,x=n[p],d=n[p+1],m=n[p+2],g=n[p+3],y=n[p+4],w=n[p+5];for(let e=0;e<f;e++){C=(S*f+e)*k+t*h,B=(e+.5)/f;for(let t=e;t<h;t++)v=(t+.5)/h,A[C+t]=(x*v+d*B+m)*o+i,U[C+t]=(g*v+y*B+w)*s+i,b[C+t]=Math.floor(A[C+t]),T[C+t]=Math.floor(U[C+t])}}return{offsets_x:A,offsets_y:U,offsets_xi:b,offsets_yi:T,gridWidth:k}}function R(t,e){const{coefficients:n,spacing:l}=e,{offsets_x:i,offsets_y:o,gridWidth:s}=I(t,t,n,{rows:l[0],cols:l[1]}),{width:r,height:a}=t,h=new Float32Array(r*a),f=180/Math.PI;for(let c=0;c<a;c++)for(let t=0;t<r;t++){const e=c*s+t,n=0===c?e:e-s,l=c===a-1?e:e+s,u=i[n]-i[l],p=o[l]-o[n];if(isNaN(u)||isNaN(p))h[c*r+t]=90;else{let e=Math.atan2(p,u)*f;e=(360+e)%360,h[c*r+t]=e}}return h}function D(e,n,l,i,s="nearest"){if(!o(e))return null;"majority"===s&&(e=v(e));const{pixels:r,mask:a,bandMasks:h,pixelType:f}=e,c=e.width,u=e.height,p=t.getPixelArrayConstructor(f),x=r.length,{width:d,height:m}=n;let g=!1;for(let t=0;t<l.length;t+=3)-1===l[t]&&-1===l[t+1]&&-1===l[t+2]&&(g=!0);const{offsets_x:y,offsets_y:w,offsets_xi:k,offsets_yi:M,gridWidth:A}=I({width:c,height:u},n,l,i,"majority"===s?.5:0);let U;const b=(t,e,n,l)=>{const i=t instanceof Float32Array||t instanceof Float64Array?0:.5;for(let o=0;o<m;o++){U=o*A;for(let s=0;s<d;s++){if(y[U]<0||w[U]<0)t[o*d+s]=0;else if(l)t[o*d+s]=e[k[U]+M[U]*c];else{const l=Math.floor(y[U]),r=Math.floor(w[U]),a=Math.ceil(y[U]),h=Math.ceil(w[U]),f=y[U]-l,u=w[U]-r;if(!n||n[l+r*c]&&n[a+r*c]&&n[l+h*c]&&n[a+h*c]){const n=(1-f)*e[l+r*c]+f*e[a+r*c],p=(1-f)*e[l+h*c]+f*e[a+h*c];t[o*d+s]=(1-u)*n+u*p+i}else t[o*d+s]=e[k[U]+M[U]*c]}U++}}},T=[];let B;const C=h?.length===x,S=[];for(let t=0;t<x;t++){if(C){const e=new Uint8Array(d*m);b(e,h[t],h[t],!0),S.push(e)}B=new p(d*m),b(B,r[t],C?h[t]:a,"nearest"===s||"majority"===s),T.push(B)}const P=new t({width:d,height:m,pixelType:f,pixels:T,bandMasks:C?S:void 0});if(null!=a)P.mask=new Uint8Array(d*m),b(P.mask,a,a,!0);else if(g){P.mask=new Uint8Array(d*m);for(let t=0;t<d*m;t++)P.mask[t]=y[t]<0||w[t]<0?0:1}return P.updateStatistics(),P}export{l as MissingBandAction,n as NoDataInterpretation,D as approximateTransform,P as clip,E as clipTile,h as colorize,r as compositeBands,a as createColormapLUT,w as createMaskLUT,y as createRemapLUT,s as extractBands,k as getClipBounds,R as getLocalArithmeticNorthRotations,I as interpolateOffsets,o as isValidPixelBlock,c as lookupBandValues,f as lookupPixels,g as mask,i as maxMapSizeGpu,U as mosaic,M as mosaicPixelData,p as remap,u as remapColor,v as resampleByMajority,T as setValidBoundary,W as split};