import{_ as E,$ as j,co as ot,a0 as at,cp as ht,g as ct,a as P,t as N,aY as ft,s as W,k as Y}from"./index.6c049565.js";class J{constructor(e=null,i=null,l=null){this.minValue=e,this.maxValue=i,this.noDataValue=l}}var L;let G=L=class extends ht{constructor(t){super(t),this.width=null,this.height=null,this.pixelType="f32",this.validPixelCount=null,this.mask=null,this.maskIsAlpha=!1,this.statistics=null}static createEmptyBand(t,e){return new(L.getPixelArrayConstructor(t))(e)}static getPixelArrayConstructor(t){let e;switch(t){case"u1":case"u2":case"u4":case"u8":e=Uint8Array;break;case"u16":e=Uint16Array;break;case"u32":e=Uint32Array;break;case"s8":e=Int8Array;break;case"s16":e=Int16Array;break;case"s32":e=Int32Array;break;case"f32":case"c64":case"c128":case"unknown":e=Float32Array;break;case"f64":e=Float64Array}return e}castPixelType(t){if(!t)return"f32";let e=t.toLowerCase();return["u1","u2","u4"].includes(e)?e="u8":["unknown","u8","s8","u16","s16","u32","s32","f32","f64"].includes(e)||(e="f32"),e}getPlaneCount(){var t;return(t=this.pixels)==null?void 0:t.length}addData(t){var e;if(!t.pixels||t.pixels.length!==this.width*this.height)throw new ct("pixelblock:invalid-or-missing-pixels","add data requires valid pixels array that has same length defined by pixel block width * height");this.pixels||(this.pixels=[]),this.statistics||(this.statistics=[]),this.pixels.push(t.pixels),this.statistics.push((e=t.statistics)!=null?e:new J)}getAsRGBA(){const t=new ArrayBuffer(this.width*this.height*4);switch(this.pixelType){case"s8":case"s16":case"u16":case"s32":case"u32":case"f32":case"f64":this._fillFromNon8Bit(t);break;default:this._fillFrom8Bit(t)}return new Uint8ClampedArray(t)}getAsRGBAFloat(){const t=new Float32Array(this.width*this.height*4);return this._fillFrom32Bit(t),t}updateStatistics(){if(!this.pixels)return;this.statistics=this.pixels.map(i=>this._calculateBandStatistics(i,this.mask));const t=this.mask;let e=0;if(P(t))for(let i=0;il?l:hs>=e.length),n=l===t.length&&!t.some((s,o)=>s!==o);return a||n?this:new L({pixelType:this.pixelType,width:this.width,height:this.height,mask:this.mask,validPixelCount:this.validPixelCount,maskIsAlpha:this.maskIsAlpha,pixels:t.map(s=>e[s]),statistics:i&&t.map(s=>i[s])})}clone(){const t=new L({width:this.width,height:this.height,pixelType:this.pixelType,maskIsAlpha:this.maskIsAlpha,validPixelCount:this.validPixelCount});let e;P(this.mask)&&(this.mask instanceof Uint8Array?t.mask=new Uint8Array(this.mask):t.mask=this.mask.slice(0));const i=L.getPixelArrayConstructor(this.pixelType);if(this.pixels&&this.pixels.length>0){t.pixels=[];const l=!!this.pixels[0].slice;for(e=0;e=3?(n=l[1],s=l[2]):l.length===2&&(n=l[1]);const h=new Uint32Array(t),f=this.width*this.height;if(a.length===f)if(P(e)&&e.length===f)if(i)for(o=0;o0){for(const p of l)if(p.minValue!=null&&(s=Math.min(s,p.minValue)),p.maxValue!=null&&p.minValue!=null){const d=p.maxValue-p.minValue;o=Math.max(o,d)}n=255/o}else{let p=255;a==="s8"?(s=-128,p=127):a==="u16"?p=65535:a==="s16"?(s=-32768,p=32767):a==="u32"?p=4294967295:a==="s32"?(s=-2147483648,p=2147483647):a==="f32"?(s=-34e38,p=34e38):a==="f64"&&(s=-Number.MAX_VALUE,p=Number.MAX_VALUE),n=255/(p-s)}const h=new Uint32Array(t),f=this.width*this.height;let r,u,g,c,x;if(r=u=g=e[0],r.length!==f)return W.getLogger(this.declaredClass).error("getAsRGBA()","Unable to convert to RGBA. The pixelblock is invalid.");if(e.length>=2)if(u=e[1],e.length>=3&&(g=e[2]),P(i)&&i.length===f)for(c=0;c=3?(a=e[1],n=e[2]):e.length===2&&(a=e[1]);const o=this.width*this.height;if(l.length!==o)return W.getLogger(this.declaredClass).error("getAsRGBAFloat()","Unable to convert to RGBA. The pixelblock is invalid.");let h=0;if(P(i)&&i.length===o)for(s=0;sl?s:l);else for(n=0;nl?s:l;return new J(i,l)}};E([j({json:{write:!0}})],G.prototype,"width",void 0),E([j({json:{write:!0}})],G.prototype,"height",void 0),E([j({json:{write:!0}})],G.prototype,"pixelType",void 0),E([ot("pixelType")],G.prototype,"castPixelType",null),E([j({json:{write:!0}})],G.prototype,"validPixelCount",void 0),E([j({json:{write:!0}})],G.prototype,"mask",void 0),E([j({json:{write:!0}})],G.prototype,"maskIsAlpha",void 0),E([j({json:{write:!0}})],G.prototype,"pixels",void 0),E([j({json:{write:!0}})],G.prototype,"statistics",void 0),G=L=E([at("esri.layers.support.PixelBlock")],G);const S=G;var K,Q;function _(t){return P(t)&&t.declaredClass==="esri.layers.support.PixelBlock"&&t.pixels&&t.pixels.length>0}function wt(t,e){if(!(e!=null&&e.length)||!_(t))return t;const i=t.pixels.length;return e&&e.some(l=>l>=i)||i===1&&e.length===1&&e[0]===0?t:i!==e.length||e.some((l,a)=>l!==a)?new S({pixelType:t.pixelType,width:t.width,height:t.height,mask:t.mask,validPixelCount:t.validPixelCount,maskIsAlpha:t.maskIsAlpha,pixels:e.map(l=>t.pixels[l]),statistics:t.statistics&&e.map(l=>t.statistics[l])}):t}function kt(t){if(!(t!=null&&t.length)||t.some(r=>!_(r)))return null;if(t.length===1)return P(t[0])?t[0].clone():null;const e=t,{width:i,height:l,pixelType:a}=e[0];if(e.some(r=>r.width!==i||r.height!==l))return null;const n=e.map(({mask:r})=>r).filter(r=>r!=null);let s=null;n.length&&(s=new Uint8Array(i*l),s.set(n[0]),n.length>1&&st(n.slice(1),s));const o=[];e.forEach(({pixels:r})=>o.push(...r));const h=e.map(({statistics:r})=>r).filter(r=>r==null?void 0:r.length),f=[];return h.forEach(r=>f.push(...r)),new S({pixelType:a,width:i,height:l,mask:s,pixels:o,statistics:f.length?f:null})}function At(t){if(!t)return;const e=t.colormap;if(!e||e.length===0)return;const i=e.sort((u,g)=>u[0]-g[0]);let l=0;i[0][0]<0&&(l=i[0][0]);const a=Math.max(256,i[i.length-1][0]-l+1),n=new Uint8Array(4*a),s=[];let o,h=0,f=0;const r=i[0].length===5;if(a>65536)return i.forEach(u=>{s[u[0]-l]=r?u.slice(1):u.slice(1).concat([255])}),{indexed2DColormap:s,offset:l,alphaSpecified:r};if(t.fillUnspecified)for(o=i[f],h=o[0]-l;hy?a[r]=0:(g[r]=s[d],c[r]=s[d+1],x[r]=s[d+2],a[r]=s[d+3]));else{for(a=new Uint8Array(n),r=0;ry?a[r]=0:(g[r]=s[d],c[r]=s[d+1],x[r]=s[d+2],a[r]=s[d+3]);i.mask=a}}else if(o)if(P(a))for(r=0;rn));const o=[],h=e.outputPixelType||"u8";for(let r=0;r1;){if(f===r.value){p=!0;break}f>r.value?u=x:g=x,x=Math.floor((u+g)/2),r=e[Math.floor(x)]}p||(f===e[u].value?(r=e[u],p=!0):f===e[g].value?(r=e[g],p=!0):fe[u].value&&(f=0;m--)if(y>=a[2*m]&&y<=a[2*m+1]){r[d]=n[m];break}}}let c=u;if(o!=null&&o.length){c=new Uint8Array(i*l),u&&c.set(u);for(let x=0;x=o[m]&&y<=o[m+1]){r[d]=0,c[d]=0;break}}}}return new S({width:i,height:l,pixelType:s,pixels:[r],mask:c})}function Z(t,e,i,l){const a=i!=null&&i.length>=2?new Set(i):null,n=(i==null?void 0:i.length)===1?i[0]:null,s=!!(e!=null&&e.length);for(let o=0;o=e[r]&&h<=e[r+1]){f=!0;break}f||(l[o]=0)}l[o]&&(h===n||(a==null?void 0:a.has(h)))&&(l[o]=0)}}function tt(t,e){const i=t[0].length;for(let l=0;lx.pixelBlock);if(!i||N(i.pixelBlock))return null;const l=(i.extent.xmax-i.extent.xmin)/i.pixelBlock.width,a=(i.extent.ymax-i.extent.ymin)/i.pixelBlock.height,n=.01*Math.min(l,a),s=t.sort((x,p)=>Math.abs(x.extent.ymax-p.extent.ymax)>n?p.extent.ymax-x.extent.ymax:Math.abs(x.extent.xmin-p.extent.xmin)>n?x.extent.xmin-p.extent.xmin:0),o=Math.min.apply(null,s.map(x=>x.extent.xmin)),h=Math.min.apply(null,s.map(x=>x.extent.ymin)),f=Math.max.apply(null,s.map(x=>x.extent.xmax)),r=Math.max.apply(null,s.map(x=>x.extent.ymax)),u={x:Math.round((e.xmin-o)/l),y:Math.round((r-e.ymax)/a)},g={width:Math.round((f-o)/l),height:Math.round((r-h)/a)},c={width:Math.round((e.xmax-e.xmin)/l),height:Math.round((e.ymax-e.ymin)/a)};return Math.round(g.width/i.pixelBlock.width)*Math.round(g.height/i.pixelBlock.height)!==s.length||u.x<0||u.y<0||g.widthx.pixelBlock),g,{clipOffset:u,clipSize:c})}}function q(t,e,i,l,a,n){var p;const{width:s,height:o}=i.block,{x:h,y:f}=i.offset,{width:r,height:u}=i.mosaic,g=ut(s,o,l,a,h,f,r,u);let c=0,x=0;if(n){const d=n.hasGCSSShiftTransform?360:(p=n.halfWorldWidth)!=null?p:0,y=s*n.resolutionX,m=n.startX+l*y,k=m+y;md?x=n.rightPadding:m>=d&&(c=n.leftMargin-n.rightPadding,x=0)}if(g.xmax-=x,typeof e!="number")for(let d=g.ymin;d_(M));if(N(o))return null;const h=a?a.width:e.width,f=a?a.height:e.height,r=o.width,u=o.height,g=e.width/r,c=e.height/u,x={offset:l||{x:0,y:0},mosaic:a||e,block:{width:r,height:u}},p=o.pixelType,d=S.getPixelArrayConstructor(p),y=o.pixels.length,m=[];let k,w;for(let M=0;MN(M)||P(M.mask)&&M.mask.length>0)){U=new Uint8Array(h*f);for(let M=0;MP(c));if(N(l))return null;const a=t.some(c=>!P(c)||!!c.mask),{width:n,height:s}=e,o=a?new Uint8Array(n*s):null,{blockWidths:h}=i,f=[],r=l.getPlaneCount(),u=S.getPixelArrayConstructor(l.pixelType);if(a)for(let c=0,x=0;cl||h>a||n===0&&s===0&&o===l&&h===a)return t;t.mask||(t.mask=new Uint8Array(l*a));const f=t.mask;for(let r=0;r=h||g=o?0:1}return t.updateStatistics(),t}function gt(t){if(!_(t))return null;const e=t.clone(),{width:i,height:l,pixels:a}=t,n=a[0],s=e.pixels[0],o=Y(t.mask);for(let h=2;he&&(i=n.value,e=l),n=a.next();return i}function z(t,e,i){if(i===0)return;const l=t.get(e);l===1?t.delete(e):t.set(e,l-1)}function D(t,e,i){i!==0&&t.set(e,t.has(e)?t.get(e)+1:1)}function dt(t,e,i){let{x:l,y:a}=e;const{width:n,height:s}=i;if(l===0&&a===0&&s===t.height&&n===t.width)return t;const{width:o,height:h}=t,f=Math.max(0,a),r=Math.max(0,l),u=Math.min(l+n,o),g=Math.min(a+s,h);if(u<0||g<0||!_(t))return null;l=Math.max(0,-l),a=Math.max(0,-a);const{pixels:c}=t,x=n*s,p=c.length,d=[];for(let w=0;w{const F=A instanceof Float32Array||A instanceof Float64Array?0:.5;for(let I=0;I