@bis-toolkit/bcn 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 +674 -0
- package/README.md +63 -0
- package/dist/bc1.d.ts +5 -0
- package/dist/bc2.d.ts +5 -0
- package/dist/bc3.d.ts +5 -0
- package/dist/bc4.d.ts +5 -0
- package/dist/bc5.d.ts +5 -0
- package/dist/bc7.d.ts +5 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +1164 -0
- package/dist/index.js.map +7 -0
- package/dist/utils.d.ts +24 -0
- package/package.json +48 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1164 @@
|
|
|
1
|
+
// src/utils.ts
|
|
2
|
+
var ColorRgb565 = class {
|
|
3
|
+
constructor(r, g, b) {
|
|
4
|
+
if (r !== void 0 && g !== void 0 && b !== void 0) {
|
|
5
|
+
const r5 = r >> 3 & 31;
|
|
6
|
+
const g6 = g >> 2 & 63;
|
|
7
|
+
const b5 = b >> 3 & 31;
|
|
8
|
+
this.data = r5 << 11 | g6 << 5 | b5;
|
|
9
|
+
} else {
|
|
10
|
+
this.data = 0;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
toColorRgb24() {
|
|
14
|
+
const r5 = this.data >> 11 & 31;
|
|
15
|
+
const g6 = this.data >> 5 & 63;
|
|
16
|
+
const b5 = this.data & 31;
|
|
17
|
+
const r = r5 << 3 | r5 >> 2;
|
|
18
|
+
const g = g6 << 2 | g6 >> 4;
|
|
19
|
+
const b = b5 << 3 | b5 >> 2;
|
|
20
|
+
return { r, g, b };
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
function interpolateHalf(c0, c1) {
|
|
24
|
+
return {
|
|
25
|
+
r: (c0.r + c1.r) / 2 | 0,
|
|
26
|
+
g: (c0.g + c1.g) / 2 | 0,
|
|
27
|
+
b: (c0.b + c1.b) / 2 | 0
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function interpolateThird(c0, c1, step) {
|
|
31
|
+
if (step === 1) {
|
|
32
|
+
return {
|
|
33
|
+
r: (2 * c0.r + c1.r) / 3 | 0,
|
|
34
|
+
g: (2 * c0.g + c1.g) / 3 | 0,
|
|
35
|
+
b: (2 * c0.b + c1.b) / 3 | 0
|
|
36
|
+
};
|
|
37
|
+
} else {
|
|
38
|
+
return {
|
|
39
|
+
r: (c0.r + 2 * c1.r) / 3 | 0,
|
|
40
|
+
g: (c0.g + 2 * c1.g) / 3 | 0,
|
|
41
|
+
b: (c0.b + 2 * c1.b) / 3 | 0
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function interpolateByteFifth(e0, e1, step) {
|
|
46
|
+
if (step === 1) return (4 * e0 + e1) / 5 | 0;
|
|
47
|
+
if (step === 2) return (3 * e0 + 2 * e1) / 5 | 0;
|
|
48
|
+
if (step === 3) return (2 * e0 + 3 * e1) / 5 | 0;
|
|
49
|
+
return (e0 + 4 * e1) / 5 | 0;
|
|
50
|
+
}
|
|
51
|
+
function interpolateByteSeventh(e0, e1, step) {
|
|
52
|
+
if (step === 1) return (6 * e0 + e1) / 7 | 0;
|
|
53
|
+
if (step === 2) return (5 * e0 + 2 * e1) / 7 | 0;
|
|
54
|
+
if (step === 3) return (4 * e0 + 3 * e1) / 7 | 0;
|
|
55
|
+
if (step === 4) return (3 * e0 + 4 * e1) / 7 | 0;
|
|
56
|
+
if (step === 5) return (2 * e0 + 5 * e1) / 7 | 0;
|
|
57
|
+
return (e0 + 6 * e1) / 7 | 0;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// src/bc1.ts
|
|
61
|
+
function decodeBC1(data, width, height, useAlpha = false) {
|
|
62
|
+
const rgba = new Uint8Array(width * height * 4);
|
|
63
|
+
const blocksX = Math.ceil(width / 4);
|
|
64
|
+
const blocksY = Math.ceil(height / 4);
|
|
65
|
+
let offset = 0;
|
|
66
|
+
for (let by = 0; by < blocksY; by++) {
|
|
67
|
+
for (let bx = 0; bx < blocksX; bx++) {
|
|
68
|
+
const color0Data = data.getUint16(offset, true);
|
|
69
|
+
const color1Data = data.getUint16(offset + 2, true);
|
|
70
|
+
const indices = data.getUint32(offset + 4, true);
|
|
71
|
+
const color0 = new ColorRgb565();
|
|
72
|
+
color0.data = color0Data;
|
|
73
|
+
const color1 = new ColorRgb565();
|
|
74
|
+
color1.data = color1Data;
|
|
75
|
+
const c0 = color0.toColorRgb24();
|
|
76
|
+
const c1 = color1.toColorRgb24();
|
|
77
|
+
const hasAlphaOrBlack = color0Data <= color1Data;
|
|
78
|
+
const actualUseAlpha = useAlpha && hasAlphaOrBlack;
|
|
79
|
+
const colors = hasAlphaOrBlack ? [
|
|
80
|
+
c0,
|
|
81
|
+
c1,
|
|
82
|
+
interpolateHalf(c0, c1),
|
|
83
|
+
{ r: 0, g: 0, b: 0 }
|
|
84
|
+
] : [
|
|
85
|
+
c0,
|
|
86
|
+
c1,
|
|
87
|
+
interpolateThird(c0, c1, 1),
|
|
88
|
+
interpolateThird(c0, c1, 2)
|
|
89
|
+
];
|
|
90
|
+
for (let y = 0; y < 4; y++) {
|
|
91
|
+
for (let x = 0; x < 4; x++) {
|
|
92
|
+
const px = bx * 4 + x;
|
|
93
|
+
const py = by * 4 + y;
|
|
94
|
+
if (px < width && py < height) {
|
|
95
|
+
const i = y * 4 + x;
|
|
96
|
+
const colorIndex = indices >> i * 2 & 3;
|
|
97
|
+
const color = colors[colorIndex];
|
|
98
|
+
const dstIdx = (py * width + px) * 4;
|
|
99
|
+
if (actualUseAlpha && colorIndex === 3) {
|
|
100
|
+
rgba[dstIdx] = 0;
|
|
101
|
+
rgba[dstIdx + 1] = 0;
|
|
102
|
+
rgba[dstIdx + 2] = 0;
|
|
103
|
+
rgba[dstIdx + 3] = 0;
|
|
104
|
+
} else {
|
|
105
|
+
rgba[dstIdx] = color.r;
|
|
106
|
+
rgba[dstIdx + 1] = color.g;
|
|
107
|
+
rgba[dstIdx + 2] = color.b;
|
|
108
|
+
rgba[dstIdx + 3] = 255;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
offset += 8;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return rgba;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// src/bc2.ts
|
|
120
|
+
function decodeBC2(data, width, height) {
|
|
121
|
+
const rgba = new Uint8Array(width * height * 4);
|
|
122
|
+
const blocksX = Math.ceil(width / 4);
|
|
123
|
+
const blocksY = Math.ceil(height / 4);
|
|
124
|
+
let offset = 0;
|
|
125
|
+
for (let by = 0; by < blocksY; by++) {
|
|
126
|
+
for (let bx = 0; bx < blocksX; bx++) {
|
|
127
|
+
const alphaLow = data.getUint32(offset, true);
|
|
128
|
+
const alphaHigh = data.getUint32(offset + 4, true);
|
|
129
|
+
const color0Data = data.getUint16(offset + 8, true);
|
|
130
|
+
const color1Data = data.getUint16(offset + 10, true);
|
|
131
|
+
const indices = data.getUint32(offset + 12, true);
|
|
132
|
+
const color0 = new ColorRgb565();
|
|
133
|
+
color0.data = color0Data;
|
|
134
|
+
const color1 = new ColorRgb565();
|
|
135
|
+
color1.data = color1Data;
|
|
136
|
+
const c0 = color0.toColorRgb24();
|
|
137
|
+
const c1 = color1.toColorRgb24();
|
|
138
|
+
const colors = [
|
|
139
|
+
c0,
|
|
140
|
+
c1,
|
|
141
|
+
interpolateThird(c0, c1, 1),
|
|
142
|
+
interpolateThird(c0, c1, 2)
|
|
143
|
+
];
|
|
144
|
+
for (let y = 0; y < 4; y++) {
|
|
145
|
+
for (let x = 0; x < 4; x++) {
|
|
146
|
+
const px = bx * 4 + x;
|
|
147
|
+
const py = by * 4 + y;
|
|
148
|
+
if (px < width && py < height) {
|
|
149
|
+
const i = y * 4 + x;
|
|
150
|
+
const colorIndex = indices >> i * 2 & 3;
|
|
151
|
+
const color = colors[colorIndex];
|
|
152
|
+
const alphaIndex = i * 4;
|
|
153
|
+
let alpha;
|
|
154
|
+
if (alphaIndex < 32) {
|
|
155
|
+
alpha = alphaLow >> alphaIndex & 15;
|
|
156
|
+
} else {
|
|
157
|
+
alpha = alphaHigh >> alphaIndex - 32 & 15;
|
|
158
|
+
}
|
|
159
|
+
alpha = alpha << 4 | alpha;
|
|
160
|
+
const dstIdx = (py * width + px) * 4;
|
|
161
|
+
rgba[dstIdx] = color.r;
|
|
162
|
+
rgba[dstIdx + 1] = color.g;
|
|
163
|
+
rgba[dstIdx + 2] = color.b;
|
|
164
|
+
rgba[dstIdx + 3] = alpha;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
offset += 16;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return rgba;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// src/bc3.ts
|
|
175
|
+
function decodeAlphaBlock(alphaData) {
|
|
176
|
+
const alpha = new Array(16);
|
|
177
|
+
const alpha0 = Number(alphaData & 0xFFn);
|
|
178
|
+
const alpha1 = Number(alphaData >> 8n & 0xFFn);
|
|
179
|
+
const alphas = alpha0 > alpha1 ? [
|
|
180
|
+
alpha0,
|
|
181
|
+
alpha1,
|
|
182
|
+
interpolateByteSeventh(alpha0, alpha1, 1),
|
|
183
|
+
interpolateByteSeventh(alpha0, alpha1, 2),
|
|
184
|
+
interpolateByteSeventh(alpha0, alpha1, 3),
|
|
185
|
+
interpolateByteSeventh(alpha0, alpha1, 4),
|
|
186
|
+
interpolateByteSeventh(alpha0, alpha1, 5),
|
|
187
|
+
interpolateByteSeventh(alpha0, alpha1, 6)
|
|
188
|
+
] : [
|
|
189
|
+
alpha0,
|
|
190
|
+
alpha1,
|
|
191
|
+
interpolateByteFifth(alpha0, alpha1, 1),
|
|
192
|
+
interpolateByteFifth(alpha0, alpha1, 2),
|
|
193
|
+
interpolateByteFifth(alpha0, alpha1, 3),
|
|
194
|
+
interpolateByteFifth(alpha0, alpha1, 4),
|
|
195
|
+
0,
|
|
196
|
+
255
|
|
197
|
+
];
|
|
198
|
+
for (let i = 0; i < 16; i++) {
|
|
199
|
+
const bitOffset = 16 + i * 3;
|
|
200
|
+
const index = Number(alphaData >> BigInt(bitOffset) & 0x7n);
|
|
201
|
+
alpha[i] = alphas[index];
|
|
202
|
+
}
|
|
203
|
+
return alpha;
|
|
204
|
+
}
|
|
205
|
+
function decodeBC3(data, width, height) {
|
|
206
|
+
const rgba = new Uint8Array(width * height * 4);
|
|
207
|
+
const blocksX = Math.ceil(width / 4);
|
|
208
|
+
const blocksY = Math.ceil(height / 4);
|
|
209
|
+
let offset = 0;
|
|
210
|
+
for (let by = 0; by < blocksY; by++) {
|
|
211
|
+
for (let bx = 0; bx < blocksX; bx++) {
|
|
212
|
+
const alphaBlock = data.getBigUint64(offset, true);
|
|
213
|
+
const alphas = decodeAlphaBlock(alphaBlock);
|
|
214
|
+
const color0Data = data.getUint16(offset + 8, true);
|
|
215
|
+
const color1Data = data.getUint16(offset + 10, true);
|
|
216
|
+
const indices = data.getUint32(offset + 12, true);
|
|
217
|
+
const color0 = new ColorRgb565();
|
|
218
|
+
color0.data = color0Data;
|
|
219
|
+
const color1 = new ColorRgb565();
|
|
220
|
+
color1.data = color1Data;
|
|
221
|
+
const c0 = color0.toColorRgb24();
|
|
222
|
+
const c1 = color1.toColorRgb24();
|
|
223
|
+
const colors = [
|
|
224
|
+
c0,
|
|
225
|
+
c1,
|
|
226
|
+
interpolateThird(c0, c1, 1),
|
|
227
|
+
interpolateThird(c0, c1, 2)
|
|
228
|
+
];
|
|
229
|
+
for (let y = 0; y < 4; y++) {
|
|
230
|
+
for (let x = 0; x < 4; x++) {
|
|
231
|
+
const px = bx * 4 + x;
|
|
232
|
+
const py = by * 4 + y;
|
|
233
|
+
if (px < width && py < height) {
|
|
234
|
+
const i = y * 4 + x;
|
|
235
|
+
const colorIndex = indices >> i * 2 & 3;
|
|
236
|
+
const color = colors[colorIndex];
|
|
237
|
+
const dstIdx = (py * width + px) * 4;
|
|
238
|
+
rgba[dstIdx] = color.r;
|
|
239
|
+
rgba[dstIdx + 1] = color.g;
|
|
240
|
+
rgba[dstIdx + 2] = color.b;
|
|
241
|
+
rgba[dstIdx + 3] = alphas[i];
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
offset += 16;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return rgba;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// src/bc4.ts
|
|
252
|
+
function decodeComponentBlock(componentData) {
|
|
253
|
+
const output = new Array(16);
|
|
254
|
+
const c0 = Number(componentData & 0xFFn);
|
|
255
|
+
const c1 = Number(componentData >> 8n & 0xFFn);
|
|
256
|
+
const components = c0 > c1 ? [
|
|
257
|
+
c0,
|
|
258
|
+
c1,
|
|
259
|
+
interpolateByteSeventh(c0, c1, 1),
|
|
260
|
+
interpolateByteSeventh(c0, c1, 2),
|
|
261
|
+
interpolateByteSeventh(c0, c1, 3),
|
|
262
|
+
interpolateByteSeventh(c0, c1, 4),
|
|
263
|
+
interpolateByteSeventh(c0, c1, 5),
|
|
264
|
+
interpolateByteSeventh(c0, c1, 6)
|
|
265
|
+
] : [
|
|
266
|
+
c0,
|
|
267
|
+
c1,
|
|
268
|
+
interpolateByteFifth(c0, c1, 1),
|
|
269
|
+
interpolateByteFifth(c0, c1, 2),
|
|
270
|
+
interpolateByteFifth(c0, c1, 3),
|
|
271
|
+
interpolateByteFifth(c0, c1, 4),
|
|
272
|
+
0,
|
|
273
|
+
255
|
|
274
|
+
];
|
|
275
|
+
for (let i = 0; i < 16; i++) {
|
|
276
|
+
const bitOffset = 16 + i * 3;
|
|
277
|
+
const index = Number(componentData >> BigInt(bitOffset) & 0x7n);
|
|
278
|
+
output[i] = components[index];
|
|
279
|
+
}
|
|
280
|
+
return output;
|
|
281
|
+
}
|
|
282
|
+
function decodeBC4(data, width, height, channel = "r") {
|
|
283
|
+
const rgba = new Uint8Array(width * height * 4);
|
|
284
|
+
const blocksX = Math.ceil(width / 4);
|
|
285
|
+
const blocksY = Math.ceil(height / 4);
|
|
286
|
+
const channelMap = { r: 0, g: 1, b: 2, a: 3 };
|
|
287
|
+
const outputChannel = channelMap[channel];
|
|
288
|
+
let offset = 0;
|
|
289
|
+
for (let by = 0; by < blocksY; by++) {
|
|
290
|
+
for (let bx = 0; bx < blocksX; bx++) {
|
|
291
|
+
const componentBlock = data.getBigUint64(offset, true);
|
|
292
|
+
const components = decodeComponentBlock(componentBlock);
|
|
293
|
+
for (let y = 0; y < 4; y++) {
|
|
294
|
+
for (let x = 0; x < 4; x++) {
|
|
295
|
+
const px = bx * 4 + x;
|
|
296
|
+
const py = by * 4 + y;
|
|
297
|
+
if (px < width && py < height) {
|
|
298
|
+
const i = y * 4 + x;
|
|
299
|
+
const dstIdx = (py * width + px) * 4;
|
|
300
|
+
rgba[dstIdx] = 0;
|
|
301
|
+
rgba[dstIdx + 1] = 0;
|
|
302
|
+
rgba[dstIdx + 2] = 0;
|
|
303
|
+
rgba[dstIdx + 3] = 255;
|
|
304
|
+
rgba[dstIdx + outputChannel] = components[i];
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
offset += 8;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return rgba;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// src/bc5.ts
|
|
315
|
+
function decodeComponentBlock2(componentData) {
|
|
316
|
+
const output = new Array(16);
|
|
317
|
+
const c0 = Number(componentData & 0xFFn);
|
|
318
|
+
const c1 = Number(componentData >> 8n & 0xFFn);
|
|
319
|
+
const components = c0 > c1 ? [
|
|
320
|
+
c0,
|
|
321
|
+
c1,
|
|
322
|
+
interpolateByteSeventh(c0, c1, 1),
|
|
323
|
+
interpolateByteSeventh(c0, c1, 2),
|
|
324
|
+
interpolateByteSeventh(c0, c1, 3),
|
|
325
|
+
interpolateByteSeventh(c0, c1, 4),
|
|
326
|
+
interpolateByteSeventh(c0, c1, 5),
|
|
327
|
+
interpolateByteSeventh(c0, c1, 6)
|
|
328
|
+
] : [
|
|
329
|
+
c0,
|
|
330
|
+
c1,
|
|
331
|
+
interpolateByteFifth(c0, c1, 1),
|
|
332
|
+
interpolateByteFifth(c0, c1, 2),
|
|
333
|
+
interpolateByteFifth(c0, c1, 3),
|
|
334
|
+
interpolateByteFifth(c0, c1, 4),
|
|
335
|
+
0,
|
|
336
|
+
255
|
|
337
|
+
];
|
|
338
|
+
for (let i = 0; i < 16; i++) {
|
|
339
|
+
const bitOffset = 16 + i * 3;
|
|
340
|
+
const index = Number(componentData >> BigInt(bitOffset) & 0x7n);
|
|
341
|
+
output[i] = components[index];
|
|
342
|
+
}
|
|
343
|
+
return output;
|
|
344
|
+
}
|
|
345
|
+
function decodeBC5(data, width, height, channel1 = "r", channel2 = "g") {
|
|
346
|
+
const rgba = new Uint8Array(width * height * 4);
|
|
347
|
+
const blocksX = Math.ceil(width / 4);
|
|
348
|
+
const blocksY = Math.ceil(height / 4);
|
|
349
|
+
const channelMap = { r: 0, g: 1, b: 2, a: 3 };
|
|
350
|
+
const outputChannel1 = channelMap[channel1];
|
|
351
|
+
const outputChannel2 = channelMap[channel2];
|
|
352
|
+
let offset = 0;
|
|
353
|
+
for (let by = 0; by < blocksY; by++) {
|
|
354
|
+
for (let bx = 0; bx < blocksX; bx++) {
|
|
355
|
+
const redBlock = data.getBigUint64(offset, true);
|
|
356
|
+
const reds = decodeComponentBlock2(redBlock);
|
|
357
|
+
const greenBlock = data.getBigUint64(offset + 8, true);
|
|
358
|
+
const greens = decodeComponentBlock2(greenBlock);
|
|
359
|
+
for (let y = 0; y < 4; y++) {
|
|
360
|
+
for (let x = 0; x < 4; x++) {
|
|
361
|
+
const px = bx * 4 + x;
|
|
362
|
+
const py = by * 4 + y;
|
|
363
|
+
if (px < width && py < height) {
|
|
364
|
+
const i = y * 4 + x;
|
|
365
|
+
const dstIdx = (py * width + px) * 4;
|
|
366
|
+
rgba[dstIdx] = 0;
|
|
367
|
+
rgba[dstIdx + 1] = 0;
|
|
368
|
+
rgba[dstIdx + 2] = 0;
|
|
369
|
+
rgba[dstIdx + 3] = 255;
|
|
370
|
+
rgba[dstIdx + outputChannel1] = reds[i];
|
|
371
|
+
rgba[dstIdx + outputChannel2] = greens[i];
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
offset += 16;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return rgba;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// src/bc7.ts
|
|
382
|
+
var ByteHelper = class _ByteHelper {
|
|
383
|
+
static extract(source, index, bitCount) {
|
|
384
|
+
const mask = (1n << BigInt(bitCount)) - 1n;
|
|
385
|
+
return Number(source >> BigInt(index) & mask);
|
|
386
|
+
}
|
|
387
|
+
static extractFrom128(low, high, index, bitCount) {
|
|
388
|
+
if (index + bitCount <= 64) {
|
|
389
|
+
return _ByteHelper.extract(low, index, bitCount);
|
|
390
|
+
}
|
|
391
|
+
if (index >= 64) {
|
|
392
|
+
return _ByteHelper.extract(high, index - 64, bitCount);
|
|
393
|
+
}
|
|
394
|
+
const lowBitCount = 64 - index;
|
|
395
|
+
const highBitCount = bitCount - lowBitCount;
|
|
396
|
+
const lowValue = _ByteHelper.extract(low, index, lowBitCount);
|
|
397
|
+
const highValue = _ByteHelper.extract(high, 0, highBitCount);
|
|
398
|
+
return lowValue | highValue << lowBitCount;
|
|
399
|
+
}
|
|
400
|
+
static extract1(source, index) {
|
|
401
|
+
return Number(source >> BigInt(index) & 1n);
|
|
402
|
+
}
|
|
403
|
+
static extract2(source, index) {
|
|
404
|
+
return Number(source >> BigInt(index) & 3n);
|
|
405
|
+
}
|
|
406
|
+
static extract4(source, index) {
|
|
407
|
+
return Number(source >> BigInt(index) & 15n);
|
|
408
|
+
}
|
|
409
|
+
static extract6(source, index) {
|
|
410
|
+
return Number(source >> BigInt(index) & 63n);
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
var COLOR_WEIGHTS_2 = [0, 21, 43, 64];
|
|
414
|
+
var COLOR_WEIGHTS_3 = [0, 9, 18, 27, 37, 46, 55, 64];
|
|
415
|
+
var COLOR_WEIGHTS_4 = [0, 4, 9, 13, 17, 21, 26, 30, 34, 38, 43, 47, 51, 55, 60, 64];
|
|
416
|
+
function interpolateByte(e0, e1, index, indexPrecision) {
|
|
417
|
+
if (indexPrecision === 0) return e0;
|
|
418
|
+
const weights = indexPrecision === 2 ? COLOR_WEIGHTS_2 : indexPrecision === 3 ? COLOR_WEIGHTS_3 : COLOR_WEIGHTS_4;
|
|
419
|
+
const w = weights[index];
|
|
420
|
+
return (64 - w) * e0 + w * e1 + 32 >> 6;
|
|
421
|
+
}
|
|
422
|
+
var SUBSETS_2_PARTITION_TABLE = [
|
|
423
|
+
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1],
|
|
424
|
+
[0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1],
|
|
425
|
+
[0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1],
|
|
426
|
+
[0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1],
|
|
427
|
+
[0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1],
|
|
428
|
+
[0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1],
|
|
429
|
+
[0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1],
|
|
430
|
+
[0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1],
|
|
431
|
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1],
|
|
432
|
+
[0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
|
|
433
|
+
[0, 0, 0, 0, 0, 0, 0, 1, 0, 1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,
|
|
567
|
+
15,
|
|
568
|
+
15,
|
|
569
|
+
15,
|
|
570
|
+
15,
|
|
571
|
+
15,
|
|
572
|
+
2,
|
|
573
|
+
8,
|
|
574
|
+
2,
|
|
575
|
+
2,
|
|
576
|
+
8,
|
|
577
|
+
8,
|
|
578
|
+
15,
|
|
579
|
+
2,
|
|
580
|
+
8,
|
|
581
|
+
2,
|
|
582
|
+
2,
|
|
583
|
+
8,
|
|
584
|
+
8,
|
|
585
|
+
2,
|
|
586
|
+
2,
|
|
587
|
+
15,
|
|
588
|
+
15,
|
|
589
|
+
6,
|
|
590
|
+
8,
|
|
591
|
+
2,
|
|
592
|
+
8,
|
|
593
|
+
15,
|
|
594
|
+
15,
|
|
595
|
+
2,
|
|
596
|
+
8,
|
|
597
|
+
2,
|
|
598
|
+
2,
|
|
599
|
+
2,
|
|
600
|
+
15,
|
|
601
|
+
15,
|
|
602
|
+
6,
|
|
603
|
+
6,
|
|
604
|
+
2,
|
|
605
|
+
6,
|
|
606
|
+
8,
|
|
607
|
+
15,
|
|
608
|
+
15,
|
|
609
|
+
2,
|
|
610
|
+
2,
|
|
611
|
+
15,
|
|
612
|
+
15,
|
|
613
|
+
15,
|
|
614
|
+
15,
|
|
615
|
+
15,
|
|
616
|
+
2,
|
|
617
|
+
2,
|
|
618
|
+
15
|
|
619
|
+
];
|
|
620
|
+
var SUBSETS_3_ANCHOR_INDICES_2 = [
|
|
621
|
+
3,
|
|
622
|
+
3,
|
|
623
|
+
15,
|
|
624
|
+
15,
|
|
625
|
+
8,
|
|
626
|
+
3,
|
|
627
|
+
15,
|
|
628
|
+
15,
|
|
629
|
+
8,
|
|
630
|
+
8,
|
|
631
|
+
6,
|
|
632
|
+
6,
|
|
633
|
+
6,
|
|
634
|
+
5,
|
|
635
|
+
3,
|
|
636
|
+
3,
|
|
637
|
+
3,
|
|
638
|
+
3,
|
|
639
|
+
8,
|
|
640
|
+
15,
|
|
641
|
+
3,
|
|
642
|
+
3,
|
|
643
|
+
6,
|
|
644
|
+
10,
|
|
645
|
+
5,
|
|
646
|
+
8,
|
|
647
|
+
8,
|
|
648
|
+
6,
|
|
649
|
+
8,
|
|
650
|
+
5,
|
|
651
|
+
15,
|
|
652
|
+
15,
|
|
653
|
+
8,
|
|
654
|
+
15,
|
|
655
|
+
3,
|
|
656
|
+
5,
|
|
657
|
+
6,
|
|
658
|
+
10,
|
|
659
|
+
8,
|
|
660
|
+
15,
|
|
661
|
+
15,
|
|
662
|
+
3,
|
|
663
|
+
15,
|
|
664
|
+
5,
|
|
665
|
+
15,
|
|
666
|
+
15,
|
|
667
|
+
15,
|
|
668
|
+
15,
|
|
669
|
+
3,
|
|
670
|
+
15,
|
|
671
|
+
5,
|
|
672
|
+
5,
|
|
673
|
+
5,
|
|
674
|
+
8,
|
|
675
|
+
5,
|
|
676
|
+
10,
|
|
677
|
+
5,
|
|
678
|
+
10,
|
|
679
|
+
8,
|
|
680
|
+
13,
|
|
681
|
+
15,
|
|
682
|
+
12,
|
|
683
|
+
3,
|
|
684
|
+
3
|
|
685
|
+
];
|
|
686
|
+
var SUBSETS_3_ANCHOR_INDICES_3 = [
|
|
687
|
+
15,
|
|
688
|
+
8,
|
|
689
|
+
8,
|
|
690
|
+
3,
|
|
691
|
+
15,
|
|
692
|
+
15,
|
|
693
|
+
3,
|
|
694
|
+
8,
|
|
695
|
+
15,
|
|
696
|
+
15,
|
|
697
|
+
15,
|
|
698
|
+
15,
|
|
699
|
+
15,
|
|
700
|
+
15,
|
|
701
|
+
15,
|
|
702
|
+
8,
|
|
703
|
+
15,
|
|
704
|
+
8,
|
|
705
|
+
15,
|
|
706
|
+
3,
|
|
707
|
+
15,
|
|
708
|
+
8,
|
|
709
|
+
15,
|
|
710
|
+
8,
|
|
711
|
+
3,
|
|
712
|
+
15,
|
|
713
|
+
6,
|
|
714
|
+
10,
|
|
715
|
+
15,
|
|
716
|
+
15,
|
|
717
|
+
10,
|
|
718
|
+
8,
|
|
719
|
+
15,
|
|
720
|
+
3,
|
|
721
|
+
15,
|
|
722
|
+
10,
|
|
723
|
+
10,
|
|
724
|
+
8,
|
|
725
|
+
9,
|
|
726
|
+
10,
|
|
727
|
+
6,
|
|
728
|
+
15,
|
|
729
|
+
8,
|
|
730
|
+
15,
|
|
731
|
+
3,
|
|
732
|
+
6,
|
|
733
|
+
6,
|
|
734
|
+
8,
|
|
735
|
+
15,
|
|
736
|
+
3,
|
|
737
|
+
15,
|
|
738
|
+
15,
|
|
739
|
+
15,
|
|
740
|
+
15,
|
|
741
|
+
15,
|
|
742
|
+
15,
|
|
743
|
+
15,
|
|
744
|
+
15,
|
|
745
|
+
15,
|
|
746
|
+
15,
|
|
747
|
+
3,
|
|
748
|
+
15,
|
|
749
|
+
15,
|
|
750
|
+
8
|
|
751
|
+
];
|
|
752
|
+
var Bc7Block = class {
|
|
753
|
+
constructor(data) {
|
|
754
|
+
const view = new DataView(data.buffer, data.byteOffset, 16);
|
|
755
|
+
this.lowBits = view.getBigUint64(0, true);
|
|
756
|
+
this.highBits = view.getBigUint64(8, true);
|
|
757
|
+
}
|
|
758
|
+
getType() {
|
|
759
|
+
for (let i = 0; i < 8; i++) {
|
|
760
|
+
const mask = 1n << BigInt(i);
|
|
761
|
+
if ((this.lowBits & mask) === mask) {
|
|
762
|
+
return i;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
return 8;
|
|
766
|
+
}
|
|
767
|
+
getNumSubsets(type) {
|
|
768
|
+
if (type === 0 || type === 2) return 3;
|
|
769
|
+
if (type === 1 || type === 3 || type === 7) return 2;
|
|
770
|
+
return 1;
|
|
771
|
+
}
|
|
772
|
+
getPartitionSetId(type) {
|
|
773
|
+
switch (type) {
|
|
774
|
+
case 0:
|
|
775
|
+
return ByteHelper.extract4(this.lowBits, 1);
|
|
776
|
+
case 1:
|
|
777
|
+
return ByteHelper.extract6(this.lowBits, 2);
|
|
778
|
+
case 2:
|
|
779
|
+
return ByteHelper.extract6(this.lowBits, 3);
|
|
780
|
+
case 3:
|
|
781
|
+
return ByteHelper.extract6(this.lowBits, 4);
|
|
782
|
+
case 7:
|
|
783
|
+
return ByteHelper.extract6(this.lowBits, 8);
|
|
784
|
+
default:
|
|
785
|
+
return 0;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
getRotationBits(type) {
|
|
789
|
+
if (type === 4) return ByteHelper.extract2(this.lowBits, 5);
|
|
790
|
+
if (type === 5) return ByteHelper.extract2(this.lowBits, 6);
|
|
791
|
+
return 0;
|
|
792
|
+
}
|
|
793
|
+
getColorComponentPrecision(type) {
|
|
794
|
+
const precisions = [5, 7, 5, 8, 5, 7, 8, 6];
|
|
795
|
+
return precisions[type] || 0;
|
|
796
|
+
}
|
|
797
|
+
getAlphaComponentPrecision(type) {
|
|
798
|
+
if (type === 4) return 6;
|
|
799
|
+
if (type === 5 || type === 6) return 8;
|
|
800
|
+
if (type === 7) return 6;
|
|
801
|
+
return 0;
|
|
802
|
+
}
|
|
803
|
+
getType4IndexMode() {
|
|
804
|
+
return ByteHelper.extract1(this.lowBits, 7);
|
|
805
|
+
}
|
|
806
|
+
getColorIndexBitCount(type) {
|
|
807
|
+
if (type === 0 || type === 1) return 3;
|
|
808
|
+
if (type === 2 || type === 3 || type === 5 || type === 7) return 2;
|
|
809
|
+
if (type === 4) {
|
|
810
|
+
const indexMode = this.getType4IndexMode();
|
|
811
|
+
return indexMode === 0 ? 2 : 3;
|
|
812
|
+
}
|
|
813
|
+
if (type === 6) return 4;
|
|
814
|
+
return 0;
|
|
815
|
+
}
|
|
816
|
+
getAlphaIndexBitCount(type) {
|
|
817
|
+
if (type === 4) {
|
|
818
|
+
const indexMode = this.getType4IndexMode();
|
|
819
|
+
return indexMode === 0 ? 3 : 2;
|
|
820
|
+
}
|
|
821
|
+
if (type === 5 || type === 7) return 2;
|
|
822
|
+
if (type === 6) return 4;
|
|
823
|
+
return 0;
|
|
824
|
+
}
|
|
825
|
+
extractRawEndpoints(type, numSubsets) {
|
|
826
|
+
const endpoints = Array(numSubsets * 2).fill(null).map(() => ({ r: 0, g: 0, b: 0, a: 0 }));
|
|
827
|
+
switch (type) {
|
|
828
|
+
case 0:
|
|
829
|
+
for (let i = 0; i < 6; i++) {
|
|
830
|
+
endpoints[i].r = ByteHelper.extractFrom128(this.lowBits, this.highBits, 5 + i * 4, 4);
|
|
831
|
+
endpoints[i].g = ByteHelper.extractFrom128(this.lowBits, this.highBits, 29 + i * 4, 4);
|
|
832
|
+
endpoints[i].b = ByteHelper.extractFrom128(this.lowBits, this.highBits, 53 + i * 4, 4);
|
|
833
|
+
}
|
|
834
|
+
break;
|
|
835
|
+
case 1:
|
|
836
|
+
for (let i = 0; i < 4; i++) {
|
|
837
|
+
endpoints[i].r = ByteHelper.extractFrom128(this.lowBits, this.highBits, 8 + i * 6, 6);
|
|
838
|
+
endpoints[i].g = ByteHelper.extractFrom128(this.lowBits, this.highBits, 32 + i * 6, 6);
|
|
839
|
+
endpoints[i].b = ByteHelper.extractFrom128(this.lowBits, this.highBits, 56 + i * 6, 6);
|
|
840
|
+
}
|
|
841
|
+
break;
|
|
842
|
+
case 2:
|
|
843
|
+
for (let i = 0; i < 6; i++) {
|
|
844
|
+
endpoints[i].r = ByteHelper.extractFrom128(this.lowBits, this.highBits, 9 + i * 5, 5);
|
|
845
|
+
endpoints[i].g = ByteHelper.extractFrom128(this.lowBits, this.highBits, 39 + i * 5, 5);
|
|
846
|
+
endpoints[i].b = ByteHelper.extractFrom128(this.lowBits, this.highBits, 69 + i * 5, 5);
|
|
847
|
+
}
|
|
848
|
+
break;
|
|
849
|
+
case 3:
|
|
850
|
+
for (let i = 0; i < 4; i++) {
|
|
851
|
+
endpoints[i].r = ByteHelper.extractFrom128(this.lowBits, this.highBits, 10 + i * 7, 7);
|
|
852
|
+
endpoints[i].g = ByteHelper.extractFrom128(this.lowBits, this.highBits, 38 + i * 7, 7);
|
|
853
|
+
endpoints[i].b = ByteHelper.extractFrom128(this.lowBits, this.highBits, 66 + i * 7, 7);
|
|
854
|
+
}
|
|
855
|
+
break;
|
|
856
|
+
case 4:
|
|
857
|
+
endpoints[0].r = ByteHelper.extractFrom128(this.lowBits, this.highBits, 8, 5);
|
|
858
|
+
endpoints[1].r = ByteHelper.extractFrom128(this.lowBits, this.highBits, 13, 5);
|
|
859
|
+
endpoints[0].g = ByteHelper.extractFrom128(this.lowBits, this.highBits, 18, 5);
|
|
860
|
+
endpoints[1].g = ByteHelper.extractFrom128(this.lowBits, this.highBits, 23, 5);
|
|
861
|
+
endpoints[0].b = ByteHelper.extractFrom128(this.lowBits, this.highBits, 28, 5);
|
|
862
|
+
endpoints[1].b = ByteHelper.extractFrom128(this.lowBits, this.highBits, 33, 5);
|
|
863
|
+
endpoints[0].a = ByteHelper.extractFrom128(this.lowBits, this.highBits, 38, 6);
|
|
864
|
+
endpoints[1].a = ByteHelper.extractFrom128(this.lowBits, this.highBits, 44, 6);
|
|
865
|
+
break;
|
|
866
|
+
case 5:
|
|
867
|
+
endpoints[0].r = ByteHelper.extractFrom128(this.lowBits, this.highBits, 8, 7);
|
|
868
|
+
endpoints[1].r = ByteHelper.extractFrom128(this.lowBits, this.highBits, 15, 7);
|
|
869
|
+
endpoints[0].g = ByteHelper.extractFrom128(this.lowBits, this.highBits, 22, 7);
|
|
870
|
+
endpoints[1].g = ByteHelper.extractFrom128(this.lowBits, this.highBits, 29, 7);
|
|
871
|
+
endpoints[0].b = ByteHelper.extractFrom128(this.lowBits, this.highBits, 36, 7);
|
|
872
|
+
endpoints[1].b = ByteHelper.extractFrom128(this.lowBits, this.highBits, 43, 7);
|
|
873
|
+
endpoints[0].a = ByteHelper.extractFrom128(this.lowBits, this.highBits, 50, 8);
|
|
874
|
+
endpoints[1].a = ByteHelper.extractFrom128(this.lowBits, this.highBits, 58, 8);
|
|
875
|
+
break;
|
|
876
|
+
case 6:
|
|
877
|
+
endpoints[0].r = ByteHelper.extractFrom128(this.lowBits, this.highBits, 7, 7);
|
|
878
|
+
endpoints[1].r = ByteHelper.extractFrom128(this.lowBits, this.highBits, 14, 7);
|
|
879
|
+
endpoints[0].g = ByteHelper.extractFrom128(this.lowBits, this.highBits, 21, 7);
|
|
880
|
+
endpoints[1].g = ByteHelper.extractFrom128(this.lowBits, this.highBits, 28, 7);
|
|
881
|
+
endpoints[0].b = ByteHelper.extractFrom128(this.lowBits, this.highBits, 35, 7);
|
|
882
|
+
endpoints[1].b = ByteHelper.extractFrom128(this.lowBits, this.highBits, 42, 7);
|
|
883
|
+
endpoints[0].a = ByteHelper.extractFrom128(this.lowBits, this.highBits, 49, 7);
|
|
884
|
+
endpoints[1].a = ByteHelper.extractFrom128(this.lowBits, this.highBits, 56, 7);
|
|
885
|
+
break;
|
|
886
|
+
case 7:
|
|
887
|
+
for (let i = 0; i < 4; i++) {
|
|
888
|
+
endpoints[i].r = ByteHelper.extractFrom128(this.lowBits, this.highBits, 14 + i * 5, 5);
|
|
889
|
+
endpoints[i].g = ByteHelper.extractFrom128(this.lowBits, this.highBits, 34 + i * 5, 5);
|
|
890
|
+
endpoints[i].b = ByteHelper.extractFrom128(this.lowBits, this.highBits, 54 + i * 5, 5);
|
|
891
|
+
endpoints[i].a = ByteHelper.extractFrom128(this.lowBits, this.highBits, 74 + i * 5, 5);
|
|
892
|
+
}
|
|
893
|
+
break;
|
|
894
|
+
}
|
|
895
|
+
return endpoints;
|
|
896
|
+
}
|
|
897
|
+
extractPBits(type, _numSubsets) {
|
|
898
|
+
switch (type) {
|
|
899
|
+
case 0:
|
|
900
|
+
return [
|
|
901
|
+
ByteHelper.extract1(this.highBits, 77 - 64),
|
|
902
|
+
ByteHelper.extract1(this.highBits, 78 - 64),
|
|
903
|
+
ByteHelper.extract1(this.highBits, 79 - 64),
|
|
904
|
+
ByteHelper.extract1(this.highBits, 80 - 64),
|
|
905
|
+
ByteHelper.extract1(this.highBits, 81 - 64),
|
|
906
|
+
ByteHelper.extract1(this.highBits, 82 - 64)
|
|
907
|
+
];
|
|
908
|
+
case 1:
|
|
909
|
+
return [
|
|
910
|
+
ByteHelper.extract1(this.highBits, 80 - 64),
|
|
911
|
+
ByteHelper.extract1(this.highBits, 81 - 64)
|
|
912
|
+
];
|
|
913
|
+
case 3:
|
|
914
|
+
return [
|
|
915
|
+
ByteHelper.extract1(this.highBits, 94 - 64),
|
|
916
|
+
ByteHelper.extract1(this.highBits, 95 - 64),
|
|
917
|
+
ByteHelper.extract1(this.highBits, 96 - 64),
|
|
918
|
+
ByteHelper.extract1(this.highBits, 97 - 64)
|
|
919
|
+
];
|
|
920
|
+
case 6:
|
|
921
|
+
return [
|
|
922
|
+
ByteHelper.extract1(this.lowBits, 63),
|
|
923
|
+
ByteHelper.extract1(this.highBits, 0)
|
|
924
|
+
];
|
|
925
|
+
case 7:
|
|
926
|
+
return [
|
|
927
|
+
ByteHelper.extract1(this.highBits, 94 - 64),
|
|
928
|
+
ByteHelper.extract1(this.highBits, 95 - 64),
|
|
929
|
+
ByteHelper.extract1(this.highBits, 96 - 64),
|
|
930
|
+
ByteHelper.extract1(this.highBits, 97 - 64)
|
|
931
|
+
];
|
|
932
|
+
default:
|
|
933
|
+
return [];
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
hasPBits(type) {
|
|
937
|
+
return type === 0 || type === 1 || type === 3 || type === 6 || type === 7;
|
|
938
|
+
}
|
|
939
|
+
hasAlpha(type) {
|
|
940
|
+
return type === 4 || type === 5 || type === 6 || type === 7;
|
|
941
|
+
}
|
|
942
|
+
finalizeEndpoints(endpoints, type) {
|
|
943
|
+
const hasPBits = this.hasPBits(type);
|
|
944
|
+
if (hasPBits) {
|
|
945
|
+
const pBits = this.extractPBits(type, endpoints.length);
|
|
946
|
+
for (const ep of endpoints) {
|
|
947
|
+
ep.r <<= 1;
|
|
948
|
+
ep.g <<= 1;
|
|
949
|
+
ep.b <<= 1;
|
|
950
|
+
ep.a <<= 1;
|
|
951
|
+
}
|
|
952
|
+
if (type === 1) {
|
|
953
|
+
endpoints[0].r |= pBits[0];
|
|
954
|
+
endpoints[0].g |= pBits[0];
|
|
955
|
+
endpoints[0].b |= pBits[0];
|
|
956
|
+
endpoints[1].r |= pBits[0];
|
|
957
|
+
endpoints[1].g |= pBits[0];
|
|
958
|
+
endpoints[1].b |= pBits[0];
|
|
959
|
+
endpoints[2].r |= pBits[1];
|
|
960
|
+
endpoints[2].g |= pBits[1];
|
|
961
|
+
endpoints[2].b |= pBits[1];
|
|
962
|
+
endpoints[3].r |= pBits[1];
|
|
963
|
+
endpoints[3].g |= pBits[1];
|
|
964
|
+
endpoints[3].b |= pBits[1];
|
|
965
|
+
} else {
|
|
966
|
+
for (let i = 0; i < endpoints.length; i++) {
|
|
967
|
+
endpoints[i].r |= pBits[i];
|
|
968
|
+
endpoints[i].g |= pBits[i];
|
|
969
|
+
endpoints[i].b |= pBits[i];
|
|
970
|
+
if (this.hasAlpha(type)) {
|
|
971
|
+
endpoints[i].a |= pBits[i];
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
const colorPrec = this.getColorComponentPrecision(type);
|
|
977
|
+
const alphaPrec = this.getAlphaComponentPrecision(type);
|
|
978
|
+
for (const ep of endpoints) {
|
|
979
|
+
ep.r = ep.r << 8 - colorPrec | ep.r >> colorPrec - (8 - colorPrec);
|
|
980
|
+
ep.g = ep.g << 8 - colorPrec | ep.g >> colorPrec - (8 - colorPrec);
|
|
981
|
+
ep.b = ep.b << 8 - colorPrec | ep.b >> colorPrec - (8 - colorPrec);
|
|
982
|
+
ep.a = alphaPrec > 0 ? ep.a << 8 - alphaPrec | ep.a >> alphaPrec - (8 - alphaPrec) : 255;
|
|
983
|
+
}
|
|
984
|
+
if (!this.hasAlpha(type)) {
|
|
985
|
+
for (const ep of endpoints) {
|
|
986
|
+
ep.a = 255;
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
getPartitionIndex(numSubsets, partitionSetId, pixelIndex) {
|
|
991
|
+
if (numSubsets === 1) return 0;
|
|
992
|
+
if (numSubsets === 2) return SUBSETS_2_PARTITION_TABLE[partitionSetId][pixelIndex];
|
|
993
|
+
return SUBSETS_3_PARTITION_TABLE[partitionSetId][pixelIndex];
|
|
994
|
+
}
|
|
995
|
+
getIndexBegin(type, bitCount, isAlpha) {
|
|
996
|
+
switch (type) {
|
|
997
|
+
case 0:
|
|
998
|
+
return 83;
|
|
999
|
+
case 1:
|
|
1000
|
+
return 82;
|
|
1001
|
+
case 2:
|
|
1002
|
+
return 99;
|
|
1003
|
+
case 3:
|
|
1004
|
+
return 98;
|
|
1005
|
+
case 4:
|
|
1006
|
+
return bitCount === 2 ? 50 : 81;
|
|
1007
|
+
case 5:
|
|
1008
|
+
return isAlpha ? 97 : 66;
|
|
1009
|
+
case 6:
|
|
1010
|
+
return 65;
|
|
1011
|
+
case 7:
|
|
1012
|
+
return 98;
|
|
1013
|
+
default:
|
|
1014
|
+
return 0;
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
getIndexBitCount(numSubsets, partitionIndex, bitCount, pixelIndex) {
|
|
1018
|
+
if (pixelIndex === 0) return bitCount - 1;
|
|
1019
|
+
if (numSubsets === 2) {
|
|
1020
|
+
const anchorIndex = SUBSETS_2_ANCHOR_INDICES[partitionIndex];
|
|
1021
|
+
if (pixelIndex === anchorIndex) return bitCount - 1;
|
|
1022
|
+
} else if (numSubsets === 3) {
|
|
1023
|
+
const anchor2 = SUBSETS_3_ANCHOR_INDICES_2[partitionIndex];
|
|
1024
|
+
const anchor3 = SUBSETS_3_ANCHOR_INDICES_3[partitionIndex];
|
|
1025
|
+
if (pixelIndex === anchor2 || pixelIndex === anchor3) return bitCount - 1;
|
|
1026
|
+
}
|
|
1027
|
+
return bitCount;
|
|
1028
|
+
}
|
|
1029
|
+
getIndexOffset(type, numSubsets, partitionIndex, bitCount, pixelIndex) {
|
|
1030
|
+
if (pixelIndex === 0) return 0;
|
|
1031
|
+
if (numSubsets === 1) {
|
|
1032
|
+
return bitCount * pixelIndex - 1;
|
|
1033
|
+
}
|
|
1034
|
+
if (numSubsets === 2) {
|
|
1035
|
+
const anchorIndex = SUBSETS_2_ANCHOR_INDICES[partitionIndex];
|
|
1036
|
+
if (pixelIndex <= anchorIndex) {
|
|
1037
|
+
return bitCount * pixelIndex - 1;
|
|
1038
|
+
} else {
|
|
1039
|
+
return bitCount * pixelIndex - 2;
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
if (numSubsets === 3) {
|
|
1043
|
+
const anchor2 = SUBSETS_3_ANCHOR_INDICES_2[partitionIndex];
|
|
1044
|
+
const anchor3 = SUBSETS_3_ANCHOR_INDICES_3[partitionIndex];
|
|
1045
|
+
if (pixelIndex <= anchor2 && pixelIndex <= anchor3) {
|
|
1046
|
+
return bitCount * pixelIndex - 1;
|
|
1047
|
+
} else if (pixelIndex > anchor2 && pixelIndex > anchor3) {
|
|
1048
|
+
return bitCount * pixelIndex - 3;
|
|
1049
|
+
} else {
|
|
1050
|
+
return bitCount * pixelIndex - 2;
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
return 0;
|
|
1054
|
+
}
|
|
1055
|
+
getColorIndex(type, numSubsets, partitionIndex, bitCount, pixelIndex) {
|
|
1056
|
+
const indexOffset = this.getIndexOffset(type, numSubsets, partitionIndex, bitCount, pixelIndex);
|
|
1057
|
+
const indexBitCount = this.getIndexBitCount(numSubsets, partitionIndex, bitCount, pixelIndex);
|
|
1058
|
+
const indexBegin = this.getIndexBegin(type, bitCount, false);
|
|
1059
|
+
return ByteHelper.extractFrom128(this.lowBits, this.highBits, indexBegin + indexOffset, indexBitCount);
|
|
1060
|
+
}
|
|
1061
|
+
getAlphaIndex(type, numSubsets, partitionIndex, bitCount, pixelIndex) {
|
|
1062
|
+
if (bitCount === 0) return 0;
|
|
1063
|
+
const indexOffset = this.getIndexOffset(type, numSubsets, partitionIndex, bitCount, pixelIndex);
|
|
1064
|
+
const indexBitCount = this.getIndexBitCount(numSubsets, partitionIndex, bitCount, pixelIndex);
|
|
1065
|
+
const indexBegin = this.getIndexBegin(type, bitCount, true);
|
|
1066
|
+
return ByteHelper.extractFrom128(this.lowBits, this.highBits, indexBegin + indexOffset, indexBitCount);
|
|
1067
|
+
}
|
|
1068
|
+
swapChannels(color, rotation) {
|
|
1069
|
+
switch (rotation) {
|
|
1070
|
+
case 0:
|
|
1071
|
+
return color;
|
|
1072
|
+
case 1:
|
|
1073
|
+
return { r: color.a, g: color.g, b: color.b, a: color.r };
|
|
1074
|
+
case 2:
|
|
1075
|
+
return { r: color.r, g: color.a, b: color.b, a: color.g };
|
|
1076
|
+
case 3:
|
|
1077
|
+
return { r: color.r, g: color.g, b: color.a, a: color.b };
|
|
1078
|
+
default:
|
|
1079
|
+
return color;
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
decode() {
|
|
1083
|
+
const output = new Uint8Array(16 * 4);
|
|
1084
|
+
const type = this.getType();
|
|
1085
|
+
if (type === 8) {
|
|
1086
|
+
for (let i = 0; i < 16; i++) {
|
|
1087
|
+
output[i * 4] = 255;
|
|
1088
|
+
output[i * 4 + 1] = 0;
|
|
1089
|
+
output[i * 4 + 2] = 255;
|
|
1090
|
+
output[i * 4 + 3] = 255;
|
|
1091
|
+
}
|
|
1092
|
+
return output;
|
|
1093
|
+
}
|
|
1094
|
+
const numSubsets = this.getNumSubsets(type);
|
|
1095
|
+
const partitionSetId = this.getPartitionSetId(type);
|
|
1096
|
+
const rotation = this.getRotationBits(type);
|
|
1097
|
+
const endpoints = this.extractRawEndpoints(type, numSubsets);
|
|
1098
|
+
this.finalizeEndpoints(endpoints, type);
|
|
1099
|
+
const colorBitCount = this.getColorIndexBitCount(type);
|
|
1100
|
+
const alphaBitCount = this.getAlphaIndexBitCount(type);
|
|
1101
|
+
for (let i = 0; i < 16; i++) {
|
|
1102
|
+
const subsetIndex = this.getPartitionIndex(numSubsets, partitionSetId, i);
|
|
1103
|
+
const ep0 = endpoints[2 * subsetIndex];
|
|
1104
|
+
const ep1 = endpoints[2 * subsetIndex + 1];
|
|
1105
|
+
const colorIndex = this.getColorIndex(type, numSubsets, partitionSetId, colorBitCount, i);
|
|
1106
|
+
const alphaIndex = this.getAlphaIndex(type, numSubsets, partitionSetId, alphaBitCount, i);
|
|
1107
|
+
let color = {
|
|
1108
|
+
r: interpolateByte(ep0.r, ep1.r, colorIndex, colorBitCount),
|
|
1109
|
+
g: interpolateByte(ep0.g, ep1.g, colorIndex, colorBitCount),
|
|
1110
|
+
b: interpolateByte(ep0.b, ep1.b, colorIndex, colorBitCount),
|
|
1111
|
+
a: interpolateByte(ep0.a, ep1.a, alphaIndex, alphaBitCount || colorBitCount)
|
|
1112
|
+
};
|
|
1113
|
+
if (rotation > 0) {
|
|
1114
|
+
color = this.swapChannels(color, rotation);
|
|
1115
|
+
}
|
|
1116
|
+
output[i * 4] = color.r;
|
|
1117
|
+
output[i * 4 + 1] = color.g;
|
|
1118
|
+
output[i * 4 + 2] = color.b;
|
|
1119
|
+
output[i * 4 + 3] = color.a;
|
|
1120
|
+
}
|
|
1121
|
+
return output;
|
|
1122
|
+
}
|
|
1123
|
+
};
|
|
1124
|
+
function decodeBC7(imageData, width, height) {
|
|
1125
|
+
const rgba = new Uint8Array(width * height * 4);
|
|
1126
|
+
const blocksX = Math.ceil(width / 4);
|
|
1127
|
+
const blocksY = Math.ceil(height / 4);
|
|
1128
|
+
let offset = 0;
|
|
1129
|
+
for (let by = 0; by < blocksY; by++) {
|
|
1130
|
+
for (let bx = 0; bx < blocksX; bx++) {
|
|
1131
|
+
const blockData = new Uint8Array(16);
|
|
1132
|
+
for (let i = 0; i < 16; i++) {
|
|
1133
|
+
blockData[i] = imageData.getUint8(offset + i);
|
|
1134
|
+
}
|
|
1135
|
+
const block = new Bc7Block(blockData);
|
|
1136
|
+
const decodedBlock = block.decode();
|
|
1137
|
+
for (let y = 0; y < 4; y++) {
|
|
1138
|
+
for (let x = 0; x < 4; x++) {
|
|
1139
|
+
const px = bx * 4 + x;
|
|
1140
|
+
const py = by * 4 + y;
|
|
1141
|
+
if (px < width && py < height) {
|
|
1142
|
+
const srcIdx = (y * 4 + x) * 4;
|
|
1143
|
+
const dstIdx = (py * width + px) * 4;
|
|
1144
|
+
rgba[dstIdx] = decodedBlock[srcIdx];
|
|
1145
|
+
rgba[dstIdx + 1] = decodedBlock[srcIdx + 1];
|
|
1146
|
+
rgba[dstIdx + 2] = decodedBlock[srcIdx + 2];
|
|
1147
|
+
rgba[dstIdx + 3] = decodedBlock[srcIdx + 3];
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
offset += 16;
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
return rgba;
|
|
1155
|
+
}
|
|
1156
|
+
export {
|
|
1157
|
+
decodeBC1,
|
|
1158
|
+
decodeBC2,
|
|
1159
|
+
decodeBC3,
|
|
1160
|
+
decodeBC4,
|
|
1161
|
+
decodeBC5,
|
|
1162
|
+
decodeBC7
|
|
1163
|
+
};
|
|
1164
|
+
//# sourceMappingURL=index.js.map
|