/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../../../chunks/_rollupPluginBabelHelpers","../../../../chunks/tslib.es6","../../../../core/Error","../../../../core/maybe","../../../../core/accessorSupport/decorators/property","../../../../core/arrayUtils","../../../../core/has","../../../../core/accessorSupport/ensureType","../../../../core/accessorSupport/decorators/subclass","../../../../geometry/Extent","../../../../layers/support/rasterFunctions/stretchUtils","./RasterLayerAdapter"],(function(t,e,r,s,a,i,o,n,c,l,h,p){"use strict";let u=function(e){function a(){return e.apply(this,arguments)||this}t._inheritsLoose(a,e);var i=a.prototype;return i.generateRasterInfo=function(t){return Promise.resolve(this.rasterInfo)},i.estimateStatisticsHistograms=function(){var e=t._asyncToGenerator((function*(t){if(null!==this._statsCache)return this._statsCache;const{raster:e}=this.layer,{extent:a,width:i,height:o}=this._getSamplePixelBlockDescriptor(e.rasterInfo),{pixelBlock:n}=yield e.fetchPixels(a,i,o,t);if(s.isNone(n))throw new r("raster-layer-adapter","Unable to estimate histograms");return this._statsCache=h.estimateStatisticsHistograms(n),this._statsCache}));function a(t){return e.apply(this,arguments)}return a}(),i.supportsMultidirectionalHillshade=function(){return!0},i.load=function(t){return this.addResolvingPromise(this.layer.load(t).then((()=>this.rasterInfo=this.layer.raster.rasterInfo))),Promise.resolve(this)},i._getSamplePixelBlockDescriptor=function(t,e=1e3){const{pyramidScalingFactor:r,maximumPyramidLevel:s}=t.storageInfo;let{extent:a,width:i,height:o,pixelSize:n}=t,c=Math.ceil(Math.log(Math.max(i,o)/e)/Math.log(r))-1,h=0,p=0;if(c<=s){const t=r**c;i=Math.floor(i/t),o=Math.floor(o/t)}else c=0,i=Math.min(i,e),o=Math.min(o,e),h=Math.max(Math.floor(i/2-500),0),p=Math.max(Math.floor(o/2-500),0),a=new l({xmin:a.xmin+h*n.x,xmax:Math.min(a.xmax,a.xmin+h*n.x*e),ymin:a.ymin+p*n.y,ymax:Math.min(a.ymax,a.ymin+p*n.y*e)});return{extent:a,width:i,height:o,origin:{x:h,y:p}}},a}(p);e.__decorate([a.property()],u.prototype,"layer",void 0),u=e.__decorate([c.subclass("esri.smartMapping.support.adapters.ImageryTileLayerAdapter")],u);return u}));
