@basemaps/lambda-tiler 7.12.0 → 7.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/build/routes/__tests__/tile.style.json.test.js +3 -1
  3. package/build/routes/__tests__/tile.style.json.test.js.map +1 -1
  4. package/build/routes/tile.style.json.d.ts +4 -0
  5. package/build/routes/tile.style.json.js +1 -1
  6. package/build/routes/tile.style.json.js.map +1 -1
  7. package/build/util/__test__/nztm.style.test.js +16 -7
  8. package/build/util/__test__/nztm.style.test.js.map +1 -1
  9. package/build/util/nztm.style.js +0 -3
  10. package/build/util/nztm.style.js.map +1 -1
  11. package/dist/index.js +86646 -0
  12. package/dist/node_modules/.package-lock.json +179 -0
  13. package/dist/node_modules/@img/sharp-libvips-linux-arm64/README.md +47 -0
  14. package/dist/node_modules/@img/sharp-libvips-linux-arm64/lib/glib-2.0/include/glibconfig.h +219 -0
  15. package/dist/node_modules/@img/sharp-libvips-linux-arm64/lib/index.js +1 -0
  16. package/dist/node_modules/@img/sharp-libvips-linux-arm64/lib/libvips-cpp.so.42 +0 -0
  17. package/dist/node_modules/@img/sharp-libvips-linux-arm64/package.json +45 -0
  18. package/dist/node_modules/@img/sharp-libvips-linux-arm64/versions.json +31 -0
  19. package/dist/node_modules/@img/sharp-linux-arm64/LICENSE +191 -0
  20. package/dist/node_modules/@img/sharp-linux-arm64/README.md +18 -0
  21. package/dist/node_modules/@img/sharp-linux-arm64/lib/sharp-linux-arm64.node +0 -0
  22. package/dist/node_modules/@img/sharp-linux-arm64/package.json +47 -0
  23. package/dist/node_modules/color/LICENSE +21 -0
  24. package/dist/node_modules/color/README.md +123 -0
  25. package/dist/node_modules/color/index.js +496 -0
  26. package/dist/node_modules/color/package.json +47 -0
  27. package/dist/node_modules/color-convert/CHANGELOG.md +54 -0
  28. package/dist/node_modules/color-convert/LICENSE +21 -0
  29. package/dist/node_modules/color-convert/README.md +68 -0
  30. package/dist/node_modules/color-convert/conversions.js +839 -0
  31. package/dist/node_modules/color-convert/index.js +81 -0
  32. package/dist/node_modules/color-convert/package.json +48 -0
  33. package/dist/node_modules/color-convert/route.js +97 -0
  34. package/dist/node_modules/color-name/LICENSE +8 -0
  35. package/dist/node_modules/color-name/README.md +11 -0
  36. package/dist/node_modules/color-name/index.js +152 -0
  37. package/dist/node_modules/color-name/package.json +28 -0
  38. package/dist/node_modules/color-string/LICENSE +21 -0
  39. package/dist/node_modules/color-string/README.md +62 -0
  40. package/dist/node_modules/color-string/index.js +242 -0
  41. package/dist/node_modules/color-string/package.json +39 -0
  42. package/dist/node_modules/detect-libc/LICENSE +201 -0
  43. package/dist/node_modules/detect-libc/README.md +163 -0
  44. package/dist/node_modules/detect-libc/index.d.ts +14 -0
  45. package/dist/node_modules/detect-libc/lib/detect-libc.js +267 -0
  46. package/dist/node_modules/detect-libc/lib/filesystem.js +41 -0
  47. package/dist/node_modules/detect-libc/lib/process.js +24 -0
  48. package/dist/node_modules/detect-libc/package.json +40 -0
  49. package/dist/node_modules/is-arrayish/LICENSE +21 -0
  50. package/dist/node_modules/is-arrayish/README.md +16 -0
  51. package/dist/node_modules/is-arrayish/index.js +9 -0
  52. package/dist/node_modules/is-arrayish/package.json +45 -0
  53. package/dist/node_modules/is-arrayish/yarn-error.log +1443 -0
  54. package/dist/node_modules/lerc/CHANGELOG.md +69 -0
  55. package/dist/node_modules/lerc/LercDecode.d.ts +61 -0
  56. package/dist/node_modules/lerc/LercDecode.es.d.ts +61 -0
  57. package/dist/node_modules/lerc/LercDecode.es.js +434 -0
  58. package/dist/node_modules/lerc/LercDecode.es.min.js +17 -0
  59. package/dist/node_modules/lerc/LercDecode.js +448 -0
  60. package/dist/node_modules/lerc/LercDecode.min.js +17 -0
  61. package/dist/node_modules/lerc/README.md +123 -0
  62. package/dist/node_modules/lerc/lerc-wasm.wasm +0 -0
  63. package/dist/node_modules/lerc/package.json +30 -0
  64. package/dist/node_modules/semver/LICENSE +15 -0
  65. package/dist/node_modules/semver/README.md +654 -0
  66. package/dist/node_modules/semver/bin/semver.js +188 -0
  67. package/dist/node_modules/semver/classes/comparator.js +141 -0
  68. package/dist/node_modules/semver/classes/index.js +5 -0
  69. package/dist/node_modules/semver/classes/range.js +554 -0
  70. package/dist/node_modules/semver/classes/semver.js +302 -0
  71. package/dist/node_modules/semver/functions/clean.js +6 -0
  72. package/dist/node_modules/semver/functions/cmp.js +52 -0
  73. package/dist/node_modules/semver/functions/coerce.js +60 -0
  74. package/dist/node_modules/semver/functions/compare-build.js +7 -0
  75. package/dist/node_modules/semver/functions/compare-loose.js +3 -0
  76. package/dist/node_modules/semver/functions/compare.js +5 -0
  77. package/dist/node_modules/semver/functions/diff.js +65 -0
  78. package/dist/node_modules/semver/functions/eq.js +3 -0
  79. package/dist/node_modules/semver/functions/gt.js +3 -0
  80. package/dist/node_modules/semver/functions/gte.js +3 -0
  81. package/dist/node_modules/semver/functions/inc.js +19 -0
  82. package/dist/node_modules/semver/functions/lt.js +3 -0
  83. package/dist/node_modules/semver/functions/lte.js +3 -0
  84. package/dist/node_modules/semver/functions/major.js +3 -0
  85. package/dist/node_modules/semver/functions/minor.js +3 -0
  86. package/dist/node_modules/semver/functions/neq.js +3 -0
  87. package/dist/node_modules/semver/functions/parse.js +16 -0
  88. package/dist/node_modules/semver/functions/patch.js +3 -0
  89. package/dist/node_modules/semver/functions/prerelease.js +6 -0
  90. package/dist/node_modules/semver/functions/rcompare.js +3 -0
  91. package/dist/node_modules/semver/functions/rsort.js +3 -0
  92. package/dist/node_modules/semver/functions/satisfies.js +10 -0
  93. package/dist/node_modules/semver/functions/sort.js +3 -0
  94. package/dist/node_modules/semver/functions/valid.js +6 -0
  95. package/dist/node_modules/semver/index.js +89 -0
  96. package/dist/node_modules/semver/internal/constants.js +35 -0
  97. package/dist/node_modules/semver/internal/debug.js +9 -0
  98. package/dist/node_modules/semver/internal/identifiers.js +23 -0
  99. package/dist/node_modules/semver/internal/lrucache.js +40 -0
  100. package/dist/node_modules/semver/internal/parse-options.js +15 -0
  101. package/dist/node_modules/semver/internal/re.js +217 -0
  102. package/dist/node_modules/semver/package.json +77 -0
  103. package/dist/node_modules/semver/preload.js +2 -0
  104. package/dist/node_modules/semver/range.bnf +16 -0
  105. package/dist/node_modules/semver/ranges/gtr.js +4 -0
  106. package/dist/node_modules/semver/ranges/intersects.js +7 -0
  107. package/dist/node_modules/semver/ranges/ltr.js +4 -0
  108. package/dist/node_modules/semver/ranges/max-satisfying.js +25 -0
  109. package/dist/node_modules/semver/ranges/min-satisfying.js +24 -0
  110. package/dist/node_modules/semver/ranges/min-version.js +61 -0
  111. package/dist/node_modules/semver/ranges/outside.js +80 -0
  112. package/dist/node_modules/semver/ranges/simplify.js +47 -0
  113. package/dist/node_modules/semver/ranges/subset.js +247 -0
  114. package/dist/node_modules/semver/ranges/to-comparators.js +8 -0
  115. package/dist/node_modules/semver/ranges/valid.js +11 -0
  116. package/dist/node_modules/sharp/LICENSE +191 -0
  117. package/dist/node_modules/sharp/README.md +118 -0
  118. package/dist/node_modules/sharp/install/check.js +36 -0
  119. package/dist/node_modules/sharp/lib/channel.js +174 -0
  120. package/dist/node_modules/sharp/lib/colour.js +182 -0
  121. package/dist/node_modules/sharp/lib/composite.js +210 -0
  122. package/dist/node_modules/sharp/lib/constructor.js +444 -0
  123. package/dist/node_modules/sharp/lib/index.d.ts +1717 -0
  124. package/dist/node_modules/sharp/lib/index.js +16 -0
  125. package/dist/node_modules/sharp/lib/input.js +657 -0
  126. package/dist/node_modules/sharp/lib/is.js +169 -0
  127. package/dist/node_modules/sharp/lib/libvips.js +171 -0
  128. package/dist/node_modules/sharp/lib/operation.js +919 -0
  129. package/dist/node_modules/sharp/lib/output.js +1561 -0
  130. package/dist/node_modules/sharp/lib/resize.js +582 -0
  131. package/dist/node_modules/sharp/lib/sharp.js +86 -0
  132. package/dist/node_modules/sharp/lib/utility.js +287 -0
  133. package/dist/node_modules/sharp/package.json +219 -0
  134. package/dist/node_modules/sharp/src/binding.gyp +277 -0
  135. package/dist/node_modules/sharp/src/common.cc +1090 -0
  136. package/dist/node_modules/sharp/src/common.h +393 -0
  137. package/dist/node_modules/sharp/src/metadata.cc +287 -0
  138. package/dist/node_modules/sharp/src/metadata.h +82 -0
  139. package/dist/node_modules/sharp/src/operations.cc +471 -0
  140. package/dist/node_modules/sharp/src/operations.h +125 -0
  141. package/dist/node_modules/sharp/src/pipeline.cc +1724 -0
  142. package/dist/node_modules/sharp/src/pipeline.h +385 -0
  143. package/dist/node_modules/sharp/src/sharp.cc +40 -0
  144. package/dist/node_modules/sharp/src/stats.cc +183 -0
  145. package/dist/node_modules/sharp/src/stats.h +59 -0
  146. package/dist/node_modules/sharp/src/utilities.cc +269 -0
  147. package/dist/node_modules/sharp/src/utilities.h +19 -0
  148. package/dist/node_modules/simple-swizzle/LICENSE +21 -0
  149. package/dist/node_modules/simple-swizzle/README.md +39 -0
  150. package/dist/node_modules/simple-swizzle/index.js +29 -0
  151. package/dist/node_modules/simple-swizzle/package.json +36 -0
  152. package/dist/package-lock.json +610 -0
  153. package/dist/package.json +40 -0
  154. package/dist/static/expected_tile_2193_153_255_z7.png +0 -0
  155. package/dist/static/expected_tile_NZTM2000Quad_30_33_z6.png +0 -0
  156. package/dist/static/expected_tile_WebMercatorQuad_252_156_z8.png +0 -0
  157. package/package.json +6 -6
  158. package/src/routes/__tests__/tile.style.json.test.ts +3 -2
  159. package/src/routes/tile.style.json.ts +1 -1
  160. package/src/util/__test__/nztm.style.test.ts +18 -8
  161. package/src/util/nztm.style.ts +0 -3
  162. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,69 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](http://keepachangelog.com/)
6
+ and this project adheres to [Semantic Versioning](http://semver.org/).
7
+
8
+ ## [Unreleased][HEAD]
9
+
10
+ ## [4.0.4] - 2023-10-30
11
+ * Removed unnecessary files in the npm package.
12
+
13
+ ## [4.0.3] - 2023-10-30
14
+ * Fixed release package -- should include dist only.
15
+
16
+ ## [4.0.2] - 2023-10-27
17
+ * Fixed a small memory leak when nDepth is more than 1 and when noData value is actually used in one or more bands.
18
+
19
+ ## [4.0.1] - 2022-07-19
20
+ * Export typings.
21
+
22
+ ## [4.0.0] - 2022-07-15
23
+
24
+ Now uses web assembly, as a result:
25
+ * The existing Javascript decoder ```js/LercDecode.js``` is deprecated. It will be removed in next major release.
26
+ * [Web Assembly](https://caniuse.com/wasm) support is now required. IE11 is therefore no longer supported.
27
+ * ```Lerc.load()``` must be invoked and the returned promise must be resolved prior to ```Lerc.decode```. This only needs to be done once per worker (or the main thread). There's no extra cost when invoked multiple times as the internal wasm loading promise is cached.
28
+ * Updated build script ```npm run build```. A dev build result (unminified UMD bundle) is included in the ```js/dist``` folder for convenience.
29
+ * Both UMD and ES modules are included in dist, along with a typing file.
30
+ * Deprecated ```decodeResult.dimCount, decodeOptions.returnPixelInterleavedDims```, prefer to use ```depthCount, returnInterleaved```
31
+ which is in line with C API concept.
32
+
33
+ ## [3.0.0] - 2021-07-30
34
+
35
+ The decoder is in sync with ArcMap 10.8.1 and ArcGIS Pro 2.8. LERC encoded binary blobs from any previous version of ArcMap or ArcGIS Pro can also be read / decoded.
36
+
37
+ ### Added
38
+ * Added an option to return decoded n-dim blob using pixel-interleaved layout
39
+
40
+ ### Changed
41
+ * Upgrade Lerc codec to new version Lerc 2.5.
42
+
43
+ ## [2.0.0] - 2018-11-06
44
+
45
+ The decoder is in sync with ArcMap 10.7 and ArcGIS Pro 2.3. LERC encoded binary blobs from any previous version of ArcMap or ArcGIS Pro can also be read / decoded.
46
+
47
+ ### Added
48
+ * Extend from one value per pixel to nDim values per pixel.
49
+
50
+ ### Changed
51
+ * Upgrade Lerc codec to new version Lerc 2.4.
52
+
53
+ ## 1.0.1 - 2017-02-18
54
+
55
+ ### Fixed
56
+
57
+ * resolved a Huffman code table parsing issue [#31](https://github.com/Esri/lerc/pull/31)
58
+
59
+ ## 1.0 - 2016-11-30
60
+
61
+ This LERC API JavaScript decoder is in sync with ArcMap 10.5 and ArcGIS Pro 1.4. LERC encoded binary blobs from any previous version of ArcMap or ArcGIS Pro can be read / decoded as well.
62
+
63
+ ### What will trigger a major version change
64
+
65
+ - A change to this LERC API that is not backwards compatible and requires users to update / change their code in order to use an upgraded .dll or .so file.
66
+ - A change to the LERC bitstream that is not backwards compatible and requires users to upgrade their LERC encoder and / or decoder.
67
+
68
+ [2.0.0]: https://github.com/Esri/lerc/compare/v1.0.1...v2.0 "v2.0"
69
+ [HEAD]: https://github.com/Esri/lerc/compare/v2.0...HEAD "Unreleased Changes"
@@ -0,0 +1,61 @@
1
+ export type PixelTypedArray =
2
+ | Int8Array
3
+ | Uint8Array
4
+ | Uint8ClampedArray
5
+ | Int16Array
6
+ | Uint16Array
7
+ | Int32Array
8
+ | Uint32Array
9
+ | Float32Array
10
+ | Float64Array;
11
+
12
+ export type LercPixelType = "S8" | "U8" | "S16" | "U16" | "S32" | "U32" | "F32" | "F64";
13
+
14
+ export interface BandStats {
15
+ minValue: number;
16
+ maxValue: number;
17
+ depthStats?: {
18
+ minValues: Float64Array;
19
+ maxValues: Float64Array;
20
+ };
21
+ }
22
+
23
+ export interface LercHeaderInfo {
24
+ version: number;
25
+ width: number;
26
+ height: number;
27
+ validPixelCount: number;
28
+ bandCount: number;
29
+ blobSize: number;
30
+ maskCount: number;
31
+ depthCount: number;
32
+ dataType: number;
33
+ minValue: number;
34
+ maxValue: number;
35
+ maxZerror: number;
36
+ statistics: BandStats[];
37
+ bandCountWithNoData: number;
38
+ }
39
+
40
+ export interface DecodeOptions {
41
+ inputOffset?: number;
42
+ returnInterleaved?: boolean;
43
+ noDataValue?: number;
44
+ }
45
+
46
+ export interface LercData {
47
+ width: number;
48
+ height: number;
49
+ pixelType: LercPixelType;
50
+ statistics: BandStats[];
51
+ pixels: PixelTypedArray[];
52
+ mask: Uint8Array;
53
+ depthCount: number;
54
+ bandMasks?: Uint8Array[];
55
+ }
56
+
57
+ export function load(options?: { locateFile?: (wasmFileName?: string, scriptDir?: string) => string }): Promise<void>;
58
+ export function isLoaded(): boolean;
59
+ export function decode(input: ArrayBuffer | Uint8Array, options?: DecodeOptions): LercData;
60
+ export function getBlobInfo(input: ArrayBuffer | Uint8Array, options?: { inputOffset?: number }): LercHeaderInfo;
61
+ export function getBandCount(input: ArrayBuffer | Uint8Array, options?: { inputOffset?: number }): number;
@@ -0,0 +1,61 @@
1
+ export type PixelTypedArray =
2
+ | Int8Array
3
+ | Uint8Array
4
+ | Uint8ClampedArray
5
+ | Int16Array
6
+ | Uint16Array
7
+ | Int32Array
8
+ | Uint32Array
9
+ | Float32Array
10
+ | Float64Array;
11
+
12
+ export type LercPixelType = "S8" | "U8" | "S16" | "U16" | "S32" | "U32" | "F32" | "F64";
13
+
14
+ export interface BandStats {
15
+ minValue: number;
16
+ maxValue: number;
17
+ depthStats?: {
18
+ minValues: Float64Array;
19
+ maxValues: Float64Array;
20
+ };
21
+ }
22
+
23
+ export interface LercHeaderInfo {
24
+ version: number;
25
+ width: number;
26
+ height: number;
27
+ validPixelCount: number;
28
+ bandCount: number;
29
+ blobSize: number;
30
+ maskCount: number;
31
+ depthCount: number;
32
+ dataType: number;
33
+ minValue: number;
34
+ maxValue: number;
35
+ maxZerror: number;
36
+ statistics: BandStats[];
37
+ bandCountWithNoData: number;
38
+ }
39
+
40
+ export interface DecodeOptions {
41
+ inputOffset?: number;
42
+ returnInterleaved?: boolean;
43
+ noDataValue?: number;
44
+ }
45
+
46
+ export interface LercData {
47
+ width: number;
48
+ height: number;
49
+ pixelType: LercPixelType;
50
+ statistics: BandStats[];
51
+ pixels: PixelTypedArray[];
52
+ mask: Uint8Array;
53
+ depthCount: number;
54
+ bandMasks?: Uint8Array[];
55
+ }
56
+
57
+ export function load(options?: { locateFile?: (wasmFileName?: string, scriptDir?: string) => string }): Promise<void>;
58
+ export function isLoaded(): boolean;
59
+ export function decode(input: ArrayBuffer | Uint8Array, options?: DecodeOptions): LercData;
60
+ export function getBlobInfo(input: ArrayBuffer | Uint8Array, options?: { inputOffset?: number }): LercHeaderInfo;
61
+ export function getBandCount(input: ArrayBuffer | Uint8Array, options?: { inputOffset?: number }): number;
@@ -0,0 +1,434 @@
1
+ /*! Lerc 4.0
2
+ Copyright 2015 - 2023 Esri
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
12
+ A local copy of the license and additional notices are located with the
13
+ source distribution at:
14
+ http://github.com/Esri/lerc/
15
+ Contributors: Thomas Maurer, Wenxue Ju
16
+ */
17
+
18
+ var Module = (() => {
19
+ var _scriptDir = import.meta.url;
20
+
21
+ return (
22
+ function(Module) {
23
+ Module = Module || {};
24
+
25
+ var Module=typeof Module!="undefined"?Module:{};var readyPromiseResolve,readyPromiseReject;Module["ready"]=new Promise(function(resolve,reject){readyPromiseResolve=resolve;readyPromiseReject=reject;});var moduleOverrides=Object.assign({},Module);var ENVIRONMENT_IS_WEB=typeof window=="object";var ENVIRONMENT_IS_WORKER=typeof importScripts=="function";var ENVIRONMENT_IS_NODE=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string";var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var read_,readAsync,readBinary;var fs;var nodePath;var requireNodeFS;if(ENVIRONMENT_IS_NODE){if(ENVIRONMENT_IS_WORKER){scriptDirectory=require("path").dirname(scriptDirectory)+"/";}else {scriptDirectory=__dirname+"/";}requireNodeFS=()=>{if(!nodePath){fs=require("fs");nodePath=require("path");}};read_=function shell_read(filename,binary){requireNodeFS();filename=nodePath["normalize"](filename);return fs.readFileSync(filename,binary?undefined:"utf8")};readBinary=filename=>{var ret=read_(filename,true);if(!ret.buffer){ret=new Uint8Array(ret);}return ret};readAsync=(filename,onload,onerror)=>{requireNodeFS();filename=nodePath["normalize"](filename);fs.readFile(filename,function(err,data){if(err)onerror(err);else onload(data.buffer);});};if(process["argv"].length>1){process["argv"][1].replace(/\\/g,"/");}process["argv"].slice(2);process["on"]("uncaughtException",function(ex){if(!(ex instanceof ExitStatus)){throw ex}});process["on"]("unhandledRejection",function(reason){throw reason});Module["inspect"]=function(){return "[Emscripten Module object]"};}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){if(ENVIRONMENT_IS_WORKER){scriptDirectory=self.location.href;}else if(typeof document!="undefined"&&document.currentScript){scriptDirectory=document.currentScript.src;}if(_scriptDir){scriptDirectory=_scriptDir;}if(scriptDirectory.indexOf("blob:")!==0){scriptDirectory=scriptDirectory.substr(0,scriptDirectory.replace(/[?#].*/,"").lastIndexOf("/")+1);}else {scriptDirectory="";}{read_=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.send(null);return xhr.responseText};if(ENVIRONMENT_IS_WORKER){readBinary=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)};}readAsync=(url,onload,onerror)=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=()=>{if(xhr.status==200||xhr.status==0&&xhr.response){onload(xhr.response);return}onerror();};xhr.onerror=onerror;xhr.send(null);};}}else;Module["print"]||console.log.bind(console);var err=Module["printErr"]||console.warn.bind(console);Object.assign(Module,moduleOverrides);moduleOverrides=null;if(Module["arguments"]);if(Module["thisProgram"]);if(Module["quit"]);var wasmBinary;if(Module["wasmBinary"])wasmBinary=Module["wasmBinary"];Module["noExitRuntime"]||true;if(typeof WebAssembly!="object"){abort("no native wasm support detected");}var wasmMemory;var ABORT=false;var UTF8Decoder=typeof TextDecoder!="undefined"?new TextDecoder("utf8"):undefined;function UTF8ArrayToString(heapOrArray,idx,maxBytesToRead){var endIdx=idx+maxBytesToRead;var endPtr=idx;while(heapOrArray[endPtr]&&!(endPtr>=endIdx))++endPtr;if(endPtr-idx>16&&heapOrArray.buffer&&UTF8Decoder){return UTF8Decoder.decode(heapOrArray.subarray(idx,endPtr))}else {var str="";while(idx<endPtr){var u0=heapOrArray[idx++];if(!(u0&128)){str+=String.fromCharCode(u0);continue}var u1=heapOrArray[idx++]&63;if((u0&224)==192){str+=String.fromCharCode((u0&31)<<6|u1);continue}var u2=heapOrArray[idx++]&63;if((u0&240)==224){u0=(u0&15)<<12|u1<<6|u2;}else {u0=(u0&7)<<18|u1<<12|u2<<6|heapOrArray[idx++]&63;}if(u0<65536){str+=String.fromCharCode(u0);}else {var ch=u0-65536;str+=String.fromCharCode(55296|ch>>10,56320|ch&1023);}}}return str}function UTF8ToString(ptr,maxBytesToRead){return ptr?UTF8ArrayToString(HEAPU8,ptr,maxBytesToRead):""}var buffer,HEAP8,HEAPU8,HEAP32,HEAPU32;function updateGlobalBufferAndViews(buf){buffer=buf;Module["HEAP8"]=HEAP8=new Int8Array(buf);Module["HEAP16"]=new Int16Array(buf);Module["HEAP32"]=HEAP32=new Int32Array(buf);Module["HEAPU8"]=HEAPU8=new Uint8Array(buf);Module["HEAPU16"]=new Uint16Array(buf);Module["HEAPU32"]=HEAPU32=new Uint32Array(buf);Module["HEAPF32"]=new Float32Array(buf);Module["HEAPF64"]=new Float64Array(buf);}Module["INITIAL_MEMORY"]||16777216;var wasmTable;var __ATPRERUN__=[];var __ATINIT__=[];var __ATPOSTRUN__=[];function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift());}}callRuntimeCallbacks(__ATPRERUN__);}function initRuntime(){callRuntimeCallbacks(__ATINIT__);}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift());}}callRuntimeCallbacks(__ATPOSTRUN__);}function addOnPreRun(cb){__ATPRERUN__.unshift(cb);}function addOnInit(cb){__ATINIT__.unshift(cb);}function addOnPostRun(cb){__ATPOSTRUN__.unshift(cb);}var runDependencies=0;var dependenciesFulfilled=null;function addRunDependency(id){runDependencies++;if(Module["monitorRunDependencies"]){Module["monitorRunDependencies"](runDependencies);}}function removeRunDependency(id){runDependencies--;if(Module["monitorRunDependencies"]){Module["monitorRunDependencies"](runDependencies);}if(runDependencies==0){if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback();}}}function abort(what){{if(Module["onAbort"]){Module["onAbort"](what);}}what="Aborted("+what+")";err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);readyPromiseReject(e);throw e}var dataURIPrefix="data:application/octet-stream;base64,";function isDataURI(filename){return filename.startsWith(dataURIPrefix)}function isFileURI(filename){return filename.startsWith("file://")}var wasmBinaryFile;if(Module["locateFile"]){wasmBinaryFile="lerc-wasm.wasm";if(!isDataURI(wasmBinaryFile)){wasmBinaryFile=locateFile(wasmBinaryFile);}}else {wasmBinaryFile=new URL("lerc-wasm.wasm",import.meta.url).toString();}function getBinary(file){try{if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}else {throw "both async and sync fetching of the wasm failed"}}catch(err){abort(err);}}function getBinaryPromise(){if(!wasmBinary&&(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER)){if(typeof fetch=="function"&&!isFileURI(wasmBinaryFile)){return fetch(wasmBinaryFile,{credentials:"same-origin"}).then(function(response){if(!response["ok"]){throw "failed to load wasm binary file at '"+wasmBinaryFile+"'"}return response["arrayBuffer"]()}).catch(function(){return getBinary(wasmBinaryFile)})}else {if(readAsync){return new Promise(function(resolve,reject){readAsync(wasmBinaryFile,function(response){resolve(new Uint8Array(response));},reject);})}}}return Promise.resolve().then(function(){return getBinary(wasmBinaryFile)})}function createWasm(){var info={"a":asmLibraryArg};function receiveInstance(instance,module){var exports=instance.exports;Module["asm"]=exports;wasmMemory=Module["asm"]["g"];updateGlobalBufferAndViews(wasmMemory.buffer);wasmTable=Module["asm"]["m"];addOnInit(Module["asm"]["h"]);removeRunDependency();}addRunDependency();function receiveInstantiationResult(result){receiveInstance(result["instance"]);}function instantiateArrayBuffer(receiver){return getBinaryPromise().then(function(binary){return WebAssembly.instantiate(binary,info)}).then(function(instance){return instance}).then(receiver,function(reason){err("failed to asynchronously prepare wasm: "+reason);abort(reason);})}function instantiateAsync(){if(!wasmBinary&&typeof WebAssembly.instantiateStreaming=="function"&&!isDataURI(wasmBinaryFile)&&!isFileURI(wasmBinaryFile)&&!ENVIRONMENT_IS_NODE&&typeof fetch=="function"){return fetch(wasmBinaryFile,{credentials:"same-origin"}).then(function(response){var result=WebAssembly.instantiateStreaming(response,info);return result.then(receiveInstantiationResult,function(reason){err("wasm streaming compile failed: "+reason);err("falling back to ArrayBuffer instantiation");return instantiateArrayBuffer(receiveInstantiationResult)})})}else {return instantiateArrayBuffer(receiveInstantiationResult)}}if(Module["instantiateWasm"]){try{var exports=Module["instantiateWasm"](info,receiveInstance);return exports}catch(e){err("Module.instantiateWasm callback failed with error: "+e);return false}}instantiateAsync().catch(readyPromiseReject);return {}}function callRuntimeCallbacks(callbacks){while(callbacks.length>0){var callback=callbacks.shift();if(typeof callback=="function"){callback(Module);continue}var func=callback.func;if(typeof func=="number"){if(callback.arg===undefined){getWasmTableEntry(func)();}else {getWasmTableEntry(func)(callback.arg);}}else {func(callback.arg===undefined?null:callback.arg);}}}var wasmTableMirror=[];function getWasmTableEntry(funcPtr){var func=wasmTableMirror[funcPtr];if(!func){if(funcPtr>=wasmTableMirror.length)wasmTableMirror.length=funcPtr+1;wasmTableMirror[funcPtr]=func=wasmTable.get(funcPtr);}return func}function ___assert_fail(condition,filename,line,func){abort("Assertion failed: "+UTF8ToString(condition)+", at: "+[filename?UTF8ToString(filename):"unknown filename",line,func?UTF8ToString(func):"unknown function"]);}function ___cxa_allocate_exception(size){return _malloc(size+24)+24}function ExceptionInfo(excPtr){this.excPtr=excPtr;this.ptr=excPtr-24;this.set_type=function(type){HEAPU32[this.ptr+4>>2]=type;};this.get_type=function(){return HEAPU32[this.ptr+4>>2]};this.set_destructor=function(destructor){HEAPU32[this.ptr+8>>2]=destructor;};this.get_destructor=function(){return HEAPU32[this.ptr+8>>2]};this.set_refcount=function(refcount){HEAP32[this.ptr>>2]=refcount;};this.set_caught=function(caught){caught=caught?1:0;HEAP8[this.ptr+12>>0]=caught;};this.get_caught=function(){return HEAP8[this.ptr+12>>0]!=0};this.set_rethrown=function(rethrown){rethrown=rethrown?1:0;HEAP8[this.ptr+13>>0]=rethrown;};this.get_rethrown=function(){return HEAP8[this.ptr+13>>0]!=0};this.init=function(type,destructor){this.set_adjusted_ptr(0);this.set_type(type);this.set_destructor(destructor);this.set_refcount(0);this.set_caught(false);this.set_rethrown(false);};this.add_ref=function(){var value=HEAP32[this.ptr>>2];HEAP32[this.ptr>>2]=value+1;};this.release_ref=function(){var prev=HEAP32[this.ptr>>2];HEAP32[this.ptr>>2]=prev-1;return prev===1};this.set_adjusted_ptr=function(adjustedPtr){HEAPU32[this.ptr+16>>2]=adjustedPtr;};this.get_adjusted_ptr=function(){return HEAPU32[this.ptr+16>>2]};this.get_exception_ptr=function(){var isPointer=___cxa_is_pointer_type(this.get_type());if(isPointer){return HEAPU32[this.excPtr>>2]}var adjusted=this.get_adjusted_ptr();if(adjusted!==0)return adjusted;return this.excPtr};}function ___cxa_throw(ptr,type,destructor){var info=new ExceptionInfo(ptr);info.init(type,destructor);throw ptr}function _abort(){abort("");}function _emscripten_memcpy_big(dest,src,num){HEAPU8.copyWithin(dest,src,src+num);}function getHeapMax(){return 2147483648}function emscripten_realloc_buffer(size){try{wasmMemory.grow(size-buffer.byteLength+65535>>>16);updateGlobalBufferAndViews(wasmMemory.buffer);return 1}catch(e){}}function _emscripten_resize_heap(requestedSize){var oldSize=HEAPU8.length;requestedSize=requestedSize>>>0;var maxHeapSize=getHeapMax();if(requestedSize>maxHeapSize){return false}let alignUp=(x,multiple)=>x+(multiple-x%multiple)%multiple;for(var cutDown=1;cutDown<=4;cutDown*=2){var overGrownHeapSize=oldSize*(1+.2/cutDown);overGrownHeapSize=Math.min(overGrownHeapSize,requestedSize+100663296);var newSize=Math.min(maxHeapSize,alignUp(Math.max(requestedSize,overGrownHeapSize),65536));var replacement=emscripten_realloc_buffer(newSize);if(replacement){return true}}return false}var asmLibraryArg={"a":___assert_fail,"c":___cxa_allocate_exception,"b":___cxa_throw,"d":_abort,"f":_emscripten_memcpy_big,"e":_emscripten_resize_heap};createWasm();Module["___wasm_call_ctors"]=function(){return (Module["___wasm_call_ctors"]=Module["asm"]["h"]).apply(null,arguments)};Module["_lerc_getBlobInfo"]=function(){return (Module["_lerc_getBlobInfo"]=Module["asm"]["i"]).apply(null,arguments)};Module["_lerc_getDataRanges"]=function(){return (Module["_lerc_getDataRanges"]=Module["asm"]["j"]).apply(null,arguments)};Module["_lerc_decode"]=function(){return (Module["_lerc_decode"]=Module["asm"]["k"]).apply(null,arguments)};Module["_lerc_decode_4D"]=function(){return (Module["_lerc_decode_4D"]=Module["asm"]["l"]).apply(null,arguments)};var _malloc=Module["_malloc"]=function(){return (_malloc=Module["_malloc"]=Module["asm"]["n"]).apply(null,arguments)};Module["_free"]=function(){return (Module["_free"]=Module["asm"]["o"]).apply(null,arguments)};var ___cxa_is_pointer_type=Module["___cxa_is_pointer_type"]=function(){return (___cxa_is_pointer_type=Module["___cxa_is_pointer_type"]=Module["asm"]["p"]).apply(null,arguments)};var calledRun;function ExitStatus(status){this.name="ExitStatus";this.message="Program terminated with exit("+status+")";this.status=status;}dependenciesFulfilled=function runCaller(){if(!calledRun)run();if(!calledRun)dependenciesFulfilled=runCaller;};function run(args){if(runDependencies>0){return}preRun();if(runDependencies>0){return}function doRun(){if(calledRun)return;calledRun=true;Module["calledRun"]=true;if(ABORT)return;initRuntime();readyPromiseResolve(Module);if(Module["onRuntimeInitialized"])Module["onRuntimeInitialized"]();postRun();}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(function(){setTimeout(function(){Module["setStatus"]("");},1);doRun();},1);}else {doRun();}}Module["run"]=run;if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].pop()();}}run();
26
+
27
+
28
+ return Module.ready
29
+ }
30
+ );
31
+ })();
32
+
33
+ const pixelTypeInfoMap = [
34
+ {
35
+ pixelType: "S8",
36
+ size: 1,
37
+ ctor: Int8Array,
38
+ range: [-128, 128]
39
+ },
40
+ {
41
+ pixelType: "U8",
42
+ size: 1,
43
+ ctor: Uint8Array,
44
+ range: [0, 255]
45
+ },
46
+ {
47
+ pixelType: "S16",
48
+ size: 2,
49
+ ctor: Int16Array,
50
+ range: [-32768, 32767]
51
+ },
52
+ {
53
+ pixelType: "U16",
54
+ size: 2,
55
+ ctor: Uint16Array,
56
+ range: [0, 65536]
57
+ },
58
+ {
59
+ pixelType: "S32",
60
+ size: 4,
61
+ ctor: Int32Array,
62
+ range: [-2147483648, 2147483647]
63
+ },
64
+ {
65
+ pixelType: "U32",
66
+ size: 4,
67
+ ctor: Uint32Array,
68
+ range: [0, 4294967296]
69
+ },
70
+ {
71
+ pixelType: "F32",
72
+ size: 4,
73
+ ctor: Float32Array,
74
+ range: [-3.4027999387901484e38, 3.4027999387901484e38]
75
+ },
76
+ {
77
+ pixelType: "F64",
78
+ size: 8,
79
+ ctor: Float64Array,
80
+ range: [-1.7976931348623157e308, 1.7976931348623157e308]
81
+ }
82
+ ];
83
+ let loadPromise = null;
84
+ let loaded = false;
85
+ function load(options = {}) {
86
+ if (loadPromise) {
87
+ return loadPromise;
88
+ }
89
+ const locateFile = options.locateFile || ((wasmFileName, scriptDir) => `${scriptDir}${wasmFileName}`);
90
+ loadPromise = Module({ locateFile }).then((lercFactory) => lercFactory.ready.then(() => {
91
+ initLercLib(lercFactory);
92
+ loaded = true;
93
+ }));
94
+ return loadPromise;
95
+ }
96
+ function isLoaded() {
97
+ return loaded;
98
+ }
99
+ const lercLib = {
100
+ getBlobInfo: null,
101
+ decode: null
102
+ };
103
+ function normalizeByteLength(n) {
104
+ // extra buffer on top of 8 byte boundary: https://stackoverflow.com/questions/56019003/why-malloc-in-webassembly-requires-4x-the-memory
105
+ return ((n >> 3) << 3) + 16;
106
+ }
107
+ function copyBytesFromWasm(wasmHeapU8, ptr_data, data) {
108
+ data.set(wasmHeapU8.slice(ptr_data, ptr_data + data.length));
109
+ }
110
+ function initLercLib(lercFactory) {
111
+ const { _malloc, _free, _lerc_getBlobInfo, _lerc_getDataRanges, _lerc_decode_4D, asm } = lercFactory;
112
+ // do not use HeapU8 as memory dynamically grows from the initial 16MB
113
+ // test case: landsat_6band_8bit.24
114
+ let heapU8;
115
+ const memory = Object.values(asm).find((val) => val && "buffer" in val && val.buffer === lercFactory.HEAPU8.buffer);
116
+ // avoid pointer for detached memory, malloc once:
117
+ const mallocMultiple = (byteLengths) => {
118
+ const lens = byteLengths.map((len) => normalizeByteLength(len));
119
+ const byteLength = lens.reduce((a, b) => a + b);
120
+ const ret = _malloc(byteLength);
121
+ heapU8 = new Uint8Array(memory.buffer);
122
+ let prev = lens[0];
123
+ lens[0] = ret;
124
+ // pointers for each allocated block
125
+ for (let i = 1; i < lens.length; i++) {
126
+ const next = lens[i];
127
+ lens[i] = lens[i - 1] + prev;
128
+ prev = next;
129
+ }
130
+ return lens;
131
+ };
132
+ lercLib.getBlobInfo = (blob) => {
133
+ // copy data to wasm. info: Uint32, range: F64
134
+ const infoArrSize = 12;
135
+ const rangeArrSize = 3;
136
+ const infoArr = new Uint8Array(infoArrSize * 4);
137
+ const rangeArr = new Uint8Array(rangeArrSize * 8);
138
+ const [ptr, ptr_info, ptr_range] = mallocMultiple([blob.length, infoArr.length, rangeArr.length]);
139
+ heapU8.set(blob, ptr);
140
+ heapU8.set(infoArr, ptr_info);
141
+ heapU8.set(rangeArr, ptr_range);
142
+ // decode
143
+ let hr = _lerc_getBlobInfo(ptr, blob.length, ptr_info, ptr_range, infoArrSize, rangeArrSize);
144
+ if (hr) {
145
+ _free(ptr);
146
+ throw `lerc-getBlobInfo: error code is ${hr}`;
147
+ }
148
+ heapU8 = new Uint8Array(memory.buffer);
149
+ copyBytesFromWasm(heapU8, ptr_info, infoArr);
150
+ copyBytesFromWasm(heapU8, ptr_range, rangeArr);
151
+ const lercInfoArr = new Uint32Array(infoArr.buffer);
152
+ const statsArr = new Float64Array(rangeArr.buffer);
153
+ // skip ndepth
154
+ const [version, dataType, dimCount, width, height, bandCount, validPixelCount, blobSize, maskCount, depthCount, bandCountWithNoData] = lercInfoArr;
155
+ const headerInfo = {
156
+ version,
157
+ dimCount,
158
+ width,
159
+ height,
160
+ validPixelCount,
161
+ bandCount,
162
+ blobSize,
163
+ maskCount,
164
+ depthCount,
165
+ dataType,
166
+ minValue: statsArr[0],
167
+ maxValue: statsArr[1],
168
+ maxZerror: statsArr[2],
169
+ statistics: [],
170
+ bandCountWithNoData
171
+ };
172
+ if (bandCountWithNoData) {
173
+ _free(ptr);
174
+ return headerInfo;
175
+ }
176
+ if (depthCount === 1 && bandCount === 1) {
177
+ _free(ptr);
178
+ headerInfo.statistics.push({
179
+ minValue: statsArr[0],
180
+ maxValue: statsArr[1]
181
+ });
182
+ return headerInfo;
183
+ }
184
+ // get data ranges for nband / ndim blob
185
+ // to reuse blob ptr we need to handle dynamic memory allocation
186
+ const numStatsBytes = depthCount * bandCount * 8;
187
+ const bandStatsMinArr = new Uint8Array(numStatsBytes);
188
+ const bandStatsMaxArr = new Uint8Array(numStatsBytes);
189
+ let ptr_blob = ptr, ptr_min = 0, ptr_max = 0, blob_freed = false;
190
+ if (heapU8.byteLength < ptr + numStatsBytes * 2) {
191
+ _free(ptr);
192
+ blob_freed = true;
193
+ [ptr_blob, ptr_min, ptr_max] = mallocMultiple([blob.length, numStatsBytes, numStatsBytes]);
194
+ heapU8.set(blob, ptr_blob);
195
+ }
196
+ else {
197
+ [ptr_min, ptr_max] = mallocMultiple([numStatsBytes, numStatsBytes]);
198
+ }
199
+ heapU8.set(bandStatsMinArr, ptr_min);
200
+ heapU8.set(bandStatsMaxArr, ptr_max);
201
+ hr = _lerc_getDataRanges(ptr_blob, blob.length, depthCount, bandCount, ptr_min, ptr_max);
202
+ if (hr) {
203
+ _free(ptr_blob);
204
+ if (!blob_freed) {
205
+ // we have two pointers in two wasm function calls
206
+ _free(ptr_min);
207
+ }
208
+ throw `lerc-getDataRanges: error code is ${hr}`;
209
+ }
210
+ heapU8 = new Uint8Array(memory.buffer);
211
+ copyBytesFromWasm(heapU8, ptr_min, bandStatsMinArr);
212
+ copyBytesFromWasm(heapU8, ptr_max, bandStatsMaxArr);
213
+ const allMinValues = new Float64Array(bandStatsMinArr.buffer);
214
+ const allMaxValues = new Float64Array(bandStatsMaxArr.buffer);
215
+ const statistics = headerInfo.statistics;
216
+ for (let i = 0; i < bandCount; i++) {
217
+ if (depthCount > 1) {
218
+ const minValues = allMinValues.slice(i * depthCount, (i + 1) * depthCount);
219
+ const maxValues = allMaxValues.slice(i * depthCount, (i + 1) * depthCount);
220
+ const minValue = Math.min.apply(null, minValues);
221
+ const maxValue = Math.max.apply(null, maxValues);
222
+ statistics.push({
223
+ minValue,
224
+ maxValue,
225
+ dimStats: { minValues, maxValues },
226
+ depthStats: { minValues, maxValues }
227
+ });
228
+ }
229
+ else {
230
+ statistics.push({
231
+ minValue: allMinValues[i],
232
+ maxValue: allMaxValues[i]
233
+ });
234
+ }
235
+ }
236
+ _free(ptr_blob);
237
+ if (!blob_freed) {
238
+ // we have two pointers in two wasm function calls
239
+ _free(ptr_min);
240
+ }
241
+ return headerInfo;
242
+ };
243
+ lercLib.decode = (blob, blobInfo) => {
244
+ const { maskCount, depthCount, bandCount, width, height, dataType, bandCountWithNoData } = blobInfo;
245
+ // if the heap is increased dynamically between raw data, mask, and data, the malloc pointer is invalid as it will raise error when accessing mask:
246
+ // Cannot perform %TypedArray%.prototype.slice on a detached ArrayBuffer
247
+ const pixelTypeInfo = pixelTypeInfoMap[dataType];
248
+ const numPixels = width * height;
249
+ const maskData = new Uint8Array(numPixels * bandCount);
250
+ const numDataBytes = numPixels * depthCount * bandCount * pixelTypeInfo.size;
251
+ const data = new Uint8Array(numDataBytes);
252
+ const useNoDataArr = new Uint8Array(bandCount);
253
+ const noDataArr = new Uint8Array(bandCount * 8);
254
+ const [ptr, ptr_mask, ptr_data, ptr_useNoData, ptr_noData] = mallocMultiple([
255
+ blob.length,
256
+ maskData.length,
257
+ data.length,
258
+ useNoDataArr.length,
259
+ noDataArr.length
260
+ ]);
261
+ heapU8.set(blob, ptr);
262
+ heapU8.set(maskData, ptr_mask);
263
+ heapU8.set(data, ptr_data);
264
+ heapU8.set(useNoDataArr, ptr_useNoData);
265
+ heapU8.set(noDataArr, ptr_noData);
266
+ const hr = _lerc_decode_4D(ptr, blob.length, maskCount, ptr_mask, depthCount, width, height, bandCount, dataType, ptr_data, ptr_useNoData, ptr_noData);
267
+ if (hr) {
268
+ _free(ptr);
269
+ throw `lerc-decode: error code is ${hr}`;
270
+ }
271
+ heapU8 = new Uint8Array(memory.buffer);
272
+ copyBytesFromWasm(heapU8, ptr_data, data);
273
+ copyBytesFromWasm(heapU8, ptr_mask, maskData);
274
+ let noDataValues = null;
275
+ if (bandCountWithNoData) {
276
+ copyBytesFromWasm(heapU8, ptr_useNoData, useNoDataArr);
277
+ copyBytesFromWasm(heapU8, ptr_noData, noDataArr);
278
+ noDataValues = [];
279
+ const noDataArr64 = new Float64Array(noDataArr.buffer);
280
+ for (let i = 0; i < useNoDataArr.length; i++) {
281
+ noDataValues.push(useNoDataArr[i] ? noDataArr64[i] : null);
282
+ }
283
+ }
284
+ _free(ptr);
285
+ return {
286
+ data,
287
+ maskData,
288
+ noDataValues
289
+ };
290
+ };
291
+ }
292
+ function swapDepthValuesOrder(pixels, numPixels, depthCount, OutPixelTypeArray, inputIsBIP) {
293
+ if (depthCount < 2) {
294
+ return pixels;
295
+ }
296
+ const swap = new OutPixelTypeArray(numPixels * depthCount);
297
+ if (inputIsBIP) {
298
+ for (let i = 0, j = 0; i < numPixels; i++) {
299
+ for (let iDim = 0, temp = i; iDim < depthCount; iDim++, temp += numPixels) {
300
+ swap[temp] = pixels[j++];
301
+ }
302
+ }
303
+ }
304
+ else {
305
+ for (let i = 0, j = 0; i < numPixels; i++) {
306
+ for (let iDim = 0, temp = i; iDim < depthCount; iDim++, temp += numPixels) {
307
+ swap[j++] = pixels[temp];
308
+ }
309
+ }
310
+ }
311
+ return swap;
312
+ }
313
+ /**
314
+ * Decoding a LERC1/LERC2 byte stream and return an object containing the pixel data.
315
+ *
316
+ * @alias module:Lerc
317
+ * @param {ArrayBuffer | Uint8Array} input The LERC input byte stream
318
+ * @param {object} [options] The decoding options below are optional.
319
+ * @param {number} [options.inputOffset] The number of bytes to skip in the input byte stream. A valid Lerc file is expected at that position.
320
+ * @param {number} [options.noDataValue] It is recommended to use the returned mask instead of setting this value.
321
+ * @param {boolean} [options.returnInterleaved] (ndepth LERC2 only) If true, returned depth values are pixel-interleaved, a.k.a [p1_dep1, p1_dep2, ..., p1_depN, p2_dep1...], default is [p1_dep1, p2_dep1, ..., p1_dep2, p2_dep2...]
322
+ * @returns {{width, height, pixels, pixelType, mask, statistics}}
323
+ * @property {number} width Width of decoded image.
324
+ * @property {number} height Height of decoded image.
325
+ * @property {number} depthCount Depth count.
326
+ * @property {array} pixels [band1, band2, …] Each band is a typed array of width*height*depthCount.
327
+ * @property {string} pixelType The type of pixels represented in the output: U8/S8/S16/U16/S32/U32/F32.
328
+ * @property {mask} mask Typed array with a size of width*height, or null if all pixels are valid.
329
+ * @property {array} statistics [statistics_band1, statistics_band2, …] Each element is a statistics object representing min and max values
330
+ * @property {array} [bandMasks] [band1_mask, band2_mask, …] Each band is a Uint8Array of width * height * depthCount.
331
+ **/
332
+ function decode(input, options = {}) {
333
+ var _a, _b;
334
+ // get blob info
335
+ const inputOffset = (_a = options.inputOffset) !== null && _a !== void 0 ? _a : 0;
336
+ const blob = input instanceof Uint8Array ? input.subarray(inputOffset) : new Uint8Array(input, inputOffset);
337
+ const blobInfo = lercLib.getBlobInfo(blob);
338
+ // decode
339
+ const { data, maskData } = lercLib.decode(blob, blobInfo);
340
+ const { width, height, bandCount, dimCount, depthCount, dataType, maskCount, statistics } = blobInfo;
341
+ // get pixels, per-band masks, and statistics
342
+ const pixelTypeInfo = pixelTypeInfoMap[dataType];
343
+ const data1 = new pixelTypeInfo.ctor(data.buffer);
344
+ const pixels = [];
345
+ const masks = [];
346
+ const numPixels = width * height;
347
+ const numElementsPerBand = numPixels * depthCount;
348
+ // options.returnPixelInterleavedDims will be removed in next release
349
+ const swap = (_b = options.returnInterleaved) !== null && _b !== void 0 ? _b : options.returnPixelInterleavedDims;
350
+ for (let i = 0; i < bandCount; i++) {
351
+ const band = data1.subarray(i * numElementsPerBand, (i + 1) * numElementsPerBand);
352
+ if (swap) {
353
+ pixels.push(band);
354
+ }
355
+ else {
356
+ const bsq = swapDepthValuesOrder(band, numPixels, depthCount, pixelTypeInfo.ctor, true);
357
+ pixels.push(bsq);
358
+ }
359
+ masks.push(maskData.subarray(i * numElementsPerBand, (i + 1) * numElementsPerBand));
360
+ }
361
+ // get unified mask
362
+ const mask = maskCount === 0 ? null : maskCount === 1 ? masks[0] : new Uint8Array(numPixels);
363
+ if (maskCount > 1) {
364
+ mask.set(masks[0]);
365
+ for (let i = 1; i < masks.length; i++) {
366
+ const bandMask = masks[i];
367
+ for (let j = 0; j < numPixels; j++) {
368
+ mask[j] = mask[j] & bandMask[j];
369
+ }
370
+ }
371
+ }
372
+ // apply no data value
373
+ const { noDataValue } = options;
374
+ const applyNoDataValue = noDataValue != null && pixelTypeInfo.range[0] <= noDataValue && pixelTypeInfo.range[1] >= noDataValue;
375
+ if (maskCount > 0 && applyNoDataValue) {
376
+ for (let i = 0; i < bandCount; i++) {
377
+ const band = pixels[i];
378
+ const bandMask = masks[i] || mask;
379
+ for (let j = 0; j < numPixels; j++) {
380
+ if (bandMask[j] === 0) {
381
+ band[j] = noDataValue;
382
+ }
383
+ }
384
+ }
385
+ }
386
+ // only keep band masks when there's per-band unique mask
387
+ const bandMasks = maskCount === bandCount && bandCount > 1 ? masks : null;
388
+ const { pixelType } = pixelTypeInfo;
389
+ return {
390
+ width,
391
+ height,
392
+ pixelType,
393
+ statistics,
394
+ pixels,
395
+ mask,
396
+ dimCount,
397
+ depthCount,
398
+ bandMasks
399
+ };
400
+ }
401
+ /**
402
+ * Get the header information of a LERC1/LERC2 byte stream.
403
+ *
404
+ * @alias module:Lerc
405
+ * @param {ArrayBuffer | Uint8Array} input The LERC input byte stream
406
+ * @param {object} [options] The decoding options below are optional.
407
+ * @param {number} [options.inputOffset] The number of bytes to skip in the input byte stream. A valid Lerc file is expected at that position.
408
+ * @returns {{version, width, height, bandCount, dimCount, validPixelCount, blobSize, dataType, mask, minValue, maxValue, maxZerror, statistics}}
409
+ * @property {number} version Compression algorithm version.
410
+ * @property {number} width Width of decoded image.
411
+ * @property {number} height Height of decoded image.
412
+ * @property {number} bandCount Number of bands.
413
+ * @property {number} depthCount Depth count.
414
+ * @property {number} validPixelCount Number of valid pixels.
415
+ * @property {number} blobSize Lerc blob size in bytes.
416
+ * @property {number} dataType Data type represented in number.
417
+ * @property {number} minValue Minimum pixel value.
418
+ * @property {number} maxValue Maximum pixel value.
419
+ * @property {number} maxZerror Maximum Z error.
420
+ * @property {array} statistics [statistics_band1, statistics_band2, …] Each element is a statistics object representing min and max values
421
+ **/
422
+ function getBlobInfo(input, options = {}) {
423
+ var _a;
424
+ const inputOffset = (_a = options.inputOffset) !== null && _a !== void 0 ? _a : 0;
425
+ const blob = input instanceof Uint8Array ? input.subarray(inputOffset) : new Uint8Array(input, inputOffset);
426
+ return lercLib.getBlobInfo(blob);
427
+ }
428
+ function getBandCount(input, options = {}) {
429
+ // this was available in the old JS version but not documented. Keep as is for backward compatibility.
430
+ const info = getBlobInfo(input, options);
431
+ return info.bandCount;
432
+ }
433
+
434
+ export { decode, getBandCount, getBlobInfo, isLoaded, load };