/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{__decorate as t}from"tslib";import{uniform as u,define as s,option as r,UniformGroup as l}from"../../../../GraphShaderModule.js";import{Vec4 as i,pow as a,Float as e,sqrt as d,Mat3 as p,Vec3 as c}from"../../../../graph/glsl.js";import{oneMinus as m}from"../../utils.js";import{BaseRasterProcessorShader as n}from"./BaseRasterProcessorShader.js";import{roundOutput as o,invertValue as y}from"./math.js";class b extends l{}t([u(p)],b.prototype,"bandIndexMat3",void 0);class h extends l{}t([u(c)],h.prototype,"adjustments",void 0);class x extends n{constructor(){super(...arguments),this.type="BandArithmeticShader",this.isOutputRounded=!1}_process(t){const u=this._getPixel(t),s=this.bandArithmeticConfig.bandIndexMat3.multiply(u.rgb),r=this._processIndex(s),l=new i(r,r,r,u.a);return this.isOutputRounded?o(l):l}_processIndex(t){const{r:u,g:s}=t,r=this.adjustmentConfig?.adjustments;switch(this.indexType){case"ndxi":{const t=u.subtract(s),r=u.add(s);return t.multiply(y(r))}case"sr":return u.multiply(y(s));case"ci":return u.multiply(y(s)).subtract(1);case"savi":{const{x:t}=r,l=u.subtract(s),i=u.add(s).add(t);return l.multiply(y(i)).multiply(t.add(1))}case"tsavi":{const{x:t,y:l,z:i}=r,a=i.multiply(t.multiply(t).add(1)).subtract(l.multiply(t)),e=t.multiply(u.subtract(t.multiply(s)).subtract(l)),d=l.multiply(u).add(s).add(a);return e.multiply(y(d))}case"msavi":{const t=u.multiply(2).add(1),r=t.multiply(t).subtract(u.subtract(s).multiply(8));return t.subtract(d(r)).multiply(.5)}case"gemi":{const t=u.multiply(u).subtract(s.multiply(s)).multiply(2).add(u.multiply(1.5)).add(s.multiply(.5)),r=u.add(s).add(.5),l=t.multiply(y(r)),i=l.multiply(m(l.multiply(.25))),a=s.subtract(.125).multiply(y(m(s)));return i.subtract(a)}case"pvi":{const{x:t,y:l}=r,i=d(t.multiply(t).add(1));return u.subtract(s.multiply(t)).subtract(l).multiply(y(i))}case"vari":{const u=t.g.subtract(t.r),s=t.g.add(t.r).subtract(t.b);return u.multiply(y(s))}case"rtvicore":return u.subtract(s).multiply(100).subtract(u.subtract(t.b).multiply(10));case"bai":{const t=a(new e(.1).subtract(s),new e(2)),r=a(new e(.06).subtract(u),new e(2));return y(t.add(r))}case"evi":{const r=t.b,l=u.add(s.multiply(6)).subtract(r.multiply(7.5)).add(1);return u.subtract(s).multiply(2.5).multiply(y(l))}case"wndwi":{const{r:u,g:s,b:l}=t,i=r.x,a=i.multiply(s),e=i.multiply(l),d=u.add(a).add(l).subtract(e);return u.subtract(a).subtract(l).add(e).multiply(y(d))}case"mtvi":{const r=t.b,l=a(u.multiply(2).add(1),new e(2)),i=u.multiply(6).subtract(d(s).multiply(5)),p=d(l.subtract(i).subtract(.5)),c=u.subtract(r).multiply(1.2),m=s.subtract(r).multiply(2.5);return c.subtract(m).multiply(1.5).multiply(y(p))}default:return u}}}t([s],x.prototype,"indexType",void 0),t([s],x.prototype,"isOutputRounded",void 0),t([u(b)],x.prototype,"bandArithmeticConfig",void 0),t([r(h)],x.prototype,"adjustmentConfig",void 0);export{x as BandArithmeticShader};
