/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{getPixelValueRange as t}from"../formats/pixelRangeUtils.js";import e from"../../support/PixelBlock.js";function s(s,i,n,h){const{pixels:o,width:a,height:l}=s,r=o.length,p=n.startsWith("f"),c=!p,[d,f]=t(n),m=a*l,g=e.createEmptyBand(n,m);for(let t=0;t<l;t++){let e=t*a;for(let t=0;t<a;t++,e++)if(!h||h[e]){let t=0;for(let s=0;s<r;s++)t+=i[s]*o[s][e];p||(t=Math.round(t),c&&(t=t>f?f:t<d?d:t)),g[e]=t}}return g}function i(t,i,n){const{width:h,height:o,mask:a,bandMasks:l}=t,r=l?.length?e.combineBandMasks(l):a,p=s(t,i,n,r),c=new e({width:h,height:o,pixels:[p],pixelType:n,mask:r});return c.updateStatistics(),c}function n(t,i,n){const{width:h,height:o,mask:a,bandMasks:l}=t,r=l?.length?e.combineBandMasks(l):a,p=[],c=t.pixels.length;for(let e=0;e<i.length/c;e++){const h=s(t,i.slice(e*c,(e+1)*c),n,r);p.push(h)}const d=new e({width:h,height:o,pixels:p,pixelType:n,mask:r});return d.updateStatistics(),d}export{i as grayscale,n as spectralConversion};
