UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) 2.44 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as t}from"tslib";import{property as e,subclass as o}from"../../../core/accessorSupport/decorators.js";import{getPixelValueRange as n}from"../formats/pixelRangeUtils.js";import s from"./BaseRasterFunction.js";import r from"./ConvolutionFunctionArguments.js";import{convolute as i}from"./convolutionUtils.js";import{convolutionKernel as u}from"../../support/rasterFunctionConstants.js";const l=25;let c=class extends s{constructor(){super(...arguments),this.functionName="Convolution",this.rasterArgumentNames=["raster"]}get _normalizedKernel(){const{kernel:t,convolutionType:e}=this.functionArguments,o=t.reduce((t,e)=>t+e);return-1===e||0===o||1===o?t:t.map(t=>t/o)}_bindSourceRasters(){const{convolutionType:t,rows:e,cols:o,kernel:n}=this.functionArguments;if(!Object.values(u).includes(t))return{success:!1,supportsGPU:!1,error:`convolution-function: the specified kernel type is not supported ${t}`};if(t!==u.none&&e*o!==n.length)return{success:!1,supportsGPU:!1,error:"convolution-function: the specified rows and cols do not match the length of the kernel"};const s=this.sourceRasterInfos[0];this.outputPixelType=this._getOutputPixelType(s.pixelType);const r=s.clone();r.pixelType=this.outputPixelType;const i=[u.none,u.sharpen,u.sharpen2,u.sharpening3x3,u.sharpening5x5];(-1===t||"u8"!==this.outputPixelType&&!i.includes(t))&&(r.statistics=null,r.histograms=null),r.colormap=null,r.attributeTable=null,this.rasterInfo=r;return{success:!0,supportsGPU:n.length<=l}}_processPixels(t){const e=t.pixelBlocks?.[0];if(null==e||this.functionArguments.convolutionType===u.none)return e;const{rows:o,cols:n}=this.functionArguments,{_normalizedKernel:s}=this;return i(e,{kernel:s,rows:o,cols:n,outputPixelType:this.outputPixelType})}_getWebGLParameters(){const t=new Float32Array(l),{rows:e,cols:o}=this.functionArguments,{_normalizedKernel:s}=this;for(let n=0;n<e;n++)for(let e=0;e<o;e++)t[5*n+e]=s[n*o+e];return{kernelRows:e,kernelCols:o,kernel:t,clampRange:n(this.outputPixelType)}}};t([e({json:{write:!0,name:"rasterFunction"}})],c.prototype,"functionName",void 0),t([e({type:r,json:{write:!0,name:"rasterFunctionArguments"}})],c.prototype,"functionArguments",void 0),t([e()],c.prototype,"rasterArgumentNames",void 0),t([e()],c.prototype,"_normalizedKernel",null),c=t([o("esri.layers.raster.functions.ConvolutionFunction")],c);const p=c;export{p as default};