LercWorker-ISXTXRV5.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import {
  2. j2 as j
  3. } from "./chunk-XNLG7T2T.js";
  4. import "./chunk-IR4PV7VK.js";
  5. import "./chunk-A5ICIBVI.js";
  6. // node_modules/@arcgis/core/layers/support/LercWorker.js
  7. var t = {};
  8. t.defaultNoDataValue = j(-1 / 0), t.decode = function(s2, r2) {
  9. var o2 = (r2 = r2 || {}).encodedMaskData || r2.encodedMaskData === null, f2 = l(s2, r2.inputOffset || 0, o2), u = r2.noDataValue != null ? j(r2.noDataValue) : t.defaultNoDataValue, m = i(f2, r2.pixelType || Float32Array, r2.encodedMaskData, u, r2.returnMask), d = { width: f2.width, height: f2.height, pixelData: m.resultPixels, minValue: f2.pixels.minValue, maxValue: f2.pixels.maxValue, noDataValue: u };
  10. return m.resultMask && (d.maskData = m.resultMask), r2.returnEncodedMask && f2.mask && (d.encodedMaskData = f2.mask.bitset ? f2.mask.bitset : null), r2.returnFileInfo && (d.fileInfo = n(f2, u), r2.computeUsedBitDepths && (d.fileInfo.bitDepths = a(f2))), d;
  11. };
  12. var i = function(e, t2, i2, n2, a2) {
  13. var l2, r2, o2 = 0, f2 = e.pixels.numBlocksX, u = e.pixels.numBlocksY, m = Math.floor(e.width / f2), d = Math.floor(e.height / u), c = 2 * e.maxZError;
  14. i2 = i2 || (e.mask ? e.mask.bitset : null), l2 = new t2(e.width * e.height), a2 && i2 && (r2 = new Uint8Array(e.width * e.height));
  15. for (var g, h, k = new Float32Array(m * d), x = 0; x <= u; x++) {
  16. var p = x !== u ? d : e.height % u;
  17. if (p !== 0)
  18. for (var w = 0; w <= f2; w++) {
  19. var y = w !== f2 ? m : e.width % f2;
  20. if (y !== 0) {
  21. var V, B, v, U, D = x * e.width * d + w * m, M = e.width - y, b = e.pixels.blocks[o2];
  22. if (b.encoding < 2 ? (b.encoding === 0 ? V = b.rawData : (s(b.stuffedData, b.bitsPerPixel, b.numValidPixels, b.offset, c, k, e.pixels.maxValue), V = k), B = 0) : v = b.encoding === 2 ? 0 : b.offset, i2)
  23. for (h = 0; h < p; h++) {
  24. for (7 & D && (U = i2[D >> 3], U <<= 7 & D), g = 0; g < y; g++)
  25. 7 & D || (U = i2[D >> 3]), 128 & U ? (r2 && (r2[D] = 1), l2[D++] = b.encoding < 2 ? V[B++] : v) : (r2 && (r2[D] = 0), l2[D++] = n2), U <<= 1;
  26. D += M;
  27. }
  28. else if (b.encoding < 2)
  29. for (h = 0; h < p; h++) {
  30. for (g = 0; g < y; g++)
  31. l2[D++] = V[B++];
  32. D += M;
  33. }
  34. else
  35. for (h = 0; h < p; h++)
  36. if (l2.fill)
  37. l2.fill(v, D, D + y), D += y + M;
  38. else {
  39. for (g = 0; g < y; g++)
  40. l2[D++] = v;
  41. D += M;
  42. }
  43. if (b.encoding === 1 && B !== b.numValidPixels)
  44. throw "Block and Mask do not match";
  45. o2++;
  46. }
  47. }
  48. }
  49. return { resultPixels: l2, resultMask: r2 };
  50. };
  51. var n = function(e, t2) {
  52. return { fileIdentifierString: e.fileIdentifierString, fileVersion: e.fileVersion, imageType: e.imageType, height: e.height, width: e.width, maxZError: e.maxZError, eofOffset: e.eofOffset, mask: e.mask ? { numBlocksX: e.mask.numBlocksX, numBlocksY: e.mask.numBlocksY, numBytes: e.mask.numBytes, maxValue: e.mask.maxValue } : null, pixels: { numBlocksX: e.pixels.numBlocksX, numBlocksY: e.pixels.numBlocksY, numBytes: e.pixels.numBytes, maxValue: e.pixels.maxValue, minValue: e.pixels.minValue, noDataValue: t2 } };
  53. };
  54. var a = function(e) {
  55. for (var t2 = e.pixels.numBlocksX * e.pixels.numBlocksY, i2 = {}, n2 = 0; n2 < t2; n2++) {
  56. var a2 = e.pixels.blocks[n2];
  57. a2.encoding === 0 ? i2.float32 = true : a2.encoding === 1 ? i2[a2.bitsPerPixel] = true : i2[0] = true;
  58. }
  59. return Object.keys(i2);
  60. };
  61. var l = function(e, t2, i2) {
  62. var n2 = {}, a2 = new Uint8Array(e, t2, 10);
  63. if (n2.fileIdentifierString = String.fromCharCode.apply(null, a2), n2.fileIdentifierString.trim() != "CntZImage")
  64. throw "Unexpected file identifier string: " + n2.fileIdentifierString;
  65. t2 += 10;
  66. var l2 = new DataView(e, t2, 24);
  67. if (n2.fileVersion = l2.getInt32(0, true), n2.imageType = l2.getInt32(4, true), n2.height = l2.getUint32(8, true), n2.width = l2.getUint32(12, true), n2.maxZError = l2.getFloat64(16, true), t2 += 24, !i2) {
  68. if (l2 = new DataView(e, t2, 16), n2.mask = {}, n2.mask.numBlocksY = l2.getUint32(0, true), n2.mask.numBlocksX = l2.getUint32(4, true), n2.mask.numBytes = l2.getUint32(8, true), n2.mask.maxValue = l2.getFloat32(12, true), t2 += 16, n2.mask.numBytes > 0) {
  69. var s2 = new Uint8Array(Math.ceil(n2.width * n2.height / 8)), r2 = (l2 = new DataView(e, t2, n2.mask.numBytes)).getInt16(0, true), o2 = 2, f2 = 0;
  70. do {
  71. if (r2 > 0)
  72. for (; r2--; )
  73. s2[f2++] = l2.getUint8(o2++);
  74. else {
  75. var u = l2.getUint8(o2++);
  76. for (r2 = -r2; r2--; )
  77. s2[f2++] = u;
  78. }
  79. r2 = l2.getInt16(o2, true), o2 += 2;
  80. } while (o2 < n2.mask.numBytes);
  81. if (r2 !== -32768 || f2 < s2.length)
  82. throw "Unexpected end of mask RLE encoding";
  83. n2.mask.bitset = s2, t2 += n2.mask.numBytes;
  84. } else if ((n2.mask.numBytes | n2.mask.numBlocksY | n2.mask.maxValue) == 0) {
  85. s2 = new Uint8Array(Math.ceil(n2.width * n2.height / 8));
  86. n2.mask.bitset = s2;
  87. }
  88. }
  89. l2 = new DataView(e, t2, 16), n2.pixels = {}, n2.pixels.numBlocksY = l2.getUint32(0, true), n2.pixels.numBlocksX = l2.getUint32(4, true), n2.pixels.numBytes = l2.getUint32(8, true), n2.pixels.maxValue = l2.getFloat32(12, true), t2 += 16;
  90. var m = n2.pixels.numBlocksX, d = n2.pixels.numBlocksY, c = m + (n2.width % m > 0 ? 1 : 0), g = d + (n2.height % d > 0 ? 1 : 0);
  91. n2.pixels.blocks = new Array(c * g);
  92. for (var h = 1e9, k = 0, x = 0; x < g; x++)
  93. for (var p = 0; p < c; p++) {
  94. var w = 0, y = e.byteLength - t2;
  95. l2 = new DataView(e, t2, Math.min(10, y));
  96. var V = {};
  97. n2.pixels.blocks[k++] = V;
  98. var B = l2.getUint8(0);
  99. if (w++, V.encoding = 63 & B, V.encoding > 3)
  100. throw "Invalid block encoding (" + V.encoding + ")";
  101. if (V.encoding !== 2) {
  102. if (B !== 0 && B !== 2) {
  103. if (B >>= 6, V.offsetType = B, B === 2)
  104. V.offset = l2.getInt8(1), w++;
  105. else if (B === 1)
  106. V.offset = l2.getInt16(1, true), w += 2;
  107. else {
  108. if (B !== 0)
  109. throw "Invalid block offset type";
  110. V.offset = l2.getFloat32(1, true), w += 4;
  111. }
  112. if (h = Math.min(V.offset, h), V.encoding === 1)
  113. if (B = l2.getUint8(w), w++, V.bitsPerPixel = 63 & B, B >>= 6, V.numValidPixelsType = B, B === 2)
  114. V.numValidPixels = l2.getUint8(w), w++;
  115. else if (B === 1)
  116. V.numValidPixels = l2.getUint16(w, true), w += 2;
  117. else {
  118. if (B !== 0)
  119. throw "Invalid valid pixel count type";
  120. V.numValidPixels = l2.getUint32(w, true), w += 4;
  121. }
  122. }
  123. var v;
  124. if (t2 += w, V.encoding != 3) {
  125. if (V.encoding === 0) {
  126. var U = (n2.pixels.numBytes - 1) / 4;
  127. if (U !== Math.floor(U))
  128. throw "uncompressed block has invalid length";
  129. v = new ArrayBuffer(4 * U), new Uint8Array(v).set(new Uint8Array(e, t2, 4 * U));
  130. for (var D = new Float32Array(v), M = 0; M < D.length; M++)
  131. h = Math.min(h, D[M]);
  132. V.rawData = D, t2 += 4 * U;
  133. } else if (V.encoding === 1) {
  134. var b = Math.ceil(V.numValidPixels * V.bitsPerPixel / 8), I = Math.ceil(b / 4);
  135. v = new ArrayBuffer(4 * I), new Uint8Array(v).set(new Uint8Array(e, t2, b)), V.stuffedData = new Uint32Array(v), t2 += b;
  136. }
  137. }
  138. } else
  139. t2++, h = Math.min(h, 0);
  140. }
  141. return n2.pixels.minValue = h, n2.eofOffset = t2, n2;
  142. };
  143. var s = function(e, t2, i2, n2, a2, l2, s2) {
  144. var r2, o2, f2, u = (1 << t2) - 1, m = 0, d = 0, c = Math.ceil((s2 - n2) / a2), g = 4 * e.length - Math.ceil(t2 * i2 / 8);
  145. for (e[e.length - 1] <<= 8 * g, r2 = 0; r2 < i2; r2++) {
  146. if (d === 0 && (f2 = e[m++], d = 32), d >= t2)
  147. o2 = f2 >>> d - t2 & u, d -= t2;
  148. else {
  149. var h = t2 - d;
  150. o2 = (f2 & u) << h & u, o2 += (f2 = e[m++]) >>> (d = 32 - h);
  151. }
  152. l2[r2] = o2 < c ? n2 + o2 * a2 : s2;
  153. }
  154. return l2;
  155. };
  156. var r = t.decode;
  157. var o = class {
  158. _decode(e) {
  159. const t2 = r(e.buffer, e.options);
  160. return Promise.resolve({ result: t2, transferList: [t2.pixelData.buffer] });
  161. }
  162. };
  163. function f() {
  164. return new o();
  165. }
  166. export {
  167. f as default
  168. };
  169. //# sourceMappingURL=LercWorker-ISXTXRV5.js.map