/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{__decorate as t}from"tslib";import{numberMaxFloat32 as e}from"../../../core/mathUtils.js";import{property as s,subclass as n}from"../../../core/accessorSupport/decorators.js";import{getPixelValueRange as u}from"../formats/pixelRangeUtils.js";import a from"./BaseRasterFunction.js";import{createRemapLUT as o,maxMapSizeGpu as i,lookupPixels as l,lookupBandValues as r,remap as p,createRangeMaps as m}from"./pixelUtils.js";import c from"./RemapFunctionArguments.js";let f=class extends a{constructor(){super(...arguments),this.functionName="Remap",this.functionArguments=null,this.rasterArgumentNames=["raster"],this.lookup=null}_bindSourceRasters(){const t=this.sourceRasterInfos[0].clone(),{pixelType:e}=t;t.bandCount=1;const{statistics:s}=t;this._removeStatsHistColormapVAT(t);const{allowUnmatched:n,replacementValue:a,outputValues:l,inputRanges:r,noDataRanges:p,isLastInputRangeInclusive:m}=this.functionArguments,c="unknown"===this.outputPixelType||null==this.outputPixelType;if(this.outputPixelType=this._getOutputPixelType(e),l?.length){const o=s?.[0];if(n&&null==a){let e=o?.min??l[0],s=o?.max??l[0];e=Math.min.apply(null,[...l,e]),s=Math.max.apply(null,[...l,s]),t.statistics=[{min:e,max:s,avg:o?.avg??0,stddev:o?.stddev??-1}]}else{let e=l[0],s=e;for(let t=0;t<l.length;t++)e=e>l[t]?l[t]:e,s=s>l[t]?s:l[t];n&&null!=a&&(e=Math.min(e,a),s=Math.max(s,a)),t.statistics=[{min:e,max:s,avg:o?.avg??0,stddev:o?.stddev??-1}]}if(c){const{min:s,max:o}=t.statistics[0],i=["u8","s8","u16","s16","u32","s32","f32"],r=i.find(t=>{const[e,n]=u(t);return s>=e&&o<=n})??"f64";l.some(t=>Math.floor(t)!==t)?this.outputPixelType="f64"===r?"f64":"f32":this.outputPixelType=n&&null==a&&i.indexOf(e)>i.indexOf(r)?e:r}}t.pixelType=this.outputPixelType,this.rasterInfo=t,this.lookup=n?null:o({srcPixelType:e,inputRanges:r,outputValues:l,noDataRanges:p,allowUnmatched:n,isLastInputRangeInclusive:m,outputPixelType:this.outputPixelType});return{success:!0,supportsGPU:(!l||l.length<=i)&&(!p||p.length<=i)}}_processPixels(t){const e=t.pixelBlocks?.[0];if(null==e)return null;const{lookup:s,outputPixelType:n}=this;if(s){const t=l(e,{lut:[s.lut],offset:s.offset,outputPixelType:n});return null!=t&&s.mask&&(t.mask=r(e.pixels[0],e.mask,s.mask,s.offset,"u8")),t}const{inputRanges:u,outputValues:a,noDataRanges:o,allowUnmatched:i,isLastInputRangeInclusive:m,replacementValue:c}=this.functionArguments;return p(e,{inputRanges:u,outputValues:a,noDataRanges:o,outputPixelType:n,allowUnmatched:i,isLastInputRangeInclusive:m,replacementValue:c})}_getWebGLParameters(){const{allowUnmatched:t,noDataRanges:s,isLastInputRangeInclusive:n}=this.functionArguments,a=this.functionArguments.inputRanges??[],o=this.functionArguments.outputValues??[],l=m(a,o,n),r=new Float32Array(2*i);r.fill(e),s?.length&&r.set(s);return{allowUnmatched:t,rangeMaps:l,noDataRanges:r,clampRange:u(this.outputPixelType),replacementValue:this.functionArguments.replacementValue}}};t([s({json:{write:!0,name:"rasterFunction"}})],f.prototype,"functionName",void 0),t([s({type:c,json:{write:!0,name:"rasterFunctionArguments"}})],f.prototype,"functionArguments",void 0),t([s()],f.prototype,"rasterArgumentNames",void 0),t([s({json:{write:!0}})],f.prototype,"lookup",void 0),f=t([n("esri.layers.raster.functions.RemapFunction")],f);const g=f;export{g as default};
