May 2023
/** * Skipped minification because the original files appears to be already minified. * Original file: /npm/geotiff@2.0.7/dist-browser/geotiff.js * * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).GeoTIFF={})}(this,(function(e){"use strict";function t(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function r(e){if(Array.isArray(e))return e}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r=0;--a){var o=this.tryEntries[a],s=o.completion;if("root"===o.tryLoc)return i("end");if(o.tryLoc<=this.prev){var u=n.call(o,"catchLoc"),f=n.call(o,"finallyLoc");if(u&&f){if(this.prev=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),T(r),v}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;T(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:O(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),v}},e}(e.exports);try{regeneratorRuntime=t}catch(e){"object"===("undefined"==typeof globalThis?"undefined":d(globalThis))?globalThis.regeneratorRuntime=t:Function("r","regeneratorRuntime = r")(t)}}(k);for(var x=k.exports,A=new ArrayBuffer(4),_=new Float32Array(A),I=new Uint32Array(A),P=new Uint32Array(512),S=new Uint32Array(512),T=0;T<256;++T){var U=T-127;U<-27?(P[T]=0,P[256|T]=32768,S[T]=24,S[256|T]=24):U<-14?(P[T]=1024>>-U-14,P[256|T]=1024>>-U-14|32768,S[T]=-U-1,S[256|T]=-U-1):U<=15?(P[T]=U+15<<10,P[256|T]=U+15<<10|32768,S[T]=13,S[256|T]=13):U<128?(P[T]=31744,P[256|T]=64512,S[T]=24,S[256|T]=24):(P[T]=31744,P[256|T]=64512,S[T]=13,S[256|T]=13)}var O=new Uint32Array(2048),D=new Uint32Array(64),E=new Uint32Array(64);O[0]=0;for(var R=1;R<1024;++R){for(var M=R<<13,B=0;0==(8388608&M);)B-=8388608,M<<=1;M&=-8388609,B+=947912704,O[R]=M|B}for(var C=1024;C<2048;++C)O[C]=939524096+(C-1024<<13);D[0]=0;for(var L=1;L<31;++L)D[L]=L<<23;D[31]=1199570944,D[32]=2147483648;for(var F=33;F<63;++F)D[F]=2147483648+(F-32<<23);D[63]=3347054592,E[0]=0;for(var V=1;V<64;++V)E[V]=32===V?0:1024;function G(e){var t=e>>10;return I[0]=O[E[t]+(1023&e)]+D[t],_[0]}function j(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function z(e){return function(e){if(Array.isArray(e))return n(e)}(e)||j(e)||i(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var N=Reflect.getPrototypeOf(Uint8Array).prototype,K=Reflect.getOwnPropertyDescriptor(N,Symbol.toStringTag).get;var Z=Object.prototype.toString;function H(e){return!!ArrayBuffer.isView(e)&&(!function(e){return void 0!==K.call(e)}(e)&&"[object DataView]"===Z.call(e))}function Y(e,t){if(!H(e))throw new TypeError("First argument to getFloat16 function must be a DataView");for(var r=arguments.length,n=new Array(r>2?r-2:0),i=2;i]"),i);if(n&&console.log("start:",a),-1!==a){var o=e.slice(a+t.length),s=X(o,"[ /]"+t+">",0),u=-1===s;u&&(s=X(o,"[ /]>",0));var f=a+t.length+s+1+(u?0:t.length)+1;if(n&&console.log("end:",f),-1!==f){var c=e.slice(a,f);return{inner:u?null:c.slice(c.indexOf(">")+1,c.lastIndexOf("<")),outer:c,start:a,end:f}}}};var J=function(e,t,r){for(var n,i=[],a=r&&r.debug||!1,o=r&&r.startIndex||0;n=W(e,t,{debug:a,startIndex:o});)o=n.end,i.push(n);return a&&console.log("findTagsByName found",i.length,"tags"),i},Q={315:"Artist",258:"BitsPerSample",265:"CellLength",264:"CellWidth",320:"ColorMap",259:"Compression",33432:"Copyright",306:"DateTime",338:"ExtraSamples",266:"FillOrder",289:"FreeByteCounts",288:"FreeOffsets",291:"GrayResponseCurve",290:"GrayResponseUnit",316:"HostComputer",270:"ImageDescription",257:"ImageLength",256:"ImageWidth",271:"Make",281:"MaxSampleValue",280:"MinSampleValue",272:"Model",254:"NewSubfileType",274:"Orientation",262:"PhotometricInterpretation",284:"PlanarConfiguration",296:"ResolutionUnit",278:"RowsPerStrip",277:"SamplesPerPixel",305:"Software",279:"StripByteCounts",273:"StripOffsets",255:"SubfileType",263:"Threshholding",282:"XResolution",283:"YResolution",326:"BadFaxLines",327:"CleanFaxData",343:"ClipPath",328:"ConsecutiveBadFaxLines",433:"Decode",434:"DefaultImageColor",269:"DocumentName",336:"DotRange",321:"HalftoneHints",346:"Indexed",347:"JPEGTables",285:"PageName",297:"PageNumber",317:"Predictor",319:"PrimaryChromaticities",532:"ReferenceBlackWhite",339:"SampleFormat",340:"SMinSampleValue",341:"SMaxSampleValue",559:"StripRowCounts",330:"SubIFDs",292:"T4Options",293:"T6Options",325:"TileByteCounts",323:"TileLength",324:"TileOffsets",322:"TileWidth",301:"TransferFunction",318:"WhitePoint",344:"XClipPathUnits",286:"XPosition",529:"YCbCrCoefficients",531:"YCbCrPositioning",530:"YCbCrSubSampling",345:"YClipPathUnits",287:"YPosition",37378:"ApertureValue",40961:"ColorSpace",36868:"DateTimeDigitized",36867:"DateTimeOriginal",34665:"Exif IFD",36864:"ExifVersion",33434:"ExposureTime",41728:"FileSource",37385:"Flash",40960:"FlashpixVersion",33437:"FNumber",42016:"ImageUniqueID",37384:"LightSource",37500:"MakerNote",37377:"ShutterSpeedValue",37510:"UserComment",33723:"IPTC",34675:"ICC Profile",700:"XMP",42112:"GDAL_METADATA",42113:"GDAL_NODATA",34377:"Photoshop",33550:"ModelPixelScale",33922:"ModelTiepoint",34264:"ModelTransformation",34735:"GeoKeyDirectory",34736:"GeoDoubleParams",34737:"GeoAsciiParams",50674:"LercParameters"},$={};for(var ee in Q)Q.hasOwnProperty(ee)&&($[Q[ee]]=parseInt(ee,10));var te={256:"SHORT",257:"SHORT",258:"SHORT",259:"SHORT",262:"SHORT",273:"LONG",274:"SHORT",277:"SHORT",278:"LONG",279:"LONG",282:"RATIONAL",283:"RATIONAL",284:"SHORT",286:"SHORT",287:"RATIONAL",296:"SHORT",297:"SHORT",305:"ASCII",306:"ASCII",338:"SHORT",339:"SHORT",513:"LONG",514:"LONG",1024:"SHORT",1025:"SHORT",2048:"SHORT",2049:"ASCII",3072:"SHORT",3073:"ASCII",33550:"DOUBLE",33922:"DOUBLE",34665:"LONG",34735:"SHORT",34737:"ASCII",42113:"ASCII"},re=[$.BitsPerSample,$.ExtraSamples,$.SampleFormat,$.StripByteCounts,$.StripOffsets,$.StripRowCounts,$.TileByteCounts,$.TileOffsets,$.SubIFDs],ne={1:"BYTE",2:"ASCII",3:"SHORT",4:"LONG",5:"RATIONAL",6:"SBYTE",7:"UNDEFINED",8:"SSHORT",9:"SLONG",10:"SRATIONAL",11:"FLOAT",12:"DOUBLE",13:"IFD",16:"LONG8",17:"SLONG8",18:"IFD8"},ie={};for(var ae in ne)ne.hasOwnProperty(ae)&&(ie[ne[ae]]=parseInt(ae,10));var oe={WhiteIsZero:0,BlackIsZero:1,RGB:2,Palette:3,TransparencyMask:4,CMYK:5,YCbCr:6,CIELab:8,ICCLab:9},se={Unspecified:0,Assocalpha:1,Unassalpha:2},ue={Version:0,AddCompression:1},fe={None:0,Deflate:1},ce={1024:"GTModelTypeGeoKey",1025:"GTRasterTypeGeoKey",1026:"GTCitationGeoKey",2048:"GeographicTypeGeoKey",2049:"GeogCitationGeoKey",2050:"GeogGeodeticDatumGeoKey",2051:"GeogPrimeMeridianGeoKey",2052:"GeogLinearUnitsGeoKey",2053:"GeogLinearUnitSizeGeoKey",2054:"GeogAngularUnitsGeoKey",2055:"GeogAngularUnitSizeGeoKey",2056:"GeogEllipsoidGeoKey",2057:"GeogSemiMajorAxisGeoKey",2058:"GeogSemiMinorAxisGeoKey",2059:"GeogInvFlatteningGeoKey",2060:"GeogAzimuthUnitsGeoKey",2061:"GeogPrimeMeridianLongGeoKey",2062:"GeogTOWGS84GeoKey",3072:"ProjectedCSTypeGeoKey",3073:"PCSCitationGeoKey",3074:"ProjectionGeoKey",3075:"ProjCoordTransGeoKey",3076:"ProjLinearUnitsGeoKey",3077:"ProjLinearUnitSizeGeoKey",3078:"ProjStdParallel1GeoKey",3079:"ProjStdParallel2GeoKey",3080:"ProjNatOriginLongGeoKey",3081:"ProjNatOriginLatGeoKey",3082:"ProjFalseEastingGeoKey",3083:"ProjFalseNorthingGeoKey",3084:"ProjFalseOriginLongGeoKey",3085:"ProjFalseOriginLatGeoKey",3086:"ProjFalseOriginEastingGeoKey",3087:"ProjFalseOriginNorthingGeoKey",3088:"ProjCenterLongGeoKey",3089:"ProjCenterLatGeoKey",3090:"ProjCenterEastingGeoKey",3091:"ProjCenterNorthingGeoKey",3092:"ProjScaleAtNatOriginGeoKey",3093:"ProjScaleAtCenterGeoKey",3094:"ProjAzimuthAngleGeoKey",3095:"ProjStraightVertPoleLongGeoKey",3096:"ProjRectifiedGridAngleGeoKey",4096:"VerticalCSTypeGeoKey",4097:"VerticalCitationGeoKey",4098:"VerticalDatumGeoKey",4099:"VerticalUnitsGeoKey"},le={};for(var he in ce)ce.hasOwnProperty(he)&&(le[ce[he]]=parseInt(he,10));var de=Object.freeze({__proto__:null,fieldTagNames:Q,fieldTags:$,fieldTagTypes:te,arrayFields:re,fieldTypeNames:ne,fieldTypes:ie,photometricInterpretations:oe,ExtraSamplesValues:se,LercParameters:ue,LercAddCompression:fe,geoKeyNames:ce,geoKeys:le});function pe(e,t){for(var r,n=e.width,i=e.height,a=new Uint8Array(n*i*3),o=0,s=0;o>24)/500+o,u=o-(e[i+2]<<24>>24)/200,f=void 0,c=void 0,l=void 0;c=-.9689*(s=.95047*(s*s*s>.008856?s*s*s:(s-16/116)/7.787))+1.8758*(o=1*(o*o*o>.008856?o*o*o:(o-16/116)/7.787))+.0415*(u=1.08883*(u*u*u>.008856?u*u*u:(u-16/116)/7.787)),l=.0557*s+-.204*o+1.057*u,f=(f=3.2406*s+-1.5372*o+-.4986*u)>.0031308?1.055*Math.pow(f,1/2.4)-.055:12.92*f,c=c>.0031308?1.055*Math.pow(c,1/2.4)-.055:12.92*c,l=l>.0031308?1.055*Math.pow(l,1/2.4)-.055:12.92*l,n[a]=255*Math.max(0,Math.min(1,f)),n[a+1]=255*Math.max(0,Math.min(1,c)),n[a+2]=255*Math.max(0,Math.min(1,l))}return n}var be=Object.freeze({__proto__:null,fromWhiteIsZero:pe,fromBlackIsZero:me,fromPalette:ve,fromCMYK:ye,fromYCbCr:ge,fromCIELab:we}),ke=new Map;function xe(e,t){Array.isArray(e)||(e=[e]),e.forEach((function(e){return ke.set(e,t)}))}function Ae(e){return _e.apply(this,arguments)}function _e(){return(_e=u(x.mark((function e(t){var r,n;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=ke.get(t.Compression)){e.next=3;break}throw new Error("Unknown compression method identifier: ".concat(t.Compression));case 3:return e.next=5,r();case 5:return n=e.sent,e.abrupt("return",new n(t));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Ie(e,t,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1;return new(Object.getPrototypeOf(e).constructor)(t*r*n)}function Pe(e,t,r,n,i){var a=t/n,o=r/i;return e.map((function(e){for(var s=Ie(e,n,i),u=0;u5&&void 0!==arguments[5]?arguments[5]:"nearest";switch(a.toLowerCase()){case"nearest":return Pe(e,t,r,n,i);case"bilinear":case"linear":return Te(e,t,r,n,i);default:throw new Error("Unsupported resampling method: '".concat(a,"'"))}}function Oe(e,t,r,n,i,a){for(var o=t/n,s=r/i,u=Ie(e,n,i,a),f=0;f6&&void 0!==arguments[6]?arguments[6]:"nearest";switch(o.toLowerCase()){case"nearest":return Oe(e,t,r,n,i,a);case"bilinear":case"linear":return De(e,t,r,n,i,a);default:throw new Error("Unsupported resampling method: '".concat(o,"'"))}}function Re(e,t,r){for(var n=0,i=t;i>8-i-b&c;else if(b+i<=16)f[g]=s.getUint16(w)>>16-i-b&c;else if(b+i<=24){var k=s.getUint16(w)<<8|s.getUint8(w+2);f[g]=k>>24-i-b&c}else f[g]=s.getUint32(w)>>32-i-b&c}}return f.buffer}xe([void 0,1],(function(){return Promise.resolve().then((function(){return Fr})).then((function(e){return e.default}))})),xe(5,(function(){return Promise.resolve().then((function(){return Nr})).then((function(e){return e.default}))})),xe(6,(function(){throw new Error("old style JPEG compression is not supported.")})),xe(7,(function(){return Promise.resolve().then((function(){return on})).then((function(e){return e.default}))})),xe([8,32946],(function(){return Promise.resolve().then((function(){return vi})).then((function(e){return e.default}))})),xe(32773,(function(){return Promise.resolve().then((function(){return wi})).then((function(e){return e.default}))})),xe(34887,(function(){return Promise.resolve().then((function(){return _i})).then((function(e){return e.default}))})),xe(50001,(function(){return Promise.resolve().then((function(){return Si})).then((function(e){return e.default}))}));var Le=function(){function e(t,r,n,i,a,o){b(this,e),this.fileDirectory=t,this.geoKeys=r,this.dataView=n,this.littleEndian=i,this.tiles=a?{}:null,this.isTiled=!t.StripOffsets;var s=t.PlanarConfiguration;if(this.planarConfiguration=void 0===s?1:s,1!==this.planarConfiguration&&2!==this.planarConfiguration)throw new Error("Invalid planar configuration.");this.source=o}var t,r,n,i;return c(e,[{key:"getFileDirectory",value:function(){return this.fileDirectory}},{key:"getGeoKeys",value:function(){return this.geoKeys}},{key:"getWidth",value:function(){return this.fileDirectory.ImageWidth}},{key:"getHeight",value:function(){return this.fileDirectory.ImageLength}},{key:"getSamplesPerPixel",value:function(){return void 0!==this.fileDirectory.SamplesPerPixel?this.fileDirectory.SamplesPerPixel:1}},{key:"getTileWidth",value:function(){return this.isTiled?this.fileDirectory.TileWidth:this.getWidth()}},{key:"getTileHeight",value:function(){return this.isTiled?this.fileDirectory.TileLength:void 0!==this.fileDirectory.RowsPerStrip?Math.min(this.fileDirectory.RowsPerStrip,this.getHeight()):this.getHeight()}},{key:"getBlockWidth",value:function(){return this.getTileWidth()}},{key:"getBlockHeight",value:function(e){return this.isTiled||(e+1)*this.getTileHeight()<=this.getHeight()?this.getTileHeight():this.getHeight()-e*this.getTileHeight()}},{key:"getBytesPerPixel",value:function(){for(var e=0,t=0;t=this.fileDirectory.BitsPerSample.length)throw new RangeError("Sample index ".concat(e," is out of range."));return Math.ceil(this.fileDirectory.BitsPerSample[e]/8)}},{key:"getReaderForSample",value:function(e){var t=this.fileDirectory.SampleFormat?this.fileDirectory.SampleFormat[e]:1,r=this.fileDirectory.BitsPerSample[e];switch(t){case 1:if(r<=8)return DataView.prototype.getUint8;if(r<=16)return DataView.prototype.getUint16;if(r<=32)return DataView.prototype.getUint32;break;case 2:if(r<=8)return DataView.prototype.getInt8;if(r<=16)return DataView.prototype.getInt16;if(r<=32)return DataView.prototype.getInt32;break;case 3:switch(r){case 16:return function(e,t){return Y(this,e,t)};case 32:return DataView.prototype.getFloat32;case 64:return DataView.prototype.getFloat64}}throw Error("Unsupported data format/bitsPerSample")}},{key:"getSampleFormat",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return this.fileDirectory.SampleFormat?this.fileDirectory.SampleFormat[e]:1}},{key:"getBitsPerSample",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return this.fileDirectory.BitsPerSample[e]}},{key:"getArrayForSample",value:function(e,t){return Me(this.getSampleFormat(e),this.getBitsPerSample(e),t)}},{key:"getTileOrStrip",value:(i=u(x.mark((function e(t,r,n,i,a){var o,s,f,c,l,h,d,p,m=this;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=Math.ceil(this.getWidth()/this.getTileWidth()),s=Math.ceil(this.getHeight()/this.getTileHeight()),c=this.tiles,1===this.planarConfiguration?f=r*o+t:2===this.planarConfiguration&&(f=n*o*s+r*o+t),this.isTiled?(l=this.fileDirectory.TileOffsets[f],h=this.fileDirectory.TileByteCounts[f]):(l=this.fileDirectory.StripOffsets[f],h=this.fileDirectory.StripByteCounts[f]),e.next=7,this.source.fetch([{offset:l,length:h}],a);case 7:return d=e.sent[0],null!==c&&c[f]?p=c[f]:(p=u(x.mark((function e(){var t,n,a;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,i.decode(m.fileDirectory,d);case 2:return t=e.sent,n=m.getSampleFormat(),a=m.getBitsPerSample(),Be(n,a)&&(t=Ce(t,n,m.planarConfiguration,m.getSamplesPerPixel(),a,m.getTileWidth(),m.getBlockHeight(r))),e.abrupt("return",t);case 7:case"end":return e.stop()}}),e)})))(),null!==c&&(c[f]=p)),e.t0=t,e.t1=r,e.t2=n,e.next=14,p;case 14:return e.t3=e.sent,e.abrupt("return",{x:e.t0,y:e.t1,sample:e.t2,data:e.t3});case 16:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n,a){return i.apply(this,arguments)})},{key:"_readRaster",value:(n=u(x.mark((function e(t,r,n,i,a,o,s,u,f){var c,l,h,d,p,m,v,y,g,w,b,k,A,_,I,P,S,T,U,O,D=this;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(c=this.getTileWidth(),l=this.getTileHeight(),h=this.getWidth(),d=this.getHeight(),p=Math.max(Math.floor(t[0]/c),0),m=Math.min(Math.ceil(t[2]/c),Math.ceil(h/c)),v=Math.max(Math.floor(t[1]/l),0),y=Math.min(Math.ceil(t[3]/l),Math.ceil(d/l)),g=t[2]-t[0],w=this.getBytesPerPixel(),b=[],k=[],A=0;A0&&void 0!==T[0]?T[0]:{},r=t.window,n=t.samples,i=void 0===n?[]:n,a=t.interleave,o=t.pool,s=void 0===o?null:o,u=t.width,f=t.height,c=t.resampleMethod,l=t.fillValue,h=t.signal,!((d=r||[0,0,this.getWidth(),this.getHeight()])[0]>d[2]||d[1]>d[3])){e.next=4;break}throw new Error("Invalid subsets");case 4:if(p=d[2]-d[0],m=d[3]-d[1],v=p*m,y=this.getSamplesPerPixel(),i&&i.length){e.next=12;break}for(g=0;g=y)){e.next=16;break}return e.abrupt("return",Promise.reject(new RangeError("Invalid sample index '".concat(i[w],"'."))));case 16:++w,e.next=13;break;case 19:if(a)k=this.fileDirectory.SampleFormat?Math.max.apply(null,this.fileDirectory.SampleFormat):1,A=Math.max.apply(null,this.fileDirectory.BitsPerSample),b=Me(k,A,v*i.length),l&&b.fill(l);else for(b=[],_=0;_0&&void 0!==U[0]?U[0]:{},r=t.window,n=t.interleave,i=void 0===n||n,a=t.pool,o=void 0===a?null:a,s=t.width,u=t.height,f=t.resampleMethod,c=t.enableAlpha,l=void 0!==c&&c,h=t.signal,!((d=r||[0,0,this.getWidth(),this.getHeight()])[0]>d[2]||d[1]>d[3])){e.next=4;break}throw new Error("Invalid subsets");case 4:if((p=this.fileDirectory.PhotometricInterpretation)!==oe.RGB){e.next=9;break}if(m=[0,1,2],this.fileDirectory.ExtraSamples!==se.Unspecified&&l)for(m=[],v=0;v0&&void 0!==arguments[0]?arguments[0]:null,t={};if(!this.fileDirectory.GDAL_METADATA)return null;var r=this.fileDirectory.GDAL_METADATA,n=J(r,"Item");n=null===e?n.filter((function(e){return void 0===q(e,"sample")})):n.filter((function(t){return Number(q(t,"sample"))===e}));for(var i=0;i0&&void 0!==arguments[0]?arguments[0]:null,t=this.fileDirectory.ModelPixelScale,r=this.fileDirectory.ModelTransformation;if(t)return[t[0],-t[1],t[2]];if(r)return[r[0],r[5],r[10]];if(e){var n=e.getResolution(),i=o(n,3),a=i[0],s=i[1],u=i[2];return[a*e.getWidth()/this.getWidth(),s*e.getHeight()/this.getHeight(),u*e.getWidth()/this.getWidth()]}throw new Error("The image does not have an affine transformation.")}},{key:"pixelIsArea",value:function(){return 1===this.geoKeys.GTRasterTypeGeoKey}},{key:"getBoundingBox",value:function(){var e=this.getOrigin(),t=this.getResolution(),r=e[0],n=e[1],i=r+t[0]*this.getWidth(),a=n+t[1]*this.getHeight();return[Math.min(r,i),Math.min(n,a),Math.max(r,i),Math.max(n,a)]}}]),e}(),Fe=Le,Ve=function(){function e(t){b(this,e),this._dataView=new DataView(t)}return c(e,[{key:"buffer",get:function(){return this._dataView.buffer}},{key:"getUint64",value:function(e,t){var r,n=this.getUint32(e,t),i=this.getUint32(e+4,t);if(t){if(r=n+Math.pow(2,32)*i,!Number.isSafeInteger(r))throw new Error("".concat(r," exceeds MAX_SAFE_INTEGER. ")+"Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues");return r}if(r=Math.pow(2,32)*n+i,!Number.isSafeInteger(r))throw new Error("".concat(r," exceeds MAX_SAFE_INTEGER. ")+"Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues");return r}},{key:"getInt64",value:function(e,t){for(var r=0,n=(128&this._dataView.getUint8(e+(t?7:0)))>0,i=!0,a=0;a<8;a++){var o=this._dataView.getUint8(e+(t?a:7-a));n&&(i?0!==o&&(o=255&~(o-1),i=!1):o=255&~o),r+=o*Math.pow(256,a)}return n&&(r=-r),r}},{key:"getUint8",value:function(e,t){return this._dataView.getUint8(e,t)}},{key:"getInt8",value:function(e,t){return this._dataView.getInt8(e,t)}},{key:"getUint16",value:function(e,t){return this._dataView.getUint16(e,t)}},{key:"getInt16",value:function(e,t){return this._dataView.getInt16(e,t)}},{key:"getUint32",value:function(e,t){return this._dataView.getUint32(e,t)}},{key:"getInt32",value:function(e,t){return this._dataView.getInt32(e,t)}},{key:"getFloat16",value:function(e,t){return Y(this._dataView,e,t)}},{key:"getFloat32",value:function(e,t){return this._dataView.getFloat32(e,t)}},{key:"getFloat64",value:function(e,t){return this._dataView.getFloat64(e,t)}}]),e}(),Ge=function(){function e(t,r,n,i){b(this,e),this._dataView=new DataView(t),this._sliceOffset=r,this._littleEndian=n,this._bigTiff=i}return c(e,[{key:"sliceOffset",get:function(){return this._sliceOffset}},{key:"sliceTop",get:function(){return this._sliceOffset+this.buffer.byteLength}},{key:"littleEndian",get:function(){return this._littleEndian}},{key:"bigTiff",get:function(){return this._bigTiff}},{key:"buffer",get:function(){return this._dataView.buffer}},{key:"covers",value:function(e,t){return this.sliceOffset<=e&&this.sliceTop>=e+t}},{key:"readUint8",value:function(e){return this._dataView.getUint8(e-this._sliceOffset,this._littleEndian)}},{key:"readInt8",value:function(e){return this._dataView.getInt8(e-this._sliceOffset,this._littleEndian)}},{key:"readUint16",value:function(e){return this._dataView.getUint16(e-this._sliceOffset,this._littleEndian)}},{key:"readInt16",value:function(e){return this._dataView.getInt16(e-this._sliceOffset,this._littleEndian)}},{key:"readUint32",value:function(e){return this._dataView.getUint32(e-this._sliceOffset,this._littleEndian)}},{key:"readInt32",value:function(e){return this._dataView.getInt32(e-this._sliceOffset,this._littleEndian)}},{key:"readFloat32",value:function(e){return this._dataView.getFloat32(e-this._sliceOffset,this._littleEndian)}},{key:"readFloat64",value:function(e){return this._dataView.getFloat64(e-this._sliceOffset,this._littleEndian)}},{key:"readUint64",value:function(e){var t,r=this.readUint32(e),n=this.readUint32(e+4);if(this._littleEndian){if(t=r+Math.pow(2,32)*n,!Number.isSafeInteger(t))throw new Error("".concat(t," exceeds MAX_SAFE_INTEGER. ")+"Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues");return t}if(t=Math.pow(2,32)*r+n,!Number.isSafeInteger(t))throw new Error("".concat(t," exceeds MAX_SAFE_INTEGER. ")+"Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues");return t}},{key:"readInt64",value:function(e){for(var t=0,r=(128&this._dataView.getUint8(e+(this._littleEndian?7:0)))>0,n=!0,i=0;i<8;i++){var a=this._dataView.getUint8(e+(this._littleEndian?i:7-i));r&&(n?0!==a&&(a=255&~(a-1),n=!1):a=255&~a),t+=a*Math.pow(256,i)}return r&&(t=-t),t}},{key:"readOffset",value:function(e){return this._bigTiff?this.readUint64(e):this.readUint32(e)}}]),e}(),je="undefined"!=typeof navigator&&navigator.hardwareConcurrency||2,ze=function(){function e(){var t=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:je,n=arguments.length>1?arguments[1]:void 0;b(this,e),this.workers=null,this._awaitingDecoder=null,this.size=r,this.messageId=0,r&&(this._awaitingDecoder=n?Promise.resolve(n):new Promise((function(e){Promise.resolve().then((function(){return Ui})).then((function(t){e(t.create)}))})),this._awaitingDecoder.then((function(e){t._awaitingDecoder=null,t.workers=[];for(var n=0;n=0||(i[r]=e[r]);return i}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(i[r]=e[r])}return i}function Ze(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,t){if(!e)return;if("string"==typeof e)return He(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return He(e,t)}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,i=function(){};return{s:i,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,s=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||null==r.return||r.return()}finally{if(s)throw a}}}}function He(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r1&&void 0!==i[1]?i[1]:void 0,e.abrupt("return",Promise.all(t.map((function(e){return n.fetchSlice(e,r)}))));case 2:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})},{key:"fetchSlice",value:(r=u(x.mark((function e(t){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:throw new Error("fetching of slice ".concat(t," not possible, not implemented"));case 1:case"end":return e.stop()}}),e)}))),function(e){return r.apply(this,arguments)})},{key:"fileSize",get:function(){return null}},{key:"close",value:(t=u(x.mark((function e(){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),e)}))),function(){return t.apply(this,arguments)})}]),e}();function et(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,t){if(!e)return;if("string"==typeof e)return tt(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return tt(e,t)}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,i=function(){};return{s:i,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,s=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||null==r.return||r.return()}finally{if(s)throw a}}}}function tt(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r0&&void 0!==arguments[0]?arguments[0]:{};if(b(this,i),e=n.call(this),!(t.maxSize&&t.maxSize>0))throw new TypeError("`maxSize` must be a number greater than 0");if("number"==typeof t.maxAge&&0===t.maxAge)throw new TypeError("`maxAge` must be a number greater than 0");return e.maxSize=t.maxSize,e.maxAge=t.maxAge||Number.POSITIVE_INFINITY,e.onEviction=t.onEviction,e.cache=new Map,e.oldCache=new Map,e._size=0,e}return c(i,[{key:"_emitEvictions",value:function(e){if("function"==typeof this.onEviction){var t,r=et(e);try{for(r.s();!(t=r.n()).done;){var n=o(t.value,2),i=n[0],a=n[1];this.onEviction(i,a.value)}}catch(e){r.e(e)}finally{r.f()}}}},{key:"_deleteIfExpired",value:function(e,t){return"number"==typeof t.expiry&&t.expiry<=Date.now()&&("function"==typeof this.onEviction&&this.onEviction(e,t.value),this.delete(e))}},{key:"_getOrDeleteIfExpired",value:function(e,t){if(!1===this._deleteIfExpired(e,t))return t.value}},{key:"_getItemValue",value:function(e,t){return t.expiry?this._getOrDeleteIfExpired(e,t):t.value}},{key:"_peek",value:function(e,t){var r=t.get(e);return this._getItemValue(e,r)}},{key:"_set",value:function(e,t){this.cache.set(e,t),this._size++,this._size>=this.maxSize&&(this._size=0,this._emitEvictions(this.oldCache),this.oldCache=this.cache,this.cache=new Map)}},{key:"_moveToRecent",value:function(e,t){this.oldCache.delete(e),this._set(e,t)}},{key:"_entriesAscending",value:x.mark((function e(){var t,r,n,i,a,s,u,f,c,l,h,d;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=et(this.oldCache),e.prev=1,t.s();case 3:if((r=t.n()).done){e.next=13;break}if(n=r.value,i=o(n,2),a=i[0],s=i[1],this.cache.has(a)){e.next=11;break}if(!1!==this._deleteIfExpired(a,s)){e.next=11;break}return e.next=11,n;case 11:e.next=3;break;case 13:e.next=18;break;case 15:e.prev=15,e.t0=e.catch(1),t.e(e.t0);case 18:return e.prev=18,t.f(),e.finish(18);case 21:u=et(this.cache),e.prev=22,u.s();case 24:if((f=u.n()).done){e.next=33;break}if(c=f.value,l=o(c,2),h=l[0],d=l[1],!1!==this._deleteIfExpired(h,d)){e.next=31;break}return e.next=31,c;case 31:e.next=24;break;case 33:e.next=38;break;case 35:e.prev=35,e.t1=e.catch(22),u.e(e.t1);case 38:return e.prev=38,u.f(),e.finish(38);case 41:case"end":return e.stop()}}),e,this,[[1,15,18,21],[22,35,38,41]])}))},{key:"get",value:function(e){if(this.cache.has(e)){var t=this.cache.get(e);return this._getItemValue(e,t)}if(this.oldCache.has(e)){var r=this.oldCache.get(e);if(!1===this._deleteIfExpired(e,r))return this._moveToRecent(e,r),r.value}}},{key:"set",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.maxAge,i=void 0===n?this.maxAge:n,a="number"==typeof i&&i!==Number.POSITIVE_INFINITY?Date.now()+i:void 0;this.cache.has(e)?this.cache.set(e,{value:t,expiry:a}):this._set(e,{value:t,expiry:a})}},{key:"has",value:function(e){return this.cache.has(e)?!this._deleteIfExpired(e,this.cache.get(e)):!!this.oldCache.has(e)&&!this._deleteIfExpired(e,this.oldCache.get(e))}},{key:"peek",value:function(e){return this.cache.has(e)?this._peek(e,this.cache):this.oldCache.has(e)?this._peek(e,this.oldCache):void 0}},{key:"delete",value:function(e){var t=this.cache.delete(e);return t&&this._size--,this.oldCache.delete(e)||t}},{key:"clear",value:function(){this.cache.clear(),this.oldCache.clear(),this._size=0}},{key:"resize",value:function(e){if(!(e&&e>0))throw new TypeError("`maxSize` must be a number greater than 0");var t=z(this._entriesAscending()),r=t.length-e;r<0?(this.cache=new Map(t),this.oldCache=new Map,this._size=t.length):(r>0&&this._emitEvictions(t.slice(0,r)),this.oldCache=new Map(t.slice(r)),this.cache=new Map,this._size=0),this.maxSize=e}},{key:"keys",value:x.mark((function e(){var t,r,n,i;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=et(this),e.prev=1,t.s();case 3:if((r=t.n()).done){e.next=9;break}return n=o(r.value,1),i=n[0],e.next=7,i;case 7:e.next=3;break;case 9:e.next=14;break;case 11:e.prev=11,e.t0=e.catch(1),t.e(e.t0);case 14:return e.prev=14,t.f(),e.finish(14);case 17:case"end":return e.stop()}}),e,this,[[1,11,14,17]])}))},{key:"values",value:x.mark((function e(){var t,r,n,i;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=et(this),e.prev=1,t.s();case 3:if((r=t.n()).done){e.next=9;break}return n=o(r.value,2),i=n[1],e.next=7,i;case 7:e.next=3;break;case 9:e.next=14;break;case 11:e.prev=11,e.t0=e.catch(1),t.e(e.t0);case 14:return e.prev=14,t.f(),e.finish(14);case 17:case"end":return e.stop()}}),e,this,[[1,11,14,17]])}))},{key:t,value:x.mark((function(){var e,t,r,n,i,a,s,u,f,c,l,h;return x.wrap((function(d){for(;;)switch(d.prev=d.next){case 0:e=et(this.cache),d.prev=1,e.s();case 3:if((t=e.n()).done){d.next=12;break}if(r=t.value,n=o(r,2),i=n[0],a=n[1],!1!==this._deleteIfExpired(i,a)){d.next=10;break}return d.next=10,[i,a.value];case 10:d.next=3;break;case 12:d.next=17;break;case 14:d.prev=14,d.t0=d.catch(1),e.e(d.t0);case 17:return d.prev=17,e.f(),d.finish(17);case 20:s=et(this.oldCache),d.prev=21,s.s();case 23:if((u=s.n()).done){d.next=33;break}if(f=u.value,c=o(f,2),l=c[0],h=c[1],this.cache.has(l)){d.next=31;break}if(!1!==this._deleteIfExpired(l,h)){d.next=31;break}return d.next=31,[l,h.value];case 31:d.next=23;break;case 33:d.next=38;break;case 35:d.prev=35,d.t1=d.catch(21),s.e(d.t1);case 38:return d.prev=38,s.f(),d.finish(38);case 41:case"end":return d.stop()}}),a,this,[[1,14,17,20],[21,35,38,41]])}))},{key:"entriesDescending",value:x.mark((function e(){var t,r,n,i,a,s,u,f,c,l,h;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=z(this.cache),r=t.length-1;case 2:if(!(r>=0)){e.next=12;break}if(n=t[r],i=o(n,2),a=i[0],s=i[1],!1!==this._deleteIfExpired(a,s)){e.next=9;break}return e.next=9,[a,s.value];case 9:--r,e.next=2;break;case 12:t=z(this.oldCache),u=t.length-1;case 14:if(!(u>=0)){e.next=25;break}if(f=t[u],c=o(f,2),l=c[0],h=c[1],this.cache.has(l)){e.next=22;break}if(!1!==this._deleteIfExpired(l,h)){e.next=22;break}return e.next=22,[l,h.value];case 22:--u,e.next=14;break;case 25:case"end":return e.stop()}}),e,this)}))},{key:"entriesAscending",value:x.mark((function e(){var t,r,n,i,a;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=et(this._entriesAscending()),e.prev=1,t.s();case 3:if((r=t.n()).done){e.next=9;break}return n=o(r.value,2),i=n[0],a=n[1],e.next=7,[i,a.value];case 7:e.next=3;break;case 9:e.next=14;break;case 11:e.prev=11,e.t0=e.catch(1),t.e(e.t0);case 14:return e.prev=14,t.f(),e.finish(14);case 17:case"end":return e.stop()}}),e,this,[[1,11,14,17]])}))},{key:"size",get:function(){if(!this._size)return this.oldCache.size;var e,t=0,r=et(this.oldCache.keys());try{for(r.s();!(e=r.n()).done;){var n=e.value;this.cache.has(n)||t++}}catch(e){r.e(e)}finally{r.f()}return Math.min(this._size+t,this.maxSize)}},{key:"entries",value:function(){return this.entriesAscending()}},{key:"forEach",value:function(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this,n=et(this.entriesAscending());try{for(n.s();!(t=n.n()).done;){var i=o(t.value,2),a=i[0],s=i[1];e.call(r,s,a,this)}}catch(e){n.e(e)}finally{n.f()}}},{key:r,get:function(){return JSON.stringify(z(this.entriesAscending()))}}]),i}(w(Map),Symbol.iterator,Symbol.toStringTag);function it(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=v(e);if(t){var i=v(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return m(this,r)}}function at(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])}function ot(e,t){return!(e.length=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,s=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||null==r.return||r.return()}finally{if(s)throw a}}}}function mt(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r2&&void 0!==arguments[2]?arguments[2]:null;b(this,e),this.offset=t,this.length=r,this.data=n}return c(e,[{key:"top",get:function(){return this.offset+this.length}}]),e}(),gt=function e(t,r,n){b(this,e),this.offset=t,this.length=r,this.blockIds=n},wt=function(e){h(n,e);var t,r=vt(n);function n(e){var t,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=i.blockSize,o=void 0===a?65536:a,s=i.cacheSize,u=void 0===s?100:s;return b(this,n),(t=r.call(this)).source=e,t.blockSize=o,t.blockCache=new nt({maxSize:u,onEviction:function(e,r){t.evictedBlocks.set(e,r)}}),t.evictedBlocks=new Map,t.blockRequests=new Map,t.blockIdsToFetch=new Set,t.abortedBlockIds=new Set,t}return c(n,[{key:"fileSize",get:function(){return this.source.fileSize}},{key:"fetch",value:(t=u(x.mark((function e(t,r){var n,i,a,o,s,u,f,c,l,h,d,p,m,v,y,g,w,b,k,A,_,I,P,S,T,U,O=this;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=[],i=[],a=[],this.evictedBlocks.clear(),o=pt(t);try{for(o.s();!(s=o.n()).done;)for(u=s.value,f=u.offset,c=u.length,l=f+c,null!==(h=this.fileSize)&&(l=Math.min(l,h)),d=Math.floor(f/this.blockSize)*this.blockSize,p=d;p0&&r)||r.aborted){e.next=41;break}this.fetchBlocks(null),A=pt(k),e.prev=21,A.s();case 23:if((_=A.n()).done){e.next=31;break}if(I=_.value,P=this.blockRequests.get(I)){e.next=28;break}throw new Error("Block ".concat(I," is not in the block requests"));case 28:b.push(P);case 29:e.next=23;break;case 31:e.next=36;break;case 33:e.prev=33,e.t0=e.catch(21),A.e(e.t0);case 36:return e.prev=36,A.f(),e.finish(36);case 39:return e.next=41,Promise.allSettled(b);case 41:if(!r||!r.aborted){e.next=43;break}throw new ht("Request was aborted");case 43:if(S=a.map((function(e){return O.blockCache.get(e)||O.evictedBlocks.get(e)})),T=S.filter((function(e){return!e})),!T.length){e.next=47;break}throw new dt(T,"Request failed");case 47:return U=new Map(lt(a,S)),e.abrupt("return",this.readSliceData(t,U));case 49:case"end":return e.stop()}}),e,this,[[21,33,36,39]])}))),function(e,r){return t.apply(this,arguments)})},{key:"fetchBlocks",value:function(e){var t=this;this.blockIdsToFetch.size>0&&function(){for(var r=t.groupBlocks(t.blockIdsToFetch),n=t.source.fetch(r,e),i=function(i){var a,o=pt(r[i].blockIds);try{var s=function(){var r=a.value;t.blockRequests.set(r,u(x.mark((function a(){var o,s,u,f,c,l;return x.wrap((function(a){for(;;)switch(a.prev=a.next){case 0:return a.prev=0,a.next=3,n;case 3:a.t0=i,o=a.sent[a.t0],s=r*t.blockSize,u=s-o.offset,f=Math.min(u+t.blockSize,o.data.byteLength),c=o.data.slice(u,f),l=new yt(s,c.byteLength,c,r),t.blockCache.set(r,l),t.abortedBlockIds.delete(r),a.next=23;break;case 14:if(a.prev=14,a.t1=a.catch(0),"AbortError"!==a.t1.name){a.next=22;break}a.t1.signal=e,t.blockCache.delete(r),t.abortedBlockIds.add(r),a.next=23;break;case 22:throw a.t1;case 23:return a.prev=23,t.blockRequests.delete(r),a.finish(23);case 26:case"end":return a.stop()}}),a,null,[[0,14,23,26]])})))())};for(o.s();!(a=o.n()).done;)s()}catch(e){o.e(e)}finally{o.f()}},a=0;a0&&(h=c),d=f.top-n<0?f.length-l:n-f.offset-l;var p=new Uint8Array(f.data,l,d);s.set(p,h)}return o}))}}]),n}($e),bt=function(){function e(){b(this,e)}var t;return c(e,[{key:"ok",get:function(){return this.status>=200&&this.status<=299}},{key:"status",get:function(){throw new Error("not implemented")}},{key:"getHeader",value:function(e){throw new Error("not implemented")}},{key:"getData",value:(t=u(x.mark((function e(){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:throw new Error("not implemented");case 1:case"end":return e.stop()}}),e)}))),function(){return t.apply(this,arguments)})}]),e}(),kt=function(){function e(t){b(this,e),this.url=t}var t;return c(e,[{key:"request",value:(t=u(x.mark((function e(){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:throw new Error("request is not implemented");case 2:case"end":return e.stop()}}),e)}))),function(){return t.apply(this,arguments)})}]),e}();function xt(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=v(e);if(t){var i=v(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return m(this,r)}}var At=function(e){h(n,e);var t,r=xt(n);function n(e){var t;return b(this,n),(t=r.call(this)).response=e,t}return c(n,[{key:"status",get:function(){return this.response.status}},{key:"getHeader",value:function(e){return this.response.headers.get(e)}},{key:"getData",value:(t=u(x.mark((function e(){var t;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.response.arrayBuffer){e.next=6;break}return e.next=3,this.response.arrayBuffer();case 3:e.t0=e.sent,e.next=9;break;case 6:return e.next=8,this.response.buffer();case 8:e.t0=e.sent.buffer;case 9:return t=e.t0,e.abrupt("return",t);case 11:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),n}(bt),_t=function(e){h(n,e);var t,r=xt(n);function n(e,t){var i;return b(this,n),(i=r.call(this,e)).credentials=t,i}return c(n,[{key:"request",value:(t=u(x.mark((function e(){var t,r,n,i,a,o=arguments;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=o.length>0&&void 0!==o[0]?o[0]:{},r=t.headers,n=t.credentials,i=t.signal,e.next=3,fetch(this.url,{headers:r,credentials:n,signal:i});case 3:return a=e.sent,e.abrupt("return",new At(a));case 5:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),n}(kt);function It(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=v(e);if(t){var i=v(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return m(this,r)}}var Pt=function(e){h(n,e);var t,r=It(n);function n(e,t){var i;return b(this,n),(i=r.call(this)).xhr=e,i.data=t,i}return c(n,[{key:"status",get:function(){return this.xhr.status}},{key:"getHeader",value:function(e){return this.xhr.getResponseHeader(e)}},{key:"getData",value:(t=u(x.mark((function e(){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.data);case 1:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),n}(bt),St=function(e){h(n,e);var t,r=It(n);function n(){return b(this,n),r.apply(this,arguments)}return c(n,[{key:"constructRequest",value:function(e,t){var r=this;return new Promise((function(n,i){var a=new XMLHttpRequest;a.open("GET",r.url),a.responseType="arraybuffer";for(var s=0,u=Object.entries(e);s0&&void 0!==a[0]?a[0]:{},r=t.headers,n=t.signal,e.next=3,this.constructRequest(r,n);case 3:return i=e.sent,e.abrupt("return",i);case 5:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),n}(kt),Tt={};function Ut(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function Ot(e){for(var r=1;r0&&void 0!==a[0]?a[0]:{},r=t.headers,n=t.signal,e.next=3,this.constructRequest(r,n);case 3:return i=e.sent,e.abrupt("return",i);case 5:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),n}(kt),Mt=["headers","credentials","maxRanges","allowFullFile"],Bt=["headers","maxRanges","allowFullFile"],Ct=["headers","maxRanges","allowFullFile"],Lt=["forceXHR"];function Ft(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function Vt(e){for(var r=1;r=t.length)){e.next=4;break}return e.abrupt("return",this.fetchSlices(t,r));case 4:this.maxRanges>0&&t.length;case 5:return e.abrupt("return",Promise.all(t.map((function(e){return n.fetchSlice(e,r)}))));case 6:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"fetchSlices",value:(r=u(x.mark((function e(t,r){var n,i,a,o,s,u,f,c,l,h,d,p,m,v=this;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.client.request({headers:Vt(Vt({},this.headers),{},{Range:"bytes=".concat(t.map((function(e){var t=e.offset,r=e.length;return"".concat(t,"-").concat(t+r)})).join(","))}),signal:r});case 2:if((n=e.sent).ok){e.next=7;break}throw new Error("Error fetching data.");case 7:if(206!==n.status){e.next=32;break}if(i=We(n.getHeader("content-type")),a=i.type,o=i.params,"multipart/byteranges"!==a){e.next=18;break}return e.t0=Qe,e.next=13,n.getData();case 13:return e.t1=e.sent,e.t2=o.boundary,s=(0,e.t0)(e.t1,e.t2),this._fileSize=s[0].fileSize||null,e.abrupt("return",s);case 18:return e.next=20,n.getData();case 20:if(u=e.sent,f=Je(n.getHeader("content-range")),c=f.start,l=f.end,h=f.total,this._fileSize=h||null,d=[{data:u,offset:c,length:l-c}],!(t.length>1)){e.next=29;break}return e.next=27,Promise.all(t.slice(1).map((function(e){return v.fetchSlice(e,r)})));case 27:return p=e.sent,e.abrupt("return",d.concat(p));case 29:return e.abrupt("return",d);case 32:if(this.allowFullFile){e.next=34;break}throw new Error("Server responded with full file");case 34:return e.next=36,n.getData();case 36:return m=e.sent,this._fileSize=m.byteLength,e.abrupt("return",[{data:m,offset:0,length:m.byteLength}]);case 39:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"fetchSlice",value:(t=u(x.mark((function e(t,r){var n,i,a,o,s,u,f;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.offset,i=t.length,e.next=3,this.client.request({headers:Vt(Vt({},this.headers),{},{Range:"bytes=".concat(n,"-").concat(n+i)}),signal:r});case 3:if((a=e.sent).ok){e.next=8;break}throw new Error("Error fetching data.");case 8:if(206!==a.status){e.next=17;break}return e.next=11,a.getData();case 11:return o=e.sent,s=Je(a.getHeader("content-range")),u=s.total,this._fileSize=u||null,e.abrupt("return",{data:o,offset:n,length:i});case 17:if(this.allowFullFile){e.next=19;break}throw new Error("Server responded with full file");case 19:return e.next=21,a.getData();case 21:return f=e.sent,this._fileSize=f.byteLength,e.abrupt("return",{data:f,offset:0,length:f.byteLength});case 24:case"end":return e.stop()}}),e,this)}))),function(e,r){return t.apply(this,arguments)})},{key:"fileSize",get:function(){return this._fileSize}}]),a}($e);function zt(e,t){var r=t.blockSize,n=t.cacheSize;return null===r?e:new wt(e,{blockSize:r,cacheSize:n})}function Nt(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.headers,n=void 0===r?{}:r,i=t.credentials,a=t.maxRanges,o=void 0===a?0:a,s=t.allowFullFile,u=void 0!==s&&s,f=Ke(t,Mt),c=new _t(e,i),l=new jt(c,n,o,u);return zt(l,f)}function Kt(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.headers,n=void 0===r?{}:r,i=t.maxRanges,a=void 0===i?0:i,o=t.allowFullFile,s=void 0!==o&&o,u=Ke(t,Bt),f=new St(e),c=new jt(f,n,a,s);return zt(c,u)}function Zt(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.headers,n=void 0===r?{}:r,i=t.maxRanges,a=void 0===i?0:i,o=t.allowFullFile,s=void 0!==o&&o,u=Ke(t,Ct),f=new Rt(e),c=new jt(f,n,a,s);return zt(c,u)}function Ht(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.forceXHR,n=void 0!==r&&r,i=Ke(t,Lt);return"function"!=typeof fetch||n?"undefined"!=typeof XMLHttpRequest?Kt(e,i):Zt(e,i):Nt(e,i)}function Yt(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=v(e);if(t){var i=v(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return m(this,r)}}var qt=function(e){h(r,e);var t=Yt(r);function r(e){var n;return b(this,r),(n=t.call(this)).arrayBuffer=e,n}return c(r,[{key:"fetchSlice",value:function(e,t){if(t&&t.aborted)throw new ht("Request aborted");return this.arrayBuffer.slice(e.offset,e.offset+e.length)}}]),r}($e);function Xt(e){return new qt(e)}function Wt(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=v(e);if(t){var i=v(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return m(this,r)}}var Jt=function(e){h(n,e);var t,r=Wt(n);function n(e){var t;return b(this,n),(t=r.call(this)).file=e,t}return c(n,[{key:"fetchSlice",value:(t=u(x.mark((function e(t,r){var n=this;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e,i){var a=n.file.slice(t.offset,t.offset+t.length),o=new FileReader;o.onload=function(t){return e(t.target.result)},o.onerror=i,o.onabort=i,o.readAsArrayBuffer(a),r&&r.addEventListener("abort",(function(){return o.abort()}))})));case 1:case"end":return e.stop()}}),e)}))),function(e,r){return t.apply(this,arguments)})}]),n}($e);function Qt(e){return new Jt(e)}function $t(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=v(e);if(t){var i=v(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return m(this,r)}}function er(e){return new Promise((function(t,r){Tt.close(e,(function(e){e?r(e):t()}))}))}function tr(){for(var e=arguments.length,t=new Array(e),r=0;r2&&void 0!==arguments[2]?arguments[2]:void 0;return new Promise((function(n,i){Tt.open(e,t,r,(function(e,t){e?i(e):n(t)}))}))}(e,"r"),t}return c(i,[{key:"fetchSlice",value:(r=u(x.mark((function e(t){var r,n,i;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.openRequest;case 2:return r=e.sent,e.next=5,tr(r,Buffer.alloc(t.length),0,t.length,t.offset);case 5:return n=e.sent,i=n.buffer,e.abrupt("return",i.buffer);case 8:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"close",value:(t=u(x.mark((function e(){var t;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.openRequest;case 2:return t=e.sent,e.next=5,er(t);case 5:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),i}($e);function nr(e){return new rr(e)}function ir(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,t){if(!e)return;if("string"==typeof e)return ar(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return ar(e,t)}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,i=function(){};return{s:i,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,s=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||null==r.return||r.return()}finally{if(s)throw a}}}}function ar(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r>8&255,e[t+1]=255&r},writeUint:function(e,t,r){e[t]=r>>24&255,e[t+1]=r>>16&255,e[t+2]=r>>8&255,e[t+3]=r>>0&255},writeASCII:function(e,t,r){ut(r.length,(function(n){e[t+n]=r.charCodeAt(n)}))},ui8:new Uint8Array(8)};lr.fl64=new Float64Array(lr.ui8.buffer),lr.writeDouble=function(e,t,r){lr.fl64[0]=r,ut(8,(function(r){e[t+r]=lr.ui8[7-r]}))};var hr=function(e){var t=new Uint8Array(cr),r=4,n=lr;t[0]=77,t[1]=77,t[3]=42;var i=8;if(n.writeUint(t,r,i),r+=4,e.forEach((function(r,a){var o=function(e,t,r,n){var i=r,a=Object.keys(n).filter((function(e){return null!=e&&"undefined"!==e}));e.writeUshort(t,i,a.length);var o,s=(i+=2)+12*a.length+4,u=ir(a);try{var f=function(){var r=o.value,a=null;"number"==typeof r?a=r:"string"==typeof r&&(a=parseInt(r,10));var u=te[a],f=fr[u];if(null==u||void 0===u||void 0===u)throw new Error("unknown type of tag: ".concat(a));var c=n[r];if(void 0===c)throw new Error("failed to get value for key ".concat(r));"ASCII"===u&&"string"==typeof c&&!1===ot(c,"\0")&&(c+="\0");var l=c.length;e.writeUshort(t,i,a),i+=2,e.writeUshort(t,i,f),i+=2,e.writeUint(t,i,l);var h=[-1,1,1,2,4,8,0,0,0,0,0,0,8][f]*l,d=i+=4;h>4&&(e.writeUint(t,i,s),d=s),"ASCII"===u?e.writeASCII(t,d,c):"SHORT"===u?ut(l,(function(r){e.writeUshort(t,d+2*r,c[r])})):"LONG"===u?ut(l,(function(r){e.writeUint(t,d+4*r,c[r])})):"RATIONAL"===u?ut(l,(function(r){e.writeUint(t,d+8*r,Math.round(1e4*c[r])),e.writeUint(t,d+8*r+4,1e4)})):"DOUBLE"===u&&ut(l,(function(r){e.writeDouble(t,d+8*r,c[r])})),h>4&&(s+=h+=1&h),i+=4};for(u.s();!(o=u.n()).done;)f()}catch(e){u.e(e)}finally{u.f()}return[i,s]}(n,t,i,r);i=o[1],a0&&(t.GeoAsciiParams=s)}if(!t.GeoKeyDirectory){var u=[1,1,0,o.length];o.forEach((function(e){var r,n,i,a=Number(ur[e]);u.push(a),"SHORT"===te[a]?(r=1,n=0,i=t[e]):"GeogCitationGeoKey"===e?(r=t.GeoAsciiParams.length,n=Number(ur.GeoAsciiParams),i=0):console.log("[geotiff.js] couldn't get TIFFTagLocation for ".concat(e)),u.push(n),u.push(r),u.push(i)})),t.GeoKeyDirectory=u}for(var f in o)o.hasOwnProperty(f)&&delete t[f];["Compression","ExtraSamples","GeographicTypeGeoKey","GTModelTypeGeoKey","GTRasterTypeGeoKey","ImageLength","ImageWidth","Orientation","PhotometricInterpretation","ProjectedCSTypeGeoKey","PlanarConfiguration","ResolutionUnit","SamplesPerPixel","XPosition","YPosition"].forEach((function(e){var r;t[e]&&(t[e]=(r=t[e],Array.isArray(r)?r:[r]))}));var c=function(e){var t={};for(var r in e)"StripOffsets"!==r&&(ur[r]||console.error(r,"not in name2code:",Object.keys(ur)),t[ur[r]]=e[r]);return t}(t),l=function(e,t,r,n){if(null==r)throw new Error("you passed into encodeImage a width of type ".concat(r));if(null==t)throw new Error("you passed into encodeImage a width of type ".concat(t));var i={256:[t],257:[r],273:[cr],278:[r],305:"geotiff.js"};if(n)for(var a in n)n.hasOwnProperty(a)&&(i[a]=n[a]);var o=new Uint8Array(hr([i])),s=new Uint8Array(e),u=i[277],f=new Uint8Array(cr+t*r*u);return ut(o.length,(function(e){f[e]=o[e]})),function(e,t){for(var r=e.length,n=0;n0;i--)e[n+t]+=e[n],n++;r-=t}while(r>0)}function yr(e,t,r){for(var n=0,i=e.length,a=i/r;i>t;){for(var o=t;o>0;--o)e[n+t]+=e[n],++n;i-=t}for(var s=e.slice(),u=0;u=e.byteLength);++f){var c=void 0;if(2===t){switch(i[0]){case 8:c=new Uint8Array(e,f*u*r*s,u*r*s);break;case 16:c=new Uint16Array(e,f*u*r*s,u*r*s/2);break;case 32:c=new Uint32Array(e,f*u*r*s,u*r*s/4);break;default:throw new Error("Predictor 2 not allowed with ".concat(i[0]," bits per sample."))}vr(c,u)}else 3===t&&yr(c=new Uint8Array(e,f*u*r*s,u*r*s),u,s)}return e}new mr;var wr=function(){function e(){b(this,e)}var t;return c(e,[{key:"decode",value:(t=u(x.mark((function e(t,r){var n,i,a,o,s;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.decodeBlock(r);case 2:if(n=e.sent,1===(i=t.Predictor||1)){e.next=9;break}return a=!t.StripOffsets,o=a?t.TileWidth:t.ImageWidth,s=a?t.TileLength:t.RowsPerStrip||t.ImageLength,e.abrupt("return",gr(n,i,o,s,t.BitsPerSample,t.PlanarConfiguration));case 9:return e.abrupt("return",n);case 10:case"end":return e.stop()}}),e,this)}))),function(e,r){return t.apply(this,arguments)})}]),e}();function br(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function kr(e){for(var r=1;r0&&void 0!==z[0]?z[0]:{},r=t.window,n=t.width,i=t.height,a=t.resX,s=t.resY,u=t.bbox,e.next=5,this.getImage();case 5:return f=e.sent,c=f,e.next=9,this.getImageCount();case 9:if(l=e.sent,h=f.getBoundingBox(),!r||!u){e.next=13;break}throw new Error('Both "bbox" and "window" passed.');case 13:if(!n&&!i){e.next=24;break}if(r&&(d=f.getOrigin(),p=o(d,2),m=p[0],v=p[1],y=f.getResolution(),g=o(y,2),w=g[0],b=g[1],u=[m+r[0]*w,v+r[1]*b,m+r[2]*w,v+r[3]*b]),k=u||h,!n){e.next=20;break}if(!a){e.next=19;break}throw new Error("Both width and resX passed");case 19:a=(k[2]-k[0])/n;case 20:if(!i){e.next=24;break}if(!s){e.next=23;break}throw new Error("Both width and resY passed");case 23:s=(k[3]-k[1])/i;case 24:if(!a&&!s){e.next=48;break}A=[],_=0;case 27:if(!(_D||s&&s>E)){e.next=45;break}return e.abrupt("break",48);case 45:++U,e.next=38;break;case 48:return R=r,u&&(M=f.getOrigin(),B=o(M,2),C=B[0],L=B[1],F=c.getResolution(f),V=o(F,2),G=V[0],j=V[1],R=[Math.round((u[0]-C)/G),Math.round((u[1]-L)/j),Math.round((u[2]-C)/G),Math.round((u[3]-L)/j)],R=[Math.min(R[0],R[2]),Math.min(R[1],R[3]),Math.max(R[0],R[2]),Math.max(R[1],R[3])]),e.abrupt("return",c.readRasters(kr(kr({},t),{},{window:R})));case 51:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}(),Ur=function(e){h(d,e);var t,r,n,i,a,s,f,l=xr(d);function d(e,t,r,n){var i,a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};return b(this,d),(i=l.call(this)).source=e,i.littleEndian=t,i.bigTiff=r,i.firstIFDOffset=n,i.cache=a.cache||!1,i.ifdRequests=[],i.ghostValues=null,i}return c(d,[{key:"getSlice",value:(f=u(x.mark((function e(t,r){var n;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=this.bigTiff?4048:1024,e.t0=Ge,e.next=4,this.source.fetch([{offset:t,length:void 0!==r?r:n}]);case 4:return e.t1=e.sent[0],e.t2=t,e.t3=this.littleEndian,e.t4=this.bigTiff,e.abrupt("return",new e.t0(e.t1,e.t2,e.t3,e.t4));case 9:case"end":return e.stop()}}),e,this)}))),function(e,t){return f.apply(this,arguments)})},{key:"parseFileDirectoryAt",value:(s=u(x.mark((function e(t){var r,n,i,a,o,s,u,f,c,l,h,d,p,m,v,y,g,w,b,k;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=this.bigTiff?20:12,n=this.bigTiff?8:2,e.next=4,this.getSlice(t);case 4:if(i=e.sent,a=this.bigTiff?i.readUint64(t):i.readUint16(t),o=a*r+(this.bigTiff?16:6),i.covers(t,o)){e.next=11;break}return e.next=10,this.getSlice(t,o);case 10:i=e.sent;case 11:s={},u=t+(this.bigTiff?8:2),f=0;case 14:if(!(f0&&void 0!==n[0]?n[0]:0,e.next=3,this.requestIFD(t);case 3:return r=e.sent,e.abrupt("return",new Fe(r.fileDirectory,r.geoKeyDirectory,this.dataView,this.littleEndian,this.cache,this.source));case 5:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"getImageCount",value:(n=u(x.mark((function e(){var t,r;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=0,r=!0;case 2:if(!r){e.next=18;break}return e.prev=3,e.next=6,this.requestIFD(t);case 6:++t,e.next=16;break;case 9:if(e.prev=9,e.t0=e.catch(3),!(e.t0 instanceof Sr)){e.next=15;break}r=!1,e.next=16;break;case 15:throw e.t0;case 16:e.next=2;break;case 18:return e.abrupt("return",t);case 19:case"end":return e.stop()}}),e,this,[[3,9]])}))),function(){return n.apply(this,arguments)})},{key:"getGhostValues",value:(r=u(x.mark((function e(){var t,r,n,i,a,s,u,f,c=this;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=this.bigTiff?16:8,!this.ghostValues){e.next=3;break}return e.abrupt("return",this.ghostValues);case 3:return n=(r="GDAL_STRUCTURAL_METADATA_SIZE=").length+100,e.next=7,this.getSlice(t,n);case 7:if(i=e.sent,r!==Ir(i,ie.ASCII,r.length,t)){e.next=19;break}if(a=Ir(i,ie.ASCII,n,t),s=a.split("\n")[0],!((u=Number(s.split("=")[1].split(" ")[0])+s.length)>n)){e.next=16;break}return e.next=15,this.getSlice(t,u);case 15:i=e.sent;case 16:f=Ir(i,ie.ASCII,u,t),this.ghostValues={},f.split("\n").filter((function(e){return e.length>0})).map((function(e){return e.split("=")})).forEach((function(e){var t=o(e,2),r=t[0],n=t[1];c.ghostValues[r]=n}));case 19:return e.abrupt("return",this.ghostValues);case 20:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"close",value:function(){return"function"==typeof this.source.close&&this.source.close()}}],[{key:"fromSource",value:(t=u(x.mark((function e(t,r,n){var i,a,o,s,u,f,c;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.fetch([{offset:0,length:1024}],n);case 2:if(i=e.sent[0],a=new Ve(i),18761!==(o=a.getUint16(0,0))){e.next=9;break}s=!0,e.next=14;break;case 9:if(19789!==o){e.next=13;break}s=!1,e.next=14;break;case 13:throw new TypeError("Invalid byte order value.");case 14:if(42!==(u=a.getUint16(2,s))){e.next=19;break}f=!1,e.next=27;break;case 19:if(43!==u){e.next=26;break}if(f=!0,8===a.getUint16(4,s)){e.next=24;break}throw new Error("Unsupported offset byte-size.");case 24:e.next=27;break;case 26:throw new TypeError("Invalid magic number.");case 27:return c=f?a.getUint64(8,s):a.getUint32(4,s),e.abrupt("return",new d(t,s,f,c,r));case 29:case"end":return e.stop()}}),e)}))),function(e,r,n){return t.apply(this,arguments)})}]),d}(Tr),Or=function(e){h(a,e);var t,r,n,i=xr(a);function a(e,t){var r;return b(this,a),(r=i.call(this)).mainFile=e,r.overviewFiles=t,r.imageFiles=[e].concat(t),r.fileDirectoriesPerFile=null,r.fileDirectoriesPerFileParsing=null,r.imageCount=null,r}return c(a,[{key:"parseFileDirectoriesPerFile",value:(n=u(x.mark((function e(){var t;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=[this.mainFile.parseFileDirectoryAt(this.mainFile.firstIFDOffset)].concat(this.overviewFiles.map((function(e){return e.parseFileDirectoryAt(e.firstIFDOffset)}))),e.next=3,Promise.all(t);case 3:return this.fileDirectoriesPerFile=e.sent,e.abrupt("return",this.fileDirectoriesPerFile);case 5:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"getImage",value:(r=u(x.mark((function e(){var t,r,n,i,a,o,s,u=arguments;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=u.length>0&&void 0!==u[0]?u[0]:0,e.next=3,this.getImageCount();case 3:return e.next=5,this.parseFileDirectoriesPerFile();case 5:r=0,n=0,i=0;case 8:if(!(i1&&void 0!==i[1]?i[1]:{},n=i.length>2?i[2]:void 0,e.abrupt("return",Ur.fromSource(Ht(t,r),n));case 3:case"end":return e.stop()}}),e)}))),Dr.apply(this,arguments)}function Er(){return(Er=u(x.mark((function e(t,r){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",Ur.fromSource(Xt(t),r));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Rr(){return(Rr=u(x.mark((function e(t,r){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",Ur.fromSource(nr(t),r));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Mr(){return(Mr=u(x.mark((function e(t,r){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",Ur.fromSource(Qt(t),r));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Br(){return Br=u(x.mark((function e(t){var r,n,i,a,o,s=arguments;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=s.length>1&&void 0!==s[1]?s[1]:[],n=s.length>2&&void 0!==s[2]?s[2]:{},i=s.length>3?s[3]:void 0,e.next=5,Ur.fromSource(Ht(t,n),i);case 5:return a=e.sent,e.next=8,Promise.all(r.map((function(e){return Ur.fromSource(Ht(e,n))})));case 8:return o=e.sent,e.abrupt("return",new Or(a,o));case 10:case"end":return e.stop()}}),e)}))),Br.apply(this,arguments)}function Cr(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=v(e);if(t){var i=v(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return m(this,r)}}var Lr=function(e){h(r,e);var t=Cr(r);function r(){return b(this,r),t.apply(this,arguments)}return c(r,[{key:"decodeBlock",value:function(e){return e}}]),r}(wr),Fr=Object.freeze({__proto__:null,default:Lr});function Vr(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=v(e);if(t){var i=v(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return m(this,r)}}function Gr(e,t){for(var r=t.length-1;r>=0;r--)e.push(t[r]);return e}function jr(e){for(var t=new Uint16Array(4093),r=new Uint8Array(4093),n=0;n<=257;n++)t[n]=4096,r[n]=n;var i=258,a=9,o=0;function s(){i=258,a=9}function u(e){var t=function(e,t,r){var n=t%8,i=Math.floor(t/8),a=8-n,o=t+r-8*(i+1),s=8*(i+2)-(t+r),u=8*(i+2)-t;if(s=Math.max(0,s),i>=e.length)return console.warn("ran off the end of the buffer before finding EOI_CODE (end on input code)"),257;var f=e[i]&Math.pow(2,8-n)-1,c=f<<=r-a;if(i+1>>s;c+=l<<=Math.max(0,r-u)}if(o>8&&i+2>>h}return c}(e,o,a);return o+=a,t}function f(e,n){return r[i]=n,t[i]=e,++i-1}function c(e){for(var n=[],i=e;4096!==i;i=t[i])n.push(r[i]);return n}var l=[];s();for(var h,d=new Uint8Array(e),p=u(d);257!==p;){if(256===p){for(s(),p=u(d);256===p;)p=u(d);if(257===p)break;if(p>256)throw new Error("corrupted code at scanline ".concat(p));Gr(l,c(p)),h=p}else if(p=Math.pow(2,a)&&(12===a?h=void 0:a++),p=u(d)}return new Uint8Array(l)}var zr=function(e){h(r,e);var t=Vr(r);function r(){return b(this,r),t.apply(this,arguments)}return c(r,[{key:"decodeBlock",value:function(e){return jr(e).buffer}}]),r}(wr),Nr=Object.freeze({__proto__:null,default:zr});function Kr(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=v(e);if(t){var i=v(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return m(this,r)}}var Zr=new Int32Array([0,1,8,16,9,2,3,10,17,24,32,25,18,11,4,5,12,19,26,33,40,48,41,34,27,20,13,6,7,14,21,28,35,42,49,56,57,50,43,36,29,22,15,23,30,37,44,51,58,59,52,45,38,31,39,46,53,60,61,54,47,55,62,63]),Hr=4017,Yr=799,qr=3406,Xr=2276,Wr=1567,Jr=3784,Qr=5793,$r=2896;function en(e,t){for(var r=0,n=[],i=16;i>0&&!e[i-1];)--i;n.push({children:[],index:0});for(var a,o=n[0],s=0;s0;)o=n.pop();for(o.index++,n.push(o);n.length<=s;)n.push(a={children:[],index:0}),o.children[o.index]=a.children,o=a;r++}s+10)return m--,p>>m&1;if(255===(p=e[h++])){var t=e[h++];if(t)throw new Error("unexpected marker: ".concat((p<<8|t).toString(16)))}return m=7,p>>>7}function y(e){for(var t,r=e;null!==(t=v());){if("number"==typeof(r=r[t]))return r;if("object"!==d(r))throw new Error("invalid huffman sequence")}return null}function g(e){for(var t=e,r=0;t>0;){var n=v();if(null===n)return;r=r<<1|n,--t}return r}function w(e){var t=g(e);return t>=1<0)b--;else for(var r=a,n=o;r<=n;){var i=y(e.huffmanTableAC),s=15&i,f=i>>4;if(0===s){if(f<15){b=g(f)+(1<>4,0===l)i<15?(b=g(i)+(1<>4;if(0===o){if(s<15)break;i+=16}else t[Zr[i+=s]]=w(o),i++}};var E,R,M=0;R=1===D?n[0].blocksPerLine*n[0].blocksPerColumn:f*r.mcusPerColumn;for(var B=i||R;M=65488&&E<=65495))break;h+=2}return h-l}function rn(e,t){var r=[],n=t.blocksPerLine,i=t.blocksPerColumn,a=n<<3,o=new Int32Array(64),s=new Uint8Array(64);function u(e,r,n){var i,a,o,s,u,f,c,l,h,d,p=t.quantizationTable,m=n;for(d=0;d<64;d++)m[d]=e[d]*p[d];for(d=0;d<8;++d){var v=8*d;0!==m[1+v]||0!==m[2+v]||0!==m[3+v]||0!==m[4+v]||0!==m[5+v]||0!==m[6+v]||0!==m[7+v]?(i=Qr*m[0+v]+128>>8,a=Qr*m[4+v]+128>>8,o=m[2+v],s=m[6+v],u=$r*(m[1+v]-m[7+v])+128>>8,l=$r*(m[1+v]+m[7+v])+128>>8,f=m[3+v]<<4,c=m[5+v]<<4,h=i-a+1>>1,i=i+a+1>>1,a=h,h=o*Jr+s*Wr+128>>8,o=o*Wr-s*Jr+128>>8,s=h,h=u-c+1>>1,u=u+c+1>>1,c=h,h=l+f+1>>1,f=l-f+1>>1,l=h,h=i-s+1>>1,i=i+s+1>>1,s=h,h=a-o+1>>1,a=a+o+1>>1,o=h,h=u*Xr+l*qr+2048>>12,u=u*qr-l*Xr+2048>>12,l=h,h=f*Yr+c*Hr+2048>>12,f=f*Hr-c*Yr+2048>>12,c=h,m[0+v]=i+l,m[7+v]=i-l,m[1+v]=a+c,m[6+v]=a-c,m[2+v]=o+f,m[5+v]=o-f,m[3+v]=s+u,m[4+v]=s-u):(h=Qr*m[0+v]+512>>10,m[0+v]=h,m[1+v]=h,m[2+v]=h,m[3+v]=h,m[4+v]=h,m[5+v]=h,m[6+v]=h,m[7+v]=h)}for(d=0;d<8;++d){var y=d;0!==m[8+y]||0!==m[16+y]||0!==m[24+y]||0!==m[32+y]||0!==m[40+y]||0!==m[48+y]||0!==m[56+y]?(i=Qr*m[0+y]+2048>>12,a=Qr*m[32+y]+2048>>12,o=m[16+y],s=m[48+y],u=$r*(m[8+y]-m[56+y])+2048>>12,l=$r*(m[8+y]+m[56+y])+2048>>12,f=m[24+y],c=m[40+y],h=i-a+1>>1,i=i+a+1>>1,a=h,h=o*Jr+s*Wr+2048>>12,o=o*Wr-s*Jr+2048>>12,s=h,h=u-c+1>>1,u=u+c+1>>1,c=h,h=l+f+1>>1,f=l-f+1>>1,l=h,h=i-s+1>>1,i=i+s+1>>1,s=h,h=a-o+1>>1,a=a+o+1>>1,o=h,h=u*Xr+l*qr+2048>>12,u=u*qr-l*Xr+2048>>12,l=h,h=f*Yr+c*Hr+2048>>12,f=f*Hr-c*Yr+2048>>12,c=h,m[0+y]=i+l,m[56+y]=i-l,m[8+y]=a+c,m[48+y]=a-c,m[16+y]=o+f,m[40+y]=o-f,m[24+y]=s+u,m[32+y]=s-u):(h=Qr*n[d+0]+8192>>14,m[0+y]=h,m[8+y]=h,m[16+y]=h,m[24+y]=h,m[32+y]=h,m[40+y]=h,m[48+y]=h,m[56+y]=h)}for(d=0;d<64;++d){var g=128+(m[d]+8>>4);r[d]=g<0?0:g>255?255:g}}for(var f=0;f>4==0)for(var l=0;l<64;l++){c[Zr[l]]=e[t++]}else{if(f>>4!=1)throw new Error("DQT: invalid table spec");for(var h=0;h<64;h++){c[Zr[h]]=r()}}this.quantizationTables[15&f]=c}break;case 65472:case 65473:case 65474:r();for(var d={extended:65473===o,progressive:65474===o,precision:e[t++],scanLines:r(),samplesPerLine:r(),components:{},componentsOrder:[]},p=e[t++],m=void 0,v=0;v>4,g=15&e[t+1],w=e[t+2];d.componentsOrder.push(m),d.components[m]={h:y,v:g,quantizationIdx:w},t+=3}n(d),this.frames.push(d);break;case 65476:for(var b=r(),k=2;k>4==0?this.huffmanTablesDC[15&x]=en(A,P):this.huffmanTablesAC[15&x]=en(A,P)}break;case 65501:r(),this.resetInterval=r();break;case 65498:r();for(var T=e[t++],U=[],O=this.frames[0],D=0;D>4],E.huffmanTableAC=this.huffmanTablesAC[15&R],U.push(E)}var M=e[t++],B=e[t++],C=e[t++],L=tn(e,t,O,U,this.resetInterval,M,B,C>>4,15&C);t+=L;break;case 65535:255!==e[t]&&t--;break;default:if(255===e[t-3]&&e[t-2]>=192&&e[t-2]<=254){t-=3;break}throw new Error("unknown JPEG marker ".concat(o.toString(16)))}o=r()}}},{key:"getResult",value:function(){var e=this.frames;if(0===this.frames.length)throw new Error("no frames were decoded");this.frames.length>1&&console.warn("more than one frame is not supported");for(var t=0;t=0;)e[t]=0}sn(new Array(576)),sn(new Array(60)),sn(new Array(512)),sn(new Array(256)),sn(new Array(29)),sn(new Array(30));var un=function(e,t,r,n){for(var i=65535&e|0,a=e>>>16&65535|0,o=0;0!==r;){r-=o=r>2e3?2e3:r;do{a=a+(i=i+t[n++]|0)|0}while(--o);i%=65521,a%=65521}return i|a<<16|0},fn=new Uint32Array(function(){for(var e,t=[],r=0;r<256;r++){e=r;for(var n=0;n<8;n++)e=1&e?3988292384^e>>>1:e>>>1;t[r]=e}return t}()),cn=function(e,t,r,n){var i=fn,a=n+r;e^=-1;for(var o=n;o>>8^i[255&(e^t[o])];return-1^e},ln={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},hn={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8},dn=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},pn=function(e){for(var t=Array.prototype.slice.call(arguments,1);t.length;){var r=t.shift();if(r){if("object"!==d(r))throw new TypeError(r+"must be non-object");for(var n in r)dn(r,n)&&(e[n]=r[n])}}return e},mn=function(e){for(var t=0,r=0,n=e.length;r=252?6:gn>=248?5:gn>=240?4:gn>=224?3:gn>=192?2:1;yn[254]=yn[254]=1;var wn=function(e){if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(e);var t,r,n,i,a,o=e.length,s=0;for(i=0;i>>6,t[a++]=128|63&r):r<65536?(t[a++]=224|r>>>12,t[a++]=128|r>>>6&63,t[a++]=128|63&r):(t[a++]=240|r>>>18,t[a++]=128|r>>>12&63,t[a++]=128|r>>>6&63,t[a++]=128|63&r);return t},bn=function(e,t){var r,n,i=t||e.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(e.subarray(0,t));var a=new Array(2*i);for(n=0,r=0;r4)a[n++]=65533,r+=s-1;else{for(o&=2===s?31:3===s?15:7;s>1&&r1?a[n++]=65533:o<65536?a[n++]=o:(o-=65536,a[n++]=55296|o>>10&1023,a[n++]=56320|1023&o)}}}return function(e,t){if(t<65534&&e.subarray&&vn)return String.fromCharCode.apply(null,e.length===t?e:e.subarray(0,t));for(var r="",n=0;ne.length&&(t=e.length);for(var r=t-1;r>=0&&128==(192&e[r]);)r--;return r<0||0===r?t:r+yn[e[r]]>t?r:t};var xn=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0},An=function(e,t){var r,n,i,a,o,s,u,f,c,l,h,d,p,m,v,y,g,w,b,k,x,A,_,I,P=e.state;r=e.next_in,_=e.input,n=r+(e.avail_in-5),i=e.next_out,I=e.output,a=i-(t-e.avail_out),o=i+(e.avail_out-257),s=P.dmax,u=P.wsize,f=P.whave,c=P.wnext,l=P.window,h=P.hold,d=P.bits,p=P.lencode,m=P.distcode,v=(1<>>=w=g>>>24,d-=w,0===(w=g>>>16&255))I[i++]=65535&g;else{if(!(16&w)){if(0==(64&w)){g=p[(65535&g)+(h&(1<>>=w,d-=w),d<15&&(h+=_[r++]<>>=w=g>>>24,d-=w,!(16&(w=g>>>16&255))){if(0==(64&w)){g=m[(65535&g)+(h&(1<s){e.msg="invalid distance too far back",P.mode=30;break e}if(h>>>=w,d-=w,k>(w=i-a)){if((w=k-w)>f&&P.sane){e.msg="invalid distance too far back",P.mode=30;break e}if(x=0,A=l,0===c){if(x+=u-w,w2;)I[i++]=A[x++],I[i++]=A[x++],I[i++]=A[x++],b-=3;b&&(I[i++]=A[x++],b>1&&(I[i++]=A[x++]))}else{x=i-k;do{I[i++]=I[x++],I[i++]=I[x++],I[i++]=I[x++],b-=3}while(b>2);b&&(I[i++]=I[x++],b>1&&(I[i++]=I[x++]))}break}}break}}while(r>3,h&=(1<<(d-=b<<3))-1,e.next_in=r,e.next_out=i,e.avail_in=r=1&&0===O[k];k--);if(x>k&&(x=k),0===k)return i[a++]=20971520,i[a++]=20971520,s.bits=1,0;for(b=1;b0&&(0===e||1!==k))return-1;for(D[1]=0,g=1;g<_n;g++)D[g+1]=D[g]+O[g];for(w=0;w852||2===e&&P>592)return 1;for(;;){p=g-_,o[w]d?(m=E[R+o[w]],v=T[U+o[w]]):(m=96,v=0),u=1<>_)+(f-=u)]=p<<24|m<<16|v|0}while(0!==f);for(u=1<>=1;if(0!==u?(S&=u-1,S+=u):S=0,w++,0==--O[g]){if(g===k)break;g=t[r+o[w]]}if(g>x&&(S&l)!==c){for(0===_&&(_=x),h+=b,I=1<<(A=g-_);A+_852||2===e&&P>592)return 1;i[c=S&l]=x<<24|A<<16|h-a|0}}return 0!==S&&(i[h+S]=g-_<<24|64<<16|0),s.bits=x,0},On=hn.Z_FINISH,Dn=hn.Z_BLOCK,En=hn.Z_TREES,Rn=hn.Z_OK,Mn=hn.Z_STREAM_END,Bn=hn.Z_NEED_DICT,Cn=hn.Z_STREAM_ERROR,Ln=hn.Z_DATA_ERROR,Fn=hn.Z_MEM_ERROR,Vn=hn.Z_BUF_ERROR,Gn=hn.Z_DEFLATED,jn=12,zn=30,Nn=function(e){return(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24)};function Kn(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}var Zn,Hn,Yn=function(e){if(!e||!e.state)return Cn;var t=e.state;return e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=1,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new Int32Array(852),t.distcode=t.distdyn=new Int32Array(592),t.sane=1,t.back=-1,Rn},qn=function(e){if(!e||!e.state)return Cn;var t=e.state;return t.wsize=0,t.whave=0,t.wnext=0,Yn(e)},Xn=function(e,t){var r;if(!e||!e.state)return Cn;var n=e.state;return t<0?(r=0,t=-t):(r=1+(t>>4),t<48&&(t&=15)),t&&(t<8||t>15)?Cn:(null!==n.window&&n.wbits!==t&&(n.window=null),n.wrap=r,n.wbits=t,qn(e))},Wn=function(e,t){if(!e)return Cn;var r=new Kn;e.state=r,r.window=null;var n=Xn(e,t);return n!==Rn&&(e.state=null),n},Jn=!0,Qn=function(e){if(Jn){Zn=new Int32Array(512),Hn=new Int32Array(32);for(var t=0;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(Un(1,e.lens,0,288,Zn,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;Un(2,e.lens,0,32,Hn,0,e.work,{bits:5}),Jn=!1}e.lencode=Zn,e.lenbits=9,e.distcode=Hn,e.distbits=5},$n=function(e,t,r,n){var i,a=e.state;return null===a.window&&(a.wsize=1<=a.wsize?(a.window.set(t.subarray(r-a.wsize,r),0),a.wnext=0,a.whave=a.wsize):((i=a.wsize-a.wnext)>n&&(i=n),a.window.set(t.subarray(r-n,r-n+i),a.wnext),(n-=i)?(a.window.set(t.subarray(r-n,r),0),a.wnext=n,a.whave=a.wsize):(a.wnext+=i,a.wnext===a.wsize&&(a.wnext=0),a.whave>>8&255,r.check=cn(r.check,S,2,0),f=0,c=0,r.mode=2;break}if(r.flags=0,r.head&&(r.head.done=!1),!(1&r.wrap)||(((255&f)<<8)+(f>>8))%31){e.msg="incorrect header check",r.mode=zn;break}if((15&f)!==Gn){e.msg="unknown compression method",r.mode=zn;break}if(c-=4,x=8+(15&(f>>>=4)),0===r.wbits)r.wbits=x;else if(x>r.wbits){e.msg="invalid window size",r.mode=zn;break}r.dmax=1<>8&1),512&r.flags&&(S[0]=255&f,S[1]=f>>>8&255,r.check=cn(r.check,S,2,0)),f=0,c=0,r.mode=3;case 3:for(;c<32;){if(0===s)break e;s--,f+=n[a++]<>>8&255,S[2]=f>>>16&255,S[3]=f>>>24&255,r.check=cn(r.check,S,4,0)),f=0,c=0,r.mode=4;case 4:for(;c<16;){if(0===s)break e;s--,f+=n[a++]<>8),512&r.flags&&(S[0]=255&f,S[1]=f>>>8&255,r.check=cn(r.check,S,2,0)),f=0,c=0,r.mode=5;case 5:if(1024&r.flags){for(;c<16;){if(0===s)break e;s--,f+=n[a++]<>>8&255,r.check=cn(r.check,S,2,0)),f=0,c=0}else r.head&&(r.head.extra=null);r.mode=6;case 6:if(1024&r.flags&&((d=r.length)>s&&(d=s),d&&(r.head&&(x=r.head.extra_len-r.length,r.head.extra||(r.head.extra=new Uint8Array(r.head.extra_len)),r.head.extra.set(n.subarray(a,a+d),x)),512&r.flags&&(r.check=cn(r.check,n,d,a)),s-=d,a+=d,r.length-=d),r.length))break e;r.length=0,r.mode=7;case 7:if(2048&r.flags){if(0===s)break e;d=0;do{x=n[a+d++],r.head&&x&&r.length<65536&&(r.head.name+=String.fromCharCode(x))}while(x&&d>9&1,r.head.done=!0),e.adler=r.check=0,r.mode=jn;break;case 10:for(;c<32;){if(0===s)break e;s--,f+=n[a++]<>>=7&c,c-=7&c,r.mode=27;break}for(;c<3;){if(0===s)break e;s--,f+=n[a++]<>>=1)){case 0:r.mode=14;break;case 1:if(Qn(r),r.mode=20,t===En){f>>>=2,c-=2;break e}break;case 2:r.mode=17;break;case 3:e.msg="invalid block type",r.mode=zn}f>>>=2,c-=2;break;case 14:for(f>>>=7&c,c-=7&c;c<32;){if(0===s)break e;s--,f+=n[a++]<>>16^65535)){e.msg="invalid stored block lengths",r.mode=zn;break}if(r.length=65535&f,f=0,c=0,r.mode=15,t===En)break e;case 15:r.mode=16;case 16:if(d=r.length){if(d>s&&(d=s),d>u&&(d=u),0===d)break e;i.set(n.subarray(a,a+d),o),s-=d,a+=d,u-=d,o+=d,r.length-=d;break}r.mode=jn;break;case 17:for(;c<14;){if(0===s)break e;s--,f+=n[a++]<>>=5,c-=5,r.ndist=1+(31&f),f>>>=5,c-=5,r.ncode=4+(15&f),f>>>=4,c-=4,r.nlen>286||r.ndist>30){e.msg="too many length or distance symbols",r.mode=zn;break}r.have=0,r.mode=18;case 18:for(;r.have>>=3,c-=3}for(;r.have<19;)r.lens[T[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,_={bits:r.lenbits},A=Un(0,r.lens,0,19,r.lencode,0,r.work,_),r.lenbits=_.bits,A){e.msg="invalid code lengths set",r.mode=zn;break}r.have=0,r.mode=19;case 19:for(;r.have>>16&255,g=65535&P,!((v=P>>>24)<=c);){if(0===s)break e;s--,f+=n[a++]<>>=v,c-=v,r.lens[r.have++]=g;else{if(16===g){for(I=v+2;c>>=v,c-=v,0===r.have){e.msg="invalid bit length repeat",r.mode=zn;break}x=r.lens[r.have-1],d=3+(3&f),f>>>=2,c-=2}else if(17===g){for(I=v+3;c>>=v)),f>>>=3,c-=3}else{for(I=v+7;c>>=v)),f>>>=7,c-=7}if(r.have+d>r.nlen+r.ndist){e.msg="invalid bit length repeat",r.mode=zn;break}for(;d--;)r.lens[r.have++]=x}}if(r.mode===zn)break;if(0===r.lens[256]){e.msg="invalid code -- missing end-of-block",r.mode=zn;break}if(r.lenbits=9,_={bits:r.lenbits},A=Un(1,r.lens,0,r.nlen,r.lencode,0,r.work,_),r.lenbits=_.bits,A){e.msg="invalid literal/lengths set",r.mode=zn;break}if(r.distbits=6,r.distcode=r.distdyn,_={bits:r.distbits},A=Un(2,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,_),r.distbits=_.bits,A){e.msg="invalid distances set",r.mode=zn;break}if(r.mode=20,t===En)break e;case 20:r.mode=21;case 21:if(s>=6&&u>=258){e.next_out=o,e.avail_out=u,e.next_in=a,e.avail_in=s,r.hold=f,r.bits=c,An(e,h),o=e.next_out,i=e.output,u=e.avail_out,a=e.next_in,n=e.input,s=e.avail_in,f=r.hold,c=r.bits,r.mode===jn&&(r.back=-1);break}for(r.back=0;y=(P=r.lencode[f&(1<>>16&255,g=65535&P,!((v=P>>>24)<=c);){if(0===s)break e;s--,f+=n[a++]<>w)])>>>16&255,g=65535&P,!(w+(v=P>>>24)<=c);){if(0===s)break e;s--,f+=n[a++]<>>=w,c-=w,r.back+=w}if(f>>>=v,c-=v,r.back+=v,r.length=g,0===y){r.mode=26;break}if(32&y){r.back=-1,r.mode=jn;break}if(64&y){e.msg="invalid literal/length code",r.mode=zn;break}r.extra=15&y,r.mode=22;case 22:if(r.extra){for(I=r.extra;c>>=r.extra,c-=r.extra,r.back+=r.extra}r.was=r.length,r.mode=23;case 23:for(;y=(P=r.distcode[f&(1<>>16&255,g=65535&P,!((v=P>>>24)<=c);){if(0===s)break e;s--,f+=n[a++]<>w)])>>>16&255,g=65535&P,!(w+(v=P>>>24)<=c);){if(0===s)break e;s--,f+=n[a++]<>>=w,c-=w,r.back+=w}if(f>>>=v,c-=v,r.back+=v,64&y){e.msg="invalid distance code",r.mode=zn;break}r.offset=g,r.extra=15&y,r.mode=24;case 24:if(r.extra){for(I=r.extra;c>>=r.extra,c-=r.extra,r.back+=r.extra}if(r.offset>r.dmax){e.msg="invalid distance too far back",r.mode=zn;break}r.mode=25;case 25:if(0===u)break e;if(d=h-u,r.offset>d){if((d=r.offset-d)>r.whave&&r.sane){e.msg="invalid distance too far back",r.mode=zn;break}d>r.wnext?(d-=r.wnext,p=r.wsize-d):p=r.wnext-d,d>r.length&&(d=r.length),m=r.window}else m=i,p=o-r.offset,d=r.length;d>u&&(d=u),u-=d,r.length-=d;do{i[o++]=m[p++]}while(--d);0===r.length&&(r.mode=21);break;case 26:if(0===u)break e;i[o++]=r.length,u--,r.mode=21;break;case 27:if(r.wrap){for(;c<32;){if(0===s)break e;s--,f|=n[a++]<=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),!(t.windowBits>=0&&t.windowBits<16)||e&&e.windowBits||(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&0==(15&t.windowBits)&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new xn,this.strm.avail_out=0;var r=ei.inflateInit2(this.strm,t.windowBits);if(r!==ai)throw new Error(ln[r]);if(this.header=new ti,ei.inflateGetHeader(this.strm,this.header),t.dictionary&&("string"==typeof t.dictionary?t.dictionary=wn(t.dictionary):"[object ArrayBuffer]"===ri.call(t.dictionary)&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw&&(r=ei.inflateSetDictionary(this.strm,t.dictionary))!==ai))throw new Error(ln[r])}function hi(e,t){var r=new li(t);if(r.push(e),r.err)throw r.msg||ln[r.err];return r.result}li.prototype.push=function(e,t){var r,n,i,a=this.strm,o=this.options.chunkSize,s=this.options.dictionary;if(this.ended)return!1;for(n=t===~~t?t:!0===t?ii:ni,"[object ArrayBuffer]"===ri.call(e)?a.input=new Uint8Array(e):a.input=e,a.next_in=0,a.avail_in=a.input.length;;){for(0===a.avail_out&&(a.output=new Uint8Array(o),a.next_out=0,a.avail_out=o),(r=ei.inflate(a,n))===si&&s&&((r=ei.inflateSetDictionary(a,s))===ai?r=ei.inflate(a,n):r===fi&&(r=si));a.avail_in>0&&r===oi&&a.state.wrap>0&&0!==e[a.next_in];)ei.inflateReset(a),r=ei.inflate(a,n);switch(r){case ui:case fi:case si:case ci:return this.onEnd(r),this.ended=!0,!1}if(i=a.avail_out,a.next_out&&(0===a.avail_out||r===oi))if("string"===this.options.to){var u=kn(a.output,a.next_out),f=a.next_out-u,c=bn(a.output,u);a.next_out=f,a.avail_out=o-f,f&&a.output.set(a.output.subarray(u,u+f),0),this.onData(c)}else this.onData(a.output.length===a.next_out?a.output:a.output.subarray(0,a.next_out));if(r!==ai||0!==i){if(r===oi)return r=ei.inflateEnd(this.strm),this.onEnd(r),this.ended=!0,!0;if(0===a.avail_in)break}}return!0},li.prototype.onData=function(e){this.chunks.push(e)},li.prototype.onEnd=function(e){e===ai&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=mn(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var di={Inflate:li,inflate:hi,inflateRaw:function(e,t){return(t=t||{}).raw=!0,hi(e,t)},ungzip:hi,constants:hn}.inflate;function pi(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=v(e);if(t){var i=v(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return m(this,r)}}var mi=function(e){h(r,e);var t=pi(r);function r(){return b(this,r),t.apply(this,arguments)}return c(r,[{key:"decodeBlock",value:function(e){return di(new Uint8Array(e)).buffer}}]),r}(wr),vi=Object.freeze({__proto__:null,default:mi});function yi(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=v(e);if(t){var i=v(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return m(this,r)}}var gi=function(e){h(r,e);var t=yi(r);function r(){return b(this,r),t.apply(this,arguments)}return c(r,[{key:"decodeBlock",value:function(e){for(var t=new DataView(e),r=[],n=0;n>3],P<<=7&S),v=0;v>3]),128&P?(u&&(u[S]=1),m=m>(a=U.encoding<2?A[_++]:I)?a:m,s[S++]=a):(u&&(u[S]=0),s[S++]=n),P<<=1;S+=T}else if(U.encoding<2)for(y=0;y(a=A[_++])?a:m,s[S++]=a;S+=T}else for(m=m>I?I:m,y=0;y0){var o=new Uint8Array(Math.ceil(n.width*n.height/8)),s=(a=new DataView(e,t,n.mask.numBytes)).getInt16(0,!0),u=2,f=0;do{if(s>0)for(;s--;)o[f++]=a.getUint8(u++);else{var c=a.getUint8(u++);for(s=-s;s--;)o[f++]=c}s=a.getInt16(u,!0),u+=2}while(u0?1:0),p=h+(n.height%h>0?1:0);n.pixels.blocks=new Array(d*p);for(var m=0,v=0;v3)throw"Invalid block encoding ("+b.encoding+")";if(2!==b.encoding){if(0!==k&&2!==k){if(k>>=6,b.offsetType=k,2===k)b.offset=a.getInt8(1),g++;else if(1===k)b.offset=a.getInt16(1,!0),g+=2;else{if(0!==k)throw"Invalid block offset type";b.offset=a.getFloat32(1,!0),g+=4}if(1===b.encoding)if(k=a.getUint8(g),g++,b.bitsPerPixel=63&k,k>>=6,b.numValidPixelsType=k,2===k)b.numValidPixels=a.getUint8(g),g++;else if(1===k)b.numValidPixels=a.getUint16(g,!0),g+=2;else{if(0!==k)throw"Invalid valid pixel count type";b.numValidPixels=a.getUint32(g,!0),g+=4}}var x;if(t+=g,3!==b.encoding)if(0===b.encoding){var A=(n.pixels.numBytes-1)/4;if(A!==Math.floor(A))throw"uncompressed block has invalid length";x=new ArrayBuffer(4*A),new Uint8Array(x).set(new Uint8Array(e,t,4*A));var _=new Float32Array(x);b.rawData=_,t+=4*A}else if(1===b.encoding){var I=Math.ceil(b.numValidPixels*b.bitsPerPixel/8),P=Math.ceil(I/4);x=new ArrayBuffer(4*P),new Uint8Array(x).set(new Uint8Array(e,t,I)),b.stuffedData=new Uint32Array(x),t+=I}}else t++}return n.eofOffset=t,n},o=function(e,t,r,n,i,a,o){var s,u,f,c=(1<=t)u=f>>>h-t&c,h-=t;else{var m=t-h;u=(f&c)<>>(h=32-m)}a[s]=u=r?(f=c>>>m-r&d,m-=r):(f=(c&d)<<(l=r-m)&d,f+=(c=e[p++])>>>(m=32-l)),t[u]=i[f];else for(h=Math.ceil((s-a)/o),u=0;u=r?(f=c>>>m-r&d,m-=r):(f=(c&d)<<(l=r-m)&d,f+=(c=e[p++])>>>(m=32-l)),t[u]=f=t?(h=o>>>l-t&s,l-=t):(h=(o&s)<<(c=t-l)&s,h+=(o=e[u++])>>>(l=32-c)),d[f]=h=r?(f=c>>>m&h,p-=r,m+=r):(f=c>>>m&h,p=32-(l=r-p),f|=((c=e[d++])&(1<=r?(f=c>>>m&h,p-=r,m+=r):(f=c>>>m&h,p=32-(l=r-p),f|=((c=e[d++])&(1<=t?(h=o>>>d&s,l-=t,d+=t):(h=o>>>d&s,l=32-(c=t-l),h|=((o=e[u++])&(1<=r?(a=o>>>c-r&u,c-=r):(a=(o&u)<<(s=r-c)&u,a+=(o=e[f++])>>>(c=32-s)),t[i]=a;return t},a=function(e,t,r,n){var i,a,o,s,u=(1<=r?(a=o>>>l&u,c-=r,l+=r):(a=o>>>l&u,c=32-(s=r-c),a|=((o=e[f++])&(1<=359?359:i;i-=o;do{t+=e[a++]<<8,r+=t+=e[a++]}while(--o);t=(65535&t)+(t>>>16),r=(65535&r)+(r>>>16)}return 1&n&&(r+=t+=e[a]<<8),((r=(65535&r)+(r>>>16))<<16|(t=(65535&t)+(t>>>16)))>>>0},readHeaderInfo:function(e,t){var r=t.ptr,n=new Uint8Array(e,r,6),i={};if(i.fileIdentifierString=String.fromCharCode.apply(null,n),0!==i.fileIdentifierString.lastIndexOf("Lerc2",0))throw"Unexpected file identifier string (expect Lerc2 ): "+i.fileIdentifierString;r+=6;var a,o=new DataView(e,r,8),s=o.getInt32(0,!0);if(i.fileVersion=s,r+=4,s>=3&&(i.checksum=o.getUint32(4,!0),r+=4),o=new DataView(e,r,12),i.height=o.getUint32(0,!0),i.width=o.getUint32(4,!0),r+=8,s>=4?(i.numDims=o.getUint32(8,!0),r+=4):i.numDims=1,o=new DataView(e,r,40),i.numValidPixel=o.getUint32(0,!0),i.microBlockSize=o.getInt32(4,!0),i.blobSize=o.getInt32(8,!0),i.imageType=o.getInt32(12,!0),i.maxZError=o.getFloat64(16,!0),i.zMin=o.getFloat64(24,!0),i.zMax=o.getFloat64(32,!0),r+=40,t.headerInfo=i,t.ptr=r,s>=3&&(a=s>=4?52:48,this.computeChecksumFletcher32(new Uint8Array(e,r-a,i.blobSize-14))!==i.checksum))throw"Checksum failed.";return!0},checkMinMaxRanges:function(e,t){var r=t.headerInfo,n=this.getDataTypeArray(r.imageType),i=r.numDims*this.getDataTypeSize(r.imageType),a=this.readSubArray(e,t.ptr,n,i),o=this.readSubArray(e,t.ptr+i,n,i);t.ptr+=2*i;var s,u=!0;for(s=0;s0){r=new Uint8Array(Math.ceil(o/8));var c=(u=new DataView(e,i,f.numBytes)).getInt16(0,!0),l=2,h=0,d=0;do{if(c>0)for(;c--;)r[h++]=u.getUint8(l++);else for(d=u.getUint8(l++),c=-c;c--;)r[h++]=d;c=u.getInt16(l,!0),l+=2}while(l>3],p<<=7&m):p=r[m>>3],128&p&&(n[m]=1);t.pixels.resultMask=n,f.bitset=r,i+=f.numBytes}return t.ptr=i,t.mask=f,!0},readDataOneSweep:function(e,t,r,n){var i,a=t.ptr,s=t.headerInfo,u=s.numDims,f=s.width*s.height,c=s.imageType,l=s.numValidPixel*o.getDataTypeSize(c)*u,h=t.pixels.resultMask;if(r===Uint8Array)i=new Uint8Array(e,a,l);else{var d=new ArrayBuffer(l);new Uint8Array(d).set(new Uint8Array(e,a,l)),i=new r(d)}if(i.length===f*u)t.pixels.resultPixels=n?o.swapDimensionOrder(i,f,u,r,!0):i;else{t.pixels.resultPixels=new r(f*u);var p=0,m=0,v=0,y=0;if(u>1){if(n){for(m=0;m=u)return!1;var f=new Uint32Array(u-a);o.decodeBits(e,t,f);var c,l,h,d,p=[];for(c=a;c0&&(p[l].second=g<>>32-d,32-b>=d?32===(b+=d)&&(b=0,g=w[++k]):(b+=d-32,g=w[++k],p[l].second|=g>>>32-b));var x=0,A=0,_=new s;for(c=0;c=r?r:x;var I,P,S,T,U,O=[];for(c=a;c0)if(I=[d,l],d<=A)for(P=p[l].second<=0;T--)P>>>T&1?(U.right||(U.right=new s),U=U.right):(U.left||(U.left=new s),U=U.left),0!==T||U.val||(U.val=I[1]);return{decodeLut:O,numBitsLUTQick:A,numBitsLUT:x,tree:_,stuffedData:w,srcPtr:k,bitPos:b}},readHuffman:function(e,t,r,n){var i,a,s,u,f,c,l,h,d,p=t.headerInfo.numDims,m=t.headerInfo.height,v=t.headerInfo.width,y=v*m,g=this.readHuffmanTree(e,t),w=g.decodeLut,b=g.tree,k=g.stuffedData,x=g.srcPtr,A=g.bitPos,_=g.numBitsLUTQick,I=g.numBitsLUT,P=0===t.headerInfo.imageType?128:0,S=t.pixels.resultMask,T=0;A>0&&(x++,A=0);var U,O=k[x],D=1===t.encodeMode,E=new r(y*p),R=E;if(p<2||D){for(U=0;U1&&(R=new r(E.buffer,y*U,y),T=0),t.headerInfo.numValidPixel===v*m)for(h=0,c=0;c>>32-_,32-A<_&&(f=u|=k[x+1]>>>64-A-_),w[f])a=w[f][1],A+=w[f][0];else for(f=u=O<>>32-I,32-A>>64-A-I),i=b,d=0;d>>I-d-1&1?i.right:i.left).left&&!i.right){a=i.val,A=A+d+1;break}A>=32&&(A-=32,O=k[++x]),s=a-P,D?(s+=l>0?T:c>0?R[h-v]:T,s&=255,R[h]=s,T=s):R[h]=s}else for(h=0,c=0;c>>32-_,32-A<_&&(f=u|=k[x+1]>>>64-A-_),w[f])a=w[f][1],A+=w[f][0];else for(f=u=O<>>32-I,32-A>>64-A-I),i=b,d=0;d>>I-d-1&1?i.right:i.left).left&&!i.right){a=i.val,A=A+d+1;break}A>=32&&(A-=32,O=k[++x]),s=a-P,D?(l>0&&S[h-1]?s+=T:c>0&&S[h-v]?s+=R[h-v]:s+=T,s&=255,R[h]=s,T=s):R[h]=s}}else for(h=0,c=0;c>>32-_,32-A<_&&(f=u|=k[x+1]>>>64-A-_),w[f])a=w[f][1],A+=w[f][0];else for(f=u=O<>>32-I,32-A>>64-A-I),i=b,d=0;d>>I-d-1&1?i.right:i.left).left&&!i.right){a=i.val,A=A+d+1;break}A>=32&&(A-=32,O=k[++x]),s=a-P,R[h]=s}t.ptr=t.ptr+4*(x+1)+(A>0?4:0),t.pixels.resultPixels=E,p>1&&!n&&(t.pixels.resultPixels=o.swapDimensionOrder(E,y,p,r))},decodeBits:function(o,s,u,f,c){var l=s.headerInfo,h=l.fileVersion,d=0,p=o.byteLength-s.ptr>=5?5:o.byteLength-s.ptr,m=new DataView(o,s.ptr,p),v=m.getUint8(0);d++;var y=v>>6,g=0===y?4:3-y,w=(32&v)>0,b=31&v,k=0;if(1===g)k=m.getUint8(d),d++;else if(2===g)k=m.getUint16(d,!0),d+=2;else{if(4!==g)throw"Invalid valid pixel count type";k=m.getUint32(d,!0),d+=4}var x,A,_,I,P,S,T,U,O,D=2*l.maxZError,E=l.numDims>1?l.maxValues[c]:l.zMax;if(w){for(s.counter.lut++,U=m.getUint8(d),d++,I=Math.ceil((U-1)*b/8),P=Math.ceil(I/4),A=new ArrayBuffer(4*P),_=new Uint8Array(A),s.ptr+=d,_.set(new Uint8Array(o,s.ptr,I)),T=new Uint32Array(A),s.ptr+=I,O=0;U-1>>>O;)O++;I=Math.ceil(k*O/8),P=Math.ceil(I/4),A=new ArrayBuffer(4*P),(_=new Uint8Array(A)).set(new Uint8Array(o,s.ptr,I)),x=new Uint32Array(A),s.ptr+=I,S=h>=3?n(T,b,U-1,f,D,E):t(T,b,U-1,f,D,E),h>=3?r(x,u,O,k,S):e(x,u,O,k,S)}else s.counter.bitstuffer++,O=b,s.ptr+=d,O>0&&(I=Math.ceil(k*O/8),P=Math.ceil(I/4),A=new ArrayBuffer(4*P),(_=new Uint8Array(A)).set(new Uint8Array(o,s.ptr,I)),x=new Uint32Array(A),s.ptr+=I,h>=3?null==f?a(x,u,O,k):r(x,u,O,k,!1,f,D,E):null==f?i(x,u,O,k):e(x,u,O,k,!1,f,D,E))},readTiles:function(e,t,r,n){var i=t.headerInfo,a=i.width,s=i.height,u=a*s,f=i.microBlockSize,c=i.imageType,l=o.getDataTypeSize(c),h=Math.ceil(a/f),d=Math.ceil(s/f);t.pixels.numBlocksY=d,t.pixels.numBlocksX=h,t.pixels.ptr=0;var p,m,v,y,g,w,b,k,x,A,_=0,I=0,P=0,S=0,T=0,U=0,O=0,D=0,E=0,R=0,M=0,B=0,C=0,L=0,F=0,V=new r(f*f),G=s%f||f,j=a%f||f,z=i.numDims,N=t.pixels.resultMask,K=t.pixels.resultPixels,Z=i.fileVersion>=5?14:15,H=i.zMax;for(P=0;P1?(A=K,R=P*a*f+S*f,K=new r(t.pixels.resultPixels.buffer,u*k*l,u),H=i.maxValues[k]):A=null,O=e.byteLength-t.ptr,m={},F=0,D=(p=new DataView(e,t.ptr,Math.min(10,O))).getUint8(0),F++,x=i.fileVersion>=5?4&D:0,E=D>>6&255,(D>>2&Z)!==(S*f>>3&Z))throw"integrity issue";if(x&&0===k)throw"integrity issue";if((g=3&D)>3)throw t.ptr+=F,"Invalid block encoding ("+g+")";if(2!==g)if(0===g){if(x)throw"integrity issue";if(t.counter.uncompressed++,t.ptr+=F,B=(B=T*U*l)<(C=e.byteLength-t.ptr)?B:C,v=new ArrayBuffer(B%l==0?B:B+l-B%l),new Uint8Array(v).set(new Uint8Array(e,t.ptr,B)),y=new r(v),L=0,N)for(_=0;_1&&!n&&(t.pixels.resultPixels=o.swapDimensionOrder(t.pixels.resultPixels,u,z,r))},formatFileInfo:function(e){return{fileIdentifierString:e.headerInfo.fileIdentifierString,fileVersion:e.headerInfo.fileVersion,imageType:e.headerInfo.imageType,height:e.headerInfo.height,width:e.headerInfo.width,numValidPixel:e.headerInfo.numValidPixel,microBlockSize:e.headerInfo.microBlockSize,blobSize:e.headerInfo.blobSize,maxZError:e.headerInfo.maxZError,pixelType:o.getPixelType(e.headerInfo.imageType),eofOffset:e.eofOffset,mask:e.mask?{numBytes:e.mask.numBytes}:null,pixels:{numBlocksX:e.pixels.numBlocksX,numBlocksY:e.pixels.numBlocksY,maxValue:e.headerInfo.zMax,minValue:e.headerInfo.zMin,noDataValue:e.noDataValue}}},constructConstantSurface:function(e,t){var r=e.headerInfo.zMax,n=e.headerInfo.zMin,i=e.headerInfo.maxValues,a=e.headerInfo.numDims,o=e.headerInfo.height*e.headerInfo.width,s=0,u=0,f=0,c=e.pixels.resultMask,l=e.pixels.resultPixels;if(c)if(a>1){if(t)for(s=0;s1&&n!==r)if(t)for(s=0;s=-128&&t<=127;break;case 1:r=t>=0&&t<=255;break;case 2:r=t>=-32768&&t<=32767;break;case 3:r=t>=0&&t<=65536;break;case 4:r=t>=-2147483648&&t<=2147483647;break;case 5:r=t>=0&&t<=4294967296;break;case 6:r=t>=-34027999387901484e22&&t<=34027999387901484e22;break;case 7:r=t>=-17976931348623157e292&&t<=17976931348623157e292;break;default:r=!1}return r},getDataTypeSize:function(e){var t=0;switch(e){case 0:case 1:t=1;break;case 2:case 3:t=2;break;case 4:case 5:case 6:t=4;break;case 7:t=8;break;default:t=e}return t},getDataTypeUsed:function(e,t){var r=e;switch(e){case 2:case 4:r=e-t;break;case 3:case 5:r=e-2*t;break;case 6:r=0===t?e:1===t?2:1;break;case 7:r=0===t?e:e-2*t+1;break;default:r=e}return r},getOnePixel:function(e,t,r,n){var i=0;switch(r){case 0:i=n.getInt8(t);break;case 1:i=n.getUint8(t);break;case 2:i=n.getInt16(t,!0);break;case 3:i=n.getUint16(t,!0);break;case 4:i=n.getInt32(t,!0);break;case 5:i=n.getUInt32(t,!0);break;case 6:i=n.getFloat32(t,!0);break;case 7:i=n.getFloat64(t,!0);break;default:throw"the decoder does not understand this pixel type"}return i},swapDimensionOrder:function(e,t,r,n,i){var a=0,o=0,s=0,u=0,f=e;if(r>1)if(f=new n(t*r),i)for(a=0;a5)throw"unsupported lerc version 2."+s;o.readMask(e,i),a.numValidPixel===a.width*a.height||i.pixels.resultMask||(i.pixels.resultMask=t.maskData);var f=a.width*a.height;i.pixels.resultPixels=new u(f*a.numDims),i.counter={onesweep:0,uncompressed:0,lut:0,bitstuffer:0,constant:0,constantoffset:0};var c,l=!t.returnPixelInterleavedDims;if(0!==a.numValidPixel)if(a.zMax===a.zMin)o.constructConstantSurface(i,l);else if(s>=4&&o.checkMinMaxRanges(e,i))o.constructConstantSurface(i,l);else{var h=new DataView(e,i.ptr,2),d=h.getUint8(0);if(i.ptr++,d)o.readDataOneSweep(e,i,u,l);else if(s>1&&a.imageType<=1&&Math.abs(a.maxZError-.5)<1e-5){var p=h.getUint8(1);if(i.ptr++,i.encodeMode=p,p>2||s<4&&p>1)throw"Invalid Huffman flag "+p;p?o.readHuffman(e,i,u,l):o.readTiles(e,i,u,l)}else o.readTiles(e,i,u,l)}i.eofOffset=i.ptr,t.inputOffset?(c=i.headerInfo.blobSize+t.inputOffset-i.ptr,Math.abs(c)>=1&&(i.eofOffset=t.inputOffset+i.headerInfo.blobSize)):(c=i.headerInfo.blobSize-i.ptr,Math.abs(c)>=1&&(i.eofOffset=i.headerInfo.blobSize));var m={width:a.width,height:a.height,pixelData:i.pixels.resultPixels,minValue:a.zMin,maxValue:a.zMax,validPixelCount:a.numValidPixel,dimCount:a.numDims,dimStats:{minValues:a.minValues,maxValues:a.maxValues},maskData:i.pixels.resultMask};if(i.pixels.resultMask&&o.isValidPixelValue(a.imageType,r)){var v=i.pixels.resultMask;for(n=0;n1&&(h&&g.push(h),k.fileInfo.mask&&k.fileInfo.mask.numBytes>0&&b++),v++,w.pixels.push(k.pixelData),w.statistics.push({minValue:k.minValue,maxValue:k.maxValue,noDataValue:k.noDataValue,dimStats:k.dimStats})}if(n>1&&b>1){for(m=w.width*w.height,w.bandMasks=g,(h=new Uint8Array(m)).set(g[0]),d=1;d=0;--a){var o=this.tryEntries[a],s=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var f=i.call(o,"catchLoc"),l=i.call(o,"finallyLoc");if(f&&l){if(this.prev=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&i.call(n,"finallyLoc")&&this.prev=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),S(r),v}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;S(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:D(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),v}},e}(e.exports);try{regeneratorRuntime=t}catch(e){"object"===("undefined"==typeof globalThis?"undefined":r(globalThis))?globalThis.regeneratorRuntime=t:Function("r","regeneratorRuntime = r")(t)}}(n);var i=n.exports,a=new Map;function o(e,t){Array.isArray(e)||(e=[e]),e.forEach((function(e){return a.set(e,t)}))}function s(e){return f.apply(this,arguments)}function f(){return(f=t(i.mark((function e(t){var r,n;return i.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=a.get(t.Compression)){e.next=3;break}throw new Error("Unknown compression method identifier: ".concat(t.Compression));case 3:return e.next=5,r();case 5:return n=e.sent,e.abrupt("return",new n(t));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}o([void 0,1],(function(){return Promise.resolve().then((function(){return _})).then((function(e){return e.default}))})),o(5,(function(){return Promise.resolve().then((function(){return S})).then((function(e){return e.default}))})),o(6,(function(){throw new Error("old style JPEG compression is not supported.")})),o(7,(function(){return Promise.resolve().then((function(){return L})).then((function(e){return e.default}))})),o([8,32946],(function(){return Promise.resolve().then((function(){return Ne})).then((function(e){return e.default}))})),o(32773,(function(){return Promise.resolve().then((function(){return Ye})).then((function(e){return e.default}))})),o(34887,(function(){return Promise.resolve().then((function(){return ut})).then((function(e){return e.default}))})),o(50001,(function(){return Promise.resolve().then((function(){return dt})).then((function(e){return e.default}))}));var l=globalThis;function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function c(e,t){for(var r=0;r0;i--)e[n+t]+=e[n],n++;r-=t}while(r>0)}function w(e,t,r){for(var n=0,i=e.length,a=i/r;i>t;){for(var o=t;o>0;--o)e[n+t]+=e[n],++n;i-=t}for(var s=e.slice(),f=0;f=e.byteLength);++l){var u=void 0;if(2===t){switch(i[0]){case 8:u=new Uint8Array(e,l*f*r*s,f*r*s);break;case 16:u=new Uint16Array(e,l*f*r*s,f*r*s/2);break;case 32:u=new Uint32Array(e,l*f*r*s,f*r*s/4);break;default:throw new Error("Predictor 2 not allowed with ".concat(i[0]," bits per sample."))}y(u,f)}else 3===t&&w(u=new Uint8Array(e,l*f*r*s,f*r*s),f,s)}return e}l.addEventListener("message",function(){var e=t(i.mark((function e(t){var r,n,a,o,f,u;return i.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.data,n=r.id,a=r.fileDirectory,o=r.buffer,e.next=3,s(a);case 3:return f=e.sent,e.next=6,f.decode(a,o);case 6:u=e.sent,l.postMessage({decoded:u,id:n},[u]);case 8:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}());var b=function(){function e(){u(this,e)}var r;return h(e,[{key:"decode",value:(r=t(i.mark((function e(t,r){var n,a,o,s,f;return i.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.decodeBlock(r);case 2:if(n=e.sent,1===(a=t.Predictor||1)){e.next=9;break}return o=!t.StripOffsets,s=o?t.TileWidth:t.ImageWidth,f=o?t.TileLength:t.RowsPerStrip||t.ImageLength,e.abrupt("return",g(n,a,s,f,t.BitsPerSample,t.PlanarConfiguration));case 9:return e.abrupt("return",n);case 10:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})}]),e}();function k(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=v(e);if(t){var i=v(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return m(this,r)}}var x=function(e){p(r,b);var t=k(r);function r(){return u(this,r),t.apply(this,arguments)}return h(r,[{key:"decodeBlock",value:function(e){return e}}]),r}(),_=Object.freeze({__proto__:null,default:x});function A(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=v(e);if(t){var i=v(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return m(this,r)}}function P(e,t){for(var r=t.length-1;r>=0;r--)e.push(t[r]);return e}function I(e){for(var t=new Uint16Array(4093),r=new Uint8Array(4093),n=0;n<=257;n++)t[n]=4096,r[n]=n;var i=258,a=9,o=0;function s(){i=258,a=9}function f(e){var t=function(e,t,r){var n=t%8,i=Math.floor(t/8),a=8-n,o=t+r-8*(i+1),s=8*(i+2)-(t+r),f=8*(i+2)-t;if(s=Math.max(0,s),i>=e.length)return console.warn("ran off the end of the buffer before finding EOI_CODE (end on input code)"),257;var l=e[i]&Math.pow(2,8-n)-1,u=l<<=r-a;if(i+1>>s;u+=c<<=Math.max(0,r-f)}if(o>8&&i+2>>h}return u}(e,o,a);return o+=a,t}function l(e,n){return r[i]=n,t[i]=e,++i-1}function u(e){for(var n=[],i=e;4096!==i;i=t[i])n.push(r[i]);return n}var c=[];s();for(var h,d=new Uint8Array(e),p=f(d);257!==p;){if(256===p){for(s(),p=f(d);256===p;)p=f(d);if(257===p)break;if(p>256)throw new Error("corrupted code at scanline ".concat(p));P(c,u(p)),h=p}else if(p=Math.pow(2,a)&&(12===a?h=void 0:a++),p=f(d)}return new Uint8Array(c)}var U=function(e){p(r,b);var t=A(r);function r(){return u(this,r),t.apply(this,arguments)}return h(r,[{key:"decodeBlock",value:function(e){return I(e).buffer}}]),r}(),S=Object.freeze({__proto__:null,default:U});function T(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=v(e);if(t){var i=v(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return m(this,r)}}var D=new Int32Array([0,1,8,16,9,2,3,10,17,24,32,25,18,11,4,5,12,19,26,33,40,48,41,34,27,20,13,6,7,14,21,28,35,42,49,56,57,50,43,36,29,22,15,23,30,37,44,51,58,59,52,45,38,31,39,46,53,60,61,54,47,55,62,63]);function E(e,t){for(var r=0,n=[],i=16;i>0&&!e[i-1];)--i;n.push({children:[],index:0});for(var a,o=n[0],s=0;s0;)o=n.pop();for(o.index++,n.push(o);n.length<=s;)n.push(a={children:[],index:0}),o.children[o.index]=a.children,o=a;r++}s+10)return m--,p>>m&1;if(255===(p=e[d++])){var t=e[d++];if(t)throw new Error("unexpected marker: ".concat((p<<8|t).toString(16)))}return m=7,p>>>7}function y(e){for(var t,n=e;null!==(t=v());){if("number"==typeof(n=n[t]))return n;if("object"!==r(n))throw new Error("invalid huffman sequence")}return null}function w(e){for(var t=e,r=0;t>0;){var n=v();if(null===n)return;r=r<<1|n,--t}return r}function g(e){var t=w(e);return t>=1<0)b--;else for(var r=o,n=s;r<=n;){var i=y(e.huffmanTableAC),a=15&i,f=i>>4;if(0===a){if(f<15){b=w(f)+(1<>4,0===c)i<15?(b=w(i)+(1<>4;if(0===o){if(s<15)break;i+=16}else t[D[i+=s]]=g(o),i++}};var O,M,C=0;M=1===B?i[0].blocksPerLine*i[0].blocksPerColumn:u*n.mcusPerColumn;for(var L=a||M;C=65488&&O<=65495))break;d+=2}return d-h}function O(e,t){var r=[],n=t.blocksPerLine,i=t.blocksPerColumn,a=n<<3,o=new Int32Array(64),s=new Uint8Array(64);function f(e,r,n){var i,a,o,s,f,l,u,c,h,d,p=t.quantizationTable,m=n;for(d=0;d<64;d++)m[d]=e[d]*p[d];for(d=0;d<8;++d){var v=8*d;0!==m[1+v]||0!==m[2+v]||0!==m[3+v]||0!==m[4+v]||0!==m[5+v]||0!==m[6+v]||0!==m[7+v]?(i=5793*m[0+v]+128>>8,a=5793*m[4+v]+128>>8,o=m[2+v],s=m[6+v],f=2896*(m[1+v]-m[7+v])+128>>8,c=2896*(m[1+v]+m[7+v])+128>>8,l=m[3+v]<<4,h=i-a+1>>1,i=i+a+1>>1,a=h,h=3784*o+1567*s+128>>8,o=1567*o-3784*s+128>>8,s=h,h=f-(u=m[5+v]<<4)+1>>1,f=f+u+1>>1,u=h,h=c+l+1>>1,l=c-l+1>>1,c=h,h=i-s+1>>1,i=i+s+1>>1,s=h,h=a-o+1>>1,a=a+o+1>>1,o=h,h=2276*f+3406*c+2048>>12,f=3406*f-2276*c+2048>>12,c=h,h=799*l+4017*u+2048>>12,l=4017*l-799*u+2048>>12,u=h,m[0+v]=i+c,m[7+v]=i-c,m[1+v]=a+u,m[6+v]=a-u,m[2+v]=o+l,m[5+v]=o-l,m[3+v]=s+f,m[4+v]=s-f):(h=5793*m[0+v]+512>>10,m[0+v]=h,m[1+v]=h,m[2+v]=h,m[3+v]=h,m[4+v]=h,m[5+v]=h,m[6+v]=h,m[7+v]=h)}for(d=0;d<8;++d){var y=d;0!==m[8+y]||0!==m[16+y]||0!==m[24+y]||0!==m[32+y]||0!==m[40+y]||0!==m[48+y]||0!==m[56+y]?(i=5793*m[0+y]+2048>>12,a=5793*m[32+y]+2048>>12,o=m[16+y],s=m[48+y],f=2896*(m[8+y]-m[56+y])+2048>>12,c=2896*(m[8+y]+m[56+y])+2048>>12,l=m[24+y],h=i-a+1>>1,i=i+a+1>>1,a=h,h=3784*o+1567*s+2048>>12,o=1567*o-3784*s+2048>>12,s=h,h=f-(u=m[40+y])+1>>1,f=f+u+1>>1,u=h,h=c+l+1>>1,l=c-l+1>>1,c=h,h=i-s+1>>1,i=i+s+1>>1,s=h,h=a-o+1>>1,a=a+o+1>>1,o=h,h=2276*f+3406*c+2048>>12,f=3406*f-2276*c+2048>>12,c=h,h=799*l+4017*u+2048>>12,l=4017*l-799*u+2048>>12,u=h,m[0+y]=i+c,m[56+y]=i-c,m[8+y]=a+u,m[48+y]=a-u,m[16+y]=o+l,m[40+y]=o-l,m[24+y]=s+f,m[32+y]=s-f):(h=5793*n[d+0]+8192>>14,m[0+y]=h,m[8+y]=h,m[16+y]=h,m[24+y]=h,m[32+y]=h,m[40+y]=h,m[48+y]=h,m[56+y]=h)}for(d=0;d<64;++d){var w=128+(m[d]+8>>4);r[d]=w<0?0:w>255?255:w}}for(var l=0;l>4==0)for(var c=0;c<64;c++){u[D[c]]=e[t++]}else{if(l>>4!=1)throw new Error("DQT: invalid table spec");for(var h=0;h<64;h++){u[D[h]]=r()}}this.quantizationTables[15&l]=u}break;case 65472:case 65473:case 65474:r();for(var d={extended:65473===o,progressive:65474===o,precision:e[t++],scanLines:r(),samplesPerLine:r(),components:{},componentsOrder:[]},p=e[t++],m=void 0,v=0;v>4,w=15&e[t+1],g=e[t+2];d.componentsOrder.push(m),d.components[m]={h:y,v:w,quantizationIdx:g},t+=3}n(d),this.frames.push(d);break;case 65476:for(var b=r(),k=2;k>4==0?this.huffmanTablesDC[15&x]=E(_,I):this.huffmanTablesAC[15&x]=E(_,I)}break;case 65501:r(),this.resetInterval=r();break;case 65498:r();for(var S=e[t++],T=[],O=this.frames[0],M=0;M>4],C.huffmanTableAC=this.huffmanTablesAC[15&L],T.push(C)}var R=e[t++],V=e[t++],G=e[t++],F=B(e,t,O,T,this.resetInterval,R,V,G>>4,15&G);t+=F;break;case 65535:255!==e[t]&&t--;break;default:if(255===e[t-3]&&e[t-2]>=192&&e[t-2]<=254){t-=3;break}throw new Error("unknown JPEG marker ".concat(o.toString(16)))}o=r()}}},{key:"getResult",value:function(){var e=this.frames;if(0===this.frames.length)throw new Error("no frames were decoded");this.frames.length>1&&console.warn("more than one frame is not supported");for(var t=0;t=0;)e[t]=0}R(new Array(576)),R(new Array(60)),R(new Array(512)),R(new Array(256)),R(new Array(29)),R(new Array(30));var V=function(e,t,r,n){for(var i=65535&e|0,a=e>>>16&65535|0,o=0;0!==r;){r-=o=r>2e3?2e3:r;do{a=a+(i=i+t[n++]|0)|0}while(--o);i%=65521,a%=65521}return i|a<<16|0},G=new Uint32Array(function(){for(var e,t=[],r=0;r<256;r++){e=r;for(var n=0;n<8;n++)e=1&e?3988292384^e>>>1:e>>>1;t[r]=e}return t}()),F=function(e,t,r,n){var i=G,a=n+r;e^=-1;for(var o=n;o>>8^i[255&(e^t[o])];return-1^e},z={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},j={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8},N=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},Z=function(e){for(var t=Array.prototype.slice.call(arguments,1);t.length;){var n=t.shift();if(n){if("object"!==r(n))throw new TypeError(n+"must be non-object");for(var i in n)N(n,i)&&(e[i]=n[i])}}return e},K=function(e){for(var t=0,r=0,n=e.length;r=252?6:X>=248?5:X>=240?4:X>=224?3:X>=192?2:1;Y[254]=Y[254]=1;var W=function(e){if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(e);var t,r,n,i,a,o=e.length,s=0;for(i=0;i>>6,t[a++]=128|63&r):r<65536?(t[a++]=224|r>>>12,t[a++]=128|r>>>6&63,t[a++]=128|63&r):(t[a++]=240|r>>>18,t[a++]=128|r>>>12&63,t[a++]=128|r>>>6&63,t[a++]=128|63&r);return t},q=function(e,t){var r,n,i=t||e.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(e.subarray(0,t));var a=new Array(2*i);for(n=0,r=0;r4)a[n++]=65533,r+=s-1;else{for(o&=2===s?31:3===s?15:7;s>1&&r1?a[n++]=65533:o<65536?a[n++]=o:(o-=65536,a[n++]=55296|o>>10&1023,a[n++]=56320|1023&o)}}}return function(e,t){if(t<65534&&e.subarray&&H)return String.fromCharCode.apply(null,e.length===t?e:e.subarray(0,t));for(var r="",n=0;ne.length&&(t=e.length);for(var r=t-1;r>=0&&128==(192&e[r]);)r--;return r<0||0===r?t:r+Y[e[r]]>t?r:t};var Q=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0},$=function(e,t){var r,n,i,a,o,s,f,l,u,c,h,d,p,m,v,y,w,g,b,k,x,_,A,P,I=e.state;r=e.next_in,A=e.input,n=r+(e.avail_in-5),i=e.next_out,P=e.output,a=i-(t-e.avail_out),o=i+(e.avail_out-257),s=I.dmax,f=I.wsize,l=I.whave,u=I.wnext,c=I.window,h=I.hold,d=I.bits,p=I.lencode,m=I.distcode,v=(1<>>=g=w>>>24,d-=g,0===(g=w>>>16&255))P[i++]=65535&w;else{if(!(16&g)){if(0==(64&g)){w=p[(65535&w)+(h&(1<>>=g,d-=g),d<15&&(h+=A[r++]<>>=g=w>>>24,d-=g,!(16&(g=w>>>16&255))){if(0==(64&g)){w=m[(65535&w)+(h&(1<s){e.msg="invalid distance too far back",I.mode=30;break e}if(h>>>=g,d-=g,k>(g=i-a)){if((g=k-g)>l&&I.sane){e.msg="invalid distance too far back",I.mode=30;break e}if(x=0,_=c,0===u){if(x+=f-g,g2;)P[i++]=_[x++],P[i++]=_[x++],P[i++]=_[x++],b-=3;b&&(P[i++]=_[x++],b>1&&(P[i++]=_[x++]))}else{x=i-k;do{P[i++]=P[x++],P[i++]=P[x++],P[i++]=P[x++],b-=3}while(b>2);b&&(P[i++]=P[x++],b>1&&(P[i++]=P[x++]))}break}}break}}while(r>3,h&=(1<<(d-=b<<3))-1,e.next_in=r,e.next_out=i,e.avail_in=r=1&&0===D[k];k--);if(x>k&&(x=k),0===k)return i[a++]=20971520,i[a++]=20971520,s.bits=1,0;for(b=1;b0&&(0===e||1!==k))return-1;for(E[1]=0,w=1;w<15;w++)E[w+1]=E[w]+D[w];for(g=0;g852||2===e&&I>592)return 1;for(;;){p=w-A,o[g]d?(m=B[O+o[g]],v=S[T+o[g]]):(m=96,v=0),f=1<>A)+(l-=f)]=p<<24|m<<16|v|0}while(0!==l);for(f=1<>=1;if(0!==f?(U&=f-1,U+=f):U=0,g++,0==--D[w]){if(w===k)break;w=t[r+o[g]]}if(w>x&&(U&c)!==u){for(0===A&&(A=x),h+=b,P=1<<(_=w-A);_+A852||2===e&&I>592)return 1;i[u=U&c]=x<<24|_<<16|h-a|0}}return 0!==U&&(i[h+U]=w-A<<24|64<<16|0),s.bits=x,0},ae=j.Z_FINISH,oe=j.Z_BLOCK,se=j.Z_TREES,fe=j.Z_OK,le=j.Z_STREAM_END,ue=j.Z_NEED_DICT,ce=j.Z_STREAM_ERROR,he=j.Z_DATA_ERROR,de=j.Z_MEM_ERROR,pe=j.Z_BUF_ERROR,me=j.Z_DEFLATED,ve=function(e){return(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24)};function ye(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}var we,ge,be=function(e){if(!e||!e.state)return ce;var t=e.state;return e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=1,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new Int32Array(852),t.distcode=t.distdyn=new Int32Array(592),t.sane=1,t.back=-1,fe},ke=function(e){if(!e||!e.state)return ce;var t=e.state;return t.wsize=0,t.whave=0,t.wnext=0,be(e)},xe=function(e,t){var r;if(!e||!e.state)return ce;var n=e.state;return t<0?(r=0,t=-t):(r=1+(t>>4),t<48&&(t&=15)),t&&(t<8||t>15)?ce:(null!==n.window&&n.wbits!==t&&(n.window=null),n.wrap=r,n.wbits=t,ke(e))},_e=function(e,t){if(!e)return ce;var r=new ye;e.state=r,r.window=null;var n=xe(e,t);return n!==fe&&(e.state=null),n},Ae=!0,Pe=function(e){if(Ae){we=new Int32Array(512),ge=new Int32Array(32);for(var t=0;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(ie(1,e.lens,0,288,we,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;ie(2,e.lens,0,32,ge,0,e.work,{bits:5}),Ae=!1}e.lencode=we,e.lenbits=9,e.distcode=ge,e.distbits=5},Ie=function(e,t,r,n){var i,a=e.state;return null===a.window&&(a.wsize=1<=a.wsize?(a.window.set(t.subarray(r-a.wsize,r),0),a.wnext=0,a.whave=a.wsize):((i=a.wsize-a.wnext)>n&&(i=n),a.window.set(t.subarray(r-n,r-n+i),a.wnext),(n-=i)?(a.window.set(t.subarray(r-n,r),0),a.wnext=n,a.whave=a.wsize):(a.wnext+=i,a.wnext===a.wsize&&(a.wnext=0),a.whave>>8&255,r.check=F(r.check,U,2,0),l=0,u=0,r.mode=2;break}if(r.flags=0,r.head&&(r.head.done=!1),!(1&r.wrap)||(((255&l)<<8)+(l>>8))%31){e.msg="incorrect header check",r.mode=30;break}if((15&l)!==me){e.msg="unknown compression method",r.mode=30;break}if(u-=4,x=8+(15&(l>>>=4)),0===r.wbits)r.wbits=x;else if(x>r.wbits){e.msg="invalid window size",r.mode=30;break}r.dmax=1<>8&1),512&r.flags&&(U[0]=255&l,U[1]=l>>>8&255,r.check=F(r.check,U,2,0)),l=0,u=0,r.mode=3;case 3:for(;u<32;){if(0===s)break e;s--,l+=n[a++]<>>8&255,U[2]=l>>>16&255,U[3]=l>>>24&255,r.check=F(r.check,U,4,0)),l=0,u=0,r.mode=4;case 4:for(;u<16;){if(0===s)break e;s--,l+=n[a++]<>8),512&r.flags&&(U[0]=255&l,U[1]=l>>>8&255,r.check=F(r.check,U,2,0)),l=0,u=0,r.mode=5;case 5:if(1024&r.flags){for(;u<16;){if(0===s)break e;s--,l+=n[a++]<>>8&255,r.check=F(r.check,U,2,0)),l=0,u=0}else r.head&&(r.head.extra=null);r.mode=6;case 6:if(1024&r.flags&&((d=r.length)>s&&(d=s),d&&(r.head&&(x=r.head.extra_len-r.length,r.head.extra||(r.head.extra=new Uint8Array(r.head.extra_len)),r.head.extra.set(n.subarray(a,a+d),x)),512&r.flags&&(r.check=F(r.check,n,d,a)),s-=d,a+=d,r.length-=d),r.length))break e;r.length=0,r.mode=7;case 7:if(2048&r.flags){if(0===s)break e;d=0;do{x=n[a+d++],r.head&&x&&r.length<65536&&(r.head.name+=String.fromCharCode(x))}while(x&&d>9&1,r.head.done=!0),e.adler=r.check=0,r.mode=12;break;case 10:for(;u<32;){if(0===s)break e;s--,l+=n[a++]<>>=7&u,u-=7&u,r.mode=27;break}for(;u<3;){if(0===s)break e;s--,l+=n[a++]<>>=1)){case 0:r.mode=14;break;case 1:if(Pe(r),r.mode=20,t===se){l>>>=2,u-=2;break e}break;case 2:r.mode=17;break;case 3:e.msg="invalid block type",r.mode=30}l>>>=2,u-=2;break;case 14:for(l>>>=7&u,u-=7&u;u<32;){if(0===s)break e;s--,l+=n[a++]<>>16^65535)){e.msg="invalid stored block lengths",r.mode=30;break}if(r.length=65535&l,l=0,u=0,r.mode=15,t===se)break e;case 15:r.mode=16;case 16:if(d=r.length){if(d>s&&(d=s),d>f&&(d=f),0===d)break e;i.set(n.subarray(a,a+d),o),s-=d,a+=d,f-=d,o+=d,r.length-=d;break}r.mode=12;break;case 17:for(;u<14;){if(0===s)break e;s--,l+=n[a++]<>>=5,u-=5,r.ndist=1+(31&l),l>>>=5,u-=5,r.ncode=4+(15&l),l>>>=4,u-=4,r.nlen>286||r.ndist>30){e.msg="too many length or distance symbols",r.mode=30;break}r.have=0,r.mode=18;case 18:for(;r.have>>=3,u-=3}for(;r.have<19;)r.lens[S[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,A={bits:r.lenbits},_=ie(0,r.lens,0,19,r.lencode,0,r.work,A),r.lenbits=A.bits,_){e.msg="invalid code lengths set",r.mode=30;break}r.have=0,r.mode=19;case 19:for(;r.have>>16&255,w=65535&I,!((v=I>>>24)<=u);){if(0===s)break e;s--,l+=n[a++]<>>=v,u-=v,r.lens[r.have++]=w;else{if(16===w){for(P=v+2;u>>=v,u-=v,0===r.have){e.msg="invalid bit length repeat",r.mode=30;break}x=r.lens[r.have-1],d=3+(3&l),l>>>=2,u-=2}else if(17===w){for(P=v+3;u>>=v)),l>>>=3,u-=3}else{for(P=v+7;u>>=v)),l>>>=7,u-=7}if(r.have+d>r.nlen+r.ndist){e.msg="invalid bit length repeat",r.mode=30;break}for(;d--;)r.lens[r.have++]=x}}if(30===r.mode)break;if(0===r.lens[256]){e.msg="invalid code -- missing end-of-block",r.mode=30;break}if(r.lenbits=9,A={bits:r.lenbits},_=ie(1,r.lens,0,r.nlen,r.lencode,0,r.work,A),r.lenbits=A.bits,_){e.msg="invalid literal/lengths set",r.mode=30;break}if(r.distbits=6,r.distcode=r.distdyn,A={bits:r.distbits},_=ie(2,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,A),r.distbits=A.bits,_){e.msg="invalid distances set",r.mode=30;break}if(r.mode=20,t===se)break e;case 20:r.mode=21;case 21:if(s>=6&&f>=258){e.next_out=o,e.avail_out=f,e.next_in=a,e.avail_in=s,r.hold=l,r.bits=u,$(e,h),o=e.next_out,i=e.output,f=e.avail_out,a=e.next_in,n=e.input,s=e.avail_in,l=r.hold,u=r.bits,12===r.mode&&(r.back=-1);break}for(r.back=0;y=(I=r.lencode[l&(1<>>16&255,w=65535&I,!((v=I>>>24)<=u);){if(0===s)break e;s--,l+=n[a++]<>g)])>>>16&255,w=65535&I,!(g+(v=I>>>24)<=u);){if(0===s)break e;s--,l+=n[a++]<>>=g,u-=g,r.back+=g}if(l>>>=v,u-=v,r.back+=v,r.length=w,0===y){r.mode=26;break}if(32&y){r.back=-1,r.mode=12;break}if(64&y){e.msg="invalid literal/length code",r.mode=30;break}r.extra=15&y,r.mode=22;case 22:if(r.extra){for(P=r.extra;u>>=r.extra,u-=r.extra,r.back+=r.extra}r.was=r.length,r.mode=23;case 23:for(;y=(I=r.distcode[l&(1<>>16&255,w=65535&I,!((v=I>>>24)<=u);){if(0===s)break e;s--,l+=n[a++]<>g)])>>>16&255,w=65535&I,!(g+(v=I>>>24)<=u);){if(0===s)break e;s--,l+=n[a++]<>>=g,u-=g,r.back+=g}if(l>>>=v,u-=v,r.back+=v,64&y){e.msg="invalid distance code",r.mode=30;break}r.offset=w,r.extra=15&y,r.mode=24;case 24:if(r.extra){for(P=r.extra;u>>=r.extra,u-=r.extra,r.back+=r.extra}if(r.offset>r.dmax){e.msg="invalid distance too far back",r.mode=30;break}r.mode=25;case 25:if(0===f)break e;if(d=h-f,r.offset>d){if((d=r.offset-d)>r.whave&&r.sane){e.msg="invalid distance too far back",r.mode=30;break}d>r.wnext?(d-=r.wnext,p=r.wsize-d):p=r.wnext-d,d>r.length&&(d=r.length),m=r.window}else m=i,p=o-r.offset,d=r.length;d>f&&(d=f),f-=d,r.length-=d;do{i[o++]=m[p++]}while(--d);0===r.length&&(r.mode=21);break;case 26:if(0===f)break e;i[o++]=r.length,f--,r.mode=21;break;case 27:if(r.wrap){for(;u<32;){if(0===s)break e;s--,l|=n[a++]<=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),!(t.windowBits>=0&&t.windowBits<16)||e&&e.windowBits||(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&0==(15&t.windowBits)&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Q,this.strm.avail_out=0;var r=Ue.inflateInit2(this.strm,t.windowBits);if(r!==Be)throw new Error(z[r]);if(this.header=new Se,Ue.inflateGetHeader(this.strm,this.header),t.dictionary&&("string"==typeof t.dictionary?t.dictionary=W(t.dictionary):"[object ArrayBuffer]"===Te.call(t.dictionary)&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw&&(r=Ue.inflateSetDictionary(this.strm,t.dictionary))!==Be))throw new Error(z[r])}function Ge(e,t){var r=new Ve(t);if(r.push(e),r.err)throw r.msg||z[r.err];return r.result}Ve.prototype.push=function(e,t){var r,n,i,a=this.strm,o=this.options.chunkSize,s=this.options.dictionary;if(this.ended)return!1;for(n=t===~~t?t:!0===t?Ee:De,"[object ArrayBuffer]"===Te.call(e)?a.input=new Uint8Array(e):a.input=e,a.next_in=0,a.avail_in=a.input.length;;){for(0===a.avail_out&&(a.output=new Uint8Array(o),a.next_out=0,a.avail_out=o),(r=Ue.inflate(a,n))===Me&&s&&((r=Ue.inflateSetDictionary(a,s))===Be?r=Ue.inflate(a,n):r===Le&&(r=Me));a.avail_in>0&&r===Oe&&a.state.wrap>0&&0!==e[a.next_in];)Ue.inflateReset(a),r=Ue.inflate(a,n);switch(r){case Ce:case Le:case Me:case Re:return this.onEnd(r),this.ended=!0,!1}if(i=a.avail_out,a.next_out&&(0===a.avail_out||r===Oe))if("string"===this.options.to){var f=J(a.output,a.next_out),l=a.next_out-f,u=q(a.output,f);a.next_out=l,a.avail_out=o-l,l&&a.output.set(a.output.subarray(f,f+l),0),this.onData(u)}else this.onData(a.output.length===a.next_out?a.output:a.output.subarray(0,a.next_out));if(r!==Be||0!==i){if(r===Oe)return r=Ue.inflateEnd(this.strm),this.onEnd(r),this.ended=!0,!0;if(0===a.avail_in)break}}return!0},Ve.prototype.onData=function(e){this.chunks.push(e)},Ve.prototype.onEnd=function(e){e===Be&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=K(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var Fe={Inflate:Ve,inflate:Ge,inflateRaw:function(e,t){return(t=t||{}).raw=!0,Ge(e,t)},ungzip:Ge,constants:j}.inflate;function ze(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=v(e);if(t){var i=v(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return m(this,r)}}var je=function(e){p(r,b);var t=ze(r);function r(){return u(this,r),t.apply(this,arguments)}return h(r,[{key:"decodeBlock",value:function(e){return Fe(new Uint8Array(e)).buffer}}]),r}(),Ne=Object.freeze({__proto__:null,default:je});function Ze(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=v(e);if(t){var i=v(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return m(this,r)}}var Ke,He=function(e){p(r,b);var t=Ze(r);function r(){return u(this,r),t.apply(this,arguments)}return h(r,[{key:"decodeBlock",value:function(e){for(var t=new DataView(e),r=[],n=0;n>3],I<<=7&U),v=0;v>3]),128&I?(f&&(f[U]=1),m=m>(o=T.encoding<2?_[A++]:P)?o:m,s[U++]=o):(f&&(f[U]=0),s[U++]=n),I<<=1;U+=S}else if(T.encoding<2)for(y=0;y(o=_[A++])?o:m,s[U++]=o;U+=S}else for(m=m>P?P:m,y=0;y0){var o=new Uint8Array(Math.ceil(n.width*n.height/8)),s=(a=new DataView(e,t,n.mask.numBytes)).getInt16(0,!0),f=2,l=0;do{if(s>0)for(;s--;)o[l++]=a.getUint8(f++);else{var u=a.getUint8(f++);for(s=-s;s--;)o[l++]=u}s=a.getInt16(f,!0),f+=2}while(f0?1:0),p=h+(n.height%h>0?1:0);n.pixels.blocks=new Array(d*p);for(var m=0,v=0;v3)throw"Invalid block encoding ("+b.encoding+")";if(2!==b.encoding){if(0!==k&&2!==k){if(k>>=6,b.offsetType=k,2===k)b.offset=a.getInt8(1),w++;else if(1===k)b.offset=a.getInt16(1,!0),w+=2;else{if(0!==k)throw"Invalid block offset type";b.offset=a.getFloat32(1,!0),w+=4}if(1===b.encoding)if(k=a.getUint8(w),w++,b.bitsPerPixel=63&k,k>>=6,b.numValidPixelsType=k,2===k)b.numValidPixels=a.getUint8(w),w++;else if(1===k)b.numValidPixels=a.getUint16(w,!0),w+=2;else{if(0!==k)throw"Invalid valid pixel count type";b.numValidPixels=a.getUint32(w,!0),w+=4}}var x;if(t+=w,3!==b.encoding)if(0===b.encoding){var _=(n.pixels.numBytes-1)/4;if(_!==Math.floor(_))throw"uncompressed block has invalid length";x=new ArrayBuffer(4*_),new Uint8Array(x).set(new Uint8Array(e,t,4*_));var A=new Float32Array(x);b.rawData=A,t+=4*_}else if(1===b.encoding){var P=Math.ceil(b.numValidPixels*b.bitsPerPixel/8),I=Math.ceil(P/4);x=new ArrayBuffer(4*I),new Uint8Array(x).set(new Uint8Array(e,t,P)),b.stuffedData=new Uint32Array(x),t+=P}}else t++}return n.eofOffset=t,n},a=function(e,t,r,n,i,a,o){var s,f,l,u=(1<=t)f=l>>>h-t&u,h-=t;else{var m=t-h;f=(l&u)<>>(h=32-m)}a[s]=f=r?(l=u>>>m-r&d,m-=r):(l=(u&d)<<(c=r-m)&d,l+=(u=e[p++])>>>(m=32-c)),t[f]=i[l];else for(h=Math.ceil((s-a)/o),f=0;f=r?(l=u>>>m-r&d,m-=r):(l=(u&d)<<(c=r-m)&d,l+=(u=e[p++])>>>(m=32-c)),t[f]=l=t?(h=o>>>c-t&s,c-=t):(h=(o&s)<<(u=t-c)&s,h+=(o=e[f++])>>>(c=32-u)),d[l]=h=r?(l=u>>>m&h,p-=r,m+=r):(l=u>>>m&h,p=32-(c=r-p),l|=((u=e[d++])&(1<=r?(l=u>>>m&h,p-=r,m+=r):(l=u>>>m&h,p=32-(c=r-p),l|=((u=e[d++])&(1<=t?(h=o>>>d&s,c-=t,d+=t):(h=o>>>d&s,c=32-(u=t-c),h|=((o=e[f++])&(1<=r?(a=o>>>u-r&f,u-=r):(a=(o&f)<<(s=r-u)&f,a+=(o=e[l++])>>>(u=32-s)),t[i]=a;return t},c=function(e,t,r,n){var i,a,o,s,f=(1<=r?(a=o>>>c&f,u-=r,c+=r):(a=o>>>c&f,u=32-(s=r-u),a|=((o=e[l++])&(1<=359?359:i;i-=o;do{t+=e[a++]<<8,r+=t+=e[a++]}while(--o);t=(65535&t)+(t>>>16),r=(65535&r)+(r>>>16)}return 1&n&&(r+=t+=e[a]<<8),((r=(65535&r)+(r>>>16))<<16|(t=(65535&t)+(t>>>16)))>>>0},readHeaderInfo:function(e,t){var r=t.ptr,n=new Uint8Array(e,r,6),i={};if(i.fileIdentifierString=String.fromCharCode.apply(null,n),0!==i.fileIdentifierString.lastIndexOf("Lerc2",0))throw"Unexpected file identifier string (expect Lerc2 ): "+i.fileIdentifierString;r+=6;var a,o=new DataView(e,r,8),s=o.getInt32(0,!0);if(i.fileVersion=s,r+=4,s>=3&&(i.checksum=o.getUint32(4,!0),r+=4),o=new DataView(e,r,12),i.height=o.getUint32(0,!0),i.width=o.getUint32(4,!0),r+=8,s>=4?(i.numDims=o.getUint32(8,!0),r+=4):i.numDims=1,o=new DataView(e,r,40),i.numValidPixel=o.getUint32(0,!0),i.microBlockSize=o.getInt32(4,!0),i.blobSize=o.getInt32(8,!0),i.imageType=o.getInt32(12,!0),i.maxZError=o.getFloat64(16,!0),i.zMin=o.getFloat64(24,!0),i.zMax=o.getFloat64(32,!0),r+=40,t.headerInfo=i,t.ptr=r,s>=3&&(a=s>=4?52:48,this.computeChecksumFletcher32(new Uint8Array(e,r-a,i.blobSize-14))!==i.checksum))throw"Checksum failed.";return!0},checkMinMaxRanges:function(e,t){var r=t.headerInfo,n=this.getDataTypeArray(r.imageType),i=r.numDims*this.getDataTypeSize(r.imageType),a=this.readSubArray(e,t.ptr,n,i),o=this.readSubArray(e,t.ptr+i,n,i);t.ptr+=2*i;var s,f=!0;for(s=0;s0){r=new Uint8Array(Math.ceil(o/8));var u=(f=new DataView(e,i,l.numBytes)).getInt16(0,!0),c=2,h=0,d=0;do{if(u>0)for(;u--;)r[h++]=f.getUint8(c++);else for(d=f.getUint8(c++),u=-u;u--;)r[h++]=d;u=f.getInt16(c,!0),c+=2}while(c>3],p<<=7&m):p=r[m>>3],128&p&&(n[m]=1);t.pixels.resultMask=n,l.bitset=r,i+=l.numBytes}return t.ptr=i,t.mask=l,!0},readDataOneSweep:function(e,t,r,n){var i,a=t.ptr,o=t.headerInfo,s=o.numDims,f=o.width*o.height,l=o.imageType,u=o.numValidPixel*h.getDataTypeSize(l)*s,c=t.pixels.resultMask;if(r===Uint8Array)i=new Uint8Array(e,a,u);else{var d=new ArrayBuffer(u);new Uint8Array(d).set(new Uint8Array(e,a,u)),i=new r(d)}if(i.length===f*s)t.pixels.resultPixels=n?h.swapDimensionOrder(i,f,s,r,!0):i;else{t.pixels.resultPixels=new r(f*s);var p=0,m=0,v=0,y=0;if(s>1){if(n){for(m=0;m=o)return!1;var s=new Uint32Array(o-a);h.decodeBits(e,t,s);var f,l,u,c,p=[];for(f=a;f0&&(p[l].second=w<>>32-c,32-b>=c?32===(b+=c)&&(b=0,w=g[++k]):(b+=c-32,w=g[++k],p[l].second|=w>>>32-b));var x=0,_=0,A=new d;for(f=0;f=r?r:x;var P,I,U,S,T,D=[];for(f=a;f0)if(P=[c,l],c<=_)for(I=p[l].second<<_-c,U=1<<_-c,u=0;u=0;S--)I>>>S&1?(T.right||(T.right=new d),T=T.right):(T.left||(T.left=new d),T=T.left),0!==S||T.val||(T.val=P[1]);return{decodeLut:D,numBitsLUTQick:_,numBitsLUT:x,tree:A,stuffedData:g,srcPtr:k,bitPos:b}},readHuffman:function(e,t,r,n){var i,a,o,s,f,l,u,c,d,p=t.headerInfo.numDims,m=t.headerInfo.height,v=t.headerInfo.width,y=v*m,w=this.readHuffmanTree(e,t),g=w.decodeLut,b=w.tree,k=w.stuffedData,x=w.srcPtr,_=w.bitPos,A=w.numBitsLUTQick,P=w.numBitsLUT,I=0===t.headerInfo.imageType?128:0,U=t.pixels.resultMask,S=0;_>0&&(x++,_=0);var T,D=k[x],E=1===t.encodeMode,B=new r(y*p),O=B;if(p<2||E){for(T=0;T1&&(O=new r(B.buffer,y*T,y),S=0),t.headerInfo.numValidPixel===v*m)for(c=0,l=0;l>>32-A,32-_>>64-_-A),g[f])a=g[f][1],_+=g[f][0];else for(f=s=D<<_>>>32-P,32-_>>64-_-P),i=b,d=0;d>>P-d-1&1?i.right:i.left).left&&!i.right){a=i.val,_=_+d+1;break}_>=32&&(_-=32,D=k[++x]),o=a-I,E?(o+=u>0?S:l>0?O[c-v]:S,o&=255,O[c]=o,S=o):O[c]=o}else for(c=0,l=0;l>>32-A,32-_>>64-_-A),g[f])a=g[f][1],_+=g[f][0];else for(f=s=D<<_>>>32-P,32-_>>64-_-P),i=b,d=0;d>>P-d-1&1?i.right:i.left).left&&!i.right){a=i.val,_=_+d+1;break}_>=32&&(_-=32,D=k[++x]),o=a-I,E?(u>0&&U[c-1]?o+=S:l>0&&U[c-v]?o+=O[c-v]:o+=S,o&=255,O[c]=o,S=o):O[c]=o}}else for(c=0,l=0;l>>32-A,32-_>>64-_-A),g[f])a=g[f][1],_+=g[f][0];else for(f=s=D<<_>>>32-P,32-_>>64-_-P),i=b,d=0;d>>P-d-1&1?i.right:i.left).left&&!i.right){a=i.val,_=_+d+1;break}_>=32&&(_-=32,D=k[++x]),o=a-I,O[c]=o}t.ptr=t.ptr+4*(x+1)+(_>0?4:0),t.pixels.resultPixels=B,p>1&&!n&&(t.pixels.resultPixels=h.swapDimensionOrder(B,y,p,r))},decodeBits:function(e,t,r,n,i){var a=t.headerInfo,h=a.fileVersion,d=0,p=e.byteLength-t.ptr>=5?5:e.byteLength-t.ptr,m=new DataView(e,t.ptr,p),v=m.getUint8(0);d++;var y=v>>6,w=0===y?4:3-y,g=(32&v)>0,b=31&v,k=0;if(1===w)k=m.getUint8(d),d++;else if(2===w)k=m.getUint16(d,!0),d+=2;else{if(4!==w)throw"Invalid valid pixel count type";k=m.getUint32(d,!0),d+=4}var x,_,A,P,I,U,S,T,D,E=2*a.maxZError,B=a.numDims>1?a.maxValues[i]:a.zMax;if(g){for(t.counter.lut++,T=m.getUint8(d),d++,P=Math.ceil((T-1)*b/8),I=Math.ceil(P/4),_=new ArrayBuffer(4*I),A=new Uint8Array(_),t.ptr+=d,A.set(new Uint8Array(e,t.ptr,P)),S=new Uint32Array(_),t.ptr+=P,D=0;T-1>>>D;)D++;P=Math.ceil(k*D/8),I=Math.ceil(P/4),_=new ArrayBuffer(4*I),(A=new Uint8Array(_)).set(new Uint8Array(e,t.ptr,P)),x=new Uint32Array(_),t.ptr+=P,U=h>=3?l(S,b,T-1,n,E,B):s(S,b,T-1,n,E,B),h>=3?f(x,r,D,k,U):o(x,r,D,k,U)}else t.counter.bitstuffer++,D=b,t.ptr+=d,D>0&&(P=Math.ceil(k*D/8),I=Math.ceil(P/4),_=new ArrayBuffer(4*I),(A=new Uint8Array(_)).set(new Uint8Array(e,t.ptr,P)),x=new Uint32Array(_),t.ptr+=P,h>=3?null==n?c(x,r,D,k):f(x,r,D,k,!1,n,E,B):null==n?u(x,r,D,k):o(x,r,D,k,!1,n,E,B))},readTiles:function(e,t,r,n){var i=t.headerInfo,a=i.width,o=i.height,s=a*o,f=i.microBlockSize,l=i.imageType,u=h.getDataTypeSize(l),c=Math.ceil(a/f),d=Math.ceil(o/f);t.pixels.numBlocksY=d,t.pixels.numBlocksX=c,t.pixels.ptr=0;var p,m,v,y,w,g,b,k,x,_,A=0,P=0,I=0,U=0,S=0,T=0,D=0,E=0,B=0,O=0,M=0,C=0,L=0,R=0,V=0,G=new r(f*f),F=o%f||f,z=a%f||f,j=i.numDims,N=t.pixels.resultMask,Z=t.pixels.resultPixels,K=i.fileVersion>=5?14:15,H=i.zMax;for(I=0;I1?(_=Z,O=I*a*f+U*f,Z=new r(t.pixels.resultPixels.buffer,s*k*u,s),H=i.maxValues[k]):_=null,D=e.byteLength-t.ptr,m={},V=0,E=(p=new DataView(e,t.ptr,Math.min(10,D))).getUint8(0),V++,x=i.fileVersion>=5?4&E:0,B=E>>6&255,(E>>2&K)!=(U*f>>3&K))throw"integrity issue";if(x&&0===k)throw"integrity issue";if((w=3&E)>3)throw t.ptr+=V,"Invalid block encoding ("+w+")";if(2!==w)if(0===w){if(x)throw"integrity issue";if(t.counter.uncompressed++,t.ptr+=V,C=(C=S*T*u)<(L=e.byteLength-t.ptr)?C:L,v=new ArrayBuffer(C%u==0?C:C+u-C%u),new Uint8Array(v).set(new Uint8Array(e,t.ptr,C)),y=new r(v),R=0,N)for(A=0;A1&&!n&&(t.pixels.resultPixels=h.swapDimensionOrder(t.pixels.resultPixels,s,j,r))},formatFileInfo:function(e){return{fileIdentifierString:e.headerInfo.fileIdentifierString,fileVersion:e.headerInfo.fileVersion,imageType:e.headerInfo.imageType,height:e.headerInfo.height,width:e.headerInfo.width,numValidPixel:e.headerInfo.numValidPixel,microBlockSize:e.headerInfo.microBlockSize,blobSize:e.headerInfo.blobSize,maxZError:e.headerInfo.maxZError,pixelType:h.getPixelType(e.headerInfo.imageType),eofOffset:e.eofOffset,mask:e.mask?{numBytes:e.mask.numBytes}:null,pixels:{numBlocksX:e.pixels.numBlocksX,numBlocksY:e.pixels.numBlocksY,maxValue:e.headerInfo.zMax,minValue:e.headerInfo.zMin,noDataValue:e.noDataValue}}},constructConstantSurface:function(e,t){var r=e.headerInfo.zMax,n=e.headerInfo.zMin,i=e.headerInfo.maxValues,a=e.headerInfo.numDims,o=e.headerInfo.height*e.headerInfo.width,s=0,f=0,l=0,u=e.pixels.resultMask,c=e.pixels.resultPixels;if(u)if(a>1){if(t)for(s=0;s1&&n!==r)if(t)for(s=0;s=-128&&t<=127;break;case 1:r=t>=0&&t<=255;break;case 2:r=t>=-32768&&t<=32767;break;case 3:r=t>=0&&t<=65536;break;case 4:r=t>=-2147483648&&t<=2147483647;break;case 5:r=t>=0&&t<=4294967296;break;case 6:r=t>=-34027999387901484e22&&t<=34027999387901484e22;break;case 7:r=t>=-17976931348623157e292&&t<=17976931348623157e292;break;default:r=!1}return r},getDataTypeSize:function(e){var t=0;switch(e){case 0:case 1:t=1;break;case 2:case 3:t=2;break;case 4:case 5:case 6:t=4;break;case 7:t=8;break;default:t=e}return t},getDataTypeUsed:function(e,t){var r=e;switch(e){case 2:case 4:r=e-t;break;case 3:case 5:r=e-2*t;break;case 6:r=0===t?e:1===t?2:1;break;case 7:r=0===t?e:e-2*t+1;break;default:r=e}return r},getOnePixel:function(e,t,r,n){var i=0;switch(r){case 0:i=n.getInt8(t);break;case 1:i=n.getUint8(t);break;case 2:i=n.getInt16(t,!0);break;case 3:i=n.getUint16(t,!0);break;case 4:i=n.getInt32(t,!0);break;case 5:i=n.getUInt32(t,!0);break;case 6:i=n.getFloat32(t,!0);break;case 7:i=n.getFloat64(t,!0);break;default:throw"the decoder does not understand this pixel type"}return i},swapDimensionOrder:function(e,t,r,n,i){var a=0,o=0,s=0,f=0,l=e;if(r>1)if(l=new n(t*r),i)for(a=0;a5)throw"unsupported lerc version 2."+o;h.readMask(e,i),a.numValidPixel===a.width*a.height||i.pixels.resultMask||(i.pixels.resultMask=t.maskData);var f=a.width*a.height;i.pixels.resultPixels=new s(f*a.numDims),i.counter={onesweep:0,uncompressed:0,lut:0,bitstuffer:0,constant:0,constantoffset:0};var l,u=!t.returnPixelInterleavedDims;if(0!==a.numValidPixel)if(a.zMax===a.zMin)h.constructConstantSurface(i,u);else if(o>=4&&h.checkMinMaxRanges(e,i))h.constructConstantSurface(i,u);else{var c=new DataView(e,i.ptr,2),d=c.getUint8(0);if(i.ptr++,d)h.readDataOneSweep(e,i,s,u);else if(o>1&&a.imageType<=1&&Math.abs(a.maxZError-.5)<1e-5){var p=c.getUint8(1);if(i.ptr++,i.encodeMode=p,p>2||o<4&&p>1)throw"Invalid Huffman flag "+p;p?h.readHuffman(e,i,s,u):h.readTiles(e,i,s,u)}else h.readTiles(e,i,s,u)}i.eofOffset=i.ptr,t.inputOffset?(l=i.headerInfo.blobSize+t.inputOffset-i.ptr,Math.abs(l)>=1&&(i.eofOffset=t.inputOffset+i.headerInfo.blobSize)):(l=i.headerInfo.blobSize-i.ptr,Math.abs(l)>=1&&(i.eofOffset=i.headerInfo.blobSize));var m={width:a.width,height:a.height,pixelData:i.pixels.resultPixels,minValue:a.zMin,maxValue:a.zMax,validPixelCount:a.numValidPixel,dimCount:a.numDims,dimStats:{minValues:a.minValues,maxValues:a.maxValues},maskData:i.pixels.resultMask};if(i.pixels.resultMask&&h.isValidPixelValue(a.imageType,r)){var v=i.pixels.resultMask;for(n=0;n1&&(l&&m.push(l),k.fileInfo.mask&&k.fileInfo.mask.numBytes>0&&b++),d++,g.pixels.push(k.pixelData),g.statistics.push({minValue:k.minValue,maxValue:k.maxValue,noDataValue:k.noDataValue,dimStats:k.dimStats})}if(n>1&&b>1){for(h=g.width*g.height,g.bandMasks=m,(l=new Uint8Array(h)).set(m[0]),u=1;u0&&void 0!==arguments[0]||new mr},e.writeArrayBuffer=function(e,t){return pr(e,t)},Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=geotiff.js.map