/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{BaseRasterProcessorTechnique as e}from"./BaseRasterProcessorTechnique.js";import{ReprojectShader as t}from"../../shaders/raster/processor/ReprojectShader.js";class r extends e{constructor(){super(...arguments),this.name="RasterReprojectProcessor",this.type=19,this.shaders={reproject:new t}}_process(e,t){const r=e.rasterFunction.parameters,o=this._getInterpolationDefines(t.interpolation,!!r.requireNNEdge),{config:i,projectionConfig:s,projectionTextures:n,textures:a,projectionDefines:c}=this._getReprojectConfig(t),p={shader:this.shaders.reproject,uniforms:{config:i,projectionConfig:s},textures:{...a,projectionTextures:n},defines:{...c,...o,applyPixelMask:!1,applyPixelHighlights:!1},optionalAttributes:null,useComputeBuffer:!1},{interpolation:u}=t;t.interpolation="nearest";const{painter:g,context:l}=e;g.submitDrawMesh(l,p,g.quadMesh),t.interpolation=u,t.projected=!0}_getReprojectConfig(e){const{source:t}=e,{names:r,textures:o}=e.getTextures({forProcessing:!0}),i=o[r.indexOf("u_image")],s={dvsMat3:new Float32Array([2,0,0,0,2,0,-1,-1,0]),coordScale:[1,1],srcImageSize:[t.width,t.height],opacity:1},n={texture:{texture:i,unit:0},pixelMaskTexture:null,highlightTexture:null},a=o[r.indexOf("u_transformGrid")],{transformGrid:c}=e,p=!(!a||!c);return{config:s,projectionConfig:p?{targetImageSize:[e.width,e.height],transformSpacing:c.spacing,transformGridSize:c.size}:void 0,projectionTextures:p?{transformTexture:{texture:a,unit:1}}:void 0,textures:n,projectionDefines:{applyProjection:p,lookupProjection:p&&1===c.spacing[0]}}}_getInterpolationDefines(e,t){const r="bilinear"===e&&t;return{bilinear:r,bicubic:"cubic"===e,nearestOnEdge:r}}}export{r as ReprojectTechnique};
