/*
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","../../../geometry","../../../core/Error","../../../core/maybe","../../../core/promiseUtils","../../../core/accessorSupport/decorators/property","../../../core/arrayUtils","../../../core/has","../../../core/accessorSupport/ensureType","../../../core/accessorSupport/decorators/subclass","../RasterInfo","./BaseRaster","../rasterFunctions/pixelUtils","../rasterFunctions/stretchUtils","../../../geometry/Extent","../../../geometry/SpatialReference"],(function(e,t,s,r,i,a,o,n,l,c,p,h,u,m,d,y,f){"use strict";let v=function(t){function s(){var e;return(e=t.apply(this,arguments)||this).datasetFormat="MEMORY",e}e._inheritsLoose(s,t);var o=s.prototype;return o.open=function(){var t=e._asyncToGenerator((function*(e){var t;yield this.init();const{pixelBlock:s,statistics:r,histograms:i,name:a,keyProperties:o,nativeExtent:n,transform:l}=this.data,{width:c,height:p,pixelType:u}=s,m=this.data.extent||new y({xmin:-.5,ymin:.5,xmax:c-.5,ymax:p-.5,spatialReference:new f({wkid:3857})}),d=null!=(t=this.data.isPseudoSpatialReference)?t:!this.data.extent,v={x:m.width/c,y:m.height/p},x=new h({width:c,height:p,pixelType:u,extent:m,nativeExtent:n,transform:l,pixelSize:v,spatialReference:m.spatialReference,bandCount:3,keyProperties:o||{},statistics:r,isPseudoSpatialReference:d,histograms:i});this.createRemoteDatasetStorageInfo(x,512,512),this._set("rasterInfo",x),this.updateTileInfo(),yield this._buildInMemoryRaster(s,{width:512,height:512},e),this.datasetName=a,this.url="/InMemory/"+a}));function s(e){return t.apply(this,arguments)}return s}(),o.fetchRawTile=function(e,t,s,r={}){const i=this._pixelBlockTiles.get(`${e}/${t}/${s}`);return Promise.resolve(i)},o._buildInMemoryRaster=function(){var t=e._asyncToGenerator((function*(e,t,s){const o=this.rasterInfo.storageInfo.maximumPyramidLevel,n=this.rasterJobHandler?this.rasterJobHandler.split({pixelBlock:e,tileSize:t,maximumPyramidLevel:o},s):Promise.resolve(m.split(e,t,o)),l=i.isSome(this.rasterInfo.statistics),c=i.isSome(this.rasterInfo.histograms),p=l?Promise.resolve({statistics:null,histograms:null}):this.rasterJobHandler?this.rasterJobHandler.estimateStatisticsHistograms({pixelBlock:e},s):Promise.resolve(d.estimateStatisticsHistograms(e)),h=yield a.eachAlways([n,p]);if(!h[0].value&&h[1].value)throw new r("inmemory-raster:open","failed to build in memory raster");var u,y;(this._pixelBlockTiles=h[0].value,l)||(this.rasterInfo.statistics=null==(u=h[1].value)?void 0:u.statistics);c||(this.rasterInfo.histograms=null==(y=h[1].value)?void 0:y.histograms)}));function s(e,s,r){return t.apply(this,arguments)}return s}(),s}(u);t.__decorate([o.property({type:String,json:{write:!0}})],v.prototype,"datasetFormat",void 0),t.__decorate([o.property()],v.prototype,"data",void 0),v=t.__decorate([p.subclass("esri.layers.support.rasterDatasets.InMemoryRaster")],v);return v}));
