/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{__decorate as t}from"tslib";import{property as s,subclass as e}from"../../../core/accessorSupport/decorators.js";import{isIntegerPixelType as o}from"../formats/pixelRangeUtils.js";import u from"./BaseRasterFunction.js";import{lookupPixels as r}from"./pixelUtils.js";import i from"./StretchFunctionArguments.js";import{getStretchCutoff as n,createStretchLUT as a,stretch as p,computeGammaCorrection as m}from"./stretchUtils.js";let c=class extends u{constructor(){super(...arguments),this.functionName="Stretch",this.functionArguments=null,this.rasterArgumentNames=["raster"],this.lookup=null,this.cutOffs=null}_bindSourceRasters(){this.lookup=null,this.cutOffs=null;const t=this.sourceRasterInfos[0],{pixelType:s}=t,{functionArguments:e}=this,{dynamicRangeAdjustment:u,gamma:r,useGamma:i}=e;if(!u&&["u8","u16","s8","s16"].includes(s)){const u=n(e.toJSON(),{rasterInfo:t}),p=o(this.outputPixelType)?"round":"float";this.lookup=a({pixelType:s,...u,gamma:i?r:null,rounding:p}),this.cutOffs=u}else u||(this.cutOffs=n(e.toJSON(),{rasterInfo:t}));this.outputPixelType=this._getOutputPixelType(s);const p=t.clone();p.pixelType=this.outputPixelType,this._removeStatsHistColormapVAT(p),"u8"===this.outputPixelType&&(p.keyProperties.DataType="processed");const{outputMin:m=0,outputMax:c=255}=this.functionArguments;p.statistics=[];for(let o=0;o<p.bandCount;o++)p.statistics[o]={min:m,max:c};this.rasterInfo=p;return{success:!0,supportsGPU:!u}}_processPixels(t,s){const e=t.pixelBlocks?.[0];if(null==e)return e;const{lookup:o}=this;if(o)return r(e,{...o,outputPixelType:this.rasterInfo.pixelType});const{functionArguments:u}=this,i=s?.stretchCutoff??this.cutOffs??n(u.toJSON(),{rasterInfo:this.sourceRasterInfos[0],pixelBlock:e}),a=u.useGamma?u.gamma:null;return p(e,{...i,gamma:a,outputPixelType:this.outputPixelType})}_getWebGLParameters(){const{outputMin:t=0,outputMax:s=255,gamma:e,useGamma:u}=this.functionArguments,r=this.rasterInfo.bandCount>=2?3:1,i=u&&e?.length?m(r,e):[1,1,1],{minCutOff:n,maxCutOff:a}=this.cutOffs??{minCutOff:[0,0,0],maxCutOff:[255,255,255]};1===n.length&&(n[1]=n[2]=n[0],a[1]=a[2]=a[0]);const p=a.map((e,o)=>(s-t)/(a[o]-n[o])),c=o(this.outputPixelType),f=u&&e?[e[0],e[1]??e[0],e[2]??e[0]]:[1,1,1],l=u?[i[0],i[1]??i[0],i[2]??i[0]]:[1,1,1];return{bandCount:r,minOutput:t,maxOutput:s,minCutOff:n,maxCutOff:a,factor:p,useGamma:u,gamma:f,gammaCorrection:l,stretchType:this.functionArguments.stretchType,isOutputRounded:c,type:"stretch"}}};t([s({json:{write:!0,name:"rasterFunction"}})],c.prototype,"functionName",void 0),t([s({type:i,json:{write:!0,name:"rasterFunctionArguments"}})],c.prototype,"functionArguments",void 0),t([s()],c.prototype,"rasterArgumentNames",void 0),t([s({json:{write:!0}})],c.prototype,"lookup",void 0),t([s({json:{write:!0}})],c.prototype,"cutOffs",void 0),c=t([e("esri.layers.raster.functions.StretchFunction")],c);const f=c;export{f as default};
