/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{__decorate as t}from"tslib";import{property as s,subclass as e}from"../../../core/accessorSupport/decorators.js";import{getPixelValueRange as n,isIntegerPixelType as o,getIntegerPixelType as i}from"../formats/pixelRangeUtils.js";import r from"./BaseRasterFunction.js";import u from"./LocalFunctionArguments.js";import{operandsCount as a,local as c,getOutputDomain as l}from"./localUtils.js";import{localOperators as p}from"../../support/rasterFunctionConstants.js";let m=class extends r{constructor(){super(...arguments),this.functionName="Local",this.functionArguments=null,this.rasterArgumentNames=["rasters"]}_bindSourceRasters(){const{sourceRasterInfos:t}=this,s=t[0],{bandCount:e}=s,{processAsMultiband:n}=this.functionArguments;if(t.some(t=>t.bandCount!==e))return{success:!1,supportsGPU:!1,error:"local-function: input rasters do not have same band count"};const{operation:o,rasters:i}=this.functionArguments,r=a[o];if(!(999===r||i.length===r||i.length<=1&&1===r))return{success:!1,supportsGPU:!1,error:`local-function: the length of functionArguments.rasters does not match operation's requirement: ${r}`};const u=s.clone();u.bandCount=999!==r||n?e:1,this._removeStatsHistColormapVAT(u),this._updateStatistics(u),this._updatePixelType(u),this.rasterInfo=u;return{success:!0,supportsGPU:1===u.bandCount&&r<=3}}_processPixels(t){const{pixelBlocks:s}=t;return null==s||s.some(t=>null==t)?null:c(s,this.functionArguments.operation,{processAsMultiband:this.functionArguments.processAsMultiband,outputPixelType:this.outputPixelType??void 0})}_getWebGLParameters(){const{operation:t}=this.functionArguments,s=a[t],e=Object.keys(p).find(s=>p[s]===t)?.toLowerCase()??"undefined",i=this.outputPixelType??"f32";let[r,u]=n(i);const c=o(i);return c&&(r-=1e-4,u+=1e-4),{imageCount:s,operationName:e,domainRange:[r,u],isOutputRounded:c}}_updateStatistics(t){const s=this.sourceRasterInfos[0],{operation:e}=this.functionArguments,n=l(e)?.domain;if(n){t.statistics=[];for(let s=0;s<t.bandCount;s++)t.statistics[s]={min:n[0],max:n[1],avg:(n[0]+n[1])/2,stddev:(n[0]+n[1])/10}}else 45===e&&s.statistics?.length&&(t.statistics=s.statistics.map(t=>({min:-t.max,max:-t.min,avg:null!=t.avg?-t.avg:void 0,stddev:null!=t.stddev?-t.stddev:void 0})))}_updatePixelType(t){const{statistics:s,pixelType:e}=this.sourceRasterInfos[0],{operation:n}=this.functionArguments,{domain:r,isInteger:u}=l(n)??{domain:null,isInteger:!1};let a="f32";if(r&&u)a=i(r[0],r[1]);else if(30===n){const t=s?.[0];a=t?i(t.min,t.max):o(e)?e:"s32"}else if(45===n&&o(e)){const t=s?.map(({max:t})=>-t),n=s?.map(({min:t})=>-t),o=t?.length?Math.min(...t):null,r=n?.length?Math.min(...n):null;a=null!=o&&null!=r?i(o,r):e.startsWith("s")?e.replace("s","u"):"u1"===e||"u2"===e||"u4"===e?"s8":"u8"===e?"s16":"s32"}t.pixelType=this.outputPixelType=this._getOutputPixelType(a)}};t([s({json:{write:!0,name:"rasterFunction"}})],m.prototype,"functionName",void 0),t([s({type:u,json:{write:!0,name:"rasterFunctionArguments"}})],m.prototype,"functionArguments",void 0),t([s()],m.prototype,"rasterArgumentNames",void 0),m=t([e("esri.layers.raster.functions.LocalFunction")],m);const d=m;export{d as default};
