/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{__decorate as t}from"tslib";import{uniform as r,texture as o,UniformGroup as e,TextureGroup as i}from"../../../GraphShaderModule.js";import{Vec4 as u,IVec2 as m,Int as a,texelFetch as n,max as p,min as d,Vec3 as s,clamp as f,step as c,Float as l,sign as x,pow as v,Sampler2D as y}from"../../../graph/glsl.js";import{oneMinus as b}from"../utils.js";import{invertValue as O}from"./processor/math.js";class g extends e{}t([r(l)],g.prototype,"minOutput",void 0),t([r(l)],g.prototype,"maxOutput",void 0),t([r(s)],g.prototype,"minCutOff",void 0),t([r(s)],g.prototype,"maxCutOff",void 0),t([r(s)],g.prototype,"factor",void 0),t([r(s)],g.prototype,"gamma",void 0),t([r(s)],g.prototype,"gammaCorrection",void 0);class C extends e{}t([r(l)],C.prototype,"numberOfStandardDeviations",void 0);class T extends i{}function w(t,r){const{minCutOff:o,maxCutOff:e,factor:i,minOutput:u}=r;return f(t,o,e).subtract(o).multiply(i).add(u)}function h(t,r){const{minCutOff:o,maxCutOff:e,minOutput:i,maxOutput:u,gamma:m,gammaCorrection:a}=r,n=f(t,o,e).subtract(o),p=e.subtract(o),d=n.divide(p),y=c(new l(1),m),O=x(m.subtract(1)),g=u.subtract(i),C=new s(1),T=v(C.divide(g),d.multiply(a)),w=b(y.multiply(O).multiply(T)),h=v(d,C.divide(m)),j=w.multiply(g).multiply(h).add(i);return f(j,i,u)}function j(t,r,o,e=255){const i=o?h(t.rgb,r).divide(e):w(t.rgb,r);return new u(i,t.a)}function S(t,r,o,e,i,f){const c=new m(0,0),l=new a(0);let x=n(e.minTexture,c,l).rgb,v=n(e.maxTexture,c,l).rgb;if(f){const t=n(e.meanTexture,c,l).rgb,r=n(e.stddevTexture,c,l).rgb.multiply(o.numberOfStandardDeviations);x=p(x,t.subtract(r)),v=d(v,t.add(r))}const y=v.subtract(x),b=new s(O(y.x),O(y.y),O(y.z)),g=r.maxOutput.subtract(r.minOutput).multiply(b),C={...r,minCutOff:x,maxCutOff:v,factor:g},T=i?h(t.rgb,C).divide(255):w(t.rgb,C);return new u(T,t.a)}t([o(y)],T.prototype,"minTexture",void 0),t([o(y)],T.prototype,"maxTexture",void 0),t([o(y)],T.prototype,"meanTexture",void 0),t([o(y)],T.prototype,"stddevTexture",void 0);export{C as StatisticsConfig,T as StatisticsTextures,g as StretchConfig,j as stretch,S as stretchWithStatisticsTexture};
