/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../../chunks/_rollupPluginBabelHelpers","../../../../../core/promiseUtils","../utils","../../../../webgl/BufferObject","../../../../webgl/enums","../../../../webgl/Texture","../../../../webgl/VertexArrayObject","../../../../webgl/VertexElementDescriptor"],(function(t,e,a,r,i,o,s,n,l){"use strict";let c=function(){function t(t){this._params=t,this.animated=!1}var i=t.prototype;return i.isCompatible=function(e){if(!(e instanceof t))return!1;if(!r.timeExtentsEqual(this._params.timeExtent,e._params.timeExtent))return!1;let a=!0;return a=a&&this._params.loadImagery===e._params.loadImagery,a=a&&this._params.color.kind===e._params.color.kind,a=a&&this._params.opacity.kind===e._params.opacity.kind,a},i.load=function(){var t=e._asyncToGenerator((function*(t,e){const{extent:r,size:i}=t;a.throwIfAborted(e);const o=yield this._params.loadImagery(r,i[0],i[1],this._params.timeExtent,e);return new f(o,{color:this._params.color,opacity:this._params.opacity})}));function r(e,a){return t.apply(this,arguments)}return r}(),i.render=function(t,e,a){const{context:i}=t,{program:s}=a;i.setFaceCullingEnabled(!1),i.setBlendingEnabled(!0),i.setBlendFunction(o.BlendFactor.ONE,o.BlendFactor.ONE_MINUS_SRC_ALPHA),i.useProgram(s),s.setUniformMatrix3fv("u_dvsMat3",e.dvsMat3),i.bindTexture(a.texture,0),s.setUniform1i("u_texture",0),s.setUniform1f("u_Min",a.min),s.setUniform1f("u_Max",a.max),r.setUniforms(s,"color","vec4",this._params.color),r.setUniforms(s,"opacity","float",this._params.opacity),i.bindVAO(a.vertexArray),i.drawArrays(o.PrimitiveType.TRIANGLE_STRIP,0,4)},t}();const m=new Map;m.set("a_position",0),m.set("a_texcoord",1);const p={geometry:[new l.VertexElementDescriptor("a_position",2,o.DataType.UNSIGNED_SHORT,0,8),new l.VertexElementDescriptor("a_texcoord",2,o.DataType.UNSIGNED_SHORT,4,8)]},u={vsPath:"raster/flow/imagery",fsPath:"raster/flow/imagery",attributes:m};let f=function(){function t(t,e){this._flowData=t,this._values=e}var a=t.prototype;return a.attach=function(t){const{context:e}=t,{width:a,height:r}=this._flowData,l={geometry:i.BufferObject.createVertex(e,o.Usage.STATIC_DRAW,new Uint16Array([0,0,0,1,a,0,1,1,0,r,0,0,a,r,1,0]))},c=new n.VertexArrayObject(e,m,p,l),f=[];"ramp"===this._values.color.kind&&f.push("vvColor"),"ramp"===this._values.opacity.kind&&f.push("vvOpacity");const h=t.painter.materialManager.getProgram(u,f);let _=1e6,d=-1e6;for(let i=0;i<r;i++)for(let t=0;t<a;t++)if(0!==this._flowData.mask[i*a+t]){const e=this._flowData.data[2*(i*a+t)+0],r=this._flowData.data[2*(i*a+t)+1],o=Math.sqrt(e*e+r*r);_=Math.min(_,o),d=Math.max(d,o)}const x=new Uint8Array(4*a*r);for(let i=0;i<r;i++)for(let t=0;t<a;t++)if(0!==this._flowData.mask[i*a+t]){const e=this._flowData.data[2*(i*a+t)+0],r=this._flowData.data[2*(i*a+t)+1],o=(Math.sqrt(e*e+r*r)-_)/(d-_);x[4*(i*a+t)+0]=255*o,x[4*(i*a+t)+1]=0,x[4*(i*a+t)+2]=0,x[4*(i*a+t)+3]=255}else x[4*(i*a+t)+0]=0,x[4*(i*a+t)+1]=0,x[4*(i*a+t)+2]=0,x[4*(i*a+t)+3]=0;const y=new s.Texture(e,{pixelFormat:o.PixelFormat.RGBA,internalFormat:o.PixelFormat.RGBA,samplingMode:o.TextureSamplingMode.LINEAR,dataType:o.PixelType.UNSIGNED_BYTE,wrapMode:o.TextureWrapMode.CLAMP_TO_EDGE,flipped:!0,width:a,height:r},x);this.vertexArray=c,this.program=h,this.texture=y,this.min=_,this.max=d,this._flowData=null},a.detach=function(){this.vertexArray.dispose(),this.texture.dispose()},e._createClass(t,[{key:"ready",get:function(){return this.program.isCompiled}}]),t}();t.ImageryResources=f,t.default=c,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
