@arcgis/core 4.26.0-next.20230113 → 4.26.0-next.20230115

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/WebMap.js +1 -1
  2. package/WebScene.js +1 -1
  3. package/assets/esri/core/workers/RemoteClient.js +1 -1
  4. package/assets/esri/core/workers/chunks/05679a6529421d546fe0.js +1 -0
  5. package/assets/esri/core/workers/chunks/2e5b61ee21fa6287cc65.js +1 -0
  6. package/assets/esri/core/workers/chunks/2e7e8b035673d90deefd.js +1 -0
  7. package/assets/esri/core/workers/chunks/4e13f84441f0b149f32e.js +1 -0
  8. package/assets/esri/core/workers/chunks/5605de870cfc1498a393.js +1 -0
  9. package/assets/esri/core/workers/chunks/5ad3a3d15831b759e758.js +1 -0
  10. package/assets/esri/core/workers/chunks/633a86e8e8ad2ab866f4.js +1 -0
  11. package/assets/esri/core/workers/chunks/86491e6269e25b1766ed.js +1 -0
  12. package/assets/esri/core/workers/chunks/c3fda4056c5eeaef1339.js +1 -0
  13. package/assets/esri/core/workers/chunks/{399c453397a1f10408bf.js → c7b23f664a2707b96daf.js} +1 -1
  14. package/assets/esri/core/workers/chunks/{dd2e9206133d6888f33d.js → dc6bad8c0a09393834a1.js} +1 -1
  15. package/assets/esri/core/workers/chunks/{bc3564689bd42cba97f9.js → f34c607e73757f6024eb.js} +1 -1
  16. package/core/accessorSupport/decorators/persistable.js +1 -1
  17. package/core/accessorSupport/write.js +1 -1
  18. package/layers/mixins/ArcGISImageService.js +1 -1
  19. package/layers/mixins/ImageryTileMixin.js +1 -1
  20. package/layers/mixins/SceneService.js +1 -1
  21. package/layers/support/PixelBlock.js +1 -1
  22. package/layers/support/imageryRendererUtils.js +1 -1
  23. package/layers/support/rasterDatasets/BaseRaster.js +1 -1
  24. package/layers/support/rasterDatasets/ImageServerRaster.js +1 -1
  25. package/layers/support/rasterDatasets/multidimensionalUtils.js +1 -1
  26. package/layers/support/rasterFormats/Lerc.js +1 -1
  27. package/layers/support/rasterFormats/RasterCodec.js +1 -1
  28. package/layers/support/rasterFormats/TiffDecoder.js +1 -1
  29. package/layers/support/rasterFormats/pixelRangeUtils.js +5 -0
  30. package/layers/support/rasterFunctions/ConvolutionFunction.js +1 -1
  31. package/layers/support/rasterFunctions/stretchUtils.js +1 -1
  32. package/package.json +1 -1
  33. package/renderers/support/rasterRendererHelper.js +1 -1
  34. package/support/revision.js +1 -1
  35. package/views/2d/engine/Stage.js +1 -1
  36. package/views/MapView.js +1 -1
  37. package/widgets/FeatureTable/FieldColumn.js +1 -1
  38. package/widgets/Legend/support/ActiveLayerInfo.js +1 -1
  39. package/assets/esri/core/workers/chunks/1363e647f3b0bca07e09.js +0 -1
  40. package/assets/esri/core/workers/chunks/2541edeae4b1a53b8723.js +0 -1
  41. package/assets/esri/core/workers/chunks/3b689bb038ebc301c3b2.js +0 -1
  42. package/assets/esri/core/workers/chunks/6216cd8134703fd9d9b4.js +0 -1
  43. package/assets/esri/core/workers/chunks/64f137358100a1c818f0.js +0 -1
  44. package/assets/esri/core/workers/chunks/6fba07833345b2d8d373.js +0 -1
  45. package/assets/esri/core/workers/chunks/78fd609f334a29ef39dc.js +0 -1
  46. package/assets/esri/core/workers/chunks/798cd875d64182741364.js +0 -1
  47. package/assets/esri/core/workers/chunks/8bd26c71e78698c16778.js +0 -1
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.26/esri/copyright.txt for details.
4
4
  */
