@geoql/v-maplibre 1.5.0 → 1.6.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.
- package/README.md +6 -2
- package/dist/controls/_shared/index.d.ts +1 -0
- package/dist/controls/_shared/useMapControl.d.ts +10 -0
- package/dist/controls/index.d.ts +6 -0
- package/dist/controls/layer/VControlLayer.vue.d.ts +38 -0
- package/dist/controls/layer/VControlLayerGroup.vue.d.ts +53 -0
- package/dist/controls/layer/events.d.ts +1 -0
- package/dist/controls/layer/index.d.ts +5 -0
- package/dist/controls/layer/types.d.ts +16 -0
- package/dist/controls/legend/VControlLegend.vue.d.ts +54 -0
- package/dist/controls/legend/events.d.ts +2 -0
- package/dist/controls/legend/index.d.ts +3 -0
- package/dist/controls/legend/types.d.ts +63 -0
- package/dist/decoder-CLokFc0V.js +9 -0
- package/dist/decoder-CLokFc0V.js.map +1 -0
- package/dist/deflate-yeu3ogBn.js +11 -0
- package/dist/deflate-yeu3ogBn.js.map +1 -0
- package/dist/geotiff-BUZniE5g.js +3106 -0
- package/dist/geotiff-BUZniE5g.js.map +1 -0
- package/dist/index-Bt_rREAc.js +168 -0
- package/dist/index-Bt_rREAc.js.map +1 -0
- package/dist/index-CA8I5Z2-.js +4667 -0
- package/dist/index-CA8I5Z2-.js.map +1 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2736 -1638
- package/dist/index.js.map +1 -1
- package/dist/jpeg-B7yImnpY.js +534 -0
- package/dist/jpeg-B7yImnpY.js.map +1 -0
- package/dist/layers/deckgl/_shared/useDeckOverlay.d.ts +2 -0
- package/dist/layers/deckgl/index.d.ts +2 -0
- package/dist/layers/deckgl/mosaic/VLayerDeckglMosaic.vue.d.ts +163 -0
- package/dist/layers/deckgl/mosaic/index.d.ts +2 -0
- package/dist/layers/deckgl/text/VLayerDeckglText.vue.d.ts +1 -1
- package/dist/layers/deckgl/wind-particle/VLayerDeckglWindParticle.vue.d.ts +1 -1
- package/dist/layers/index.d.ts +3 -2
- package/dist/layers/maplibre/canvas/VLayerMaplibreCanvas.vue.d.ts +1 -1
- package/dist/layers/maplibre/custom/isochrone/VLayerMaplibreIsochrone.vue.d.ts +71 -0
- package/dist/layers/maplibre/custom/isochrone/index.d.ts +1 -0
- package/dist/layers/maplibre/geojson/VLayerMaplibreGeojson.vue.d.ts +1 -1
- package/dist/layers/maplibre/image/VLayerMaplibreImage.vue.d.ts +1 -1
- package/dist/layers/maplibre/pmtile/VLayerMaplibrePmtile.vue.d.ts +1 -1
- package/dist/layers/maplibre/video/VLayerMaplibreVideo.vue.d.ts +1 -1
- package/dist/lerc-CqgA9njy.js +1032 -0
- package/dist/lerc-CqgA9njy.js.map +1 -0
- package/dist/lzw-DL9RcHOz.js +85 -0
- package/dist/lzw-DL9RcHOz.js.map +1 -0
- package/dist/markers/VMarker.vue.d.ts +1 -2
- package/dist/packbits-YEJGULcy.js +25 -0
- package/dist/packbits-YEJGULcy.js.map +1 -0
- package/dist/pako.esm-Bx5X36Wo.js +1075 -0
- package/dist/pako.esm-Bx5X36Wo.js.map +1 -0
- package/dist/popups/VPopup.vue.d.ts +1 -1
- package/dist/raw-CoQHiEnn.js +10 -0
- package/dist/raw-CoQHiEnn.js.map +1 -0
- package/dist/v-maplibre.css +1 -1
- package/dist/webimage-BXLN-zu8.js +20 -0
- package/dist/webimage-BXLN-zu8.js.map +1 -0
- package/package.json +100 -84
- package/dist/layers/maplibre/{cluster → custom/cluster}/VLayerMaplibreCluster.vue.d.ts +1 -1
- package/dist/layers/maplibre/{cluster → custom/cluster}/index.d.ts +0 -0
- package/dist/layers/maplibre/{route → custom/route}/VLayerMaplibreRoute.vue.d.ts +2 -2
- /package/dist/layers/maplibre/{route → custom/route}/index.d.ts +0 -0
|
@@ -0,0 +1,3106 @@
|
|
|
1
|
+
function T(r) {
|
|
2
|
+
return (e, ...t) => Et(r, e, t);
|
|
3
|
+
}
|
|
4
|
+
function z(r, e) {
|
|
5
|
+
return T(
|
|
6
|
+
Ve(
|
|
7
|
+
r,
|
|
8
|
+
e
|
|
9
|
+
).get
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
const {
|
|
13
|
+
apply: Et,
|
|
14
|
+
getOwnPropertyDescriptor: Ve,
|
|
15
|
+
getPrototypeOf: De,
|
|
16
|
+
ownKeys: Pt
|
|
17
|
+
} = Reflect, {
|
|
18
|
+
iterator: J,
|
|
19
|
+
toStringTag: Ct
|
|
20
|
+
} = Symbol, Ft = Object, {
|
|
21
|
+
create: Oe,
|
|
22
|
+
defineProperty: kt
|
|
23
|
+
} = Ft, Rt = Array, Bt = Rt.prototype, je = Bt[J], Mt = T(je), He = ArrayBuffer, Gt = He.prototype;
|
|
24
|
+
z(Gt, "byteLength");
|
|
25
|
+
const Ge = typeof SharedArrayBuffer < "u" ? SharedArrayBuffer : null;
|
|
26
|
+
Ge && z(Ge.prototype, "byteLength");
|
|
27
|
+
const Ye = De(Uint8Array);
|
|
28
|
+
Ye.from;
|
|
29
|
+
const O = Ye.prototype;
|
|
30
|
+
O[J];
|
|
31
|
+
T(O.keys);
|
|
32
|
+
T(
|
|
33
|
+
O.values
|
|
34
|
+
);
|
|
35
|
+
T(
|
|
36
|
+
O.entries
|
|
37
|
+
);
|
|
38
|
+
T(O.set);
|
|
39
|
+
T(
|
|
40
|
+
O.reverse
|
|
41
|
+
);
|
|
42
|
+
T(O.fill);
|
|
43
|
+
T(
|
|
44
|
+
O.copyWithin
|
|
45
|
+
);
|
|
46
|
+
T(O.sort);
|
|
47
|
+
T(O.slice);
|
|
48
|
+
T(
|
|
49
|
+
O.subarray
|
|
50
|
+
);
|
|
51
|
+
z(
|
|
52
|
+
O,
|
|
53
|
+
"buffer"
|
|
54
|
+
);
|
|
55
|
+
z(
|
|
56
|
+
O,
|
|
57
|
+
"byteOffset"
|
|
58
|
+
);
|
|
59
|
+
z(
|
|
60
|
+
O,
|
|
61
|
+
"length"
|
|
62
|
+
);
|
|
63
|
+
z(
|
|
64
|
+
O,
|
|
65
|
+
Ct
|
|
66
|
+
);
|
|
67
|
+
const Ut = Uint8Array, $e = Uint16Array, Ee = Uint32Array, _t = Float32Array, Z = De([][J]()), Xe = T(Z.next), vt = T((function* () {
|
|
68
|
+
})().next), Lt = De(Z), Nt = DataView.prototype, Kt = T(
|
|
69
|
+
Nt.getUint16
|
|
70
|
+
), Pe = WeakMap, Ze = Pe.prototype, Je = T(Ze.get), zt = T(Ze.set), Qe = new Pe(), qt = Oe(null, {
|
|
71
|
+
next: {
|
|
72
|
+
value: function() {
|
|
73
|
+
const e = Je(Qe, this);
|
|
74
|
+
return Xe(e);
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
[J]: {
|
|
78
|
+
value: function() {
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
function Vt(r) {
|
|
84
|
+
if (r[J] === je && Z.next === Xe)
|
|
85
|
+
return r;
|
|
86
|
+
const e = Oe(qt);
|
|
87
|
+
return zt(Qe, e, Mt(r)), e;
|
|
88
|
+
}
|
|
89
|
+
const jt = new Pe(), Ht = Oe(Lt, {
|
|
90
|
+
next: {
|
|
91
|
+
value: function() {
|
|
92
|
+
const e = Je(jt, this);
|
|
93
|
+
return vt(e);
|
|
94
|
+
},
|
|
95
|
+
writable: !0,
|
|
96
|
+
configurable: !0
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
for (const r of Pt(Z))
|
|
100
|
+
r !== "next" && kt(Ht, r, Ve(Z, r));
|
|
101
|
+
const We = new He(4), Yt = new _t(We), $t = new Ee(We), R = new $e(512), B = new Ut(512);
|
|
102
|
+
for (let r = 0; r < 256; ++r) {
|
|
103
|
+
const e = r - 127;
|
|
104
|
+
e < -24 ? (R[r] = 0, R[r | 256] = 32768, B[r] = 24, B[r | 256] = 24) : e < -14 ? (R[r] = 1024 >> -e - 14, R[r | 256] = 1024 >> -e - 14 | 32768, B[r] = -e - 1, B[r | 256] = -e - 1) : e <= 15 ? (R[r] = e + 15 << 10, R[r | 256] = e + 15 << 10 | 32768, B[r] = 13, B[r | 256] = 13) : e < 128 ? (R[r] = 31744, R[r | 256] = 64512, B[r] = 24, B[r | 256] = 24) : (R[r] = 31744, R[r | 256] = 64512, B[r] = 13, B[r | 256] = 13);
|
|
105
|
+
}
|
|
106
|
+
const Ce = new Ee(2048);
|
|
107
|
+
for (let r = 1; r < 1024; ++r) {
|
|
108
|
+
let e = r << 13, t = 0;
|
|
109
|
+
for (; (e & 8388608) === 0; )
|
|
110
|
+
e <<= 1, t -= 8388608;
|
|
111
|
+
e &= -8388609, t += 947912704, Ce[r] = e | t;
|
|
112
|
+
}
|
|
113
|
+
for (let r = 1024; r < 2048; ++r)
|
|
114
|
+
Ce[r] = 939524096 + (r - 1024 << 13);
|
|
115
|
+
const q = new Ee(64);
|
|
116
|
+
for (let r = 1; r < 31; ++r)
|
|
117
|
+
q[r] = r << 23;
|
|
118
|
+
q[31] = 1199570944;
|
|
119
|
+
q[32] = 2147483648;
|
|
120
|
+
for (let r = 33; r < 63; ++r)
|
|
121
|
+
q[r] = 2147483648 + (r - 32 << 23);
|
|
122
|
+
q[63] = 3347054592;
|
|
123
|
+
const et = new $e(64);
|
|
124
|
+
for (let r = 1; r < 64; ++r)
|
|
125
|
+
r !== 32 && (et[r] = 1024);
|
|
126
|
+
function Xt(r) {
|
|
127
|
+
const e = r >> 10;
|
|
128
|
+
return $t[0] = Ce[et[e] + (r & 1023)] + q[e], Yt[0];
|
|
129
|
+
}
|
|
130
|
+
function tt(r, e, ...t) {
|
|
131
|
+
return Xt(
|
|
132
|
+
Kt(r, e, ...Vt(t))
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
function rt(r) {
|
|
136
|
+
return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r;
|
|
137
|
+
}
|
|
138
|
+
var ne = { exports: {} }, Ue;
|
|
139
|
+
function Zt() {
|
|
140
|
+
if (Ue) return ne.exports;
|
|
141
|
+
Ue = 1;
|
|
142
|
+
function r(e, t, s) {
|
|
143
|
+
const n = s && s.debug || !1;
|
|
144
|
+
n && console.log("[xml-utils] getting " + t + " in " + e);
|
|
145
|
+
const i = typeof e == "object" ? e.outer : e, a = i.slice(0, i.indexOf(">") + 1), o = ['"', "'"];
|
|
146
|
+
for (let c = 0; c < o.length; c++) {
|
|
147
|
+
const l = o[c], f = t + "\\=" + l + "([^" + l + "]*)" + l;
|
|
148
|
+
n && console.log("[xml-utils] pattern:", f);
|
|
149
|
+
const u = new RegExp(f).exec(a);
|
|
150
|
+
if (n && console.log("[xml-utils] match:", u), u) return u[1];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return ne.exports = r, ne.exports.default = r, ne.exports;
|
|
154
|
+
}
|
|
155
|
+
var Jt = Zt();
|
|
156
|
+
const Se = /* @__PURE__ */ rt(Jt);
|
|
157
|
+
var ie = { exports: {} }, oe = { exports: {} }, ae = { exports: {} }, _e;
|
|
158
|
+
function Qt() {
|
|
159
|
+
if (_e) return ae.exports;
|
|
160
|
+
_e = 1;
|
|
161
|
+
function r(e, t, s) {
|
|
162
|
+
const i = new RegExp(t).exec(e.slice(s));
|
|
163
|
+
return i ? s + i.index : -1;
|
|
164
|
+
}
|
|
165
|
+
return ae.exports = r, ae.exports.default = r, ae.exports;
|
|
166
|
+
}
|
|
167
|
+
var ce = { exports: {} }, ve;
|
|
168
|
+
function Wt() {
|
|
169
|
+
if (ve) return ce.exports;
|
|
170
|
+
ve = 1;
|
|
171
|
+
function r(e, t, s) {
|
|
172
|
+
const i = new RegExp(t).exec(e.slice(s));
|
|
173
|
+
return i ? s + i.index + i[0].length - 1 : -1;
|
|
174
|
+
}
|
|
175
|
+
return ce.exports = r, ce.exports.default = r, ce.exports;
|
|
176
|
+
}
|
|
177
|
+
var le = { exports: {} }, Le;
|
|
178
|
+
function er() {
|
|
179
|
+
if (Le) return le.exports;
|
|
180
|
+
Le = 1;
|
|
181
|
+
function r(e, t) {
|
|
182
|
+
const s = new RegExp(t, "g"), n = e.match(s);
|
|
183
|
+
return n ? n.length : 0;
|
|
184
|
+
}
|
|
185
|
+
return le.exports = r, le.exports.default = r, le.exports;
|
|
186
|
+
}
|
|
187
|
+
var Ne;
|
|
188
|
+
function tr() {
|
|
189
|
+
if (Ne) return oe.exports;
|
|
190
|
+
Ne = 1;
|
|
191
|
+
const r = Qt(), e = Wt(), t = er();
|
|
192
|
+
function s(n, i, a) {
|
|
193
|
+
const o = a && a.debug || !1, c = !(a && typeof a.nested === !1), l = a && a.startIndex || 0;
|
|
194
|
+
o && console.log("[xml-utils] starting findTagByName with", i, " and ", a);
|
|
195
|
+
const f = r(n, `<${i}[
|
|
196
|
+
>/]`, l);
|
|
197
|
+
if (o && console.log("[xml-utils] start:", f), f === -1) return;
|
|
198
|
+
const h = n.slice(f + i.length);
|
|
199
|
+
let u = e(h, "^[^<]*[ /]>", 0);
|
|
200
|
+
const d = u !== -1 && h[u - 1] === "/";
|
|
201
|
+
if (o && console.log("[xml-utils] selfClosing:", d), d === !1)
|
|
202
|
+
if (c) {
|
|
203
|
+
let x = 0, w = 1, S = 0;
|
|
204
|
+
for (; (u = e(h, "[ /]" + i + ">", x)) !== -1; ) {
|
|
205
|
+
const I = h.substring(x, u + 1);
|
|
206
|
+
if (w += t(I, "<" + i + `[
|
|
207
|
+
>]`), S += t(I, "</" + i + ">"), S >= w) break;
|
|
208
|
+
x = u;
|
|
209
|
+
}
|
|
210
|
+
} else
|
|
211
|
+
u = e(h, "[ /]" + i + ">", 0);
|
|
212
|
+
const g = f + i.length + u + 1;
|
|
213
|
+
if (o && console.log("[xml-utils] end:", g), g === -1) return;
|
|
214
|
+
const y = n.slice(f, g);
|
|
215
|
+
let p;
|
|
216
|
+
return d ? p = null : p = y.slice(y.indexOf(">") + 1, y.lastIndexOf("<")), { inner: p, outer: y, start: f, end: g };
|
|
217
|
+
}
|
|
218
|
+
return oe.exports = s, oe.exports.default = s, oe.exports;
|
|
219
|
+
}
|
|
220
|
+
var Ke;
|
|
221
|
+
function rr() {
|
|
222
|
+
if (Ke) return ie.exports;
|
|
223
|
+
Ke = 1;
|
|
224
|
+
const r = tr();
|
|
225
|
+
function e(t, s, n) {
|
|
226
|
+
const i = [], a = n && n.debug || !1, o = n && typeof n.nested == "boolean" ? n.nested : !0;
|
|
227
|
+
let c = n && n.startIndex || 0, l;
|
|
228
|
+
for (; l = r(t, s, { debug: a, startIndex: c }); )
|
|
229
|
+
o ? c = l.start + 1 + s.length : c = l.end, i.push(l);
|
|
230
|
+
return a && console.log("findTagsByName found", i.length, "tags"), i;
|
|
231
|
+
}
|
|
232
|
+
return ie.exports = e, ie.exports.default = e, ie.exports;
|
|
233
|
+
}
|
|
234
|
+
var sr = rr();
|
|
235
|
+
const nr = /* @__PURE__ */ rt(sr), U = {
|
|
236
|
+
// TIFF Baseline
|
|
237
|
+
315: "Artist",
|
|
238
|
+
258: "BitsPerSample",
|
|
239
|
+
265: "CellLength",
|
|
240
|
+
264: "CellWidth",
|
|
241
|
+
320: "ColorMap",
|
|
242
|
+
259: "Compression",
|
|
243
|
+
33432: "Copyright",
|
|
244
|
+
306: "DateTime",
|
|
245
|
+
338: "ExtraSamples",
|
|
246
|
+
266: "FillOrder",
|
|
247
|
+
289: "FreeByteCounts",
|
|
248
|
+
288: "FreeOffsets",
|
|
249
|
+
291: "GrayResponseCurve",
|
|
250
|
+
290: "GrayResponseUnit",
|
|
251
|
+
316: "HostComputer",
|
|
252
|
+
270: "ImageDescription",
|
|
253
|
+
257: "ImageLength",
|
|
254
|
+
256: "ImageWidth",
|
|
255
|
+
271: "Make",
|
|
256
|
+
281: "MaxSampleValue",
|
|
257
|
+
280: "MinSampleValue",
|
|
258
|
+
272: "Model",
|
|
259
|
+
254: "NewSubfileType",
|
|
260
|
+
274: "Orientation",
|
|
261
|
+
262: "PhotometricInterpretation",
|
|
262
|
+
284: "PlanarConfiguration",
|
|
263
|
+
296: "ResolutionUnit",
|
|
264
|
+
278: "RowsPerStrip",
|
|
265
|
+
277: "SamplesPerPixel",
|
|
266
|
+
305: "Software",
|
|
267
|
+
279: "StripByteCounts",
|
|
268
|
+
273: "StripOffsets",
|
|
269
|
+
255: "SubfileType",
|
|
270
|
+
263: "Threshholding",
|
|
271
|
+
282: "XResolution",
|
|
272
|
+
283: "YResolution",
|
|
273
|
+
// TIFF Extended
|
|
274
|
+
326: "BadFaxLines",
|
|
275
|
+
327: "CleanFaxData",
|
|
276
|
+
343: "ClipPath",
|
|
277
|
+
328: "ConsecutiveBadFaxLines",
|
|
278
|
+
433: "Decode",
|
|
279
|
+
434: "DefaultImageColor",
|
|
280
|
+
269: "DocumentName",
|
|
281
|
+
336: "DotRange",
|
|
282
|
+
321: "HalftoneHints",
|
|
283
|
+
346: "Indexed",
|
|
284
|
+
347: "JPEGTables",
|
|
285
|
+
285: "PageName",
|
|
286
|
+
297: "PageNumber",
|
|
287
|
+
317: "Predictor",
|
|
288
|
+
319: "PrimaryChromaticities",
|
|
289
|
+
532: "ReferenceBlackWhite",
|
|
290
|
+
339: "SampleFormat",
|
|
291
|
+
340: "SMinSampleValue",
|
|
292
|
+
341: "SMaxSampleValue",
|
|
293
|
+
559: "StripRowCounts",
|
|
294
|
+
330: "SubIFDs",
|
|
295
|
+
292: "T4Options",
|
|
296
|
+
293: "T6Options",
|
|
297
|
+
325: "TileByteCounts",
|
|
298
|
+
323: "TileLength",
|
|
299
|
+
324: "TileOffsets",
|
|
300
|
+
322: "TileWidth",
|
|
301
|
+
301: "TransferFunction",
|
|
302
|
+
318: "WhitePoint",
|
|
303
|
+
344: "XClipPathUnits",
|
|
304
|
+
286: "XPosition",
|
|
305
|
+
529: "YCbCrCoefficients",
|
|
306
|
+
531: "YCbCrPositioning",
|
|
307
|
+
530: "YCbCrSubSampling",
|
|
308
|
+
345: "YClipPathUnits",
|
|
309
|
+
287: "YPosition",
|
|
310
|
+
// EXIF
|
|
311
|
+
37378: "ApertureValue",
|
|
312
|
+
40961: "ColorSpace",
|
|
313
|
+
36868: "DateTimeDigitized",
|
|
314
|
+
36867: "DateTimeOriginal",
|
|
315
|
+
34665: "Exif IFD",
|
|
316
|
+
36864: "ExifVersion",
|
|
317
|
+
33434: "ExposureTime",
|
|
318
|
+
41728: "FileSource",
|
|
319
|
+
37385: "Flash",
|
|
320
|
+
40960: "FlashpixVersion",
|
|
321
|
+
33437: "FNumber",
|
|
322
|
+
42016: "ImageUniqueID",
|
|
323
|
+
37384: "LightSource",
|
|
324
|
+
37500: "MakerNote",
|
|
325
|
+
37377: "ShutterSpeedValue",
|
|
326
|
+
37510: "UserComment",
|
|
327
|
+
// IPTC
|
|
328
|
+
33723: "IPTC",
|
|
329
|
+
// ICC
|
|
330
|
+
34675: "ICC Profile",
|
|
331
|
+
// XMP
|
|
332
|
+
700: "XMP",
|
|
333
|
+
// GDAL
|
|
334
|
+
42112: "GDAL_METADATA",
|
|
335
|
+
42113: "GDAL_NODATA",
|
|
336
|
+
// Photoshop
|
|
337
|
+
34377: "Photoshop",
|
|
338
|
+
// GeoTiff
|
|
339
|
+
33550: "ModelPixelScale",
|
|
340
|
+
33922: "ModelTiepoint",
|
|
341
|
+
34264: "ModelTransformation",
|
|
342
|
+
34735: "GeoKeyDirectory",
|
|
343
|
+
34736: "GeoDoubleParams",
|
|
344
|
+
34737: "GeoAsciiParams",
|
|
345
|
+
// LERC
|
|
346
|
+
50674: "LercParameters"
|
|
347
|
+
}, F = {};
|
|
348
|
+
for (const r in U)
|
|
349
|
+
U.hasOwnProperty(r) && (F[U[r]] = parseInt(r, 10));
|
|
350
|
+
const ue = {
|
|
351
|
+
256: "SHORT",
|
|
352
|
+
257: "SHORT",
|
|
353
|
+
258: "SHORT",
|
|
354
|
+
259: "SHORT",
|
|
355
|
+
262: "SHORT",
|
|
356
|
+
273: "LONG",
|
|
357
|
+
274: "SHORT",
|
|
358
|
+
277: "SHORT",
|
|
359
|
+
278: "LONG",
|
|
360
|
+
279: "LONG",
|
|
361
|
+
282: "RATIONAL",
|
|
362
|
+
283: "RATIONAL",
|
|
363
|
+
284: "SHORT",
|
|
364
|
+
286: "SHORT",
|
|
365
|
+
287: "RATIONAL",
|
|
366
|
+
296: "SHORT",
|
|
367
|
+
297: "SHORT",
|
|
368
|
+
305: "ASCII",
|
|
369
|
+
306: "ASCII",
|
|
370
|
+
338: "SHORT",
|
|
371
|
+
339: "SHORT",
|
|
372
|
+
513: "LONG",
|
|
373
|
+
514: "LONG",
|
|
374
|
+
1024: "SHORT",
|
|
375
|
+
1025: "SHORT",
|
|
376
|
+
2048: "SHORT",
|
|
377
|
+
2049: "ASCII",
|
|
378
|
+
3072: "SHORT",
|
|
379
|
+
3073: "ASCII",
|
|
380
|
+
33550: "DOUBLE",
|
|
381
|
+
33922: "DOUBLE",
|
|
382
|
+
34264: "DOUBLE",
|
|
383
|
+
34665: "LONG",
|
|
384
|
+
34735: "SHORT",
|
|
385
|
+
34736: "DOUBLE",
|
|
386
|
+
34737: "ASCII",
|
|
387
|
+
42113: "ASCII"
|
|
388
|
+
}, st = [
|
|
389
|
+
F.BitsPerSample,
|
|
390
|
+
F.ExtraSamples,
|
|
391
|
+
F.SampleFormat,
|
|
392
|
+
F.StripByteCounts,
|
|
393
|
+
F.StripOffsets,
|
|
394
|
+
F.StripRowCounts,
|
|
395
|
+
F.TileByteCounts,
|
|
396
|
+
F.TileOffsets,
|
|
397
|
+
F.SubIFDs
|
|
398
|
+
], X = {
|
|
399
|
+
1: "BYTE",
|
|
400
|
+
2: "ASCII",
|
|
401
|
+
3: "SHORT",
|
|
402
|
+
4: "LONG",
|
|
403
|
+
5: "RATIONAL",
|
|
404
|
+
6: "SBYTE",
|
|
405
|
+
7: "UNDEFINED",
|
|
406
|
+
8: "SSHORT",
|
|
407
|
+
9: "SLONG",
|
|
408
|
+
10: "SRATIONAL",
|
|
409
|
+
11: "FLOAT",
|
|
410
|
+
12: "DOUBLE",
|
|
411
|
+
// IFD offset, suggested by https://owl.phy.queensu.ca/~phil/exiftool/standards.html
|
|
412
|
+
13: "IFD",
|
|
413
|
+
// introduced by BigTIFF
|
|
414
|
+
16: "LONG8",
|
|
415
|
+
17: "SLONG8",
|
|
416
|
+
18: "IFD8"
|
|
417
|
+
}, m = {};
|
|
418
|
+
for (const r in X)
|
|
419
|
+
X.hasOwnProperty(r) && (m[X[r]] = parseInt(r, 10));
|
|
420
|
+
const P = {
|
|
421
|
+
WhiteIsZero: 0,
|
|
422
|
+
BlackIsZero: 1,
|
|
423
|
+
RGB: 2,
|
|
424
|
+
Palette: 3,
|
|
425
|
+
TransparencyMask: 4,
|
|
426
|
+
CMYK: 5,
|
|
427
|
+
YCbCr: 6,
|
|
428
|
+
CIELab: 8,
|
|
429
|
+
ICCLab: 9
|
|
430
|
+
}, nt = {
|
|
431
|
+
Unspecified: 0,
|
|
432
|
+
Assocalpha: 1,
|
|
433
|
+
Unassalpha: 2
|
|
434
|
+
}, ir = {
|
|
435
|
+
Version: 0,
|
|
436
|
+
AddCompression: 1
|
|
437
|
+
}, or = {
|
|
438
|
+
None: 0,
|
|
439
|
+
Deflate: 1,
|
|
440
|
+
Zstandard: 2
|
|
441
|
+
}, L = {
|
|
442
|
+
1024: "GTModelTypeGeoKey",
|
|
443
|
+
1025: "GTRasterTypeGeoKey",
|
|
444
|
+
1026: "GTCitationGeoKey",
|
|
445
|
+
2048: "GeographicTypeGeoKey",
|
|
446
|
+
2049: "GeogCitationGeoKey",
|
|
447
|
+
2050: "GeogGeodeticDatumGeoKey",
|
|
448
|
+
2051: "GeogPrimeMeridianGeoKey",
|
|
449
|
+
2052: "GeogLinearUnitsGeoKey",
|
|
450
|
+
2053: "GeogLinearUnitSizeGeoKey",
|
|
451
|
+
2054: "GeogAngularUnitsGeoKey",
|
|
452
|
+
2055: "GeogAngularUnitSizeGeoKey",
|
|
453
|
+
2056: "GeogEllipsoidGeoKey",
|
|
454
|
+
2057: "GeogSemiMajorAxisGeoKey",
|
|
455
|
+
2058: "GeogSemiMinorAxisGeoKey",
|
|
456
|
+
2059: "GeogInvFlatteningGeoKey",
|
|
457
|
+
2060: "GeogAzimuthUnitsGeoKey",
|
|
458
|
+
2061: "GeogPrimeMeridianLongGeoKey",
|
|
459
|
+
2062: "GeogTOWGS84GeoKey",
|
|
460
|
+
3072: "ProjectedCSTypeGeoKey",
|
|
461
|
+
3073: "PCSCitationGeoKey",
|
|
462
|
+
3074: "ProjectionGeoKey",
|
|
463
|
+
3075: "ProjCoordTransGeoKey",
|
|
464
|
+
3076: "ProjLinearUnitsGeoKey",
|
|
465
|
+
3077: "ProjLinearUnitSizeGeoKey",
|
|
466
|
+
3078: "ProjStdParallel1GeoKey",
|
|
467
|
+
3079: "ProjStdParallel2GeoKey",
|
|
468
|
+
3080: "ProjNatOriginLongGeoKey",
|
|
469
|
+
3081: "ProjNatOriginLatGeoKey",
|
|
470
|
+
3082: "ProjFalseEastingGeoKey",
|
|
471
|
+
3083: "ProjFalseNorthingGeoKey",
|
|
472
|
+
3084: "ProjFalseOriginLongGeoKey",
|
|
473
|
+
3085: "ProjFalseOriginLatGeoKey",
|
|
474
|
+
3086: "ProjFalseOriginEastingGeoKey",
|
|
475
|
+
3087: "ProjFalseOriginNorthingGeoKey",
|
|
476
|
+
3088: "ProjCenterLongGeoKey",
|
|
477
|
+
3089: "ProjCenterLatGeoKey",
|
|
478
|
+
3090: "ProjCenterEastingGeoKey",
|
|
479
|
+
3091: "ProjCenterNorthingGeoKey",
|
|
480
|
+
3092: "ProjScaleAtNatOriginGeoKey",
|
|
481
|
+
3093: "ProjScaleAtCenterGeoKey",
|
|
482
|
+
3094: "ProjAzimuthAngleGeoKey",
|
|
483
|
+
3095: "ProjStraightVertPoleLongGeoKey",
|
|
484
|
+
3096: "ProjRectifiedGridAngleGeoKey",
|
|
485
|
+
4096: "VerticalCSTypeGeoKey",
|
|
486
|
+
4097: "VerticalCitationGeoKey",
|
|
487
|
+
4098: "VerticalDatumGeoKey",
|
|
488
|
+
4099: "VerticalUnitsGeoKey"
|
|
489
|
+
}, it = {};
|
|
490
|
+
for (const r in L)
|
|
491
|
+
L.hasOwnProperty(r) && (it[L[r]] = parseInt(r, 10));
|
|
492
|
+
const ar = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
493
|
+
__proto__: null,
|
|
494
|
+
ExtraSamplesValues: nt,
|
|
495
|
+
LercAddCompression: or,
|
|
496
|
+
LercParameters: ir,
|
|
497
|
+
arrayFields: st,
|
|
498
|
+
fieldTagNames: U,
|
|
499
|
+
fieldTagTypes: ue,
|
|
500
|
+
fieldTags: F,
|
|
501
|
+
fieldTypeNames: X,
|
|
502
|
+
fieldTypes: m,
|
|
503
|
+
geoKeyNames: L,
|
|
504
|
+
geoKeys: it,
|
|
505
|
+
photometricInterpretations: P
|
|
506
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
507
|
+
function ot(r, e) {
|
|
508
|
+
const { width: t, height: s } = r, n = new Uint8Array(t * s * 3);
|
|
509
|
+
let i;
|
|
510
|
+
for (let a = 0, o = 0; a < r.length; ++a, o += 3)
|
|
511
|
+
i = 256 - r[a] / e * 256, n[o] = i, n[o + 1] = i, n[o + 2] = i;
|
|
512
|
+
return n;
|
|
513
|
+
}
|
|
514
|
+
function at(r, e) {
|
|
515
|
+
const { width: t, height: s } = r, n = new Uint8Array(t * s * 3);
|
|
516
|
+
let i;
|
|
517
|
+
for (let a = 0, o = 0; a < r.length; ++a, o += 3)
|
|
518
|
+
i = r[a] / e * 256, n[o] = i, n[o + 1] = i, n[o + 2] = i;
|
|
519
|
+
return n;
|
|
520
|
+
}
|
|
521
|
+
function ct(r, e) {
|
|
522
|
+
const { width: t, height: s } = r, n = new Uint8Array(t * s * 3), i = e.length / 3, a = e.length / 3 * 2;
|
|
523
|
+
for (let o = 0, c = 0; o < r.length; ++o, c += 3) {
|
|
524
|
+
const l = r[o];
|
|
525
|
+
n[c] = e[l] / 65536 * 256, n[c + 1] = e[l + i] / 65536 * 256, n[c + 2] = e[l + a] / 65536 * 256;
|
|
526
|
+
}
|
|
527
|
+
return n;
|
|
528
|
+
}
|
|
529
|
+
function lt(r) {
|
|
530
|
+
const { width: e, height: t } = r, s = new Uint8Array(e * t * 3);
|
|
531
|
+
for (let n = 0, i = 0; n < r.length; n += 4, i += 3) {
|
|
532
|
+
const a = r[n], o = r[n + 1], c = r[n + 2], l = r[n + 3];
|
|
533
|
+
s[i] = 255 * ((255 - a) / 256) * ((255 - l) / 256), s[i + 1] = 255 * ((255 - o) / 256) * ((255 - l) / 256), s[i + 2] = 255 * ((255 - c) / 256) * ((255 - l) / 256);
|
|
534
|
+
}
|
|
535
|
+
return s;
|
|
536
|
+
}
|
|
537
|
+
function ft(r) {
|
|
538
|
+
const { width: e, height: t } = r, s = new Uint8ClampedArray(e * t * 3);
|
|
539
|
+
for (let n = 0, i = 0; n < r.length; n += 3, i += 3) {
|
|
540
|
+
const a = r[n], o = r[n + 1], c = r[n + 2];
|
|
541
|
+
s[i] = a + 1.402 * (c - 128), s[i + 1] = a - 0.34414 * (o - 128) - 0.71414 * (c - 128), s[i + 2] = a + 1.772 * (o - 128);
|
|
542
|
+
}
|
|
543
|
+
return s;
|
|
544
|
+
}
|
|
545
|
+
const cr = 0.95047, lr = 1, fr = 1.08883;
|
|
546
|
+
function ht(r) {
|
|
547
|
+
const { width: e, height: t } = r, s = new Uint8Array(e * t * 3);
|
|
548
|
+
for (let n = 0, i = 0; n < r.length; n += 3, i += 3) {
|
|
549
|
+
const a = r[n + 0], o = r[n + 1] << 24 >> 24, c = r[n + 2] << 24 >> 24;
|
|
550
|
+
let l = (a + 16) / 116, f = o / 500 + l, h = l - c / 200, u, d, g;
|
|
551
|
+
f = cr * (f * f * f > 8856e-6 ? f * f * f : (f - 16 / 116) / 7.787), l = lr * (l * l * l > 8856e-6 ? l * l * l : (l - 16 / 116) / 7.787), h = fr * (h * h * h > 8856e-6 ? h * h * h : (h - 16 / 116) / 7.787), u = f * 3.2406 + l * -1.5372 + h * -0.4986, d = f * -0.9689 + l * 1.8758 + h * 0.0415, g = f * 0.0557 + l * -0.204 + h * 1.057, u = u > 31308e-7 ? 1.055 * u ** (1 / 2.4) - 0.055 : 12.92 * u, d = d > 31308e-7 ? 1.055 * d ** (1 / 2.4) - 0.055 : 12.92 * d, g = g > 31308e-7 ? 1.055 * g ** (1 / 2.4) - 0.055 : 12.92 * g, s[i] = Math.max(0, Math.min(1, u)) * 255, s[i + 1] = Math.max(0, Math.min(1, d)) * 255, s[i + 2] = Math.max(0, Math.min(1, g)) * 255;
|
|
552
|
+
}
|
|
553
|
+
return s;
|
|
554
|
+
}
|
|
555
|
+
const hr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
556
|
+
__proto__: null,
|
|
557
|
+
fromBlackIsZero: at,
|
|
558
|
+
fromCIELab: ht,
|
|
559
|
+
fromCMYK: lt,
|
|
560
|
+
fromPalette: ct,
|
|
561
|
+
fromWhiteIsZero: ot,
|
|
562
|
+
fromYCbCr: ft
|
|
563
|
+
}, Symbol.toStringTag, { value: "Module" })), ut = /* @__PURE__ */ new Map();
|
|
564
|
+
function G(r, e) {
|
|
565
|
+
Array.isArray(r) || (r = [r]), r.forEach((t) => ut.set(t, e));
|
|
566
|
+
}
|
|
567
|
+
async function Fe(r) {
|
|
568
|
+
const e = ut.get(r.Compression);
|
|
569
|
+
if (!e)
|
|
570
|
+
throw new Error(`Unknown compression method identifier: ${r.Compression}`);
|
|
571
|
+
const t = await e();
|
|
572
|
+
return new t(r);
|
|
573
|
+
}
|
|
574
|
+
G([void 0, 1], () => import("./raw-CoQHiEnn.js").then((r) => r.default));
|
|
575
|
+
G(5, () => import("./lzw-DL9RcHOz.js").then((r) => r.default));
|
|
576
|
+
G(6, () => {
|
|
577
|
+
throw new Error("old style JPEG compression is not supported.");
|
|
578
|
+
});
|
|
579
|
+
G(7, () => import("./jpeg-B7yImnpY.js").then((r) => r.default));
|
|
580
|
+
G([8, 32946], () => import("./deflate-yeu3ogBn.js").then((r) => r.default));
|
|
581
|
+
G(32773, () => import("./packbits-YEJGULcy.js").then((r) => r.default));
|
|
582
|
+
G(
|
|
583
|
+
34887,
|
|
584
|
+
() => import("./lerc-CqgA9njy.js").then(async (r) => (await r.zstd.init(), r)).then((r) => r.default)
|
|
585
|
+
);
|
|
586
|
+
G(50001, () => import("./webimage-BXLN-zu8.js").then((r) => r.default));
|
|
587
|
+
function ge(r, e, t, s = 1) {
|
|
588
|
+
return new (Object.getPrototypeOf(r)).constructor(e * t * s);
|
|
589
|
+
}
|
|
590
|
+
function ur(r, e, t, s, n) {
|
|
591
|
+
const i = e / s, a = t / n;
|
|
592
|
+
return r.map((o) => {
|
|
593
|
+
const c = ge(o, s, n);
|
|
594
|
+
for (let l = 0; l < n; ++l) {
|
|
595
|
+
const f = Math.min(Math.round(a * l), t - 1);
|
|
596
|
+
for (let h = 0; h < s; ++h) {
|
|
597
|
+
const u = Math.min(Math.round(i * h), e - 1), d = o[f * e + u];
|
|
598
|
+
c[l * s + h] = d;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
return c;
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
function N(r, e, t) {
|
|
605
|
+
return (1 - t) * r + t * e;
|
|
606
|
+
}
|
|
607
|
+
function gr(r, e, t, s, n) {
|
|
608
|
+
const i = e / s, a = t / n;
|
|
609
|
+
return r.map((o) => {
|
|
610
|
+
const c = ge(o, s, n);
|
|
611
|
+
for (let l = 0; l < n; ++l) {
|
|
612
|
+
const f = a * l, h = Math.floor(f), u = Math.min(Math.ceil(f), t - 1);
|
|
613
|
+
for (let d = 0; d < s; ++d) {
|
|
614
|
+
const g = i * d, y = g % 1, p = Math.floor(g), x = Math.min(Math.ceil(g), e - 1), w = o[h * e + p], S = o[h * e + x], I = o[u * e + p], b = o[u * e + x], E = N(
|
|
615
|
+
N(w, S, y),
|
|
616
|
+
N(I, b, y),
|
|
617
|
+
f % 1
|
|
618
|
+
);
|
|
619
|
+
c[l * s + d] = E;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
return c;
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
function dr(r, e, t, s, n, i = "nearest") {
|
|
626
|
+
switch (i.toLowerCase()) {
|
|
627
|
+
case "nearest":
|
|
628
|
+
return ur(r, e, t, s, n);
|
|
629
|
+
case "bilinear":
|
|
630
|
+
case "linear":
|
|
631
|
+
return gr(r, e, t, s, n);
|
|
632
|
+
default:
|
|
633
|
+
throw new Error(`Unsupported resampling method: '${i}'`);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
function yr(r, e, t, s, n, i) {
|
|
637
|
+
const a = e / s, o = t / n, c = ge(r, s, n, i);
|
|
638
|
+
for (let l = 0; l < n; ++l) {
|
|
639
|
+
const f = Math.min(Math.round(o * l), t - 1);
|
|
640
|
+
for (let h = 0; h < s; ++h) {
|
|
641
|
+
const u = Math.min(Math.round(a * h), e - 1);
|
|
642
|
+
for (let d = 0; d < i; ++d) {
|
|
643
|
+
const g = r[f * e * i + u * i + d];
|
|
644
|
+
c[l * s * i + h * i + d] = g;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
return c;
|
|
649
|
+
}
|
|
650
|
+
function pr(r, e, t, s, n, i) {
|
|
651
|
+
const a = e / s, o = t / n, c = ge(r, s, n, i);
|
|
652
|
+
for (let l = 0; l < n; ++l) {
|
|
653
|
+
const f = o * l, h = Math.floor(f), u = Math.min(Math.ceil(f), t - 1);
|
|
654
|
+
for (let d = 0; d < s; ++d) {
|
|
655
|
+
const g = a * d, y = g % 1, p = Math.floor(g), x = Math.min(Math.ceil(g), e - 1);
|
|
656
|
+
for (let w = 0; w < i; ++w) {
|
|
657
|
+
const S = r[h * e * i + p * i + w], I = r[h * e * i + x * i + w], b = r[u * e * i + p * i + w], E = r[u * e * i + x * i + w], V = N(
|
|
658
|
+
N(S, I, y),
|
|
659
|
+
N(b, E, y),
|
|
660
|
+
f % 1
|
|
661
|
+
);
|
|
662
|
+
c[l * s * i + d * i + w] = V;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
return c;
|
|
667
|
+
}
|
|
668
|
+
function wr(r, e, t, s, n, i, a = "nearest") {
|
|
669
|
+
switch (a.toLowerCase()) {
|
|
670
|
+
case "nearest":
|
|
671
|
+
return yr(
|
|
672
|
+
r,
|
|
673
|
+
e,
|
|
674
|
+
t,
|
|
675
|
+
s,
|
|
676
|
+
n,
|
|
677
|
+
i
|
|
678
|
+
);
|
|
679
|
+
case "bilinear":
|
|
680
|
+
case "linear":
|
|
681
|
+
return pr(
|
|
682
|
+
r,
|
|
683
|
+
e,
|
|
684
|
+
t,
|
|
685
|
+
s,
|
|
686
|
+
n,
|
|
687
|
+
i
|
|
688
|
+
);
|
|
689
|
+
default:
|
|
690
|
+
throw new Error(`Unsupported resampling method: '${a}'`);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
function mr(r, e, t) {
|
|
694
|
+
let s = 0;
|
|
695
|
+
for (let n = e; n < t; ++n)
|
|
696
|
+
s += r[n];
|
|
697
|
+
return s;
|
|
698
|
+
}
|
|
699
|
+
function Ie(r, e, t) {
|
|
700
|
+
switch (r) {
|
|
701
|
+
case 1:
|
|
702
|
+
if (e <= 8)
|
|
703
|
+
return new Uint8Array(t);
|
|
704
|
+
if (e <= 16)
|
|
705
|
+
return new Uint16Array(t);
|
|
706
|
+
if (e <= 32)
|
|
707
|
+
return new Uint32Array(t);
|
|
708
|
+
break;
|
|
709
|
+
case 2:
|
|
710
|
+
if (e === 8)
|
|
711
|
+
return new Int8Array(t);
|
|
712
|
+
if (e === 16)
|
|
713
|
+
return new Int16Array(t);
|
|
714
|
+
if (e === 32)
|
|
715
|
+
return new Int32Array(t);
|
|
716
|
+
break;
|
|
717
|
+
case 3:
|
|
718
|
+
switch (e) {
|
|
719
|
+
case 16:
|
|
720
|
+
case 32:
|
|
721
|
+
return new Float32Array(t);
|
|
722
|
+
case 64:
|
|
723
|
+
return new Float64Array(t);
|
|
724
|
+
}
|
|
725
|
+
break;
|
|
726
|
+
}
|
|
727
|
+
throw Error("Unsupported data format/bitsPerSample");
|
|
728
|
+
}
|
|
729
|
+
function xr(r, e) {
|
|
730
|
+
return (r === 1 || r === 2) && e <= 32 && e % 8 === 0 ? !1 : !(r === 3 && (e === 16 || e === 32 || e === 64));
|
|
731
|
+
}
|
|
732
|
+
function Sr(r, e, t, s, n, i, a) {
|
|
733
|
+
const o = new DataView(r), c = t === 2 ? a * i : a * i * s, l = t === 2 ? 1 : s, f = Ie(e, n, c), h = parseInt("1".repeat(n), 2);
|
|
734
|
+
if (e === 1) {
|
|
735
|
+
let u;
|
|
736
|
+
t === 1 ? u = s * n : u = n;
|
|
737
|
+
let d = i * u;
|
|
738
|
+
(d & 7) !== 0 && (d = d + 7 & -8);
|
|
739
|
+
for (let g = 0; g < a; ++g) {
|
|
740
|
+
const y = g * d;
|
|
741
|
+
for (let p = 0; p < i; ++p) {
|
|
742
|
+
const x = y + p * l * n;
|
|
743
|
+
for (let w = 0; w < l; ++w) {
|
|
744
|
+
const S = x + w * n, I = (g * i + p) * l + w, b = Math.floor(S / 8), E = S % 8;
|
|
745
|
+
if (E + n <= 8)
|
|
746
|
+
f[I] = o.getUint8(b) >> 8 - n - E & h;
|
|
747
|
+
else if (E + n <= 16)
|
|
748
|
+
f[I] = o.getUint16(b) >> 16 - n - E & h;
|
|
749
|
+
else if (E + n <= 24) {
|
|
750
|
+
const V = o.getUint16(b) << 8 | o.getUint8(b + 2);
|
|
751
|
+
f[I] = V >> 24 - n - E & h;
|
|
752
|
+
} else
|
|
753
|
+
f[I] = o.getUint32(b) >> 32 - n - E & h;
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
return f.buffer;
|
|
759
|
+
}
|
|
760
|
+
class ke {
|
|
761
|
+
/**
|
|
762
|
+
* @constructor
|
|
763
|
+
* @param {Object} fileDirectory The parsed file directory
|
|
764
|
+
* @param {Object} geoKeys The parsed geo-keys
|
|
765
|
+
* @param {DataView} dataView The DataView for the underlying file.
|
|
766
|
+
* @param {Boolean} littleEndian Whether the file is encoded in little or big endian
|
|
767
|
+
* @param {Boolean} cache Whether or not decoded tiles shall be cached
|
|
768
|
+
* @param {import('./source/basesource').BaseSource} source The datasource to read from
|
|
769
|
+
*/
|
|
770
|
+
constructor(e, t, s, n, i, a) {
|
|
771
|
+
this.fileDirectory = e, this.geoKeys = t, this.dataView = s, this.littleEndian = n, this.tiles = i ? {} : null, this.isTiled = !e.StripOffsets;
|
|
772
|
+
const o = e.PlanarConfiguration;
|
|
773
|
+
if (this.planarConfiguration = typeof o > "u" ? 1 : o, this.planarConfiguration !== 1 && this.planarConfiguration !== 2)
|
|
774
|
+
throw new Error("Invalid planar configuration.");
|
|
775
|
+
this.source = a;
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* Returns the associated parsed file directory.
|
|
779
|
+
* @returns {Object} the parsed file directory
|
|
780
|
+
*/
|
|
781
|
+
getFileDirectory() {
|
|
782
|
+
return this.fileDirectory;
|
|
783
|
+
}
|
|
784
|
+
/**
|
|
785
|
+
* Returns the associated parsed geo keys.
|
|
786
|
+
* @returns {Object} the parsed geo keys
|
|
787
|
+
*/
|
|
788
|
+
getGeoKeys() {
|
|
789
|
+
return this.geoKeys;
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* Returns the width of the image.
|
|
793
|
+
* @returns {Number} the width of the image
|
|
794
|
+
*/
|
|
795
|
+
getWidth() {
|
|
796
|
+
return this.fileDirectory.ImageWidth;
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* Returns the height of the image.
|
|
800
|
+
* @returns {Number} the height of the image
|
|
801
|
+
*/
|
|
802
|
+
getHeight() {
|
|
803
|
+
return this.fileDirectory.ImageLength;
|
|
804
|
+
}
|
|
805
|
+
/**
|
|
806
|
+
* Returns the number of samples per pixel.
|
|
807
|
+
* @returns {Number} the number of samples per pixel
|
|
808
|
+
*/
|
|
809
|
+
getSamplesPerPixel() {
|
|
810
|
+
return typeof this.fileDirectory.SamplesPerPixel < "u" ? this.fileDirectory.SamplesPerPixel : 1;
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* Returns the width of each tile.
|
|
814
|
+
* @returns {Number} the width of each tile
|
|
815
|
+
*/
|
|
816
|
+
getTileWidth() {
|
|
817
|
+
return this.isTiled ? this.fileDirectory.TileWidth : this.getWidth();
|
|
818
|
+
}
|
|
819
|
+
/**
|
|
820
|
+
* Returns the height of each tile.
|
|
821
|
+
* @returns {Number} the height of each tile
|
|
822
|
+
*/
|
|
823
|
+
getTileHeight() {
|
|
824
|
+
return this.isTiled ? this.fileDirectory.TileLength : typeof this.fileDirectory.RowsPerStrip < "u" ? Math.min(this.fileDirectory.RowsPerStrip, this.getHeight()) : this.getHeight();
|
|
825
|
+
}
|
|
826
|
+
getBlockWidth() {
|
|
827
|
+
return this.getTileWidth();
|
|
828
|
+
}
|
|
829
|
+
getBlockHeight(e) {
|
|
830
|
+
return this.isTiled || (e + 1) * this.getTileHeight() <= this.getHeight() ? this.getTileHeight() : this.getHeight() - e * this.getTileHeight();
|
|
831
|
+
}
|
|
832
|
+
/**
|
|
833
|
+
* Calculates the number of bytes for each pixel across all samples. Only full
|
|
834
|
+
* bytes are supported, an exception is thrown when this is not the case.
|
|
835
|
+
* @returns {Number} the bytes per pixel
|
|
836
|
+
*/
|
|
837
|
+
getBytesPerPixel() {
|
|
838
|
+
let e = 0;
|
|
839
|
+
for (let t = 0; t < this.fileDirectory.BitsPerSample.length; ++t)
|
|
840
|
+
e += this.getSampleByteSize(t);
|
|
841
|
+
return e;
|
|
842
|
+
}
|
|
843
|
+
getSampleByteSize(e) {
|
|
844
|
+
if (e >= this.fileDirectory.BitsPerSample.length)
|
|
845
|
+
throw new RangeError(`Sample index ${e} is out of range.`);
|
|
846
|
+
return Math.ceil(this.fileDirectory.BitsPerSample[e] / 8);
|
|
847
|
+
}
|
|
848
|
+
getReaderForSample(e) {
|
|
849
|
+
const t = this.fileDirectory.SampleFormat ? this.fileDirectory.SampleFormat[e] : 1, s = this.fileDirectory.BitsPerSample[e];
|
|
850
|
+
switch (t) {
|
|
851
|
+
case 1:
|
|
852
|
+
if (s <= 8)
|
|
853
|
+
return DataView.prototype.getUint8;
|
|
854
|
+
if (s <= 16)
|
|
855
|
+
return DataView.prototype.getUint16;
|
|
856
|
+
if (s <= 32)
|
|
857
|
+
return DataView.prototype.getUint32;
|
|
858
|
+
break;
|
|
859
|
+
case 2:
|
|
860
|
+
if (s <= 8)
|
|
861
|
+
return DataView.prototype.getInt8;
|
|
862
|
+
if (s <= 16)
|
|
863
|
+
return DataView.prototype.getInt16;
|
|
864
|
+
if (s <= 32)
|
|
865
|
+
return DataView.prototype.getInt32;
|
|
866
|
+
break;
|
|
867
|
+
case 3:
|
|
868
|
+
switch (s) {
|
|
869
|
+
case 16:
|
|
870
|
+
return function(n, i) {
|
|
871
|
+
return tt(this, n, i);
|
|
872
|
+
};
|
|
873
|
+
case 32:
|
|
874
|
+
return DataView.prototype.getFloat32;
|
|
875
|
+
case 64:
|
|
876
|
+
return DataView.prototype.getFloat64;
|
|
877
|
+
}
|
|
878
|
+
break;
|
|
879
|
+
}
|
|
880
|
+
throw Error("Unsupported data format/bitsPerSample");
|
|
881
|
+
}
|
|
882
|
+
getSampleFormat(e = 0) {
|
|
883
|
+
return this.fileDirectory.SampleFormat ? this.fileDirectory.SampleFormat[e] : 1;
|
|
884
|
+
}
|
|
885
|
+
getBitsPerSample(e = 0) {
|
|
886
|
+
return this.fileDirectory.BitsPerSample[e];
|
|
887
|
+
}
|
|
888
|
+
getArrayForSample(e, t) {
|
|
889
|
+
const s = this.getSampleFormat(e), n = this.getBitsPerSample(e);
|
|
890
|
+
return Ie(s, n, t);
|
|
891
|
+
}
|
|
892
|
+
/**
|
|
893
|
+
* Returns the decoded strip or tile.
|
|
894
|
+
* @param {Number} x the strip or tile x-offset
|
|
895
|
+
* @param {Number} y the tile y-offset (0 for stripped images)
|
|
896
|
+
* @param {Number} sample the sample to get for separated samples
|
|
897
|
+
* @param {import("./geotiff").Pool|import("./geotiff").BaseDecoder} poolOrDecoder the decoder or decoder pool
|
|
898
|
+
* @param {AbortSignal} [signal] An AbortSignal that may be signalled if the request is
|
|
899
|
+
* to be aborted
|
|
900
|
+
* @returns {Promise.<ArrayBuffer>}
|
|
901
|
+
*/
|
|
902
|
+
async getTileOrStrip(e, t, s, n, i) {
|
|
903
|
+
const a = Math.ceil(this.getWidth() / this.getTileWidth()), o = Math.ceil(this.getHeight() / this.getTileHeight());
|
|
904
|
+
let c;
|
|
905
|
+
const { tiles: l } = this;
|
|
906
|
+
this.planarConfiguration === 1 ? c = t * a + e : this.planarConfiguration === 2 && (c = s * a * o + t * a + e);
|
|
907
|
+
let f, h;
|
|
908
|
+
this.isTiled ? (f = this.fileDirectory.TileOffsets[c], h = this.fileDirectory.TileByteCounts[c]) : (f = this.fileDirectory.StripOffsets[c], h = this.fileDirectory.StripByteCounts[c]);
|
|
909
|
+
const u = (await this.source.fetch([{ offset: f, length: h }], i))[0];
|
|
910
|
+
let d;
|
|
911
|
+
return l === null || !l[c] ? (d = (async () => {
|
|
912
|
+
let g = await n.decode(this.fileDirectory, u);
|
|
913
|
+
const y = this.getSampleFormat(), p = this.getBitsPerSample();
|
|
914
|
+
return xr(y, p) && (g = Sr(
|
|
915
|
+
g,
|
|
916
|
+
y,
|
|
917
|
+
this.planarConfiguration,
|
|
918
|
+
this.getSamplesPerPixel(),
|
|
919
|
+
p,
|
|
920
|
+
this.getTileWidth(),
|
|
921
|
+
this.getBlockHeight(t)
|
|
922
|
+
)), g;
|
|
923
|
+
})(), l !== null && (l[c] = d)) : d = l[c], { x: e, y: t, sample: s, data: await d };
|
|
924
|
+
}
|
|
925
|
+
/**
|
|
926
|
+
* Internal read function.
|
|
927
|
+
* @private
|
|
928
|
+
* @param {Array} imageWindow The image window in pixel coordinates
|
|
929
|
+
* @param {Array} samples The selected samples (0-based indices)
|
|
930
|
+
* @param {TypedArray|TypedArray[]} valueArrays The array(s) to write into
|
|
931
|
+
* @param {Boolean} interleave Whether or not to write in an interleaved manner
|
|
932
|
+
* @param {import("./geotiff").Pool|AbstractDecoder} poolOrDecoder the decoder or decoder pool
|
|
933
|
+
* @param {number} width the width of window to be read into
|
|
934
|
+
* @param {number} height the height of window to be read into
|
|
935
|
+
* @param {number} resampleMethod the resampling method to be used when interpolating
|
|
936
|
+
* @param {AbortSignal} [signal] An AbortSignal that may be signalled if the request is
|
|
937
|
+
* to be aborted
|
|
938
|
+
* @returns {Promise<ReadRasterResult>}
|
|
939
|
+
*/
|
|
940
|
+
async _readRaster(e, t, s, n, i, a, o, c, l) {
|
|
941
|
+
const f = this.getTileWidth(), h = this.getTileHeight(), u = this.getWidth(), d = this.getHeight(), g = Math.max(Math.floor(e[0] / f), 0), y = Math.min(
|
|
942
|
+
Math.ceil(e[2] / f),
|
|
943
|
+
Math.ceil(u / f)
|
|
944
|
+
), p = Math.max(Math.floor(e[1] / h), 0), x = Math.min(
|
|
945
|
+
Math.ceil(e[3] / h),
|
|
946
|
+
Math.ceil(d / h)
|
|
947
|
+
), w = e[2] - e[0];
|
|
948
|
+
let S = this.getBytesPerPixel();
|
|
949
|
+
const I = [], b = [];
|
|
950
|
+
for (let D = 0; D < t.length; ++D)
|
|
951
|
+
this.planarConfiguration === 1 ? I.push(mr(this.fileDirectory.BitsPerSample, 0, t[D]) / 8) : I.push(0), b.push(this.getReaderForSample(t[D]));
|
|
952
|
+
const E = [], { littleEndian: V } = this;
|
|
953
|
+
for (let D = p; D < x; ++D)
|
|
954
|
+
for (let W = g; W < y; ++W) {
|
|
955
|
+
let me;
|
|
956
|
+
this.planarConfiguration === 1 && (me = this.getTileOrStrip(W, D, 0, i, l));
|
|
957
|
+
for (let ee = 0; ee < t.length; ++ee) {
|
|
958
|
+
const te = ee, Be = t[ee];
|
|
959
|
+
this.planarConfiguration === 2 && (S = this.getSampleByteSize(Be), me = this.getTileOrStrip(W, D, Be, i, l));
|
|
960
|
+
const mt = me.then((j) => {
|
|
961
|
+
const xt = j.data, St = new DataView(xt), xe = this.getBlockHeight(j.y), H = j.y * h, re = j.x * f, It = H + xe, bt = (j.x + 1) * f, Tt = b[te], At = Math.min(xe, xe - (It - e[3]), d - H), Dt = Math.min(f, f - (bt - e[2]), u - re);
|
|
962
|
+
for (let Y = Math.max(0, e[1] - H); Y < At; ++Y)
|
|
963
|
+
for (let $ = Math.max(0, e[0] - re); $ < Dt; ++$) {
|
|
964
|
+
const Ot = (Y * f + $) * S, Me = Tt.call(
|
|
965
|
+
St,
|
|
966
|
+
Ot + I[te],
|
|
967
|
+
V
|
|
968
|
+
);
|
|
969
|
+
let se;
|
|
970
|
+
n ? (se = (Y + H - e[1]) * w * t.length + ($ + re - e[0]) * t.length + te, s[se] = Me) : (se = (Y + H - e[1]) * w + $ + re - e[0], s[te][se] = Me);
|
|
971
|
+
}
|
|
972
|
+
});
|
|
973
|
+
E.push(mt);
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
if (await Promise.all(E), a && e[2] - e[0] !== a || o && e[3] - e[1] !== o) {
|
|
977
|
+
let D;
|
|
978
|
+
return n ? D = wr(
|
|
979
|
+
s,
|
|
980
|
+
e[2] - e[0],
|
|
981
|
+
e[3] - e[1],
|
|
982
|
+
a,
|
|
983
|
+
o,
|
|
984
|
+
t.length,
|
|
985
|
+
c
|
|
986
|
+
) : D = dr(
|
|
987
|
+
s,
|
|
988
|
+
e[2] - e[0],
|
|
989
|
+
e[3] - e[1],
|
|
990
|
+
a,
|
|
991
|
+
o,
|
|
992
|
+
c
|
|
993
|
+
), D.width = a, D.height = o, D;
|
|
994
|
+
}
|
|
995
|
+
return s.width = a || e[2] - e[0], s.height = o || e[3] - e[1], s;
|
|
996
|
+
}
|
|
997
|
+
/**
|
|
998
|
+
* Reads raster data from the image. This function reads all selected samples
|
|
999
|
+
* into separate arrays of the correct type for that sample or into a single
|
|
1000
|
+
* combined array when `interleave` is set. When provided, only a subset
|
|
1001
|
+
* of the raster is read for each sample.
|
|
1002
|
+
*
|
|
1003
|
+
* @param {ReadRasterOptions} [options={}] optional parameters
|
|
1004
|
+
* @returns {Promise<ReadRasterResult>} the decoded arrays as a promise
|
|
1005
|
+
*/
|
|
1006
|
+
async readRasters({
|
|
1007
|
+
window: e,
|
|
1008
|
+
samples: t = [],
|
|
1009
|
+
interleave: s,
|
|
1010
|
+
pool: n = null,
|
|
1011
|
+
width: i,
|
|
1012
|
+
height: a,
|
|
1013
|
+
resampleMethod: o,
|
|
1014
|
+
fillValue: c,
|
|
1015
|
+
signal: l
|
|
1016
|
+
} = {}) {
|
|
1017
|
+
const f = e || [0, 0, this.getWidth(), this.getHeight()];
|
|
1018
|
+
if (f[0] > f[2] || f[1] > f[3])
|
|
1019
|
+
throw new Error("Invalid subsets");
|
|
1020
|
+
const h = f[2] - f[0], u = f[3] - f[1], d = h * u, g = this.getSamplesPerPixel();
|
|
1021
|
+
if (!t || !t.length)
|
|
1022
|
+
for (let w = 0; w < g; ++w)
|
|
1023
|
+
t.push(w);
|
|
1024
|
+
else
|
|
1025
|
+
for (let w = 0; w < t.length; ++w)
|
|
1026
|
+
if (t[w] >= g)
|
|
1027
|
+
return Promise.reject(new RangeError(`Invalid sample index '${t[w]}'.`));
|
|
1028
|
+
let y;
|
|
1029
|
+
if (s) {
|
|
1030
|
+
const w = this.fileDirectory.SampleFormat ? Math.max.apply(null, this.fileDirectory.SampleFormat) : 1, S = Math.max.apply(null, this.fileDirectory.BitsPerSample);
|
|
1031
|
+
y = Ie(w, S, d * t.length), c && y.fill(c);
|
|
1032
|
+
} else {
|
|
1033
|
+
y = [];
|
|
1034
|
+
for (let w = 0; w < t.length; ++w) {
|
|
1035
|
+
const S = this.getArrayForSample(t[w], d);
|
|
1036
|
+
Array.isArray(c) && w < c.length ? S.fill(c[w]) : c && !Array.isArray(c) && S.fill(c), y.push(S);
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
const p = n || await Fe(this.fileDirectory);
|
|
1040
|
+
return await this._readRaster(
|
|
1041
|
+
f,
|
|
1042
|
+
t,
|
|
1043
|
+
y,
|
|
1044
|
+
s,
|
|
1045
|
+
p,
|
|
1046
|
+
i,
|
|
1047
|
+
a,
|
|
1048
|
+
o,
|
|
1049
|
+
l
|
|
1050
|
+
);
|
|
1051
|
+
}
|
|
1052
|
+
/**
|
|
1053
|
+
* Reads raster data from the image as RGB. The result is always an
|
|
1054
|
+
* interleaved typed array.
|
|
1055
|
+
* Colorspaces other than RGB will be transformed to RGB, color maps expanded.
|
|
1056
|
+
* When no other method is applicable, the first sample is used to produce a
|
|
1057
|
+
* grayscale image.
|
|
1058
|
+
* When provided, only a subset of the raster is read for each sample.
|
|
1059
|
+
*
|
|
1060
|
+
* @param {Object} [options] optional parameters
|
|
1061
|
+
* @param {Array<number>} [options.window] the subset to read data from in pixels.
|
|
1062
|
+
* @param {boolean} [options.interleave=true] whether the data shall be read
|
|
1063
|
+
* in one single array or separate
|
|
1064
|
+
* arrays.
|
|
1065
|
+
* @param {import("./geotiff").Pool} [options.pool=null] The optional decoder pool to use.
|
|
1066
|
+
* @param {number} [options.width] The desired width of the output. When the width is no the
|
|
1067
|
+
* same as the images, resampling will be performed.
|
|
1068
|
+
* @param {number} [options.height] The desired height of the output. When the width is no the
|
|
1069
|
+
* same as the images, resampling will be performed.
|
|
1070
|
+
* @param {string} [options.resampleMethod='nearest'] The desired resampling method.
|
|
1071
|
+
* @param {boolean} [options.enableAlpha=false] Enable reading alpha channel if present.
|
|
1072
|
+
* @param {AbortSignal} [options.signal] An AbortSignal that may be signalled if the request is
|
|
1073
|
+
* to be aborted
|
|
1074
|
+
* @returns {Promise<ReadRasterResult>} the RGB array as a Promise
|
|
1075
|
+
*/
|
|
1076
|
+
async readRGB({
|
|
1077
|
+
window: e,
|
|
1078
|
+
interleave: t = !0,
|
|
1079
|
+
pool: s = null,
|
|
1080
|
+
width: n,
|
|
1081
|
+
height: i,
|
|
1082
|
+
resampleMethod: a,
|
|
1083
|
+
enableAlpha: o = !1,
|
|
1084
|
+
signal: c
|
|
1085
|
+
} = {}) {
|
|
1086
|
+
const l = e || [0, 0, this.getWidth(), this.getHeight()];
|
|
1087
|
+
if (l[0] > l[2] || l[1] > l[3])
|
|
1088
|
+
throw new Error("Invalid subsets");
|
|
1089
|
+
const f = this.fileDirectory.PhotometricInterpretation;
|
|
1090
|
+
if (f === P.RGB) {
|
|
1091
|
+
let x = [0, 1, 2];
|
|
1092
|
+
if (this.fileDirectory.ExtraSamples !== nt.Unspecified && o) {
|
|
1093
|
+
x = [];
|
|
1094
|
+
for (let w = 0; w < this.fileDirectory.BitsPerSample.length; w += 1)
|
|
1095
|
+
x.push(w);
|
|
1096
|
+
}
|
|
1097
|
+
return this.readRasters({
|
|
1098
|
+
window: e,
|
|
1099
|
+
interleave: t,
|
|
1100
|
+
samples: x,
|
|
1101
|
+
pool: s,
|
|
1102
|
+
width: n,
|
|
1103
|
+
height: i,
|
|
1104
|
+
resampleMethod: a,
|
|
1105
|
+
signal: c
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
let h;
|
|
1109
|
+
switch (f) {
|
|
1110
|
+
case P.WhiteIsZero:
|
|
1111
|
+
case P.BlackIsZero:
|
|
1112
|
+
case P.Palette:
|
|
1113
|
+
h = [0];
|
|
1114
|
+
break;
|
|
1115
|
+
case P.CMYK:
|
|
1116
|
+
h = [0, 1, 2, 3];
|
|
1117
|
+
break;
|
|
1118
|
+
case P.YCbCr:
|
|
1119
|
+
case P.CIELab:
|
|
1120
|
+
h = [0, 1, 2];
|
|
1121
|
+
break;
|
|
1122
|
+
default:
|
|
1123
|
+
throw new Error("Invalid or unsupported photometric interpretation.");
|
|
1124
|
+
}
|
|
1125
|
+
const u = {
|
|
1126
|
+
window: l,
|
|
1127
|
+
interleave: !0,
|
|
1128
|
+
samples: h,
|
|
1129
|
+
pool: s,
|
|
1130
|
+
width: n,
|
|
1131
|
+
height: i,
|
|
1132
|
+
resampleMethod: a,
|
|
1133
|
+
signal: c
|
|
1134
|
+
}, { fileDirectory: d } = this, g = await this.readRasters(u), y = 2 ** this.fileDirectory.BitsPerSample[0];
|
|
1135
|
+
let p;
|
|
1136
|
+
switch (f) {
|
|
1137
|
+
case P.WhiteIsZero:
|
|
1138
|
+
p = ot(g, y);
|
|
1139
|
+
break;
|
|
1140
|
+
case P.BlackIsZero:
|
|
1141
|
+
p = at(g, y);
|
|
1142
|
+
break;
|
|
1143
|
+
case P.Palette:
|
|
1144
|
+
p = ct(g, d.ColorMap);
|
|
1145
|
+
break;
|
|
1146
|
+
case P.CMYK:
|
|
1147
|
+
p = lt(g);
|
|
1148
|
+
break;
|
|
1149
|
+
case P.YCbCr:
|
|
1150
|
+
p = ft(g);
|
|
1151
|
+
break;
|
|
1152
|
+
case P.CIELab:
|
|
1153
|
+
p = ht(g);
|
|
1154
|
+
break;
|
|
1155
|
+
default:
|
|
1156
|
+
throw new Error("Unsupported photometric interpretation.");
|
|
1157
|
+
}
|
|
1158
|
+
if (!t) {
|
|
1159
|
+
const x = new Uint8Array(p.length / 3), w = new Uint8Array(p.length / 3), S = new Uint8Array(p.length / 3);
|
|
1160
|
+
for (let I = 0, b = 0; I < p.length; I += 3, ++b)
|
|
1161
|
+
x[b] = p[I], w[b] = p[I + 1], S[b] = p[I + 2];
|
|
1162
|
+
p = [x, w, S];
|
|
1163
|
+
}
|
|
1164
|
+
return p.width = g.width, p.height = g.height, p;
|
|
1165
|
+
}
|
|
1166
|
+
/**
|
|
1167
|
+
* Returns an array of tiepoints.
|
|
1168
|
+
* @returns {Object[]}
|
|
1169
|
+
*/
|
|
1170
|
+
getTiePoints() {
|
|
1171
|
+
if (!this.fileDirectory.ModelTiepoint)
|
|
1172
|
+
return [];
|
|
1173
|
+
const e = [];
|
|
1174
|
+
for (let t = 0; t < this.fileDirectory.ModelTiepoint.length; t += 6)
|
|
1175
|
+
e.push({
|
|
1176
|
+
i: this.fileDirectory.ModelTiepoint[t],
|
|
1177
|
+
j: this.fileDirectory.ModelTiepoint[t + 1],
|
|
1178
|
+
k: this.fileDirectory.ModelTiepoint[t + 2],
|
|
1179
|
+
x: this.fileDirectory.ModelTiepoint[t + 3],
|
|
1180
|
+
y: this.fileDirectory.ModelTiepoint[t + 4],
|
|
1181
|
+
z: this.fileDirectory.ModelTiepoint[t + 5]
|
|
1182
|
+
});
|
|
1183
|
+
return e;
|
|
1184
|
+
}
|
|
1185
|
+
/**
|
|
1186
|
+
* Returns the parsed GDAL metadata items.
|
|
1187
|
+
*
|
|
1188
|
+
* If sample is passed to null, dataset-level metadata will be returned.
|
|
1189
|
+
* Otherwise only metadata specific to the provided sample will be returned.
|
|
1190
|
+
*
|
|
1191
|
+
* @param {number} [sample=null] The sample index.
|
|
1192
|
+
* @returns {Object}
|
|
1193
|
+
*/
|
|
1194
|
+
getGDALMetadata(e = null) {
|
|
1195
|
+
const t = {};
|
|
1196
|
+
if (!this.fileDirectory.GDAL_METADATA)
|
|
1197
|
+
return null;
|
|
1198
|
+
const s = this.fileDirectory.GDAL_METADATA;
|
|
1199
|
+
let n = nr(s, "Item");
|
|
1200
|
+
e === null ? n = n.filter((i) => Se(i, "sample") === void 0) : n = n.filter((i) => Number(Se(i, "sample")) === e);
|
|
1201
|
+
for (let i = 0; i < n.length; ++i) {
|
|
1202
|
+
const a = n[i];
|
|
1203
|
+
t[Se(a, "name")] = a.inner;
|
|
1204
|
+
}
|
|
1205
|
+
return t;
|
|
1206
|
+
}
|
|
1207
|
+
/**
|
|
1208
|
+
* Returns the GDAL nodata value
|
|
1209
|
+
* @returns {number|null}
|
|
1210
|
+
*/
|
|
1211
|
+
getGDALNoData() {
|
|
1212
|
+
if (!this.fileDirectory.GDAL_NODATA)
|
|
1213
|
+
return null;
|
|
1214
|
+
const e = this.fileDirectory.GDAL_NODATA;
|
|
1215
|
+
return Number(e.substring(0, e.length - 1));
|
|
1216
|
+
}
|
|
1217
|
+
/**
|
|
1218
|
+
* Returns the image origin as a XYZ-vector. When the image has no affine
|
|
1219
|
+
* transformation, then an exception is thrown.
|
|
1220
|
+
* @returns {Array<number>} The origin as a vector
|
|
1221
|
+
*/
|
|
1222
|
+
getOrigin() {
|
|
1223
|
+
const e = this.fileDirectory.ModelTiepoint, t = this.fileDirectory.ModelTransformation;
|
|
1224
|
+
if (e && e.length === 6)
|
|
1225
|
+
return [
|
|
1226
|
+
e[3],
|
|
1227
|
+
e[4],
|
|
1228
|
+
e[5]
|
|
1229
|
+
];
|
|
1230
|
+
if (t)
|
|
1231
|
+
return [
|
|
1232
|
+
t[3],
|
|
1233
|
+
t[7],
|
|
1234
|
+
t[11]
|
|
1235
|
+
];
|
|
1236
|
+
throw new Error("The image does not have an affine transformation.");
|
|
1237
|
+
}
|
|
1238
|
+
/**
|
|
1239
|
+
* Returns the image resolution as a XYZ-vector. When the image has no affine
|
|
1240
|
+
* transformation, then an exception is thrown.
|
|
1241
|
+
* @param {GeoTIFFImage} [referenceImage=null] A reference image to calculate the resolution from
|
|
1242
|
+
* in cases when the current image does not have the
|
|
1243
|
+
* required tags on its own.
|
|
1244
|
+
* @returns {Array<number>} The resolution as a vector
|
|
1245
|
+
*/
|
|
1246
|
+
getResolution(e = null) {
|
|
1247
|
+
const t = this.fileDirectory.ModelPixelScale, s = this.fileDirectory.ModelTransformation;
|
|
1248
|
+
if (t)
|
|
1249
|
+
return [
|
|
1250
|
+
t[0],
|
|
1251
|
+
-t[1],
|
|
1252
|
+
t[2]
|
|
1253
|
+
];
|
|
1254
|
+
if (s)
|
|
1255
|
+
return s[1] === 0 && s[4] === 0 ? [
|
|
1256
|
+
s[0],
|
|
1257
|
+
-s[5],
|
|
1258
|
+
s[10]
|
|
1259
|
+
] : [
|
|
1260
|
+
Math.sqrt(s[0] * s[0] + s[4] * s[4]),
|
|
1261
|
+
-Math.sqrt(s[1] * s[1] + s[5] * s[5]),
|
|
1262
|
+
s[10]
|
|
1263
|
+
];
|
|
1264
|
+
if (e) {
|
|
1265
|
+
const [n, i, a] = e.getResolution();
|
|
1266
|
+
return [
|
|
1267
|
+
n * e.getWidth() / this.getWidth(),
|
|
1268
|
+
i * e.getHeight() / this.getHeight(),
|
|
1269
|
+
a * e.getWidth() / this.getWidth()
|
|
1270
|
+
];
|
|
1271
|
+
}
|
|
1272
|
+
throw new Error("The image does not have an affine transformation.");
|
|
1273
|
+
}
|
|
1274
|
+
/**
|
|
1275
|
+
* Returns whether or not the pixels of the image depict an area (or point).
|
|
1276
|
+
* @returns {Boolean} Whether the pixels are a point
|
|
1277
|
+
*/
|
|
1278
|
+
pixelIsArea() {
|
|
1279
|
+
return this.geoKeys.GTRasterTypeGeoKey === 1;
|
|
1280
|
+
}
|
|
1281
|
+
/**
|
|
1282
|
+
* Returns the image bounding box as an array of 4 values: min-x, min-y,
|
|
1283
|
+
* max-x and max-y. When the image has no affine transformation, then an
|
|
1284
|
+
* exception is thrown.
|
|
1285
|
+
* @param {boolean} [tilegrid=false] If true return extent for a tilegrid
|
|
1286
|
+
* without adjustment for ModelTransformation.
|
|
1287
|
+
* @returns {Array<number>} The bounding box
|
|
1288
|
+
*/
|
|
1289
|
+
getBoundingBox(e = !1) {
|
|
1290
|
+
const t = this.getHeight(), s = this.getWidth();
|
|
1291
|
+
if (this.fileDirectory.ModelTransformation && !e) {
|
|
1292
|
+
const [n, i, a, o, c, l, f, h] = this.fileDirectory.ModelTransformation, d = [
|
|
1293
|
+
[0, 0],
|
|
1294
|
+
[0, t],
|
|
1295
|
+
[s, 0],
|
|
1296
|
+
[s, t]
|
|
1297
|
+
].map(([p, x]) => [
|
|
1298
|
+
o + n * p + i * x,
|
|
1299
|
+
h + c * p + l * x
|
|
1300
|
+
]), g = d.map((p) => p[0]), y = d.map((p) => p[1]);
|
|
1301
|
+
return [
|
|
1302
|
+
Math.min(...g),
|
|
1303
|
+
Math.min(...y),
|
|
1304
|
+
Math.max(...g),
|
|
1305
|
+
Math.max(...y)
|
|
1306
|
+
];
|
|
1307
|
+
} else {
|
|
1308
|
+
const n = this.getOrigin(), i = this.getResolution(), a = n[0], o = n[1], c = a + i[0] * s, l = o + i[1] * t;
|
|
1309
|
+
return [
|
|
1310
|
+
Math.min(a, c),
|
|
1311
|
+
Math.min(o, l),
|
|
1312
|
+
Math.max(a, c),
|
|
1313
|
+
Math.max(o, l)
|
|
1314
|
+
];
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
class Ir {
|
|
1319
|
+
constructor(e) {
|
|
1320
|
+
this._dataView = new DataView(e);
|
|
1321
|
+
}
|
|
1322
|
+
get buffer() {
|
|
1323
|
+
return this._dataView.buffer;
|
|
1324
|
+
}
|
|
1325
|
+
getUint64(e, t) {
|
|
1326
|
+
const s = this.getUint32(e, t), n = this.getUint32(e + 4, t);
|
|
1327
|
+
let i;
|
|
1328
|
+
if (t) {
|
|
1329
|
+
if (i = s + 2 ** 32 * n, !Number.isSafeInteger(i))
|
|
1330
|
+
throw new Error(
|
|
1331
|
+
`${i} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`
|
|
1332
|
+
);
|
|
1333
|
+
return i;
|
|
1334
|
+
}
|
|
1335
|
+
if (i = 2 ** 32 * s + n, !Number.isSafeInteger(i))
|
|
1336
|
+
throw new Error(
|
|
1337
|
+
`${i} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`
|
|
1338
|
+
);
|
|
1339
|
+
return i;
|
|
1340
|
+
}
|
|
1341
|
+
// adapted from https://stackoverflow.com/a/55338384/8060591
|
|
1342
|
+
getInt64(e, t) {
|
|
1343
|
+
let s = 0;
|
|
1344
|
+
const n = (this._dataView.getUint8(e + (t ? 7 : 0)) & 128) > 0;
|
|
1345
|
+
let i = !0;
|
|
1346
|
+
for (let a = 0; a < 8; a++) {
|
|
1347
|
+
let o = this._dataView.getUint8(e + (t ? a : 7 - a));
|
|
1348
|
+
n && (i ? o !== 0 && (o = ~(o - 1) & 255, i = !1) : o = ~o & 255), s += o * 256 ** a;
|
|
1349
|
+
}
|
|
1350
|
+
return n && (s = -s), s;
|
|
1351
|
+
}
|
|
1352
|
+
getUint8(e, t) {
|
|
1353
|
+
return this._dataView.getUint8(e, t);
|
|
1354
|
+
}
|
|
1355
|
+
getInt8(e, t) {
|
|
1356
|
+
return this._dataView.getInt8(e, t);
|
|
1357
|
+
}
|
|
1358
|
+
getUint16(e, t) {
|
|
1359
|
+
return this._dataView.getUint16(e, t);
|
|
1360
|
+
}
|
|
1361
|
+
getInt16(e, t) {
|
|
1362
|
+
return this._dataView.getInt16(e, t);
|
|
1363
|
+
}
|
|
1364
|
+
getUint32(e, t) {
|
|
1365
|
+
return this._dataView.getUint32(e, t);
|
|
1366
|
+
}
|
|
1367
|
+
getInt32(e, t) {
|
|
1368
|
+
return this._dataView.getInt32(e, t);
|
|
1369
|
+
}
|
|
1370
|
+
getFloat16(e, t) {
|
|
1371
|
+
return tt(this._dataView, e, t);
|
|
1372
|
+
}
|
|
1373
|
+
getFloat32(e, t) {
|
|
1374
|
+
return this._dataView.getFloat32(e, t);
|
|
1375
|
+
}
|
|
1376
|
+
getFloat64(e, t) {
|
|
1377
|
+
return this._dataView.getFloat64(e, t);
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
class br {
|
|
1381
|
+
constructor(e, t, s, n) {
|
|
1382
|
+
this._dataView = new DataView(e), this._sliceOffset = t, this._littleEndian = s, this._bigTiff = n;
|
|
1383
|
+
}
|
|
1384
|
+
get sliceOffset() {
|
|
1385
|
+
return this._sliceOffset;
|
|
1386
|
+
}
|
|
1387
|
+
get sliceTop() {
|
|
1388
|
+
return this._sliceOffset + this.buffer.byteLength;
|
|
1389
|
+
}
|
|
1390
|
+
get littleEndian() {
|
|
1391
|
+
return this._littleEndian;
|
|
1392
|
+
}
|
|
1393
|
+
get bigTiff() {
|
|
1394
|
+
return this._bigTiff;
|
|
1395
|
+
}
|
|
1396
|
+
get buffer() {
|
|
1397
|
+
return this._dataView.buffer;
|
|
1398
|
+
}
|
|
1399
|
+
covers(e, t) {
|
|
1400
|
+
return this.sliceOffset <= e && this.sliceTop >= e + t;
|
|
1401
|
+
}
|
|
1402
|
+
readUint8(e) {
|
|
1403
|
+
return this._dataView.getUint8(
|
|
1404
|
+
e - this._sliceOffset,
|
|
1405
|
+
this._littleEndian
|
|
1406
|
+
);
|
|
1407
|
+
}
|
|
1408
|
+
readInt8(e) {
|
|
1409
|
+
return this._dataView.getInt8(
|
|
1410
|
+
e - this._sliceOffset,
|
|
1411
|
+
this._littleEndian
|
|
1412
|
+
);
|
|
1413
|
+
}
|
|
1414
|
+
readUint16(e) {
|
|
1415
|
+
return this._dataView.getUint16(
|
|
1416
|
+
e - this._sliceOffset,
|
|
1417
|
+
this._littleEndian
|
|
1418
|
+
);
|
|
1419
|
+
}
|
|
1420
|
+
readInt16(e) {
|
|
1421
|
+
return this._dataView.getInt16(
|
|
1422
|
+
e - this._sliceOffset,
|
|
1423
|
+
this._littleEndian
|
|
1424
|
+
);
|
|
1425
|
+
}
|
|
1426
|
+
readUint32(e) {
|
|
1427
|
+
return this._dataView.getUint32(
|
|
1428
|
+
e - this._sliceOffset,
|
|
1429
|
+
this._littleEndian
|
|
1430
|
+
);
|
|
1431
|
+
}
|
|
1432
|
+
readInt32(e) {
|
|
1433
|
+
return this._dataView.getInt32(
|
|
1434
|
+
e - this._sliceOffset,
|
|
1435
|
+
this._littleEndian
|
|
1436
|
+
);
|
|
1437
|
+
}
|
|
1438
|
+
readFloat32(e) {
|
|
1439
|
+
return this._dataView.getFloat32(
|
|
1440
|
+
e - this._sliceOffset,
|
|
1441
|
+
this._littleEndian
|
|
1442
|
+
);
|
|
1443
|
+
}
|
|
1444
|
+
readFloat64(e) {
|
|
1445
|
+
return this._dataView.getFloat64(
|
|
1446
|
+
e - this._sliceOffset,
|
|
1447
|
+
this._littleEndian
|
|
1448
|
+
);
|
|
1449
|
+
}
|
|
1450
|
+
readUint64(e) {
|
|
1451
|
+
const t = this.readUint32(e), s = this.readUint32(e + 4);
|
|
1452
|
+
let n;
|
|
1453
|
+
if (this._littleEndian) {
|
|
1454
|
+
if (n = t + 2 ** 32 * s, !Number.isSafeInteger(n))
|
|
1455
|
+
throw new Error(
|
|
1456
|
+
`${n} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`
|
|
1457
|
+
);
|
|
1458
|
+
return n;
|
|
1459
|
+
}
|
|
1460
|
+
if (n = 2 ** 32 * t + s, !Number.isSafeInteger(n))
|
|
1461
|
+
throw new Error(
|
|
1462
|
+
`${n} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`
|
|
1463
|
+
);
|
|
1464
|
+
return n;
|
|
1465
|
+
}
|
|
1466
|
+
// adapted from https://stackoverflow.com/a/55338384/8060591
|
|
1467
|
+
readInt64(e) {
|
|
1468
|
+
let t = 0;
|
|
1469
|
+
const s = (this._dataView.getUint8(e + (this._littleEndian ? 7 : 0)) & 128) > 0;
|
|
1470
|
+
let n = !0;
|
|
1471
|
+
for (let i = 0; i < 8; i++) {
|
|
1472
|
+
let a = this._dataView.getUint8(
|
|
1473
|
+
e + (this._littleEndian ? i : 7 - i)
|
|
1474
|
+
);
|
|
1475
|
+
s && (n ? a !== 0 && (a = ~(a - 1) & 255, n = !1) : a = ~a & 255), t += a * 256 ** i;
|
|
1476
|
+
}
|
|
1477
|
+
return s && (t = -t), t;
|
|
1478
|
+
}
|
|
1479
|
+
readOffset(e) {
|
|
1480
|
+
return this._bigTiff ? this.readUint64(e) : this.readUint32(e);
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
const Tr = typeof navigator < "u" && navigator.hardwareConcurrency || 2;
|
|
1484
|
+
class Ar {
|
|
1485
|
+
/**
|
|
1486
|
+
* @constructor
|
|
1487
|
+
* @param {Number} [size] The size of the pool. Defaults to the number of CPUs
|
|
1488
|
+
* available. When this parameter is `null` or 0, then the
|
|
1489
|
+
* decoding will be done in the main thread.
|
|
1490
|
+
* @param {function(): Worker} [createWorker] A function that creates the decoder worker.
|
|
1491
|
+
* Defaults to a worker with all decoders that ship with geotiff.js. The `createWorker()`
|
|
1492
|
+
* function is expected to return a `Worker` compatible with Web Workers. For code that
|
|
1493
|
+
* runs in Node, [web-worker](https://www.npmjs.com/package/web-worker) is a good choice.
|
|
1494
|
+
*
|
|
1495
|
+
* A worker that uses a custom lzw decoder would look like this `my-custom-worker.js` file:
|
|
1496
|
+
* ```js
|
|
1497
|
+
* import { addDecoder, getDecoder } from 'geotiff';
|
|
1498
|
+
* addDecoder(5, () => import ('./my-custom-lzw').then((m) => m.default));
|
|
1499
|
+
* self.addEventListener('message', async (e) => {
|
|
1500
|
+
* const { id, fileDirectory, buffer } = e.data;
|
|
1501
|
+
* const decoder = await getDecoder(fileDirectory);
|
|
1502
|
+
* const decoded = await decoder.decode(fileDirectory, buffer);
|
|
1503
|
+
* self.postMessage({ decoded, id }, [decoded]);
|
|
1504
|
+
* });
|
|
1505
|
+
* ```
|
|
1506
|
+
* The way the above code is built into a worker by the `createWorker()` function
|
|
1507
|
+
* depends on the used bundler. For most bundlers, something like this will work:
|
|
1508
|
+
* ```js
|
|
1509
|
+
* function createWorker() {
|
|
1510
|
+
* return new Worker(new URL('./my-custom-worker.js', import.meta.url));
|
|
1511
|
+
* }
|
|
1512
|
+
* ```
|
|
1513
|
+
*/
|
|
1514
|
+
constructor(e = Tr, t) {
|
|
1515
|
+
this.workers = null, this._awaitingDecoder = null, this.size = e, this.messageId = 0, e && (this._awaitingDecoder = t ? Promise.resolve(t) : new Promise((s) => {
|
|
1516
|
+
import("./decoder-CLokFc0V.js").then((n) => {
|
|
1517
|
+
s(n.create);
|
|
1518
|
+
});
|
|
1519
|
+
}), this._awaitingDecoder.then((s) => {
|
|
1520
|
+
this._awaitingDecoder = null, this.workers = [];
|
|
1521
|
+
for (let n = 0; n < e; n++)
|
|
1522
|
+
this.workers.push({ worker: s(), idle: !0 });
|
|
1523
|
+
}));
|
|
1524
|
+
}
|
|
1525
|
+
/**
|
|
1526
|
+
* Decode the given block of bytes with the set compression method.
|
|
1527
|
+
* @param {ArrayBuffer} buffer the array buffer of bytes to decode.
|
|
1528
|
+
* @returns {Promise<ArrayBuffer>} the decoded result as a `Promise`
|
|
1529
|
+
*/
|
|
1530
|
+
async decode(e, t) {
|
|
1531
|
+
return this._awaitingDecoder && await this._awaitingDecoder, this.size === 0 ? Fe(e).then((s) => s.decode(e, t)) : new Promise((s) => {
|
|
1532
|
+
const n = this.workers.find((o) => o.idle) || this.workers[Math.floor(Math.random() * this.size)];
|
|
1533
|
+
n.idle = !1;
|
|
1534
|
+
const i = this.messageId++, a = (o) => {
|
|
1535
|
+
o.data.id === i && (n.idle = !0, s(o.data.decoded), n.worker.removeEventListener("message", a));
|
|
1536
|
+
};
|
|
1537
|
+
n.worker.addEventListener("message", a), n.worker.postMessage({ fileDirectory: e, buffer: t, id: i }, [t]);
|
|
1538
|
+
});
|
|
1539
|
+
}
|
|
1540
|
+
destroy() {
|
|
1541
|
+
this.workers && (this.workers.forEach((e) => {
|
|
1542
|
+
e.worker.terminate();
|
|
1543
|
+
}), this.workers = null);
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
const ze = `\r
|
|
1547
|
+
\r
|
|
1548
|
+
`;
|
|
1549
|
+
function gt(r) {
|
|
1550
|
+
if (typeof Object.fromEntries < "u")
|
|
1551
|
+
return Object.fromEntries(r);
|
|
1552
|
+
const e = {};
|
|
1553
|
+
for (const [t, s] of r)
|
|
1554
|
+
e[t.toLowerCase()] = s;
|
|
1555
|
+
return e;
|
|
1556
|
+
}
|
|
1557
|
+
function Dr(r) {
|
|
1558
|
+
const e = r.split(`\r
|
|
1559
|
+
`).map((t) => {
|
|
1560
|
+
const s = t.split(":").map((n) => n.trim());
|
|
1561
|
+
return s[0] = s[0].toLowerCase(), s;
|
|
1562
|
+
});
|
|
1563
|
+
return gt(e);
|
|
1564
|
+
}
|
|
1565
|
+
function Or(r) {
|
|
1566
|
+
const [e, ...t] = r.split(";").map((n) => n.trim()), s = t.map((n) => n.split("="));
|
|
1567
|
+
return { type: e, params: gt(s) };
|
|
1568
|
+
}
|
|
1569
|
+
function be(r) {
|
|
1570
|
+
let e, t, s;
|
|
1571
|
+
return r && ([, e, t, s] = r.match(/bytes (\d+)-(\d+)\/(\d+)/), e = parseInt(e, 10), t = parseInt(t, 10), s = parseInt(s, 10)), { start: e, end: t, total: s };
|
|
1572
|
+
}
|
|
1573
|
+
function Er(r, e) {
|
|
1574
|
+
let t = null;
|
|
1575
|
+
const s = new TextDecoder("ascii"), n = [], i = `--${e}`, a = `${i}--`;
|
|
1576
|
+
for (let o = 0; o < 10; ++o)
|
|
1577
|
+
s.decode(
|
|
1578
|
+
new Uint8Array(r, o, i.length)
|
|
1579
|
+
) === i && (t = o);
|
|
1580
|
+
if (t === null)
|
|
1581
|
+
throw new Error("Could not find initial boundary");
|
|
1582
|
+
for (; t < r.byteLength; ) {
|
|
1583
|
+
const o = s.decode(
|
|
1584
|
+
new Uint8Array(
|
|
1585
|
+
r,
|
|
1586
|
+
t,
|
|
1587
|
+
Math.min(i.length + 1024, r.byteLength - t)
|
|
1588
|
+
)
|
|
1589
|
+
);
|
|
1590
|
+
if (o.length === 0 || o.startsWith(a))
|
|
1591
|
+
break;
|
|
1592
|
+
if (!o.startsWith(i))
|
|
1593
|
+
throw new Error("Part does not start with boundary");
|
|
1594
|
+
const c = o.substr(i.length + 2);
|
|
1595
|
+
if (c.length === 0)
|
|
1596
|
+
break;
|
|
1597
|
+
const l = c.indexOf(ze), f = Dr(c.substr(0, l)), { start: h, end: u, total: d } = be(f["content-range"]), g = t + i.length + l + ze.length, y = parseInt(u, 10) + 1 - parseInt(h, 10);
|
|
1598
|
+
n.push({
|
|
1599
|
+
headers: f,
|
|
1600
|
+
data: r.slice(g, g + y),
|
|
1601
|
+
offset: h,
|
|
1602
|
+
length: y,
|
|
1603
|
+
fileSize: d
|
|
1604
|
+
}), t = g + y + 4;
|
|
1605
|
+
}
|
|
1606
|
+
return n;
|
|
1607
|
+
}
|
|
1608
|
+
class Q {
|
|
1609
|
+
/**
|
|
1610
|
+
*
|
|
1611
|
+
* @param {Slice[]} slices
|
|
1612
|
+
* @returns {ArrayBuffer[]}
|
|
1613
|
+
*/
|
|
1614
|
+
async fetch(e, t = void 0) {
|
|
1615
|
+
return Promise.all(
|
|
1616
|
+
e.map((s) => this.fetchSlice(s, t))
|
|
1617
|
+
);
|
|
1618
|
+
}
|
|
1619
|
+
/**
|
|
1620
|
+
*
|
|
1621
|
+
* @param {Slice} slice
|
|
1622
|
+
* @returns {ArrayBuffer}
|
|
1623
|
+
*/
|
|
1624
|
+
async fetchSlice(e) {
|
|
1625
|
+
throw new Error(`fetching of slice ${e} not possible, not implemented`);
|
|
1626
|
+
}
|
|
1627
|
+
/**
|
|
1628
|
+
* Returns the filesize if already determined and null otherwise
|
|
1629
|
+
*/
|
|
1630
|
+
get fileSize() {
|
|
1631
|
+
return null;
|
|
1632
|
+
}
|
|
1633
|
+
async close() {
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
class Pr extends Map {
|
|
1637
|
+
constructor(e = {}) {
|
|
1638
|
+
if (super(), !(e.maxSize && e.maxSize > 0))
|
|
1639
|
+
throw new TypeError("`maxSize` must be a number greater than 0");
|
|
1640
|
+
if (typeof e.maxAge == "number" && e.maxAge === 0)
|
|
1641
|
+
throw new TypeError("`maxAge` must be a number greater than 0");
|
|
1642
|
+
this.maxSize = e.maxSize, this.maxAge = e.maxAge || Number.POSITIVE_INFINITY, this.onEviction = e.onEviction, this.cache = /* @__PURE__ */ new Map(), this.oldCache = /* @__PURE__ */ new Map(), this._size = 0;
|
|
1643
|
+
}
|
|
1644
|
+
// TODO: Use private class methods when targeting Node.js 16.
|
|
1645
|
+
_emitEvictions(e) {
|
|
1646
|
+
if (typeof this.onEviction == "function")
|
|
1647
|
+
for (const [t, s] of e)
|
|
1648
|
+
this.onEviction(t, s.value);
|
|
1649
|
+
}
|
|
1650
|
+
_deleteIfExpired(e, t) {
|
|
1651
|
+
return typeof t.expiry == "number" && t.expiry <= Date.now() ? (typeof this.onEviction == "function" && this.onEviction(e, t.value), this.delete(e)) : !1;
|
|
1652
|
+
}
|
|
1653
|
+
_getOrDeleteIfExpired(e, t) {
|
|
1654
|
+
if (this._deleteIfExpired(e, t) === !1)
|
|
1655
|
+
return t.value;
|
|
1656
|
+
}
|
|
1657
|
+
_getItemValue(e, t) {
|
|
1658
|
+
return t.expiry ? this._getOrDeleteIfExpired(e, t) : t.value;
|
|
1659
|
+
}
|
|
1660
|
+
_peek(e, t) {
|
|
1661
|
+
const s = t.get(e);
|
|
1662
|
+
return this._getItemValue(e, s);
|
|
1663
|
+
}
|
|
1664
|
+
_set(e, t) {
|
|
1665
|
+
this.cache.set(e, t), this._size++, this._size >= this.maxSize && (this._size = 0, this._emitEvictions(this.oldCache), this.oldCache = this.cache, this.cache = /* @__PURE__ */ new Map());
|
|
1666
|
+
}
|
|
1667
|
+
_moveToRecent(e, t) {
|
|
1668
|
+
this.oldCache.delete(e), this._set(e, t);
|
|
1669
|
+
}
|
|
1670
|
+
*_entriesAscending() {
|
|
1671
|
+
for (const e of this.oldCache) {
|
|
1672
|
+
const [t, s] = e;
|
|
1673
|
+
this.cache.has(t) || this._deleteIfExpired(t, s) === !1 && (yield e);
|
|
1674
|
+
}
|
|
1675
|
+
for (const e of this.cache) {
|
|
1676
|
+
const [t, s] = e;
|
|
1677
|
+
this._deleteIfExpired(t, s) === !1 && (yield e);
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
get(e) {
|
|
1681
|
+
if (this.cache.has(e)) {
|
|
1682
|
+
const t = this.cache.get(e);
|
|
1683
|
+
return this._getItemValue(e, t);
|
|
1684
|
+
}
|
|
1685
|
+
if (this.oldCache.has(e)) {
|
|
1686
|
+
const t = this.oldCache.get(e);
|
|
1687
|
+
if (this._deleteIfExpired(e, t) === !1)
|
|
1688
|
+
return this._moveToRecent(e, t), t.value;
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
set(e, t, { maxAge: s = this.maxAge } = {}) {
|
|
1692
|
+
const n = typeof s == "number" && s !== Number.POSITIVE_INFINITY ? Date.now() + s : void 0;
|
|
1693
|
+
return this.cache.has(e) ? this.cache.set(e, {
|
|
1694
|
+
value: t,
|
|
1695
|
+
expiry: n
|
|
1696
|
+
}) : this._set(e, { value: t, expiry: n }), this;
|
|
1697
|
+
}
|
|
1698
|
+
has(e) {
|
|
1699
|
+
return this.cache.has(e) ? !this._deleteIfExpired(e, this.cache.get(e)) : this.oldCache.has(e) ? !this._deleteIfExpired(e, this.oldCache.get(e)) : !1;
|
|
1700
|
+
}
|
|
1701
|
+
peek(e) {
|
|
1702
|
+
if (this.cache.has(e))
|
|
1703
|
+
return this._peek(e, this.cache);
|
|
1704
|
+
if (this.oldCache.has(e))
|
|
1705
|
+
return this._peek(e, this.oldCache);
|
|
1706
|
+
}
|
|
1707
|
+
delete(e) {
|
|
1708
|
+
const t = this.cache.delete(e);
|
|
1709
|
+
return t && this._size--, this.oldCache.delete(e) || t;
|
|
1710
|
+
}
|
|
1711
|
+
clear() {
|
|
1712
|
+
this.cache.clear(), this.oldCache.clear(), this._size = 0;
|
|
1713
|
+
}
|
|
1714
|
+
resize(e) {
|
|
1715
|
+
if (!(e && e > 0))
|
|
1716
|
+
throw new TypeError("`maxSize` must be a number greater than 0");
|
|
1717
|
+
const t = [...this._entriesAscending()], s = t.length - e;
|
|
1718
|
+
s < 0 ? (this.cache = new Map(t), this.oldCache = /* @__PURE__ */ new Map(), this._size = t.length) : (s > 0 && this._emitEvictions(t.slice(0, s)), this.oldCache = new Map(t.slice(s)), this.cache = /* @__PURE__ */ new Map(), this._size = 0), this.maxSize = e;
|
|
1719
|
+
}
|
|
1720
|
+
*keys() {
|
|
1721
|
+
for (const [e] of this)
|
|
1722
|
+
yield e;
|
|
1723
|
+
}
|
|
1724
|
+
*values() {
|
|
1725
|
+
for (const [, e] of this)
|
|
1726
|
+
yield e;
|
|
1727
|
+
}
|
|
1728
|
+
*[Symbol.iterator]() {
|
|
1729
|
+
for (const e of this.cache) {
|
|
1730
|
+
const [t, s] = e;
|
|
1731
|
+
this._deleteIfExpired(t, s) === !1 && (yield [t, s.value]);
|
|
1732
|
+
}
|
|
1733
|
+
for (const e of this.oldCache) {
|
|
1734
|
+
const [t, s] = e;
|
|
1735
|
+
this.cache.has(t) || this._deleteIfExpired(t, s) === !1 && (yield [t, s.value]);
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
*entriesDescending() {
|
|
1739
|
+
let e = [...this.cache];
|
|
1740
|
+
for (let t = e.length - 1; t >= 0; --t) {
|
|
1741
|
+
const s = e[t], [n, i] = s;
|
|
1742
|
+
this._deleteIfExpired(n, i) === !1 && (yield [n, i.value]);
|
|
1743
|
+
}
|
|
1744
|
+
e = [...this.oldCache];
|
|
1745
|
+
for (let t = e.length - 1; t >= 0; --t) {
|
|
1746
|
+
const s = e[t], [n, i] = s;
|
|
1747
|
+
this.cache.has(n) || this._deleteIfExpired(n, i) === !1 && (yield [n, i.value]);
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
*entriesAscending() {
|
|
1751
|
+
for (const [e, t] of this._entriesAscending())
|
|
1752
|
+
yield [e, t.value];
|
|
1753
|
+
}
|
|
1754
|
+
get size() {
|
|
1755
|
+
if (!this._size)
|
|
1756
|
+
return this.oldCache.size;
|
|
1757
|
+
let e = 0;
|
|
1758
|
+
for (const t of this.oldCache.keys())
|
|
1759
|
+
this.cache.has(t) || e++;
|
|
1760
|
+
return Math.min(this._size + e, this.maxSize);
|
|
1761
|
+
}
|
|
1762
|
+
entries() {
|
|
1763
|
+
return this.entriesAscending();
|
|
1764
|
+
}
|
|
1765
|
+
forEach(e, t = this) {
|
|
1766
|
+
for (const [s, n] of this.entriesAscending())
|
|
1767
|
+
e.call(t, n, s, this);
|
|
1768
|
+
}
|
|
1769
|
+
get [Symbol.toStringTag]() {
|
|
1770
|
+
return JSON.stringify([...this.entriesAscending()]);
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
function dt(r, e) {
|
|
1774
|
+
for (const t in e)
|
|
1775
|
+
e.hasOwnProperty(t) && (r[t] = e[t]);
|
|
1776
|
+
}
|
|
1777
|
+
function yt(r, e) {
|
|
1778
|
+
return r.length < e.length ? !1 : r.substr(r.length - e.length) === e;
|
|
1779
|
+
}
|
|
1780
|
+
function Cr(r, e) {
|
|
1781
|
+
const { length: t } = r;
|
|
1782
|
+
for (let s = 0; s < t; s++)
|
|
1783
|
+
e(r[s], s);
|
|
1784
|
+
}
|
|
1785
|
+
function Re(r) {
|
|
1786
|
+
const e = {};
|
|
1787
|
+
for (const t in r)
|
|
1788
|
+
if (r.hasOwnProperty(t)) {
|
|
1789
|
+
const s = r[t];
|
|
1790
|
+
e[s] = t;
|
|
1791
|
+
}
|
|
1792
|
+
return e;
|
|
1793
|
+
}
|
|
1794
|
+
function C(r, e) {
|
|
1795
|
+
const t = [];
|
|
1796
|
+
for (let s = 0; s < r; s++)
|
|
1797
|
+
t.push(e(s));
|
|
1798
|
+
return t;
|
|
1799
|
+
}
|
|
1800
|
+
async function Fr(r) {
|
|
1801
|
+
return new Promise((e) => setTimeout(e, r));
|
|
1802
|
+
}
|
|
1803
|
+
function kr(r, e) {
|
|
1804
|
+
const t = Array.isArray(r) ? r : Array.from(r), s = Array.isArray(e) ? e : Array.from(e);
|
|
1805
|
+
return t.map((n, i) => [n, s[i]]);
|
|
1806
|
+
}
|
|
1807
|
+
class _ extends Error {
|
|
1808
|
+
constructor(e) {
|
|
1809
|
+
super(e), Error.captureStackTrace && Error.captureStackTrace(this, _), this.name = "AbortError";
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
class Rr extends Error {
|
|
1813
|
+
constructor(e, t) {
|
|
1814
|
+
super(t), this.errors = e, this.message = t, this.name = "AggregateError";
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
const Br = Rr;
|
|
1818
|
+
class Mr {
|
|
1819
|
+
/**
|
|
1820
|
+
*
|
|
1821
|
+
* @param {number} offset
|
|
1822
|
+
* @param {number} length
|
|
1823
|
+
* @param {ArrayBuffer} [data]
|
|
1824
|
+
*/
|
|
1825
|
+
constructor(e, t, s = null) {
|
|
1826
|
+
this.offset = e, this.length = t, this.data = s;
|
|
1827
|
+
}
|
|
1828
|
+
/**
|
|
1829
|
+
* @returns {number} the top byte border
|
|
1830
|
+
*/
|
|
1831
|
+
get top() {
|
|
1832
|
+
return this.offset + this.length;
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
class qe {
|
|
1836
|
+
/**
|
|
1837
|
+
*
|
|
1838
|
+
* @param {number} offset
|
|
1839
|
+
* @param {number} length
|
|
1840
|
+
* @param {number[]} blockIds
|
|
1841
|
+
*/
|
|
1842
|
+
constructor(e, t, s) {
|
|
1843
|
+
this.offset = e, this.length = t, this.blockIds = s;
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
class Gr extends Q {
|
|
1847
|
+
/**
|
|
1848
|
+
*
|
|
1849
|
+
* @param {BaseSource} source The underlying source that shall be blocked and cached
|
|
1850
|
+
* @param {object} options
|
|
1851
|
+
* @param {number} [options.blockSize]
|
|
1852
|
+
* @param {number} [options.cacheSize]
|
|
1853
|
+
*/
|
|
1854
|
+
constructor(e, { blockSize: t = 65536, cacheSize: s = 100 } = {}) {
|
|
1855
|
+
super(), this.source = e, this.blockSize = t, this.blockCache = new Pr({
|
|
1856
|
+
maxSize: s,
|
|
1857
|
+
onEviction: (n, i) => {
|
|
1858
|
+
this.evictedBlocks.set(n, i);
|
|
1859
|
+
}
|
|
1860
|
+
}), this.evictedBlocks = /* @__PURE__ */ new Map(), this.blockRequests = /* @__PURE__ */ new Map(), this.blockIdsToFetch = /* @__PURE__ */ new Set(), this.abortedBlockIds = /* @__PURE__ */ new Set();
|
|
1861
|
+
}
|
|
1862
|
+
get fileSize() {
|
|
1863
|
+
return this.source.fileSize;
|
|
1864
|
+
}
|
|
1865
|
+
/**
|
|
1866
|
+
*
|
|
1867
|
+
* @param {import("./basesource").Slice[]} slices
|
|
1868
|
+
*/
|
|
1869
|
+
async fetch(e, t) {
|
|
1870
|
+
const s = [], n = [], i = [];
|
|
1871
|
+
this.evictedBlocks.clear();
|
|
1872
|
+
for (const { offset: u, length: d } of e) {
|
|
1873
|
+
let g = u + d;
|
|
1874
|
+
const { fileSize: y } = this;
|
|
1875
|
+
y !== null && (g = Math.min(g, y));
|
|
1876
|
+
const p = Math.floor(u / this.blockSize) * this.blockSize;
|
|
1877
|
+
for (let x = p; x < g; x += this.blockSize) {
|
|
1878
|
+
const w = Math.floor(x / this.blockSize);
|
|
1879
|
+
!this.blockCache.has(w) && !this.blockRequests.has(w) && (this.blockIdsToFetch.add(w), n.push(w)), this.blockRequests.has(w) && s.push(this.blockRequests.get(w)), i.push(w);
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
await Fr(), this.fetchBlocks(t);
|
|
1883
|
+
const a = [];
|
|
1884
|
+
for (const u of n)
|
|
1885
|
+
this.blockRequests.has(u) && a.push(this.blockRequests.get(u));
|
|
1886
|
+
await Promise.allSettled(s), await Promise.allSettled(a);
|
|
1887
|
+
const o = [], c = i.filter((u) => this.abortedBlockIds.has(u) || !this.blockCache.has(u));
|
|
1888
|
+
if (c.forEach((u) => this.blockIdsToFetch.add(u)), c.length > 0 && t && !t.aborted) {
|
|
1889
|
+
this.fetchBlocks(null);
|
|
1890
|
+
for (const u of c) {
|
|
1891
|
+
const d = this.blockRequests.get(u);
|
|
1892
|
+
if (!d)
|
|
1893
|
+
throw new Error(`Block ${u} is not in the block requests`);
|
|
1894
|
+
o.push(d);
|
|
1895
|
+
}
|
|
1896
|
+
await Promise.allSettled(o);
|
|
1897
|
+
}
|
|
1898
|
+
if (t && t.aborted)
|
|
1899
|
+
throw new _("Request was aborted");
|
|
1900
|
+
const l = i.map((u) => this.blockCache.get(u) || this.evictedBlocks.get(u)), f = l.filter((u) => !u);
|
|
1901
|
+
if (f.length)
|
|
1902
|
+
throw new Br(f, "Request failed");
|
|
1903
|
+
const h = new Map(kr(i, l));
|
|
1904
|
+
return this.readSliceData(e, h);
|
|
1905
|
+
}
|
|
1906
|
+
/**
|
|
1907
|
+
*
|
|
1908
|
+
* @param {AbortSignal} signal
|
|
1909
|
+
*/
|
|
1910
|
+
fetchBlocks(e) {
|
|
1911
|
+
if (this.blockIdsToFetch.size > 0) {
|
|
1912
|
+
const t = this.groupBlocks(this.blockIdsToFetch), s = this.source.fetch(t, e);
|
|
1913
|
+
for (let n = 0; n < t.length; ++n) {
|
|
1914
|
+
const i = t[n];
|
|
1915
|
+
for (const a of i.blockIds)
|
|
1916
|
+
this.blockRequests.set(a, (async () => {
|
|
1917
|
+
try {
|
|
1918
|
+
const o = (await s)[n], c = a * this.blockSize, l = c - o.offset, f = Math.min(l + this.blockSize, o.data.byteLength), h = o.data.slice(l, f), u = new Mr(
|
|
1919
|
+
c,
|
|
1920
|
+
h.byteLength,
|
|
1921
|
+
h,
|
|
1922
|
+
a
|
|
1923
|
+
);
|
|
1924
|
+
this.blockCache.set(a, u), this.abortedBlockIds.delete(a);
|
|
1925
|
+
} catch (o) {
|
|
1926
|
+
if (o.name === "AbortError")
|
|
1927
|
+
o.signal = e, this.blockCache.delete(a), this.abortedBlockIds.add(a);
|
|
1928
|
+
else
|
|
1929
|
+
throw o;
|
|
1930
|
+
} finally {
|
|
1931
|
+
this.blockRequests.delete(a);
|
|
1932
|
+
}
|
|
1933
|
+
})());
|
|
1934
|
+
}
|
|
1935
|
+
this.blockIdsToFetch.clear();
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
/**
|
|
1939
|
+
*
|
|
1940
|
+
* @param {Set} blockIds
|
|
1941
|
+
* @returns {BlockGroup[]}
|
|
1942
|
+
*/
|
|
1943
|
+
groupBlocks(e) {
|
|
1944
|
+
const t = Array.from(e).sort((a, o) => a - o);
|
|
1945
|
+
if (t.length === 0)
|
|
1946
|
+
return [];
|
|
1947
|
+
let s = [], n = null;
|
|
1948
|
+
const i = [];
|
|
1949
|
+
for (const a of t)
|
|
1950
|
+
n === null || n + 1 === a ? (s.push(a), n = a) : (i.push(new qe(
|
|
1951
|
+
s[0] * this.blockSize,
|
|
1952
|
+
s.length * this.blockSize,
|
|
1953
|
+
s
|
|
1954
|
+
)), s = [a], n = a);
|
|
1955
|
+
return i.push(new qe(
|
|
1956
|
+
s[0] * this.blockSize,
|
|
1957
|
+
s.length * this.blockSize,
|
|
1958
|
+
s
|
|
1959
|
+
)), i;
|
|
1960
|
+
}
|
|
1961
|
+
/**
|
|
1962
|
+
*
|
|
1963
|
+
* @param {import("./basesource").Slice[]} slices
|
|
1964
|
+
* @param {Map} blocks
|
|
1965
|
+
*/
|
|
1966
|
+
readSliceData(e, t) {
|
|
1967
|
+
return e.map((s) => {
|
|
1968
|
+
let n = s.offset + s.length;
|
|
1969
|
+
this.fileSize !== null && (n = Math.min(this.fileSize, n));
|
|
1970
|
+
const i = Math.floor(s.offset / this.blockSize), a = Math.floor(n / this.blockSize), o = new ArrayBuffer(s.length), c = new Uint8Array(o);
|
|
1971
|
+
for (let l = i; l <= a; ++l) {
|
|
1972
|
+
const f = t.get(l), h = f.offset - s.offset, u = f.top - n;
|
|
1973
|
+
let d = 0, g = 0, y;
|
|
1974
|
+
h < 0 ? d = -h : h > 0 && (g = h), u < 0 ? y = f.length - d : y = n - f.offset - d;
|
|
1975
|
+
const p = new Uint8Array(f.data, d, y);
|
|
1976
|
+
c.set(p, g);
|
|
1977
|
+
}
|
|
1978
|
+
return o;
|
|
1979
|
+
});
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
class de {
|
|
1983
|
+
/**
|
|
1984
|
+
* Returns whether the response has an ok'ish status code
|
|
1985
|
+
*/
|
|
1986
|
+
get ok() {
|
|
1987
|
+
return this.status >= 200 && this.status <= 299;
|
|
1988
|
+
}
|
|
1989
|
+
/**
|
|
1990
|
+
* Returns the status code of the response
|
|
1991
|
+
*/
|
|
1992
|
+
get status() {
|
|
1993
|
+
throw new Error("not implemented");
|
|
1994
|
+
}
|
|
1995
|
+
/**
|
|
1996
|
+
* Returns the value of the specified header
|
|
1997
|
+
* @param {string} headerName the header name
|
|
1998
|
+
* @returns {string} the header value
|
|
1999
|
+
*/
|
|
2000
|
+
getHeader(e) {
|
|
2001
|
+
throw new Error("not implemented");
|
|
2002
|
+
}
|
|
2003
|
+
/**
|
|
2004
|
+
* @returns {ArrayBuffer} the response data of the request
|
|
2005
|
+
*/
|
|
2006
|
+
async getData() {
|
|
2007
|
+
throw new Error("not implemented");
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
class ye {
|
|
2011
|
+
constructor(e) {
|
|
2012
|
+
this.url = e;
|
|
2013
|
+
}
|
|
2014
|
+
/**
|
|
2015
|
+
* Send a request with the options
|
|
2016
|
+
* @param {{headers: HeadersInit, signal: AbortSignal}} [options={}]
|
|
2017
|
+
* @returns {Promise<BaseResponse>}
|
|
2018
|
+
*/
|
|
2019
|
+
async request({ headers: e, signal: t } = {}) {
|
|
2020
|
+
throw new Error("request is not implemented");
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
class Ur extends de {
|
|
2024
|
+
/**
|
|
2025
|
+
* BaseResponse facade for fetch API Response
|
|
2026
|
+
* @param {Response} response
|
|
2027
|
+
*/
|
|
2028
|
+
constructor(e) {
|
|
2029
|
+
super(), this.response = e;
|
|
2030
|
+
}
|
|
2031
|
+
get status() {
|
|
2032
|
+
return this.response.status;
|
|
2033
|
+
}
|
|
2034
|
+
getHeader(e) {
|
|
2035
|
+
return this.response.headers.get(e);
|
|
2036
|
+
}
|
|
2037
|
+
async getData() {
|
|
2038
|
+
return this.response.arrayBuffer ? await this.response.arrayBuffer() : (await this.response.buffer()).buffer;
|
|
2039
|
+
}
|
|
2040
|
+
}
|
|
2041
|
+
class _r extends ye {
|
|
2042
|
+
constructor(e, t) {
|
|
2043
|
+
super(e), this.credentials = t;
|
|
2044
|
+
}
|
|
2045
|
+
/**
|
|
2046
|
+
* @param {{headers: HeadersInit, signal: AbortSignal}} [options={}]
|
|
2047
|
+
* @returns {Promise<FetchResponse>}
|
|
2048
|
+
*/
|
|
2049
|
+
async request({ headers: e, signal: t } = {}) {
|
|
2050
|
+
const s = await fetch(this.url, {
|
|
2051
|
+
headers: e,
|
|
2052
|
+
credentials: this.credentials,
|
|
2053
|
+
signal: t
|
|
2054
|
+
});
|
|
2055
|
+
return new Ur(s);
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
class vr extends de {
|
|
2059
|
+
/**
|
|
2060
|
+
* BaseResponse facade for XMLHttpRequest
|
|
2061
|
+
* @param {XMLHttpRequest} xhr
|
|
2062
|
+
* @param {ArrayBuffer} data
|
|
2063
|
+
*/
|
|
2064
|
+
constructor(e, t) {
|
|
2065
|
+
super(), this.xhr = e, this.data = t;
|
|
2066
|
+
}
|
|
2067
|
+
get status() {
|
|
2068
|
+
return this.xhr.status;
|
|
2069
|
+
}
|
|
2070
|
+
getHeader(e) {
|
|
2071
|
+
return this.xhr.getResponseHeader(e);
|
|
2072
|
+
}
|
|
2073
|
+
async getData() {
|
|
2074
|
+
return this.data;
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
class Lr extends ye {
|
|
2078
|
+
constructRequest(e, t) {
|
|
2079
|
+
return new Promise((s, n) => {
|
|
2080
|
+
const i = new XMLHttpRequest();
|
|
2081
|
+
i.open("GET", this.url), i.responseType = "arraybuffer";
|
|
2082
|
+
for (const [a, o] of Object.entries(e))
|
|
2083
|
+
i.setRequestHeader(a, o);
|
|
2084
|
+
i.onload = () => {
|
|
2085
|
+
const a = i.response;
|
|
2086
|
+
s(new vr(i, a));
|
|
2087
|
+
}, i.onerror = n, i.onabort = () => n(new _("Request aborted")), i.send(), t && (t.aborted && i.abort(), t.addEventListener("abort", () => i.abort()));
|
|
2088
|
+
});
|
|
2089
|
+
}
|
|
2090
|
+
async request({ headers: e, signal: t } = {}) {
|
|
2091
|
+
return await this.constructRequest(e, t);
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
const K = {};
|
|
2095
|
+
class Nr extends de {
|
|
2096
|
+
/**
|
|
2097
|
+
* BaseResponse facade for node HTTP/HTTPS API Response
|
|
2098
|
+
* @param {http.ServerResponse} response
|
|
2099
|
+
*/
|
|
2100
|
+
constructor(e, t) {
|
|
2101
|
+
super(), this.response = e, this.dataPromise = t;
|
|
2102
|
+
}
|
|
2103
|
+
get status() {
|
|
2104
|
+
return this.response.statusCode;
|
|
2105
|
+
}
|
|
2106
|
+
getHeader(e) {
|
|
2107
|
+
return this.response.headers[e];
|
|
2108
|
+
}
|
|
2109
|
+
async getData() {
|
|
2110
|
+
return await this.dataPromise;
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2113
|
+
class Kr extends ye {
|
|
2114
|
+
constructor(e) {
|
|
2115
|
+
super(e), this.parsedUrl = K.parse(this.url), this.httpApi = (this.parsedUrl.protocol === "http:", K);
|
|
2116
|
+
}
|
|
2117
|
+
constructRequest(e, t) {
|
|
2118
|
+
return new Promise((s, n) => {
|
|
2119
|
+
const i = this.httpApi.get(
|
|
2120
|
+
{
|
|
2121
|
+
...this.parsedUrl,
|
|
2122
|
+
headers: e
|
|
2123
|
+
},
|
|
2124
|
+
(a) => {
|
|
2125
|
+
const o = new Promise((c) => {
|
|
2126
|
+
const l = [];
|
|
2127
|
+
a.on("data", (f) => {
|
|
2128
|
+
l.push(f);
|
|
2129
|
+
}), a.on("end", () => {
|
|
2130
|
+
const f = Buffer.concat(l).buffer;
|
|
2131
|
+
c(f);
|
|
2132
|
+
}), a.on("error", n);
|
|
2133
|
+
});
|
|
2134
|
+
s(new Nr(a, o));
|
|
2135
|
+
}
|
|
2136
|
+
);
|
|
2137
|
+
i.on("error", n), t && (t.aborted && i.destroy(new _("Request aborted")), t.addEventListener("abort", () => i.destroy(new _("Request aborted"))));
|
|
2138
|
+
});
|
|
2139
|
+
}
|
|
2140
|
+
async request({ headers: e, signal: t } = {}) {
|
|
2141
|
+
return await this.constructRequest(e, t);
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
class pe extends Q {
|
|
2145
|
+
/**
|
|
2146
|
+
*
|
|
2147
|
+
* @param {BaseClient} client
|
|
2148
|
+
* @param {object} headers
|
|
2149
|
+
* @param {numbers} maxRanges
|
|
2150
|
+
* @param {boolean} allowFullFile
|
|
2151
|
+
*/
|
|
2152
|
+
constructor(e, t, s, n) {
|
|
2153
|
+
super(), this.client = e, this.headers = t, this.maxRanges = s, this.allowFullFile = n, this._fileSize = null;
|
|
2154
|
+
}
|
|
2155
|
+
/**
|
|
2156
|
+
*
|
|
2157
|
+
* @param {Slice[]} slices
|
|
2158
|
+
*/
|
|
2159
|
+
async fetch(e, t) {
|
|
2160
|
+
return this.maxRanges >= e.length ? this.fetchSlices(e, t) : (this.maxRanges > 0 && e.length > 1, Promise.all(
|
|
2161
|
+
e.map((s) => this.fetchSlice(s, t))
|
|
2162
|
+
));
|
|
2163
|
+
}
|
|
2164
|
+
async fetchSlices(e, t) {
|
|
2165
|
+
const s = await this.client.request({
|
|
2166
|
+
headers: {
|
|
2167
|
+
...this.headers,
|
|
2168
|
+
Range: `bytes=${e.map(({ offset: n, length: i }) => `${n}-${n + i}`).join(",")}`
|
|
2169
|
+
},
|
|
2170
|
+
signal: t
|
|
2171
|
+
});
|
|
2172
|
+
if (s.ok)
|
|
2173
|
+
if (s.status === 206) {
|
|
2174
|
+
const { type: n, params: i } = Or(s.getHeader("content-type"));
|
|
2175
|
+
if (n === "multipart/byteranges") {
|
|
2176
|
+
const h = Er(await s.getData(), i.boundary);
|
|
2177
|
+
return this._fileSize = h[0].fileSize || null, h;
|
|
2178
|
+
}
|
|
2179
|
+
const a = await s.getData(), { start: o, end: c, total: l } = be(s.getHeader("content-range"));
|
|
2180
|
+
this._fileSize = l || null;
|
|
2181
|
+
const f = [{
|
|
2182
|
+
data: a,
|
|
2183
|
+
offset: o,
|
|
2184
|
+
length: c - o
|
|
2185
|
+
}];
|
|
2186
|
+
if (e.length > 1) {
|
|
2187
|
+
const h = await Promise.all(e.slice(1).map((u) => this.fetchSlice(u, t)));
|
|
2188
|
+
return f.concat(h);
|
|
2189
|
+
}
|
|
2190
|
+
return f;
|
|
2191
|
+
} else {
|
|
2192
|
+
if (!this.allowFullFile)
|
|
2193
|
+
throw new Error("Server responded with full file");
|
|
2194
|
+
const n = await s.getData();
|
|
2195
|
+
return this._fileSize = n.byteLength, [{
|
|
2196
|
+
data: n,
|
|
2197
|
+
offset: 0,
|
|
2198
|
+
length: n.byteLength
|
|
2199
|
+
}];
|
|
2200
|
+
}
|
|
2201
|
+
else throw new Error("Error fetching data.");
|
|
2202
|
+
}
|
|
2203
|
+
async fetchSlice(e, t) {
|
|
2204
|
+
const { offset: s, length: n } = e, i = await this.client.request({
|
|
2205
|
+
headers: {
|
|
2206
|
+
...this.headers,
|
|
2207
|
+
Range: `bytes=${s}-${s + n}`
|
|
2208
|
+
},
|
|
2209
|
+
signal: t
|
|
2210
|
+
});
|
|
2211
|
+
if (i.ok)
|
|
2212
|
+
if (i.status === 206) {
|
|
2213
|
+
const a = await i.getData(), { total: o } = be(i.getHeader("content-range"));
|
|
2214
|
+
return this._fileSize = o || null, {
|
|
2215
|
+
data: a,
|
|
2216
|
+
offset: s,
|
|
2217
|
+
length: n
|
|
2218
|
+
};
|
|
2219
|
+
} else {
|
|
2220
|
+
if (!this.allowFullFile)
|
|
2221
|
+
throw new Error("Server responded with full file");
|
|
2222
|
+
const a = await i.getData();
|
|
2223
|
+
return this._fileSize = a.byteLength, {
|
|
2224
|
+
data: a,
|
|
2225
|
+
offset: 0,
|
|
2226
|
+
length: a.byteLength
|
|
2227
|
+
};
|
|
2228
|
+
}
|
|
2229
|
+
else throw new Error("Error fetching data.");
|
|
2230
|
+
}
|
|
2231
|
+
get fileSize() {
|
|
2232
|
+
return this._fileSize;
|
|
2233
|
+
}
|
|
2234
|
+
}
|
|
2235
|
+
function we(r, { blockSize: e, cacheSize: t }) {
|
|
2236
|
+
return e === null ? r : new Gr(r, { blockSize: e, cacheSize: t });
|
|
2237
|
+
}
|
|
2238
|
+
function zr(r, { headers: e = {}, credentials: t, maxRanges: s = 0, allowFullFile: n = !1, ...i } = {}) {
|
|
2239
|
+
const a = new _r(r, t), o = new pe(a, e, s, n);
|
|
2240
|
+
return we(o, i);
|
|
2241
|
+
}
|
|
2242
|
+
function qr(r, { headers: e = {}, maxRanges: t = 0, allowFullFile: s = !1, ...n } = {}) {
|
|
2243
|
+
const i = new Lr(r), a = new pe(i, e, t, s);
|
|
2244
|
+
return we(a, n);
|
|
2245
|
+
}
|
|
2246
|
+
function Vr(r, { headers: e = {}, maxRanges: t = 0, allowFullFile: s = !1, ...n } = {}) {
|
|
2247
|
+
const i = new Kr(r), a = new pe(i, e, t, s);
|
|
2248
|
+
return we(a, n);
|
|
2249
|
+
}
|
|
2250
|
+
function jr(r, { headers: e = {}, maxRanges: t = 0, allowFullFile: s = !1, ...n } = {}) {
|
|
2251
|
+
const i = new pe(r, e, t, s);
|
|
2252
|
+
return we(i, n);
|
|
2253
|
+
}
|
|
2254
|
+
function Te(r, { forceXHR: e = !1, ...t } = {}) {
|
|
2255
|
+
return typeof fetch == "function" && !e ? zr(r, t) : typeof XMLHttpRequest < "u" ? qr(r, t) : Vr(r, t);
|
|
2256
|
+
}
|
|
2257
|
+
class Hr extends Q {
|
|
2258
|
+
constructor(e) {
|
|
2259
|
+
super(), this.arrayBuffer = e;
|
|
2260
|
+
}
|
|
2261
|
+
fetchSlice(e, t) {
|
|
2262
|
+
if (t && t.aborted)
|
|
2263
|
+
throw new _("Request aborted");
|
|
2264
|
+
return this.arrayBuffer.slice(e.offset, e.offset + e.length);
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
function Yr(r) {
|
|
2268
|
+
return new Hr(r);
|
|
2269
|
+
}
|
|
2270
|
+
class $r extends Q {
|
|
2271
|
+
constructor(e) {
|
|
2272
|
+
super(), this.file = e;
|
|
2273
|
+
}
|
|
2274
|
+
async fetchSlice(e, t) {
|
|
2275
|
+
return new Promise((s, n) => {
|
|
2276
|
+
const i = this.file.slice(e.offset, e.offset + e.length), a = new FileReader();
|
|
2277
|
+
a.onload = (o) => s(o.target.result), a.onerror = n, a.onabort = n, a.readAsArrayBuffer(i), t && t.addEventListener("abort", () => a.abort());
|
|
2278
|
+
});
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
function Xr(r) {
|
|
2282
|
+
return new $r(r);
|
|
2283
|
+
}
|
|
2284
|
+
function Zr(r) {
|
|
2285
|
+
return new Promise((e, t) => {
|
|
2286
|
+
K.close(r, (s) => {
|
|
2287
|
+
s ? t(s) : e();
|
|
2288
|
+
});
|
|
2289
|
+
});
|
|
2290
|
+
}
|
|
2291
|
+
function Jr(r, e, t = void 0) {
|
|
2292
|
+
return new Promise((s, n) => {
|
|
2293
|
+
K.open(r, e, t, (i, a) => {
|
|
2294
|
+
i ? n(i) : s(a);
|
|
2295
|
+
});
|
|
2296
|
+
});
|
|
2297
|
+
}
|
|
2298
|
+
function Qr(...r) {
|
|
2299
|
+
return new Promise((e, t) => {
|
|
2300
|
+
K.read(...r, (s, n, i) => {
|
|
2301
|
+
s ? t(s) : e({ bytesRead: n, buffer: i });
|
|
2302
|
+
});
|
|
2303
|
+
});
|
|
2304
|
+
}
|
|
2305
|
+
class Wr extends Q {
|
|
2306
|
+
constructor(e) {
|
|
2307
|
+
super(), this.path = e, this.openRequest = Jr(e, "r");
|
|
2308
|
+
}
|
|
2309
|
+
async fetchSlice(e) {
|
|
2310
|
+
const t = await this.openRequest, { buffer: s } = await Qr(
|
|
2311
|
+
t,
|
|
2312
|
+
Buffer.alloc(e.length),
|
|
2313
|
+
0,
|
|
2314
|
+
e.length,
|
|
2315
|
+
e.offset
|
|
2316
|
+
);
|
|
2317
|
+
return s.buffer;
|
|
2318
|
+
}
|
|
2319
|
+
async close() {
|
|
2320
|
+
const e = await this.openRequest;
|
|
2321
|
+
await Zr(e);
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2324
|
+
function es(r) {
|
|
2325
|
+
return new Wr(r);
|
|
2326
|
+
}
|
|
2327
|
+
const ts = Re(U), rs = Re(L), M = {};
|
|
2328
|
+
dt(M, ts);
|
|
2329
|
+
dt(M, rs);
|
|
2330
|
+
const ss = Re(X), he = 1e3, A = {
|
|
2331
|
+
nextZero: (r, e) => {
|
|
2332
|
+
let t = e;
|
|
2333
|
+
for (; r[t] !== 0; )
|
|
2334
|
+
t++;
|
|
2335
|
+
return t;
|
|
2336
|
+
},
|
|
2337
|
+
readUshort: (r, e) => r[e] << 8 | r[e + 1],
|
|
2338
|
+
readShort: (r, e) => {
|
|
2339
|
+
const t = A.ui8;
|
|
2340
|
+
return t[0] = r[e + 1], t[1] = r[e + 0], A.i16[0];
|
|
2341
|
+
},
|
|
2342
|
+
readInt: (r, e) => {
|
|
2343
|
+
const t = A.ui8;
|
|
2344
|
+
return t[0] = r[e + 3], t[1] = r[e + 2], t[2] = r[e + 1], t[3] = r[e + 0], A.i32[0];
|
|
2345
|
+
},
|
|
2346
|
+
readUint: (r, e) => {
|
|
2347
|
+
const t = A.ui8;
|
|
2348
|
+
return t[0] = r[e + 3], t[1] = r[e + 2], t[2] = r[e + 1], t[3] = r[e + 0], A.ui32[0];
|
|
2349
|
+
},
|
|
2350
|
+
readASCII: (r, e, t) => t.map((s) => String.fromCharCode(r[e + s])).join(""),
|
|
2351
|
+
readFloat: (r, e) => {
|
|
2352
|
+
const t = A.ui8;
|
|
2353
|
+
return C(4, (s) => {
|
|
2354
|
+
t[s] = r[e + 3 - s];
|
|
2355
|
+
}), A.fl32[0];
|
|
2356
|
+
},
|
|
2357
|
+
readDouble: (r, e) => {
|
|
2358
|
+
const t = A.ui8;
|
|
2359
|
+
return C(8, (s) => {
|
|
2360
|
+
t[s] = r[e + 7 - s];
|
|
2361
|
+
}), A.fl64[0];
|
|
2362
|
+
},
|
|
2363
|
+
writeUshort: (r, e, t) => {
|
|
2364
|
+
r[e] = t >> 8 & 255, r[e + 1] = t & 255;
|
|
2365
|
+
},
|
|
2366
|
+
writeUint: (r, e, t) => {
|
|
2367
|
+
r[e] = t >> 24 & 255, r[e + 1] = t >> 16 & 255, r[e + 2] = t >> 8 & 255, r[e + 3] = t >> 0 & 255;
|
|
2368
|
+
},
|
|
2369
|
+
writeASCII: (r, e, t) => {
|
|
2370
|
+
C(t.length, (s) => {
|
|
2371
|
+
r[e + s] = t.charCodeAt(s);
|
|
2372
|
+
});
|
|
2373
|
+
},
|
|
2374
|
+
ui8: new Uint8Array(8)
|
|
2375
|
+
};
|
|
2376
|
+
A.fl64 = new Float64Array(A.ui8.buffer);
|
|
2377
|
+
A.writeDouble = (r, e, t) => {
|
|
2378
|
+
A.fl64[0] = t, C(8, (s) => {
|
|
2379
|
+
r[e + s] = A.ui8[7 - s];
|
|
2380
|
+
});
|
|
2381
|
+
};
|
|
2382
|
+
const ns = (r, e, t, s) => {
|
|
2383
|
+
let n = t;
|
|
2384
|
+
const i = Object.keys(s).filter((o) => o != null && o !== "undefined");
|
|
2385
|
+
r.writeUshort(e, n, i.length), n += 2;
|
|
2386
|
+
let a = n + 12 * i.length + 4;
|
|
2387
|
+
for (const o of i) {
|
|
2388
|
+
let c = null;
|
|
2389
|
+
typeof o == "number" ? c = o : typeof o == "string" && (c = parseInt(o, 10));
|
|
2390
|
+
const l = ue[c], f = ss[l];
|
|
2391
|
+
if (l == null || l === void 0 || typeof l > "u")
|
|
2392
|
+
throw new Error(`unknown type of tag: ${c}`);
|
|
2393
|
+
let h = s[o];
|
|
2394
|
+
if (h === void 0)
|
|
2395
|
+
throw new Error(`failed to get value for key ${o}`);
|
|
2396
|
+
l === "ASCII" && typeof h == "string" && yt(h, "\0") === !1 && (h += "\0");
|
|
2397
|
+
const u = h.length;
|
|
2398
|
+
r.writeUshort(e, n, c), n += 2, r.writeUshort(e, n, f), n += 2, r.writeUint(e, n, u), n += 4;
|
|
2399
|
+
let d = [-1, 1, 1, 2, 4, 8, 0, 0, 0, 0, 0, 0, 8][f] * u, g = n;
|
|
2400
|
+
d > 4 && (r.writeUint(e, n, a), g = a), l === "ASCII" ? r.writeASCII(e, g, h) : l === "SHORT" ? C(u, (y) => {
|
|
2401
|
+
r.writeUshort(e, g + 2 * y, h[y]);
|
|
2402
|
+
}) : l === "LONG" ? C(u, (y) => {
|
|
2403
|
+
r.writeUint(e, g + 4 * y, h[y]);
|
|
2404
|
+
}) : l === "RATIONAL" ? C(u, (y) => {
|
|
2405
|
+
r.writeUint(e, g + 8 * y, Math.round(h[y] * 1e4)), r.writeUint(e, g + 8 * y + 4, 1e4);
|
|
2406
|
+
}) : l === "DOUBLE" && C(u, (y) => {
|
|
2407
|
+
r.writeDouble(e, g + 8 * y, h[y]);
|
|
2408
|
+
}), d > 4 && (d += d & 1, a += d), n += 4;
|
|
2409
|
+
}
|
|
2410
|
+
return [n, a];
|
|
2411
|
+
}, is = (r) => {
|
|
2412
|
+
const e = new Uint8Array(he);
|
|
2413
|
+
let t = 4;
|
|
2414
|
+
const s = A;
|
|
2415
|
+
e[0] = 77, e[1] = 77, e[3] = 42;
|
|
2416
|
+
let n = 8;
|
|
2417
|
+
if (s.writeUint(e, t, n), t += 4, r.forEach((a, o) => {
|
|
2418
|
+
const c = ns(s, e, n, a);
|
|
2419
|
+
n = c[1], o < r.length - 1 && s.writeUint(e, c[0], n);
|
|
2420
|
+
}), e.slice)
|
|
2421
|
+
return e.slice(0, n).buffer;
|
|
2422
|
+
const i = new Uint8Array(n);
|
|
2423
|
+
for (let a = 0; a < n; a++)
|
|
2424
|
+
i[a] = e[a];
|
|
2425
|
+
return i.buffer;
|
|
2426
|
+
}, os = (r, e, t, s) => {
|
|
2427
|
+
if (t == null)
|
|
2428
|
+
throw new Error(`you passed into encodeImage a width of type ${t}`);
|
|
2429
|
+
if (e == null)
|
|
2430
|
+
throw new Error(`you passed into encodeImage a width of type ${e}`);
|
|
2431
|
+
const n = {
|
|
2432
|
+
256: [e],
|
|
2433
|
+
// ImageWidth
|
|
2434
|
+
257: [t],
|
|
2435
|
+
// ImageLength
|
|
2436
|
+
273: [he],
|
|
2437
|
+
// strips offset
|
|
2438
|
+
278: [t],
|
|
2439
|
+
// RowsPerStrip
|
|
2440
|
+
305: "geotiff.js"
|
|
2441
|
+
// no array for ASCII(Z)
|
|
2442
|
+
};
|
|
2443
|
+
if (s)
|
|
2444
|
+
for (const l in s)
|
|
2445
|
+
s.hasOwnProperty(l) && (n[l] = s[l]);
|
|
2446
|
+
const i = new Uint8Array(is([n])), a = new Uint8Array(r), o = n[277], c = new Uint8Array(he + e * t * o);
|
|
2447
|
+
return C(i.length, (l) => {
|
|
2448
|
+
c[l] = i[l];
|
|
2449
|
+
}), Cr(a, (l, f) => {
|
|
2450
|
+
c[he + f] = l;
|
|
2451
|
+
}), c.buffer;
|
|
2452
|
+
}, as = (r) => {
|
|
2453
|
+
const e = {};
|
|
2454
|
+
for (const t in r)
|
|
2455
|
+
t !== "StripOffsets" && (M[t] || console.error(t, "not in name2code:", Object.keys(M)), e[M[t]] = r[t]);
|
|
2456
|
+
return e;
|
|
2457
|
+
}, cs = (r) => Array.isArray(r) ? r : [r], ls = [
|
|
2458
|
+
["Compression", 1],
|
|
2459
|
+
// no compression
|
|
2460
|
+
["PlanarConfiguration", 1],
|
|
2461
|
+
["ExtraSamples", 0]
|
|
2462
|
+
];
|
|
2463
|
+
function fs(r, e) {
|
|
2464
|
+
const t = typeof r[0] == "number";
|
|
2465
|
+
let s, n, i, a;
|
|
2466
|
+
t ? (s = e.height || e.ImageLength, i = e.width || e.ImageWidth, n = r.length / (s * i), a = r) : (n = r.length, s = r[0].length, i = r[0][0].length, a = [], C(s, (f) => {
|
|
2467
|
+
C(i, (h) => {
|
|
2468
|
+
C(n, (u) => {
|
|
2469
|
+
a.push(r[u][f][h]);
|
|
2470
|
+
});
|
|
2471
|
+
});
|
|
2472
|
+
})), e.ImageLength = s, delete e.height, e.ImageWidth = i, delete e.width, e.BitsPerSample || (e.BitsPerSample = C(n, () => 8)), ls.forEach((f) => {
|
|
2473
|
+
const h = f[0];
|
|
2474
|
+
if (!e[h]) {
|
|
2475
|
+
const u = f[1];
|
|
2476
|
+
e[h] = u;
|
|
2477
|
+
}
|
|
2478
|
+
}), e.PhotometricInterpretation || (e.PhotometricInterpretation = e.BitsPerSample.length === 3 ? 2 : 1), e.SamplesPerPixel || (e.SamplesPerPixel = [n]), e.StripByteCounts || (e.StripByteCounts = [n * s * i]), e.ModelPixelScale || (e.ModelPixelScale = [360 / i, 180 / s, 0]), e.SampleFormat || (e.SampleFormat = C(n, () => 1)), !e.hasOwnProperty("GeographicTypeGeoKey") && !e.hasOwnProperty("ProjectedCSTypeGeoKey") && (e.GeographicTypeGeoKey = 4326, e.ModelTiepoint = [0, 0, 0, -180, 90, 0], e.GeogCitationGeoKey = "WGS 84", e.GTModelTypeGeoKey = 2);
|
|
2479
|
+
const o = Object.keys(e).filter((f) => yt(f, "GeoKey")).sort((f, h) => M[f] - M[h]);
|
|
2480
|
+
if (!e.GeoAsciiParams) {
|
|
2481
|
+
let f = "";
|
|
2482
|
+
o.forEach((h) => {
|
|
2483
|
+
const u = Number(M[h]);
|
|
2484
|
+
ue[u] === "ASCII" && (f += `${e[h].toString()}\0`);
|
|
2485
|
+
}), f.length > 0 && (e.GeoAsciiParams = f);
|
|
2486
|
+
}
|
|
2487
|
+
if (!e.GeoKeyDirectory) {
|
|
2488
|
+
const h = [1, 1, 0, o.length];
|
|
2489
|
+
o.forEach((u) => {
|
|
2490
|
+
const d = Number(M[u]);
|
|
2491
|
+
h.push(d);
|
|
2492
|
+
let g, y, p;
|
|
2493
|
+
ue[d] === "SHORT" ? (g = 1, y = 0, p = e[u]) : u === "GeogCitationGeoKey" ? (g = e.GeoAsciiParams.length, y = Number(M.GeoAsciiParams), p = 0) : console.log(`[geotiff.js] couldn't get TIFFTagLocation for ${u}`), h.push(y), h.push(g), h.push(p);
|
|
2494
|
+
}), e.GeoKeyDirectory = h;
|
|
2495
|
+
}
|
|
2496
|
+
for (const f of o)
|
|
2497
|
+
e.hasOwnProperty(f) && delete e[f];
|
|
2498
|
+
[
|
|
2499
|
+
"Compression",
|
|
2500
|
+
"ExtraSamples",
|
|
2501
|
+
"GeographicTypeGeoKey",
|
|
2502
|
+
"GTModelTypeGeoKey",
|
|
2503
|
+
"GTRasterTypeGeoKey",
|
|
2504
|
+
"ImageLength",
|
|
2505
|
+
// synonym of ImageHeight
|
|
2506
|
+
"ImageWidth",
|
|
2507
|
+
"Orientation",
|
|
2508
|
+
"PhotometricInterpretation",
|
|
2509
|
+
"ProjectedCSTypeGeoKey",
|
|
2510
|
+
"PlanarConfiguration",
|
|
2511
|
+
"ResolutionUnit",
|
|
2512
|
+
"SamplesPerPixel",
|
|
2513
|
+
"XPosition",
|
|
2514
|
+
"YPosition",
|
|
2515
|
+
"RowsPerStrip"
|
|
2516
|
+
].forEach((f) => {
|
|
2517
|
+
e[f] && (e[f] = cs(e[f]));
|
|
2518
|
+
});
|
|
2519
|
+
const c = as(e);
|
|
2520
|
+
return os(a, i, s, c);
|
|
2521
|
+
}
|
|
2522
|
+
class hs {
|
|
2523
|
+
log() {
|
|
2524
|
+
}
|
|
2525
|
+
debug() {
|
|
2526
|
+
}
|
|
2527
|
+
info() {
|
|
2528
|
+
}
|
|
2529
|
+
warn() {
|
|
2530
|
+
}
|
|
2531
|
+
error() {
|
|
2532
|
+
}
|
|
2533
|
+
time() {
|
|
2534
|
+
}
|
|
2535
|
+
timeEnd() {
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
function us(r = new hs()) {
|
|
2539
|
+
}
|
|
2540
|
+
function gs(r, e) {
|
|
2541
|
+
let t = r.length - e, s = 0;
|
|
2542
|
+
do {
|
|
2543
|
+
for (let n = e; n > 0; n--)
|
|
2544
|
+
r[s + e] += r[s], s++;
|
|
2545
|
+
t -= e;
|
|
2546
|
+
} while (t > 0);
|
|
2547
|
+
}
|
|
2548
|
+
function ds(r, e, t) {
|
|
2549
|
+
let s = 0, n = r.length;
|
|
2550
|
+
const i = n / t;
|
|
2551
|
+
for (; n > e; ) {
|
|
2552
|
+
for (let o = e; o > 0; --o)
|
|
2553
|
+
r[s + e] += r[s], ++s;
|
|
2554
|
+
n -= e;
|
|
2555
|
+
}
|
|
2556
|
+
const a = r.slice();
|
|
2557
|
+
for (let o = 0; o < i; ++o)
|
|
2558
|
+
for (let c = 0; c < t; ++c)
|
|
2559
|
+
r[t * o + c] = a[(t - c - 1) * i + o];
|
|
2560
|
+
}
|
|
2561
|
+
function ys(r, e, t, s, n, i) {
|
|
2562
|
+
if (e === 1)
|
|
2563
|
+
return r;
|
|
2564
|
+
for (let c = 0; c < n.length; ++c) {
|
|
2565
|
+
if (n[c] % 8 !== 0)
|
|
2566
|
+
throw new Error("When decoding with predictor, only multiple of 8 bits are supported.");
|
|
2567
|
+
if (n[c] !== n[0])
|
|
2568
|
+
throw new Error("When decoding with predictor, all samples must have the same size.");
|
|
2569
|
+
}
|
|
2570
|
+
const a = n[0] / 8, o = i === 2 ? 1 : n.length;
|
|
2571
|
+
for (let c = 0; c < s && !(c * o * t * a >= r.byteLength); ++c) {
|
|
2572
|
+
let l;
|
|
2573
|
+
if (e === 2) {
|
|
2574
|
+
switch (n[0]) {
|
|
2575
|
+
case 8:
|
|
2576
|
+
l = new Uint8Array(
|
|
2577
|
+
r,
|
|
2578
|
+
c * o * t * a,
|
|
2579
|
+
o * t * a
|
|
2580
|
+
);
|
|
2581
|
+
break;
|
|
2582
|
+
case 16:
|
|
2583
|
+
l = new Uint16Array(
|
|
2584
|
+
r,
|
|
2585
|
+
c * o * t * a,
|
|
2586
|
+
o * t * a / 2
|
|
2587
|
+
);
|
|
2588
|
+
break;
|
|
2589
|
+
case 32:
|
|
2590
|
+
l = new Uint32Array(
|
|
2591
|
+
r,
|
|
2592
|
+
c * o * t * a,
|
|
2593
|
+
o * t * a / 4
|
|
2594
|
+
);
|
|
2595
|
+
break;
|
|
2596
|
+
default:
|
|
2597
|
+
throw new Error(`Predictor 2 not allowed with ${n[0]} bits per sample.`);
|
|
2598
|
+
}
|
|
2599
|
+
gs(l, o);
|
|
2600
|
+
} else e === 3 && (l = new Uint8Array(
|
|
2601
|
+
r,
|
|
2602
|
+
c * o * t * a,
|
|
2603
|
+
o * t * a
|
|
2604
|
+
), ds(l, o, a));
|
|
2605
|
+
}
|
|
2606
|
+
return r;
|
|
2607
|
+
}
|
|
2608
|
+
class ps {
|
|
2609
|
+
async decode(e, t) {
|
|
2610
|
+
const s = await this.decodeBlock(t), n = e.Predictor || 1;
|
|
2611
|
+
if (n !== 1) {
|
|
2612
|
+
const i = !e.StripOffsets, a = i ? e.TileWidth : e.ImageWidth, o = i ? e.TileLength : e.RowsPerStrip || e.ImageLength;
|
|
2613
|
+
return ys(
|
|
2614
|
+
s,
|
|
2615
|
+
n,
|
|
2616
|
+
a,
|
|
2617
|
+
o,
|
|
2618
|
+
e.BitsPerSample,
|
|
2619
|
+
e.PlanarConfiguration
|
|
2620
|
+
);
|
|
2621
|
+
}
|
|
2622
|
+
return s;
|
|
2623
|
+
}
|
|
2624
|
+
}
|
|
2625
|
+
function Ae(r) {
|
|
2626
|
+
switch (r) {
|
|
2627
|
+
case m.BYTE:
|
|
2628
|
+
case m.ASCII:
|
|
2629
|
+
case m.SBYTE:
|
|
2630
|
+
case m.UNDEFINED:
|
|
2631
|
+
return 1;
|
|
2632
|
+
case m.SHORT:
|
|
2633
|
+
case m.SSHORT:
|
|
2634
|
+
return 2;
|
|
2635
|
+
case m.LONG:
|
|
2636
|
+
case m.SLONG:
|
|
2637
|
+
case m.FLOAT:
|
|
2638
|
+
case m.IFD:
|
|
2639
|
+
return 4;
|
|
2640
|
+
case m.RATIONAL:
|
|
2641
|
+
case m.SRATIONAL:
|
|
2642
|
+
case m.DOUBLE:
|
|
2643
|
+
case m.LONG8:
|
|
2644
|
+
case m.SLONG8:
|
|
2645
|
+
case m.IFD8:
|
|
2646
|
+
return 8;
|
|
2647
|
+
default:
|
|
2648
|
+
throw new RangeError(`Invalid field type: ${r}`);
|
|
2649
|
+
}
|
|
2650
|
+
}
|
|
2651
|
+
function ws(r) {
|
|
2652
|
+
const e = r.GeoKeyDirectory;
|
|
2653
|
+
if (!e)
|
|
2654
|
+
return null;
|
|
2655
|
+
const t = {};
|
|
2656
|
+
for (let s = 4; s <= e[3] * 4; s += 4) {
|
|
2657
|
+
const n = L[e[s]], i = e[s + 1] ? U[e[s + 1]] : null, a = e[s + 2], o = e[s + 3];
|
|
2658
|
+
let c = null;
|
|
2659
|
+
if (!i)
|
|
2660
|
+
c = o;
|
|
2661
|
+
else {
|
|
2662
|
+
if (c = r[i], typeof c > "u" || c === null)
|
|
2663
|
+
throw new Error(`Could not get value of geoKey '${n}'.`);
|
|
2664
|
+
typeof c == "string" ? c = c.substring(o, o + a - 1) : c.subarray && (c = c.subarray(o, o + a), a === 1 && (c = c[0]));
|
|
2665
|
+
}
|
|
2666
|
+
t[n] = c;
|
|
2667
|
+
}
|
|
2668
|
+
return t;
|
|
2669
|
+
}
|
|
2670
|
+
function v(r, e, t, s) {
|
|
2671
|
+
let n = null, i = null;
|
|
2672
|
+
const a = Ae(e);
|
|
2673
|
+
switch (e) {
|
|
2674
|
+
case m.BYTE:
|
|
2675
|
+
case m.ASCII:
|
|
2676
|
+
case m.UNDEFINED:
|
|
2677
|
+
n = new Uint8Array(t), i = r.readUint8;
|
|
2678
|
+
break;
|
|
2679
|
+
case m.SBYTE:
|
|
2680
|
+
n = new Int8Array(t), i = r.readInt8;
|
|
2681
|
+
break;
|
|
2682
|
+
case m.SHORT:
|
|
2683
|
+
n = new Uint16Array(t), i = r.readUint16;
|
|
2684
|
+
break;
|
|
2685
|
+
case m.SSHORT:
|
|
2686
|
+
n = new Int16Array(t), i = r.readInt16;
|
|
2687
|
+
break;
|
|
2688
|
+
case m.LONG:
|
|
2689
|
+
case m.IFD:
|
|
2690
|
+
n = new Uint32Array(t), i = r.readUint32;
|
|
2691
|
+
break;
|
|
2692
|
+
case m.SLONG:
|
|
2693
|
+
n = new Int32Array(t), i = r.readInt32;
|
|
2694
|
+
break;
|
|
2695
|
+
case m.LONG8:
|
|
2696
|
+
case m.IFD8:
|
|
2697
|
+
n = new Array(t), i = r.readUint64;
|
|
2698
|
+
break;
|
|
2699
|
+
case m.SLONG8:
|
|
2700
|
+
n = new Array(t), i = r.readInt64;
|
|
2701
|
+
break;
|
|
2702
|
+
case m.RATIONAL:
|
|
2703
|
+
n = new Uint32Array(t * 2), i = r.readUint32;
|
|
2704
|
+
break;
|
|
2705
|
+
case m.SRATIONAL:
|
|
2706
|
+
n = new Int32Array(t * 2), i = r.readInt32;
|
|
2707
|
+
break;
|
|
2708
|
+
case m.FLOAT:
|
|
2709
|
+
n = new Float32Array(t), i = r.readFloat32;
|
|
2710
|
+
break;
|
|
2711
|
+
case m.DOUBLE:
|
|
2712
|
+
n = new Float64Array(t), i = r.readFloat64;
|
|
2713
|
+
break;
|
|
2714
|
+
default:
|
|
2715
|
+
throw new RangeError(`Invalid field type: ${e}`);
|
|
2716
|
+
}
|
|
2717
|
+
if (e === m.RATIONAL || e === m.SRATIONAL)
|
|
2718
|
+
for (let o = 0; o < t; o += 2)
|
|
2719
|
+
n[o] = i.call(
|
|
2720
|
+
r,
|
|
2721
|
+
s + o * a
|
|
2722
|
+
), n[o + 1] = i.call(
|
|
2723
|
+
r,
|
|
2724
|
+
s + (o * a + 4)
|
|
2725
|
+
);
|
|
2726
|
+
else
|
|
2727
|
+
for (let o = 0; o < t; ++o)
|
|
2728
|
+
n[o] = i.call(
|
|
2729
|
+
r,
|
|
2730
|
+
s + o * a
|
|
2731
|
+
);
|
|
2732
|
+
return e === m.ASCII ? new TextDecoder("utf-8").decode(n) : n;
|
|
2733
|
+
}
|
|
2734
|
+
class ms {
|
|
2735
|
+
constructor(e, t, s) {
|
|
2736
|
+
this.fileDirectory = e, this.geoKeyDirectory = t, this.nextIFDByteOffset = s;
|
|
2737
|
+
}
|
|
2738
|
+
}
|
|
2739
|
+
class fe extends Error {
|
|
2740
|
+
constructor(e) {
|
|
2741
|
+
super(`No image at index ${e}`), this.index = e;
|
|
2742
|
+
}
|
|
2743
|
+
}
|
|
2744
|
+
class pt {
|
|
2745
|
+
/**
|
|
2746
|
+
* (experimental) Reads raster data from the best fitting image. This function uses
|
|
2747
|
+
* the image with the lowest resolution that is still a higher resolution than the
|
|
2748
|
+
* requested resolution.
|
|
2749
|
+
* When specified, the `bbox` option is translated to the `window` option and the
|
|
2750
|
+
* `resX` and `resY` to `width` and `height` respectively.
|
|
2751
|
+
* Then, the [readRasters]{@link GeoTIFFImage#readRasters} method of the selected
|
|
2752
|
+
* image is called and the result returned.
|
|
2753
|
+
* @see GeoTIFFImage.readRasters
|
|
2754
|
+
* @param {import('./geotiffimage').ReadRasterOptions} [options={}] optional parameters
|
|
2755
|
+
* @returns {Promise<ReadRasterResult>} the decoded array(s), with `height` and `width`, as a promise
|
|
2756
|
+
*/
|
|
2757
|
+
async readRasters(e = {}) {
|
|
2758
|
+
const { window: t, width: s, height: n } = e;
|
|
2759
|
+
let { resX: i, resY: a, bbox: o } = e;
|
|
2760
|
+
const c = await this.getImage();
|
|
2761
|
+
let l = c;
|
|
2762
|
+
const f = await this.getImageCount(), h = c.getBoundingBox();
|
|
2763
|
+
if (t && o)
|
|
2764
|
+
throw new Error('Both "bbox" and "window" passed.');
|
|
2765
|
+
if (s || n) {
|
|
2766
|
+
if (t) {
|
|
2767
|
+
const [g, y] = c.getOrigin(), [p, x] = c.getResolution();
|
|
2768
|
+
o = [
|
|
2769
|
+
g + t[0] * p,
|
|
2770
|
+
y + t[1] * x,
|
|
2771
|
+
g + t[2] * p,
|
|
2772
|
+
y + t[3] * x
|
|
2773
|
+
];
|
|
2774
|
+
}
|
|
2775
|
+
const d = o || h;
|
|
2776
|
+
if (s) {
|
|
2777
|
+
if (i)
|
|
2778
|
+
throw new Error("Both width and resX passed");
|
|
2779
|
+
i = (d[2] - d[0]) / s;
|
|
2780
|
+
}
|
|
2781
|
+
if (n) {
|
|
2782
|
+
if (a)
|
|
2783
|
+
throw new Error("Both width and resY passed");
|
|
2784
|
+
a = (d[3] - d[1]) / n;
|
|
2785
|
+
}
|
|
2786
|
+
}
|
|
2787
|
+
if (i || a) {
|
|
2788
|
+
const d = [];
|
|
2789
|
+
for (let g = 0; g < f; ++g) {
|
|
2790
|
+
const y = await this.getImage(g), { SubfileType: p, NewSubfileType: x } = y.fileDirectory;
|
|
2791
|
+
(g === 0 || p === 2 || x & 1) && d.push(y);
|
|
2792
|
+
}
|
|
2793
|
+
d.sort((g, y) => g.getWidth() - y.getWidth());
|
|
2794
|
+
for (let g = 0; g < d.length; ++g) {
|
|
2795
|
+
const y = d[g], p = (h[2] - h[0]) / y.getWidth(), x = (h[3] - h[1]) / y.getHeight();
|
|
2796
|
+
if (l = y, i && i > p || a && a > x)
|
|
2797
|
+
break;
|
|
2798
|
+
}
|
|
2799
|
+
}
|
|
2800
|
+
let u = t;
|
|
2801
|
+
if (o) {
|
|
2802
|
+
const [d, g] = c.getOrigin(), [y, p] = l.getResolution(c);
|
|
2803
|
+
u = [
|
|
2804
|
+
Math.round((o[0] - d) / y),
|
|
2805
|
+
Math.round((o[1] - g) / p),
|
|
2806
|
+
Math.round((o[2] - d) / y),
|
|
2807
|
+
Math.round((o[3] - g) / p)
|
|
2808
|
+
], u = [
|
|
2809
|
+
Math.min(u[0], u[2]),
|
|
2810
|
+
Math.min(u[1], u[3]),
|
|
2811
|
+
Math.max(u[0], u[2]),
|
|
2812
|
+
Math.max(u[1], u[3])
|
|
2813
|
+
];
|
|
2814
|
+
}
|
|
2815
|
+
return l.readRasters({ ...e, window: u });
|
|
2816
|
+
}
|
|
2817
|
+
}
|
|
2818
|
+
class k extends pt {
|
|
2819
|
+
/**
|
|
2820
|
+
* @constructor
|
|
2821
|
+
* @param {*} source The datasource to read from.
|
|
2822
|
+
* @param {boolean} littleEndian Whether the image uses little endian.
|
|
2823
|
+
* @param {boolean} bigTiff Whether the image uses bigTIFF conventions.
|
|
2824
|
+
* @param {number} firstIFDOffset The numeric byte-offset from the start of the image
|
|
2825
|
+
* to the first IFD.
|
|
2826
|
+
* @param {GeoTIFFOptions} [options] further options.
|
|
2827
|
+
*/
|
|
2828
|
+
constructor(e, t, s, n, i = {}) {
|
|
2829
|
+
super(), this.source = e, this.littleEndian = t, this.bigTiff = s, this.firstIFDOffset = n, this.cache = i.cache || !1, this.ifdRequests = [], this.ghostValues = null;
|
|
2830
|
+
}
|
|
2831
|
+
async getSlice(e, t) {
|
|
2832
|
+
const s = this.bigTiff ? 4048 : 1024;
|
|
2833
|
+
return new br(
|
|
2834
|
+
(await this.source.fetch([{
|
|
2835
|
+
offset: e,
|
|
2836
|
+
length: typeof t < "u" ? t : s
|
|
2837
|
+
}]))[0],
|
|
2838
|
+
e,
|
|
2839
|
+
this.littleEndian,
|
|
2840
|
+
this.bigTiff
|
|
2841
|
+
);
|
|
2842
|
+
}
|
|
2843
|
+
/**
|
|
2844
|
+
* Instructs to parse an image file directory at the given file offset.
|
|
2845
|
+
* As there is no way to ensure that a location is indeed the start of an IFD,
|
|
2846
|
+
* this function must be called with caution (e.g only using the IFD offsets from
|
|
2847
|
+
* the headers or other IFDs).
|
|
2848
|
+
* @param {number} offset the offset to parse the IFD at
|
|
2849
|
+
* @returns {Promise<ImageFileDirectory>} the parsed IFD
|
|
2850
|
+
*/
|
|
2851
|
+
async parseFileDirectoryAt(e) {
|
|
2852
|
+
const t = this.bigTiff ? 20 : 12, s = this.bigTiff ? 8 : 2;
|
|
2853
|
+
let n = await this.getSlice(e);
|
|
2854
|
+
const i = this.bigTiff ? n.readUint64(e) : n.readUint16(e), a = i * t + (this.bigTiff ? 16 : 6);
|
|
2855
|
+
n.covers(e, a) || (n = await this.getSlice(e, a));
|
|
2856
|
+
const o = {};
|
|
2857
|
+
let c = e + (this.bigTiff ? 8 : 2);
|
|
2858
|
+
for (let h = 0; h < i; c += t, ++h) {
|
|
2859
|
+
const u = n.readUint16(c), d = n.readUint16(c + 2), g = this.bigTiff ? n.readUint64(c + 4) : n.readUint32(c + 4);
|
|
2860
|
+
let y, p;
|
|
2861
|
+
const x = Ae(d), w = c + (this.bigTiff ? 12 : 8);
|
|
2862
|
+
if (x * g <= (this.bigTiff ? 8 : 4))
|
|
2863
|
+
y = v(n, d, g, w);
|
|
2864
|
+
else {
|
|
2865
|
+
const S = n.readOffset(w), I = Ae(d) * g;
|
|
2866
|
+
if (n.covers(S, I))
|
|
2867
|
+
y = v(n, d, g, S);
|
|
2868
|
+
else {
|
|
2869
|
+
const b = await this.getSlice(S, I);
|
|
2870
|
+
y = v(b, d, g, S);
|
|
2871
|
+
}
|
|
2872
|
+
}
|
|
2873
|
+
g === 1 && st.indexOf(u) === -1 && !(d === m.RATIONAL || d === m.SRATIONAL) ? p = y[0] : p = y, o[U[u]] = p;
|
|
2874
|
+
}
|
|
2875
|
+
const l = ws(o), f = n.readOffset(
|
|
2876
|
+
e + s + t * i
|
|
2877
|
+
);
|
|
2878
|
+
return new ms(
|
|
2879
|
+
o,
|
|
2880
|
+
l,
|
|
2881
|
+
f
|
|
2882
|
+
);
|
|
2883
|
+
}
|
|
2884
|
+
async requestIFD(e) {
|
|
2885
|
+
if (this.ifdRequests[e])
|
|
2886
|
+
return this.ifdRequests[e];
|
|
2887
|
+
if (e === 0)
|
|
2888
|
+
return this.ifdRequests[e] = this.parseFileDirectoryAt(this.firstIFDOffset), this.ifdRequests[e];
|
|
2889
|
+
if (!this.ifdRequests[e - 1])
|
|
2890
|
+
try {
|
|
2891
|
+
this.ifdRequests[e - 1] = this.requestIFD(e - 1);
|
|
2892
|
+
} catch (t) {
|
|
2893
|
+
throw t instanceof fe ? new fe(e) : t;
|
|
2894
|
+
}
|
|
2895
|
+
return this.ifdRequests[e] = (async () => {
|
|
2896
|
+
const t = await this.ifdRequests[e - 1];
|
|
2897
|
+
if (t.nextIFDByteOffset === 0)
|
|
2898
|
+
throw new fe(e);
|
|
2899
|
+
return this.parseFileDirectoryAt(t.nextIFDByteOffset);
|
|
2900
|
+
})(), this.ifdRequests[e];
|
|
2901
|
+
}
|
|
2902
|
+
/**
|
|
2903
|
+
* Get the n-th internal subfile of an image. By default, the first is returned.
|
|
2904
|
+
*
|
|
2905
|
+
* @param {number} [index=0] the index of the image to return.
|
|
2906
|
+
* @returns {Promise<GeoTIFFImage>} the image at the given index
|
|
2907
|
+
*/
|
|
2908
|
+
async getImage(e = 0) {
|
|
2909
|
+
const t = await this.requestIFD(e);
|
|
2910
|
+
return new ke(
|
|
2911
|
+
t.fileDirectory,
|
|
2912
|
+
t.geoKeyDirectory,
|
|
2913
|
+
this.dataView,
|
|
2914
|
+
this.littleEndian,
|
|
2915
|
+
this.cache,
|
|
2916
|
+
this.source
|
|
2917
|
+
);
|
|
2918
|
+
}
|
|
2919
|
+
/**
|
|
2920
|
+
* Returns the count of the internal subfiles.
|
|
2921
|
+
*
|
|
2922
|
+
* @returns {Promise<number>} the number of internal subfile images
|
|
2923
|
+
*/
|
|
2924
|
+
async getImageCount() {
|
|
2925
|
+
let e = 0, t = !0;
|
|
2926
|
+
for (; t; )
|
|
2927
|
+
try {
|
|
2928
|
+
await this.requestIFD(e), ++e;
|
|
2929
|
+
} catch (s) {
|
|
2930
|
+
if (s instanceof fe)
|
|
2931
|
+
t = !1;
|
|
2932
|
+
else
|
|
2933
|
+
throw s;
|
|
2934
|
+
}
|
|
2935
|
+
return e;
|
|
2936
|
+
}
|
|
2937
|
+
/**
|
|
2938
|
+
* Get the values of the COG ghost area as a parsed map.
|
|
2939
|
+
* See https://gdal.org/drivers/raster/cog.html#header-ghost-area for reference
|
|
2940
|
+
* @returns {Promise<Object>} the parsed ghost area or null, if no such area was found
|
|
2941
|
+
*/
|
|
2942
|
+
async getGhostValues() {
|
|
2943
|
+
const e = this.bigTiff ? 16 : 8;
|
|
2944
|
+
if (this.ghostValues)
|
|
2945
|
+
return this.ghostValues;
|
|
2946
|
+
const t = "GDAL_STRUCTURAL_METADATA_SIZE=", s = t.length + 100;
|
|
2947
|
+
let n = await this.getSlice(e, s);
|
|
2948
|
+
if (t === v(n, m.ASCII, t.length, e)) {
|
|
2949
|
+
const a = v(n, m.ASCII, s, e).split(`
|
|
2950
|
+
`)[0], o = Number(a.split("=")[1].split(" ")[0]) + a.length;
|
|
2951
|
+
o > s && (n = await this.getSlice(e, o));
|
|
2952
|
+
const c = v(n, m.ASCII, o, e);
|
|
2953
|
+
this.ghostValues = {}, c.split(`
|
|
2954
|
+
`).filter((l) => l.length > 0).map((l) => l.split("=")).forEach(([l, f]) => {
|
|
2955
|
+
this.ghostValues[l] = f;
|
|
2956
|
+
});
|
|
2957
|
+
}
|
|
2958
|
+
return this.ghostValues;
|
|
2959
|
+
}
|
|
2960
|
+
/**
|
|
2961
|
+
* Parse a (Geo)TIFF file from the given source.
|
|
2962
|
+
*
|
|
2963
|
+
* @param {*} source The source of data to parse from.
|
|
2964
|
+
* @param {GeoTIFFOptions} [options] Additional options.
|
|
2965
|
+
* @param {AbortSignal} [signal] An AbortSignal that may be signalled if the request is
|
|
2966
|
+
* to be aborted
|
|
2967
|
+
*/
|
|
2968
|
+
static async fromSource(e, t, s) {
|
|
2969
|
+
const n = (await e.fetch([{ offset: 0, length: 1024 }], s))[0], i = new Ir(n), a = i.getUint16(0, 0);
|
|
2970
|
+
let o;
|
|
2971
|
+
if (a === 18761)
|
|
2972
|
+
o = !0;
|
|
2973
|
+
else if (a === 19789)
|
|
2974
|
+
o = !1;
|
|
2975
|
+
else
|
|
2976
|
+
throw new TypeError("Invalid byte order value.");
|
|
2977
|
+
const c = i.getUint16(2, o);
|
|
2978
|
+
let l;
|
|
2979
|
+
if (c === 42)
|
|
2980
|
+
l = !1;
|
|
2981
|
+
else if (c === 43) {
|
|
2982
|
+
if (l = !0, i.getUint16(4, o) !== 8)
|
|
2983
|
+
throw new Error("Unsupported offset byte-size.");
|
|
2984
|
+
} else
|
|
2985
|
+
throw new TypeError("Invalid magic number.");
|
|
2986
|
+
const f = l ? i.getUint64(8, o) : i.getUint32(4, o);
|
|
2987
|
+
return new k(e, o, l, f, t);
|
|
2988
|
+
}
|
|
2989
|
+
/**
|
|
2990
|
+
* Closes the underlying file buffer
|
|
2991
|
+
* N.B. After the GeoTIFF has been completely processed it needs
|
|
2992
|
+
* to be closed but only if it has been constructed from a file.
|
|
2993
|
+
*/
|
|
2994
|
+
close() {
|
|
2995
|
+
return typeof this.source.close == "function" ? this.source.close() : !1;
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
class wt extends pt {
|
|
2999
|
+
/**
|
|
3000
|
+
* Construct a new MultiGeoTIFF from a main and several overview files.
|
|
3001
|
+
* @param {GeoTIFF} mainFile The main GeoTIFF file.
|
|
3002
|
+
* @param {GeoTIFF[]} overviewFiles An array of overview files.
|
|
3003
|
+
*/
|
|
3004
|
+
constructor(e, t) {
|
|
3005
|
+
super(), this.mainFile = e, this.overviewFiles = t, this.imageFiles = [e].concat(t), this.fileDirectoriesPerFile = null, this.fileDirectoriesPerFileParsing = null, this.imageCount = null;
|
|
3006
|
+
}
|
|
3007
|
+
async parseFileDirectoriesPerFile() {
|
|
3008
|
+
const e = [this.mainFile.parseFileDirectoryAt(this.mainFile.firstIFDOffset)].concat(this.overviewFiles.map((t) => t.parseFileDirectoryAt(t.firstIFDOffset)));
|
|
3009
|
+
return this.fileDirectoriesPerFile = await Promise.all(e), this.fileDirectoriesPerFile;
|
|
3010
|
+
}
|
|
3011
|
+
/**
|
|
3012
|
+
* Get the n-th internal subfile of an image. By default, the first is returned.
|
|
3013
|
+
*
|
|
3014
|
+
* @param {number} [index=0] the index of the image to return.
|
|
3015
|
+
* @returns {Promise<GeoTIFFImage>} the image at the given index
|
|
3016
|
+
*/
|
|
3017
|
+
async getImage(e = 0) {
|
|
3018
|
+
await this.getImageCount(), await this.parseFileDirectoriesPerFile();
|
|
3019
|
+
let t = 0, s = 0;
|
|
3020
|
+
for (let n = 0; n < this.imageFiles.length; n++) {
|
|
3021
|
+
const i = this.imageFiles[n];
|
|
3022
|
+
for (let a = 0; a < this.imageCounts[n]; a++) {
|
|
3023
|
+
if (e === t) {
|
|
3024
|
+
const o = await i.requestIFD(s);
|
|
3025
|
+
return new ke(
|
|
3026
|
+
o.fileDirectory,
|
|
3027
|
+
o.geoKeyDirectory,
|
|
3028
|
+
i.dataView,
|
|
3029
|
+
i.littleEndian,
|
|
3030
|
+
i.cache,
|
|
3031
|
+
i.source
|
|
3032
|
+
);
|
|
3033
|
+
}
|
|
3034
|
+
t++, s++;
|
|
3035
|
+
}
|
|
3036
|
+
s = 0;
|
|
3037
|
+
}
|
|
3038
|
+
throw new RangeError("Invalid image index");
|
|
3039
|
+
}
|
|
3040
|
+
/**
|
|
3041
|
+
* Returns the count of the internal subfiles.
|
|
3042
|
+
*
|
|
3043
|
+
* @returns {Promise<number>} the number of internal subfile images
|
|
3044
|
+
*/
|
|
3045
|
+
async getImageCount() {
|
|
3046
|
+
if (this.imageCount !== null)
|
|
3047
|
+
return this.imageCount;
|
|
3048
|
+
const e = [this.mainFile.getImageCount()].concat(this.overviewFiles.map((t) => t.getImageCount()));
|
|
3049
|
+
return this.imageCounts = await Promise.all(e), this.imageCount = this.imageCounts.reduce((t, s) => t + s, 0), this.imageCount;
|
|
3050
|
+
}
|
|
3051
|
+
}
|
|
3052
|
+
async function xs(r, e = {}, t) {
|
|
3053
|
+
return k.fromSource(Te(r, e), t);
|
|
3054
|
+
}
|
|
3055
|
+
async function Ss(r, e = {}, t) {
|
|
3056
|
+
return k.fromSource(jr(r, e), t);
|
|
3057
|
+
}
|
|
3058
|
+
async function Is(r, e) {
|
|
3059
|
+
return k.fromSource(Yr(r), e);
|
|
3060
|
+
}
|
|
3061
|
+
async function bs(r, e) {
|
|
3062
|
+
return k.fromSource(es(r), e);
|
|
3063
|
+
}
|
|
3064
|
+
async function Ts(r, e) {
|
|
3065
|
+
return k.fromSource(Xr(r), e);
|
|
3066
|
+
}
|
|
3067
|
+
async function As(r, e = [], t = {}, s) {
|
|
3068
|
+
const n = await k.fromSource(Te(r, t), s), i = await Promise.all(
|
|
3069
|
+
e.map((a) => k.fromSource(Te(a, t)))
|
|
3070
|
+
);
|
|
3071
|
+
return new wt(n, i);
|
|
3072
|
+
}
|
|
3073
|
+
function Ds(r, e) {
|
|
3074
|
+
return fs(r, e);
|
|
3075
|
+
}
|
|
3076
|
+
const Os = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
3077
|
+
__proto__: null,
|
|
3078
|
+
BaseClient: ye,
|
|
3079
|
+
BaseDecoder: ps,
|
|
3080
|
+
BaseResponse: de,
|
|
3081
|
+
GeoTIFF: k,
|
|
3082
|
+
GeoTIFFImage: ke,
|
|
3083
|
+
MultiGeoTIFF: wt,
|
|
3084
|
+
Pool: Ar,
|
|
3085
|
+
addDecoder: G,
|
|
3086
|
+
default: k,
|
|
3087
|
+
fromArrayBuffer: Is,
|
|
3088
|
+
fromBlob: Ts,
|
|
3089
|
+
fromCustomClient: Ss,
|
|
3090
|
+
fromFile: bs,
|
|
3091
|
+
fromUrl: xs,
|
|
3092
|
+
fromUrls: As,
|
|
3093
|
+
getDecoder: Fe,
|
|
3094
|
+
globals: ar,
|
|
3095
|
+
rgb: hr,
|
|
3096
|
+
setLogger: us,
|
|
3097
|
+
writeArrayBuffer: Ds
|
|
3098
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
3099
|
+
export {
|
|
3100
|
+
ps as B,
|
|
3101
|
+
ir as L,
|
|
3102
|
+
or as a,
|
|
3103
|
+
Os as b,
|
|
3104
|
+
rt as g
|
|
3105
|
+
};
|
|
3106
|
+
//# sourceMappingURL=geotiff-BUZniE5g.js.map
|