@bis-toolkit/edds 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/dist/index.js ADDED
@@ -0,0 +1,1509 @@
1
+ // ../utils/dist/index.js
2
+ var BinaryReader = class {
3
+ constructor(buffer) {
4
+ this.position = 0;
5
+ this.buffer = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
6
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
7
+ }
8
+ get length() {
9
+ return this.buffer.length;
10
+ }
11
+ get pos() {
12
+ return this.position;
13
+ }
14
+ seek(offset, origin = "begin") {
15
+ switch (origin) {
16
+ case "begin":
17
+ this.position = offset;
18
+ break;
19
+ case "current":
20
+ this.position += offset;
21
+ break;
22
+ case "end":
23
+ this.position = this.buffer.length + offset;
24
+ break;
25
+ }
26
+ }
27
+ readByte() {
28
+ const value = this.view.getUint8(this.position);
29
+ this.position += 1;
30
+ return value;
31
+ }
32
+ readUInt16() {
33
+ const value = this.view.getUint16(this.position, true);
34
+ this.position += 2;
35
+ return value;
36
+ }
37
+ readUInt32() {
38
+ const value = this.view.getUint32(this.position, true);
39
+ this.position += 4;
40
+ return value;
41
+ }
42
+ readInt32() {
43
+ const value = this.view.getInt32(this.position, true);
44
+ this.position += 4;
45
+ return value;
46
+ }
47
+ readInt24() {
48
+ const b1 = this.view.getUint8(this.position);
49
+ const b2 = this.view.getUint8(this.position + 1);
50
+ const b3 = this.view.getUint8(this.position + 2);
51
+ this.position += 3;
52
+ return b1 | b2 << 8 | b3 << 16;
53
+ }
54
+ readBytes(count) {
55
+ const bytes = this.buffer.subarray(this.position, this.position + count);
56
+ this.position += count;
57
+ return bytes;
58
+ }
59
+ readRawString(length) {
60
+ const bytes = this.buffer.subarray(this.position, this.position + length);
61
+ this.position += length;
62
+ return String.fromCharCode(...bytes);
63
+ }
64
+ readFloat() {
65
+ const value = this.view.getFloat32(this.position, true);
66
+ this.position += 4;
67
+ return value;
68
+ }
69
+ readBoolean() {
70
+ return this.readByte() !== 0;
71
+ }
72
+ /**
73
+ * Read a null-terminated C-style string
74
+ */
75
+ readCString() {
76
+ const start = this.position;
77
+ let end = start;
78
+ while (end < this.buffer.length && this.buffer[end] !== 0) {
79
+ end++;
80
+ }
81
+ const bytes = this.buffer.subarray(start, end);
82
+ this.position = end + 1;
83
+ const decoder = new TextDecoder("utf-8");
84
+ return decoder.decode(bytes);
85
+ }
86
+ /**
87
+ * Alias for readRawString for compatibility
88
+ */
89
+ readString(length) {
90
+ return this.readRawString(length);
91
+ }
92
+ };
93
+ function decompressLz4Block(reader, declaredSize) {
94
+ const startPos = reader.pos;
95
+ const targetSize = reader.readUInt32();
96
+ const target = new Uint8Array(targetSize);
97
+ let targetIdx = 0;
98
+ const LzBlockSize = 65536;
99
+ const dict = new Uint8Array(LzBlockSize);
100
+ let dictSize = 0;
101
+ while (true) {
102
+ const compressedSize = reader.readInt24();
103
+ const flags = reader.readByte();
104
+ if ((flags & ~128) !== 0) {
105
+ throw new Error(`Unknown LZ4 flags 0x${flags.toString(16)}`);
106
+ }
107
+ const compressed = reader.readBytes(compressedSize);
108
+ const decoded = decompressLz4BlockWithDict(compressed, dict, dictSize);
109
+ if (targetIdx + decoded.length > target.length) {
110
+ throw new Error("Decoded LZ4 data overruns target buffer");
111
+ }
112
+ target.set(decoded, targetIdx);
113
+ targetIdx += decoded.length;
114
+ if (decoded.length >= LzBlockSize) {
115
+ dict.set(decoded.subarray(decoded.length - LzBlockSize));
116
+ dictSize = LzBlockSize;
117
+ } else {
118
+ const available = LzBlockSize - dictSize;
119
+ if (decoded.length <= available) {
120
+ dict.set(decoded, dictSize);
121
+ dictSize += decoded.length;
122
+ } else {
123
+ const shift = decoded.length - available;
124
+ dict.copyWithin(0, shift);
125
+ dict.set(decoded, LzBlockSize - decoded.length);
126
+ dictSize = LzBlockSize;
127
+ }
128
+ }
129
+ if ((flags & 128) !== 0) {
130
+ break;
131
+ }
132
+ }
133
+ if (startPos + declaredSize !== reader.pos) {
134
+ throw new Error("LZ4 block length mismatch");
135
+ }
136
+ if (targetIdx !== targetSize) {
137
+ throw new Error(`LZ4 decoded size mismatch (expected ${targetSize}, got ${targetIdx})`);
138
+ }
139
+ return target;
140
+ }
141
+ function decompressLz4BlockWithDict(compressed, dict, dictSize) {
142
+ const output = [];
143
+ let src = 0;
144
+ while (src < compressed.length) {
145
+ const token = compressed[src++];
146
+ let literalLength = token >> 4;
147
+ if (literalLength === 15) {
148
+ let len = 0;
149
+ do {
150
+ len = compressed[src++];
151
+ literalLength += len;
152
+ } while (len === 255 && src < compressed.length);
153
+ }
154
+ for (let i = 0; i < literalLength; i++) {
155
+ output.push(compressed[src++]);
156
+ }
157
+ if (src >= compressed.length) {
158
+ break;
159
+ }
160
+ const offset = compressed[src] | compressed[src + 1] << 8;
161
+ src += 2;
162
+ let matchLength = token & 15;
163
+ if (matchLength === 15) {
164
+ let len = 0;
165
+ do {
166
+ len = compressed[src++];
167
+ matchLength += len;
168
+ } while (len === 255 && src < compressed.length);
169
+ }
170
+ matchLength += 4;
171
+ if (offset === 0) {
172
+ throw new Error("Invalid LZ4 offset");
173
+ }
174
+ const totalAvailable = dictSize + output.length;
175
+ if (offset > totalAvailable) {
176
+ throw new Error("Invalid LZ4 offset");
177
+ }
178
+ for (let i = 0; i < matchLength; i++) {
179
+ const backPos = output.length - offset;
180
+ if (backPos >= 0) {
181
+ output.push(output[backPos]);
182
+ } else {
183
+ const dictPos = dictSize + backPos;
184
+ output.push(dict[dictPos]);
185
+ }
186
+ }
187
+ }
188
+ return Uint8Array.from(output);
189
+ }
190
+
191
+ // ../bcn/dist/index.js
192
+ var ColorRgb565 = class {
193
+ constructor(r, g, b) {
194
+ if (r !== void 0 && g !== void 0 && b !== void 0) {
195
+ const r5 = r >> 3 & 31;
196
+ const g6 = g >> 2 & 63;
197
+ const b5 = b >> 3 & 31;
198
+ this.data = r5 << 11 | g6 << 5 | b5;
199
+ } else {
200
+ this.data = 0;
201
+ }
202
+ }
203
+ toColorRgb24() {
204
+ const r5 = this.data >> 11 & 31;
205
+ const g6 = this.data >> 5 & 63;
206
+ const b5 = this.data & 31;
207
+ const r = r5 << 3 | r5 >> 2;
208
+ const g = g6 << 2 | g6 >> 4;
209
+ const b = b5 << 3 | b5 >> 2;
210
+ return { r, g, b };
211
+ }
212
+ };
213
+ function interpolateHalf(c0, c1) {
214
+ return {
215
+ r: (c0.r + c1.r) / 2 | 0,
216
+ g: (c0.g + c1.g) / 2 | 0,
217
+ b: (c0.b + c1.b) / 2 | 0
218
+ };
219
+ }
220
+ function interpolateThird(c0, c1, step) {
221
+ if (step === 1) {
222
+ return {
223
+ r: (2 * c0.r + c1.r) / 3 | 0,
224
+ g: (2 * c0.g + c1.g) / 3 | 0,
225
+ b: (2 * c0.b + c1.b) / 3 | 0
226
+ };
227
+ } else {
228
+ return {
229
+ r: (c0.r + 2 * c1.r) / 3 | 0,
230
+ g: (c0.g + 2 * c1.g) / 3 | 0,
231
+ b: (c0.b + 2 * c1.b) / 3 | 0
232
+ };
233
+ }
234
+ }
235
+ function interpolateByteFifth(e0, e1, step) {
236
+ if (step === 1) return (4 * e0 + e1) / 5 | 0;
237
+ if (step === 2) return (3 * e0 + 2 * e1) / 5 | 0;
238
+ if (step === 3) return (2 * e0 + 3 * e1) / 5 | 0;
239
+ return (e0 + 4 * e1) / 5 | 0;
240
+ }
241
+ function interpolateByteSeventh(e0, e1, step) {
242
+ if (step === 1) return (6 * e0 + e1) / 7 | 0;
243
+ if (step === 2) return (5 * e0 + 2 * e1) / 7 | 0;
244
+ if (step === 3) return (4 * e0 + 3 * e1) / 7 | 0;
245
+ if (step === 4) return (3 * e0 + 4 * e1) / 7 | 0;
246
+ if (step === 5) return (2 * e0 + 5 * e1) / 7 | 0;
247
+ return (e0 + 6 * e1) / 7 | 0;
248
+ }
249
+ function decodeBC1(data, width, height, useAlpha = false) {
250
+ const rgba = new Uint8Array(width * height * 4);
251
+ const blocksX = Math.ceil(width / 4);
252
+ const blocksY = Math.ceil(height / 4);
253
+ let offset = 0;
254
+ for (let by = 0; by < blocksY; by++) {
255
+ for (let bx = 0; bx < blocksX; bx++) {
256
+ const color0Data = data.getUint16(offset, true);
257
+ const color1Data = data.getUint16(offset + 2, true);
258
+ const indices = data.getUint32(offset + 4, true);
259
+ const color0 = new ColorRgb565();
260
+ color0.data = color0Data;
261
+ const color1 = new ColorRgb565();
262
+ color1.data = color1Data;
263
+ const c0 = color0.toColorRgb24();
264
+ const c1 = color1.toColorRgb24();
265
+ const hasAlphaOrBlack = color0Data <= color1Data;
266
+ const actualUseAlpha = useAlpha && hasAlphaOrBlack;
267
+ const colors = hasAlphaOrBlack ? [
268
+ c0,
269
+ c1,
270
+ interpolateHalf(c0, c1),
271
+ { r: 0, g: 0, b: 0 }
272
+ ] : [
273
+ c0,
274
+ c1,
275
+ interpolateThird(c0, c1, 1),
276
+ interpolateThird(c0, c1, 2)
277
+ ];
278
+ for (let y = 0; y < 4; y++) {
279
+ for (let x = 0; x < 4; x++) {
280
+ const px = bx * 4 + x;
281
+ const py = by * 4 + y;
282
+ if (px < width && py < height) {
283
+ const i = y * 4 + x;
284
+ const colorIndex = indices >> i * 2 & 3;
285
+ const color = colors[colorIndex];
286
+ const dstIdx = (py * width + px) * 4;
287
+ if (actualUseAlpha && colorIndex === 3) {
288
+ rgba[dstIdx] = 0;
289
+ rgba[dstIdx + 1] = 0;
290
+ rgba[dstIdx + 2] = 0;
291
+ rgba[dstIdx + 3] = 0;
292
+ } else {
293
+ rgba[dstIdx] = color.r;
294
+ rgba[dstIdx + 1] = color.g;
295
+ rgba[dstIdx + 2] = color.b;
296
+ rgba[dstIdx + 3] = 255;
297
+ }
298
+ }
299
+ }
300
+ }
301
+ offset += 8;
302
+ }
303
+ }
304
+ return rgba;
305
+ }
306
+ function decodeBC2(data, width, height) {
307
+ const rgba = new Uint8Array(width * height * 4);
308
+ const blocksX = Math.ceil(width / 4);
309
+ const blocksY = Math.ceil(height / 4);
310
+ let offset = 0;
311
+ for (let by = 0; by < blocksY; by++) {
312
+ for (let bx = 0; bx < blocksX; bx++) {
313
+ const alphaLow = data.getUint32(offset, true);
314
+ const alphaHigh = data.getUint32(offset + 4, true);
315
+ const color0Data = data.getUint16(offset + 8, true);
316
+ const color1Data = data.getUint16(offset + 10, true);
317
+ const indices = data.getUint32(offset + 12, true);
318
+ const color0 = new ColorRgb565();
319
+ color0.data = color0Data;
320
+ const color1 = new ColorRgb565();
321
+ color1.data = color1Data;
322
+ const c0 = color0.toColorRgb24();
323
+ const c1 = color1.toColorRgb24();
324
+ const colors = [
325
+ c0,
326
+ c1,
327
+ interpolateThird(c0, c1, 1),
328
+ interpolateThird(c0, c1, 2)
329
+ ];
330
+ for (let y = 0; y < 4; y++) {
331
+ for (let x = 0; x < 4; x++) {
332
+ const px = bx * 4 + x;
333
+ const py = by * 4 + y;
334
+ if (px < width && py < height) {
335
+ const i = y * 4 + x;
336
+ const colorIndex = indices >> i * 2 & 3;
337
+ const color = colors[colorIndex];
338
+ const alphaIndex = i * 4;
339
+ let alpha;
340
+ if (alphaIndex < 32) {
341
+ alpha = alphaLow >> alphaIndex & 15;
342
+ } else {
343
+ alpha = alphaHigh >> alphaIndex - 32 & 15;
344
+ }
345
+ alpha = alpha << 4 | alpha;
346
+ const dstIdx = (py * width + px) * 4;
347
+ rgba[dstIdx] = color.r;
348
+ rgba[dstIdx + 1] = color.g;
349
+ rgba[dstIdx + 2] = color.b;
350
+ rgba[dstIdx + 3] = alpha;
351
+ }
352
+ }
353
+ }
354
+ offset += 16;
355
+ }
356
+ }
357
+ return rgba;
358
+ }
359
+ function decodeAlphaBlock(alphaData) {
360
+ const alpha = new Array(16);
361
+ const alpha0 = Number(alphaData & 0xFFn);
362
+ const alpha1 = Number(alphaData >> 8n & 0xFFn);
363
+ const alphas = alpha0 > alpha1 ? [
364
+ alpha0,
365
+ alpha1,
366
+ interpolateByteSeventh(alpha0, alpha1, 1),
367
+ interpolateByteSeventh(alpha0, alpha1, 2),
368
+ interpolateByteSeventh(alpha0, alpha1, 3),
369
+ interpolateByteSeventh(alpha0, alpha1, 4),
370
+ interpolateByteSeventh(alpha0, alpha1, 5),
371
+ interpolateByteSeventh(alpha0, alpha1, 6)
372
+ ] : [
373
+ alpha0,
374
+ alpha1,
375
+ interpolateByteFifth(alpha0, alpha1, 1),
376
+ interpolateByteFifth(alpha0, alpha1, 2),
377
+ interpolateByteFifth(alpha0, alpha1, 3),
378
+ interpolateByteFifth(alpha0, alpha1, 4),
379
+ 0,
380
+ 255
381
+ ];
382
+ for (let i = 0; i < 16; i++) {
383
+ const bitOffset = 16 + i * 3;
384
+ const index = Number(alphaData >> BigInt(bitOffset) & 0x7n);
385
+ alpha[i] = alphas[index];
386
+ }
387
+ return alpha;
388
+ }
389
+ function decodeBC3(data, width, height) {
390
+ const rgba = new Uint8Array(width * height * 4);
391
+ const blocksX = Math.ceil(width / 4);
392
+ const blocksY = Math.ceil(height / 4);
393
+ let offset = 0;
394
+ for (let by = 0; by < blocksY; by++) {
395
+ for (let bx = 0; bx < blocksX; bx++) {
396
+ const alphaBlock = data.getBigUint64(offset, true);
397
+ const alphas = decodeAlphaBlock(alphaBlock);
398
+ const color0Data = data.getUint16(offset + 8, true);
399
+ const color1Data = data.getUint16(offset + 10, true);
400
+ const indices = data.getUint32(offset + 12, true);
401
+ const color0 = new ColorRgb565();
402
+ color0.data = color0Data;
403
+ const color1 = new ColorRgb565();
404
+ color1.data = color1Data;
405
+ const c0 = color0.toColorRgb24();
406
+ const c1 = color1.toColorRgb24();
407
+ const colors = [
408
+ c0,
409
+ c1,
410
+ interpolateThird(c0, c1, 1),
411
+ interpolateThird(c0, c1, 2)
412
+ ];
413
+ for (let y = 0; y < 4; y++) {
414
+ for (let x = 0; x < 4; x++) {
415
+ const px = bx * 4 + x;
416
+ const py = by * 4 + y;
417
+ if (px < width && py < height) {
418
+ const i = y * 4 + x;
419
+ const colorIndex = indices >> i * 2 & 3;
420
+ const color = colors[colorIndex];
421
+ const dstIdx = (py * width + px) * 4;
422
+ rgba[dstIdx] = color.r;
423
+ rgba[dstIdx + 1] = color.g;
424
+ rgba[dstIdx + 2] = color.b;
425
+ rgba[dstIdx + 3] = alphas[i];
426
+ }
427
+ }
428
+ }
429
+ offset += 16;
430
+ }
431
+ }
432
+ return rgba;
433
+ }
434
+ var ByteHelper = class _ByteHelper {
435
+ static extract(source, index, bitCount) {
436
+ const mask = (1n << BigInt(bitCount)) - 1n;
437
+ return Number(source >> BigInt(index) & mask);
438
+ }
439
+ static extractFrom128(low, high, index, bitCount) {
440
+ if (index + bitCount <= 64) {
441
+ return _ByteHelper.extract(low, index, bitCount);
442
+ }
443
+ if (index >= 64) {
444
+ return _ByteHelper.extract(high, index - 64, bitCount);
445
+ }
446
+ const lowBitCount = 64 - index;
447
+ const highBitCount = bitCount - lowBitCount;
448
+ const lowValue = _ByteHelper.extract(low, index, lowBitCount);
449
+ const highValue = _ByteHelper.extract(high, 0, highBitCount);
450
+ return lowValue | highValue << lowBitCount;
451
+ }
452
+ static extract1(source, index) {
453
+ return Number(source >> BigInt(index) & 1n);
454
+ }
455
+ static extract2(source, index) {
456
+ return Number(source >> BigInt(index) & 3n);
457
+ }
458
+ static extract4(source, index) {
459
+ return Number(source >> BigInt(index) & 15n);
460
+ }
461
+ static extract6(source, index) {
462
+ return Number(source >> BigInt(index) & 63n);
463
+ }
464
+ };
465
+ var COLOR_WEIGHTS_2 = [0, 21, 43, 64];
466
+ var COLOR_WEIGHTS_3 = [0, 9, 18, 27, 37, 46, 55, 64];
467
+ var COLOR_WEIGHTS_4 = [0, 4, 9, 13, 17, 21, 26, 30, 34, 38, 43, 47, 51, 55, 60, 64];
468
+ function interpolateByte(e0, e1, index, indexPrecision) {
469
+ if (indexPrecision === 0) return e0;
470
+ const weights = indexPrecision === 2 ? COLOR_WEIGHTS_2 : indexPrecision === 3 ? COLOR_WEIGHTS_3 : COLOR_WEIGHTS_4;
471
+ const w = weights[index];
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[0, 0, 0, 2, 1, 1, 1, 2, 0, 0, 0, 2, 1, 1, 1, 2],
592
+ [0, 0, 0, 0, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2],
593
+ [0, 2, 2, 2, 0, 1, 1, 1, 0, 1, 1, 1, 0, 2, 2, 2],
594
+ [0, 0, 0, 2, 1, 1, 1, 2, 1, 1, 1, 2, 0, 0, 0, 2],
595
+ [0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 2, 2, 2, 2],
596
+ [0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 1, 2, 2, 1, 1, 2],
597
+ [0, 1, 1, 0, 0, 1, 1, 0, 2, 2, 2, 2, 2, 2, 2, 2],
598
+ [0, 0, 2, 2, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 2, 2],
599
+ [0, 0, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 0, 0, 2, 2],
600
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 1, 2],
601
+ [0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 1],
602
+ [0, 2, 2, 2, 1, 2, 2, 2, 0, 2, 2, 2, 1, 2, 2, 2],
603
+ [0, 1, 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
604
+ [0, 1, 1, 1, 2, 0, 1, 1, 2, 2, 0, 1, 2, 2, 2, 0]
605
+ ];
606
+ var SUBSETS_2_ANCHOR_INDICES = [
607
+ 15,
608
+ 15,
609
+ 15,
610
+ 15,
611
+ 15,
612
+ 15,
613
+ 15,
614
+ 15,
615
+ 15,
616
+ 15,
617
+ 15,
618
+ 15,
619
+ 15,
620
+ 15,
621
+ 15,
622
+ 15,
623
+ 15,
624
+ 2,
625
+ 8,
626
+ 2,
627
+ 2,
628
+ 8,
629
+ 8,
630
+ 15,
631
+ 2,
632
+ 8,
633
+ 2,
634
+ 2,
635
+ 8,
636
+ 8,
637
+ 2,
638
+ 2,
639
+ 15,
640
+ 15,
641
+ 6,
642
+ 8,
643
+ 2,
644
+ 8,
645
+ 15,
646
+ 15,
647
+ 2,
648
+ 8,
649
+ 2,
650
+ 2,
651
+ 2,
652
+ 15,
653
+ 15,
654
+ 6,
655
+ 6,
656
+ 2,
657
+ 6,
658
+ 8,
659
+ 15,
660
+ 15,
661
+ 2,
662
+ 2,
663
+ 15,
664
+ 15,
665
+ 15,
666
+ 15,
667
+ 15,
668
+ 2,
669
+ 2,
670
+ 15
671
+ ];
672
+ var SUBSETS_3_ANCHOR_INDICES_2 = [
673
+ 3,
674
+ 3,
675
+ 15,
676
+ 15,
677
+ 8,
678
+ 3,
679
+ 15,
680
+ 15,
681
+ 8,
682
+ 8,
683
+ 6,
684
+ 6,
685
+ 6,
686
+ 5,
687
+ 3,
688
+ 3,
689
+ 3,
690
+ 3,
691
+ 8,
692
+ 15,
693
+ 3,
694
+ 3,
695
+ 6,
696
+ 10,
697
+ 5,
698
+ 8,
699
+ 8,
700
+ 6,
701
+ 8,
702
+ 5,
703
+ 15,
704
+ 15,
705
+ 8,
706
+ 15,
707
+ 3,
708
+ 5,
709
+ 6,
710
+ 10,
711
+ 8,
712
+ 15,
713
+ 15,
714
+ 3,
715
+ 15,
716
+ 5,
717
+ 15,
718
+ 15,
719
+ 15,
720
+ 15,
721
+ 3,
722
+ 15,
723
+ 5,
724
+ 5,
725
+ 5,
726
+ 8,
727
+ 5,
728
+ 10,
729
+ 5,
730
+ 10,
731
+ 8,
732
+ 13,
733
+ 15,
734
+ 12,
735
+ 3,
736
+ 3
737
+ ];
738
+ var SUBSETS_3_ANCHOR_INDICES_3 = [
739
+ 15,
740
+ 8,
741
+ 8,
742
+ 3,
743
+ 15,
744
+ 15,
745
+ 3,
746
+ 8,
747
+ 15,
748
+ 15,
749
+ 15,
750
+ 15,
751
+ 15,
752
+ 15,
753
+ 15,
754
+ 8,
755
+ 15,
756
+ 8,
757
+ 15,
758
+ 3,
759
+ 15,
760
+ 8,
761
+ 15,
762
+ 8,
763
+ 3,
764
+ 15,
765
+ 6,
766
+ 10,
767
+ 15,
768
+ 15,
769
+ 10,
770
+ 8,
771
+ 15,
772
+ 3,
773
+ 15,
774
+ 10,
775
+ 10,
776
+ 8,
777
+ 9,
778
+ 10,
779
+ 6,
780
+ 15,
781
+ 8,
782
+ 15,
783
+ 3,
784
+ 6,
785
+ 6,
786
+ 8,
787
+ 15,
788
+ 3,
789
+ 15,
790
+ 15,
791
+ 15,
792
+ 15,
793
+ 15,
794
+ 15,
795
+ 15,
796
+ 15,
797
+ 15,
798
+ 15,
799
+ 3,
800
+ 15,
801
+ 15,
802
+ 8
803
+ ];
804
+ var Bc7Block = class {
805
+ constructor(data) {
806
+ const view = new DataView(data.buffer, data.byteOffset, 16);
807
+ this.lowBits = view.getBigUint64(0, true);
808
+ this.highBits = view.getBigUint64(8, true);
809
+ }
810
+ getType() {
811
+ for (let i = 0; i < 8; i++) {
812
+ const mask = 1n << BigInt(i);
813
+ if ((this.lowBits & mask) === mask) {
814
+ return i;
815
+ }
816
+ }
817
+ return 8;
818
+ }
819
+ getNumSubsets(type) {
820
+ if (type === 0 || type === 2) return 3;
821
+ if (type === 1 || type === 3 || type === 7) return 2;
822
+ return 1;
823
+ }
824
+ getPartitionSetId(type) {
825
+ switch (type) {
826
+ case 0:
827
+ return ByteHelper.extract4(this.lowBits, 1);
828
+ case 1:
829
+ return ByteHelper.extract6(this.lowBits, 2);
830
+ case 2:
831
+ return ByteHelper.extract6(this.lowBits, 3);
832
+ case 3:
833
+ return ByteHelper.extract6(this.lowBits, 4);
834
+ case 7:
835
+ return ByteHelper.extract6(this.lowBits, 8);
836
+ default:
837
+ return 0;
838
+ }
839
+ }
840
+ getRotationBits(type) {
841
+ if (type === 4) return ByteHelper.extract2(this.lowBits, 5);
842
+ if (type === 5) return ByteHelper.extract2(this.lowBits, 6);
843
+ return 0;
844
+ }
845
+ getColorComponentPrecision(type) {
846
+ const precisions = [5, 7, 5, 8, 5, 7, 8, 6];
847
+ return precisions[type] || 0;
848
+ }
849
+ getAlphaComponentPrecision(type) {
850
+ if (type === 4) return 6;
851
+ if (type === 5 || type === 6) return 8;
852
+ if (type === 7) return 6;
853
+ return 0;
854
+ }
855
+ getType4IndexMode() {
856
+ return ByteHelper.extract1(this.lowBits, 7);
857
+ }
858
+ getColorIndexBitCount(type) {
859
+ if (type === 0 || type === 1) return 3;
860
+ if (type === 2 || type === 3 || type === 5 || type === 7) return 2;
861
+ if (type === 4) {
862
+ const indexMode = this.getType4IndexMode();
863
+ return indexMode === 0 ? 2 : 3;
864
+ }
865
+ if (type === 6) return 4;
866
+ return 0;
867
+ }
868
+ getAlphaIndexBitCount(type) {
869
+ if (type === 4) {
870
+ const indexMode = this.getType4IndexMode();
871
+ return indexMode === 0 ? 3 : 2;
872
+ }
873
+ if (type === 5 || type === 7) return 2;
874
+ if (type === 6) return 4;
875
+ return 0;
876
+ }
877
+ extractRawEndpoints(type, numSubsets) {
878
+ const endpoints = Array(numSubsets * 2).fill(null).map(() => ({ r: 0, g: 0, b: 0, a: 0 }));
879
+ switch (type) {
880
+ case 0:
881
+ for (let i = 0; i < 6; i++) {
882
+ endpoints[i].r = ByteHelper.extractFrom128(this.lowBits, this.highBits, 5 + i * 4, 4);
883
+ endpoints[i].g = ByteHelper.extractFrom128(this.lowBits, this.highBits, 29 + i * 4, 4);
884
+ endpoints[i].b = ByteHelper.extractFrom128(this.lowBits, this.highBits, 53 + i * 4, 4);
885
+ }
886
+ break;
887
+ case 1:
888
+ for (let i = 0; i < 4; i++) {
889
+ endpoints[i].r = ByteHelper.extractFrom128(this.lowBits, this.highBits, 8 + i * 6, 6);
890
+ endpoints[i].g = ByteHelper.extractFrom128(this.lowBits, this.highBits, 32 + i * 6, 6);
891
+ endpoints[i].b = ByteHelper.extractFrom128(this.lowBits, this.highBits, 56 + i * 6, 6);
892
+ }
893
+ break;
894
+ case 2:
895
+ for (let i = 0; i < 6; i++) {
896
+ endpoints[i].r = ByteHelper.extractFrom128(this.lowBits, this.highBits, 9 + i * 5, 5);
897
+ endpoints[i].g = ByteHelper.extractFrom128(this.lowBits, this.highBits, 39 + i * 5, 5);
898
+ endpoints[i].b = ByteHelper.extractFrom128(this.lowBits, this.highBits, 69 + i * 5, 5);
899
+ }
900
+ break;
901
+ case 3:
902
+ for (let i = 0; i < 4; i++) {
903
+ endpoints[i].r = ByteHelper.extractFrom128(this.lowBits, this.highBits, 10 + i * 7, 7);
904
+ endpoints[i].g = ByteHelper.extractFrom128(this.lowBits, this.highBits, 38 + i * 7, 7);
905
+ endpoints[i].b = ByteHelper.extractFrom128(this.lowBits, this.highBits, 66 + i * 7, 7);
906
+ }
907
+ break;
908
+ case 4:
909
+ endpoints[0].r = ByteHelper.extractFrom128(this.lowBits, this.highBits, 8, 5);
910
+ endpoints[1].r = ByteHelper.extractFrom128(this.lowBits, this.highBits, 13, 5);
911
+ endpoints[0].g = ByteHelper.extractFrom128(this.lowBits, this.highBits, 18, 5);
912
+ endpoints[1].g = ByteHelper.extractFrom128(this.lowBits, this.highBits, 23, 5);
913
+ endpoints[0].b = ByteHelper.extractFrom128(this.lowBits, this.highBits, 28, 5);
914
+ endpoints[1].b = ByteHelper.extractFrom128(this.lowBits, this.highBits, 33, 5);
915
+ endpoints[0].a = ByteHelper.extractFrom128(this.lowBits, this.highBits, 38, 6);
916
+ endpoints[1].a = ByteHelper.extractFrom128(this.lowBits, this.highBits, 44, 6);
917
+ break;
918
+ case 5:
919
+ endpoints[0].r = ByteHelper.extractFrom128(this.lowBits, this.highBits, 8, 7);
920
+ endpoints[1].r = ByteHelper.extractFrom128(this.lowBits, this.highBits, 15, 7);
921
+ endpoints[0].g = ByteHelper.extractFrom128(this.lowBits, this.highBits, 22, 7);
922
+ endpoints[1].g = ByteHelper.extractFrom128(this.lowBits, this.highBits, 29, 7);
923
+ endpoints[0].b = ByteHelper.extractFrom128(this.lowBits, this.highBits, 36, 7);
924
+ endpoints[1].b = ByteHelper.extractFrom128(this.lowBits, this.highBits, 43, 7);
925
+ endpoints[0].a = ByteHelper.extractFrom128(this.lowBits, this.highBits, 50, 8);
926
+ endpoints[1].a = ByteHelper.extractFrom128(this.lowBits, this.highBits, 58, 8);
927
+ break;
928
+ case 6:
929
+ endpoints[0].r = ByteHelper.extractFrom128(this.lowBits, this.highBits, 7, 7);
930
+ endpoints[1].r = ByteHelper.extractFrom128(this.lowBits, this.highBits, 14, 7);
931
+ endpoints[0].g = ByteHelper.extractFrom128(this.lowBits, this.highBits, 21, 7);
932
+ endpoints[1].g = ByteHelper.extractFrom128(this.lowBits, this.highBits, 28, 7);
933
+ endpoints[0].b = ByteHelper.extractFrom128(this.lowBits, this.highBits, 35, 7);
934
+ endpoints[1].b = ByteHelper.extractFrom128(this.lowBits, this.highBits, 42, 7);
935
+ endpoints[0].a = ByteHelper.extractFrom128(this.lowBits, this.highBits, 49, 7);
936
+ endpoints[1].a = ByteHelper.extractFrom128(this.lowBits, this.highBits, 56, 7);
937
+ break;
938
+ case 7:
939
+ for (let i = 0; i < 4; i++) {
940
+ endpoints[i].r = ByteHelper.extractFrom128(this.lowBits, this.highBits, 14 + i * 5, 5);
941
+ endpoints[i].g = ByteHelper.extractFrom128(this.lowBits, this.highBits, 34 + i * 5, 5);
942
+ endpoints[i].b = ByteHelper.extractFrom128(this.lowBits, this.highBits, 54 + i * 5, 5);
943
+ endpoints[i].a = ByteHelper.extractFrom128(this.lowBits, this.highBits, 74 + i * 5, 5);
944
+ }
945
+ break;
946
+ }
947
+ return endpoints;
948
+ }
949
+ extractPBits(type, _numSubsets) {
950
+ switch (type) {
951
+ case 0:
952
+ return [
953
+ ByteHelper.extract1(this.highBits, 77 - 64),
954
+ ByteHelper.extract1(this.highBits, 78 - 64),
955
+ ByteHelper.extract1(this.highBits, 79 - 64),
956
+ ByteHelper.extract1(this.highBits, 80 - 64),
957
+ ByteHelper.extract1(this.highBits, 81 - 64),
958
+ ByteHelper.extract1(this.highBits, 82 - 64)
959
+ ];
960
+ case 1:
961
+ return [
962
+ ByteHelper.extract1(this.highBits, 80 - 64),
963
+ ByteHelper.extract1(this.highBits, 81 - 64)
964
+ ];
965
+ case 3:
966
+ return [
967
+ ByteHelper.extract1(this.highBits, 94 - 64),
968
+ ByteHelper.extract1(this.highBits, 95 - 64),
969
+ ByteHelper.extract1(this.highBits, 96 - 64),
970
+ ByteHelper.extract1(this.highBits, 97 - 64)
971
+ ];
972
+ case 6:
973
+ return [
974
+ ByteHelper.extract1(this.lowBits, 63),
975
+ ByteHelper.extract1(this.highBits, 0)
976
+ ];
977
+ case 7:
978
+ return [
979
+ ByteHelper.extract1(this.highBits, 94 - 64),
980
+ ByteHelper.extract1(this.highBits, 95 - 64),
981
+ ByteHelper.extract1(this.highBits, 96 - 64),
982
+ ByteHelper.extract1(this.highBits, 97 - 64)
983
+ ];
984
+ default:
985
+ return [];
986
+ }
987
+ }
988
+ hasPBits(type) {
989
+ return type === 0 || type === 1 || type === 3 || type === 6 || type === 7;
990
+ }
991
+ hasAlpha(type) {
992
+ return type === 4 || type === 5 || type === 6 || type === 7;
993
+ }
994
+ finalizeEndpoints(endpoints, type) {
995
+ const hasPBits = this.hasPBits(type);
996
+ if (hasPBits) {
997
+ const pBits = this.extractPBits(type, endpoints.length);
998
+ for (const ep of endpoints) {
999
+ ep.r <<= 1;
1000
+ ep.g <<= 1;
1001
+ ep.b <<= 1;
1002
+ ep.a <<= 1;
1003
+ }
1004
+ if (type === 1) {
1005
+ endpoints[0].r |= pBits[0];
1006
+ endpoints[0].g |= pBits[0];
1007
+ endpoints[0].b |= pBits[0];
1008
+ endpoints[1].r |= pBits[0];
1009
+ endpoints[1].g |= pBits[0];
1010
+ endpoints[1].b |= pBits[0];
1011
+ endpoints[2].r |= pBits[1];
1012
+ endpoints[2].g |= pBits[1];
1013
+ endpoints[2].b |= pBits[1];
1014
+ endpoints[3].r |= pBits[1];
1015
+ endpoints[3].g |= pBits[1];
1016
+ endpoints[3].b |= pBits[1];
1017
+ } else {
1018
+ for (let i = 0; i < endpoints.length; i++) {
1019
+ endpoints[i].r |= pBits[i];
1020
+ endpoints[i].g |= pBits[i];
1021
+ endpoints[i].b |= pBits[i];
1022
+ if (this.hasAlpha(type)) {
1023
+ endpoints[i].a |= pBits[i];
1024
+ }
1025
+ }
1026
+ }
1027
+ }
1028
+ const colorPrec = this.getColorComponentPrecision(type);
1029
+ const alphaPrec = this.getAlphaComponentPrecision(type);
1030
+ for (const ep of endpoints) {
1031
+ ep.r = ep.r << 8 - colorPrec | ep.r >> colorPrec - (8 - colorPrec);
1032
+ ep.g = ep.g << 8 - colorPrec | ep.g >> colorPrec - (8 - colorPrec);
1033
+ ep.b = ep.b << 8 - colorPrec | ep.b >> colorPrec - (8 - colorPrec);
1034
+ ep.a = alphaPrec > 0 ? ep.a << 8 - alphaPrec | ep.a >> alphaPrec - (8 - alphaPrec) : 255;
1035
+ }
1036
+ if (!this.hasAlpha(type)) {
1037
+ for (const ep of endpoints) {
1038
+ ep.a = 255;
1039
+ }
1040
+ }
1041
+ }
1042
+ getPartitionIndex(numSubsets, partitionSetId, pixelIndex) {
1043
+ if (numSubsets === 1) return 0;
1044
+ if (numSubsets === 2) return SUBSETS_2_PARTITION_TABLE[partitionSetId][pixelIndex];
1045
+ return SUBSETS_3_PARTITION_TABLE[partitionSetId][pixelIndex];
1046
+ }
1047
+ getIndexBegin(type, bitCount, isAlpha) {
1048
+ switch (type) {
1049
+ case 0:
1050
+ return 83;
1051
+ case 1:
1052
+ return 82;
1053
+ case 2:
1054
+ return 99;
1055
+ case 3:
1056
+ return 98;
1057
+ case 4:
1058
+ return bitCount === 2 ? 50 : 81;
1059
+ case 5:
1060
+ return isAlpha ? 97 : 66;
1061
+ case 6:
1062
+ return 65;
1063
+ case 7:
1064
+ return 98;
1065
+ default:
1066
+ return 0;
1067
+ }
1068
+ }
1069
+ getIndexBitCount(numSubsets, partitionIndex, bitCount, pixelIndex) {
1070
+ if (pixelIndex === 0) return bitCount - 1;
1071
+ if (numSubsets === 2) {
1072
+ const anchorIndex = SUBSETS_2_ANCHOR_INDICES[partitionIndex];
1073
+ if (pixelIndex === anchorIndex) return bitCount - 1;
1074
+ } else if (numSubsets === 3) {
1075
+ const anchor2 = SUBSETS_3_ANCHOR_INDICES_2[partitionIndex];
1076
+ const anchor3 = SUBSETS_3_ANCHOR_INDICES_3[partitionIndex];
1077
+ if (pixelIndex === anchor2 || pixelIndex === anchor3) return bitCount - 1;
1078
+ }
1079
+ return bitCount;
1080
+ }
1081
+ getIndexOffset(type, numSubsets, partitionIndex, bitCount, pixelIndex) {
1082
+ if (pixelIndex === 0) return 0;
1083
+ if (numSubsets === 1) {
1084
+ return bitCount * pixelIndex - 1;
1085
+ }
1086
+ if (numSubsets === 2) {
1087
+ const anchorIndex = SUBSETS_2_ANCHOR_INDICES[partitionIndex];
1088
+ if (pixelIndex <= anchorIndex) {
1089
+ return bitCount * pixelIndex - 1;
1090
+ } else {
1091
+ return bitCount * pixelIndex - 2;
1092
+ }
1093
+ }
1094
+ if (numSubsets === 3) {
1095
+ const anchor2 = SUBSETS_3_ANCHOR_INDICES_2[partitionIndex];
1096
+ const anchor3 = SUBSETS_3_ANCHOR_INDICES_3[partitionIndex];
1097
+ if (pixelIndex <= anchor2 && pixelIndex <= anchor3) {
1098
+ return bitCount * pixelIndex - 1;
1099
+ } else if (pixelIndex > anchor2 && pixelIndex > anchor3) {
1100
+ return bitCount * pixelIndex - 3;
1101
+ } else {
1102
+ return bitCount * pixelIndex - 2;
1103
+ }
1104
+ }
1105
+ return 0;
1106
+ }
1107
+ getColorIndex(type, numSubsets, partitionIndex, bitCount, pixelIndex) {
1108
+ const indexOffset = this.getIndexOffset(type, numSubsets, partitionIndex, bitCount, pixelIndex);
1109
+ const indexBitCount = this.getIndexBitCount(numSubsets, partitionIndex, bitCount, pixelIndex);
1110
+ const indexBegin = this.getIndexBegin(type, bitCount, false);
1111
+ return ByteHelper.extractFrom128(this.lowBits, this.highBits, indexBegin + indexOffset, indexBitCount);
1112
+ }
1113
+ getAlphaIndex(type, numSubsets, partitionIndex, bitCount, pixelIndex) {
1114
+ if (bitCount === 0) return 0;
1115
+ const indexOffset = this.getIndexOffset(type, numSubsets, partitionIndex, bitCount, pixelIndex);
1116
+ const indexBitCount = this.getIndexBitCount(numSubsets, partitionIndex, bitCount, pixelIndex);
1117
+ const indexBegin = this.getIndexBegin(type, bitCount, true);
1118
+ return ByteHelper.extractFrom128(this.lowBits, this.highBits, indexBegin + indexOffset, indexBitCount);
1119
+ }
1120
+ swapChannels(color, rotation) {
1121
+ switch (rotation) {
1122
+ case 0:
1123
+ return color;
1124
+ case 1:
1125
+ return { r: color.a, g: color.g, b: color.b, a: color.r };
1126
+ case 2:
1127
+ return { r: color.r, g: color.a, b: color.b, a: color.g };
1128
+ case 3:
1129
+ return { r: color.r, g: color.g, b: color.a, a: color.b };
1130
+ default:
1131
+ return color;
1132
+ }
1133
+ }
1134
+ decode() {
1135
+ const output = new Uint8Array(16 * 4);
1136
+ const type = this.getType();
1137
+ if (type === 8) {
1138
+ for (let i = 0; i < 16; i++) {
1139
+ output[i * 4] = 255;
1140
+ output[i * 4 + 1] = 0;
1141
+ output[i * 4 + 2] = 255;
1142
+ output[i * 4 + 3] = 255;
1143
+ }
1144
+ return output;
1145
+ }
1146
+ const numSubsets = this.getNumSubsets(type);
1147
+ const partitionSetId = this.getPartitionSetId(type);
1148
+ const rotation = this.getRotationBits(type);
1149
+ const endpoints = this.extractRawEndpoints(type, numSubsets);
1150
+ this.finalizeEndpoints(endpoints, type);
1151
+ const colorBitCount = this.getColorIndexBitCount(type);
1152
+ const alphaBitCount = this.getAlphaIndexBitCount(type);
1153
+ for (let i = 0; i < 16; i++) {
1154
+ const subsetIndex = this.getPartitionIndex(numSubsets, partitionSetId, i);
1155
+ const ep0 = endpoints[2 * subsetIndex];
1156
+ const ep1 = endpoints[2 * subsetIndex + 1];
1157
+ const colorIndex = this.getColorIndex(type, numSubsets, partitionSetId, colorBitCount, i);
1158
+ const alphaIndex = this.getAlphaIndex(type, numSubsets, partitionSetId, alphaBitCount, i);
1159
+ let color = {
1160
+ r: interpolateByte(ep0.r, ep1.r, colorIndex, colorBitCount),
1161
+ g: interpolateByte(ep0.g, ep1.g, colorIndex, colorBitCount),
1162
+ b: interpolateByte(ep0.b, ep1.b, colorIndex, colorBitCount),
1163
+ a: interpolateByte(ep0.a, ep1.a, alphaIndex, alphaBitCount || colorBitCount)
1164
+ };
1165
+ if (rotation > 0) {
1166
+ color = this.swapChannels(color, rotation);
1167
+ }
1168
+ output[i * 4] = color.r;
1169
+ output[i * 4 + 1] = color.g;
1170
+ output[i * 4 + 2] = color.b;
1171
+ output[i * 4 + 3] = color.a;
1172
+ }
1173
+ return output;
1174
+ }
1175
+ };
1176
+ function decodeBC7(imageData, width, height) {
1177
+ const rgba = new Uint8Array(width * height * 4);
1178
+ const blocksX = Math.ceil(width / 4);
1179
+ const blocksY = Math.ceil(height / 4);
1180
+ let offset = 0;
1181
+ for (let by = 0; by < blocksY; by++) {
1182
+ for (let bx = 0; bx < blocksX; bx++) {
1183
+ const blockData = new Uint8Array(16);
1184
+ for (let i = 0; i < 16; i++) {
1185
+ blockData[i] = imageData.getUint8(offset + i);
1186
+ }
1187
+ const block = new Bc7Block(blockData);
1188
+ const decodedBlock = block.decode();
1189
+ for (let y = 0; y < 4; y++) {
1190
+ for (let x = 0; x < 4; x++) {
1191
+ const px = bx * 4 + x;
1192
+ const py = by * 4 + y;
1193
+ if (px < width && py < height) {
1194
+ const srcIdx = (y * 4 + x) * 4;
1195
+ const dstIdx = (py * width + px) * 4;
1196
+ rgba[dstIdx] = decodedBlock[srcIdx];
1197
+ rgba[dstIdx + 1] = decodedBlock[srcIdx + 1];
1198
+ rgba[dstIdx + 2] = decodedBlock[srcIdx + 2];
1199
+ rgba[dstIdx + 3] = decodedBlock[srcIdx + 3];
1200
+ }
1201
+ }
1202
+ }
1203
+ offset += 16;
1204
+ }
1205
+ }
1206
+ return rgba;
1207
+ }
1208
+
1209
+ // src/Edds.ts
1210
+ var DDS_MAGIC = "DDS ";
1211
+ var LZ4_MAGIC = "LZ4 ";
1212
+ var COPY_MAGIC = "COPY";
1213
+ var HEADER_SIZE = 124;
1214
+ var FOURCC_DX10 = fourCcToInt("DX10");
1215
+ var HEADER_CAPS_MIPMAP = 4194304;
1216
+ var HEADER_CAPS2_CUBEMAP = 512;
1217
+ var PIXELFORMAT_FLAG_FOURCC = 4;
1218
+ var PIXELFORMAT_FLAG_RGB = 64;
1219
+ var PIXELFORMAT_FLAG_ALPHA_PIXELS = 1;
1220
+ var PIXELFORMAT_FLAG_LUMINANCE = 131072;
1221
+ function fourCcToInt(text) {
1222
+ if (text.length !== 4) {
1223
+ throw new Error("FourCC needs exactly four characters");
1224
+ }
1225
+ return (text.charCodeAt(0) | text.charCodeAt(1) << 8 | text.charCodeAt(2) << 16 | text.charCodeAt(3) << 24) >>> 0;
1226
+ }
1227
+ function intToFourCc(value) {
1228
+ return String.fromCharCode(
1229
+ value & 255,
1230
+ value >> 8 & 255,
1231
+ value >> 16 & 255,
1232
+ value >> 24 & 255
1233
+ );
1234
+ }
1235
+ function readDdsHeader(reader) {
1236
+ const size = reader.readUInt32();
1237
+ if (size !== HEADER_SIZE) {
1238
+ throw new Error(`Unexpected DDS header size ${size} (expected ${HEADER_SIZE})`);
1239
+ }
1240
+ const flags = reader.readUInt32();
1241
+ const height = reader.readUInt32();
1242
+ const width = reader.readUInt32();
1243
+ const pitchOrLinearSize = reader.readUInt32();
1244
+ const depth = reader.readUInt32();
1245
+ const mipMapCount = reader.readUInt32();
1246
+ reader.readBytes(11 * 4);
1247
+ const pfSize = reader.readUInt32();
1248
+ const pfFlags = reader.readUInt32();
1249
+ const pfFourCC = reader.readUInt32();
1250
+ const pfRgbBitCount = reader.readUInt32();
1251
+ const pfRMask = reader.readUInt32();
1252
+ const pfGMask = reader.readUInt32();
1253
+ const pfBMask = reader.readUInt32();
1254
+ const pfAMask = reader.readUInt32();
1255
+ const pixelFormat = {
1256
+ size: pfSize,
1257
+ flags: pfFlags,
1258
+ fourCC: pfFourCC >>> 0,
1259
+ rgbBitCount: pfRgbBitCount,
1260
+ rMask: pfRMask >>> 0,
1261
+ gMask: pfGMask >>> 0,
1262
+ bMask: pfBMask >>> 0,
1263
+ aMask: pfAMask >>> 0
1264
+ };
1265
+ const caps = reader.readUInt32();
1266
+ const caps2 = reader.readUInt32();
1267
+ const caps3 = reader.readUInt32();
1268
+ const caps4 = reader.readUInt32();
1269
+ const reserved2 = reader.readUInt32();
1270
+ if (reserved2 !== 0) {
1271
+ throw new Error("Invalid DDS header: reserved2 is not zero");
1272
+ }
1273
+ const header = {
1274
+ size,
1275
+ flags,
1276
+ height,
1277
+ width,
1278
+ pitchOrLinearSize,
1279
+ depth,
1280
+ mipMapCount,
1281
+ pixelFormat,
1282
+ caps,
1283
+ caps2,
1284
+ caps3,
1285
+ caps4
1286
+ };
1287
+ if ((pixelFormat.flags & PIXELFORMAT_FLAG_FOURCC) !== 0 && pixelFormat.fourCC === FOURCC_DX10) {
1288
+ const dxgiFormat = reader.readUInt32();
1289
+ const resourceDimension = reader.readUInt32();
1290
+ const miscFlag = reader.readUInt32();
1291
+ const arraySize = reader.readUInt32();
1292
+ const miscFlags2 = reader.readUInt32();
1293
+ return {
1294
+ header,
1295
+ dx10: { dxgiFormat, resourceDimension, miscFlag, arraySize, miscFlags2 }
1296
+ };
1297
+ }
1298
+ return { header };
1299
+ }
1300
+ function mipDimension(base, level) {
1301
+ return Math.max(1, base >> level);
1302
+ }
1303
+ function expectedDataLength(format, width, height) {
1304
+ switch (format) {
1305
+ case "BC1":
1306
+ case "BC4": {
1307
+ const blocksW = Math.max(1, Math.ceil(width / 4));
1308
+ const blocksH = Math.max(1, Math.ceil(height / 4));
1309
+ return blocksW * blocksH * 8;
1310
+ }
1311
+ case "BC2":
1312
+ case "BC3":
1313
+ case "BC5":
1314
+ case "BC6":
1315
+ case "BC7": {
1316
+ const blocksW = Math.max(1, Math.ceil(width / 4));
1317
+ const blocksH = Math.max(1, Math.ceil(height / 4));
1318
+ return blocksW * blocksH * 16;
1319
+ }
1320
+ case "RGBA8":
1321
+ case "BGRA8":
1322
+ return width * height * 4;
1323
+ default:
1324
+ return null;
1325
+ }
1326
+ }
1327
+ function detectFormat(header, dx10) {
1328
+ if (dx10) {
1329
+ const format = mapDxgiFormat(dx10.dxgiFormat);
1330
+ return { format, details: `DXGI ${dx10.dxgiFormat}` };
1331
+ }
1332
+ const pf = header.pixelFormat;
1333
+ if ((pf.flags & PIXELFORMAT_FLAG_FOURCC) !== 0) {
1334
+ const fourCCStr = intToFourCc(pf.fourCC).toUpperCase();
1335
+ switch (fourCCStr) {
1336
+ case "DXT1":
1337
+ return { format: "BC1", details: fourCCStr };
1338
+ case "DXT2":
1339
+ case "DXT3":
1340
+ return { format: "BC2", details: fourCCStr };
1341
+ case "DXT4":
1342
+ case "DXT5":
1343
+ return { format: "BC3", details: fourCCStr };
1344
+ case "ATI1":
1345
+ case "BC4U":
1346
+ case "BC4S":
1347
+ return { format: "BC4", details: fourCCStr };
1348
+ case "ATI2":
1349
+ case "BC5U":
1350
+ case "BC5S":
1351
+ return { format: "BC5", details: fourCCStr };
1352
+ default:
1353
+ return { format: "UNKNOWN", details: fourCCStr };
1354
+ }
1355
+ }
1356
+ if ((pf.flags & PIXELFORMAT_FLAG_RGB) !== 0) {
1357
+ if ((pf.flags & PIXELFORMAT_FLAG_ALPHA_PIXELS) !== 0 && pf.rgbBitCount === 32) {
1358
+ if (pf.rMask === 255 && pf.gMask === 65280 && pf.bMask === 16711680 && pf.aMask === 4278190080) {
1359
+ return { format: "RGBA8", details: "RGBA8" };
1360
+ }
1361
+ if (pf.rMask === 16711680 && pf.gMask === 65280 && pf.bMask === 255 && pf.aMask === 4278190080) {
1362
+ return { format: "BGRA8", details: "BGRA8" };
1363
+ }
1364
+ }
1365
+ }
1366
+ if ((pf.flags & PIXELFORMAT_FLAG_LUMINANCE) !== 0 && pf.rgbBitCount === 8) {
1367
+ return { format: "RGBA8", details: "LUMINANCE8" };
1368
+ }
1369
+ return { format: "UNKNOWN", details: "UNKNOWN" };
1370
+ }
1371
+ function mapDxgiFormat(dxgiFormat) {
1372
+ switch (dxgiFormat) {
1373
+ case 71:
1374
+ return "BC1";
1375
+ case 74:
1376
+ return "BC2";
1377
+ case 77:
1378
+ return "BC3";
1379
+ case 80:
1380
+ return "BC4";
1381
+ case 83:
1382
+ return "BC5";
1383
+ case 95:
1384
+ return "BC6";
1385
+ case 98:
1386
+ return "BC7";
1387
+ case 87:
1388
+ return "BGRA8";
1389
+ case 28:
1390
+ return "RGBA8";
1391
+ default:
1392
+ return "UNKNOWN";
1393
+ }
1394
+ }
1395
+ function convertToRgba(mip, format) {
1396
+ const dataView = new DataView(mip.data.buffer, mip.data.byteOffset, mip.data.byteLength);
1397
+ switch (format) {
1398
+ case "BC1":
1399
+ return decodeBC1(dataView, mip.width, mip.height);
1400
+ case "BC2":
1401
+ return decodeBC2(dataView, mip.width, mip.height);
1402
+ case "BC3":
1403
+ return decodeBC3(dataView, mip.width, mip.height);
1404
+ case "BC6":
1405
+ throw new Error(`RGBA conversion for BC6 (HDR) is not yet implemented`);
1406
+ case "BC7":
1407
+ return decodeBC7(dataView, mip.width, mip.height);
1408
+ case "RGBA8":
1409
+ return mip.data.slice();
1410
+ case "BGRA8": {
1411
+ const rgba = new Uint8Array(mip.data.length);
1412
+ for (let i = 0; i < mip.data.length; i += 4) {
1413
+ rgba[i] = mip.data[i + 2];
1414
+ rgba[i + 1] = mip.data[i + 1];
1415
+ rgba[i + 2] = mip.data[i];
1416
+ rgba[i + 3] = mip.data[i + 3];
1417
+ }
1418
+ return rgba;
1419
+ }
1420
+ default:
1421
+ throw new Error(`RGBA conversion is not implemented for format ${format}`);
1422
+ }
1423
+ }
1424
+ var Edds = class {
1425
+ constructor() {
1426
+ this.width = 0;
1427
+ this.height = 0;
1428
+ this.format = "UNKNOWN";
1429
+ this.formatDetails = "";
1430
+ this.mipmaps = [];
1431
+ }
1432
+ read(buffer) {
1433
+ const reader = new BinaryReader(buffer);
1434
+ const magic = reader.readRawString(4);
1435
+ if (magic !== DDS_MAGIC) {
1436
+ throw new Error("File is not a valid EDDS (missing DDS magic)");
1437
+ }
1438
+ const { header, dx10 } = readDdsHeader(reader);
1439
+ const mipCount = (header.caps & HEADER_CAPS_MIPMAP) !== 0 && header.mipMapCount > 0 ? header.mipMapCount : 1;
1440
+ const faceCount = (header.caps2 & HEADER_CAPS2_CUBEMAP) !== 0 ? 6 : 1;
1441
+ if (faceCount !== 1) {
1442
+ throw new Error("Cubemap EDDS files are not supported yet");
1443
+ }
1444
+ this.width = header.width;
1445
+ this.height = header.height;
1446
+ const blocks = [];
1447
+ for (let i = 0; i < mipCount; i++) {
1448
+ const blockMagic = reader.readRawString(4);
1449
+ const size = reader.readInt32();
1450
+ if (blockMagic === COPY_MAGIC) {
1451
+ blocks.push({ kind: "COPY", size });
1452
+ } else if (blockMagic === LZ4_MAGIC) {
1453
+ blocks.push({ kind: "LZ4", size });
1454
+ } else {
1455
+ throw new Error(`Unknown EDDS block magic: ${blockMagic}`);
1456
+ }
1457
+ }
1458
+ const { format, details } = detectFormat(header, dx10);
1459
+ this.format = format;
1460
+ this.formatDetails = details;
1461
+ if (blocks.length !== mipCount) {
1462
+ throw new Error("Block header count does not match mip map count");
1463
+ }
1464
+ this.mipmaps = new Array(mipCount);
1465
+ for (let mipIdx = 0; mipIdx < mipCount; mipIdx++) {
1466
+ const block = blocks[mipIdx];
1467
+ const mipLevel = mipCount - mipIdx - 1;
1468
+ const mipWidth = mipDimension(header.width, mipLevel);
1469
+ const mipHeight = mipDimension(header.height, mipLevel);
1470
+ let data;
1471
+ if (block.kind === "COPY") {
1472
+ const raw = reader.readBytes(block.size);
1473
+ data = new Uint8Array(raw);
1474
+ } else {
1475
+ data = decompressLz4Block(reader, block.size);
1476
+ }
1477
+ const expected = expectedDataLength(this.format, mipWidth, mipHeight);
1478
+ if (expected !== null && expected !== data.length) {
1479
+ throw new Error(`Unexpected mip level size (expected ${expected} bytes, got ${data.length})`);
1480
+ }
1481
+ this.mipmaps[mipLevel] = { width: mipWidth, height: mipHeight, data, compression: block.kind };
1482
+ }
1483
+ }
1484
+ getRgbaPixelData(mipLevel = 0) {
1485
+ if (this.mipmaps.length === 0) {
1486
+ throw new Error("No mipmaps loaded");
1487
+ }
1488
+ if (mipLevel < 0 || mipLevel >= this.mipmaps.length) {
1489
+ throw new RangeError(`mipLevel ${mipLevel} is out of range`);
1490
+ }
1491
+ const mip = this.mipmaps[mipLevel];
1492
+ return convertToRgba(mip, this.format);
1493
+ }
1494
+ get formatName() {
1495
+ if (this.formatDetails && this.format !== "UNKNOWN") {
1496
+ return `${this.format} (${this.formatDetails})`;
1497
+ }
1498
+ return this.formatDetails || this.format;
1499
+ }
1500
+ };
1501
+ export {
1502
+ Edds
1503
+ };
1504
+ /**
1505
+ * LZO1X compression and decompression
1506
+ * Based on https://github.com/thaumictom/lzo-ts
1507
+ * @license GPL-3.0
1508
+ */
1509
+ //# sourceMappingURL=index.js.map