@margoengine/points 0.1.0 → 1.0.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/LICENSE +201 -201
- package/NOTICE +4 -4
- package/README.md +877 -794
- package/dist/copc-write.d.ts +95 -0
- package/dist/copc-write.js +318 -0
- package/dist/copc.d.ts +1 -1
- package/dist/copc.js +25 -28
- package/dist/frame.d.ts +5 -0
- package/dist/index.js +66 -66
- package/dist/laz-encode-CHXgHra_.js +446 -0
- package/dist/laz-encode.d.ts +14 -0
- package/dist/laz-model-DCphHLqH.js +385 -0
- package/dist/laz-model.d.ts +47 -0
- package/dist/laz-write.d.ts +46 -0
- package/dist/laz-write.js +75 -0
- package/dist/laz.js +198 -578
- package/dist/material.d.ts +3 -3
- package/dist/octree.js +3 -3
- package/dist/pick.js +20 -20
- package/dist/plugin.d.ts +3 -3
- package/dist/potree-las-RC8sjbYU.js +1 -0
- package/dist/potree-las.d.ts +1 -0
- package/dist/potree.js +1 -1
- package/dist/{shaders-Deu8H36P.js → shaders-DCnbvb0-.js} +50 -46
- package/dist/shared/fog.d.ts +33 -33
- package/dist/shared/pass.d.ts +53 -53
- package/dist/shared/selection-mask.d.ts +52 -52
- package/dist/shared/style-expression.d.ts +18 -18
- package/dist/sprites.d.ts +1 -1
- package/dist/style.js +1 -0
- package/dist/surfels.js +68 -68
- package/package.json +104 -96
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
//#region src/laz-model.ts
|
|
2
|
+
var e = 16777216, t = class {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.prob = 0, this.zeros = 0, this.total = 0, this.cycle = 0, this.until = 0, this.reset();
|
|
5
|
+
}
|
|
6
|
+
reset() {
|
|
7
|
+
this.zeros = 1, this.total = 2, this.prob = 4096, this.cycle = this.until = 4;
|
|
8
|
+
}
|
|
9
|
+
update() {
|
|
10
|
+
(this.total += this.cycle) > 8192 && (this.total = this.total + 1 >>> 1, this.zeros = this.zeros + 1 >>> 1, this.zeros === this.total && this.total++);
|
|
11
|
+
let e = Math.floor(2147483648 / this.total);
|
|
12
|
+
this.prob = Math.floor(this.zeros * e / 2 ** 18), this.cycle = Math.min(5 * this.cycle >>> 2, 64), this.until = this.cycle;
|
|
13
|
+
}
|
|
14
|
+
}, n = class {
|
|
15
|
+
constructor(e, t = !0) {
|
|
16
|
+
if (this.total = 0, this.cycle = 0, this.until = 0, this.symbols = e, this.last = e - 1, this.dist = new Uint32Array(e), this.counts = new Uint32Array(e), t && e > 16) {
|
|
17
|
+
let t = 3;
|
|
18
|
+
for (; e > 1 << t + 2;) t++;
|
|
19
|
+
this.tableSize = 1 << t, this.tableShift = 15 - t, this.table = new Uint32Array(this.tableSize + 2);
|
|
20
|
+
} else this.tableSize = 0, this.tableShift = 0;
|
|
21
|
+
this.reset();
|
|
22
|
+
}
|
|
23
|
+
reset() {
|
|
24
|
+
this.total = 0, this.cycle = this.symbols, this.counts.fill(1), this.update(), this.cycle = this.until = this.symbols + 6 >>> 1;
|
|
25
|
+
}
|
|
26
|
+
update() {
|
|
27
|
+
let { counts: e, dist: t, symbols: n } = this;
|
|
28
|
+
if ((this.total += this.cycle) > 32768) {
|
|
29
|
+
let t = 0;
|
|
30
|
+
for (let r = 0; r < n; r++) t += e[r] = e[r] + 1 >>> 1;
|
|
31
|
+
this.total = t;
|
|
32
|
+
}
|
|
33
|
+
let r = Math.floor(2147483648 / this.total), i = 2 ** 16, a = 0, o = this.table;
|
|
34
|
+
if (o) {
|
|
35
|
+
let s = 0;
|
|
36
|
+
for (let c = 0; c < n; c++) {
|
|
37
|
+
t[c] = Math.floor(r * a / i), a += e[c];
|
|
38
|
+
let n = t[c] >>> this.tableShift;
|
|
39
|
+
for (; s < n;) o[++s] = c - 1;
|
|
40
|
+
}
|
|
41
|
+
for (o[0] = 0; s <= this.tableSize;) o[++s] = n - 1;
|
|
42
|
+
} else for (let o = 0; o < n; o++) t[o] = Math.floor(r * a / i), a += e[o];
|
|
43
|
+
this.cycle = Math.min(5 * this.cycle >>> 2, n + 6 << 3), this.until = this.cycle;
|
|
44
|
+
}
|
|
45
|
+
}, r = class {
|
|
46
|
+
constructor() {
|
|
47
|
+
this.v = /* @__PURE__ */ new Int32Array(5), this.high = !0;
|
|
48
|
+
}
|
|
49
|
+
reset() {
|
|
50
|
+
this.v.fill(0), this.high = !0;
|
|
51
|
+
}
|
|
52
|
+
get() {
|
|
53
|
+
return this.v[2];
|
|
54
|
+
}
|
|
55
|
+
add(e) {
|
|
56
|
+
let t = this.v;
|
|
57
|
+
this.high ? e < t[2] ? (t[4] = t[3], t[3] = t[2], e < t[0] ? (t[2] = t[1], t[1] = t[0], t[0] = e) : e < t[1] ? (t[2] = t[1], t[1] = e) : t[2] = e) : (e < t[3] ? (t[4] = t[3], t[3] = e) : t[4] = e, this.high = !1) : t[2] < e ? (t[0] = t[1], t[1] = t[2], t[4] < e ? (t[2] = t[3], t[3] = t[4], t[4] = e) : t[3] < e ? (t[2] = t[3], t[3] = e) : t[2] = e) : (t[1] < e ? (t[0] = t[1], t[1] = e) : t[0] = e, this.high = !0);
|
|
58
|
+
}
|
|
59
|
+
}, i = (e) => Array.from({ length: e }, () => new r()), a = (e) => e <= 0 ? 0 : e >= 255 ? 255 : e, o = (e, t, r) => e[t] ??= new n(r), s = (e) => {
|
|
60
|
+
for (let t of e) t?.reset();
|
|
61
|
+
}, c = new Uint8Array([
|
|
62
|
+
15,
|
|
63
|
+
14,
|
|
64
|
+
13,
|
|
65
|
+
12,
|
|
66
|
+
11,
|
|
67
|
+
10,
|
|
68
|
+
9,
|
|
69
|
+
8,
|
|
70
|
+
14,
|
|
71
|
+
0,
|
|
72
|
+
1,
|
|
73
|
+
3,
|
|
74
|
+
6,
|
|
75
|
+
10,
|
|
76
|
+
10,
|
|
77
|
+
9,
|
|
78
|
+
13,
|
|
79
|
+
1,
|
|
80
|
+
2,
|
|
81
|
+
4,
|
|
82
|
+
7,
|
|
83
|
+
11,
|
|
84
|
+
11,
|
|
85
|
+
10,
|
|
86
|
+
12,
|
|
87
|
+
3,
|
|
88
|
+
4,
|
|
89
|
+
5,
|
|
90
|
+
8,
|
|
91
|
+
12,
|
|
92
|
+
12,
|
|
93
|
+
11,
|
|
94
|
+
11,
|
|
95
|
+
6,
|
|
96
|
+
7,
|
|
97
|
+
8,
|
|
98
|
+
9,
|
|
99
|
+
13,
|
|
100
|
+
13,
|
|
101
|
+
12,
|
|
102
|
+
10,
|
|
103
|
+
10,
|
|
104
|
+
11,
|
|
105
|
+
12,
|
|
106
|
+
13,
|
|
107
|
+
14,
|
|
108
|
+
14,
|
|
109
|
+
13,
|
|
110
|
+
9,
|
|
111
|
+
10,
|
|
112
|
+
11,
|
|
113
|
+
12,
|
|
114
|
+
13,
|
|
115
|
+
14,
|
|
116
|
+
15,
|
|
117
|
+
14,
|
|
118
|
+
8,
|
|
119
|
+
9,
|
|
120
|
+
10,
|
|
121
|
+
11,
|
|
122
|
+
12,
|
|
123
|
+
13,
|
|
124
|
+
14,
|
|
125
|
+
15
|
|
126
|
+
]), l = (/* @__PURE__ */ new Uint8Array(64)).map((e, t) => Math.abs((t >> 3) - (t & 7))), u = new Uint8Array([
|
|
127
|
+
0,
|
|
128
|
+
1,
|
|
129
|
+
2,
|
|
130
|
+
3,
|
|
131
|
+
4,
|
|
132
|
+
5,
|
|
133
|
+
3,
|
|
134
|
+
4,
|
|
135
|
+
4,
|
|
136
|
+
5,
|
|
137
|
+
5,
|
|
138
|
+
5,
|
|
139
|
+
5,
|
|
140
|
+
5,
|
|
141
|
+
5,
|
|
142
|
+
5,
|
|
143
|
+
1,
|
|
144
|
+
0,
|
|
145
|
+
1,
|
|
146
|
+
3,
|
|
147
|
+
4,
|
|
148
|
+
5,
|
|
149
|
+
3,
|
|
150
|
+
4,
|
|
151
|
+
4,
|
|
152
|
+
5,
|
|
153
|
+
5,
|
|
154
|
+
5,
|
|
155
|
+
5,
|
|
156
|
+
5,
|
|
157
|
+
5,
|
|
158
|
+
5,
|
|
159
|
+
2,
|
|
160
|
+
1,
|
|
161
|
+
2,
|
|
162
|
+
4,
|
|
163
|
+
5,
|
|
164
|
+
3,
|
|
165
|
+
4,
|
|
166
|
+
4,
|
|
167
|
+
5,
|
|
168
|
+
5,
|
|
169
|
+
5,
|
|
170
|
+
5,
|
|
171
|
+
5,
|
|
172
|
+
5,
|
|
173
|
+
5,
|
|
174
|
+
5,
|
|
175
|
+
3,
|
|
176
|
+
3,
|
|
177
|
+
4,
|
|
178
|
+
5,
|
|
179
|
+
4,
|
|
180
|
+
5,
|
|
181
|
+
4,
|
|
182
|
+
4,
|
|
183
|
+
5,
|
|
184
|
+
5,
|
|
185
|
+
5,
|
|
186
|
+
5,
|
|
187
|
+
5,
|
|
188
|
+
5,
|
|
189
|
+
5,
|
|
190
|
+
5,
|
|
191
|
+
4,
|
|
192
|
+
3,
|
|
193
|
+
4,
|
|
194
|
+
4,
|
|
195
|
+
5,
|
|
196
|
+
5,
|
|
197
|
+
4,
|
|
198
|
+
4,
|
|
199
|
+
5,
|
|
200
|
+
5,
|
|
201
|
+
5,
|
|
202
|
+
5,
|
|
203
|
+
5,
|
|
204
|
+
5,
|
|
205
|
+
5,
|
|
206
|
+
5,
|
|
207
|
+
5,
|
|
208
|
+
3,
|
|
209
|
+
4,
|
|
210
|
+
4,
|
|
211
|
+
4,
|
|
212
|
+
5,
|
|
213
|
+
4,
|
|
214
|
+
4,
|
|
215
|
+
5,
|
|
216
|
+
5,
|
|
217
|
+
5,
|
|
218
|
+
5,
|
|
219
|
+
5,
|
|
220
|
+
5,
|
|
221
|
+
5,
|
|
222
|
+
5,
|
|
223
|
+
3,
|
|
224
|
+
3,
|
|
225
|
+
4,
|
|
226
|
+
4,
|
|
227
|
+
4,
|
|
228
|
+
4,
|
|
229
|
+
5,
|
|
230
|
+
4,
|
|
231
|
+
5,
|
|
232
|
+
5,
|
|
233
|
+
5,
|
|
234
|
+
5,
|
|
235
|
+
5,
|
|
236
|
+
5,
|
|
237
|
+
5,
|
|
238
|
+
5,
|
|
239
|
+
4,
|
|
240
|
+
3,
|
|
241
|
+
4,
|
|
242
|
+
4,
|
|
243
|
+
4,
|
|
244
|
+
4,
|
|
245
|
+
4,
|
|
246
|
+
5,
|
|
247
|
+
5,
|
|
248
|
+
5,
|
|
249
|
+
5,
|
|
250
|
+
5,
|
|
251
|
+
5,
|
|
252
|
+
5,
|
|
253
|
+
5,
|
|
254
|
+
5,
|
|
255
|
+
4,
|
|
256
|
+
3,
|
|
257
|
+
4,
|
|
258
|
+
4,
|
|
259
|
+
4,
|
|
260
|
+
4,
|
|
261
|
+
4,
|
|
262
|
+
4,
|
|
263
|
+
5,
|
|
264
|
+
5,
|
|
265
|
+
5,
|
|
266
|
+
5,
|
|
267
|
+
5,
|
|
268
|
+
5,
|
|
269
|
+
5,
|
|
270
|
+
5,
|
|
271
|
+
5,
|
|
272
|
+
3,
|
|
273
|
+
4,
|
|
274
|
+
4,
|
|
275
|
+
4,
|
|
276
|
+
4,
|
|
277
|
+
4,
|
|
278
|
+
4,
|
|
279
|
+
4,
|
|
280
|
+
5,
|
|
281
|
+
5,
|
|
282
|
+
5,
|
|
283
|
+
5,
|
|
284
|
+
5,
|
|
285
|
+
5,
|
|
286
|
+
5,
|
|
287
|
+
5,
|
|
288
|
+
3,
|
|
289
|
+
4,
|
|
290
|
+
4,
|
|
291
|
+
4,
|
|
292
|
+
4,
|
|
293
|
+
4,
|
|
294
|
+
4,
|
|
295
|
+
4,
|
|
296
|
+
4,
|
|
297
|
+
5,
|
|
298
|
+
5,
|
|
299
|
+
5,
|
|
300
|
+
5,
|
|
301
|
+
5,
|
|
302
|
+
5,
|
|
303
|
+
5,
|
|
304
|
+
3,
|
|
305
|
+
4,
|
|
306
|
+
4,
|
|
307
|
+
4,
|
|
308
|
+
4,
|
|
309
|
+
4,
|
|
310
|
+
4,
|
|
311
|
+
4,
|
|
312
|
+
4,
|
|
313
|
+
4,
|
|
314
|
+
5,
|
|
315
|
+
5,
|
|
316
|
+
5,
|
|
317
|
+
5,
|
|
318
|
+
5,
|
|
319
|
+
5,
|
|
320
|
+
3,
|
|
321
|
+
4,
|
|
322
|
+
4,
|
|
323
|
+
4,
|
|
324
|
+
4,
|
|
325
|
+
4,
|
|
326
|
+
4,
|
|
327
|
+
4,
|
|
328
|
+
4,
|
|
329
|
+
4,
|
|
330
|
+
4,
|
|
331
|
+
5,
|
|
332
|
+
5,
|
|
333
|
+
5,
|
|
334
|
+
5,
|
|
335
|
+
5,
|
|
336
|
+
3,
|
|
337
|
+
4,
|
|
338
|
+
4,
|
|
339
|
+
4,
|
|
340
|
+
4,
|
|
341
|
+
4,
|
|
342
|
+
4,
|
|
343
|
+
4,
|
|
344
|
+
4,
|
|
345
|
+
4,
|
|
346
|
+
4,
|
|
347
|
+
4,
|
|
348
|
+
5,
|
|
349
|
+
5,
|
|
350
|
+
5,
|
|
351
|
+
5,
|
|
352
|
+
3,
|
|
353
|
+
4,
|
|
354
|
+
4,
|
|
355
|
+
4,
|
|
356
|
+
4,
|
|
357
|
+
4,
|
|
358
|
+
4,
|
|
359
|
+
4,
|
|
360
|
+
4,
|
|
361
|
+
4,
|
|
362
|
+
4,
|
|
363
|
+
4,
|
|
364
|
+
4,
|
|
365
|
+
5,
|
|
366
|
+
5,
|
|
367
|
+
5,
|
|
368
|
+
3,
|
|
369
|
+
4,
|
|
370
|
+
4,
|
|
371
|
+
4,
|
|
372
|
+
4,
|
|
373
|
+
4,
|
|
374
|
+
4,
|
|
375
|
+
4,
|
|
376
|
+
4,
|
|
377
|
+
4,
|
|
378
|
+
4,
|
|
379
|
+
4,
|
|
380
|
+
4,
|
|
381
|
+
4,
|
|
382
|
+
5
|
|
383
|
+
]), d = (/* @__PURE__ */ new Uint8Array(256)).map((e, t) => Math.min(Math.abs((t >> 4) - (t & 15)), 7));
|
|
384
|
+
//#endregion
|
|
385
|
+
export { u as a, a as c, s as d, c as i, o as l, l as n, e as o, d as r, n as s, t, i as u };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** A coder renormalises when its interval's length falls below this. */
|
|
2
|
+
export declare const MIN_LENGTH = 16777216;
|
|
3
|
+
/** Probabilities take 13 bits for a bit model and 15 for a symbol model. */
|
|
4
|
+
export declare const BIT_SHIFT = 13, SYMBOL_SHIFT = 15;
|
|
5
|
+
/** An adaptive binary model. */
|
|
6
|
+
export declare class BitModel {
|
|
7
|
+
prob: number;
|
|
8
|
+
zeros: number;
|
|
9
|
+
total: number;
|
|
10
|
+
cycle: number;
|
|
11
|
+
until: number;
|
|
12
|
+
constructor();
|
|
13
|
+
reset(): void;
|
|
14
|
+
update(): void;
|
|
15
|
+
}
|
|
16
|
+
/** An adaptive model of `symbols` symbols, with a lookup table to start the search when there are more than 16. */
|
|
17
|
+
export declare class SymbolModel {
|
|
18
|
+
readonly symbols: number;
|
|
19
|
+
readonly last: number;
|
|
20
|
+
readonly dist: Uint32Array;
|
|
21
|
+
readonly counts: Uint32Array;
|
|
22
|
+
readonly table: Uint32Array | undefined;
|
|
23
|
+
readonly tableSize: number;
|
|
24
|
+
readonly tableShift: number;
|
|
25
|
+
total: number;
|
|
26
|
+
cycle: number;
|
|
27
|
+
until: number;
|
|
28
|
+
/** `search` builds the table a decoder starts its symbol search from. */
|
|
29
|
+
constructor(symbols: number, search?: boolean);
|
|
30
|
+
reset(): void;
|
|
31
|
+
update(): void;
|
|
32
|
+
}
|
|
33
|
+
export declare class Median5 {
|
|
34
|
+
private readonly v;
|
|
35
|
+
private high;
|
|
36
|
+
reset(): void;
|
|
37
|
+
get(): number;
|
|
38
|
+
add(x: number): void;
|
|
39
|
+
}
|
|
40
|
+
export declare const median5s: (n: number) => Median5[];
|
|
41
|
+
export declare const clampByte: (n: number) => number;
|
|
42
|
+
export declare const lazy: (models: (SymbolModel | undefined)[], i: number, symbols: number) => SymbolModel;
|
|
43
|
+
export declare const resetAll: (models: readonly (SymbolModel | undefined)[]) => void;
|
|
44
|
+
export declare const MAP10: Uint8Array<ArrayBuffer>;
|
|
45
|
+
export declare const LEVEL10: Uint8Array<ArrayBuffer>;
|
|
46
|
+
export declare const MAP14: Uint8Array<ArrayBuffer>;
|
|
47
|
+
export declare const LEVEL14: Uint8Array<ArrayBuffer>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type LASWriteInput } from './las.js';
|
|
2
|
+
/** Options of {@link compressLAZ} and {@link writeLAZ}. */
|
|
3
|
+
export interface LazWriteOptions {
|
|
4
|
+
/** Points per chunk, 1 to 4,294,967,294. Default 50,000: a reader seeks to a chunk, and smaller chunks compress less. */
|
|
5
|
+
chunkSize?: number;
|
|
6
|
+
/** The point count of each chunk in turn, for variable chunks (as an octree's nodes have); they add up to every point. */
|
|
7
|
+
chunks?: readonly number[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Compresses a LAS file to LAZ, losslessly: every point record, extra bytes included, decompresses byte for byte, and
|
|
11
|
+
* the header, variable length records and extended records are kept. The compressed points are the bytes LASzip writes
|
|
12
|
+
* for the same records and chunks.
|
|
13
|
+
*
|
|
14
|
+
* @param input An uncompressed LAS file, versions 1.0 to 1.5, point formats 0 to 10.
|
|
15
|
+
* @param options Points per chunk, or each chunk's count.
|
|
16
|
+
* @returns The LAZ file.
|
|
17
|
+
* @throws TypeError for bytes that are not an uncompressed LAS file or whose points or records are cut off.
|
|
18
|
+
* @throws RangeError for a bad chunk size or chunk counts.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { compressLAZ } from '@margoengine/points/laz-write';
|
|
23
|
+
*
|
|
24
|
+
* const las = new Uint8Array(await (await fetch('/scans/site.las')).arrayBuffer());
|
|
25
|
+
* const laz = compressLAZ(las);
|
|
26
|
+
* console.log(laz.length / las.length);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function compressLAZ(input: ArrayBuffer | Uint8Array, options?: LazWriteOptions): Uint8Array;
|
|
30
|
+
/**
|
|
31
|
+
* Writes points as LAZ: {@link writeLAS}'s file, compressed by {@link compressLAZ}.
|
|
32
|
+
*
|
|
33
|
+
* @param input World positions and any attributes of the point format, as `writeLAS` takes them.
|
|
34
|
+
* @param options Points per chunk, or each chunk's count.
|
|
35
|
+
* @returns The LAZ file.
|
|
36
|
+
* @throws RangeError for input `writeLAS` refuses and for bad chunk options.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* import { writeLAZ } from '@margoengine/points/laz-write';
|
|
41
|
+
*
|
|
42
|
+
* const laz = writeLAZ({ positions: [0, 0, 0, 1, 2, 3], wkt: 'GEOGCS["WGS 84"]' });
|
|
43
|
+
* console.log(laz.length);
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function writeLAZ(input: LASWriteInput, options?: LazWriteOptions): Uint8Array;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { readLASHeader as e, writeLAS as t } from "./las.js";
|
|
2
|
+
import { i as n, n as r, r as i, t as a } from "./laz-encode-CHXgHra_.js";
|
|
3
|
+
//#region src/laz-write.ts
|
|
4
|
+
function o(e, t) {
|
|
5
|
+
let { chunks: n, chunkSize: r = 5e4 } = t;
|
|
6
|
+
if (n) {
|
|
7
|
+
if (t.chunkSize !== void 0) throw RangeError("Pass chunkSize or chunks, not both");
|
|
8
|
+
let r = 0;
|
|
9
|
+
for (let e of n) {
|
|
10
|
+
if (!Number.isInteger(e) || e < 1) throw RangeError("Every chunk needs a whole number of points, 1 or more");
|
|
11
|
+
r += e;
|
|
12
|
+
}
|
|
13
|
+
if (r !== e) throw RangeError(`chunks hold ${r} points; the file has ${e}`);
|
|
14
|
+
return [...n];
|
|
15
|
+
}
|
|
16
|
+
if (!Number.isInteger(r) || r < 1 || r >= 4294967295) throw RangeError("chunkSize must be a whole number from 1 to 4294967294");
|
|
17
|
+
let i = [];
|
|
18
|
+
for (let t = e; t > 0; t -= r) i.push(Math.min(r, t));
|
|
19
|
+
return i;
|
|
20
|
+
}
|
|
21
|
+
function s(t, s = {}) {
|
|
22
|
+
let c = t instanceof Uint8Array ? t : new Uint8Array(t), { header: l } = e(c);
|
|
23
|
+
if (c[104] & 192) throw TypeError("The file is already compressed; compressLAZ takes an uncompressed LAS file");
|
|
24
|
+
let u = new DataView(c.buffer, c.byteOffset, c.byteLength), { pointDataOffset: d, pointRecordLength: f, pointFormat: p, pointCount: m } = l, h = d + m * f, g = u.getUint16(94, !0), _ = l.versionMinor;
|
|
25
|
+
if (!Number.isSafeInteger(h) || h > c.length) throw TypeError(`The LAS file ends before its ${m} points of ${f} bytes; it is cut off`);
|
|
26
|
+
let v = [], y = g, b = 0;
|
|
27
|
+
for (let e = 0, t = u.getUint32(100, !0); e < t; e++) {
|
|
28
|
+
let e = y + 54 <= d ? 54 + u.getUint16(y + 20, !0) : Infinity;
|
|
29
|
+
if (y + e > d) throw TypeError("A variable length record runs into the points; the LAS file is damaged, so pass an intact one");
|
|
30
|
+
u.getUint16(y + 18, !0) !== 22204 && (v.push(c.subarray(y, y + e)), b++), y += e;
|
|
31
|
+
}
|
|
32
|
+
let x = i(p, f), S = o(m, s), C = n(x, s.chunks ? 4294967295 : s.chunkSize ?? 5e4), w = c.slice(0, g), T = c.subarray(y, d), E = [
|
|
33
|
+
w,
|
|
34
|
+
...v,
|
|
35
|
+
C,
|
|
36
|
+
T
|
|
37
|
+
], D = E.reduce((e, t) => e + t.length, 0), O = c.subarray(d, h), k = new DataView(O.buffer, O.byteOffset, O.byteLength), A = [], j = [], M = 0, N = 0;
|
|
38
|
+
for (let e of S) {
|
|
39
|
+
let t = 0;
|
|
40
|
+
for (let n of a(O, k, M * f, e, f, x)) {
|
|
41
|
+
let e = n.byteLength === n.buffer.byteLength ? n : n.slice();
|
|
42
|
+
A.push(e), t += e.length;
|
|
43
|
+
}
|
|
44
|
+
j.push(t), N += t, M += e;
|
|
45
|
+
}
|
|
46
|
+
let P = r(j, s.chunks ? S : void 0), F = D + 8 + N, I = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(8));
|
|
47
|
+
I.setBigInt64(0, BigInt(F), !0);
|
|
48
|
+
let L = F + P.reduce((e, t) => e + t.length, 0), R = new DataView(w.buffer), z = [];
|
|
49
|
+
if (_ >= 3 && g >= 235) {
|
|
50
|
+
let e = Number(u.getBigUint64(227, !0));
|
|
51
|
+
e && z.push([227, e]);
|
|
52
|
+
}
|
|
53
|
+
_ >= 4 && g >= 375 && u.getUint32(243, !0) && z.push([235, Number(u.getBigUint64(235, !0))]);
|
|
54
|
+
let B = c.length;
|
|
55
|
+
for (let [, e] of z) {
|
|
56
|
+
if (e < h || e > c.length) throw TypeError("The header places extended records outside the bytes after the points; the file is corrupt");
|
|
57
|
+
B = Math.min(B, e);
|
|
58
|
+
}
|
|
59
|
+
for (let [e, t] of z) R.setBigUint64(e, BigInt(L + t - B), !0);
|
|
60
|
+
R.setUint32(96, D, !0), R.setUint32(100, b + 1, !0), R.setUint8(104, p | 128);
|
|
61
|
+
let V = [
|
|
62
|
+
...E,
|
|
63
|
+
new Uint8Array(I.buffer),
|
|
64
|
+
...A,
|
|
65
|
+
...P,
|
|
66
|
+
c.subarray(B)
|
|
67
|
+
], H = new Uint8Array(V.reduce((e, t) => e + t.length, 0)), U = 0;
|
|
68
|
+
for (let e of V) H.set(e, U), U += e.length;
|
|
69
|
+
return H;
|
|
70
|
+
}
|
|
71
|
+
function c(e, n = {}) {
|
|
72
|
+
return s(t(e), n);
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
export { s as compressLAZ, c as writeLAZ };
|