/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../PixelBlock","./pixelUtils"],(function(e,t,i){"use strict";function l(e){let{altitude:t,azimuth:i}=e;const{hillshadeType:l,pixelSizePower:s,pixelSizeFactor:a,scalingType:n,isGCS:o,resolution:r}=e,c="multi-directional"===l?2*e.zFactor:e.zFactor,{x:h,y:u}=r;let d=c/(8*h),f=c/(8*u);if(o&&c>.001&&(d/=111e3,f/=111e3),"adjusted"===n)if(o){const e=111e3*h,t=111e3*u;d=(c+e**s*a)/(8*e),f=(c+t**s*a)/(8*t)}else d=(c+h**s*a)/(8*h),f=(c+u**s*a)/(8*u);let p=(90-t)*Math.PI/180,x=Math.cos(p),M=(360-i+90)*Math.PI/180,m=Math.sin(p)*Math.cos(M),A=Math.sin(p)*Math.sin(M);const w=[315,270,225,360,180,0],y=[60,60,60,60,60,90],g=new Float32Array([3,5,3,2,1,4]),P=g.reduce(((e,t)=>e+t)),k=g.map((e=>e/P)),Z="multi-directional"===l?w.length:1,b=new Float32Array(6),F=new Float32Array(6),C=new Float32Array(6);if("multi-directional"===l)for(let S=0;S<Z;S++)t=y[S],i=w[S],p=(90-t)*Math.PI/180,x=Math.cos(p),M=(360-i+90)*Math.PI/180,m=Math.sin(p)*Math.cos(M),A=Math.sin(p)*Math.sin(M),b[S]=x,F[S]=m,C[S]=A;else b.fill(x),F.fill(m),C.fill(A);return{resolution:r,factor:[d,f],sinZcosA:m,sinZsinA:A,cosZ:x,sinZcosAs:F,sinZsinAs:C,cosZs:b,weights:k,hillshadeType:["traditional","multi-directional"].indexOf(l)}}function s(e,s){if(!i.isValidPixelBlock(e))return e;const{width:a,height:n,mask:o}=e,r=new Uint8Array(a*n);o&&r.set(o);const{factor:c,sinZcosA:h,sinZsinA:u,cosZ:d,sinZcosAs:f,sinZsinAs:p,cosZs:x,weights:M}=l(s),[m,A]=c,{hillshadeType:w}=s,y=e.pixels[0],g=new Uint8Array(a*n);let P,k,Z,b,F,C,S,T;const U=1;for(let t=U;t<n-U;t++){const e=t*a;for(let t=U;t<a-U;t++){if(o&&!o[e+t]){g[e+t]=0;continue}let i=8;if(o&&(i=o[e-a+t-1]+o[e-a+t]+o[e-a+t+1]+o[e+t-1]+o[e+t+1]+o[e+a+t-1]+o[e+a+t]+o[e+a+t+1],i<7)){g[e+t]=0,r[e+t]=0;continue}7===i?(P=o[e-a+t-1]?y[e-a+t-1]:y[e+t],k=o[e-a+t]?y[e-a+t]:y[e+t],Z=o[e-a+t+1]?y[e-a+t+1]:y[e+t],b=o[e+t-1]?y[e+t-1]:y[e+t],F=o[e+t+1]?y[e+t+1]:y[e+t],C=o[e+a+t-1]?y[e+a+t-1]:y[e+t],S=o[e+a+t]?y[e+a+t]:y[e+t],T=o[e+a+t+1]?y[e+a+t+1]:y[e+t]):(P=y[e-a+t-1],k=y[e-a+t],Z=y[e-a+t+1],b=y[e+t-1],F=y[e+t+1],C=y[e+a+t-1],S=y[e+a+t],T=y[e+a+t+1]);const l=(Z+F+F+T-(P+b+b+C))*m,s=(C+S+S+T-(P+k+k+Z))*A,n=Math.sqrt(1+l*l+s*s);let c=0;if("traditional"===w){let e=255*(d+u*s-h*l)/n;e<0&&(e=0),c=e}else{const e=p.length;for(let t=0;t<e;t++){let e=255*(x[t]+p[t]*s-f[t]*l)/n;e<0&&(e=0),c+=e*M[t]}}g[e+t]=255&c}}for(let t=0;t<n;t++)g[t*a]=g[t*a+1],g[(t+1)*a-1]=g[(t+1)*a-2];for(let t=1;t<a-1;t++)g[t]=g[t+a],g[t+(n-1)*a]=g[t+(n-2)*a];return new t({width:a,height:n,pixels:[g],mask:o?r:null,pixelType:"u8",validPixelCount:e.validPixelCount,statistics:[{minValue:0,maxValue:255}]})}function a(e,t,l,s){if(!i.isValidPixelBlock(e)||!i.isValidPixelBlock(t))return;const{min:a,max:n}=s,o=e.pixels[0],{pixels:r,mask:c}=t,h=r[0],u=255.00001/(n-a),d=new Uint8ClampedArray(h.length),f=new Uint8ClampedArray(h.length),p=new Uint8ClampedArray(h.length),x=l.length-1;for(let i=0;i<h.length;i++){if(c&&0===c[i])continue;const e=Math.floor((h[i]-a)*u),[t,s]=l[e<0?0:e>x?x:e],n=o[i],r=n*s,M=r*(1-Math.abs(t%2-1)),m=n-r;switch(Math.floor(t)){case 0:d[i]=r+m,f[i]=M+m,p[i]=m;break;case 1:d[i]=M+m,f[i]=r+m,p[i]=m;break;case 2:d[i]=m,f[i]=r+m,p[i]=M+m;break;case 3:d[i]=m,f[i]=M+m,p[i]=r+m;break;case 4:d[i]=M+m,f[i]=m,p[i]=r+m;break;case 5:case 6:d[i]=r+m,f[i]=m,p[i]=M+m}}e.pixels=[d,f,p],e.updateStatistics()}e.calculateHillshadeParams=l,e.hillshade=s,e.tintHillshade=a,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
