/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{__decorate as t}from"tslib";import{property as o,subclass as e}from"../../../core/accessorSupport/decorators.js";import r from"./BaseRasterFunction.js";import s from"./ColormapToRGBFunctionArguments.js";import{createColormapLUT as n}from"./pixelUtils.js";import i from"../../support/SimpleBandStatistics.js";import{isColormapSupportedByWebGL as p}from"../../../renderers/support/rasterRendererChecks.js";let a=class extends r{constructor(){super(...arguments),this.functionName="ColormapToRGB",this.functionArguments=null,this.rasterArgumentNames=["raster"]}_bindSourceRasters(){const t=this.sourceRasterInfos[0];if(t.bandCount>1||!t.colormap?.length)return{success:!1,supportsGPU:!1,error:"colormap-to-rgb-function: source data must be single band with a colormap"};const o=t.clone();o.pixelType=this.outputPixelType=this._getOutputPixelType("u8"),this._removeStatsHistColormapVAT(o),o.bandCount=3,o.statistics=[{min:0,max:255,avg:100,stddev:20},{min:0,max:255,avg:100,stddev:20},{min:0,max:255,avg:100,stddev:20}],this.rasterInfo=o;const e=[...t.colormap].sort((t,o)=>t[0]-o[0]),{indexedColormap:r,offset:s}=n({colormap:e});return r?(this.lookup={indexedColormap:r,offset:s},{success:!0,supportsGPU:p(r)}):{success:!1,supportsGPU:!1,error:"colormap-to-rgb-function: the colormap is not supported"}}_processPixels(t){let o=t.pixelBlocks?.[0];if(!o||!this.lookup)return o;o=o.clone();const e=o.pixels[0],r=o.mask??new Uint8Array(e.length).fill(255),s=new Uint8Array(e.length),n=new Uint8Array(e.length),p=new Uint8Array(e.length),{indexedColormap:a,offset:u}=this.lookup,l=a.length;for(let i=0;i<e.length;i++)if(r[i]){let t=4*(e[i]-u);t<0||t>l-4?r[i]=0:(s[i]=a[t++],n[i]=a[t++],p[i]=a[t++])}return o.pixels=[s,n,p],o.statistics=[new i(0,255),new i(0,255),new i(0,255)],o.pixelType=this.outputPixelType,o}_getWebGLParameters(){return this.lookup}};t([o({json:{write:!0,name:"rasterFunction"}})],a.prototype,"functionName",void 0),t([o({type:s,json:{write:!0,name:"rasterFunctionArguments"}})],a.prototype,"functionArguments",void 0),t([o()],a.prototype,"rasterArgumentNames",void 0),t([o({json:{write:!0}})],a.prototype,"lookup",void 0),a=t([e("esri.layers.raster.functions.ColormapToRGBFunction")],a);const u=a;export{u as default};