5
- import{_ as t}from"../../../chunks/tslib.es6.js";import"../../../geometry.js";import e from"../../../request.js";import i from"../../../core/Error.js";import{JSONSupport as r}from"../../../core/JSONSupport.js";import o from"../../../core/Logger.js";import{isSome as n,unwrap as s,isNone as a,unwrapOrThrow as l}from"../../../core/maybe.js";import{EsriPromiseMixin as c}from"../../../core/Promise.js";import{onAbort as m}from"../../../core/promiseUtils.js";import{property as f}from"../../../core/accessorSupport/decorators/property.js";import{ensureClass as h}from"../../../core/accessorSupport/ensureType.js";import"../../../core/arrayUtils.js";import{subclass as u}from"../../../core/accessorSupport/decorators/subclass.js";import{sanitizeUrl as p}from"../arcgisLayerUrl.js";import{url as d}from"../commonProperties.js";import x from"../DimensionalDefinition.js";import g from"../LOD.js";import y from"../RasterStorageInfo.js";import I from"../TileInfo.js";import{isMultiSliceOrRangeDefinition as R,getSliceIndex as w,createSlices as k,getSliceIds as b}from"./multidimensionalUtils.js";import{getRasterId as S,getBlock as T,putBlock as v,deleteBlock as B,decreaseRefCount as P}from"./RawBlockCache.js";import{decode as M}from"../rasterFormats/RasterCodec.js";import{mosaic as W,approximateTransform as _,getLocalArithmeticNorthRotations as C}from"../rasterFunctions/pixelUtils.js";import{load as j,getWorldWidth as H,projectPoint as L,snapPyramid as E,snapExtent as z,getWorldWrapCount as D,projectExtent as A,getProjectionOffsetGrid as F,getRasterDatasetAlignmentInfo as O,projectResolution as q}from"../rasterFunctions/rasterProjectionHelper.js";import{convertToLocalDirections as G,uvComponentToVector as J}from"../rasterFunctions/vectorFieldUtils.js";import N from"../../../geometry/Extent.js";import V from"../../../geometry/Point.js";const $=8,U=256;let X=class extends(c(r)){constructor(){super(...arguments),this.rasterJobHandler=null,this.datasetName=null,this.datasetFormat=null,this.rasterInfo=null,this.ioConfig={sampling:"closest"}}async init(){const t=j();this.addResolvingPromise(t),await this.when()}normalizeCtorArgs(t){return t&&t.ioConfig&&(t={...t,ioConfig:{resolution:null,bandIds:null,sampling:"closest",tileInfo:I.create(),...t.ioConfig}}),t}get _isGlobalWrappableSource(){const{rasterInfo:t}=this,e=H(t.spatialReference);return n(e)&&t.extent.width>=e/2}set url(t){this._set("url",p(t,o.getLogger(this.declaredClass)))}async open(t){throw new i("BaseRaster:open-not-implemented","open() is not implemented")}async fetchTile(t,e,i,r={}){const o=r.tileInfo||this.rasterInfo.storageInfo.tileInfo,n=this.getTileExtentFromTileInfo(t,e,i,o);return this.fetchPixels(n,o.size[0],o.size[1],r)}async identify(t,e={}){t=h(V,t).clone().normalize();const{multidimensionalDefinition:i,timeExtent:r}=e,{hasMultidimensionalTranspose:o,multidimensionalInfo:l}=this.rasterInfo;let{transposedVariableName:c}=e;const m=n(l)&&o&&(null!=r||R(i));if(m&&!c){c=n(i)&&i.length>0?i[0].variableName??void 0:l.variables[0].name,e={...e,transposedVariableName:c}}e=this._getRequestOptionsWithSliceId(e);const{spatialReference:f,extent:u}=this.rasterInfo,{datumTransformation:p}=e;let d=L(t,f,p);if(!u.intersects(d))return{location:d,value:null};if(n(this.rasterInfo.transform)){const t=this.rasterInfo.transform.inverseTransform(d);if(!this.rasterInfo.nativeExtent.intersects(t))return{location:t,value:null};d=t}let x=0;const g=n(c)&&n(l)&&this.rasterInfo.hasMultidimensionalTranspose;if(!g)if(e.srcResolution){x=E(e.srcResolution,this.rasterInfo,this.ioConfig.sampling).pyramidLevel}else if(x=await this.computeBestPyramidLevelForLocation(t,e),null==x)return{location:d,value:null};const y=this.identifyPixelLocation(d,x,null,g);if(null===y)return{location:d,value:null};const{row:I,col:w,rowOffset:k,colOffset:b,blockWidth:B}=y,P=c??s(e.sliceId),M=S(this.url,P),W=`${x}/${I}/${w}`;let _=T(M,null,W);a(_)&&(_=this.fetchRawTile(x,I,w,e),v(M,null,W,_));const C=await _;if(a(C)||!C.pixels?.length)return{location:d,value:null};const j=k*B+b;return this._processIdentifyResult(C,{srcLocation:d,position:j,pyramidLevel:x,useTransposedTile:!!g,requestSomeSlices:m,identifyOptions:e})}async fetchPixels(t,e,i,r={}){if(t=z(t),(r=this._getRequestOptionsWithSliceId(r)).requestRawData)return this._fetchPixels(t,e,i,r);const o=H(t.spatialReference),n=D(t);if(a(o)||0===n||1===n&&this._isGlobalWrappableSource)return this._fetchPixels(t,e,i,r);if(n>=3)return{extent:t,pixelBlock:null};const s=[],{xmin:l,xmax:c}=t,m=Math.round(o/(c-l)*e),f=m-Math.round((o/2-l)/(c-l)*e);let h=0;const u=[];for(let a=0;a<=n;a++){const p=new N({xmin:0===a?l:-o/2,xmax:a===n?c-o*a:o/2,ymin:t.ymin,ymax:t.ymax,spatialReference:t.spatialReference}),d=0===a?m-f:a===n?e-h:m;h+=d,u.push(d);const x=r.disableWrapAround&&a>0?null:this._fetchPixels(p,d,i,r);s.push(x)}const p=(await Promise.all(s)).map((t=>t?.pixelBlock));let d=null;const x={width:e,height:i};if(this.rasterJobHandler){d=(await this.rasterJobHandler.mosaicAndTransform({srcPixelBlocks:p,srcMosaicSize:x,destDimension:null,coefs:null,sampleSpacing:null,interpolation:"nearest",alignmentInfo:null,blockWidths:u},r)).pixelBlock}else d=W(p,x,{blockWidths:u});return{extent:t,srcExtent:A(t,this.rasterInfo.spatialReference,r.datumTransformation),pixelBlock:d}}async fetchRawPixels(t,e,i,r={}){e={x:Math.floor(e.x),y:Math.floor(e.y)};const o=await this._fetchRawTiles(t,e,i,r),{nativeExtent:s,nativePixelSize:a,storageInfo:l}=this.rasterInfo,c=2**t,m=a.x*c,f=a.y*c,h=new N({xmin:s.xmin+m*e.x,xmax:s.xmin+m*(e.x+i.width-1),ymin:s.ymax-f*(e.y+i.height-1),ymax:s.ymax-f*e.y,spatialReference:s.spatialReference});if(!o)return{extent:h,srcExtent:h,pixelBlock:null};const{pixelBlocks:u,mosaicSize:p}=o;if(1===u.length&&n(u[0])&&u[0].width===i.width&&u[0].height===i.height)return{extent:h,srcExtent:h,pixelBlock:o.pixelBlocks[0]};const d=t>0?l.pyramidBlockWidth:l.blockWidth,x=t>0?l.pyramidBlockHeight:l.blockHeight,g={x:e.x%d,y:e.y%x};let y;if(this.rasterJobHandler){y=(await this.rasterJobHandler.mosaicAndTransform({srcPixelBlocks:u,srcMosaicSize:p,destDimension:i,clipOffset:g,clipSize:i,coefs:null,sampleSpacing:null,interpolation:r.interpolation,alignmentInfo:null,blockWidths:null},r)).pixelBlock}else y=W(u,p,{clipOffset:g,clipSize:i});return{extent:h,srcExtent:h,pixelBlock:y}}fetchRawTile(t,e,r,o){throw new i("BaseRaster:read-not-implemented","fetchRawTile() is not implemented")}computeExtent(t){return A(this.rasterInfo.extent,t)}decodePixelBlock(t,e){return!this.rasterJobHandler||e.useCanvas?M(t,e):this.rasterJobHandler.decode({data:t,options:e})}async request(t,i,r=0){const{customFetchParameters:o}=this.ioConfig,{range:n,query:s,headers:a}=i;r=r??i.retryCount??this.ioConfig.retryCount;const l=n?{Range:`bytes=${n.from}-${n.to}`}:null;try{return await e(t,{...i,query:{...s,...o},headers:{...a,...l}})}catch(c){if(r>0)return r--,this.request(t,i,r);throw c}}getSliceIndex(t){const{multidimensionalInfo:e}=this.rasterInfo;return a(e)||a(t)||0===t.length?null:w(t,e)}getTileExtentFromTileInfo(t,e,i,r){const o=l(r.lodAt(t));return this.getTileExtent({x:o.resolution,y:o.resolution},e,i,r.origin,r.spatialReference,r.size)}updateTileInfo(){const{storageInfo:t,spatialReference:e,extent:i,pixelSize:r}=this.rasterInfo;if(!t.tileInfo){const o=[],n=t.maximumPyramidLevel||0;let s=Math.max(r.x,r.y),a=1/.0254*96*s;for(let t=0;t<=n;t++)o.push(new g({level:n-t,resolution:s,scale:a})),s*=2,a*=2;const l=new V({x:i.xmin,y:i.ymax,spatialReference:e});t.tileInfo=new I({origin:l,size:[t.blockWidth,t.blockHeight],spatialReference:e,lods:o}),t.isVirtualTileInfo=!0}}createRemoteDatasetStorageInfo(t,e=512,i=512,r){const{width:o,height:n,nativeExtent:s,pixelSize:a,spatialReference:l}=t,c=new V({x:s.xmin,y:s.ymax,spatialReference:l});null==r&&(r=Math.max(0,Math.round(Math.log(Math.max(o,n))/Math.LN2-8)));const m=this.computeBlockBoundary(s,512,512,{x:s.xmin,y:s.ymax},[a],r);t.storageInfo=new y({blockWidth:e,blockHeight:i,pyramidBlockWidth:e,pyramidBlockHeight:i,origin:c,firstPyramidLevel:1,maximumPyramidLevel:r,blockBoundary:m})}async computeBestPyramidLevelForLocation(t,e={}){return 0}computeBlockBoundary(t,e,i,r,o,n=0,s=2){if(1===o.length&&n>0){o=[...o];let{x:t,y:e}=o[0];for(let i=0;i<n;i++)t*=s,e*=s,o.push({x:t,y:e})}const a=[],{x:l,y:c}=r;for(let m=0;m<o.length;m++){const{x:r,y:n}=o[m];a.push({minCol:Math.floor((t.xmin-l+.1*r)/e/r),maxCol:Math.floor((t.xmax-l-.1*r)/e/r),minRow:Math.floor((c-t.ymax+.1*n)/i/n),maxRow:Math.floor((c-t.ymin-.1*n)/i/n)})}return a}getPyramidPixelSize(t){const{nativePixelSize:e}=this.rasterInfo,{pyramidResolutions:i,pyramidScalingFactor:r}=this.rasterInfo.storageInfo;if(0===t)return e;if(n(i)&&i.length)return i[t-1];const o=r**t;return{x:e.x*o,y:e.y*o}}identifyPixelLocation(t,e,i,r){const{spatialReference:o,nativeExtent:s,storageInfo:a}=this.rasterInfo,{maximumPyramidLevel:l,origin:c,transposeInfo:m}=a,f=r&&n(m)?m.tileSize[0]:a.blockWidth,h=r&&n(m)?m.tileSize[1]:a.blockHeight,u=L(t,o,i);if(!s.intersects(u))return null;if(e<0||e>l)return null;const p=this.getPyramidPixelSize(e),{x:d,y:x}=p,g=(c.y-u.y)/x/h,y=(u.x-c.x)/d/f,I=Math.min(h-1,Math.floor((g-Math.floor(g))*h)),R=Math.min(f-1,Math.floor((y-Math.floor(y))*f));return{pyramidLevel:e,row:Math.floor(g),col:Math.floor(y),rowOffset:I,colOffset:R,blockWidth:f,srcLocation:u}}getTileExtent(t,e,i,r,o,n){const[s,a]=n,l=r.x+i*s*t.x,c=l+s*t.x,m=r.y-e*a*t.y,f=m-a*t.y;return new N({xmin:l,xmax:c,ymin:f,ymax:m,spatialReference:o})}getBlockWidthHeight(t){return{blockWidth:t>0?this.rasterInfo.storageInfo.pyramidBlockWidth:this.rasterInfo.storageInfo.blockWidth,blockHeight:t>0?this.rasterInfo.storageInfo.pyramidBlockHeight:this.rasterInfo.storageInfo.blockHeight}}isBlockOutside(t,e,i){const r=this.rasterInfo.storageInfo.blockBoundary[t];return!r||r.maxRow<e||r.maxCol<i||r.minRow>e||r.minCol>i}async _fetchPixels(t,e,i,r={}){let o=D(t);if(o>=2)return{extent:t,pixelBlock:null};const a=this._getSourceDataInfo(t,e,i,r),{pyramidLevel:l,pyramidResolution:c,srcResolution:m,srcExtent:f,srcWidth:h,srcHeight:u}=a;if(0===h||0===u)return{extent:t,srcExtent:f,pixelBlock:null};const p=s(this.rasterInfo.transform),d="gcs-shift"===p?.type,x=n(H(t.spatialReference));!d&&x||(o=D(a.srcExtent,d));const g=this.rasterInfo.storageInfo,y={x:Math.floor((f.xmin-g.origin.x)/c.x+.1),y:Math.floor((g.origin.y-f.ymax)/c.y+.1)},I=await this._fetchRawTiles(l,y,{width:h,height:u,wrapCount:o},r);if(!I)return{extent:t,srcExtent:f,pixelBlock:null};const R=l>0?g.pyramidBlockWidth:g.blockWidth,w=l>0?g.pyramidBlockHeight:g.blockHeight,k=R===h&&w===u&&y.x%R==0&&y.y%w==0,b=new V({x:(t.xmax-t.xmin)/e,y:(t.ymax-t.ymin)/i,spatialReference:t.spatialReference}),S=!t.spatialReference.equals(this.rasterInfo.spatialReference),{datumTransformation:T}=r;if(!S&&k&&1===I.pixelBlocks.length&&R===e&&w===i&&m.x===b.x&&m.y===b.y)return{extent:t,srcExtent:f,pixelBlock:I.pixelBlocks[0]};const v=x&&n(H(f.spatialReference)),B=r.requestProjectedLocalDirections&&this.rasterInfo.dataType.startsWith("vector");B&&!this.rasterJobHandler&&await j();const P=this.rasterJobHandler?await this.rasterJobHandler.getProjectionOffsetGrid({projectedExtent:t,srcBufferExtent:I.extent,pixelSize:b.toJSON(),datumTransformation:T,rasterTransform:p,hasWrapAround:o>0||v,isAdaptive:!1!==this.ioConfig.optimizeProjectionAccuracy,includeGCSGrid:B},r):F({projectedExtent:t,srcBufferExtent:I.extent,pixelSize:b,datumTransformation:T,rasterTransform:p,hasWrapAround:o>0||v,isAdaptive:!1,includeGCSGrid:B});let M;const L=!r.requestRawData,E={rows:P.spacing[0],cols:P.spacing[1]},z=s(this._getRasterTileAlignmentInfo(l,I.extent.xmin)),{pixelBlocks:A,mosaicSize:O,isPartiallyFilled:q}=I;let J=null;if(this.rasterJobHandler){const t=await this.rasterJobHandler.mosaicAndTransform({srcPixelBlocks:A,srcMosaicSize:O,destDimension:L?{width:e,height:i}:null,coefs:L?P.coefficients:null,sampleSpacing:L?E:null,projectDirections:B,gcsGrid:B?P.gcsGrid:null,isUV:"vector-uv"===this.rasterInfo.dataType,interpolation:r.interpolation,alignmentInfo:z,blockWidths:null},r);({pixelBlock:M,localNorthDirections:J}=t)}else{const t=W(A,O,{alignmentInfo:z});M=L?_(t,{width:e,height:i},P.coefficients,E,r.interpolation):t,B&&P.gcsGrid&&(J=C({width:e,height:i},P.gcsGrid),M=G(M,this.rasterInfo.dataType,J))}return r.requestRawData||B?{srcExtent:f,pixelBlock:M,transformGrid:P,localNorthDirections:J,extent:t,isPartiallyFilled:q}:{srcExtent:f,extent:t,pixelBlock:M}}async _fetchRawTiles(t,e,i,r){const{origin:o,blockBoundary:s}=this.rasterInfo.storageInfo,{blockWidth:a,blockHeight:l}=this.getBlockWidthHeight(t);let{x:c,y:m}=e,{width:f,height:h,wrapCount:u}=i;const p=this._getRasterTileAlignmentInfo(t,0);r.buffer&&(c-=r.buffer.cols,m-=r.buffer.rows,f+=2*r.buffer.cols,h+=2*r.buffer.rows);let d=0,x=0,g=0;if(u&&n(p)){({worldColumnCountFromOrigin:x,originColumnOffset:g,rightPadding:d}=p);x*p.blockWidth-d>=c+f&&(d=0)}const y=Math.floor(c/a),I=Math.floor(m/l),R=Math.floor((c+f+d-1)/a),w=Math.floor((m+h+d-1)/l),k=s[t];if(!k)return null;const{minRow:b,minCol:S,maxCol:T,maxRow:v}=k;if(0===u&&(w<b||R<S||I>v||y>T))return null;const B=new Array;let P=!1;const M=null==this.ioConfig.allowPartialFill?r.allowPartialFill:this.ioConfig.allowPartialFill;for(let E=I;E<=w;E++)for(let e=y;e<=R;e++){let i=e;if(!r.disableWrapAround&&u&&n(p)&&x<=e&&(i=e-x-g),E>=b&&i>=S&&v>=E&&T>=i){const e=this._fetchRawTile(t,E,i,r);M?B.push(new Promise((t=>{e.then((e=>t(e))).catch((()=>{P=!0,t(null)}))}))):B.push(e)}else B.push(Promise.resolve(null))}if(0===B.length)return null;const W=await Promise.all(B),_={height:(w-I+1)*l,width:(R-y+1)*a},{spatialReference:C}=this.rasterInfo,j=this.getPyramidPixelSize(t),{x:H,y:L}=j;return{extent:new N({xmin:o.x+y*a*H,xmax:o.x+(R+1)*a*H,ymin:o.y-(w+1)*l*L,ymax:o.y-I*l*L,spatialReference:C}),pixelBlocks:W,mosaicSize:_,isPartiallyFilled:P}}_fetchRawTile(t,e,i,r){const o=this.rasterInfo.storageInfo.blockBoundary[t];if(!o)return Promise.resolve(null);const{minRow:n,minCol:s,maxCol:l,maxRow:c}=o;if(e<n||i<s||e>c||i>l)return Promise.resolve(null);const f=S(this.url,r.sliceId),h=`${t}/${e}/${i}`;let u=T(f,r.registryId,h);if(a(u)){const o=new AbortController;u=this.fetchRawTile(t,e,i,{...r,signal:o.signal}),v(f,r.registryId,h,u,o),u.catch((()=>B(f,r.registryId,h)))}return r.signal&&m(r,(()=>{P(f,r.registryId,h)})),u}_computeMagDirValues(t){const{bandCount:e,dataType:i}=this.rasterInfo;if(!(2===e&&"vector-magdir"===i||"vector-uv"===i)||2!==t?.length||!t[0]?.length)return null;const r=t[0].length;if("vector-magdir"===i){const e=t[1].map((t=>(t+360)%360));return[t[0],e]}const[o,n]=t,s=[],a=[];for(let l=0;l<r;l++){const[t,e]=J([o[l],n[l]]);s.push(t),a.push(e)}return[s,a]}_getRasterTileAlignmentInfo(t,e){return null==this._rasterTileAlighmentInfo&&(this._rasterTileAlighmentInfo=O(this.rasterInfo)),a(this._rasterTileAlighmentInfo.pyramidsInfo)?null:{startX:e,halfWorldWidth:this._rasterTileAlighmentInfo.halfWorldWidth,hasGCSSShiftTransform:this._rasterTileAlighmentInfo.hasGCSSShiftTransform,...this._rasterTileAlighmentInfo.pyramidsInfo[t]}}_getSourceDataInfo(t,e,i,r={}){const o={datumTransformation:r.datumTransformation,pyramidLevel:0,pyramidResolution:null,srcExtent:null,srcHeight:0,srcResolution:null,srcWidth:0};r.srcResolution&&(o.srcResolution=r.srcResolution,this._updateSourceDataInfo(t,o));const n=this.rasterInfo.storageInfo.maximumPyramidLevel||0,{srcWidth:s,srcHeight:a,pyramidLevel:l}=o,c=s/e,m=a/i,f=l<n&&c*m>=16,h=l===n&&this._requireTooManySrcTiles(s,a,e,i);if(f||h||(0===s||0===a)){const s=new V({x:(t.xmax-t.xmin)/e,y:(t.ymax-t.ymin)/i,spatialReference:t.spatialReference});let a=q(s,this.rasterInfo.spatialReference,t,o.datumTransformation);const h=!a||r.srcResolution&&a.x+a.y<r.srcResolution.x+r.srcResolution.y;if(f&&r.srcResolution&&h){const t=Math.round(Math.log(Math.max(c,m))/Math.LN2)-1;if(n-l+3>=t){const e=2**t;a={x:r.srcResolution.x*e,y:r.srcResolution.y*e}}}a&&(o.srcResolution=a,this._updateSourceDataInfo(t,o))}return this._requireTooManySrcTiles(o.srcWidth,o.srcHeight,e,i)&&(o.srcWidth=0,o.srcHeight=0),o}_requireTooManySrcTiles(t,e,i,r){const{tileInfo:o}=this.rasterInfo.storageInfo;return Math.ceil(t/o.size[0])*Math.ceil(e/o.size[1])>=U||t/i>$||e/r>$}_updateSourceDataInfo(t,e){e.srcWidth=0,e.srcHeight=0;const i=this.rasterInfo.spatialReference,{srcResolution:r,datumTransformation:o}=e,{pyramidLevel:n,pyramidResolution:a,excessiveReading:l}=E(r,this.rasterInfo,this.ioConfig.sampling);if(l)return;let c=e.srcExtent||A(t,i,o);if(null==c)return;const m=s(this.rasterInfo.transform);m&&(c=m.inverseTransform(c)),e.srcExtent=c;const f=Math.ceil((c.xmax-c.xmin)/a.x-.1),h=Math.ceil((c.ymax-c.ymin)/a.y-.1);e.pyramidLevel=n,e.pyramidResolution=a,e.srcWidth=f,e.srcHeight=h}_getRequestOptionsWithSliceId(t){return n(this.rasterInfo.multidimensionalInfo)&&null==t.sliceId&&(t={...t,sliceId:this.getSliceIndex(t.multidimensionalDefinition)}),t}_processIdentifyResult(t,e){const{srcLocation:i,position:r,pyramidLevel:o,useTransposedTile:n}=e,l=t.pixels[0].length/t.width/t.height;if(!(!t.mask||t.mask[r]))return{location:i,value:null};const{multidimensionalInfo:c}=this.rasterInfo;if(a(c)||!n){const e=t.pixels.map((t=>t[r])),n={location:i,value:e,pyramidLevel:o},s=this._computeMagDirValues(e.map((t=>[t])));return s?.length&&(n.magdirValue=s.map((t=>t[0]))),n}let m=t.pixels.map((t=>Array.prototype.slice.call(t,r*l,r*l+l))),f=this._computeMagDirValues(m);const{requestSomeSlices:h,identifyOptions:u}=e;let p=k(c,u.transposedVariableName);if(h){const t=b(p,s(u.multidimensionalDefinition),s(u.timeExtent));m=m.map((e=>t.map((t=>e[t])))),f=f?.map((e=>t.map((t=>e[t])))),p=t.map((t=>p[t]))}return{location:i,value:null,dataSeries:p.map(((t,e)=>{const i={value:m.map((t=>t[e])),multidimensionalDefinition:t.multidimensionalDefinition.map((t=>new x({...t,isSlice:!0})))};return f?.length&&(i.magdirValue=[f[0][e],f[1][e]]),i})),pyramidLevel:o}}};t([f()],X.prototype,"_rasterTileAlighmentInfo",void 0),t([f({readOnly:!0})],X.prototype,"_isGlobalWrappableSource",null),t([f(d)],X.prototype,"url",null),t([f({type:String,json:{write:!0}})],X.prototype,"datasetName",void 0),t([f({type:String,json:{write:!0}})],X.prototype,"datasetFormat",void 0),t([f()],X.prototype,"rasterInfo",void 0),t([f()],X.prototype,"ioConfig",void 0),t([f()],X.prototype,"sourceJSON",void 0),X=t([u("esri.layers.support.rasterDatasets.BaseRaster")],X);const K=X;export{K as default};
5
+ import{_ as e}from"../../../chunks/tslib.es6.js";import"../../../geometry.js";import t from"../../../request.js";import i from"../../../core/Error.js";import{JSONSupport as r}from"../../../core/JSONSupport.js";import o from"../../../core/Logger.js";import{isSome as n,unwrap as s,isNone as a,unwrapOrThrow as l}from"../../../core/maybe.js";import{EsriPromiseMixin as c}from"../../../core/Promise.js";import{onAbort as m}from"../../../core/promiseUtils.js";import{property as f}from"../../../core/accessorSupport/decorators/property.js";import{ensureClass as h}from"../../../core/accessorSupport/ensureType.js";import"../../../core/arrayUtils.js";import{subclass as u}from"../../../core/accessorSupport/decorators/subclass.js";import{sanitizeUrl as p}from"../arcgisLayerUrl.js";import{url as d}from"../commonProperties.js";import x from"../DimensionalDefinition.js";import g from"../LOD.js";import y from"../RasterStorageInfo.js";import I from"../TileInfo.js";import{isMultiSliceOrRangeDefinition as R,getSliceIndex as w,createSlices as k,getSliceIds as T}from"./multidimensionalUtils.js";import{getRasterId as b,getBlock as S,putBlock as v,deleteBlock as B,decreaseRefCount as P}from"./RawBlockCache.js";import{convertNoDataToMask as M}from"../rasterFormats/pixelRangeUtils.js";import{decode as W}from"../rasterFormats/RasterCodec.js";import{mosaic as _,approximateTransform as C,getLocalArithmeticNorthRotations as j}from"../rasterFunctions/pixelUtils.js";import{load as H,getWorldWidth as L,projectPoint as E,snapPyramid as D,snapExtent as z,getWorldWrapCount as A,projectExtent as F,getProjectionOffsetGrid as O,getRasterDatasetAlignmentInfo as q,projectResolution as G}from"../rasterFunctions/rasterProjectionHelper.js";import{convertToLocalDirections as J,uvComponentToVector as N}from"../rasterFunctions/vectorFieldUtils.js";import V from"../../../geometry/Extent.js";import U from"../../../geometry/Point.js";const $=8,X=256;let K=class extends(c(r)){constructor(){super(...arguments),this.rasterJobHandler=null,this.datasetName=null,this.datasetFormat=null,this.rasterInfo=null,this.ioConfig={sampling:"closest"}}async init(){const e=H();this.addResolvingPromise(e),await this.when()}normalizeCtorArgs(e){return e&&e.ioConfig&&(e={...e,ioConfig:{resolution:null,bandIds:null,sampling:"closest",tileInfo:I.create(),...e.ioConfig}}),e}get _isGlobalWrappableSource(){const{rasterInfo:e}=this,t=L(e.spatialReference);return n(t)&&e.extent.width>=t/2}set url(e){this._set("url",p(e,o.getLogger(this.declaredClass)))}async open(e){throw new i("BaseRaster:open-not-implemented","open() is not implemented")}async fetchTile(e,t,i,r={}){const o=r.tileInfo||this.rasterInfo.storageInfo.tileInfo,n=this.getTileExtentFromTileInfo(e,t,i,o);return this.fetchPixels(n,o.size[0],o.size[1],r)}async identify(e,t={}){e=h(U,e).clone().normalize();const{multidimensionalDefinition:i,timeExtent:r}=t,{hasMultidimensionalTranspose:o,multidimensionalInfo:l}=this.rasterInfo;let{transposedVariableName:c}=t;const m=n(l)&&o&&(null!=r||R(i));if(m&&!c){c=n(i)&&i.length>0?i[0].variableName??void 0:l.variables[0].name,t={...t,transposedVariableName:c}}t=this._getRequestOptionsWithSliceId(t);const{spatialReference:f,extent:u}=this.rasterInfo,{datumTransformation:p}=t;let d=E(e,f,p);if(!u.intersects(d))return{location:d,value:null};if(n(this.rasterInfo.transform)){const e=this.rasterInfo.transform.inverseTransform(d);if(!this.rasterInfo.nativeExtent.intersects(e))return{location:e,value:null};d=e}let x=0;const g=n(c)&&n(l)&&this.rasterInfo.hasMultidimensionalTranspose;if(!g)if(t.srcResolution){x=D(t.srcResolution,this.rasterInfo,this.ioConfig.sampling).pyramidLevel}else if(x=await this.computeBestPyramidLevelForLocation(e,t),null==x)return{location:d,value:null};const y=this.identifyPixelLocation(d,x,null,g);if(null===y)return{location:d,value:null};const{row:I,col:w,rowOffset:k,colOffset:T,blockWidth:B}=y,P=c??s(t.sliceId),M=b(this.url,P),W=`${x}/${I}/${w}`;let _=S(M,null,W);a(_)&&(_=this.fetchRawTile(x,I,w,t),v(M,null,W,_));const C=await _;if(a(C)||!C.pixels?.length)return{location:d,value:null};const j=k*B+T;return this._processIdentifyResult(C,{srcLocation:d,position:j,pyramidLevel:x,useTransposedTile:!!g,requestSomeSlices:m,identifyOptions:t})}async fetchPixels(e,t,i,r={}){if(e=z(e),(r=this._getRequestOptionsWithSliceId(r)).requestRawData)return this._fetchPixels(e,t,i,r);const o=L(e.spatialReference),n=A(e);if(a(o)||0===n||1===n&&this._isGlobalWrappableSource)return this._fetchPixels(e,t,i,r);if(n>=3)return{extent:e,pixelBlock:null};const s=[],{xmin:l,xmax:c}=e,m=Math.round(o/(c-l)*t),f=m-Math.round((o/2-l)/(c-l)*t);let h=0;const u=[];for(let a=0;a<=n;a++){const p=new V({xmin:0===a?l:-o/2,xmax:a===n?c-o*a:o/2,ymin:e.ymin,ymax:e.ymax,spatialReference:e.spatialReference}),d=0===a?m-f:a===n?t-h:m;h+=d,u.push(d);const x=r.disableWrapAround&&a>0?null:this._fetchPixels(p,d,i,r);s.push(x)}const p=(await Promise.all(s)).map((e=>e?.pixelBlock));let d=null;const x={width:t,height:i};if(this.rasterJobHandler){d=(await this.rasterJobHandler.mosaicAndTransform({srcPixelBlocks:p,srcMosaicSize:x,destDimension:null,coefs:null,sampleSpacing:null,interpolation:"nearest",alignmentInfo:null,blockWidths:u},r)).pixelBlock}else d=_(p,x,{blockWidths:u});return{extent:e,srcExtent:F(e,this.rasterInfo.spatialReference,r.datumTransformation),pixelBlock:d}}async fetchRawPixels(e,t,i,r={}){t={x:Math.floor(t.x),y:Math.floor(t.y)};const o=await this._fetchRawTiles(e,t,i,r),{nativeExtent:s,nativePixelSize:a,storageInfo:l}=this.rasterInfo,c=2**e,m=a.x*c,f=a.y*c,h=new V({xmin:s.xmin+m*t.x,xmax:s.xmin+m*(t.x+i.width-1),ymin:s.ymax-f*(t.y+i.height-1),ymax:s.ymax-f*t.y,spatialReference:s.spatialReference});if(!o)return{extent:h,srcExtent:h,pixelBlock:null};const{pixelBlocks:u,mosaicSize:p}=o;if(1===u.length&&n(u[0])&&u[0].width===i.width&&u[0].height===i.height)return{extent:h,srcExtent:h,pixelBlock:o.pixelBlocks[0]};const d=e>0?l.pyramidBlockWidth:l.blockWidth,x=e>0?l.pyramidBlockHeight:l.blockHeight,g={x:t.x%d,y:t.y%x};let y;if(this.rasterJobHandler){y=(await this.rasterJobHandler.mosaicAndTransform({srcPixelBlocks:u,srcMosaicSize:p,destDimension:i,clipOffset:g,clipSize:i,coefs:null,sampleSpacing:null,interpolation:r.interpolation,alignmentInfo:null,blockWidths:null},r)).pixelBlock}else y=_(u,p,{clipOffset:g,clipSize:i});return{extent:h,srcExtent:h,pixelBlock:y}}fetchRawTile(e,t,r,o){throw new i("BaseRaster:read-not-implemented","fetchRawTile() is not implemented")}computeExtent(e){return F(this.rasterInfo.extent,e)}decodePixelBlock(e,t){return!this.rasterJobHandler||t.useCanvas?W(e,t):this.rasterJobHandler.decode({data:e,options:t})}async request(e,i,r=0){const{customFetchParameters:o}=this.ioConfig,{range:n,query:s,headers:a}=i;r=r??i.retryCount??this.ioConfig.retryCount;const l=n?{Range:`bytes=${n.from}-${n.to}`}:null;try{return await t(e,{...i,query:{...s,...o},headers:{...a,...l}})}catch(c){if(r>0)return r--,this.request(e,i,r);throw c}}getSliceIndex(e){const{multidimensionalInfo:t}=this.rasterInfo;return a(t)||a(e)||0===e.length?null:w(e,t)}getTileExtentFromTileInfo(e,t,i,r){const o=l(r.lodAt(e));return this.getTileExtent({x:o.resolution,y:o.resolution},t,i,r.origin,r.spatialReference,r.size)}updateTileInfo(){const{storageInfo:e,spatialReference:t,extent:i,pixelSize:r}=this.rasterInfo;if(!e.tileInfo){const o=[],n=e.maximumPyramidLevel||0;let s=Math.max(r.x,r.y),a=1/.0254*96*s;for(let e=0;e<=n;e++)o.push(new g({level:n-e,resolution:s,scale:a})),s*=2,a*=2;const l=new U({x:i.xmin,y:i.ymax,spatialReference:t});e.tileInfo=new I({origin:l,size:[e.blockWidth,e.blockHeight],spatialReference:t,lods:o}),e.isVirtualTileInfo=!0}}createRemoteDatasetStorageInfo(e,t=512,i=512,r){const{width:o,height:n,nativeExtent:s,pixelSize:a,spatialReference:l}=e,c=new U({x:s.xmin,y:s.ymax,spatialReference:l});null==r&&(r=Math.max(0,Math.round(Math.log(Math.max(o,n))/Math.LN2-8)));const m=this.computeBlockBoundary(s,512,512,{x:s.xmin,y:s.ymax},[a],r);e.storageInfo=new y({blockWidth:t,blockHeight:i,pyramidBlockWidth:t,pyramidBlockHeight:i,origin:c,firstPyramidLevel:1,maximumPyramidLevel:r,blockBoundary:m})}async computeBestPyramidLevelForLocation(e,t={}){return 0}computeBlockBoundary(e,t,i,r,o,n=0,s=2){if(1===o.length&&n>0){o=[...o];let{x:e,y:t}=o[0];for(let i=0;i<n;i++)e*=s,t*=s,o.push({x:e,y:t})}const a=[],{x:l,y:c}=r;for(let m=0;m<o.length;m++){const{x:r,y:n}=o[m];a.push({minCol:Math.floor((e.xmin-l+.1*r)/t/r),maxCol:Math.floor((e.xmax-l-.1*r)/t/r),minRow:Math.floor((c-e.ymax+.1*n)/i/n),maxRow:Math.floor((c-e.ymin-.1*n)/i/n)})}return a}getPyramidPixelSize(e){const{nativePixelSize:t}=this.rasterInfo,{pyramidResolutions:i,pyramidScalingFactor:r}=this.rasterInfo.storageInfo;if(0===e)return t;if(n(i)&&i.length)return i[e-1];const o=r**e;return{x:t.x*o,y:t.y*o}}identifyPixelLocation(e,t,i,r){const{spatialReference:o,nativeExtent:s,storageInfo:a}=this.rasterInfo,{maximumPyramidLevel:l,origin:c,transposeInfo:m}=a,f=r&&n(m)?m.tileSize[0]:a.blockWidth,h=r&&n(m)?m.tileSize[1]:a.blockHeight,u=E(e,o,i);if(!s.intersects(u))return null;if(t<0||t>l)return null;const p=this.getPyramidPixelSize(t),{x:d,y:x}=p,g=(c.y-u.y)/x/h,y=(u.x-c.x)/d/f,I=Math.min(h-1,Math.floor((g-Math.floor(g))*h)),R=Math.min(f-1,Math.floor((y-Math.floor(y))*f));return{pyramidLevel:t,row:Math.floor(g),col:Math.floor(y),rowOffset:I,colOffset:R,blockWidth:f,srcLocation:u}}getTileExtent(e,t,i,r,o,n){const[s,a]=n,l=r.x+i*s*e.x,c=l+s*e.x,m=r.y-t*a*e.y,f=m-a*e.y;return new V({xmin:l,xmax:c,ymin:f,ymax:m,spatialReference:o})}getBlockWidthHeight(e){return{blockWidth:e>0?this.rasterInfo.storageInfo.pyramidBlockWidth:this.rasterInfo.storageInfo.blockWidth,blockHeight:e>0?this.rasterInfo.storageInfo.pyramidBlockHeight:this.rasterInfo.storageInfo.blockHeight}}isBlockOutside(e,t,i){const r=this.rasterInfo.storageInfo.blockBoundary[e];return!r||r.maxRow<t||r.maxCol<i||r.minRow>t||r.minCol>i}async _fetchPixels(e,t,i,r={}){let o=A(e);if(o>=2)return{extent:e,pixelBlock:null};const a=this._getSourceDataInfo(e,t,i,r),{pyramidLevel:l,pyramidResolution:c,srcResolution:m,srcExtent:f,srcWidth:h,srcHeight:u}=a;if(0===h||0===u)return{extent:e,srcExtent:f,pixelBlock:null};const p=s(this.rasterInfo.transform),d="gcs-shift"===p?.type,x=n(L(e.spatialReference));!d&&x||(o=A(a.srcExtent,d));const g=this.rasterInfo.storageInfo,y={x:Math.floor((f.xmin-g.origin.x)/c.x+.1),y:Math.floor((g.origin.y-f.ymax)/c.y+.1)},I=await this._fetchRawTiles(l,y,{width:h,height:u,wrapCount:o},r);if(!I)return{extent:e,srcExtent:f,pixelBlock:null};const R=l>0?g.pyramidBlockWidth:g.blockWidth,w=l>0?g.pyramidBlockHeight:g.blockHeight,k=R===h&&w===u&&y.x%R==0&&y.y%w==0,T=new U({x:(e.xmax-e.xmin)/t,y:(e.ymax-e.ymin)/i,spatialReference:e.spatialReference}),b=!e.spatialReference.equals(this.rasterInfo.spatialReference),{datumTransformation:S}=r;if(!b&&k&&1===I.pixelBlocks.length&&R===t&&w===i&&m.x===T.x&&m.y===T.y)return{extent:e,srcExtent:f,pixelBlock:I.pixelBlocks[0]};const v=x&&n(L(f.spatialReference)),B=r.requestProjectedLocalDirections&&this.rasterInfo.dataType.startsWith("vector");B&&!this.rasterJobHandler&&await H();const P=this.rasterJobHandler?await this.rasterJobHandler.getProjectionOffsetGrid({projectedExtent:e,srcBufferExtent:I.extent,pixelSize:T.toJSON(),datumTransformation:S,rasterTransform:p,hasWrapAround:o>0||v,isAdaptive:!1!==this.ioConfig.optimizeProjectionAccuracy,includeGCSGrid:B},r):O({projectedExtent:e,srcBufferExtent:I.extent,pixelSize:T,datumTransformation:S,rasterTransform:p,hasWrapAround:o>0||v,isAdaptive:!1,includeGCSGrid:B});let M;const W=!r.requestRawData,E={rows:P.spacing[0],cols:P.spacing[1]},D=s(this._getRasterTileAlignmentInfo(l,I.extent.xmin)),{pixelBlocks:z,mosaicSize:F,isPartiallyFilled:q}=I;let G=null;if(this.rasterJobHandler){const e=await this.rasterJobHandler.mosaicAndTransform({srcPixelBlocks:z,srcMosaicSize:F,destDimension:W?{width:t,height:i}:null,coefs:W?P.coefficients:null,sampleSpacing:W?E:null,projectDirections:B,gcsGrid:B?P.gcsGrid:null,isUV:"vector-uv"===this.rasterInfo.dataType,interpolation:r.interpolation,alignmentInfo:D,blockWidths:null},r);({pixelBlock:M,localNorthDirections:G}=e)}else{const e=_(z,F,{alignmentInfo:D});M=W?C(e,{width:t,height:i},P.coefficients,E,r.interpolation):e,B&&P.gcsGrid&&(G=j({width:t,height:i},P.gcsGrid),M=J(M,this.rasterInfo.dataType,G))}return r.requestRawData||B?{srcExtent:f,pixelBlock:M,transformGrid:P,localNorthDirections:G,extent:e,isPartiallyFilled:q}:{srcExtent:f,extent:e,pixelBlock:M}}async _fetchRawTiles(e,t,i,r){const{origin:o,blockBoundary:s}=this.rasterInfo.storageInfo,{blockWidth:a,blockHeight:l}=this.getBlockWidthHeight(e);let{x:c,y:m}=t,{width:f,height:h,wrapCount:u}=i;const p=this._getRasterTileAlignmentInfo(e,0);r.buffer&&(c-=r.buffer.cols,m-=r.buffer.rows,f+=2*r.buffer.cols,h+=2*r.buffer.rows);let d=0,x=0,g=0;if(u&&n(p)){({worldColumnCountFromOrigin:x,originColumnOffset:g,rightPadding:d}=p);x*p.blockWidth-d>=c+f&&(d=0)}const y=Math.floor(c/a),I=Math.floor(m/l),R=Math.floor((c+f+d-1)/a),w=Math.floor((m+h+d-1)/l),k=s[e];if(!k)return null;const{minRow:T,minCol:b,maxCol:S,maxRow:v}=k;if(0===u&&(w<T||R<b||I>v||y>S))return null;const B=new Array;let P=!1;const M=null==this.ioConfig.allowPartialFill?r.allowPartialFill:this.ioConfig.allowPartialFill;for(let E=I;E<=w;E++)for(let t=y;t<=R;t++){let i=t;if(!r.disableWrapAround&&u&&n(p)&&x<=t&&(i=t-x-g),E>=T&&i>=b&&v>=E&&S>=i){const t=this._fetchRawTile(e,E,i,r);M?B.push(new Promise((e=>{t.then((t=>e(t))).catch((()=>{P=!0,e(null)}))}))):B.push(t)}else B.push(Promise.resolve(null))}if(0===B.length)return null;const W=await Promise.all(B),_={height:(w-I+1)*l,width:(R-y+1)*a},{spatialReference:C}=this.rasterInfo,j=this.getPyramidPixelSize(e),{x:H,y:L}=j;return{extent:new V({xmin:o.x+y*a*H,xmax:o.x+(R+1)*a*H,ymin:o.y-(w+1)*l*L,ymax:o.y-I*l*L,spatialReference:C}),pixelBlocks:W,mosaicSize:_,isPartiallyFilled:P}}_fetchRawTile(e,t,i,r){const o=this.rasterInfo.storageInfo.blockBoundary[e];if(!o)return Promise.resolve(null);const{minRow:n,minCol:s,maxCol:l,maxRow:c}=o;if(t<n||i<s||t>c||i>l)return Promise.resolve(null);const f=b(this.url,r.sliceId),h=`${e}/${t}/${i}`;let u=S(f,r.registryId,h);if(a(u)){const o=new AbortController;u=this.fetchRawTile(e,t,i,{...r,signal:o.signal}),v(f,r.registryId,h,u,o),u.catch((()=>B(f,r.registryId,h)))}return r.signal&&m(r,(()=>{P(f,r.registryId,h)})),u}_computeMagDirValues(e){const{bandCount:t,dataType:i}=this.rasterInfo;if(!(2===t&&"vector-magdir"===i||"vector-uv"===i)||2!==e?.length||!e[0]?.length)return null;const r=e[0].length;if("vector-magdir"===i){const t=e[1].map((e=>(e+360)%360));return[e[0],t]}const[o,n]=e,s=[],a=[];for(let l=0;l<r;l++){const[e,t]=N([o[l],n[l]]);s.push(e),a.push(t)}return[s,a]}_getRasterTileAlignmentInfo(e,t){return null==this._rasterTileAlighmentInfo&&(this._rasterTileAlighmentInfo=q(this.rasterInfo)),a(this._rasterTileAlighmentInfo.pyramidsInfo)?null:{startX:t,halfWorldWidth:this._rasterTileAlighmentInfo.halfWorldWidth,hasGCSSShiftTransform:this._rasterTileAlighmentInfo.hasGCSSShiftTransform,...this._rasterTileAlighmentInfo.pyramidsInfo[e]}}_getSourceDataInfo(e,t,i,r={}){const o={datumTransformation:r.datumTransformation,pyramidLevel:0,pyramidResolution:null,srcExtent:null,srcHeight:0,srcResolution:null,srcWidth:0};r.srcResolution&&(o.srcResolution=r.srcResolution,this._updateSourceDataInfo(e,o));const n=this.rasterInfo.storageInfo.maximumPyramidLevel||0,{srcWidth:s,srcHeight:a,pyramidLevel:l}=o,c=s/t,m=a/i,f=l<n&&c*m>=16,h=l===n&&this._requireTooManySrcTiles(s,a,t,i);if(f||h||(0===s||0===a)){const s=new U({x:(e.xmax-e.xmin)/t,y:(e.ymax-e.ymin)/i,spatialReference:e.spatialReference});let a=G(s,this.rasterInfo.spatialReference,e,o.datumTransformation);const h=!a||r.srcResolution&&a.x+a.y<r.srcResolution.x+r.srcResolution.y;if(f&&r.srcResolution&&h){const e=Math.round(Math.log(Math.max(c,m))/Math.LN2)-1;if(n-l+3>=e){const t=2**e;a={x:r.srcResolution.x*t,y:r.srcResolution.y*t}}}a&&(o.srcResolution=a,this._updateSourceDataInfo(e,o))}return this._requireTooManySrcTiles(o.srcWidth,o.srcHeight,t,i)&&(o.srcWidth=0,o.srcHeight=0),o}_requireTooManySrcTiles(e,t,i,r){const{tileInfo:o}=this.rasterInfo.storageInfo;return Math.ceil(e/o.size[0])*Math.ceil(t/o.size[1])>=X||e/i>$||t/r>$}_updateSourceDataInfo(e,t){t.srcWidth=0,t.srcHeight=0;const i=this.rasterInfo.spatialReference,{srcResolution:r,datumTransformation:o}=t,{pyramidLevel:n,pyramidResolution:a,excessiveReading:l}=D(r,this.rasterInfo,this.ioConfig.sampling);if(l)return;let c=t.srcExtent||F(e,i,o);if(null==c)return;const m=s(this.rasterInfo.transform);m&&(c=m.inverseTransform(c)),t.srcExtent=c;const f=Math.ceil((c.xmax-c.xmin)/a.x-.1),h=Math.ceil((c.ymax-c.ymin)/a.y-.1);t.pyramidLevel=n,t.pyramidResolution=a,t.srcWidth=f,t.srcHeight=h}_getRequestOptionsWithSliceId(e){return n(this.rasterInfo.multidimensionalInfo)&&null==e.sliceId&&(e={...e,sliceId:this.getSliceIndex(e.multidimensionalDefinition)}),e}_processIdentifyResult(e,t){const{srcLocation:i,position:r,pyramidLevel:o,useTransposedTile:l}=t,c=e.pixels[0].length/e.width/e.height;if(!(!e.mask||e.mask[r]))return{location:i,value:null};const{multidimensionalInfo:m}=this.rasterInfo;if(a(m)||!l){const t=e.pixels.map((e=>e[r])),n={location:i,value:t,pyramidLevel:o},s=this._computeMagDirValues(t.map((e=>[e])));return s?.length&&(n.magdirValue=s.map((e=>e[0]))),n}let f=e.pixels.map((e=>e.slice(r*c,r*c+c))),h=this._computeMagDirValues(f);const{requestSomeSlices:u,identifyOptions:p}=t;let d=k(m,p.transposedVariableName);if(u){const e=T(d,s(p.multidimensionalDefinition),s(p.timeExtent));f=f.map((t=>e.map((e=>t[e])))),h=h?.map((t=>e.map((e=>t[e])))),d=e.map((e=>d[e]))}const g=e.noDataValues||this.rasterInfo.noDataValue,y={pixels:f,pixelType:e.pixelType};let I;n(g)&&(M(y,g),I=y.mask);return{location:i,value:null,dataSeries:d.map(((e,t)=>{const i={value:0===I?.[t]?null:f.map((e=>e[t])),multidimensionalDefinition:e.multidimensionalDefinition.map((e=>new x({...e,isSlice:!0})))};return h?.length&&(i.magdirValue=[h[0][t],h[1][t]]),i})),pyramidLevel:o}}};e([f()],K.prototype,"_rasterTileAlighmentInfo",void 0),e([f({readOnly:!0})],K.prototype,"_isGlobalWrappableSource",null),e([f(d)],K.prototype,"url",null),e([f({type:String,json:{write:!0}})],K.prototype,"datasetName",void 0),e([f({type:String,json:{write:!0}})],K.prototype,"datasetFormat",void 0),e([f()],K.prototype,"rasterInfo",void 0),e([f()],K.prototype,"ioConfig",void 0),e([f()],K.prototype,"sourceJSON",void 0),K=e([u("esri.layers.support.rasterDatasets.BaseRaster")],K);const Q=K;export{Q as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.26/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../chunks/tslib.es6.js";import"../../../geometry.js";import t from"../../../core/Error.js";import{isNone as i,assertIsSome as s,isSome as r,unwrap as a}from"../../../core/maybe.js";import{urlToObject as l}from"../../../core/urlUtils.js";import{property as o}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/accessorSupport/ensureType.js";import"../../../core/arrayUtils.js";import{subclass as n}from"../../../core/accessorSupport/decorators/subclass.js";import c from"../RasterInfo.js";import m from"../RasterStorageInfo.js";import{readServiceTileInfo as h}from"../serviceTileInfoProperty.js";import f from"../TileInfo.js";import{TilemapCache as p}from"../TilemapCache.js";import u from"./BaseRaster.js";import{setValidBoundary as y}from"../rasterFunctions/pixelUtils.js";import d from"../rasterTransforms/GCSShiftTransform.js";import{fetchServiceRasterInfo as x}from"../../../rest/imageService/fetchRasterInfo.js";import g from"../../../geometry/SpatialReference.js";import v from"../../../geometry/Point.js";import S from"../../../geometry/Extent.js";let I=class extends u{constructor(){super(...arguments),this._levelOffset=0,this._tilemapCache=null,this._slices=null,this.datasetFormat="RasterTileServer",this.tileType=null}async open(e){await this.init();const r=e&&e.signal,a=this.sourceJSON?{data:this.sourceJSON}:await this.request(this.url,{query:{f:"json"},signal:r});a.ssl&&(this.url=this.url.replace(/^http:/i,"https:"));const o=a.data;if(this.sourceJSON=o,!o)throw new t("imageserverraster:open","cannot initialize tiled image service, missing service info");if(!o.tileInfo)throw new t("imageserverraster:open","use ImageryLayer to open non-tiled image services");this._fixScaleInServiceInfo();const n=["jpg","jpeg","png","png8","png24","png32","mixed"];this.tileType=o.cacheType,null==this.tileType&&(n.includes(o.tileInfo.format.toLowerCase())?this.tileType="Map":"lerc"===o.tileInfo.format.toLowerCase()?this.tileType="Elevation":this.tileType="Raster"),this.datasetName=o.name?.slice(o.name.indexOf("/")+1)??"";const c=await this._fetchRasterInfo({signal:r});if(i(c))throw new t("image-server-raster:open","cannot initialize image service");const u="Map"===this.tileType?h(o.tileInfo,o):f.fromJSON(o.tileInfo);s(u);const[y,d]=this._computeMinMaxLOD(c,u),{extent:x,pixelSize:g}=c,v=.5/c.width*g.x,S=Math.max(g.x,g.y),{lods:I}=u;("Map"!==this.tileType&&0!==o.maxScale||Math.abs(g.x-g.y)>v||!I.some((e=>Math.abs(e.resolution-S)<v)))&&(g.x=g.y=y.resolution,c.width=Math.ceil((x.xmax-x.xmin)/g.x-.1),c.height=Math.ceil((x.ymax-x.ymin)/g.y-.1));const w=y.level-d.level,[j,T]=u.size,b=[];I.forEach((e=>{e.level>=d.level&&e.level<=y.level&&b.push({x:e.resolution,y:e.resolution})})),b.sort(((e,t)=>e.x-t.x));const _=this.computeBlockBoundary(x,j,T,u.origin,b,w),M=b.length>1?b.slice(1):null;let R;if(o.transposeInfo&&(R={tileSize:[o.transposeInfo.rows,o.transposeInfo.cols],packetSize:c.keyProperties?._yxs.PacketSize??0}),c.storageInfo=new m({blockWidth:u.size[0],blockHeight:u.size[1],pyramidBlockWidth:u.size[0],pyramidBlockHeight:u.size[1],pyramidResolutions:M,compression:u.format,origin:u.origin,firstPyramidLevel:1,maximumPyramidLevel:w,tileInfo:u,transposeInfo:R,blockBoundary:_}),this._fixGCSShift(c),this._set("rasterInfo",c),o.capabilities.toLowerCase().includes("tilemap")){const e={tileInfo:c.storageInfo.tileInfo,parsedUrl:l(this.url),url:this.url,tileServers:[],type:"tile"};this._tilemapCache=new p({layer:e})}}async fetchRawTile(e,t,i,s={}){const{storageInfo:a,extent:l}=this.rasterInfo,{transposeInfo:o}=a,n=r(o)&&!!s.transposedVariableName;if(this._slices&&!n&&null==s.sliceId)return null;const c=n?0:a.maximumPyramidLevel-e+this._levelOffset,m=`${this.url}/tile/${c}/${t}/${i}`,h=this._slices?n?{variable:s.transposedVariableName}:{sliceId:s.sliceId||0}:null,{data:f}=await this.request(m,{query:h,responseType:"array-buffer",signal:s.signal});if(!f)return null;const p=n?o.tileSize:a.tileInfo.size,u=await this.decodePixelBlock(f,{width:p[0],height:p[1],planes:null,pixelType:null,isPoint:"Elevation"===this.tileType,returnInterleaved:n});if(null==u)return null;const d=a.blockBoundary[e];if("jpg"!==a.compression||i>d.minCol&&i<d.maxCol&&t>d.minRow&&t<d.maxRow)return u;const{origin:x,blockWidth:g,blockHeight:v}=a,{x:S,y:I}=this.getPyramidPixelSize(e),w=Math.round((l.xmin-x.x)/S)%g,j=Math.round((l.xmax-x.x)/S)%g||g,T=Math.round((x.y-l.ymax)/I)%v,b=Math.round((x.y-l.ymin)/I)%v||v,_=i===d.minCol?w:0,M=t===d.minRow?T:0,R=i===d.maxCol?j:g,z=t===d.maxRow?b:v;return y(u,{x:_,y:M},{width:R-_,height:z-M}),u}getSliceIndex(e){if(!this._slices||i(e)||0===e.length)return null;const t=e;for(let i=0;i<this._slices.length;i++){const e=this._slices[i].multidimensionalDefinition;if(e.length===t.length&&!e.some((e=>{const i=t.find((t=>e.variableName===t.variableName&&t.dimensionName===e.dimensionName));if(!i)return!0;return(Array.isArray(e.values[0])?`${e.values[0][0]}-${e.values[0][1]}`:e.values[0])!==(Array.isArray(i.values[0])?`${i.values[0][0]}-${i.values[0][1]}`:i.values[0])})))return i}return null}async fetchVariableStatisticsHistograms(e,t){const i=this.request(this.url+"/statistics",{query:{variable:e,f:"json"},signal:t}).then((e=>e.data?.statistics)),s=this.request(this.url+"/histograms",{query:{variable:e,f:"json"},signal:t}).then((e=>e.data?.histograms)),r=await Promise.all([i,s]);return r[0]&&r[0].forEach((e=>{e.avg=e.mean,e.stddev=e.standardDeviation})),{statistics:r[0]||null,histograms:r[1]||null}}async computeBestPyramidLevelForLocation(e,t={}){if(!this._tilemapCache)return 0;let i=this.identifyPixelLocation(e,0,a(t.datumTransformation));if(null===i)return null;let s=0;const{maximumPyramidLevel:r}=this.rasterInfo.storageInfo;let l=r-s+this._levelOffset;const o=i.srcLocation;for(;l>=0;){try{if("available"===await this._tilemapCache.fetchAvailability(l,i.row,i.col,t))break}catch{}if(l--,s++,i=this.identifyPixelLocation(o,s,a(t.datumTransformation)),null===i)return null}return-1===l||null==i?null:s}async _fetchRasterInfo(e){const t=this.sourceJSON;if("Map"===this.tileType){const e=t.fullExtent||t.extent,i=Math.ceil((e.xmax-e.xmin)/t.pixelSizeX-.1),s=Math.ceil((e.ymax-e.ymin)/t.pixelSizeY-.1),r=g.fromJSON(t.spatialReference||e.spatialReference),a=new v({x:t.pixelSizeX,y:t.pixelSizeY,spatialReference:r});return new c({width:i,height:s,bandCount:3,extent:S.fromJSON(e),spatialReference:r,pixelSize:a,pixelType:"u8",statistics:null,keyProperties:{DataType:"processed"}})}const{signal:i}=e,s=x(this.url,this.sourceJSON,{signal:i,query:this.ioConfig.customFetchParameters}),r=t.hasMultidimensions?this.request(`${this.url}/slices`,{query:{f:"json"},signal:i}).then((e=>e.data&&e.data.slices)).catch((()=>null)):null,a=await Promise.all([s,r]);return this._slices=a[1],a[0]}_fixScaleInServiceInfo(){const{sourceJSON:e}=this;e.minScale&&e.minScale<0&&(e.minScale=0),e.maxScale&&e.maxScale<0&&(e.maxScale=0)}_fixGCSShift(e){const{extent:t,spatialReference:i}=e;t.xmin>-1&&t.xmax>181&&i?.wkid&&i.isGeographic&&(e.nativeExtent=e.extent,e.transform=new d,e.extent=e.transform.forwardTransform(t))}_computeMinMaxLOD(e,t){const{pixelSize:i}=e,s=.5/e.width*i.x,{lods:r}=t,a=t.lodAt(Math.max.apply(null,r.map((e=>e.level)))),l=t.lodAt(Math.min.apply(null,r.map((e=>e.level)))),{tileType:o}=this;if("Map"===o)return this._levelOffset=r[0].level,[a,l];if("Raster"===o){return[r.find((e=>e.resolution===i.x))??a,l]}const{minScale:n,maxScale:c}=this.sourceJSON;let m=a;c>0&&(m=r.find((e=>Math.abs(e.scale-c)<s)),m||(m=r.filter((e=>e.scale>c)).sort(((e,t)=>e.scale>t.scale?1:-1))[0]??a));let h=l;return n>0&&(h=r.find((e=>Math.abs(e.scale-n)<s))??l,this._levelOffset=h.level-l.level),[m,h]}};e([o({type:String,json:{write:!0}})],I.prototype,"datasetFormat",void 0),e([o()],I.prototype,"tileType",void 0),I=e([n("esri.layers.support.rasterDatasets.ImageServerRaster")],I);const w=I;export{w as default};
5
+ import{_ as e}from"../../../chunks/tslib.es6.js";import"../../../geometry.js";import t from"../../../core/Error.js";import{isNone as i,assertIsSome as s,isSome as r,unwrap as a}from"../../../core/maybe.js";import{urlToObject as l}from"../../../core/urlUtils.js";import{property as o}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/accessorSupport/ensureType.js";import"../../../core/arrayUtils.js";import{subclass as n}from"../../../core/accessorSupport/decorators/subclass.js";import c from"../RasterInfo.js";import m from"../RasterStorageInfo.js";import{readServiceTileInfo as h}from"../serviceTileInfoProperty.js";import f from"../TileInfo.js";import{TilemapCache as u}from"../TilemapCache.js";import p from"./BaseRaster.js";import{setValidBoundary as y}from"../rasterFunctions/pixelUtils.js";import d from"../rasterTransforms/GCSShiftTransform.js";import{fetchServiceRasterInfo as x}from"../../../rest/imageService/fetchRasterInfo.js";import g from"../../../geometry/SpatialReference.js";import v from"../../../geometry/Point.js";import S from"../../../geometry/Extent.js";let I=class extends p{constructor(){super(...arguments),this._levelOffset=0,this._tilemapCache=null,this._slices=null,this.datasetFormat="RasterTileServer",this.tileType=null}async open(e){await this.init();const r=e&&e.signal,a=this.sourceJSON?{data:this.sourceJSON}:await this.request(this.url,{query:{f:"json"},signal:r});a.ssl&&(this.url=this.url.replace(/^http:/i,"https:"));const o=a.data;if(this.sourceJSON=o,!o)throw new t("imageserverraster:open","cannot initialize tiled image service, missing service info");if(!o.tileInfo)throw new t("imageserverraster:open","use ImageryLayer to open non-tiled image services");this._fixScaleInServiceInfo();const n=["jpg","jpeg","png","png8","png24","png32","mixed"];this.tileType=o.cacheType,null==this.tileType&&(n.includes(o.tileInfo.format.toLowerCase())?this.tileType="Map":"lerc"===o.tileInfo.format.toLowerCase()?this.tileType="Elevation":this.tileType="Raster"),this.datasetName=o.name?.slice(o.name.indexOf("/")+1)??"";const c=await this._fetchRasterInfo({signal:r});if(i(c))throw new t("image-server-raster:open","cannot initialize image service");const p="Map"===this.tileType?h(o.tileInfo,o):f.fromJSON(o.tileInfo);s(p);const[y,d]=this._computeMinMaxLOD(c,p),{extent:x,pixelSize:g}=c,v=.5/c.width*g.x,S=Math.max(g.x,g.y),{lods:I}=p;("Map"!==this.tileType&&0!==o.maxScale||Math.abs(g.x-g.y)>v||!I.some((e=>Math.abs(e.resolution-S)<v)))&&(g.x=g.y=y.resolution,c.width=Math.ceil((x.xmax-x.xmin)/g.x-.1),c.height=Math.ceil((x.ymax-x.ymin)/g.y-.1));const w=y.level-d.level,[j,T]=p.size,b=[];I.forEach((e=>{e.level>=d.level&&e.level<=y.level&&b.push({x:e.resolution,y:e.resolution})})),b.sort(((e,t)=>e.x-t.x));const _=this.computeBlockBoundary(x,j,T,p.origin,b,w),M=b.length>1?b.slice(1):null;let R;if(o.transposeInfo&&(R={tileSize:[o.transposeInfo.rows,o.transposeInfo.cols],packetSize:c.keyProperties?._yxs.PacketSize??0}),c.storageInfo=new m({blockWidth:p.size[0],blockHeight:p.size[1],pyramidBlockWidth:p.size[0],pyramidBlockHeight:p.size[1],pyramidResolutions:M,compression:p.format,origin:p.origin,firstPyramidLevel:1,maximumPyramidLevel:w,tileInfo:p,transposeInfo:R,blockBoundary:_}),this._fixGCSShift(c),this._set("rasterInfo",c),o.capabilities.toLowerCase().includes("tilemap")){const e={tileInfo:c.storageInfo.tileInfo,parsedUrl:l(this.url),url:this.url,tileServers:[],type:"tile"};this._tilemapCache=new u({layer:e})}}async fetchRawTile(e,t,i,s={}){const{storageInfo:l,extent:o}=this.rasterInfo,{transposeInfo:n}=l,c=r(n)&&!!s.transposedVariableName;if(this._slices&&!c&&null==s.sliceId)return null;const m=c?0:l.maximumPyramidLevel-e+this._levelOffset,h=`${this.url}/tile/${m}/${t}/${i}`,f=this._slices?c?{variable:s.transposedVariableName}:{sliceId:s.sliceId||0}:null,{data:u}=await this.request(h,{query:f,responseType:"array-buffer",signal:s.signal});if(!u)return null;const p=c?n.tileSize:l.tileInfo.size,d=await this.decodePixelBlock(u,{width:p[0],height:p[1],planes:null,pixelType:null,isPoint:"Elevation"===this.tileType,returnInterleaved:c,noDataValue:a(this.rasterInfo.noDataValue)});if(null==d)return null;const x=l.blockBoundary[e];if("jpg"!==l.compression||i>x.minCol&&i<x.maxCol&&t>x.minRow&&t<x.maxRow)return d;const{origin:g,blockWidth:v,blockHeight:S}=l,{x:I,y:w}=this.getPyramidPixelSize(e),j=Math.round((o.xmin-g.x)/I)%v,T=Math.round((o.xmax-g.x)/I)%v||v,b=Math.round((g.y-o.ymax)/w)%S,_=Math.round((g.y-o.ymin)/w)%S||S,M=i===x.minCol?j:0,R=t===x.minRow?b:0,z=i===x.maxCol?T:v,P=t===x.maxRow?_:S;return y(d,{x:M,y:R},{width:z-M,height:P-R}),d}getSliceIndex(e){if(!this._slices||i(e)||0===e.length)return null;const t=e;for(let i=0;i<this._slices.length;i++){const e=this._slices[i].multidimensionalDefinition;if(e.length===t.length&&!e.some((e=>{const i=t.find((t=>e.variableName===t.variableName&&t.dimensionName===e.dimensionName));if(!i)return!0;return(Array.isArray(e.values[0])?`${e.values[0][0]}-${e.values[0][1]}`:e.values[0])!==(Array.isArray(i.values[0])?`${i.values[0][0]}-${i.values[0][1]}`:i.values[0])})))return i}return null}async fetchVariableStatisticsHistograms(e,t){const i=this.request(this.url+"/statistics",{query:{variable:e,f:"json"},signal:t}).then((e=>e.data?.statistics)),s=this.request(this.url+"/histograms",{query:{variable:e,f:"json"},signal:t}).then((e=>e.data?.histograms)),r=await Promise.all([i,s]);return r[0]&&r[0].forEach((e=>{e.avg=e.mean,e.stddev=e.standardDeviation})),{statistics:r[0]||null,histograms:r[1]||null}}async computeBestPyramidLevelForLocation(e,t={}){if(!this._tilemapCache)return 0;let i=this.identifyPixelLocation(e,0,a(t.datumTransformation));if(null===i)return null;let s=0;const{maximumPyramidLevel:r}=this.rasterInfo.storageInfo;let l=r-s+this._levelOffset;const o=i.srcLocation;for(;l>=0;){try{if("available"===await this._tilemapCache.fetchAvailability(l,i.row,i.col,t))break}catch{}if(l--,s++,i=this.identifyPixelLocation(o,s,a(t.datumTransformation)),null===i)return null}return-1===l||null==i?null:s}async _fetchRasterInfo(e){const t=this.sourceJSON;if("Map"===this.tileType){const e=t.fullExtent||t.extent,i=Math.ceil((e.xmax-e.xmin)/t.pixelSizeX-.1),s=Math.ceil((e.ymax-e.ymin)/t.pixelSizeY-.1),r=g.fromJSON(t.spatialReference||e.spatialReference),a=new v({x:t.pixelSizeX,y:t.pixelSizeY,spatialReference:r});return new c({width:i,height:s,bandCount:3,extent:S.fromJSON(e),spatialReference:r,pixelSize:a,pixelType:"u8",statistics:null,keyProperties:{DataType:"processed"}})}const{signal:i}=e,s=x(this.url,this.sourceJSON,{signal:i,query:this.ioConfig.customFetchParameters}),r=t.hasMultidimensions?this.request(`${this.url}/slices`,{query:{f:"json"},signal:i}).then((e=>e.data&&e.data.slices)).catch((()=>null)):null,a=await Promise.all([s,r]);return this._slices=a[1],a[0]}_fixScaleInServiceInfo(){const{sourceJSON:e}=this;e.minScale&&e.minScale<0&&(e.minScale=0),e.maxScale&&e.maxScale<0&&(e.maxScale=0)}_fixGCSShift(e){const{extent:t,spatialReference:i}=e;t.xmin>-1&&t.xmax>181&&i?.wkid&&i.isGeographic&&(e.nativeExtent=e.extent,e.transform=new d,e.extent=e.transform.forwardTransform(t))}_computeMinMaxLOD(e,t){const{pixelSize:i}=e,s=.5/e.width*i.x,{lods:r}=t,a=t.lodAt(Math.max.apply(null,r.map((e=>e.level)))),l=t.lodAt(Math.min.apply(null,r.map((e=>e.level)))),{tileType:o}=this;if("Map"===o)return this._levelOffset=r[0].level,[a,l];if("Raster"===o){return[r.find((e=>e.resolution===i.x))??a,l]}const{minScale:n,maxScale:c}=this.sourceJSON;let m=a;c>0&&(m=r.find((e=>Math.abs(e.scale-c)<s)),m||(m=r.filter((e=>e.scale>c)).sort(((e,t)=>e.scale>t.scale?1:-1))[0]??a));let h=l;return n>0&&(h=r.find((e=>Math.abs(e.scale-n)<s))??l,this._levelOffset=h.level-l.level),[m,h]}};e([o({type:String,json:{write:!0}})],I.prototype,"datasetFormat",void 0),e([o()],I.prototype,"tileType",void 0),I=e([n("esri.layers.support.rasterDatasets.ImageServerRaster")],I);const w=I;export{w as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.26/esri/copyright.txt for details.
4
4
  */
5
- import{isSome as e,isNone as n}from"../../../core/maybe.js";import t from"../DimensionalDefinition.js";function a(e,n,t){const i=n.shift();if(0===t.length){const e=[];t.push({sliceId:-1,multidimensionalDefinition:e})}const r=t.length;for(let a=0;a<r;a++){const n=t.shift().multidimensionalDefinition;i.values?.forEach((a=>{t.push({sliceId:-1,multidimensionalDefinition:[...n,{variableName:e,dimensionName:i.name,values:[a]}]})}))}n.length&&a(e,n,t)}function i(e,n){const t=[];let i=0;return(n?e.variables.filter((e=>e.name.toLowerCase()===n.toLowerCase())):[...e.variables].sort(((e,n)=>e.name>n.name?1:-1))).forEach((e=>{const n=[],r=[...e.dimensions].sort(((e,n)=>e.name>n.name?-1:1));a(e.name,r,n),n.forEach((e=>{t.push({...e,sliceId:i++})}))})),t}function r(n,t,a){let i=n;if(t&&(t=[...t].sort(((e,n)=>e.dimensionName<n.dimensionName?-1:1))).forEach((({dimensionName:e,values:n,isSlice:t})=>{n.length&&(i=i.filter((a=>{const i=a.multidimensionalDefinition.find((n=>n.dimensionName===e));if(null==i)return!1;const r=i.values[0];return"number"==typeof r?"number"==typeof n[0]?n.includes(r):n.some((e=>e[0]<=r&&e[1]>=r)):"number"==typeof n[0]?n.some((e=>r[0]<=e&&r[1]>=e)):t?n.some((e=>e[0]===r[0]&&e[0]===r[1])):n.some((e=>e[0]>=r[0]&&e[0]<=r[1]||e[1]>=r[0]&&e[1]<=r[1]||e[0]<r[0]&&e[1]>r[1]))})))})),i.length&&a&&e(a.start)&&e(a.end)){const e=a.start.getTime(),n=a.end.getTime(),t=i[0].multidimensionalDefinition.findIndex((e=>"StdTime"===e.dimensionName));t>-1&&(i=i.filter((a=>{const i=a.multidimensionalDefinition[t].values[0];return e<=i&&n>=i})))}return i.map((e=>e.sliceId))}function s(e,n){return Array.isArray(e)?n[0]===n[1]?e[0]===n[0]||e[1]===n[0]:e[0]>=n[0]&&e[0]<=n[1]&&e[1]>=n[0]&&e[1]<=n[1]:e>=n[0]&&e<=n[1]}function l(e,n){return e[0]<=n[0]&&e[1]>=n[0]||e[0]<=n[1]&&e[1]>=n[1]||e[0]>=n[0]&&e[1]<=n[1]}function o(e){return 1===e.length?[e[0],e[0]]:[e[0],e[e.length-1]]}function u(e,n,t){if(!n?.subsetDefinitions?.length)return e;let a;if(t){const{variables:i}=n;if(i.length&&!i.includes(t))return null;const r=n.subsetDefinitions.find((n=>n.dimensionName===e.name&&n.variableName===t));if(!r?.values?.length)return e;a=o(r.values)}else{a=n.dimensions.find((({name:n})=>n===e.name))?.extent}const i=a;if(!i||!i?.length)return e;const r=e.values.filter((e=>s(e,i)));return{...e,extent:[...i],values:r}}function m(e,n,t){if(!n?.subsetDefinitions?.length)return!1;const{variables:a}=n;if(a.length&&e.some((({variableName:e})=>e&&!a.includes(e))))return!0;for(let i=0;i<e.length;i++){const a=e[i],r=n.subsetDefinitions.find((e=>(""===a.variableName||e.variableName===a.variableName)&&e.dimensionName===a.dimensionName));if(r?.values.length){const e=o(r.values);if(!a.isSlice&&2===a.values.length&&!Array.isArray(a.values[0])&&a.values[0]!==a.values[1]&&t){if(!l(a.values,e))return!0}else if(a.values.some((n=>!s(n,e))))return!0}}return!1}function c(t,a={}){const{multidimensionalInfo:i,keyProperties:r}=t;if(n(i))return null;const{variableName:s,multidimensionalSubset:l,multidimensionalDefinition:o}=a,u=e(o)?o[0]?.variableName:null,m=s||u||r?.DefaultVariable;let{variables:c}=i;l?.variables?.length&&(c=c.filter((({name:e})=>l.variables.includes(e))));return m?c.find((({name:e})=>e===m))??c[0]:c[0]}function f(e,n={}){const a=c(e,n);if(!a)return null;const i=[],{dimensions:r,name:s}=a;if(0===r.length)return[new t({variableName:s,dimensionName:"",values:[],isSlice:!0})];for(let l=0;l<r.length;l++){const e=u(r[l],n.multidimensionalSubset,s);if(!e)return null;const{values:a,extent:o}=e;let m=a?.[0]??o[0];"stdz"===e.name.toLowerCase()&&!e.hasRanges&&Math.abs(o[1])<=Math.abs(o[0])&&(m=a?.length?a[a.length-1]:o[1]),i.push(new t({variableName:s,dimensionName:e.name,values:[m],isSlice:!n.useRangeForRangedDimensionInfo||!!e.hasRanges}))}return i}function d(e){return!(n(e)||!e.length)&&e.some((e=>{if(null==e.values)return!0;const n=e.values.length;return 0===n||n>1||!e.isSlice&&Array.isArray(e.values[0])}))}function h(t,a){if(n(a)||n(t))return null;let i=a.variables.map((e=>({...e})));return t?.variables?.length&&(i=i.filter((({name:e})=>t.variables.includes(e))),i.forEach((n=>{n.dimensions=n.dimensions.map((e=>u(e,t,n.name))).filter(e)}))),i}function v(e,n){const{values:t}=n;if(t?.length)return Array.isArray(t[0])!==Array.isArray(e)?-1:Array.isArray(t[0])?t.findIndex((n=>n[0]===e[0]&&n[1]===e[1])):t.indexOf(e);const{extent:a}=n;if(Array.isArray(e)||e<a[0]||e>a[1])return-1;const i=n.interval||1;if("ISO8601"!==n.unit)return Math.round((e-a[0])/i);const r=a[0];let s=-1;switch(n.intervalUnit?.toLowerCase()||"seconds"){case"seconds":s=Math.round((e-r)/1e3/i);break;case"minutes":s=Math.round((e-r)/6e4/i);break;case"hours":s=Math.round((e-r)/36e5/i);break;case"days":s=Math.round((e-r)/864e5/i);break;case"months":{const n=new Date(e).getUTCFullYear()-new Date(r).getUTCFullYear(),t=new Date(r).getUTCMonth(),a=new Date(e).getUTCMonth();s=0===n?a-t:a+11-t+12*(n-1)}break;case"years":s=Math.round((new Date(e).getUTCFullYear()-new Date(r).getUTCFullYear())/i);break;case"decades":s=Math.round((new Date(e).getUTCFullYear()-new Date(r).getUTCFullYear())/10/i)}return s}function g(e){let n=e.values?.length;if(n)return n;const{extent:t,unit:a}=e,i=e.interval||1,r=t?t[1]-t[0]:0;if("ISO8601"!==a)return Math.round(r/i);switch(e.intervalUnit?.toLowerCase()??"seconds"){case"seconds":n=Math.round(r/1e3/i);break;case"minutes":n=Math.round(r/6e4/i);break;case"hours":n=Math.round(r/36e5/i);break;case"days":n=Math.round(r/864e5/i);break;case"months":{const e=new Date(t[1]).getUTCFullYear()-new Date(t[0]).getUTCFullYear(),a=new Date(t[1][0]).getUTCMonth(),i=new Date(t[1][1]).getUTCMonth();n=0===e?i-a+1:i+11-a+12*(e-1)+1}break;case"years":n=Math.round((new Date(t[1]).getUTCFullYear()-new Date(t[0]).getUTCFullYear())/i);break;case"decades":n=Math.round((new Date(t[1]).getUTCFullYear()-new Date(t[0]).getUTCFullYear())/10/i);break;default:n=0}return n}function b(e,n){let t=0;const a=e[0].variableName,i=[...n.variables].sort(((e,n)=>e.name>n.name?1:-1));for(let r=0;r<i.length;r++){const n=i[r],s=[...n.dimensions].sort(((e,n)=>e.name>n.name?-1:1));if(n.name!==a){t+=s.map((e=>g(e))).reduce(((e,n)=>e*n));continue}const l=s.map((e=>g(e))),o=s.length;for(let a=0;a<o;a++){const n=e.find((e=>e.dimensionName===s[a].name));if(null==n)return null;const i=v(n.values[0],s[a]);if(-1===i)return null;l.shift(),t+=a===o-1?i:i*l.reduce(((e,n)=>e*n))}break}return t}export{i as createSlices,f as getDefaultMultidimensionalDefinition,c as getDefaultVariablInfo,r as getSliceIds,b as getSliceIndex,h as getSubsetVariablesFromMdInfo,m as hasExcludedVariableOrDimension,d as isMultiSliceOrRangeDefinition};
5
+ import{isSome as e,isNone as n}from"../../../core/maybe.js";import t from"../DimensionalDefinition.js";function i(e,n,t){const a=n.shift();if(0===t.length){const e=[];t.push({sliceId:-1,multidimensionalDefinition:e})}const s=t.length;for(let i=0;i<s;i++){const n=t.shift().multidimensionalDefinition;a.values?.forEach((i=>{t.push({sliceId:-1,multidimensionalDefinition:[...n,{variableName:e,dimensionName:a.name,values:[i]}]})}))}n.length&&i(e,n,t)}function a(e,n){const t=[];let a=0;return(n?e.variables.filter((e=>e.name.toLowerCase()===n.toLowerCase())):[...e.variables].sort(((e,n)=>e.name>n.name?1:-1))).forEach((e=>{const n=[],s=[...e.dimensions].sort(((e,n)=>e.name>n.name?-1:1));i(e.name,s,n),n.forEach((e=>{t.push({...e,sliceId:a++})}))})),t}function s(n,t,i){let a=n;if(t&&(t=[...t].sort(((e,n)=>e.dimensionName<n.dimensionName?-1:1))).forEach((({dimensionName:e,values:n,isSlice:t})=>{n.length&&(a=a.filter((i=>{const a=i.multidimensionalDefinition.find((n=>n.dimensionName===e));if(null==a)return!1;const s=a.values[0];return"number"==typeof s?"number"==typeof n[0]?n.includes(s):n.some((e=>e[0]<=s&&e[1]>=s)):"number"==typeof n[0]?n.some((e=>s[0]<=e&&s[1]>=e)):t?n.some((e=>e[0]===s[0]&&e[0]===s[1])):n.some((e=>e[0]>=s[0]&&e[0]<=s[1]||e[1]>=s[0]&&e[1]<=s[1]||e[0]<s[0]&&e[1]>s[1]))})))})),a.length&&i&&e(i.start)&&e(i.end)){const e=i.start.getTime(),n=i.end.getTime(),t=a[0].multidimensionalDefinition.findIndex((e=>"StdTime"===e.dimensionName));t>-1&&(a=a.filter((i=>{const a=i.multidimensionalDefinition[t].values[0];return e<=a&&n>=a})))}return a.map((e=>e.sliceId))}function r(e,n){return Array.isArray(e)?n[0]===n[1]?e[0]===n[0]||e[1]===n[0]:e[0]>=n[0]&&e[0]<=n[1]&&e[1]>=n[0]&&e[1]<=n[1]:e>=n[0]&&e<=n[1]}function l(e,n){return e[0]<=n[0]&&e[1]>=n[0]||e[0]<=n[1]&&e[1]>=n[1]||e[0]>=n[0]&&e[1]<=n[1]}function o(e){return 1===e.length?[e[0],e[0]]:[e[0],e[e.length-1]]}function u(e,n,t){if(!n?.subsetDefinitions?.length)return e;let i;if(t){const{variables:a}=n;if(a.length&&!a.includes(t))return null;const s=n.subsetDefinitions.find((n=>n.dimensionName===e.name&&n.variableName===t));if(!s?.values?.length)return e;i=o(s.values)}else{i=n.dimensions.find((({name:n})=>n===e.name))?.extent}const a=i;if(!a||!a?.length)return e;const s=e.values.filter((e=>r(e,a)));return{...e,extent:[...a],values:s}}function m(e,n,t){if(!n?.subsetDefinitions?.length)return!1;const{variables:i}=n;if(i.length&&e.some((({variableName:e})=>e&&!i.includes(e))))return!0;for(let a=0;a<e.length;a++){const i=e[a],s=n.subsetDefinitions.find((e=>(""===i.variableName||e.variableName===i.variableName)&&e.dimensionName===i.dimensionName));if(s?.values.length){const e=o(s.values);if(!i.isSlice&&2===i.values.length&&!Array.isArray(i.values[0])&&i.values[0]!==i.values[1]&&t){if(!l(i.values,e))return!0}else if(i.values.some((n=>!r(n,e))))return!0}}return!1}function c(t,i){if(n(t))return{isOutside:!1};const{geometry:a,timeExtent:s,multidimensionalDefinition:r}=i;let l=null;if(e(s)&&(l=f(t,s),n(l)))return{isOutside:!0};const{areaOfInterest:o}=t;if(o&&a){const e="point"===a.type?a:"extent"===a.type?a.center:"polygon"===a.type?a.centroid:null;if(e&&!o.contains(e))return{isOutside:!0}}return e(r)&&r.length&&m(r,t,!0)?{isOutside:!0}:{isOutside:!1,intersection:{geometry:a,timeExtent:l,multidimensionalDefinition:r}}}function f(e,i){const a=e.dimensions.find((({name:e})=>"StdTime"===e));if(null==a||n(i.start)&&n(i.end))return i;i=i.clone();const{start:s,end:r}=i.toJSON(),l=s===r?[s]:null!=s&&null!=r?[s,r]:[s??r];if(2===l.length&&a?.extent.length&&(l[0]=Math.max(l[0],a.extent[0]),l[1]=Math.min(l[1],a.extent[1]??a.extent[0]),l[1]<l[0]))return null;return m([new t({variableName:"",dimensionName:"StdTime",isSlice:1===l.length,values:l})],e,!0)?null:(i.start=new Date(l[0]),i.end=new Date(l[1]??l[0]),i)}function d(t,i={}){const{multidimensionalInfo:a,keyProperties:s}=t;if(n(a))return null;const{variableName:r,multidimensionalSubset:l,multidimensionalDefinition:o}=i,u=e(o)?o[0]?.variableName:null,m=r||u||s?.DefaultVariable;let{variables:c}=a;l?.variables?.length&&(c=c.filter((({name:e})=>l.variables.includes(e))));return m?c.find((({name:e})=>e===m))??c[0]:c[0]}function h(e,n={}){const i=d(e,n);if(!i)return null;const a=[],{dimensions:s,name:r}=i;if(0===s.length)return[new t({variableName:r,dimensionName:"",values:[],isSlice:!0})];for(let l=0;l<s.length;l++){const e=u(s[l],n.multidimensionalSubset,r);if(!e)return null;const{values:i,extent:o}=e;let m=i?.[0]??o[0];"stdz"===e.name.toLowerCase()&&!e.hasRanges&&Math.abs(o[1])<=Math.abs(o[0])&&(m=i?.length?i[i.length-1]:o[1]),a.push(new t({variableName:r,dimensionName:e.name,values:[m],isSlice:!n.useRangeForRangedDimensionInfo||!!e.hasRanges}))}return a}function g(e){return!(n(e)||!e.length)&&e.some((e=>{if(null==e.values)return!0;const n=e.values.length;return 0===n||n>1||!e.isSlice&&Array.isArray(e.values[0])}))}function v(t,i){if(n(i)||n(t))return null;let a=i.variables.map((e=>({...e})));return t?.variables?.length&&(a=a.filter((({name:e})=>t.variables.includes(e))),a.forEach((n=>{n.dimensions=n.dimensions.map((e=>u(e,t,n.name))).filter(e)}))),a}function b(e,n){const{values:t}=n;if(t?.length)return Array.isArray(t[0])!==Array.isArray(e)?-1:Array.isArray(t[0])?t.findIndex((n=>n[0]===e[0]&&n[1]===e[1])):t.indexOf(e);const{extent:i}=n;if(Array.isArray(e)||e<i[0]||e>i[1])return-1;const a=n.interval||1;if("ISO8601"!==n.unit)return Math.round((e-i[0])/a);const s=i[0];let r=-1;switch(n.intervalUnit?.toLowerCase()||"seconds"){case"seconds":r=Math.round((e-s)/1e3/a);break;case"minutes":r=Math.round((e-s)/6e4/a);break;case"hours":r=Math.round((e-s)/36e5/a);break;case"days":r=Math.round((e-s)/864e5/a);break;case"months":{const n=new Date(e).getUTCFullYear()-new Date(s).getUTCFullYear(),t=new Date(s).getUTCMonth(),i=new Date(e).getUTCMonth();r=0===n?i-t:i+11-t+12*(n-1)}break;case"years":r=Math.round((new Date(e).getUTCFullYear()-new Date(s).getUTCFullYear())/a);break;case"decades":r=Math.round((new Date(e).getUTCFullYear()-new Date(s).getUTCFullYear())/10/a)}return r}function D(e){let n=e.values?.length;if(n)return n;const{extent:t,unit:i}=e,a=e.interval||1,s=t?t[1]-t[0]:0;if("ISO8601"!==i)return Math.round(s/a);switch(e.intervalUnit?.toLowerCase()??"seconds"){case"seconds":n=Math.round(s/1e3/a);break;case"minutes":n=Math.round(s/6e4/a);break;case"hours":n=Math.round(s/36e5/a);break;case"days":n=Math.round(s/864e5/a);break;case"months":{const e=new Date(t[1]).getUTCFullYear()-new Date(t[0]).getUTCFullYear(),i=new Date(t[1][0]).getUTCMonth(),a=new Date(t[1][1]).getUTCMonth();n=0===e?a-i+1:a+11-i+12*(e-1)+1}break;case"years":n=Math.round((new Date(t[1]).getUTCFullYear()-new Date(t[0]).getUTCFullYear())/a);break;case"decades":n=Math.round((new Date(t[1]).getUTCFullYear()-new Date(t[0]).getUTCFullYear())/10/a);break;default:n=0}return n}function y(e,n){let t=0;const i=e[0].variableName,a=[...n.variables].sort(((e,n)=>e.name>n.name?1:-1));for(let s=0;s<a.length;s++){const n=a[s],r=[...n.dimensions].sort(((e,n)=>e.name>n.name?-1:1));if(n.name!==i){t+=r.map((e=>D(e))).reduce(((e,n)=>e*n));continue}const l=r.map((e=>D(e))),o=r.length;for(let i=0;i<o;i++){const n=e.find((e=>e.dimensionName===r[i].name));if(null==n)return null;const a=b(n.values[0],r[i]);if(-1===a)return null;l.shift(),t+=i===o-1?a:a*l.reduce(((e,n)=>e*n))}break}return t}export{a as createSlices,h as getDefaultMultidimensionalDefinition,d as getDefaultVariablInfo,s as getSliceIds,y as getSliceIndex,v as getSubsetVariablesFromMdInfo,m as hasExcludedVariableOrDimension,c as intersectMultimensionalSubset,g as isMultiSliceOrRangeDefinition};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.26/esri/copyright.txt for details.
4
4
  */
5
- import{getAssetUrl as e}from"../../../assets.js";const t=[{pixelType:"S8",size:1,ctor:Int8Array,range:[-128,127]},{pixelType:"U8",size:1,ctor:Uint8Array,range:[0,255]},{pixelType:"S16",size:2,ctor:Int16Array,range:[-32768,32767]},{pixelType:"U16",size:2,ctor:Uint16Array,range:[0,65536]},{pixelType:"S32",size:4,ctor:Int32Array,range:[-2147483648,2147483647]},{pixelType:"U32",size:4,ctor:Uint32Array,range:[0,4294967296]},{pixelType:"F32",size:4,ctor:Float32Array,range:[-34027999387901484e22,34027999387901484e22]},{pixelType:"F64",size:8,ctor:Float64Array,range:[-17976931348623157e292,17976931348623157e292]}];let n=null,r=!1;function a(){return n||(n=import("../../../chunks/lerc-wasm.js").then((e=>e.l)).then((({default:t})=>t({locateFile:t=>e(`esri/layers/support/rasterFormats/${t}`)}))).then((e=>{u(e),r=!0})),n)}function o(){return r}const l={getBlobInfo:null,decode:null};function s(e){return 16+(e>>3<<3)}function i(e,t,n){n.set(e.slice(t,t+n.length))}function u(e){const{_malloc:n,_free:r,_lerc_getBlobInfo:a,_lerc_getDataRanges:o,_lerc_decode_4D:u,asm:f}=e;let c;const h=Object.values(f).find((t=>t&&"buffer"in t&&t.buffer===e.HEAPU8.buffer)),y=e=>{const t=e.map((e=>s(e))),r=t.reduce(((e,t)=>e+t)),a=n(r);c=new Uint8Array(h.buffer);let o=t[0];t[0]=a;for(let n=1;n<t.length;n++){const e=t[n];t[n]=t[n-1]+o,o=e}return t};l.getBlobInfo=e=>{const t=12,n=3,l=new Uint8Array(4*t),s=new Uint8Array(8*n),[u,f,p]=y([e.length,l.length,s.length]);c.set(e,u),c.set(l,f),c.set(s,p);let g=a(u,e.length,f,p,t,n);if(g)throw r(u),new Error(`lerc-getBlobInfo: error code is ${g}`);c=new Uint8Array(h.buffer),i(c,f,l),i(c,p,s);const d=new Uint32Array(l.buffer),b=new Float64Array(s.buffer),[w,A,,m,U,x,C,T,V,z,F]=d,I={version:w,depthCount:z,width:m,height:U,validPixelCount:C,bandCount:x,blobSize:T,maskCount:V,dataType:A,minValue:b[0],maxValue:b[1],maxZerror:b[2],statistics:[],bandCountWithNoData:F};if(F)return I;if(1===z&&1===x)return r(u),I.statistics.push({minValue:b[0],maxValue:b[1]}),I;const D=z*x*8,_=new Uint8Array(D),k=new Uint8Array(D);let B=u,S=0,v=0,E=!1;if(c.byteLength<u+2*D?(r(u),E=!0,[B,S,v]=y([e.length,D,D]),c.set(e,B)):[S,v]=y([D,D]),c.set(_,S),c.set(k,v),g=o(B,e.length,z,x,S,v),g)throw r(B),E||r(S),new Error(`lerc-getDataRanges: error code is ${g}`);c=new Uint8Array(h.buffer),i(c,S,_),i(c,v,k);const O=new Float64Array(_.buffer),$=new Float64Array(k.buffer),j=I.statistics;for(let r=0;r<x;r++)if(z>1){const e=O.slice(r*z,(r+1)*z),t=$.slice(r*z,(r+1)*z),n=Math.min.apply(null,e),a=Math.max.apply(null,t);j.push({minValue:n,maxValue:a,depthStats:{minValues:e,maxValues:t}})}else j.push({minValue:O[r],maxValue:$[r]});return r(B),E||r(S),I},l.decode=(e,n)=>{const{maskCount:a,depthCount:o,bandCount:l,width:s,height:f,dataType:p,bandCountWithNoData:g}=n,d=t[p],b=s*f,w=new Uint8Array(b*l),A=b*o*l*d.size,m=new Uint8Array(A),U=new Uint8Array(l),x=new Uint8Array(8*l),[C,T,V,z,F]=y([e.length,w.length,m.length,U.length,x.length]);c.set(e,C),c.set(w,T),c.set(m,V),c.set(U,z),c.set(x,F);const I=u(C,e.length,a,T,o,s,f,l,p,V,z,F);if(I)throw r(C),new Error(`lerc-decode: error code is ${I}`);c=new Uint8Array(h.buffer),i(c,V,m),i(c,T,w);let D=null;if(g){i(c,z,U),i(c,F,x),D=[];const e=new Float64Array(x.buffer);for(let t=0;t<U.length;t++)D.push(U[t]?e[t]:null)}return r(C),{data:m,maskData:w,noDataValues:D}}}function f(e,t,n,r,a){if(n<2)return e;const o=new r(t*n);if(a)for(let l=0,s=0;l<t;l++)for(let r=0,a=l;r<n;r++,a+=t)o[a]=e[s++];else for(let l=0,s=0;l<t;l++)for(let r=0,a=l;r<n;r++,a+=t)o[s++]=e[a];return o}function c(e,n={}){const r=n.inputOffset??0,a=e instanceof Uint8Array?e.subarray(r):new Uint8Array(e,r),o=l.getBlobInfo(a),{data:s,maskData:i}=l.decode(a,o),{width:u,height:c,bandCount:h,depthCount:y,dataType:p,maskCount:g,statistics:d}=o,b=t[p],w=new b.ctor(s.buffer),A=[],m=[],U=u*c,x=U*y;for(let t=0;t<h;t++){const e=w.subarray(t*x,(t+1)*x);if(n.returnInterleaved)A.push(e);else{const t=f(e,U,y,b.ctor,!0);A.push(t)}m.push(i.subarray(t*x,(t+1)*x))}const C=0===g?null:1===g?m[0]:new Uint8Array(U);if(g>1){C.set(m[0]);for(let e=1;e<m.length;e++){const t=m[e];for(let e=0;e<U;e++)C[e]=C[e]&t[e]}}const{noDataValue:T}=n,V=null!=T&&b.range[0]<=T&&b.range[1]>=T;if(g>0&&V)for(let t=0;t<h;t++){const e=A[t],n=m[t]||C;for(let t=0;t<U;t++)0===n[t]&&(e[t]=T)}const z=g===h&&h>1?m:null,{pixelType:F}=b;return{width:u,height:c,bandCount:h,pixelType:F,depthCount:y,statistics:d,pixels:A,mask:C,bandMasks:z}}function h(e,t={}){const n=e instanceof Uint8Array?e.subarray(t.inputOffset??0):new Uint8Array(e,t.inputOffset??0);return l.getBlobInfo(n)}export{c as decode,h as getBlobInfo,o as isLoaded,a as load};
5
+ import{getAssetUrl as e}from"../../../assets.js";const t=[{pixelType:"S8",size:1,ctor:Int8Array,range:[-128,127]},{pixelType:"U8",size:1,ctor:Uint8Array,range:[0,255]},{pixelType:"S16",size:2,ctor:Int16Array,range:[-32768,32767]},{pixelType:"U16",size:2,ctor:Uint16Array,range:[0,65536]},{pixelType:"S32",size:4,ctor:Int32Array,range:[-2147483648,2147483647]},{pixelType:"U32",size:4,ctor:Uint32Array,range:[0,4294967296]},{pixelType:"F32",size:4,ctor:Float32Array,range:[-34027999387901484e22,34027999387901484e22]},{pixelType:"F64",size:8,ctor:Float64Array,range:[-17976931348623157e292,17976931348623157e292]}];let n=null,r=!1;function a(){return n||(n=import("../../../chunks/lerc-wasm.js").then((e=>e.l)).then((({default:t})=>t({locateFile:t=>e(`esri/layers/support/rasterFormats/${t}`)}))).then((e=>{u(e),r=!0})),n)}function o(){return r}const l={getBlobInfo:null,decode:null};function s(e){return 16+(e>>3<<3)}function i(e,t,n){n.set(e.slice(t,t+n.length))}function u(e){const{_malloc:n,_free:r,_lerc_getBlobInfo:a,_lerc_getDataRanges:o,_lerc_decode_4D:u,asm:f}=e;let c;const h=Object.values(f).find((t=>t&&"buffer"in t&&t.buffer===e.HEAPU8.buffer)),y=e=>{const t=e.map((e=>s(e))),r=t.reduce(((e,t)=>e+t)),a=n(r);c=new Uint8Array(h.buffer);let o=t[0];t[0]=a;for(let n=1;n<t.length;n++){const e=t[n];t[n]=t[n-1]+o,o=e}return t};l.getBlobInfo=e=>{const t=12,n=3,l=new Uint8Array(4*t),s=new Uint8Array(8*n),[u,f,p]=y([e.length,l.length,s.length]);c.set(e,u),c.set(l,f),c.set(s,p);let g=a(u,e.length,f,p,t,n);if(g)throw r(u),new Error(`lerc-getBlobInfo: error code is ${g}`);c=new Uint8Array(h.buffer),i(c,f,l),i(c,p,s);const d=new Uint32Array(l.buffer),b=new Float64Array(s.buffer),[w,A,,m,U,x,C,V,T,D,z]=d,F={version:w,depthCount:D,width:m,height:U,validPixelCount:C,bandCount:x,blobSize:V,maskCount:T,dataType:A,minValue:b[0],maxValue:b[1],maxZerror:b[2],statistics:[],bandCountWithNoData:z};if(z)return F;if(1===D&&1===x)return r(u),F.statistics.push({minValue:b[0],maxValue:b[1]}),F;const I=D*x*8,_=new Uint8Array(I),k=new Uint8Array(I);let B=u,S=0,v=0,E=!1;if(c.byteLength<u+2*I?(r(u),E=!0,[B,S,v]=y([e.length,I,I]),c.set(e,B)):[S,v]=y([I,I]),c.set(_,S),c.set(k,v),g=o(B,e.length,D,x,S,v),g)throw r(B),E||r(S),new Error(`lerc-getDataRanges: error code is ${g}`);c=new Uint8Array(h.buffer),i(c,S,_),i(c,v,k);const O=new Float64Array(_.buffer),$=new Float64Array(k.buffer),j=F.statistics;for(let r=0;r<x;r++)if(D>1){const e=O.slice(r*D,(r+1)*D),t=$.slice(r*D,(r+1)*D),n=Math.min.apply(null,e),a=Math.max.apply(null,t);j.push({minValue:n,maxValue:a,depthStats:{minValues:e,maxValues:t}})}else j.push({minValue:O[r],maxValue:$[r]});return r(B),E||r(S),F},l.decode=(e,n)=>{const{maskCount:a,depthCount:o,bandCount:l,width:s,height:f,dataType:p,bandCountWithNoData:g}=n,d=t[p],b=s*f,w=new Uint8Array(b*l),A=b*o*l*d.size,m=new Uint8Array(A),U=new Uint8Array(l),x=new Uint8Array(8*l),[C,V,T,D,z]=y([e.length,w.length,m.length,U.length,x.length]);c.set(e,C),c.set(w,V),c.set(m,T),c.set(U,D),c.set(x,z);const F=u(C,e.length,a,V,o,s,f,l,p,T,D,z);if(F)throw r(C),new Error(`lerc-decode: error code is ${F}`);c=new Uint8Array(h.buffer),i(c,T,m),i(c,V,w);let I=null;if(g){i(c,D,U),i(c,z,x),I=[];const e=new Float64Array(x.buffer);for(let t=0;t<U.length;t++)I.push(U[t]?e[t]:null)}return r(C),{data:m,maskData:w,noDataValues:I}}}function f(e,t,n,r,a){if(n<2)return e;const o=new r(t*n);if(a)for(let l=0,s=0;l<t;l++)for(let r=0,a=l;r<n;r++,a+=t)o[a]=e[s++];else for(let l=0,s=0;l<t;l++)for(let r=0,a=l;r<n;r++,a+=t)o[s++]=e[a];return o}function c(e,n={}){const r=n.inputOffset??0,a=e instanceof Uint8Array?e.subarray(r):new Uint8Array(e,r),o=l.getBlobInfo(a),{data:s,maskData:i,noDataValues:u}=l.decode(a,o),{width:c,height:h,bandCount:y,depthCount:p,dataType:g,maskCount:d,statistics:b}=o,w=t[g],A=new w.ctor(s.buffer),m=[],U=[],x=c*h,C=x*p;for(let t=0;t<y;t++){const e=A.subarray(t*C,(t+1)*C);if(n.returnInterleaved)m.push(e);else{const t=f(e,x,p,w.ctor,!0);m.push(t)}U.push(i.subarray(t*C,(t+1)*C))}const V=0===d?null:1===d?U[0]:new Uint8Array(x);if(d>1){V.set(U[0]);for(let e=1;e<U.length;e++){const t=U[e];for(let e=0;e<x;e++)V[e]=V[e]&t[e]}}const{noDataValue:T}=n,D=null!=T&&w.range[0]<=T&&w.range[1]>=T;if(d>0&&D)for(let t=0;t<y;t++){const e=m[t],n=U[t]||V;for(let t=0;t<x;t++)0===n[t]&&(e[t]=T)}const z=d===y&&y>1?U:null,{pixelType:F}=w;return{width:c,height:h,bandCount:y,pixelType:F,depthCount:p,statistics:b,pixels:m,mask:V,bandMasks:z,noDataValues:u}}function h(e,t={}){const n=e instanceof Uint8Array?e.subarray(t.inputOffset??0):new Uint8Array(e,t.inputOffset??0);return l.getBlobInfo(n)}export{c as decode,h as getBlobInfo,o as isLoaded,a as load,t as pixelTypeInfoMap};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.26/esri/copyright.txt for details.
4
4
  */
5
- import t from"../../../core/Error.js";import{isSome as e,assertIsSome as i}from"../../../core/maybe.js";import a from"../PixelBlock.js";import s from"./ImageCanvasDecoder.js";import r from"./JpgPlus.js";import{load as n,decode as o}from"./Lerc.js";import{decode as h}from"./Lzw.js";import{Z as c}from"../../../chunks/Zlib.js";import p from"./Raw.js";import{decodeTileOrStrip as l,decode as d}from"./TiffDecoder.js";import{isPlatformLittleEndian as u}from"./utils.js";var f=function(t){var e,i,a,s,r,n;function o(t){var e,i,a,s,r,n,o,h,c,p,l,d,u;for(this.data=t,this.pos=8,this.palette=[],this.imgData=[],this.transparency={},this.animation=null,this.text={},r=null;;){switch(e=this.readUInt32(),h=function(){var t,e;for(e=[],t=0;t<4;++t)e.push(String.fromCharCode(this.data[this.pos++]));return e}.call(this).join(""),h){case"IHDR":this.width=this.readUInt32(),this.height=this.readUInt32(),this.bits=this.data[this.pos++],this.colorType=this.data[this.pos++],this.compressionMethod=this.data[this.pos++],this.filterMethod=this.data[this.pos++],this.interlaceMethod=this.data[this.pos++];break;case"acTL":this.animation={numFrames:this.readUInt32(),numPlays:this.readUInt32()||1/0,frames:[]};break;case"PLTE":this.palette=this.read(e);break;case"fcTL":r&&this.animation.frames.push(r),this.pos+=4,r={width:this.readUInt32(),height:this.readUInt32(),xOffset:this.readUInt32(),yOffset:this.readUInt32()},s=this.readUInt16(),a=this.readUInt16()||100,r.delay=1e3*s/a,r.disposeOp=this.data[this.pos++],r.blendOp=this.data[this.pos++],r.data=[];break;case"IDAT":case"fdAT":for("fdAT"===h&&(this.pos+=4,e-=4),t=(null!=r?r.data:void 0)||this.imgData,l=0;0<=e?l<e:l>e;0<=e?++l:--l)t.push(this.data[this.pos++]);break;case"tRNS":switch(this.transparency={},this.colorType){case 3:if(this.transparency.indexed=this.read(e),(c=255-this.transparency.indexed.length)>0)for(d=0;0<=c?d<c:d>c;0<=c?++d:--d)this.transparency.indexed.push(255);break;case 0:this.transparency.grayscale=this.read(e)[0];break;case 2:this.transparency.rgb=this.read(e)}break;case"tEXt":n=(p=this.read(e)).indexOf(0),o=String.fromCharCode.apply(String,p.slice(0,n)),this.text[o]=String.fromCharCode.apply(String,p.slice(n+1));break;case"IEND":return r&&this.animation.frames.push(r),this.colors=function(){switch(this.colorType){case 0:case 3:case 4:return 1;case 2:case 6:return 3}}.call(this),this.hasAlphaChannel=4===(u=this.colorType)||6===u,i=this.colors+(this.hasAlphaChannel?1:0),this.pixelBitlength=this.bits*i,this.colorSpace=function(){switch(this.colors){case 1:return"DeviceGray";case 3:return"DeviceRGB"}}.call(this),void(this.imgData=new Uint8Array(this.imgData));default:this.pos+=e}if(this.pos+=4,this.pos>this.data.length)throw new Error("Incomplete or corrupt PNG file")}}return o.load=function(t,e,i){var a;return"function"==typeof e&&(i=e),(a=new XMLHttpRequest).open("GET",t,!0),a.responseType="arraybuffer",a.onload=function(){var t;return t=new o(new Uint8Array(a.response||a.mozResponseArrayBuffer)),"function"==typeof(null!=e?e.getContext:void 0)&&t.render(e),"function"==typeof i?i(t):void 0},a.send(null)},i=1,a=2,e=0,o.prototype.read=function(t){var e,i;for(i=[],e=0;0<=t?e<t:e>t;0<=t?++e:--e)i.push(this.data[this.pos++]);return i},o.prototype.readUInt32=function(){return this.data[this.pos++]<<24|this.data[this.pos++]<<16|this.data[this.pos++]<<8|this.data[this.pos++]},o.prototype.readUInt16=function(){return this.data[this.pos++]<<8|this.data[this.pos++]},o.prototype.decodePixels=function(t){var e,i,a,s,r,n,o,h,p,l,d,u,f,m,g,w,y,x,b,k,I,T,v;if(null==t&&(t=this.imgData),0===t.length)return new Uint8Array(0);for(t=(t=new c(t)).getBytes(),w=(u=this.pixelBitlength/8)*this.width,f=new Uint8Array(w*this.height),n=t.length,g=0,m=0,i=0;m<n;){switch(t[m++]){case 0:for(s=b=0;b<w;s=b+=1)f[i++]=t[m++];break;case 1:for(s=k=0;k<w;s=k+=1)e=t[m++],r=s<u?0:f[i-u],f[i++]=(e+r)%256;break;case 2:for(s=I=0;I<w;s=I+=1)e=t[m++],a=(s-s%u)/u,y=g&&f[(g-1)*w+a*u+s%u],f[i++]=(y+e)%256;break;case 3:for(s=T=0;T<w;s=T+=1)e=t[m++],a=(s-s%u)/u,r=s<u?0:f[i-u],y=g&&f[(g-1)*w+a*u+s%u],f[i++]=(e+Math.floor((r+y)/2))%256;break;case 4:for(s=v=0;v<w;s=v+=1)e=t[m++],a=(s-s%u)/u,r=s<u?0:f[i-u],0===g?y=x=0:(y=f[(g-1)*w+a*u+s%u],x=a&&f[(g-1)*w+(a-1)*u+s%u]),o=r+y-x,h=Math.abs(o-r),l=Math.abs(o-y),d=Math.abs(o-x),p=h<=l&&h<=d?r:l<=d?y:x,f[i++]=(e+p)%256;break;default:throw new Error("Invalid filter algorithm: "+t[m-1])}g++}return f},o.prototype.decodePalette=function(){var t,e,i,a,s,r,n,o,h;for(i=this.palette,r=this.transparency.indexed||[],s=new Uint8Array((r.length||0)+i.length),a=0,i.length,t=0,e=n=0,o=i.length;n<o;e=n+=3)s[a++]=i[e],s[a++]=i[e+1],s[a++]=i[e+2],s[a++]=null!=(h=r[t++])?h:255;return s},o.prototype.copyToImageData=function(t,e){var i,a,s,r,n,o,h,c,p,l,d;if(a=this.colors,p=null,i=this.hasAlphaChannel,this.palette.length&&(p=null!=(d=this._decodedPalette)?d:this._decodedPalette=this.decodePalette(),a=4,i=!0),c=(s=t.data||t).length,n=p||e,r=o=0,1===a)for(;r<c;)h=p?4*e[r/4]:o,l=n[h++],s[r++]=l,s[r++]=l,s[r++]=l,s[r++]=i?n[h++]:this.transparency.grayscale&&this.transparency.grayscale===l?0:255,o=h;else for(;r<c;)h=p?4*e[r/4]:o,s[r++]=n[h++],s[r++]=n[h++],s[r++]=n[h++],s[r++]=i?n[h++]:this.transparency.rgb&&this.transparency.rgb[1]===n[h-3]&&this.transparency.rgb[3]===n[h-2]&&this.transparency.rgb[5]===n[h-1]?0:255,o=h},o.prototype.decode=function(){var t;return t=new Uint8Array(this.width*this.height*4),this.copyToImageData(t,this.decodePixels()),t},r=t.document&&t.document.createElement("canvas"),n=r&&r.getContext("2d"),s=function(t){var e;return n.width=t.width,n.height=t.height,n.clearRect(0,0,t.width,t.height),n.putImageData(t,0,0),(e=new Image).src=r.toDataURL(),e},o.prototype.decodeFrames=function(t){var e,i,a,r,n,o,h,c;if(this.animation){for(c=[],i=n=0,o=(h=this.animation.frames).length;n<o;i=++n)e=h[i],a=t.createImageData(e.width,e.height),r=this.decodePixels(new Uint8Array(e.data)),this.copyToImageData(a,r),e.imageData=a,c.push(e.image=s(a));return c}},o.prototype.renderFrame=function(t,s){var r,n,o;return r=(n=this.animation.frames)[s],o=n[s-1],0===s&&t.clearRect(0,0,this.width,this.height),(null!=o?o.disposeOp:void 0)===i?t.clearRect(o.xOffset,o.yOffset,o.width,o.height):(null!=o?o.disposeOp:void 0)===a&&t.putImageData(o.imageData,o.xOffset,o.yOffset),r.blendOp===e&&t.clearRect(r.xOffset,r.yOffset,r.width,r.height),t.drawImage(r.image,r.xOffset,r.yOffset)},o.prototype.animate=function(t){var e,i,a,s,r,n,o=this;return i=0,n=this.animation,s=n.numFrames,a=n.frames,r=n.numPlays,(e=function(){var n,h;if(n=i++%s,h=a[n],o.renderFrame(t,n),s>1&&i/s<r)return o.animation._timeout=setTimeout(e,h.delay)})()},o.prototype.stopAnimation=function(){var t;return clearTimeout(null!=(t=this.animation)?t._timeout:void 0)},o.prototype.render=function(t){var e,i;return t._png&&t._png.stopAnimation(),t._png=this,t.width=this.width,t.height=this.height,e=t.getContext("2d"),this.animation?(this.decodeFrames(e),this.animate(e)):(i=e.createImageData(this.width,this.height),this.copyToImageData(i,this.decodePixels()),e.putImageData(i,0,0))},o}(self);const m=new Set(["jpg","png","bmp","gif"]);async function g(e,i){if(!u)throw new t("rasterCoded:decode","lerc decoder is not supported on big endian platform");await n();const{offset:s,noDataValue:r}=i,{width:h,height:c,pixelType:p,statistics:l,pixels:d,mask:f}=o(e,{inputOffset:s,noDataValue:r,returnInterleaved:i.returnInterleaved});return new a({width:h,height:c,pixelType:p.toLowerCase(),pixels:d,mask:f,statistics:l})}async function w(t,e){const s=await d(t,e);i(s);const r=new a({width:s.width,height:s.height,pixels:s.pixels,pixelType:s.pixelType.toLowerCase(),mask:s.mask,statistics:null});return r.updateStatistics(),r}async function y(t,e){const i=await l(t,e.customOptions),s=new a({width:i.width,height:i.height,pixels:i.pixels,pixelType:i.pixelType.toLowerCase(),mask:i.mask,statistics:null});return s.updateStatistics(),s}function x(t,e){const i=e.pixelType||"u8",s=a.getPixelArrayConstructor(i),r="u8"===i?t:new s(t.buffer),n=[],o=e.planes||1;if(1===o)n.push(r);else for(let a=0;a<o;a++){const i=(e.width||1)*(e.height||t.length),h=new s(i);for(let t=0;t<i;t++)h[t]=r[t*o+a];n.push(h)}const h=new a({width:e.width||1,height:e.height||t.length,pixels:n,pixelType:i,statistics:null});return h.updateStatistics(),h}function b(t,e){return x(new c(new Uint8Array(t)).getBytes(),e)}function k(t,e){return x(h(t,e.offset,e.eof,!e.isInputBigEndian),e)}function I(t,e,i){const{pixelTypeCtor:s}=D(e.pixelType),r=(0,p.decode)(t,{width:e.width,height:e.height,pixelType:s,format:i}),n=new a({width:e.width,height:e.height,pixels:r.pixels,pixelType:e.pixelType,mask:r.mask,statistics:null});return n.updateStatistics(),n}function T(t,e){const i=r.decode(t,e.hasNoZlibMask??void 0),s=new a({width:i.width,height:i.height,pixels:i.pixels,pixelType:"U8",mask:i.mask,statistics:null});return s.updateStatistics(),s}function v(t,e){const i=new Uint8Array(t),s=new f(i),{width:r,height:n}=e,o=r*n,h=s.decode();let c,p=0,l=0;const d=new Uint8Array(o);for(p=0;p<o;p++)d[p]=h[4*p+3];const u=new a({width:r,height:n,pixels:[],pixelType:"U8",mask:d,statistics:[]});for(p=0;p<3;p++){for(c=new Uint8Array(o),l=0;l<o;l++)c[l]=h[4*l+p];u.addData({pixels:c})}return u.updateStatistics(),u}async function U(t,e,i,r){const n=new s,o={applyJpegMask:!1,format:e,...i},h=await n.decode(t,o,r),c=new a(h);return c.updateStatistics(),c}function A(e){if(null==e)throw new t("rasterCodec:decode","parameter encodeddata is required.");const i=new Uint8Array(e,0,10);let a="";return 255===i[0]&&216===i[1]?a="jpg":137===i[0]&&80===i[1]&&78===i[2]&&71===i[3]?a="png":67===i[0]&&110===i[1]&&116===i[2]&&90===i[3]&&73===i[4]&&109===i[5]&&97===i[6]&&103===i[7]&&101===i[8]&&32===i[9]?a="lerc":76===i[0]&&101===i[1]&&114===i[2]&&99===i[3]&&50===i[4]&&32===i[5]?a="lerc2":73===i[0]&&73===i[1]&&42===i[2]&&0===i[3]||77===i[0]&&77===i[1]&&0===i[2]&&42===i[3]||73===i[0]&&73===i[1]&&43===i[2]&&0===i[3]||77===i[0]&&77===i[1]&&0===i[2]&&43===i[3]?a="tiff":71===i[0]&&73===i[1]&&70===i[2]?a="gif":66===i[0]&&77===i[1]?a="bmp":String.fromCharCode.apply(null,i).toLowerCase().includes("error")&&(a="error"),a}function C(e){let i=null;switch(e){case"lerc":case"lerc2":i=g;break;case"jpg":i=T;break;case"png":i=v;break;case"bsq":case"bip":i=(t,i)=>I(t,i,e);break;case"tiff":i=w;break;case"deflate":i=b;break;case"lzw":i=k;break;case"error":i=()=>{throw new t("rasterCodec:decode","input data contains error")};break;default:i=()=>{throw new t("rasterCodec:decode","unsupported raster format")}}return i}function D(t){let e=null,i=null;switch(t?t.toLowerCase():"f32"){case"u1":case"u2":case"u4":case"u8":i=255,e=Uint8Array;break;case"u16":i=i||65535,e=Uint16Array;break;case"u32":i=i||2**32-1,e=Uint32Array;break;case"s8":i=i||-128,e=Int8Array;break;case"s16":i=i||-32768,e=Int16Array;break;case"s32":i=i||0-2**31,e=Int32Array;break;default:e=Float32Array}return{pixelTypeCtor:e,noDataValue:i}}function O(t,i=1){if(!t)return;const{pixels:s,width:r,height:n,mask:o}=t;if(!s||0===s.length)return;const h=s.length,c=r-1,p=n-1,l=[];let d,u,f,m,g,w,y=null;const x=a.getPixelArrayConstructor(t.pixelType);if(0===i){for(d=0;d<h;d++){for(g=s[d],w=new x(c*p),u=0;u<p;u++)for(m=u*r,f=0;f<c;f++)w[u*c+f]=g[m+f];l.push(w)}if(e(o))for(y=new Uint8Array(c*p),u=0;u<p;u++)for(m=u*r,f=0;f<c;f++)y[u*c+f]=o[m+f]}else{for(d=0;d<h;d++){for(g=s[d],w=new x(c*p),u=0;u<p;u++)for(m=u*r,f=0;f<c;f++)w[u*c+f]=(g[m+f]+g[m+f+1]+g[m+r+f]+g[m+r+f+1])/4;l.push(w)}if(o)for(y=new Uint8Array(c*p),u=0;u<p;u++)for(m=u*r,f=0;f<c;f++)y[u*c+f]=Math.min.apply(null,[o[m+f],o[m+f+1],o[m+r+f],o[m+r+f+1]])}t.width=c,t.height=p,t.mask=y,t.pixels=l}function P(t){let e=A(t);return"lerc2"===e?e="lerc":"error"===e&&(e=""),e}async function S(e,i={},a){if(null==e)throw new t("rasterCodec:decode","missing encodeddata parameter.");let s,r,n=i.format&&i.format.toLowerCase();if(!("bsq"!==n&&"bip"!==n||null!=i.width&&null!=i.height))throw new t("rasterCodec:decode","requires width and height in options parameter.");return"tiff"===n&&i.customOptions?y(e,i):((!n||"bsq"!==n&&"bip"!==n&&"deflate"!==n&&"lzw"!==n)&&(n=A(e)),i.useCanvas&&m.has(n)?r=await U(e,n,i,a):(s=C(n),i.isPoint&&(null!=(i={...i}).width&&i.width++,null!=i.height&&i.height++),r=await s(e,i),i.isPoint&&O(r)),r)}export{S as decode,P as getFormat};
5
+ import t from"../../../core/Error.js";import{isSome as e,assertIsSome as a}from"../../../core/maybe.js";import i from"../PixelBlock.js";import s from"./ImageCanvasDecoder.js";import r from"./JpgPlus.js";import{load as n,decode as o}from"./Lerc.js";import{decode as h}from"./Lzw.js";import{convertNoDataToMask as c}from"./pixelRangeUtils.js";import{Z as l}from"../../../chunks/Zlib.js";import p from"./Raw.js";import{decodeTileOrStrip as d,decode as u}from"./TiffDecoder.js";import{isPlatformLittleEndian as f}from"./utils.js";var m=function(t){var e,a,i,s,r,n;function o(t){var e,a,i,s,r,n,o,h,c,l,p,d,u;for(this.data=t,this.pos=8,this.palette=[],this.imgData=[],this.transparency={},this.animation=null,this.text={},r=null;;){switch(e=this.readUInt32(),h=function(){var t,e;for(e=[],t=0;t<4;++t)e.push(String.fromCharCode(this.data[this.pos++]));return e}.call(this).join(""),h){case"IHDR":this.width=this.readUInt32(),this.height=this.readUInt32(),this.bits=this.data[this.pos++],this.colorType=this.data[this.pos++],this.compressionMethod=this.data[this.pos++],this.filterMethod=this.data[this.pos++],this.interlaceMethod=this.data[this.pos++];break;case"acTL":this.animation={numFrames:this.readUInt32(),numPlays:this.readUInt32()||1/0,frames:[]};break;case"PLTE":this.palette=this.read(e);break;case"fcTL":r&&this.animation.frames.push(r),this.pos+=4,r={width:this.readUInt32(),height:this.readUInt32(),xOffset:this.readUInt32(),yOffset:this.readUInt32()},s=this.readUInt16(),i=this.readUInt16()||100,r.delay=1e3*s/i,r.disposeOp=this.data[this.pos++],r.blendOp=this.data[this.pos++],r.data=[];break;case"IDAT":case"fdAT":for("fdAT"===h&&(this.pos+=4,e-=4),t=(null!=r?r.data:void 0)||this.imgData,p=0;0<=e?p<e:p>e;0<=e?++p:--p)t.push(this.data[this.pos++]);break;case"tRNS":switch(this.transparency={},this.colorType){case 3:if(this.transparency.indexed=this.read(e),(c=255-this.transparency.indexed.length)>0)for(d=0;0<=c?d<c:d>c;0<=c?++d:--d)this.transparency.indexed.push(255);break;case 0:this.transparency.grayscale=this.read(e)[0];break;case 2:this.transparency.rgb=this.read(e)}break;case"tEXt":n=(l=this.read(e)).indexOf(0),o=String.fromCharCode.apply(String,l.slice(0,n)),this.text[o]=String.fromCharCode.apply(String,l.slice(n+1));break;case"IEND":return r&&this.animation.frames.push(r),this.colors=function(){switch(this.colorType){case 0:case 3:case 4:return 1;case 2:case 6:return 3}}.call(this),this.hasAlphaChannel=4===(u=this.colorType)||6===u,a=this.colors+(this.hasAlphaChannel?1:0),this.pixelBitlength=this.bits*a,this.colorSpace=function(){switch(this.colors){case 1:return"DeviceGray";case 3:return"DeviceRGB"}}.call(this),void(this.imgData=new Uint8Array(this.imgData));default:this.pos+=e}if(this.pos+=4,this.pos>this.data.length)throw new Error("Incomplete or corrupt PNG file")}}return o.load=function(t,e,a){var i;return"function"==typeof e&&(a=e),(i=new XMLHttpRequest).open("GET",t,!0),i.responseType="arraybuffer",i.onload=function(){var t;return t=new o(new Uint8Array(i.response||i.mozResponseArrayBuffer)),"function"==typeof(null!=e?e.getContext:void 0)&&t.render(e),"function"==typeof a?a(t):void 0},i.send(null)},a=1,i=2,e=0,o.prototype.read=function(t){var e,a;for(a=[],e=0;0<=t?e<t:e>t;0<=t?++e:--e)a.push(this.data[this.pos++]);return a},o.prototype.readUInt32=function(){return this.data[this.pos++]<<24|this.data[this.pos++]<<16|this.data[this.pos++]<<8|this.data[this.pos++]},o.prototype.readUInt16=function(){return this.data[this.pos++]<<8|this.data[this.pos++]},o.prototype.decodePixels=function(t){var e,a,i,s,r,n,o,h,c,p,d,u,f,m,g,w,y,x,b,k,T,I,C;if(null==t&&(t=this.imgData),0===t.length)return new Uint8Array(0);for(t=(t=new l(t)).getBytes(),w=(u=this.pixelBitlength/8)*this.width,f=new Uint8Array(w*this.height),n=t.length,g=0,m=0,a=0;m<n;){switch(t[m++]){case 0:for(s=b=0;b<w;s=b+=1)f[a++]=t[m++];break;case 1:for(s=k=0;k<w;s=k+=1)e=t[m++],r=s<u?0:f[a-u],f[a++]=(e+r)%256;break;case 2:for(s=T=0;T<w;s=T+=1)e=t[m++],i=(s-s%u)/u,y=g&&f[(g-1)*w+i*u+s%u],f[a++]=(y+e)%256;break;case 3:for(s=I=0;I<w;s=I+=1)e=t[m++],i=(s-s%u)/u,r=s<u?0:f[a-u],y=g&&f[(g-1)*w+i*u+s%u],f[a++]=(e+Math.floor((r+y)/2))%256;break;case 4:for(s=C=0;C<w;s=C+=1)e=t[m++],i=(s-s%u)/u,r=s<u?0:f[a-u],0===g?y=x=0:(y=f[(g-1)*w+i*u+s%u],x=i&&f[(g-1)*w+(i-1)*u+s%u]),o=r+y-x,h=Math.abs(o-r),p=Math.abs(o-y),d=Math.abs(o-x),c=h<=p&&h<=d?r:p<=d?y:x,f[a++]=(e+c)%256;break;default:throw new Error("Invalid filter algorithm: "+t[m-1])}g++}return f},o.prototype.decodePalette=function(){var t,e,a,i,s,r,n,o,h;for(a=this.palette,r=this.transparency.indexed||[],s=new Uint8Array((r.length||0)+a.length),i=0,a.length,t=0,e=n=0,o=a.length;n<o;e=n+=3)s[i++]=a[e],s[i++]=a[e+1],s[i++]=a[e+2],s[i++]=null!=(h=r[t++])?h:255;return s},o.prototype.copyToImageData=function(t,e){var a,i,s,r,n,o,h,c,l,p,d;if(i=this.colors,l=null,a=this.hasAlphaChannel,this.palette.length&&(l=null!=(d=this._decodedPalette)?d:this._decodedPalette=this.decodePalette(),i=4,a=!0),c=(s=t.data||t).length,n=l||e,r=o=0,1===i)for(;r<c;)h=l?4*e[r/4]:o,p=n[h++],s[r++]=p,s[r++]=p,s[r++]=p,s[r++]=a?n[h++]:this.transparency.grayscale&&this.transparency.grayscale===p?0:255,o=h;else for(;r<c;)h=l?4*e[r/4]:o,s[r++]=n[h++],s[r++]=n[h++],s[r++]=n[h++],s[r++]=a?n[h++]:this.transparency.rgb&&this.transparency.rgb[1]===n[h-3]&&this.transparency.rgb[3]===n[h-2]&&this.transparency.rgb[5]===n[h-1]?0:255,o=h},o.prototype.decode=function(){var t;return t=new Uint8Array(this.width*this.height*4),this.copyToImageData(t,this.decodePixels()),t},r=t.document&&t.document.createElement("canvas"),n=r&&r.getContext("2d"),s=function(t){var e;return n.width=t.width,n.height=t.height,n.clearRect(0,0,t.width,t.height),n.putImageData(t,0,0),(e=new Image).src=r.toDataURL(),e},o.prototype.decodeFrames=function(t){var e,a,i,r,n,o,h,c;if(this.animation){for(c=[],a=n=0,o=(h=this.animation.frames).length;n<o;a=++n)e=h[a],i=t.createImageData(e.width,e.height),r=this.decodePixels(new Uint8Array(e.data)),this.copyToImageData(i,r),e.imageData=i,c.push(e.image=s(i));return c}},o.prototype.renderFrame=function(t,s){var r,n,o;return r=(n=this.animation.frames)[s],o=n[s-1],0===s&&t.clearRect(0,0,this.width,this.height),(null!=o?o.disposeOp:void 0)===a?t.clearRect(o.xOffset,o.yOffset,o.width,o.height):(null!=o?o.disposeOp:void 0)===i&&t.putImageData(o.imageData,o.xOffset,o.yOffset),r.blendOp===e&&t.clearRect(r.xOffset,r.yOffset,r.width,r.height),t.drawImage(r.image,r.xOffset,r.yOffset)},o.prototype.animate=function(t){var e,a,i,s,r,n,o=this;return a=0,n=this.animation,s=n.numFrames,i=n.frames,r=n.numPlays,(e=function(){var n,h;if(n=a++%s,h=i[n],o.renderFrame(t,n),s>1&&a/s<r)return o.animation._timeout=setTimeout(e,h.delay)})()},o.prototype.stopAnimation=function(){var t;return clearTimeout(null!=(t=this.animation)?t._timeout:void 0)},o.prototype.render=function(t){var e,a;return t._png&&t._png.stopAnimation(),t._png=this,t.width=this.width,t.height=this.height,e=t.getContext("2d"),this.animation?(this.decodeFrames(e),this.animate(e)):(a=e.createImageData(this.width,this.height),this.copyToImageData(a,this.decodePixels()),e.putImageData(a,0,0))},o}(self);const g=new Set(["jpg","png","bmp","gif"]);async function w(e,a){if(!f)throw new t("rasterCoded:decode","lerc decoder is not supported on big endian platform");await n();const{offset:s}=a,{width:r,height:h,pixelType:c,statistics:l,depthCount:p,noDataValues:d,bandMasks:u,pixels:m,mask:g}=o(e,{inputOffset:s,returnInterleaved:a.returnInterleaved});return new i({width:r,height:h,pixelType:c.toLowerCase(),pixels:m,mask:g,statistics:l,bandMasks:u,depthCount:p,noDataValues:d})}async function y(t,e){const s=await u(t,{...e,noDataValue:null});a(s);const r=new i({width:s.width,height:s.height,pixels:s.pixels,pixelType:s.pixelType.toLowerCase(),mask:s.mask,statistics:null});return r.updateStatistics(),r}async function x(t,e){const a=await d(t,e.customOptions),s=new i({width:a.width,height:a.height,pixels:a.pixels,pixelType:a.pixelType.toLowerCase(),mask:a.mask,statistics:null});return s.updateStatistics(),s}function b(t,e){const a=e.pixelType||"u8",s=i.getPixelArrayConstructor(a),r="u8"===a?t:new s(t.buffer),n=[],o=e.planes||1;if(1===o)n.push(r);else for(let i=0;i<o;i++){const a=(e.width||1)*(e.height||t.length),h=new s(a);for(let t=0;t<a;t++)h[t]=r[t*o+i];n.push(h)}const h=new i({width:e.width||1,height:e.height||t.length,pixels:n,pixelType:a,statistics:null});return h.updateStatistics(),h}function k(t,e){return b(new l(new Uint8Array(t)).getBytes(),e)}function T(t,e){return b(h(t,e.offset,e.eof,!e.isInputBigEndian),e)}function I(t,e,a){const{pixelTypeCtor:s}=O(e.pixelType),r=(0,p.decode)(t,{width:e.width,height:e.height,pixelType:s,format:a}),n=new i({width:e.width,height:e.height,pixels:r.pixels,pixelType:e.pixelType,mask:r.mask,statistics:null});return n.updateStatistics(),n}function C(t,e){const a=r.decode(t,e.hasNoZlibMask??void 0),s=new i({width:a.width,height:a.height,pixels:a.pixels,pixelType:"U8",mask:a.mask,statistics:null});return s.updateStatistics(),s}function v(t,e){const a=new Uint8Array(t),s=new m(a),{width:r,height:n}=e,o=r*n,h=s.decode();let c,l=0,p=0;const d=new Uint8Array(o);for(l=0;l<o;l++)d[l]=h[4*l+3];const u=new i({width:r,height:n,pixels:[],pixelType:"U8",mask:d,statistics:[]});for(l=0;l<3;l++){for(c=new Uint8Array(o),p=0;p<o;p++)c[p]=h[4*p+l];u.addData({pixels:c})}return u.updateStatistics(),u}async function U(t,e,a,r){const n=new s,o={applyJpegMask:!1,format:e,...a},h=await n.decode(t,o,r),c=new i(h);return c.updateStatistics(),c}function A(e){if(null==e)throw new t("rasterCodec:decode","parameter encodeddata is required.");const a=new Uint8Array(e,0,10);let i="";return 255===a[0]&&216===a[1]?i="jpg":137===a[0]&&80===a[1]&&78===a[2]&&71===a[3]?i="png":67===a[0]&&110===a[1]&&116===a[2]&&90===a[3]&&73===a[4]&&109===a[5]&&97===a[6]&&103===a[7]&&101===a[8]&&32===a[9]?i="lerc":76===a[0]&&101===a[1]&&114===a[2]&&99===a[3]&&50===a[4]&&32===a[5]?i="lerc2":73===a[0]&&73===a[1]&&42===a[2]&&0===a[3]||77===a[0]&&77===a[1]&&0===a[2]&&42===a[3]||73===a[0]&&73===a[1]&&43===a[2]&&0===a[3]||77===a[0]&&77===a[1]&&0===a[2]&&43===a[3]?i="tiff":71===a[0]&&73===a[1]&&70===a[2]?i="gif":66===a[0]&&77===a[1]?i="bmp":String.fromCharCode.apply(null,a).toLowerCase().includes("error")&&(i="error"),i}function D(e){let a=null;switch(e){case"lerc":case"lerc2":a=w;break;case"jpg":a=C;break;case"png":a=v;break;case"bsq":case"bip":a=(t,a)=>I(t,a,e);break;case"tiff":a=y;break;case"deflate":a=k;break;case"lzw":a=T;break;case"error":a=()=>{throw new t("rasterCodec:decode","input data contains error")};break;default:a=()=>{throw new t("rasterCodec:decode","unsupported raster format")}}return a}function O(t){let e=null,a=null;switch(t?t.toLowerCase():"f32"){case"u1":case"u2":case"u4":case"u8":a=255,e=Uint8Array;break;case"u16":a=a||65535,e=Uint16Array;break;case"u32":a=a||2**32-1,e=Uint32Array;break;case"s8":a=a||-128,e=Int8Array;break;case"s16":a=a||-32768,e=Int16Array;break;case"s32":a=a||0-2**31,e=Int32Array;break;default:e=Float32Array}return{pixelTypeCtor:e,noDataValue:a}}function P(t,a=1){if(!t)return;const{pixels:s,width:r,height:n,mask:o}=t;if(!s||0===s.length)return;const h=s.length,c=r-1,l=n-1,p=[];let d,u,f,m,g,w,y=null;const x=i.getPixelArrayConstructor(t.pixelType);if(0===a){for(d=0;d<h;d++){for(g=s[d],w=new x(c*l),u=0;u<l;u++)for(m=u*r,f=0;f<c;f++)w[u*c+f]=g[m+f];p.push(w)}if(e(o))for(y=new Uint8Array(c*l),u=0;u<l;u++)for(m=u*r,f=0;f<c;f++)y[u*c+f]=o[m+f]}else{for(d=0;d<h;d++){for(g=s[d],w=new x(c*l),u=0;u<l;u++)for(m=u*r,f=0;f<c;f++)w[u*c+f]=(g[m+f]+g[m+f+1]+g[m+r+f]+g[m+r+f+1])/4;p.push(w)}if(o)for(y=new Uint8Array(c*l),u=0;u<l;u++)for(m=u*r,f=0;f<c;f++)y[u*c+f]=Math.min.apply(null,[o[m+f],o[m+f+1],o[m+r+f],o[m+r+f+1]])}t.width=c,t.height=l,t.mask=y,t.pixels=p}function j(t){let e=A(t);return"lerc2"===e?e="lerc":"error"===e&&(e=""),e}async function S(e,a={},i){if(null==e)throw new t("rasterCodec:decode","missing encodeddata parameter.");let s=a.format&&a.format.toLowerCase();if(!("bsq"!==s&&"bip"!==s||null!=a.width&&null!=a.height))throw new t("rasterCodec:decode","requires width and height in options parameter.");if("tiff"===s&&a.customOptions)return x(e,a);if((!s||"bsq"!==s&&"bip"!==s&&"deflate"!==s&&"lzw"!==s)&&(s=A(e)),a.useCanvas&&g.has(s))return U(e,s,a,i);const r=D(s);a.isPoint&&(null!=(a={...a}).width&&a.width++,null!=a.height&&a.height++);const n=await r(e,a);return n?("jpg"!==s&&null!=a.noDataValue&&1===n.depthCount&&c(n,a.noDataValue,{customFloatTolerance:a.tolerance}),a.isPoint&&P(n),n):n}export{S as decode,j as getFormat};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.26/esri/copyright.txt for details.
4
4
  */
5
- import{bytesToUTF8 as e}from"../rasterDatasets/byteStreamUtils.js";import{J as t}from"../../../chunks/Jpg.js";import{load as n,decode as a}from"./Lerc.js";import{decode as i}from"./Lzw.js";import s from"./TiffTags.js";import{isPlatformLittleEndian as r}from"./utils.js";import{Z as l}from"../../../chunks/Zlib.js";const o=[0,1,1,2,4,8,1,1,2,4,8,4,8,-1,-1,-1,8,8,8],f=4294967296,u=new Set([1,5,6,7,8,34712,34887]);function c(e,t){let n="unknown";return 3===e?n=64===t?"f64":"f32":1===e?1===t?n="u1":2===t?n="u2":4===t?n="u4":t<=8?n="u8":t<=16?n="u16":t<=32&&(n="u32"):2===e&&(t<=8?n="s8":t<=16?n="s16":t<=32&&(n="s32")),n}function h(e){let t=null;switch(e?e.toLowerCase():"f32"){case"u1":case"u2":case"u4":case"u8":t=Uint8Array;break;case"u16":t=Uint16Array;break;case"u32":t=Uint32Array;break;case"s8":t=Int8Array;break;case"s16":t=Int16Array;break;case"s32":t=Int32Array;break;case"f64":t=Float64Array;break;default:t=Float32Array}return t}function g(e,t){return{x:t[0]*e.x+t[1]*e.y+t[2],y:t[3]*e.x+t[4]*e.y+t[5]}}function E(e,t){return e.get(t)?.values}function I(e,t){return e.get(t)?.values}function T(e,t){return e.get(t)?.values?.[0]}function w(e,t){return e.get(t)?.values?.[0]}function d(e,t,n,a=0,i=s.TIFF_TAGS,r=4){const l=8===r,o=l?k(new DataView(e,n,8),0,t):new DataView(e,n,2).getUint16(0,t),f=4+2*r,u=l?8:2,c=u+o*f;if(n+c>e.byteLength)return{success:!1,ifd:null,nextIFD:null,requiredBufferSize:c};const h=n+c+4<=e.byteLength?F(new DataView(e,n+c,8===r?8:4),0,t,8===r):null,g=n+u,E=new Map;let I,T,w,d,p,m=0,S=0;for(let y=0;y<o;y++){T=new DataView(e,g+f*y,f),w=T.getUint16(0,t),p=T.getUint16(2,t),d=s.getTagName(w,i);const n=[];2===r?(m=T.getUint16(4,t),S=T.getUint16(6,t)):4===r?(m=T.getUint32(4,t),S=T.getUint32(8,t)):8===r&&(m=F(T,4,t,!0),S=F(T,12,t,!0),n.push(T.getUint32(12,t)),n.push(T.getUint32(16,t))),I={id:w,type:p,valueCount:m,valueOffset:S,valueOffsets:n,values:null},x(e,t,I,a,!1,r),E.set(d,I)}return{success:!0,ifd:E,nextIFD:h,requiredBufferSize:c}}const p=(e,t)=>a(e,{inputOffset:t}).pixels[0];function m(e,t){if(1!==t&&2!==t&&4!==t)return e;const n=new Uint8Array(e),a=8/t,i=new Uint8Array(e.byteLength*a);let s=0;const r=2**t-1;for(let l=0;l<n.length;l++){const e=n[l];for(let n=0;n<a;n++)i[s++]=e<<t*n>>>8-t&r}return i.buffer}function S(e,n,a){const i=new t;i.parse(e),i.colorTransform=6===a?-1:0;const s=i.getData(i.width,i.height,1!==n);return new Uint8Array(s.buffer)}function y(e){const t=new l(e).getBytes(),n=new ArrayBuffer(t.length),a=new Uint8Array(n);return a.set(t),a}async function A(e,t,a,s,l){const o=r===t,f=w(a,"BITSPERSAMPLE"),u=w(a,"SAMPLESPERPIXEL"),g=w(a,"PHOTOMETRICINTERPRETATION"),E=c(w(a,"SAMPLEFORMAT")??1,f),I=w(a,"COMPRESSION")??1,T=h(E);let d,A,M;if(34887===I)return await n(),p(e,s);if(1===I)d=e.slice(s,s+l),A=new Uint8Array(d);else if(8===I||32946===I)A=new Uint8Array(e,s,l),A=y(A),d=A.buffer;else if(6===I)A=new Uint8Array(e,s,l),A=S(A,u,g),d=A.buffer;else if(7===I){const t=a.get("JPEGTABLES").values,n=t.length-2;A=new Uint8Array(n+l-2);for(let e=0;e<n;e++)A[e]=t[e];const i=new Uint8Array(e,s+2,l-2);for(let e=0;e<i.length;e++)A[n+e]=i[e];A=S(A,u,g),d=A.buffer}else{if(5!==I)throw new Error("tiff-decode: unsupport compression "+I);A=i(e,s,l,t),d=A.buffer}if(d=m(d,f),"u8"===E||"s8"===E||o)M=new T(d);else{d=new ArrayBuffer(A.length);const e=new Uint8Array(d);switch(E){case"u16":case"s16":for(let t=0;t<A.length;t+=2)e[t]=A[t+1],e[t+1]=A[t];break;case"u32":case"s32":case"f32":for(let t=0;t<A.length;t+=4)e[t]=A[t+3],e[t+1]=A[t+2],e[t+2]=A[t+1],e[t+3]=A[t]}M=new T(d)}return M}async function M(e,t,n){const a=I(n,"TILEOFFSETS");if(void 0===a)return null;const i=I(n,"TILEBYTECOUNTS"),{width:s,height:r,pixelType:l,tileWidth:o,tileHeight:f}=L([n]),u=R(n,t),c=w(n,"SAMPLESPERPIXEL")||t.planes,g=s*r,E=w(n,"BITSPERSAMPLE"),T=34887===(w(n,"COMPRESSION")??1),d=h(l),p=[];for(let h=0;h<c;h++)p.push(new d(g));let m,S,y,M,P,b,O,x,D,U,N,k,G;const F=Math.ceil(s/o);if(E%8==0)if(T&&u&&c>1){const l=Math.round(a.length/c);for(m=0;m<l;m++){b=Math.floor(m/F)*f,O=m%F*o,x=b*s+O;for(let l=0;l<c;l++){const u=m*c+l;if(0!==i[u])for(y=await A(e,t.littleEndian,n,a[u],i[u]),U=0,D=x,k=Math.min(o,s-O),N=Math.min(f,r-b),G=p[l],M=0;M<N;M++)for(D=x+M*s,U=M*o,P=0;P<k;P++,D++,U++)G[D]=y[U]}}}else for(m=0;m<a.length;m++)if(0!==i[m])for(b=Math.floor(m/F)*f,O=m%F*o,x=b*s+O,y=await A(e,t.littleEndian,n,a[m],i[m]),U=0,D=x,k=Math.min(o,s-O),N=Math.min(f,r-b),S=0;S<c;S++)if(G=p[S],u||T)for(M=0;M<N;M++)for(D=x+M*s,U=o*f*S+M*o,P=0;P<k;P++,D++,U++)G[D]=y[U];else for(M=0;M<N;M++)for(D=x+M*s,U=M*o*c+S,P=0;P<k;P++,D++,U+=c)G[D]=y[U];return{width:s,height:r,pixelType:l,pixels:p}}const P=(e,t,n)=>{const a=r===t.littleEndian,s=I(n,"STRIPOFFSETS");if(void 0===s)return null;const{width:l,height:o,pixelType:f}=L([n]),u=w(n,"SAMPLESPERPIXEL")||t.planes,c=w(n,"PHOTOMETRICINTERPRETATION"),g=l*o,E=w(n,"BITSPERSAMPLE"),T=h(f),d=new T(g*u),p=I(n,"STRIPBYTECOUNTS"),A=w(n,"ROWSPERSTRIP"),M=w(n,"COMPRESSION")??1;let P,b,O,x,R,D,U,N,k,G=A;if(E%8==0)for(P=0;P<s.length;P++){if(R=P*(A*l)*u,G=(P+1)*A>o?o-P*A:A,"u8"===f||"s8"===f||a)8===M||32946===M?(U=new Uint8Array(e,s[P],p[P]),U=y(U),D=U.buffer):6===M?(U=new Uint8Array(e,s[P],p[P]),U=S(U,u,c),D=U.buffer):5===M?(U=i(e,s[P],p[P],t.littleEndian),D=U.buffer):(p[P]!==G*l*u*E/8&&console.log("strip byte counts is different than expected"),D=e.slice(s[P],s[P]+p[P])),D=m(D,E),x=new T(D);else{switch(6===M||8===M||32946===M?(U=new Uint8Array(e,s[P],p[P]),N=y(U),D=N.buffer):(p[P]!==G*l*u*E/8&&console.log("strip byte counts is different than expected"),D=new ArrayBuffer(p[P]),U=new Uint8Array(e,s[P],p[P]),N=new Uint8Array(D)),f){case"u16":case"s16":for(O=0;O<U.length;O+=2)N[O]=U[O+1],N[O+1]=U[O];break;case"u32":case"s32":case"f32":for(O=0;O<U.length;O+=4)N[O]=U[O+3],N[O+1]=U[O+2],N[O+2]=U[O+1],N[O+3]=U[O]}D=m(D,E),x=new T(D)}d.set(x,R)}const F=[];if(1===u)F.push(d);else for(P=0;P<u;P++){for(k=new T(g),b=0;b<g;b++)k[b]=d[b*u+P];F.push(k)}return{width:l,height:o,pixelType:f,pixels:F}},b=(e,t,n)=>{if(!(e&&e.length>0&&t&&n))return null;let a,i,s;const r=e[0].length,l=e.length,o=new Uint8Array(r);for(let f=0;f<l;f++)if(a=e[f],i=t[f],s=n[f],0===f)for(let e=0;e<r;e++)o[e]=a[e]<i||a[e]>s?0:1;else for(let e=0;e<r;e++)o[e]&&(o[e]=a[e]<i||a[e]>s?0:1);return o},O=e=>{if(!e)return null;const t=e.match(/<Item(.*?)Item>/gi);if(!t||0===t.length)return null;const n=new Map;let a,i,s,r,l;for(let w=0;w<t.length;w++)a=t[w],i=a.slice("<Item ".length,a.indexOf(">")),r=a.indexOf("sample="),r>-1&&(l=a.slice(r+'sample="'.length,a.indexOf('"',r+'sample="'.length))),r=a.indexOf("name="),r>-1&&(i=a.slice(r+'name="'.length,a.indexOf('"',r+'name="'.length))),i&&(s=a.slice(a.indexOf(">")+1,a.indexOf("</Item>")).trim(),null!=l?n.has(i)?n.get(i)[l]=s:n.set(i,[s]):n.set(i,s)),l=null;const o=n.get("STATISTICS_MINIMUM"),f=n.get("STATISTICS_MAXIMUM"),u=n.get("STATISTICS_MEAN"),c=n.get("STATISTICS_STDDEV");let h=null;if(o&&f){h=[];for(let e=0;e<o.length;e++)h.push({min:parseFloat(o[e]),max:parseFloat(f[e]),avg:u&&parseFloat(u[e]),stddev:c&&parseFloat(c[e])})}const g=n.get("BandName"),E=n.get("WavelengthMin"),I=n.get("WavelengthMax");let T=null;if(g){T=[];for(let e=0;e<g.length;e++)T.push({BandName:g[e],WavelengthMin:E&&parseFloat(E[e]),WavelengthMax:I&&parseFloat(I[e])})}return{statistics:h,bandProperties:T,dataType:n.get("DataType"),rawMetadata:n}};function x(e,t,n,a=0,i=!1,s=4){if(n.values)return!0;const r=n.type,l=n.valueCount;let u=n.valueOffset,c=[];const h=o[r],g=8*h,E=l*h,I=l*o[r]*8;let T,w;const d=8===s?64:32,p=n.valueOffsets;if(I>d){if(E>(i?e.byteLength:e?e.byteLength-u+a:0))return n.offlineOffsetSize=[u,E],n.values=null,!1}if(I<=d){if(!t)if(d<=32)u>>>=32-I;else{const e=p?.length?p[0]:u>>>0,t=p?.length?p[1]:Math.round((u-e)/f);I<=32?(u=e>>>32-I,p[0]=u):(u=e*2**(32-I)+(t>>>32-I),p[0]=e,p[1]=t>>>32-I)}if(1===l&&g===d)c=[u];else if(64===d){const e=p?.length?p[0]:u>>>0,t=p?.length?p[1]:Math.round((u-e)/f);let n=e,a=32;for(w=1;w<=l;w++){const e=32-g*w%32;if(a<g){const i=n<<e>>>32-a,s=t<<32-a>>>32-a;n=t,c.push(i+s*2**(g-a)),a-=32-(g-a)}else c.push(n<<e>>>32-g),a-=g;0===a&&(a=32,n=t)}}else for(w=1;w<=l;w++){const e=32-g*w;c.push(u<<e>>>32-g)}}else{u-=a,i&&(u=0);for(let n=u;n<u+E;n+=h){switch(r){case 1:case 2:case 7:T=new DataView(e,n,1).getUint8(0);break;case 3:T=new DataView(e,n,2).getUint16(0,t);break;case 4:case 13:T=new DataView(e,n,4).getUint32(0,t);break;case 5:T=new DataView(e,n,4).getUint32(0,t)/new DataView(e,n+4,4).getUint32(0,t);break;case 6:T=new DataView(e,n,1).getInt8(0);break;case 8:T=new DataView(e,n,2).getInt16(0,t);break;case 9:T=new DataView(e,n,4).getInt32(0,t);break;case 10:T=new DataView(e,n,4).getInt32(0,t)/new DataView(e,n+4,4).getInt32(0,t);break;case 11:T=new DataView(e,n,4).getFloat32(0,t);break;case 12:T=new DataView(e,n,8).getFloat64(0,t);break;case 16:case 18:T=k(new DataView(e,n,8),0,t);break;case 17:T=G(new DataView(e,n,8),0,t);break;default:T=null}c.push(T)}}if(2===r){let e="";const t=c;for(c=[],w=0;w<t.length;w++)0===t[w]&&""!==e?(c.push(e),e=""):e+=String.fromCharCode(t[w]);""===e&&0!==c.length||c.push(e)}return n.values=c,!0}function L(e){const t=e[0],n=w(t,"TILEWIDTH"),a=w(t,"TILELENGTH"),i=w(t,"IMAGEWIDTH"),s=w(t,"IMAGELENGTH"),r=w(t,"BITSPERSAMPLE"),l=w(t,"SAMPLESPERPIXEL"),o=w(t,"SAMPLEFORMAT")??1,f=c(o,r),h=R(t),d=E(t,"GDAL_NODATA");let p=null;d?.length&&(p=d.map((e=>parseFloat(e))),p.some((e=>isNaN(e)))&&(p=null));const m=w(t,"COMPRESSION")??1;let S;switch(m){case 1:S="NONE";break;case 2:case 3:case 4:case 32771:S="CCITT";break;case 5:S="LZW";break;case 6:case 7:S="JPEG";break;case 32773:S="PACKBITS";break;case 8:case 32946:S="DEFLATE";break;case 34712:S="JPEG2000";break;case 34887:S="LERC";break;default:S=String(m)}let y=!0,A="";u.has(m)||(y=!1,A+="unsupported tag compression "+m),o>3&&(y=!1,A+="unsupported tag sampleFormat "+o),1!==r&&2!==r&&4!==r&&r%8!=0&&(y=!1,A+="unsupported tag bitsPerSample "+r);const M=T(t,"GEOASCIIPARAMS");let P;if(M){const e=M.split("|").find((e=>e.includes("ESRI PE String = "))),t=e?e.replace("ESRI PE String = ",""):"";P=t.startsWith("COMPD_CS")||t.startsWith("PROJCS")||t.startsWith("GEOGCS")?{wkid:null,wkt:t}:null}const b=I(t,"GEOTIEPOINTS"),x=I(t,"GEOPIXELSCALE"),L=I(t,"GEOTRANSMATRIX"),N=t.has("GEOKEYDIRECTORY")?t.get("GEOKEYDIRECTORY").data:null;let k,G,F=!1,C=!1;if(N){F=2===w(N,"GTRasterTypeGeoKey");const e=w(N,"GTModelTypeGeoKey");if(2===e){const e=w(N,"GeographicTypeGeoKey");e>=1024&&e<=32766&&(P={wkid:e}),P||32767!==e||(C=!0,P={wkid:4326})}else if(1===e){const e=w(N,"ProjectedCSTypeGeoKey");e>=1024&&e<=32766&&(P={wkid:e})}}if(x&&b&&b.length>=6?(k=[x[0],0,b[3]-b[0]*x[0],0,-Math.abs(x[1]),b[4]-b[1]*x[1]],F&&(k[2]-=.5*k[0]+.5*k[1],k[5]-=.5*k[3]+.5*k[4])):L&&16===L.length&&(k=F?[L[0],L[1],L[3]-.5*L[0],L[4],L[5],L[7]-.5*L[5]]:[L[0],L[1],L[3],L[4],L[5],L[7]]),k){const e=[{x:0,y:s},{x:0,y:0},{x:i,y:s},{x:i,y:0}];let t,n=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;for(let i=0;i<e.length;i++)t=g(e[i],k),n=t.x>n?n:t.x,r=t.x<r?r:t.x,a=t.y>a?a:t.y,l=t.y<l?l:t.y;G={xmin:n,xmax:r,ymin:a,ymax:l,spatialReference:P}}else G={xmin:-.5,ymin:.5-s,xmax:i-.5,ymax:.5,spatialReference:P};C&&(G.xmax-G.xmin>400||Math.max(Math.abs(G.xmin),Math.abs(G.xmax))>361)&&(P=null,G.spatialReference=null);const v=D(e);let V,W,H,Y,_;if(v.length>0){H=Math.round(Math.log(i/w(v[0],"IMAGEWIDTH"))/Math.LN2);const e=v[v.length-1];Y=Math.round(Math.log(i/w(e,"IMAGEWIDTH"))/Math.LN2),V=w(e,"TILEWIDTH"),W=w(e,"TILELENGTH")}V=null!=Y&&Y>0?V||n:null,W=null!=Y&&Y>0?W||a:null,n&&(_=[{maxCol:Math.ceil(i/n)-1,maxRow:Math.ceil(s/a)-1,minRow:0,minCol:0}],v.forEach((e=>{_.push({maxCol:Math.ceil(w(e,"IMAGEWIDTH")/w(e,"TILEWIDTH"))-1,maxRow:Math.ceil(w(e,"IMAGELENGTH")/w(e,"TILELENGTH"))-1,minRow:0,minCol:0})})));const K=T(e[0],"GDAL_METADATA"),X=O(K);A+=" "+B({width:i,height:s,tileWidth:n,tileHeight:a,planes:l,ifds:e});return{width:i,height:s,tileWidth:n,tileHeight:a,planes:l,isBSQ:h,pixelType:f,compression:S,noData:p,hasMaskBand:U(e).length===v.length+1,isSupported:y,message:A,extent:G,isPseudoGeographic:C,affine:x?null:k,firstPyramidLevel:H,maximumPyramidLevel:Y,pyramidBlockWidth:V,pyramidBlockHeight:W,tileBoundary:_,metadata:X}}function R(e,t){const n=E(e,"PLANARCONFIGURATION");return n?2===n[0]:!!t&&t.isBSQ}function D(e){return e.filter((e=>1===w(e,"NEWSUBFILETYPE")))}function U(e){return e.filter((e=>{const t=4==(4&(w(e,"NEWSUBFILETYPE")??0)),n=4===w(e,"PHOTOMETRICINTERPRETATION");return t&&n}))}function N(e){const{littleEndian:t,isBigTiff:n,firstIFDPos:a}=C(e);let i=a;const r=[];do{const a=v(e,t,i,0,s.TIFF_TAGS,n?8:4);if(!a.success)break;r.push(a.ifd),i=a.nextIFD}while(i>0);return{...L(r),littleEndian:t,isBigTiff:n,ifds:r,pyramidIFDs:D(r),maskIFDs:U(r)}}function k(e,t,n){const a=e.getUint32(t,n),i=e.getUint32(t+4,n);return n?i*f+a:a*f+i}function G(e,t,n){let a=n?e.getInt32(t,n):e.getUint32(t,n),i=n?e.getUint32(t+4,n):e.getInt32(t+4,n);const s=(n?a:i)>=0?1:-1;n?a*=s:i*=s;return s*(n?i*f+a:a*f+i)}function F(e,t,n,a){return a?k(e,t,n):e.getUint32(t,n)}function C(e){const t=new DataView(e,0,16),n=t.getUint16(0,!1);let a=null;if(18761===n)a=!0;else{if(19789!==n)throw new Error("unexpected endianess byte");a=!1}const i=t.getUint16(2,a);if(42!==i&&43!==i)throw new Error("unexpected tiff identifier");let s=4;const r=43===i;if(r){const e=t.getUint16(s,a);if(s+=2,8!==e)throw new Error("unsupported bigtiff version");if(0!==t.getUint16(s,a))throw new Error("unsupported bigtiff version");s+=2}return{littleEndian:a,isBigTiff:r,firstIFDPos:F(t,s,a,r)}}function v(t,n,a,i=0,r=s.TIFF_TAGS,l=4){const o=d(t,n,a,i,r,l);let f;const u=o.ifd;if(u){if(s.ifdTags.forEach(((e,a)=>{u.has(a)&&(f=u.get(a),f.data=d(t,n,f.valueOffset-i,i,e).ifd)})),u.has("GEOKEYDIRECTORY")){f=u.get("GEOKEYDIRECTORY");const e=f.values;if(e&&e.length>4){const a=e[0]+"."+e[1]+"."+e[2];f.data=d(t,n,f.valueOffset+6-i,i,s.GEO_KEYS,2).ifd,f.data&&f.data.set("GEOTIFFVersion",{id:0,type:2,valueCount:1,valueOffset:null,values:[a]})}}if(u.has("XMP")){f=u.get("XMP");const t=f.values;"number"==typeof t[0]&&7===f.type&&(f.values=[e(new Uint8Array(t))])}}return o}function B(e){const{width:t,height:n,tileHeight:a,tileWidth:i}=e,s=e.planes,r=i?i*a:t*n,l=w(e.ifds[0],"BITSPERSAMPLE");let o="";return r*s>2**30/(l>8?l/8:1)&&(o=i?"tiled tiff exceeding 1 gigabits per tile is not supported":"scanline tiff exceeding 1 gigabits is not supported"),o}async function V(e,t){const{headerInfo:n,ifd:a,offsets:i,sizes:s}=t,r=[];for(let c=0;c<i.length;c++){const t=await A(e,n.littleEndian,a,i[c],s[c]||e.byteLength);r.push(t)}const l=R(a,n),o=w(a,"BITSPERSAMPLE"),f=c(w(a,"SAMPLEFORMAT")??1,o),u=w(a,"SAMPLESPERPIXEL")||n.planes,g=h(f),E=w(a,"TILEWIDTH"),I=w(a,"TILELENGTH"),T=w(a,"COMPRESSION")??1,d=E*I;let p;const m=[];let S=r[0];const y=34887===T;for(let c=0;c<u;c++){if(p=new g(d),l&&y){if(S=r[c],S.length)for(let e=0;e<d;e++)p[e]=S[c][e+c]}else if(S.length)if(l||y&&!l)p=S.slice(d*c,d*(c+1));else for(let e=0;e<d;e++)p[e]=S[e*u+c];m.push(p)}const M=n.noData?n.noData[0]:t.noDataValue,P=n.metadata?n.metadata.statistics:null,O=P?P.map((e=>e.min)):null,x=P?P.map((e=>e.max)):null;let L,D=null;if(null!=M)if(D=new Uint8Array(d),Math.abs(M)>1e24)for(L=0;L<d;L++)Math.abs((m[0][L]-M)/M)<1e-6?D[L]=0:D[L]=1;else for(L=0;L<d;L++)m[0][L]===M?D[L]=0:D[L]=1;else O&&x&&t.applyMinMaxConstraint&&(D=b(m,O,x));return{pixelType:f,width:E,height:I,pixels:m,mask:D,noDataValue:M}}async function W(e,t={}){const n=t.pyramidLevel||0,a=t.headerInfo||N(e),{ifds:i,noData:s}=a;if(0===i.length)throw new Error("no valid image file directory");const r=B(a);if(r)throw r;let l,o=null;const f=-1===n?i[i.length-1]:i[n],u=s?s[0]:t.noDataValue;if(o=a.tileWidth?await M(e,a,f):await P(e,a,f),!o)return o;if(null!=u){if(o.mask=new Uint8Array(o.width*o.height),Math.abs(u)>1e24)for(l=0;l<o.width*o.height;l++)Math.abs((o.pixels[0][l]-u)/u)<1e-6?o.mask[l]=0:o.mask[l]=1;else for(l=0;l<o.width*o.height;l++)o.pixels[0][l]===u?o.mask[l]=0:o.mask[l]=1;o.noDataValue=u}return o}export{W as decode,V as decodeTileOrStrip,L as getImageInfo,U as getMaskIFDs,D as getPyramidIFDs,R as isBSQConfig,x as parseFieldValues,N as parseHeader,v as parseIFD,C as parseSignature};
5
+ import{bytesToUTF8 as e}from"../rasterDatasets/byteStreamUtils.js";import{J as t}from"../../../chunks/Jpg.js";import{load as n,decode as a}from"./Lerc.js";import{decode as i}from"./Lzw.js";import{convertNoDataToMask as s}from"./pixelRangeUtils.js";import r from"./TiffTags.js";import{isPlatformLittleEndian as l}from"./utils.js";import{Z as o}from"../../../chunks/Zlib.js";const f=[0,1,1,2,4,8,1,1,2,4,8,4,8,-1,-1,-1,8,8,8],u=4294967296,c=new Set([1,5,6,7,8,34712,34887]);function h(e,t){let n="unknown";return 3===e?n=64===t?"f64":"f32":1===e?1===t?n="u1":2===t?n="u2":4===t?n="u4":t<=8?n="u8":t<=16?n="u16":t<=32&&(n="u32"):2===e&&(t<=8?n="s8":t<=16?n="s16":t<=32&&(n="s32")),n}function g(e){let t=null;switch(e?e.toLowerCase():"f32"){case"u1":case"u2":case"u4":case"u8":t=Uint8Array;break;case"u16":t=Uint16Array;break;case"u32":t=Uint32Array;break;case"s8":t=Int8Array;break;case"s16":t=Int16Array;break;case"s32":t=Int32Array;break;case"f64":t=Float64Array;break;default:t=Float32Array}return t}function E(e,t){return{x:t[0]*e.x+t[1]*e.y+t[2],y:t[3]*e.x+t[4]*e.y+t[5]}}function I(e,t){return e.get(t)?.values}function T(e,t){return e.get(t)?.values}function p(e,t){return e.get(t)?.values?.[0]}function d(e,t){return e.get(t)?.values?.[0]}function w(e,t,n,a=0,i=r.TIFF_TAGS,s=4){const l=8===s,o=l?G(new DataView(e,n,8),0,t):new DataView(e,n,2).getUint16(0,t),f=4+2*s,u=l?8:2,c=u+o*f;if(n+c>e.byteLength)return{success:!1,ifd:null,nextIFD:null,requiredBufferSize:c};const h=n+c+4<=e.byteLength?C(new DataView(e,n+c,8===s?8:4),0,t,8===s):null,g=n+u,E=new Map;let I,T,p,d,w,m=0,S=0;for(let y=0;y<o;y++){T=new DataView(e,g+f*y,f),p=T.getUint16(0,t),w=T.getUint16(2,t),d=r.getTagName(p,i);const n=[];2===s?(m=T.getUint16(4,t),S=T.getUint16(6,t)):4===s?(m=T.getUint32(4,t),S=T.getUint32(8,t)):8===s&&(m=C(T,4,t,!0),S=C(T,12,t,!0),n.push(T.getUint32(12,t)),n.push(T.getUint32(16,t))),I={id:p,type:w,valueCount:m,valueOffset:S,valueOffsets:n,values:null},L(e,t,I,a,!1,s),E.set(d,I)}return{success:!0,ifd:E,nextIFD:h,requiredBufferSize:c}}const m=(e,t)=>a(e,{inputOffset:t}).pixels[0];function S(e,t){if(1!==t&&2!==t&&4!==t)return e;const n=new Uint8Array(e),a=8/t,i=new Uint8Array(e.byteLength*a);let s=0;const r=2**t-1;for(let l=0;l<n.length;l++){const e=n[l];for(let n=0;n<a;n++)i[s++]=e<<t*n>>>8-t&r}return i.buffer}function y(e,n,a){const i=new t;i.parse(e),i.colorTransform=6===a?-1:0;const s=i.getData(i.width,i.height,1!==n);return new Uint8Array(s.buffer)}function A(e){const t=new o(e).getBytes(),n=new ArrayBuffer(t.length),a=new Uint8Array(n);return a.set(t),a}async function M(e,t,a,s,r){const o=l===t,f=d(a,"BITSPERSAMPLE"),u=d(a,"SAMPLESPERPIXEL"),c=d(a,"PHOTOMETRICINTERPRETATION"),E=h(d(a,"SAMPLEFORMAT")??1,f),I=d(a,"COMPRESSION")??1,T=g(E);let p,w,M;if(34887===I)return await n(),m(e,s);if(1===I)p=e.slice(s,s+r),w=new Uint8Array(p);else if(8===I||32946===I)w=new Uint8Array(e,s,r),w=A(w),p=w.buffer;else if(6===I)w=new Uint8Array(e,s,r),w=y(w,u,c),p=w.buffer;else if(7===I){const t=a.get("JPEGTABLES").values,n=t.length-2;w=new Uint8Array(n+r-2);for(let e=0;e<n;e++)w[e]=t[e];const i=new Uint8Array(e,s+2,r-2);for(let e=0;e<i.length;e++)w[n+e]=i[e];w=y(w,u,c),p=w.buffer}else{if(5!==I)throw new Error("tiff-decode: unsupport compression "+I);w=i(e,s,r,t),p=w.buffer}if(p=S(p,f),"u8"===E||"s8"===E||o)M=new T(p);else{p=new ArrayBuffer(w.length);const e=new Uint8Array(p);switch(E){case"u16":case"s16":for(let t=0;t<w.length;t+=2)e[t]=w[t+1],e[t+1]=w[t];break;case"u32":case"s32":case"f32":for(let t=0;t<w.length;t+=4)e[t]=w[t+3],e[t+1]=w[t+2],e[t+2]=w[t+1],e[t+3]=w[t]}M=new T(p)}return M}async function P(e,t,n){const a=T(n,"TILEOFFSETS");if(void 0===a)return null;const i=T(n,"TILEBYTECOUNTS"),{width:s,height:r,pixelType:l,tileWidth:o,tileHeight:f}=R([n]),u=D(n,t),c=d(n,"SAMPLESPERPIXEL")||t.planes,h=s*r,E=d(n,"BITSPERSAMPLE"),I=34887===(d(n,"COMPRESSION")??1),p=g(l),w=[];for(let g=0;g<c;g++)w.push(new p(h));let m,S,y,A,P,O,b,x,L,N,U,k,G;const F=Math.ceil(s/o);if(E%8==0)if(I&&u&&c>1){const l=Math.round(a.length/c);for(m=0;m<l;m++){O=Math.floor(m/F)*f,b=m%F*o,x=O*s+b;for(let l=0;l<c;l++){const u=m*c+l;if(0!==i[u])for(y=await M(e,t.littleEndian,n,a[u],i[u]),N=0,L=x,k=Math.min(o,s-b),U=Math.min(f,r-O),G=w[l],A=0;A<U;A++)for(L=x+A*s,N=A*o,P=0;P<k;P++,L++,N++)G[L]=y[N]}}}else for(m=0;m<a.length;m++)if(0!==i[m])for(O=Math.floor(m/F)*f,b=m%F*o,x=O*s+b,y=await M(e,t.littleEndian,n,a[m],i[m]),N=0,L=x,k=Math.min(o,s-b),U=Math.min(f,r-O),S=0;S<c;S++)if(G=w[S],u||I)for(A=0;A<U;A++)for(L=x+A*s,N=o*f*S+A*o,P=0;P<k;P++,L++,N++)G[L]=y[N];else for(A=0;A<U;A++)for(L=x+A*s,N=A*o*c+S,P=0;P<k;P++,L++,N+=c)G[L]=y[N];return{width:s,height:r,pixelType:l,pixels:w}}const O=(e,t,n)=>{const a=l===t.littleEndian,s=T(n,"STRIPOFFSETS");if(void 0===s)return null;const{width:r,height:o,pixelType:f}=R([n]),u=d(n,"SAMPLESPERPIXEL")||t.planes,c=d(n,"PHOTOMETRICINTERPRETATION"),h=r*o,E=d(n,"BITSPERSAMPLE"),I=g(f),p=new I(h*u),w=T(n,"STRIPBYTECOUNTS"),m=d(n,"ROWSPERSTRIP"),M=d(n,"COMPRESSION")??1;let P,O,b,x,L,D,N,U,k,G=m;if(E%8==0)for(P=0;P<s.length;P++){if(L=P*(m*r)*u,G=(P+1)*m>o?o-P*m:m,"u8"===f||"s8"===f||a)8===M||32946===M?(N=new Uint8Array(e,s[P],w[P]),N=A(N),D=N.buffer):6===M?(N=new Uint8Array(e,s[P],w[P]),N=y(N,u,c),D=N.buffer):5===M?(N=i(e,s[P],w[P],t.littleEndian),D=N.buffer):(w[P]!==G*r*u*E/8&&console.log("strip byte counts is different than expected"),D=e.slice(s[P],s[P]+w[P])),D=S(D,E),x=new I(D);else{switch(6===M||8===M||32946===M?(N=new Uint8Array(e,s[P],w[P]),U=A(N),D=U.buffer):(w[P]!==G*r*u*E/8&&console.log("strip byte counts is different than expected"),D=new ArrayBuffer(w[P]),N=new Uint8Array(e,s[P],w[P]),U=new Uint8Array(D)),f){case"u16":case"s16":for(b=0;b<N.length;b+=2)U[b]=N[b+1],U[b+1]=N[b];break;case"u32":case"s32":case"f32":for(b=0;b<N.length;b+=4)U[b]=N[b+3],U[b+1]=N[b+2],U[b+2]=N[b+1],U[b+3]=N[b]}D=S(D,E),x=new I(D)}p.set(x,L)}const F=[];if(1===u)F.push(p);else for(P=0;P<u;P++){for(k=new I(h),O=0;O<h;O++)k[O]=p[O*u+P];F.push(k)}return{width:r,height:o,pixelType:f,pixels:F}},b=(e,t,n)=>{if(!(e&&e.length>0&&t&&n))return null;let a,i,s;const r=e[0].length,l=e.length,o=new Uint8Array(r);for(let f=0;f<l;f++)if(a=e[f],i=t[f],s=n[f],0===f)for(let e=0;e<r;e++)o[e]=a[e]<i||a[e]>s?0:1;else for(let e=0;e<r;e++)o[e]&&(o[e]=a[e]<i||a[e]>s?0:1);return o},x=e=>{if(!e)return null;const t=e.match(/<Item(.*?)Item>/gi);if(!t||0===t.length)return null;const n=new Map;let a,i,s,r,l;for(let p=0;p<t.length;p++)a=t[p],i=a.slice("<Item ".length,a.indexOf(">")),r=a.indexOf("sample="),r>-1&&(l=a.slice(r+'sample="'.length,a.indexOf('"',r+'sample="'.length))),r=a.indexOf("name="),r>-1&&(i=a.slice(r+'name="'.length,a.indexOf('"',r+'name="'.length))),i&&(s=a.slice(a.indexOf(">")+1,a.indexOf("</Item>")).trim(),null!=l?n.has(i)?n.get(i)[l]=s:n.set(i,[s]):n.set(i,s)),l=null;const o=n.get("STATISTICS_MINIMUM"),f=n.get("STATISTICS_MAXIMUM"),u=n.get("STATISTICS_MEAN"),c=n.get("STATISTICS_STDDEV");let h=null;if(o&&f){h=[];for(let e=0;e<o.length;e++)h.push({min:parseFloat(o[e]),max:parseFloat(f[e]),avg:u&&parseFloat(u[e]),stddev:c&&parseFloat(c[e])})}const g=n.get("BandName"),E=n.get("WavelengthMin"),I=n.get("WavelengthMax");let T=null;if(g){T=[];for(let e=0;e<g.length;e++)T.push({BandName:g[e],WavelengthMin:E&&parseFloat(E[e]),WavelengthMax:I&&parseFloat(I[e])})}return{statistics:h,bandProperties:T,dataType:n.get("DataType"),rawMetadata:n}};function L(e,t,n,a=0,i=!1,s=4){if(n.values)return!0;const r=n.type,l=n.valueCount;let o=n.valueOffset,c=[];const h=f[r],g=8*h,E=l*h,I=l*f[r]*8;let T,p;const d=8===s?64:32,w=n.valueOffsets;if(I>d){if(E>(i?e.byteLength:e?e.byteLength-o+a:0))return n.offlineOffsetSize=[o,E],n.values=null,!1}if(I<=d){if(!t)if(d<=32)o>>>=32-I;else{const e=w?.length?w[0]:o>>>0,t=w?.length?w[1]:Math.round((o-e)/u);I<=32?(o=e>>>32-I,w[0]=o):(o=e*2**(32-I)+(t>>>32-I),w[0]=e,w[1]=t>>>32-I)}if(1===l&&g===d)c=[o];else if(64===d){const e=w?.length?w[0]:o>>>0,t=w?.length?w[1]:Math.round((o-e)/u);let n=e,a=32;for(p=1;p<=l;p++){const e=32-g*p%32;if(a<g){const i=n<<e>>>32-a,s=t<<32-a>>>32-a;n=t,c.push(i+s*2**(g-a)),a-=32-(g-a)}else c.push(n<<e>>>32-g),a-=g;0===a&&(a=32,n=t)}}else for(p=1;p<=l;p++){const e=32-g*p;c.push(o<<e>>>32-g)}}else{o-=a,i&&(o=0);for(let n=o;n<o+E;n+=h){switch(r){case 1:case 2:case 7:T=new DataView(e,n,1).getUint8(0);break;case 3:T=new DataView(e,n,2).getUint16(0,t);break;case 4:case 13:T=new DataView(e,n,4).getUint32(0,t);break;case 5:T=new DataView(e,n,4).getUint32(0,t)/new DataView(e,n+4,4).getUint32(0,t);break;case 6:T=new DataView(e,n,1).getInt8(0);break;case 8:T=new DataView(e,n,2).getInt16(0,t);break;case 9:T=new DataView(e,n,4).getInt32(0,t);break;case 10:T=new DataView(e,n,4).getInt32(0,t)/new DataView(e,n+4,4).getInt32(0,t);break;case 11:T=new DataView(e,n,4).getFloat32(0,t);break;case 12:T=new DataView(e,n,8).getFloat64(0,t);break;case 16:case 18:T=G(new DataView(e,n,8),0,t);break;case 17:T=F(new DataView(e,n,8),0,t);break;default:T=null}c.push(T)}}if(2===r){let e="";const t=c;for(c=[],p=0;p<t.length;p++)0===t[p]&&""!==e?(c.push(e),e=""):e+=String.fromCharCode(t[p]);""===e&&0!==c.length||c.push(e)}return n.values=c,!0}function R(e){const t=e[0],n=d(t,"TILEWIDTH"),a=d(t,"TILELENGTH"),i=d(t,"IMAGEWIDTH"),s=d(t,"IMAGELENGTH"),r=d(t,"BITSPERSAMPLE"),l=d(t,"SAMPLESPERPIXEL"),o=d(t,"SAMPLEFORMAT")??1,f=h(o,r),u=D(t),g=I(t,"GDAL_NODATA");let w=null;g?.length&&(w=g.map((e=>parseFloat(e))),w.some((e=>isNaN(e)))&&(w=null));const m=d(t,"COMPRESSION")??1;let S;switch(m){case 1:S="NONE";break;case 2:case 3:case 4:case 32771:S="CCITT";break;case 5:S="LZW";break;case 6:case 7:S="JPEG";break;case 32773:S="PACKBITS";break;case 8:case 32946:S="DEFLATE";break;case 34712:S="JPEG2000";break;case 34887:S="LERC";break;default:S=String(m)}let y=!0,A="";c.has(m)||(y=!1,A+="unsupported tag compression "+m),o>3&&(y=!1,A+="unsupported tag sampleFormat "+o),1!==r&&2!==r&&4!==r&&r%8!=0&&(y=!1,A+="unsupported tag bitsPerSample "+r);const M=p(t,"GEOASCIIPARAMS");let P;if(M){const e=M.split("|").find((e=>e.includes("ESRI PE String = "))),t=e?e.replace("ESRI PE String = ",""):"";P=t.startsWith("COMPD_CS")||t.startsWith("PROJCS")||t.startsWith("GEOGCS")?{wkid:null,wkt:t}:null}const O=T(t,"GEOTIEPOINTS"),b=T(t,"GEOPIXELSCALE"),L=T(t,"GEOTRANSMATRIX"),R=t.has("GEOKEYDIRECTORY")?t.get("GEOKEYDIRECTORY").data:null;let k,G,F=!1,C=!1;if(R){F=2===d(R,"GTRasterTypeGeoKey");const e=d(R,"GTModelTypeGeoKey");if(2===e){const e=d(R,"GeographicTypeGeoKey");e>=1024&&e<=32766&&(P={wkid:e}),P||32767!==e||(C=!0,P={wkid:4326})}else if(1===e){const e=d(R,"ProjectedCSTypeGeoKey");e>=1024&&e<=32766&&(P={wkid:e})}}if(b&&O&&O.length>=6?(k=[b[0],0,O[3]-O[0]*b[0],0,-Math.abs(b[1]),O[4]-O[1]*b[1]],F&&(k[2]-=.5*k[0]+.5*k[1],k[5]-=.5*k[3]+.5*k[4])):L&&16===L.length&&(k=F?[L[0],L[1],L[3]-.5*L[0],L[4],L[5],L[7]-.5*L[5]]:[L[0],L[1],L[3],L[4],L[5],L[7]]),k){const e=[{x:0,y:s},{x:0,y:0},{x:i,y:s},{x:i,y:0}];let t,n=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;for(let i=0;i<e.length;i++)t=E(e[i],k),n=t.x>n?n:t.x,r=t.x<r?r:t.x,a=t.y>a?a:t.y,l=t.y<l?l:t.y;G={xmin:n,xmax:r,ymin:a,ymax:l,spatialReference:P}}else G={xmin:-.5,ymin:.5-s,xmax:i-.5,ymax:.5,spatialReference:P};C&&(G.xmax-G.xmin>400||Math.max(Math.abs(G.xmin),Math.abs(G.xmax))>361)&&(P=null,G.spatialReference=null);const v=N(e);let B,W,H,Y,_;if(v.length>0){H=Math.round(Math.log(i/d(v[0],"IMAGEWIDTH"))/Math.LN2);const e=v[v.length-1];Y=Math.round(Math.log(i/d(e,"IMAGEWIDTH"))/Math.LN2),B=d(e,"TILEWIDTH"),W=d(e,"TILELENGTH")}B=null!=Y&&Y>0?B||n:null,W=null!=Y&&Y>0?W||a:null,n&&(_=[{maxCol:Math.ceil(i/n)-1,maxRow:Math.ceil(s/a)-1,minRow:0,minCol:0}],v.forEach((e=>{_.push({maxCol:Math.ceil(d(e,"IMAGEWIDTH")/d(e,"TILEWIDTH"))-1,maxRow:Math.ceil(d(e,"IMAGELENGTH")/d(e,"TILELENGTH"))-1,minRow:0,minCol:0})})));const K=p(e[0],"GDAL_METADATA"),X=x(K);A+=" "+V({width:i,height:s,tileWidth:n,tileHeight:a,planes:l,ifds:e});return{width:i,height:s,tileWidth:n,tileHeight:a,planes:l,isBSQ:u,pixelType:f,compression:S,noData:w,hasMaskBand:U(e).length===v.length+1,isSupported:y,message:A,extent:G,isPseudoGeographic:C,affine:b?null:k,firstPyramidLevel:H,maximumPyramidLevel:Y,pyramidBlockWidth:B,pyramidBlockHeight:W,tileBoundary:_,metadata:X}}function D(e,t){const n=I(e,"PLANARCONFIGURATION");return n?2===n[0]:!!t&&t.isBSQ}function N(e){return e.filter((e=>1===d(e,"NEWSUBFILETYPE")))}function U(e){return e.filter((e=>{const t=4==(4&(d(e,"NEWSUBFILETYPE")??0)),n=4===d(e,"PHOTOMETRICINTERPRETATION");return t&&n}))}function k(e){const{littleEndian:t,isBigTiff:n,firstIFDPos:a}=v(e);let i=a;const s=[];do{const a=B(e,t,i,0,r.TIFF_TAGS,n?8:4);if(!a.success)break;s.push(a.ifd),i=a.nextIFD}while(i>0);return{...R(s),littleEndian:t,isBigTiff:n,ifds:s,pyramidIFDs:N(s),maskIFDs:U(s)}}function G(e,t,n){const a=e.getUint32(t,n),i=e.getUint32(t+4,n);return n?i*u+a:a*u+i}function F(e,t,n){let a=n?e.getInt32(t,n):e.getUint32(t,n),i=n?e.getUint32(t+4,n):e.getInt32(t+4,n);const s=(n?a:i)>=0?1:-1;n?a*=s:i*=s;return s*(n?i*u+a:a*u+i)}function C(e,t,n,a){return a?G(e,t,n):e.getUint32(t,n)}function v(e){const t=new DataView(e,0,16),n=t.getUint16(0,!1);let a=null;if(18761===n)a=!0;else{if(19789!==n)throw new Error("unexpected endianess byte");a=!1}const i=t.getUint16(2,a);if(42!==i&&43!==i)throw new Error("unexpected tiff identifier");let s=4;const r=43===i;if(r){const e=t.getUint16(s,a);if(s+=2,8!==e)throw new Error("unsupported bigtiff version");if(0!==t.getUint16(s,a))throw new Error("unsupported bigtiff version");s+=2}return{littleEndian:a,isBigTiff:r,firstIFDPos:C(t,s,a,r)}}function B(t,n,a,i=0,s=r.TIFF_TAGS,l=4){const o=w(t,n,a,i,s,l);let f;const u=o.ifd;if(u){if(r.ifdTags.forEach(((e,a)=>{u.has(a)&&(f=u.get(a),f.data=w(t,n,f.valueOffset-i,i,e).ifd)})),u.has("GEOKEYDIRECTORY")){f=u.get("GEOKEYDIRECTORY");const e=f.values;if(e&&e.length>4){const a=e[0]+"."+e[1]+"."+e[2];f.data=w(t,n,f.valueOffset+6-i,i,r.GEO_KEYS,2).ifd,f.data&&f.data.set("GEOTIFFVersion",{id:0,type:2,valueCount:1,valueOffset:null,values:[a]})}}if(u.has("XMP")){f=u.get("XMP");const t=f.values;"number"==typeof t[0]&&7===f.type&&(f.values=[e(new Uint8Array(t))])}}return o}function V(e){const{width:t,height:n,tileHeight:a,tileWidth:i}=e,s=e.planes,r=i?i*a:t*n,l=d(e.ifds[0],"BITSPERSAMPLE");let o="";return r*s>2**30/(l>8?l/8:1)&&(o=i?"tiled tiff exceeding 1 gigabits per tile is not supported":"scanline tiff exceeding 1 gigabits is not supported"),o}async function W(e,t){const{headerInfo:n,ifd:a,offsets:i,sizes:r}=t,l=[];for(let s=0;s<i.length;s++){const t=await M(e,n.littleEndian,a,i[s],r[s]||e.byteLength);l.push(t)}const o=D(a,n),f=d(a,"BITSPERSAMPLE"),u=h(d(a,"SAMPLEFORMAT")??1,f),c=d(a,"SAMPLESPERPIXEL")||n.planes,E=g(u),I=d(a,"TILEWIDTH"),T=d(a,"TILELENGTH"),p=d(a,"COMPRESSION")??1,w=I*T;let m;const S=[];let y=l[0];const A=34887===p;for(let s=0;s<c;s++){if(m=new E(w),o&&A){if(y=l[s],y.length)for(let e=0;e<w;e++)m[e]=y[s][e+s]}else if(y.length)if(o||A&&!o)m=y.slice(w*s,w*(s+1));else for(let e=0;e<w;e++)m[e]=y[e*c+s];S.push(m)}const P=n.noData?n.noData[0]:t.noDataValue,O=n.metadata?n.metadata.statistics:null,x=O?O.map((e=>e.min)):null,L=O?O.map((e=>e.max)):null,R={pixelType:u,width:I,height:T,pixels:S,noDataValue:P};return null!=P?s(R,P):x&&L&&t.applyMinMaxConstraint&&(R.mask=b(S,x,L)),R}async function H(e,t={}){const n=t.pyramidLevel||0,a=t.headerInfo||k(e),{ifds:i,noData:r}=a;if(0===i.length)throw new Error("no valid image file directory");const l=V(a);if(l)throw l;let o=null;const f=-1===n?i[i.length-1]:i[n],u=r??t.noDataValue;return o=a.tileWidth?await P(e,a,f):await O(e,a,f),o?(null!=u&&s(o,u),o):o}export{H as decode,W as decodeTileOrStrip,R as getImageInfo,U as getMaskIFDs,N as getPyramidIFDs,D as isBSQConfig,L as parseFieldValues,k as parseHeader,B as parseIFD,v as parseSignature};
@@ -0,0 +1,5 @@
1
+ /*
2
+ All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
+ See https://js.arcgis.com/4.26/esri/copyright.txt for details.
4
+ */
5
+ const t=9999999e31,e=2e-7,n={u1:[0,1],u2:[0,3],u4:[0,15],u8:[0,255],s8:[-128,127],u16:[0,65535],s16:[-32768,32767],u32:[0,4294967295],s32:[-2147483648,2147483647],f32:[-34028234663852886e22,34028234663852886e22],f64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function s(t){return n[t]??[-34028234663852886e22,34028234663852886e22]}function u(n,u,a){if(n.depthCount&&n.depthCount>1)return;const{pixels:i,statistics:l,pixelType:o}=n,r=i[0].length,f=n.bandMasks??[],c=n.mask??new Uint8Array(r).fill(255),b="f32"===o||"f64"===o,m=s(o);let h=!1;for(let s=0;s<i.length;s++){const n="number"==typeof u?u:u[s];if(null==n)continue;const p=l?.[s].minValue??m[0],N=l?.[s].maxValue??m[1];if(p>n-Number.EPSILON||N<n+Number.EPSILON)continue;const M=f[s]||new Uint8Array(r).fill(255),d=i[s],A=a?.customFloatTolerance;if(b&&0!==A){let s=A;s||(s=Math.abs(n)>=t?e*Math.abs(n):"f32"===o?2**-23:Number.EPSILON);for(let t=0;t<d.length;t++)M[t]&&Math.abs(d[t]-n)<s&&(d[t]=0,M[t]=0,c[t]=0,h=!0)}else for(let t=0;t<d.length;t++)M[t]&&d[t]===n&&(d[t]=0,M[t]=0,c[t]=0,h=!0);f[s]=M}h&&(n.bandMasks=f,n.mask=c),h&&"updateStatistics"in n&&n.updateStatistics()}export{u as convertNoDataToMask,s as getPixelValueRange};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.26/esri/copyright.txt for details.
4
4
  */
5
- import{_ as t}from"../../../chunks/tslib.es6.js";import{isNone as e}from"../../../core/maybe.js";import{property as o}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/accessorSupport/ensureType.js";import"../../../core/arrayUtils.js";import{subclass as s}from"../../../core/accessorSupport/decorators/subclass.js";import r from"./BaseRasterFunction.js";import n from"./ConvolutionFunctionArguments.js";import{ConvolutionKernel as i,convolute as u}from"./convolutionUtils.js";import{pixelTypeRanges as c}from"./stretchUtils.js";const p=25;let l=class extends r{constructor(){super(...arguments),this.functionName="Convolution",this.rasterArgumentNames=["raster"]}_bindSourceRasters(){const{convolutionType:t,rows:e,cols:o,kernel:s}=this.functionArguments;if(!i[t])return{success:!1,supportsGPU:!1,error:`convolution-function: the specified kernel type is not supported ${t}`};if(t!==i.None&&e*o!==s.length)return{success:!1,supportsGPU:!1,error:"convolution-function: the specified rows and cols do not match the length of the kernel"};const r=this.sourceRasterInfos[0];this.outputPixelType=this._getOutputPixelType(r.pixelType);const n=r.clone();n.pixelType=this.outputPixelType;const u=[i.None,i.Sharpen,i.Sharpen2,i.Sharpening3x3,i.Sharpening5x5];"u8"===this.outputPixelType||u.includes(t)||(n.statistics=null,n.histograms=null),this.rasterInfo=n;return{success:!0,supportsGPU:s.length<=p}}_processPixels(t){const o=t.pixelBlocks?.[0];if(e(o)||this.functionArguments.convolutionType===i.None)return o;let{kernel:s,rows:r,cols:n}=this.functionArguments;const c=s.reduce(((t,e)=>t+e));return 0!==c&&1!==c&&(s=s.map((t=>t/c))),u(o,{kernel:s,rows:r,cols:n,outputPixelType:this.outputPixelType})}_getWebGLParameters(){let{kernel:t}=this.functionArguments;const e=t.reduce(((t,e)=>t+e));0!==e&&1!==e&&(t=t.map((t=>t/e)));const o=new Float32Array(p);return o.set(t),{kernelRows:this.functionArguments.rows,kernelCols:this.functionArguments.cols,kernel:o,clampRange:c[this.outputPixelType]}}};t([o({json:{write:!0,name:"rasterFunction"}})],l.prototype,"functionName",void 0),t([o({type:n,json:{write:!0,name:"rasterFunctionArguments"}})],l.prototype,"functionArguments",void 0),t([o()],l.prototype,"rasterArgumentNames",void 0),l=t([s("esri.layers.support.rasterFunctions.ConvolutionFunction")],l);const a=l;export{a as default};
5
+ import{_ as t}from"../../../chunks/tslib.es6.js";import{isNone as e}from"../../../core/maybe.js";import{property as o}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/accessorSupport/ensureType.js";import"../../../core/arrayUtils.js";import{subclass as s}from"../../../core/accessorSupport/decorators/subclass.js";import{getPixelValueRange as r}from"../rasterFormats/pixelRangeUtils.js";import n from"./BaseRasterFunction.js";import i from"./ConvolutionFunctionArguments.js";import{ConvolutionKernel as u,convolute as c}from"./convolutionUtils.js";const p=25;let l=class extends n{constructor(){super(...arguments),this.functionName="Convolution",this.rasterArgumentNames=["raster"]}_bindSourceRasters(){const{convolutionType:t,rows:e,cols:o,kernel:s}=this.functionArguments;if(!u[t])return{success:!1,supportsGPU:!1,error:`convolution-function: the specified kernel type is not supported ${t}`};if(t!==u.None&&e*o!==s.length)return{success:!1,supportsGPU:!1,error:"convolution-function: the specified rows and cols do not match the length of the kernel"};const r=this.sourceRasterInfos[0];this.outputPixelType=this._getOutputPixelType(r.pixelType);const n=r.clone();n.pixelType=this.outputPixelType;const i=[u.None,u.Sharpen,u.Sharpen2,u.Sharpening3x3,u.Sharpening5x5];"u8"===this.outputPixelType||i.includes(t)||(n.statistics=null,n.histograms=null),this.rasterInfo=n;return{success:!0,supportsGPU:s.length<=p}}_processPixels(t){const o=t.pixelBlocks?.[0];if(e(o)||this.functionArguments.convolutionType===u.None)return o;let{kernel:s,rows:r,cols:n}=this.functionArguments;const i=s.reduce(((t,e)=>t+e));return 0!==i&&1!==i&&(s=s.map((t=>t/i))),c(o,{kernel:s,rows:r,cols:n,outputPixelType:this.outputPixelType})}_getWebGLParameters(){let{kernel:t}=this.functionArguments;const e=t.reduce(((t,e)=>t+e));0!==e&&1!==e&&(t=t.map((t=>t/e)));const o=new Float32Array(p);return o.set(t),{kernelRows:this.functionArguments.rows,kernelCols:this.functionArguments.cols,kernel:o,clampRange:r(this.outputPixelType)}}};t([o({json:{write:!0,name:"rasterFunction"}})],l.prototype,"functionName",void 0),t([o({type:i,json:{write:!0,name:"rasterFunctionArguments"}})],l.prototype,"functionArguments",void 0),t([o()],l.prototype,"rasterArgumentNames",void 0),l=t([s("esri.layers.support.rasterFunctions.ConvolutionFunction")],l);const a=l;export{a as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.26/esri/copyright.txt for details.
4
4
  */
5
- import{isNone as t,assertIsSome as e,isSome as n,unwrap as i}from"../../../core/maybe.js";import r from"../PixelBlock.js";import{stretchTypeFunctionEnum as s}from"../../../renderers/support/stretchRendererUtils.js";const o={u1:[0,1],u2:[0,3],u4:[0,15],u8:[0,255],s8:[-128,127],u16:[0,65535],s16:[-32768,32767],u32:[0,4294967295],s32:[-2147483648,2147483647],f32:[-34e38,34e38],f64:[-Number.MAX_VALUE,Number.MAX_VALUE]},a=1,f=[.299,.587,.114];function l(t,e=256){e=Math.min(e,256);const{size:n,counts:i}=t,r=new Uint8Array(n),s=i.reduce(((t,n)=>t+n/e),0);let o=0,a=0,f=0,l=s;for(let u=0;u<n;u++)if(f+=i[u],!(u<n-1&&f+i[u+1]<l)){for(;o<e-1&&l<f;)o++,l+=s;for(let t=a;t<=u;t++)r[t]=o;a=u+1}for(let u=a;u<n;u++)r[u]=e-1;return r}function u(t){const{minCutOff:e,maxCutOff:n,gamma:i,pixelType:r}=t,s=t.outMin||0,o=t.outMax||255;if(!["u8","u16","s8","s16"].includes(r))return null;const a=e.length;let f,l,u=0;"s8"===r?u=-127:"s16"===r&&(u=-32767);let c=256;["u16","s16"].includes(r)&&(c=65536);const h=[],p=o-s;for(f=0;f<a;f++)h[f]=n[f]-e[f],n[f],e[f];let g;const x=[];let M,y,b;if(i&&i.length>=a){const t=d(a,i);for(f=0;f<a;f++){for(b=[],l=0;l<c;l++)M=l+u,g=(M-e[f])/h[f],y=1,i[f]>1&&(y-=(1/p)**(g*t[f])),M<n[f]&&M>e[f]?b[l]=Math.floor(y*p*g**(1/i[f]))+s:M>=n[f]?b[l]=o:b[l]=s;x[f]=b}}else for(f=0;f<a;f++){for(b=[],l=0;l<c;l++)M=l+u,M<=e[f]?b[l]=s:M>=n[f]?b[l]=o:b[l]=Math.floor((M-e[f])/h[f]*p)+s;x[f]=b}if(null!=t.contrastOffset){const e=m(t.contrastOffset,t.brightnessOffset);for(f=0;f<a;f++)for(b=x[f],l=0;l<c;l++)b[l]=e[b[l]]}return{lut:x,offset:u}}function m(t,e){const n=Math.min(Math.max(t,-100),100),i=Math.min(Math.max(e??0,-100),100),r=255,s=128;let o=0,a=0;const f=new Uint8Array(256);for(o=0;o<256;o++)n>0&&n<100?a=(200*o-100*r+2*r*i)/(2*(100-n))+s:n<=0&&n>-100?a=(200*o-100*r+2*r*i)*(100+n)/2e4+s:100===n?(a=200*o-100*r+(r+1)*(100-n)+2*r*i,a=a>0?r:0):-100===n&&(a=s),f[o]=a>r?r:a<0?0:a;return f}function c(t,e,n){const i=[];for(let r=0;r<e.length;r++){let s=0,o=0,a=0;"min"in e[r]?({min:s,max:o,avg:a}=e[r]):[s,o,a]=e[r];let l=a??0;"u8"!==t&&(l=255*(l-s)/(o-s)),n&&(l*=f[r]),i.push(h(l))}return i}function h(t){if(t<=0||t>=255)return a;let e=0;150!==t&&(e=t<=150?45*Math.cos(.01047*t):17*Math.sin(.021*t));const n=255,i=t+e,r=Math.log(t/n),s=Math.log(i/n);if(0===s)return a;const o=r/s;return isNaN(o)?a:Math.min(9.9,Math.max(.01,o))}function p(n){if(t(n)||!n.pixels?.length)return null;n.statistics||n.updateStatistics();const{pixels:i,mask:r,pixelType:s,statistics:o}=n,a=n.width*n.height,f=i.length;let l,u,m,c,h;const p=[],g=[];let x,M,d,y,b,O,C,k,z,A;const v=256;for(c=0;c<f;c++){if(x=new Uint32Array(v),d=i[c],"u8"===s)if(l=-.5,u=255.5,r)for(h=0;h<a;h++)r[h]&&x[d[h]]++;else for(h=0;h<a;h++)x[d[h]]++;else{if(e(o),l=o[c].minValue,u=o[c].maxValue,m=(u-l)/v,M=new Uint32Array(v+1),r)for(h=0;h<a;h++)r[h]&&M[Math.floor((d[h]-l)/m)]++;else for(h=0;h<a;h++)M[Math.floor((d[h]-l)/m)]++;for(h=0;h<255;h++)x[h]=M[h];x[255]=M[255]+M[256]}for(p.push({min:l,max:u,size:v,counts:x}),y=0,b=0,k=0,h=0;h<v;h++)y+=x[h],b+=h*x[h];for(z=b/y,h=0;h<v;h++)k+=x[h]*(h-z)**2;A=Math.sqrt(k/(y-1)),m=(u-l)/v,O=(z+.5)*m+l,C=A*m,g.push({min:l,max:u,avg:O,stddev:C})}return{statistics:g,histograms:p}}function g(t){const e=[];for(let n=0;n<t.length;n++){const{min:i,max:r,size:s,counts:o}=t[n];let a=0,f=0;for(let t=0;t<s;t++)a+=o[t],f+=t*o[t];const l=f/a;let u=0;for(let t=0;t<s;t++)u+=o[t]*(t-l)**2;const m=(r-i)/s,c=(l+.5)*m+i,h=Math.sqrt(u/(a-1))*m;e.push({min:i,max:r,avg:c,stddev:h})}return e}function x(t,r){const{pixelBlock:a,bandIds:f,returnHistogramLut:u,rasterInfo:m}=r;let c=null,h=null,g=t.stretchType;if("number"==typeof g&&(g=s[g]),t.dra)if("minMax"===g&&n(a)&&a.statistics)c=a.statistics.map((t=>[t.minValue,t.maxValue,0,0]));else{const t=p(a);c=n(t)?t.statistics:null,h=n(t)?t.histograms:null}else c=t.statistics?.length>0?t.statistics:i(m.statistics),h=t.histograms||i(m.histograms);"percentClip"!==g&&"histogramEqualization"!==g||h?.length||(g="minMax");const x=c?.length||h?.length||m.bandCount,d=[],y=[];let b,O,C,k,z,A,v,w,U,T,E,L;if(c&&!Array.isArray(c[0])&&(c=c.map((t=>[t.min,t.max,t.avg,t.stddev]))),!c?.length){const[t,e]=o[m.pixelType]||o.f32;for(c=[],w=0;w<x;w++)c.push([t,e,1,1]);"standardDeviation"===g&&(g="minMax")}switch(g){case"none":{const t=o[m.pixelType]||o.f32;for(w=0;w<x;w++)d[w]=t[0],y[w]=t[1]}break;case"minMax":for(w=0;w<x;w++)d[w]=c[w][0],y[w]=c[w][1];break;case"standardDeviation":for(w=0;w<x;w++)d[w]=c[w][2]-t.numberOfStandardDeviations*c[w][3],y[w]=c[w][2]+t.numberOfStandardDeviations*c[w][3],d[w]<c[w][0]&&(d[w]=c[w][0]),y[w]>c[w][1]&&(y[w]=c[w][1]);break;case"histogramEqualization":for(e(h),w=0;w<x;w++)d[w]=h[w].min,y[w]=h[w].max;break;case"percentClip":for(e(h),w=0;w<h.length;w++){for(b=h[w],z=new Uint32Array(b.size),k=[...b.counts],k.length>=20&&(k[0]=k[1]=k[2]=k[k.length-1]=k[k.length-2]=0),C=0,O=(b.max-b.min)/b.size,v=-.5===b.min&&1===O?.5:0,U=0;U<b.size;U++)C+=k[U],z[U]=C;for(A=(t.minPercent||0)*C/100,U=0;U<b.size;U++)if(z[U]>A){d[w]=b.min+O*(U+v);break}for(A=(1-(t.maxPercent||0)/100)*C,U=b.size-2;U>=0;U--)if(z[U]<A){y[w]=b.min+O*(U+2-v);break}}break;default:for(w=0;w<x;w++)d[w]=c[w][0],y[w]=c[w][1]}"histogramEqualization"===g?(e(h),E=h[0].size||256,T=0,u&&(L=h.map((t=>l(t))))):(E=t.max||255,T=t.min||0);return M({minCutOff:d,maxCutOff:y,outMax:E,outMin:T,histogramLut:L},f)}function M(t,e){if(null==e||0===e.length)return t;const n=Math.max.apply(null,e),{minCutOff:i,maxCutOff:r,outMin:s,outMax:o,histogramLut:a}=t;return i.length===e.length||i.length<=n?t:{minCutOff:e.map((t=>i[t])),maxCutOff:e.map((t=>r[t])),histogramLut:a?e.map((t=>a[t])):null,outMin:s,outMax:o}}function d(t,e){const n=new Float32Array(t);for(let i=0;i<t;i++)e[i]>1?e[i]>2?n[i]=6.5+(e[i]-2)**2.5:n[i]=6.5+100*(2-e[i])**4:n[i]=1;return n}function y(e,n){if(t(e)||!e.pixels?.length)return e;const{mask:i,width:s,height:o,pixels:a}=e,{minCutOff:f,maxCutOff:l,gamma:u}=n,m=n.outMin||0,c=n.outMax||255,h=s*o,p=n.outputPixelType||"u8",g=e.pixels.map((()=>r.createEmptyBand(p,h))),x=g.length;let M,y,b,O,C;const k=c-m,z=[];for(M=0;M<x;M++)z[M]=l[M]-f[M],l[M],f[M];if(u&&u.length>=x){const t=d(x,u);if(null!=i){for(y=0;y<h;y++)if(i[y])for(M=0;M<x;M++)b=a[M][y],C=(b-f[M])/z[M],O=1,u[M]>1&&(O-=(1/k)**(C*t[M])),b<l[M]&&b>f[M]?g[M][y]=Math.floor(O*k*C**(1/u[M]))+m:b>=l[M]?g[M][y]=c:g[M][y]=m}else for(y=0;y<h;y++)for(M=0;M<x;M++)b=a[M][y],C=(b-f[M])/z[M],O=1,u[M]>1&&(O-=(1/k)**(C*t[M])),b<l[M]&&b>f[M]?g[M][y]=Math.floor(O*k*C**(1/u[M]))+m:b>=l[M]?g[M][y]=c:g[M][y]=m}else if(null!=i){for(y=0;y<h;y++)if(i[y])for(M=0;M<x;M++)b=a[M][y],b<l[M]&&b>f[M]?g[M][y]=Math.floor((b-f[M])/z[M]*k)+m:b>=l[M]?g[M][y]=c:g[M][y]=m}else for(y=0;y<h;y++)for(M=0;M<x;M++)b=a[M][y],b<l[M]&&b>f[M]?g[M][y]=Math.floor((b-f[M])/z[M]*k)+m:b>=l[M]?g[M][y]=c:g[M][y]=m;const A=new r({width:s,height:o,mask:i,pixels:g,pixelType:p});return A.updateStatistics(),A}export{d as computeGammaCorrection,c as computeGammaValues,m as createContrastBrightnessLUT,l as createHistogramEqualizationLUT,u as createStretchLUT,g as estimateStatisticsFromHistograms,p as estimateStatisticsHistograms,x as getStretchCutoff,o as pixelTypeRanges,y as stretch};
5
+ import{isNone as t,assertIsSome as n,isSome as e,unwrap as i}from"../../../core/maybe.js";import r from"../PixelBlock.js";import{getPixelValueRange as s}from"../rasterFormats/pixelRangeUtils.js";import{stretchTypeFunctionEnum as o}from"../../../renderers/support/stretchRendererUtils.js";const a=1,l=[.299,.587,.114];function f(t,n=256){n=Math.min(n,256);const{size:e,counts:i}=t,r=new Uint8Array(e),s=i.reduce(((t,e)=>t+e/n),0);let o=0,a=0,l=0,f=s;for(let u=0;u<e;u++)if(l+=i[u],!(u<e-1&&l+i[u+1]<f)){for(;o<n-1&&f<l;)o++,f+=s;for(let t=a;t<=u;t++)r[t]=o;a=u+1}for(let u=a;u<e;u++)r[u]=n-1;return r}function u(t){const{minCutOff:n,maxCutOff:e,gamma:i,pixelType:r}=t,s=t.outMin||0,o=t.outMax||255;if(!["u8","u16","s8","s16"].includes(r))return null;const a=n.length;let l,f,u=0;"s8"===r?u=-127:"s16"===r&&(u=-32767);let c=256;["u16","s16"].includes(r)&&(c=65536);const h=[],p=o-s;for(l=0;l<a;l++)h[l]=e[l]-n[l],e[l],n[l];let g;const x=[];let M,y,O;if(i&&i.length>=a){const t=d(a,i);for(l=0;l<a;l++){for(O=[],f=0;f<c;f++)M=f+u,g=(M-n[l])/h[l],y=1,i[l]>1&&(y-=(1/p)**(g*t[l])),M<e[l]&&M>n[l]?O[f]=Math.floor(y*p*g**(1/i[l]))+s:M>=e[l]?O[f]=o:O[f]=s;x[l]=O}}else for(l=0;l<a;l++){for(O=[],f=0;f<c;f++)M=f+u,M<=n[l]?O[f]=s:M>=e[l]?O[f]=o:O[f]=Math.floor((M-n[l])/h[l]*p)+s;x[l]=O}if(null!=t.contrastOffset){const n=m(t.contrastOffset,t.brightnessOffset);for(l=0;l<a;l++)for(O=x[l],f=0;f<c;f++)O[f]=n[O[f]]}return{lut:x,offset:u}}function m(t,n){const e=Math.min(Math.max(t,-100),100),i=Math.min(Math.max(n??0,-100),100),r=255,s=128;let o=0,a=0;const l=new Uint8Array(256);for(o=0;o<256;o++)e>0&&e<100?a=(200*o-100*r+2*r*i)/(2*(100-e))+s:e<=0&&e>-100?a=(200*o-100*r+2*r*i)*(100+e)/2e4+s:100===e?(a=200*o-100*r+(r+1)*(100-e)+2*r*i,a=a>0?r:0):-100===e&&(a=s),l[o]=a>r?r:a<0?0:a;return l}function c(t,n,e){const i=[];for(let r=0;r<n.length;r++){let s=0,o=0,a=0;"min"in n[r]?({min:s,max:o,avg:a}=n[r]):[s,o,a]=n[r];let f=a??0;"u8"!==t&&(f=255*(f-s)/(o-s)),e&&(f*=l[r]),i.push(h(f))}return i}function h(t){if(t<=0||t>=255)return a;let n=0;150!==t&&(n=t<=150?45*Math.cos(.01047*t):17*Math.sin(.021*t));const e=255,i=t+n,r=Math.log(t/e),s=Math.log(i/e);if(0===s)return a;const o=r/s;return isNaN(o)?a:Math.min(9.9,Math.max(.01,o))}function p(e){if(t(e)||!e.pixels?.length)return null;e.statistics||e.updateStatistics();const{pixels:i,mask:r,pixelType:s,statistics:o}=e,a=e.width*e.height,l=i.length;let f,u,m,c,h;const p=[],g=[];let x,M,d,y,O,b,C,k,z,v;const w=256;for(c=0;c<l;c++){if(x=new Uint32Array(w),d=i[c],"u8"===s)if(f=-.5,u=255.5,r)for(h=0;h<a;h++)r[h]&&x[d[h]]++;else for(h=0;h<a;h++)x[d[h]]++;else{if(n(o),f=o[c].minValue,u=o[c].maxValue,m=(u-f)/w,M=new Uint32Array(w+1),r)for(h=0;h<a;h++)r[h]&&M[Math.floor((d[h]-f)/m)]++;else for(h=0;h<a;h++)M[Math.floor((d[h]-f)/m)]++;for(h=0;h<255;h++)x[h]=M[h];x[255]=M[255]+M[256]}for(p.push({min:f,max:u,size:w,counts:x}),y=0,O=0,k=0,h=0;h<w;h++)y+=x[h],O+=h*x[h];for(z=O/y,h=0;h<w;h++)k+=x[h]*(h-z)**2;v=Math.sqrt(k/(y-1)),m=(u-f)/w,b=(z+.5)*m+f,C=v*m,g.push({min:f,max:u,avg:b,stddev:C})}return{statistics:g,histograms:p}}function g(t){const n=[];for(let e=0;e<t.length;e++){const{min:i,max:r,size:s,counts:o}=t[e];let a=0,l=0;for(let t=0;t<s;t++)a+=o[t],l+=t*o[t];const f=l/a;let u=0;for(let t=0;t<s;t++)u+=o[t]*(t-f)**2;const m=(r-i)/s,c=(f+.5)*m+i,h=Math.sqrt(u/(a-1))*m;n.push({min:i,max:r,avg:c,stddev:h})}return n}function x(t,r){const{pixelBlock:a,bandIds:l,returnHistogramLut:u,rasterInfo:m}=r;let c=null,h=null,g=t.stretchType;if("number"==typeof g&&(g=o[g]),t.dra)if("minMax"===g&&e(a)&&a.statistics)c=a.statistics.map((t=>[t.minValue,t.maxValue,0,0]));else{const t=p(a);c=e(t)?t.statistics:null,h=e(t)?t.histograms:null}else c=t.statistics?.length>0?t.statistics:i(m.statistics),h=t.histograms||i(m.histograms);"percentClip"!==g&&"histogramEqualization"!==g||h?.length||(g="minMax");const x=c?.length||h?.length||m.bandCount,d=[],y=[];let O,b,C,k,z,v,w,A,U;c&&!Array.isArray(c[0])&&(c=c.map((t=>[t.min,t.max,t.avg,t.stddev])));const[T,q]=s(m.pixelType);if(!c?.length){for(c=[],A=0;A<x;A++)c.push([T,q,1,1]);"standardDeviation"===g&&(g="minMax")}switch(g){case"none":for(A=0;A<x;A++)d[A]=T,y[A]=q;break;case"minMax":for(A=0;A<x;A++)d[A]=c[A][0],y[A]=c[A][1];break;case"standardDeviation":for(A=0;A<x;A++)d[A]=c[A][2]-t.numberOfStandardDeviations*c[A][3],y[A]=c[A][2]+t.numberOfStandardDeviations*c[A][3],d[A]<c[A][0]&&(d[A]=c[A][0]),y[A]>c[A][1]&&(y[A]=c[A][1]);break;case"histogramEqualization":for(n(h),A=0;A<x;A++)d[A]=h[A].min,y[A]=h[A].max;break;case"percentClip":for(n(h),A=0;A<h.length;A++){for(O=h[A],z=new Uint32Array(O.size),k=[...O.counts],k.length>=20&&(k[0]=k[1]=k[2]=k[k.length-1]=k[k.length-2]=0),C=0,b=(O.max-O.min)/O.size,w=-.5===O.min&&1===b?.5:0,U=0;U<O.size;U++)C+=k[U],z[U]=C;for(v=(t.minPercent||0)*C/100,U=0;U<O.size;U++)if(z[U]>v){d[A]=O.min+b*(U+w);break}for(v=(1-(t.maxPercent||0)/100)*C,U=O.size-2;U>=0;U--)if(z[U]<v){y[A]=O.min+b*(U+2-w);break}}break;default:for(A=0;A<x;A++)d[A]=c[A][0],y[A]=c[A][1]}let j,D,E;"histogramEqualization"===g?(n(h),D=h[0].size||256,j=0,u&&(E=h.map((t=>f(t))))):(D=t.max||255,j=t.min||0);return M({minCutOff:d,maxCutOff:y,outMax:D,outMin:j,histogramLut:E},l)}function M(t,n){if(null==n||0===n.length)return t;const e=Math.max.apply(null,n),{minCutOff:i,maxCutOff:r,outMin:s,outMax:o,histogramLut:a}=t;return i.length===n.length||i.length<=e?t:{minCutOff:n.map((t=>i[t])),maxCutOff:n.map((t=>r[t])),histogramLut:a?n.map((t=>a[t])):null,outMin:s,outMax:o}}function d(t,n){const e=new Float32Array(t);for(let i=0;i<t;i++)n[i]>1?n[i]>2?e[i]=6.5+(n[i]-2)**2.5:e[i]=6.5+100*(2-n[i])**4:e[i]=1;return e}function y(n,e){if(t(n)||!n.pixels?.length)return n;const{mask:i,width:s,height:o,pixels:a}=n,{minCutOff:l,maxCutOff:f,gamma:u}=e,m=e.outMin||0,c=e.outMax||255,h=s*o,p=e.outputPixelType||"u8",g=n.pixels.map((()=>r.createEmptyBand(p,h))),x=g.length;let M,y,O,b,C;const k=c-m,z=[];for(M=0;M<x;M++)z[M]=f[M]-l[M],f[M],l[M];if(u&&u.length>=x){const t=d(x,u);if(null!=i){for(y=0;y<h;y++)if(i[y])for(M=0;M<x;M++)O=a[M][y],C=(O-l[M])/z[M],b=1,u[M]>1&&(b-=(1/k)**(C*t[M])),O<f[M]&&O>l[M]?g[M][y]=Math.floor(b*k*C**(1/u[M]))+m:O>=f[M]?g[M][y]=c:g[M][y]=m}else for(y=0;y<h;y++)for(M=0;M<x;M++)O=a[M][y],C=(O-l[M])/z[M],b=1,u[M]>1&&(b-=(1/k)**(C*t[M])),O<f[M]&&O>l[M]?g[M][y]=Math.floor(b*k*C**(1/u[M]))+m:O>=f[M]?g[M][y]=c:g[M][y]=m}else if(null!=i){for(y=0;y<h;y++)if(i[y])for(M=0;M<x;M++)O=a[M][y],O<f[M]&&O>l[M]?g[M][y]=Math.floor((O-l[M])/z[M]*k)+m:O>=f[M]?g[M][y]=c:g[M][y]=m}else for(y=0;y<h;y++)for(M=0;M<x;M++)O=a[M][y],O<f[M]&&O>l[M]?g[M][y]=Math.floor((O-l[M])/z[M]*k)+m:O>=f[M]?g[M][y]=c:g[M][y]=m;const v=new r({width:s,height:o,mask:i,pixels:g,pixelType:p});return v.updateStatistics(),v}export{d as computeGammaCorrection,c as computeGammaValues,m as createContrastBrightnessLUT,f as createHistogramEqualizationLUT,u as createStretchLUT,g as estimateStatisticsFromHistograms,p as estimateStatisticsHistograms,x as getStretchCutoff,y as stretch};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcgis/core",
3
- "version": "4.26.0-next.20230113",
3
+ "version": "4.26.0-next.20230115",
4
4
  "homepage": "https://js.arcgis.com",
5
5
  "description": "ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API",
6
6
  "keywords": [
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.26/esri/copyright.txt for details.
4
4
  */
5
- import e from"../../Color.js";import"../../rasterRenderers.js";import{isSome as t,unwrap as n,isNone as a}from"../../core/maybe.js";import{getMetersPerUnitForSR as r}from"../../core/unitUtils.js";import s from"../../layers/support/Field.js";import o from"../../layers/support/RasterInfo.js";import i from"../FlowRenderer.js";import l from"./AuthoringInfo.js";import u from"./ClassBreakInfo.js";import{PREDEFINED_JSON_COLOR_RAMPS as m,convertColorRampToColormap as c}from"./colorRampUtils.js";import f from"./UniqueValueInfo.js";import p from"../../rest/support/ClassBreaksDefinition.js";import{createGenerateRendererClassBreaks as d}from"../../rest/support/generateRendererUtils.js";import b from"../../rest/support/MultipartColorRamp.js";import h from"../RasterStretchRenderer.js";import y from"../UniqueValueRenderer.js";import g from"../RasterColormapRenderer.js";import v from"../RasterShadedReliefRenderer.js";import C from"../ClassBreaksRenderer.js";import M from"../VectorFieldRenderer.js";const w=.25,x=b.fromJSON({type:"multipart",colorRamps:[{fromColor:[0,0,255],toColor:[0,255,255]},{fromColor:[0,255,255],toColor:[255,255,0]},{fromColor:[255,255,0],toColor:[255,0,0]}]}),T=b.fromJSON(m[0]),R=new Set(["scientific","standard-time","vector-uv","vector-magdir","vector-u","vector-v","vector-magnitude","vector-direction"]);function j(e,n){const{attributeTable:a,colormap:r}=e;if(K(e)){const n=Y(e);if(t(n))return n}if(t(r)){const n=U(e);if(t(n))return n}if(t(a)){const n=F(e);if(t(n))return n}return I(e,n)}function k(e,t=!1){const n=["raster-stretch"];return O(e)&&n.push("raster-colormap"),W(e)&&n.push("unique-value"),J(e,t)&&n.push("class-breaks"),A(e)&&n.push("raster-shaded-relief"),K(e)&&n.push("vector-field"),Q(e)&&n.push("flow"),n}function V(e,t,n){const a=["nearest","bilinear","cubic","majority"].find((e=>e===n?.toLowerCase()));if("Map"===t)return a??"bilinear";if("standard-time"===e.dataType)return a??"nearest";return"thematic"===e.dataType||e.attributeTable||e.colormap?"nearest"===a||"majority"===a?a:"nearest":a??"bilinear"}function I(e,a){e=S(e,a?.variableName);const{bandCount:r}=e;let{bandIds:s,stretchType:o}=a||{};s?.some((e=>e>=r))&&(s=null);let i=n(e.statistics),l=n(e.histograms);r>1?(s=s?.length?s:L(e),i=null==i?null:s?.map((e=>i[e])),l=null==l?null:s?.map((e=>l[e]))):s=[0],null==o&&(o=q(e));let u=!1;switch(o){case"none":u=!1;break;case"percent-clip":u=!l?.length;break;default:u=!i?.length}const{dataType:m}=e,c=1===s?.length&&R.has(m)?x:null,f=new h({stretchType:o,dynamicRangeAdjustment:u,colorRamp:c,outputMin:0,outputMax:255,gamma:1===s?.length?[1]:[1,1,1],useGamma:!1});return"percent-clip"===o?f.maxPercent=f.minPercent=w:"standard-deviation"===o&&(f.numberOfStandardDeviations=2),u||!t(e.multidimensionalInfo)&&!a?.includeStatisticsInStretch||("percent-clip"===o?f.histograms=l:"min-max"!==o&&"standard-deviation"!==o||(f.statistics=i)),f}function S(e,a){if(!a)return e;let r=n(e.statistics),s=n(e.histograms);const{multidimensionalInfo:i}=e;if(a&&t(i)){const e=i.variables.find((e=>e.name===a));if(e){const{statistics:t,histograms:n}=e;t?.length&&(r=t),n?.length&&(s=n)}}return o.fromJSON({...e.toJSON(),statistics:r,histograms:s})}function L(e){const t=e.bandCount;if(1===t)return null;if(2===t)return[0];const n=e.keyProperties&&e.keyProperties.BandProperties;let a;if(n&&n.length===t){const{red:e,green:t,blue:r,nir:s}=E(n);null!=e&&null!=t&&null!=r?a=[e,t,r]:null!=s&&null!=e&&null!=t&&(a=[s,e,t])}return!a&&t>=3&&(a=[0,1,2]),a}function B(e,t){const n=e.keyProperties&&e.keyProperties.BandProperties;return(t=t?.length?t:Array.from(Array(e.bandCount).keys())).map((t=>n&&n.length===e.bandCount&&n[t]&&n[t].BandName||"band_"+(t+1)))}function E(e){const t={};for(let n=0;n<e.length;n++){const a=e[n],r=a.BandName?.toLowerCase();if("red"===r)t.red=n;else if("green"===r)t.green=n;else if("blue"===r)t.blue=n;else if("nearinfrared"===r||"nearinfrared_1"===r||"nir"===r)t.nir=n;else if(a.WavelengthMax&&a.WavelengthMin){const e=a.WavelengthMin,r=a.WavelengthMax;null==t.blue&&e>=410&&e<=480&&r>=480&&r<=540?t.blue=n:null==t.green&&e>=490&&e<=560&&r>=560&&r<=610?t.green=n:null==t.red&&e>=595&&e<=670&&r>=660&&r<=730?t.red=n:null==t.nir&&e>=700&&e<=860&&r>=800&&r<=950&&(t.nir=n)}}return t}function q(e){let n="percent-clip";const{pixelType:a,dataType:r,histograms:s,statistics:o}=e;return"u8"!==a||"processed"!==r&&t(s)&&t(o)?"u8"===a||"elevation"===r||R.has(r)?n="min-max":t(s)?n="percent-clip":t(o)&&(n="min-max"):n="none",n}function F(n,a,r,s){if(!W(n,a))return null;const{attributeTable:o,statistics:i}=n,u=N(o,a),m=z(o,"red"),p=z(o,"green"),d=z(o,"blue"),b=new l,h=[],g=new Set,v=!!(m&&p&&d);if(t(o))o.features.forEach((t=>{const n=t.attributes[u.name];if(!g.has(t.attributes[u.name])&&null!=n){g.add(n);const a=v&&("single"===m.type||"double"===m.type)&&("single"===p.type||"double"===p.type)&&("single"===d.type||"double"===d.type)&&!o.features.some((e=>e.attributes[m.name]>1||e.attributes[p.name]>1||e.attributes[d.name]>1)),r=a?255:1;h.push(new f({value:t.attributes[u.name],label:t.attributes[u.name]+"",symbol:{type:"simple-fill",style:"solid",outline:null,color:new e(v?[t.attributes[m.name]*r,t.attributes[p.name]*r,t.attributes[d.name]*r,1]:[0,0,0,0])}}))}}));else if(i?.[0])for(let t=i[0].min;t<=i[0].max;t++)h.push(new f({value:t,label:t.toString(),symbol:{type:"simple-fill",style:"solid",outline:null,color:new e([0,0,0,0])}}));if(h.sort(((e,t)=>e.value&&"string"==typeof e.value.valueOf()?0:e.value>t.value?1:-1)),!v){const t=c(T,{numColors:h.length});h.forEach(((n,a)=>n.symbol.color=new e(t[a].slice(1,4)))),b.colorRamp=T}if(r||s){const t=r||c(s,{numColors:h.length}).map((e=>e.slice(1)));h.forEach(((n,a)=>n.symbol.color=new e(t[a]))),b.colorRamp=s}return new y({field:u.name,uniqueValueInfos:h,authoringInfo:b})}function N(e,n,a){let r;return t(e)?(r=n?e.fields.find((e=>n.toLowerCase()===e.name.toLowerCase())):P(e.fields),r||(a||(r=e.fields.find((e=>"string"===e.type))),r||(r=z(e,"value")))):r=new s({name:"value"}),r}function P(e){let t;for(let n=0;n<e.length;n++){const a=e[n].name.toLowerCase();if("string"===e[n].type){if(a.startsWith("class")){t=e[n];break}null==t&&(a.endsWith("name")||a.endsWith("type"))&&(t=e[n])}}return t}function z(e,t){return a(e)?null:e.fields.find((e=>e.name.toLowerCase()===t))}function W(e,t){const{attributeTable:n,bandCount:r}=e;if(a(n)&&H(e))return!0;if(a(n)||r>1)return!1;if(t){if(null==n.fields.find((e=>e.name.toLowerCase()===t.toLowerCase())))return!1}return!0}function O(e){const{bandCount:n,colormap:a}=e;return t(a)&&a.length>0&&1===n}function U(e){if(!O(e))return null;let a;const{attributeTable:r,colormap:s}=e;if(t(r)){const e=z(r,"value"),t=N(r,null,!0);"string"===t.type&&(a={},r.features.forEach((n=>{const r=n.attributes;a[r[e.name]]=t?r[t.name]:r[e.name]})))}return g.createFromColormap(n(s),a)}function A(e){const{bandCount:t,dataType:n,pixelType:a}=e;return"elevation"===n||"generic"===n&&1===t&&("s16"===a||"s32"===a||"f32"===a||"f64"===a)}function D(e,t="traditional"){if(!A(e))return null;const{extent:n}=e,a=n.width*r(n.spatialReference);return new v({hillshadeType:t,scalingType:a>5e6?"adjusted":"none"})}function J(e,n=!1){const{attributeTable:a,bandCount:r}=e;return 1===r&&(!n||t(a)||t(e.histograms))}function _(e,n){e=S(e,n?.variableName);const{attributeTable:a}=e;if(!J(e))return null;const r=t(e.histograms)?e.histograms[0]:null,s=null!=n?.numClasses&&isFinite(n?.numClasses)?n.numClasses:5,o=new l({classificationMethod:n?.classificationMethod,colorRamp:n?.colorRamp});let i=n?.field||"value";const m=[],f=[],b=1e3,h=t(a),y=h&&a.fields.find((e=>"count"===e.name.toLowerCase())),g=h?a.fields.find((e=>e.name.toLowerCase()===i.toLowerCase())):void 0;if(g&&h){i=g.name;const e=a.features.length;let t=0;a.features.forEach((n=>t+=(y?n.attributes[y.name]:50)/e)),a.features.forEach((n=>{const a=n.attributes[g.name],r=y?n.attributes[y.name]:50;if(r>0){f.push(r);const n=Math.max(1,Math.round(r/e/t*b));for(let e=0;e<n;e++)m.push(a)}}))}else{const{pixelType:t}=e,n=(r.max-r.min)/r.size,s=t.includes("s")||t.includes("u"),o=s&&1===n?Math.floor(r.min+.5):r.min,i=s&&1===n?Math.floor(r.max-.5):r.max,l=r.size;let u,c=0;r.counts.forEach((e=>c+=e/l)),r.counts.forEach(((e,t)=>{if(e>0){f.push(e);const s=Math.max(1,Math.round(e/l/c*b));u=h?a.features[t].attributes[g.name]:0===t?o:t===l-1?i:r.min+n*(t+.5);for(let e=0;e<s;e++)m.push(u)}}))}const v=n?.classificationMethod||"natural-breaks";let M=n?.definedInterval;"defined-interval"!==v||M||(M=G(e,g,s));const w=d({values:m,valueFrequency:f,normalizationTotal:null,definition:new p({classificationMethod:v,breakCount:s,definedInterval:M})});let T=n?.colors;if(!T){const e=n?.colorRamp||x;o.colorRamp=e;const t=c(e,{numColors:w.classBreaks.length,interpolateAlpha:!0});T=t.map((e=>e.slice(1)))}const R=w.classBreaks.map(((e,t)=>new u({minValue:e.minValue,maxValue:e.maxValue,label:e.label,symbol:{type:"simple-fill",color:T[t]}})));return new C({field:i,classBreakInfos:R,authoringInfo:o})}function G(e,n,a){let r=0,s=0;if(t(e.attributeTable)){const t=e.attributeTable;r=s=t.features[0].attributes[n.name],t.features.forEach((e=>{const t=e.attributes[n.name];t<r&&(r=t),t>s&&(s=t)}))}else if(t(e.histograms)){const t=e.histograms;r=t[0].min,s=t[0].max}return(s-r)/a}function H(e){return["u8","s8"].includes(e.pixelType)&&null!=e.statistics?.[0]?.min&&null!=e.statistics[0]?.max&&1===e.bandCount}function K(e){const{dataType:t}=e;return"vector-uv"===t||"vector-magdir"===t}function Q(e){const{dataType:t}=e;return"vector-uv"===t||"vector-magdir"===t}const X=new Map([["m/s","meter-per-second"],["km/h","kilometer-per-hour"],["knots","knots"],["ft/s","feet-per-second"],["mph","mile-per-hour"]]);function Y(e){if(!K(e))return null;let n;if(t(e.statistics)&&e.statistics.length&&("vector-magdir"===e.dataType||"vector-uv"===e.dataType)){const{minMagnitude:t,maxMagnitude:a}=te(e.dataType,e.statistics);n=[{type:"size",field:"Magnitude",minSize:10,maxSize:40,minDataValue:t,maxDataValue:a}]}const a=t(e.multidimensionalInfo)?X.get(e.multidimensionalInfo.variables[0].unit):null,r=new M({visualVariables:n,inputUnit:a,rotationType:"geographic"});return r.visualVariables=[...r.sizeVariables,...r.rotationVariables],r}function Z(e){return{color:e.symbolLayers[0].material?.color,type:"esriSFS",style:"esriSFSSolid"}}function $(e){if("uniqueValue"===e.type){const t=e.uniqueValueInfos,n=t?.[0].symbol;return n?.symbolLayers?.length&&(e.uniqueValueInfos=t?.map((e=>({value:e.value,label:e.label,symbol:e.symbol?Z(e.symbol):null})))),e}if("classBreaks"===e.type){const t=e.classBreakInfos;return t[0].symbol?.symbolLayers?.length&&(e.classBreakInfos=t.map((e=>({classMinValue:e.classMinValue,classMaxValue:e.classMaxValue,label:e.label,symbol:e.symbol?Z(e.symbol):null})))),e}return e}function ee(e){if(!Q(e))return null;let n;if(t(e.statistics)&&e.statistics.length>0&&("vector-magdir"===e.dataType||"vector-uv"===e.dataType)){const{minMagnitude:t,maxMagnitude:a}=te(e.dataType,e.statistics);n=[{type:"color",field:"Magnitude",stops:[{value:t,color:"#1020C0"},{value:a,color:"#C02010"}]}]}return new i({visualVariables:n})}function te(e,t){let n,a;if("vector-magdir"===e)n=t[0].min,a=t[0].max;else{const e=t[0].min,r=t[0].max,s=t[1].min,o=t[1].max;n=0,a=Math.max(Math.abs(e),Math.abs(s),Math.abs(r),Math.abs(o))}return{minMagnitude:n,maxMagnitude:a}}export{_ as createClassBreaksRenderer,U as createColormapRenderer,j as createDefaultRenderer,ee as createFlowRenderer,D as createShadedReliefRenderer,I as createStretchRenderer,F as createUVRenderer,Y as createVectorFieldRenderer,te as estimateMagnitudeRange,B as getBandNames,N as getClassField,L as getDefaultBandCombination,V as getDefaultInterpolation,G as getDefinedInterval,z as getField,k as getSupportedRendererTypes,S as getVariableRasterInfo,E as getWellKnownBandIndexes,J as isClassBreaksSupported,O as isColormapRendererSupported,Q as isFlowRendererSupported,A as isShadedReliefRendererSupported,H as isSingleBand8BitRasterWithStats,W as isUVRendererSupported,K as isVectorFieldRendererSupported,$ as normalizeRendererJSON};
5
+ import e from"../../Color.js";import"../../rasterRenderers.js";import{isSome as t,unwrap as n,isNone as a}from"../../core/maybe.js";import{getMetersPerUnitForSR as r}from"../../core/unitUtils.js";import s from"../../layers/support/Field.js";import o from"../../layers/support/RasterInfo.js";import i from"../FlowRenderer.js";import l from"./AuthoringInfo.js";import u from"./ClassBreakInfo.js";import{PREDEFINED_JSON_COLOR_RAMPS as m,convertColorRampToColormap as c}from"./colorRampUtils.js";import f from"./UniqueValueInfo.js";import p from"../../rest/support/ClassBreaksDefinition.js";import{createGenerateRendererClassBreaks as d}from"../../rest/support/generateRendererUtils.js";import b from"../../rest/support/MultipartColorRamp.js";import h from"../RasterStretchRenderer.js";import y from"../UniqueValueRenderer.js";import g from"../RasterColormapRenderer.js";import v from"../RasterShadedReliefRenderer.js";import C from"../ClassBreaksRenderer.js";import M from"../VectorFieldRenderer.js";const w=.25,x=b.fromJSON({type:"multipart",colorRamps:[{fromColor:[0,0,255],toColor:[0,255,255]},{fromColor:[0,255,255],toColor:[255,255,0]},{fromColor:[255,255,0],toColor:[255,0,0]}]}),T=b.fromJSON(m[0]),R=new Set(["scientific","standard-time","vector-uv","vector-magdir","vector-u","vector-v","vector-magnitude","vector-direction"]);function j(e,n){const{attributeTable:a,colormap:r}=e;if(K(e)){const n=Y(e);if(t(n))return n}if(t(r)){const n=U(e);if(t(n))return n}if(t(a)){const n=F(e);if(t(n))return n}return I(e,n)}function k(e,t=!1){const n=["raster-stretch"];return O(e)&&n.push("raster-colormap"),W(e)&&n.push("unique-value"),J(e,t)&&n.push("class-breaks"),A(e)&&n.push("raster-shaded-relief"),K(e)&&n.push("vector-field"),Q(e)&&n.push("flow"),n}function V(e,t,n){const a=["nearest","bilinear","cubic","majority"].find((e=>e===n?.toLowerCase()));if("Map"===t)return a??"bilinear";if("standard-time"===e.dataType)return a??"nearest";return"thematic"===e.dataType||e.attributeTable||e.colormap?"nearest"===a||"majority"===a?a:"nearest":a??"bilinear"}function I(e,a){e=S(e,a?.variableName);const{bandCount:r}=e;let{bandIds:s,stretchType:o}=a||{};s?.some((e=>e>=r))&&(s=null);let i=n(e.statistics),l=n(e.histograms);r>1?(s=s?.length?s:L(e),i=null==i?null:s?.map((e=>i[e])),l=null==l?null:s?.map((e=>l[e]))):s=[0],null==o&&(o=q(e));let u=!1;switch(o){case"none":u=!1;break;case"percent-clip":u=!l?.length;break;default:u=!i?.length}const{dataType:m}=e,c=1===s?.length&&R.has(m)?x:null,f=new h({stretchType:o,dynamicRangeAdjustment:u,colorRamp:c,outputMin:0,outputMax:255,gamma:1===s?.length?[1]:[1,1,1],useGamma:!1});return"percent-clip"===o?f.maxPercent=f.minPercent=w:"standard-deviation"===o&&(f.numberOfStandardDeviations=2),u||!t(e.multidimensionalInfo)&&!a?.includeStatisticsInStretch||("percent-clip"===o?f.histograms=l:"min-max"!==o&&"standard-deviation"!==o||(f.statistics=i)),f}function S(e,a){if(!a)return e;let r=n(e.statistics),s=n(e.histograms);const{multidimensionalInfo:i}=e;if(a&&t(i)){const e=i.variables.find((e=>e.name===a));if(e){const{statistics:t,histograms:n}=e;t?.length&&(r=t),n?.length&&(s=n)}}return o.fromJSON({...e.toJSON(),statistics:r,histograms:s})}function L(e){const t=e.bandCount;if(1===t)return null;if(2===t)return[0];const n=e.keyProperties&&e.keyProperties.BandProperties;let a;if(n&&n.length===t){const{red:e,green:t,blue:r,nir:s}=E(n);null!=e&&null!=t&&null!=r?a=[e,t,r]:null!=s&&null!=e&&null!=t&&(a=[s,e,t])}return!a&&t>=3&&(a=[0,1,2]),a}function B(e,t){const n=e.keyProperties&&e.keyProperties.BandProperties;return(t=t?.length?t:Array.from(Array(e.bandCount).keys())).map((t=>n&&n.length===e.bandCount&&n[t]&&n[t].BandName||"band_"+(t+1)))}function E(e){const t={};for(let n=0;n<e.length;n++){const a=e[n],r=a.BandName?.toLowerCase();if("red"===r)t.red=n;else if("green"===r)t.green=n;else if("blue"===r)t.blue=n;else if("nearinfrared"===r||"nearinfrared_1"===r||"nir"===r)t.nir=n;else if(a.WavelengthMax&&a.WavelengthMin){const e=a.WavelengthMin,r=a.WavelengthMax;null==t.blue&&e>=410&&e<=480&&r>=480&&r<=540?t.blue=n:null==t.green&&e>=490&&e<=560&&r>=560&&r<=610?t.green=n:null==t.red&&e>=595&&e<=670&&r>=660&&r<=730?t.red=n:null==t.nir&&e>=700&&e<=860&&r>=800&&r<=950&&(t.nir=n)}}return t}function q(e){let n="percent-clip";const{pixelType:a,dataType:r,histograms:s,statistics:o,multidimensionalInfo:i}=e,l=R.has(r)||"generic"===r&&t(i);return"u8"!==a||"processed"!==r&&t(s)&&t(o)?"u8"===a||"elevation"===r||l?n="min-max":t(s)?n="percent-clip":t(o)&&(n="min-max"):n="none",n}function F(n,a,r,s){if(!W(n,a))return null;const{attributeTable:o,statistics:i}=n,u=N(o,a),m=z(o,"red"),p=z(o,"green"),d=z(o,"blue"),b=new l,h=[],g=new Set,v=!!(m&&p&&d);if(t(o))o.features.forEach((t=>{const n=t.attributes[u.name];if(!g.has(t.attributes[u.name])&&null!=n){g.add(n);const a=v&&("single"===m.type||"double"===m.type)&&("single"===p.type||"double"===p.type)&&("single"===d.type||"double"===d.type)&&!o.features.some((e=>e.attributes[m.name]>1||e.attributes[p.name]>1||e.attributes[d.name]>1)),r=a?255:1;h.push(new f({value:t.attributes[u.name],label:t.attributes[u.name]+"",symbol:{type:"simple-fill",style:"solid",outline:null,color:new e(v?[t.attributes[m.name]*r,t.attributes[p.name]*r,t.attributes[d.name]*r,1]:[0,0,0,0])}}))}}));else if(i?.[0])for(let t=i[0].min;t<=i[0].max;t++)h.push(new f({value:t,label:t.toString(),symbol:{type:"simple-fill",style:"solid",outline:null,color:new e([0,0,0,0])}}));if(h.sort(((e,t)=>e.value&&"string"==typeof e.value.valueOf()?0:e.value>t.value?1:-1)),!v){const t=c(T,{numColors:h.length});h.forEach(((n,a)=>n.symbol.color=new e(t[a].slice(1,4)))),b.colorRamp=T}if(r||s){const t=r||c(s,{numColors:h.length}).map((e=>e.slice(1)));h.forEach(((n,a)=>n.symbol.color=new e(t[a]))),b.colorRamp=s}return new y({field:u.name,uniqueValueInfos:h,authoringInfo:b})}function N(e,n,a){let r;return t(e)?(r=n?e.fields.find((e=>n.toLowerCase()===e.name.toLowerCase())):P(e.fields),r||(a||(r=e.fields.find((e=>"string"===e.type))),r||(r=z(e,"value")))):r=new s({name:"value"}),r}function P(e){let t;for(let n=0;n<e.length;n++){const a=e[n].name.toLowerCase();if("string"===e[n].type){if(a.startsWith("class")){t=e[n];break}null==t&&(a.endsWith("name")||a.endsWith("type"))&&(t=e[n])}}return t}function z(e,t){return a(e)?null:e.fields.find((e=>e.name.toLowerCase()===t))}function W(e,t){const{attributeTable:n,bandCount:r}=e;if(a(n)&&H(e))return!0;if(a(n)||r>1)return!1;if(t){if(null==n.fields.find((e=>e.name.toLowerCase()===t.toLowerCase())))return!1}return!0}function O(e){const{bandCount:n,colormap:a}=e;return t(a)&&a.length>0&&1===n}function U(e){if(!O(e))return null;let a;const{attributeTable:r,colormap:s}=e;if(t(r)){const e=z(r,"value"),t=N(r,null,!0);"string"===t.type&&(a={},r.features.forEach((n=>{const r=n.attributes;a[r[e.name]]=t?r[t.name]:r[e.name]})))}return g.createFromColormap(n(s),a)}function A(e){const{bandCount:t,dataType:n,pixelType:a}=e;return"elevation"===n||"generic"===n&&1===t&&("s16"===a||"s32"===a||"f32"===a||"f64"===a)}function D(e,t="traditional"){if(!A(e))return null;const{extent:n}=e,a=n.width*r(n.spatialReference);return new v({hillshadeType:t,scalingType:a>5e6?"adjusted":"none"})}function J(e,n=!1){const{attributeTable:a,bandCount:r}=e;return 1===r&&(!n||t(a)||t(e.histograms))}function _(e,n){e=S(e,n?.variableName);const{attributeTable:a}=e;if(!J(e))return null;const r=t(e.histograms)?e.histograms[0]:null,s=null!=n?.numClasses&&isFinite(n?.numClasses)?n.numClasses:5,o=new l({classificationMethod:n?.classificationMethod,colorRamp:n?.colorRamp});let i=n?.field||"value";const m=[],f=[],b=1e3,h=t(a),y=h&&a.fields.find((e=>"count"===e.name.toLowerCase())),g=h?a.fields.find((e=>e.name.toLowerCase()===i.toLowerCase())):void 0;if(g&&h){i=g.name;const e=a.features.length;let t=0;a.features.forEach((n=>t+=(y?n.attributes[y.name]:50)/e)),a.features.forEach((n=>{const a=n.attributes[g.name],r=y?n.attributes[y.name]:50;if(r>0){f.push(r);const n=Math.max(1,Math.round(r/e/t*b));for(let e=0;e<n;e++)m.push(a)}}))}else{const{pixelType:t}=e,n=(r.max-r.min)/r.size,s=t.includes("s")||t.includes("u"),o=s&&1===n?Math.floor(r.min+.5):r.min,i=s&&1===n?Math.floor(r.max-.5):r.max,l=r.size;let u,c=0;r.counts.forEach((e=>c+=e/l)),r.counts.forEach(((e,t)=>{if(e>0){f.push(e);const s=Math.max(1,Math.round(e/l/c*b));u=h?a.features[t].attributes[g.name]:0===t?o:t===l-1?i:r.min+n*(t+.5);for(let e=0;e<s;e++)m.push(u)}}))}const v=n?.classificationMethod||"natural-breaks";let M=n?.definedInterval;"defined-interval"!==v||M||(M=G(e,g,s));const w=d({values:m,valueFrequency:f,normalizationTotal:null,definition:new p({classificationMethod:v,breakCount:s,definedInterval:M})});let T=n?.colors;if(!T){const e=n?.colorRamp||x;o.colorRamp=e;const t=c(e,{numColors:w.classBreaks.length,interpolateAlpha:!0});T=t.map((e=>e.slice(1)))}const R=w.classBreaks.map(((e,t)=>new u({minValue:e.minValue,maxValue:e.maxValue,label:e.label,symbol:{type:"simple-fill",color:T[t]}})));return new C({field:i,classBreakInfos:R,authoringInfo:o})}function G(e,n,a){let r=0,s=0;if(t(e.attributeTable)){const t=e.attributeTable;r=s=t.features[0].attributes[n.name],t.features.forEach((e=>{const t=e.attributes[n.name];t<r&&(r=t),t>s&&(s=t)}))}else if(t(e.histograms)){const t=e.histograms;r=t[0].min,s=t[0].max}return(s-r)/a}function H(e){return["u8","s8"].includes(e.pixelType)&&null!=e.statistics?.[0]?.min&&null!=e.statistics[0]?.max&&1===e.bandCount}function K(e){const{dataType:t}=e;return"vector-uv"===t||"vector-magdir"===t}function Q(e){const{dataType:t}=e;return"vector-uv"===t||"vector-magdir"===t}const X=new Map([["m/s","meter-per-second"],["km/h","kilometer-per-hour"],["knots","knots"],["ft/s","feet-per-second"],["mph","mile-per-hour"]]);function Y(e){if(!K(e))return null;let n;if(t(e.statistics)&&e.statistics.length&&("vector-magdir"===e.dataType||"vector-uv"===e.dataType)){const{minMagnitude:t,maxMagnitude:a}=te(e.dataType,e.statistics);n=[{type:"size",field:"Magnitude",minSize:10,maxSize:40,minDataValue:t,maxDataValue:a}]}const a=t(e.multidimensionalInfo)?X.get(e.multidimensionalInfo.variables[0].unit):null,r=new M({visualVariables:n,inputUnit:a,rotationType:"geographic"});return r.visualVariables=[...r.sizeVariables,...r.rotationVariables],r}function Z(e){return{color:e.symbolLayers[0].material?.color,type:"esriSFS",style:"esriSFSSolid"}}function $(e){if("uniqueValue"===e.type){const t=e.uniqueValueInfos,n=t?.[0].symbol;return n?.symbolLayers?.length&&(e.uniqueValueInfos=t?.map((e=>({value:e.value,label:e.label,symbol:e.symbol?Z(e.symbol):null})))),e}if("classBreaks"===e.type){const t=e.classBreakInfos;return t[0].symbol?.symbolLayers?.length&&(e.classBreakInfos=t.map((e=>({classMinValue:e.classMinValue,classMaxValue:e.classMaxValue,label:e.label,symbol:e.symbol?Z(e.symbol):null})))),e}return e}function ee(e){if(!Q(e))return null;let n;if(t(e.statistics)&&e.statistics.length>0&&("vector-magdir"===e.dataType||"vector-uv"===e.dataType)){const{minMagnitude:t,maxMagnitude:a}=te(e.dataType,e.statistics);n=[{type:"color",field:"Magnitude",stops:[{value:t,color:"#1020C0"},{value:a,color:"#C02010"}]}]}return new i({visualVariables:n})}function te(e,t){let n,a;if("vector-magdir"===e)n=t[0].min,a=t[0].max;else{const e=t[0].min,r=t[0].max,s=t[1].min,o=t[1].max;n=0,a=Math.max(Math.abs(e),Math.abs(s),Math.abs(r),Math.abs(o))}return{minMagnitude:n,maxMagnitude:a}}export{_ as createClassBreaksRenderer,U as createColormapRenderer,j as createDefaultRenderer,ee as createFlowRenderer,D as createShadedReliefRenderer,I as createStretchRenderer,F as createUVRenderer,Y as createVectorFieldRenderer,te as estimateMagnitudeRange,B as getBandNames,N as getClassField,L as getDefaultBandCombination,V as getDefaultInterpolation,G as getDefinedInterval,z as getField,k as getSupportedRendererTypes,S as getVariableRasterInfo,E as getWellKnownBandIndexes,J as isClassBreaksSupported,O as isColormapRendererSupported,Q as isFlowRendererSupported,A as isShadedReliefRendererSupported,H as isSingleBand8BitRasterWithStats,W as isUVRendererSupported,K as isVectorFieldRendererSupported,$ as normalizeRendererJSON};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.26/esri/copyright.txt for details.
4
4
  */
5
- const a="20230113",c="8559a9366e4f2245dac1f05db0ab22559c700ae6";export{a as buildDate,c as commitHash};
5
+ const c="20230115",b="e92a0b6c9c6734bcd8b3437811d748c7986cc033";export{c as buildDate,b as commitHash};