/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import t from"../../../core/Error.js";import{createStretchRenderer as e,getDefaultBandCombination as r}from"../../../renderers/support/rasterRendererHelper.js";import{processRasterRendererParameters as n}from"../support/utils.js";async function a(e){e=await n(e);const{serviceRasterInfo:a}=e.layer;if(1===a.bandCount)throw new t("raster-rgb-renderer:not-supported","Only multiband image is supported");const{rgbBandIds:s}=e;if(s&&3!==s.length)throw new t("raster-rgb-renderer:invalid-parameters","rgb band ids must have exactly three 0-based band indices");if(!s){const t=r(a);t&&t.length<3&&2===a.bandCount?e.rgbBandIds=[0,1,1]:e.rgbBandIds=t}return e}async function s(t){const r=(t=await a(t)).layer,{rasterInfo:n}=r,{rgbBandIds:s}=t,d={bandIds:s,stretchType:t.stretchType,includeStatisticsInStretch:t.includeStatisticsInStretch};let o=e(n,d);if(t.estimateStatistics){t.includeStatisticsInStretch=!0;const a=n.clone();await r.updateRasterInfoWithEstimatedStats(a,{rasterFunction:t.rasterFunction,signal:t.signal}),o=e(a,d)}return i(o,t),{renderer:o,rgbBandIds:s}}function i(t,e){const{gamma:r,useGamma:n,dynamicRangeAdjustment:a}=e;3===r?.length&&(t.gamma=r),null!=n&&(t.useGamma=n),null!=a&&(t.dynamicRangeAdjustment=a)}export{s as createRenderer};
