@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 3.32 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{mirror as e}from"./mirror.js";import t from"../../support/PixelBlock.js";import{convolutionKernel as n}from"../../support/rasterFunctionConstants.js";const o=new Map;function l(e){const t=Math.sqrt(e.length),n=e.slice(0,t),o=[1];for(let l=1;l<t;l++){let n=null;for(let o=0;o<t;o++){const r=e[o+l*t],s=e[o];if(null==n)if(0===s){if(r)return{separable:!1,row:null,col:null}}else n=r/s;else if(r/s!==n)return{separable:!1,row:null,col:null}}if(null==n)return{separable:!1,row:null,col:null};o.push(n)}return{separable:!0,row:n,col:o}}function r(e,t,n,o,l,r,s){const i=new Float32Array(t*n),a=r.length,p=s?0:o,h=s?o:0,c=s?1:t;for(let u=p;u<n-p;u++){const n=u*t;for(let s=h;s<t-h;s++){if(l&&!l[n+s])continue;let t=0;for(let l=0;l<a;l++)t+=e[n+s+(l-o)*c]*r[l];i[n+s]=t}}return i}function s(e,t,n,o,l,r,s){const i=new Float32Array(t*n),a=Math.floor(o/2),p=Math.floor(l/2);for(let h=a;h<n-a;h++){const n=h*t;for(let h=p;h<t-p;h++){if(r&&!r[n+h])continue;let c=0;for(let r=0;r<o;r++)for(let o=0;o<l;o++)c+=e[n+h+(r-a)*t+o-p]*s[r*l+o];i[n+h]=c}}return i}function i(n,o,l=!0){const{pixels:r,width:i,height:a,pixelType:p,mask:h}=n,c=r.length,u=[],{kernel:f,rows:g,cols:m}=o;for(let t=0;t<c;t++){const n=s(r[t],i,a,g,m,h,f);l&&e(n,i,a,g,m),u.push(n)}return new t({width:i,height:a,pixelType:p,pixels:u,mask:h})}function a(n,o,l,s=!0){const{pixels:i,width:a,height:p,pixelType:h,mask:c}=n,u=i.length,f=[],g=o.length,m=l.length,x=Math.floor(g/2),w=Math.floor(m/2);for(let t=0;t<u;t++){let n=r(i[t],a,p,x,c,o,!0);n=r(n,a,p,w,c,l,!1),s&&e(n,a,p,g,m),f.push(n)}return new t({width:a,height:p,pixelType:h,pixels:f,mask:c})}function p(e,t){const n=l(t.kernel),o=!1!==t.mirrorEdges,r=n.separable?a(e,n.row,n.col,o):i(e,t,o),{outputPixelType:s}=t;return s&&r.clamp(s),r}o.set(n.none,[0,0,0,0,1,0,0,0,0]),o.set(n.lineDetectionHorizontal,[-1,-1,-1,2,2,2,-1,-1,-1]),o.set(n.lineDetectionVertical,[-1,2,-1,-1,2,-1,-1,2,-1]),o.set(n.lineDetectionLeftDiagonal,[2,-1,-1,-1,2,-1,-1,-1,2]),o.set(n.lineDetectionRightDiagonal,[-1,-1,2,-1,2,-1,2,-1,-1]),o.set(n.gradientNorth,[-1,-2,-1,0,0,0,1,2,1]),o.set(n.gradientWest,[-1,0,1,-2,0,2,-1,0,1]),o.set(n.gradientEast,[1,0,-1,2,0,-2,1,0,-1]),o.set(n.gradientSouth,[1,2,1,0,0,0,-1,-2,-1]),o.set(n.gradientNorthEast,[0,-1,-2,1,0,-1,2,1,0]),o.set(n.gradientNorthWest,[-2,-1,0,-1,0,1,0,1,2]),o.set(n.smoothArithmeticMean,[.111111111111,.111111111111,.111111111111,.111111111111,.111111111111,.111111111111,.111111111111,.111111111111,.111111111111]),o.set(n.smoothing3x3,[.0625,.125,.0625,.125,.25,.125,.0625,.125,.0625]),o.set(n.smoothing5x5,[1,1,1,1,1,1,4,4,4,1,1,4,12,4,1,1,4,4,4,1,1,1,1,1,1]),o.set(n.sharpening3x3,[-1,-1,-1,-1,9,-1,-1,-1,-1]),o.set(n.sharpening5x5,[-1,-3,-4,-3,-1,-3,0,6,0,-3,-4,6,21,6,-4,-3,0,6,0,-3,-1,-3,-4,-3,-1]),o.set(n.laplacian3x3,[0,-1,0,-1,4,-1,0,-1,0]),o.set(n.laplacian5x5,[0,0,-1,0,0,0,-1,-2,-1,0,-1,-2,17,-2,-1,0,-1,-2,-1,0,0,0,-1,0,0]),o.set(n.sobelHorizontal,[-1,-2,-1,0,0,0,1,2,1]),o.set(n.sobelVertical,[-1,0,1,-2,0,2,-1,0,1]),o.set(n.sharpen,[0,-.25,0,-.25,2,-.25,0,-.25,0]),o.set(n.sharpen2,[-.25,-.25,-.25,-.25,3,-.25,-.25,-.25,-.25]),o.set(n.pointSpread,[-.627,.352,-.627,.352,2.923,.352,-.627,.352,-.627]);export{p as convolute,a as convoluteSeparable,o as convolutionKernels,l as separateKernels};