UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 3.5 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{_ as t}from"../../../chunks/tslib.es6.js";import{property as s}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as e}from"../../../core/accessorSupport/decorators/subclass.js";import{localOperators as o}from"../rasterFunctionConstants.js";import{getPixelValueRange as n,isIntegerPixelType as r,getIntegerPixelType as i}from"../rasterFormats/pixelRangeUtils.js";import a from"./BaseRasterFunction.js";import u from"./LocalFunctionArguments.js";import{operandsCount as c,local as p,getOutputDomain as l}from"./localUtils.js";let m=class extends a{constructor(){super(...arguments),this.functionName="Local",this.functionArguments=null,this.rasterArgumentNames=["rasters"]}_bindSourceRasters(){const{sourceRasterInfos:t}=this,s=t[0],{bandCount:e}=s,{processAsMultiband:o}=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:n,rasters:r}=this.functionArguments,i=c[n];if(!(999===i||r.length===i||r.length<=1&&1===i))return{success:!1,supportsGPU:!1,error:`local-function: the length of functionArguments.rasters does not match operation's requirement: ${i}`};const a=s.clone();a.bandCount=999!==i||o?e:1,this._removeStatsHistColormapVAT(a),this._updateStatistics(a),this._updatePixelType(a),this.rasterInfo=a;return{success:!0,supportsGPU:1===a.bandCount&&i<=3}}_processPixels(t){const{pixelBlocks:s}=t;return null==s||s.some((t=>null==t))?null:p(s,this.functionArguments.operation,{processAsMultiband:this.functionArguments.processAsMultiband,outputPixelType:this.outputPixelType??void 0})}_getWebGLParameters(){const{operation:t}=this.functionArguments,s=c[t],e=Object.keys(o).find((s=>o[s]===t))?.toLowerCase()??"undefined",i=this.outputPixelType??"f32";let[a,u]=n(i);const p=r(i);return p&&(a-=1e-4,u+=1e-4),{imageCount:s,operationName:e,domainRange:[a,u],isOutputRounded:p}}_updateStatistics(t){const s=this.sourceRasterInfos[0],{operation:e}=this.functionArguments,o=l(e)?.domain;if(o){t.statistics=[];for(let s=0;s<t.bandCount;s++)t.statistics[s]={min:o[0],max:o[1],avg:(o[0]+o[1])/2,stddev:(o[0]+o[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:o}=this.functionArguments,{domain:n,isInteger:a}=l(o)??{domain:null,isInteger:!1};let u="f32";if(n&&a)u=i(n[0],n[1]);else if(30===o){const t=s?.[0];u=t?i(t.min,t.max):r(e)?e:"s32"}else if(45===o&&r(e)){const t=s?.map((({max:t})=>-t)),o=s?.map((({min:t})=>-t)),n=t?.length?Math.min(...t):null,r=o?.length?Math.min(...o):null;u=null!=n&&null!=r?i(n,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(u)}};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.support.rasterFunctions.LocalFunction")],m);const d=m;export{d as default};