unbikit 0.4.0 → 0.5.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/unbikit.cjs +18 -22
- package/dist/unbikit.d.cts +2 -0
- package/dist/unbikit.d.ts +2 -0
- package/dist/unbikit.js +18 -22
- package/package.json +15 -21
package/dist/unbikit.cjs
CHANGED
|
@@ -144,7 +144,8 @@ var BikAudioDecoder = class {
|
|
|
144
144
|
let numInternalChannels = numChannels;
|
|
145
145
|
if (!useDCT) {
|
|
146
146
|
sampleRate *= numChannels;
|
|
147
|
-
frameLenBits += Math.ceil(Math.log2(numChannels));
|
|
147
|
+
frameLenBits += Math.ceil(Math.log2(numChannels)) & 3;
|
|
148
|
+
frameLenBits = frameLenBits;
|
|
148
149
|
numInternalChannels = 1;
|
|
149
150
|
}
|
|
150
151
|
this.#numInternalChannels = numInternalChannels;
|
|
@@ -267,7 +268,6 @@ var IDCT = class {
|
|
|
267
268
|
#n;
|
|
268
269
|
#tempBuf;
|
|
269
270
|
constructor(nbits) {
|
|
270
|
-
if (nbits < 1) throw new Error(`Invalid nbits: ${nbits}. Must be greater than 0.`);
|
|
271
271
|
this.#n = 1 << nbits;
|
|
272
272
|
this.#tempBuf = new Float32Array(this.#n);
|
|
273
273
|
}
|
|
@@ -305,7 +305,6 @@ var IRDFT = class {
|
|
|
305
305
|
#nDiv4;
|
|
306
306
|
#fft;
|
|
307
307
|
constructor(nbits) {
|
|
308
|
-
if (nbits < 4 || nbits > 16) throw new Error(`Invalid nbits: ${nbits}. Must be between 4 and 16.`);
|
|
309
308
|
this.#n = 1 << nbits;
|
|
310
309
|
this.#nDiv4 = this.#n >>> 2;
|
|
311
310
|
this.#fft = new FFT(nbits - 1);
|
|
@@ -357,7 +356,6 @@ var FFT = class {
|
|
|
357
356
|
#revTable;
|
|
358
357
|
#twiddle;
|
|
359
358
|
constructor(nbits) {
|
|
360
|
-
if (nbits < 2 || nbits > 16) throw new Error(`Invalid nbits: ${nbits}. Must be between 2 and 16.`);
|
|
361
359
|
this.#nbits = nbits;
|
|
362
360
|
this.#n = 1 << nbits;
|
|
363
361
|
this.#revTable = new Uint16Array(this.#n);
|
|
@@ -457,8 +455,7 @@ var HuffTable = class HuffTable {
|
|
|
457
455
|
const peek = reader.a(this.#maxBits);
|
|
458
456
|
reader.u(savedPos);
|
|
459
457
|
const len = this.#lens[peek] ?? 0;
|
|
460
|
-
const symbol = this.#symbols[peek];
|
|
461
|
-
if (typeof symbol === "undefined") throw new Error(`HuffTable decode error: invalid code ${peek}`);
|
|
458
|
+
const symbol = this.#symbols[peek] ?? 0;
|
|
462
459
|
reader.j(len);
|
|
463
460
|
return symbol;
|
|
464
461
|
}
|
|
@@ -507,7 +504,7 @@ var BikVideoDecoder = class {
|
|
|
507
504
|
this.#hasAlpha = hasAlpha;
|
|
508
505
|
this.#hasSwappedUVPlanes = hasSwappedUVPlanes;
|
|
509
506
|
const numPixels = width * height;
|
|
510
|
-
const uvSize =
|
|
507
|
+
const uvSize = (width + 1 >>> 1) * (height + 1 >>> 1);
|
|
511
508
|
const frameSize = (numPixels << (hasAlpha ? 1 : 0)) + (uvSize << 1);
|
|
512
509
|
this.#numPixels = numPixels;
|
|
513
510
|
this.#uvSize = uvSize;
|
|
@@ -549,11 +546,10 @@ var BikVideoDecoder = class {
|
|
|
549
546
|
}
|
|
550
547
|
#createFrame() {
|
|
551
548
|
const numPixels = this.#width * this.#height;
|
|
552
|
-
const uvSize = numPixels >>> 2;
|
|
553
549
|
return {
|
|
554
550
|
width: this.#width,
|
|
555
551
|
height: this.#height,
|
|
556
|
-
yuv: new Uint8Array((numPixels << (this.#hasAlpha ? 1 : 0)) + (uvSize << 1)),
|
|
552
|
+
yuv: new Uint8Array((numPixels << (this.#hasAlpha ? 1 : 0)) + (this.#uvSize << 1)),
|
|
557
553
|
lineSize: [
|
|
558
554
|
this.#width,
|
|
559
555
|
this.#width >>> 1,
|
|
@@ -623,7 +619,7 @@ var BikVideoDecoder = class {
|
|
|
623
619
|
case 9:
|
|
624
620
|
this.#decodeRawBlock();
|
|
625
621
|
break;
|
|
626
|
-
default: throw new Error(`
|
|
622
|
+
default: throw new Error(`Invalid block type ${blockType}`);
|
|
627
623
|
}
|
|
628
624
|
this.#dataPtr += 8;
|
|
629
625
|
}
|
|
@@ -735,7 +731,7 @@ var BikVideoDecoder = class {
|
|
|
735
731
|
case 9:
|
|
736
732
|
for (let j = 0; j < 8; j++) for (let i = 0; i < 8; i++) tmpScalingBuf[i + (j << 3)] = this.#getValue(2);
|
|
737
733
|
break;
|
|
738
|
-
default: throw new Error(`
|
|
734
|
+
default: throw new Error(`Invalid sub-block type ${subBlk}`);
|
|
739
735
|
}
|
|
740
736
|
const dest = this.#data;
|
|
741
737
|
let srcPos = 0;
|
|
@@ -1223,7 +1219,7 @@ var BikDecoder = class BikDecoder {
|
|
|
1223
1219
|
}
|
|
1224
1220
|
async #ensureReadBytes(len) {
|
|
1225
1221
|
const bufBytes = await this.#readBytes(len);
|
|
1226
|
-
if (bufBytes?.byteLength !== len) throw new Error(`
|
|
1222
|
+
if (bufBytes?.byteLength !== len) throw new Error(`Read ${bufBytes?.byteLength ?? 0} bytes but expected ${len}`);
|
|
1227
1223
|
return bufBytes;
|
|
1228
1224
|
}
|
|
1229
1225
|
async #init() {
|
|
@@ -1233,7 +1229,7 @@ var BikDecoder = class BikDecoder {
|
|
|
1233
1229
|
this.#streamReader = null;
|
|
1234
1230
|
}
|
|
1235
1231
|
const streamReader = (await this.#getReadStreamFn(0))?.getReader();
|
|
1236
|
-
if (!streamReader) throw new Error("
|
|
1232
|
+
if (!streamReader) throw new Error("Invalid stream reader");
|
|
1237
1233
|
this.#streamReader = streamReader;
|
|
1238
1234
|
this.#seek(0);
|
|
1239
1235
|
const headerBytes = await this.#ensureReadBytes(44);
|
|
@@ -1241,13 +1237,16 @@ var BikDecoder = class BikDecoder {
|
|
|
1241
1237
|
const headerWords = new Uint32Array(11).fill(0).map((_, index) => headerDataView.getUint32(index << 2, true));
|
|
1242
1238
|
const magicUint = headerWords[0];
|
|
1243
1239
|
const version = [4933954, 3293771].indexOf(magicUint & 16777215) + 1;
|
|
1244
|
-
if (!version) throw new Error(`
|
|
1240
|
+
if (!version) throw new Error(`Invalid format`);
|
|
1245
1241
|
const subVersion = magicUint >>> 24;
|
|
1246
1242
|
const numFrames = headerWords[2];
|
|
1247
1243
|
const width = headerWords[5];
|
|
1248
1244
|
const height = headerWords[6];
|
|
1249
|
-
const
|
|
1245
|
+
const videoFlags = headerWords[9];
|
|
1246
|
+
const hasAlpha = !!(videoFlags & 1048576);
|
|
1250
1247
|
const hasSwappedUVPlanes = subVersion >= 104;
|
|
1248
|
+
const isGrayscale = !!(videoFlags & 131072);
|
|
1249
|
+
const scaling = videoFlags >>> 28 & 15;
|
|
1251
1250
|
const numAudioTracks = headerWords[10];
|
|
1252
1251
|
const audioTrackHeaderSize = numAudioTracks * 12;
|
|
1253
1252
|
const frameListSize = (numFrames + 1) * 4;
|
|
@@ -1303,7 +1302,9 @@ var BikDecoder = class BikDecoder {
|
|
|
1303
1302
|
fps: headerWords[7] / headerWords[8],
|
|
1304
1303
|
videoFlags: {
|
|
1305
1304
|
hasAlpha,
|
|
1306
|
-
hasSwappedUVPlanes
|
|
1305
|
+
hasSwappedUVPlanes,
|
|
1306
|
+
isGrayscale,
|
|
1307
|
+
scaling
|
|
1307
1308
|
},
|
|
1308
1309
|
numAudioTracks,
|
|
1309
1310
|
audioTracks,
|
|
@@ -1404,12 +1405,7 @@ var BikDecoder = class BikDecoder {
|
|
|
1404
1405
|
*/
|
|
1405
1406
|
static async open(getReadStreamFn) {
|
|
1406
1407
|
const decoder = new BikDecoder(getReadStreamFn);
|
|
1407
|
-
|
|
1408
|
-
await decoder.#init();
|
|
1409
|
-
} catch (err) {
|
|
1410
|
-
console.error("Error during parsing");
|
|
1411
|
-
throw err;
|
|
1412
|
-
}
|
|
1408
|
+
await decoder.#init();
|
|
1413
1409
|
return decoder;
|
|
1414
1410
|
}
|
|
1415
1411
|
};
|
package/dist/unbikit.d.cts
CHANGED
package/dist/unbikit.d.ts
CHANGED
package/dist/unbikit.js
CHANGED
|
@@ -143,7 +143,8 @@ var BikAudioDecoder = class {
|
|
|
143
143
|
let numInternalChannels = numChannels;
|
|
144
144
|
if (!useDCT) {
|
|
145
145
|
sampleRate *= numChannels;
|
|
146
|
-
frameLenBits += Math.ceil(Math.log2(numChannels));
|
|
146
|
+
frameLenBits += Math.ceil(Math.log2(numChannels)) & 3;
|
|
147
|
+
frameLenBits = frameLenBits;
|
|
147
148
|
numInternalChannels = 1;
|
|
148
149
|
}
|
|
149
150
|
this.#numInternalChannels = numInternalChannels;
|
|
@@ -266,7 +267,6 @@ var IDCT = class {
|
|
|
266
267
|
#n;
|
|
267
268
|
#tempBuf;
|
|
268
269
|
constructor(nbits) {
|
|
269
|
-
if (nbits < 1) throw new Error(`Invalid nbits: ${nbits}. Must be greater than 0.`);
|
|
270
270
|
this.#n = 1 << nbits;
|
|
271
271
|
this.#tempBuf = new Float32Array(this.#n);
|
|
272
272
|
}
|
|
@@ -304,7 +304,6 @@ var IRDFT = class {
|
|
|
304
304
|
#nDiv4;
|
|
305
305
|
#fft;
|
|
306
306
|
constructor(nbits) {
|
|
307
|
-
if (nbits < 4 || nbits > 16) throw new Error(`Invalid nbits: ${nbits}. Must be between 4 and 16.`);
|
|
308
307
|
this.#n = 1 << nbits;
|
|
309
308
|
this.#nDiv4 = this.#n >>> 2;
|
|
310
309
|
this.#fft = new FFT(nbits - 1);
|
|
@@ -356,7 +355,6 @@ var FFT = class {
|
|
|
356
355
|
#revTable;
|
|
357
356
|
#twiddle;
|
|
358
357
|
constructor(nbits) {
|
|
359
|
-
if (nbits < 2 || nbits > 16) throw new Error(`Invalid nbits: ${nbits}. Must be between 2 and 16.`);
|
|
360
358
|
this.#nbits = nbits;
|
|
361
359
|
this.#n = 1 << nbits;
|
|
362
360
|
this.#revTable = new Uint16Array(this.#n);
|
|
@@ -456,8 +454,7 @@ var HuffTable = class HuffTable {
|
|
|
456
454
|
const peek = reader.a(this.#maxBits);
|
|
457
455
|
reader.u(savedPos);
|
|
458
456
|
const len = this.#lens[peek] ?? 0;
|
|
459
|
-
const symbol = this.#symbols[peek];
|
|
460
|
-
if (typeof symbol === "undefined") throw new Error(`HuffTable decode error: invalid code ${peek}`);
|
|
457
|
+
const symbol = this.#symbols[peek] ?? 0;
|
|
461
458
|
reader.j(len);
|
|
462
459
|
return symbol;
|
|
463
460
|
}
|
|
@@ -506,7 +503,7 @@ var BikVideoDecoder = class {
|
|
|
506
503
|
this.#hasAlpha = hasAlpha;
|
|
507
504
|
this.#hasSwappedUVPlanes = hasSwappedUVPlanes;
|
|
508
505
|
const numPixels = width * height;
|
|
509
|
-
const uvSize =
|
|
506
|
+
const uvSize = (width + 1 >>> 1) * (height + 1 >>> 1);
|
|
510
507
|
const frameSize = (numPixels << (hasAlpha ? 1 : 0)) + (uvSize << 1);
|
|
511
508
|
this.#numPixels = numPixels;
|
|
512
509
|
this.#uvSize = uvSize;
|
|
@@ -548,11 +545,10 @@ var BikVideoDecoder = class {
|
|
|
548
545
|
}
|
|
549
546
|
#createFrame() {
|
|
550
547
|
const numPixels = this.#width * this.#height;
|
|
551
|
-
const uvSize = numPixels >>> 2;
|
|
552
548
|
return {
|
|
553
549
|
width: this.#width,
|
|
554
550
|
height: this.#height,
|
|
555
|
-
yuv: new Uint8Array((numPixels << (this.#hasAlpha ? 1 : 0)) + (uvSize << 1)),
|
|
551
|
+
yuv: new Uint8Array((numPixels << (this.#hasAlpha ? 1 : 0)) + (this.#uvSize << 1)),
|
|
556
552
|
lineSize: [
|
|
557
553
|
this.#width,
|
|
558
554
|
this.#width >>> 1,
|
|
@@ -622,7 +618,7 @@ var BikVideoDecoder = class {
|
|
|
622
618
|
case 9:
|
|
623
619
|
this.#decodeRawBlock();
|
|
624
620
|
break;
|
|
625
|
-
default: throw new Error(`
|
|
621
|
+
default: throw new Error(`Invalid block type ${blockType}`);
|
|
626
622
|
}
|
|
627
623
|
this.#dataPtr += 8;
|
|
628
624
|
}
|
|
@@ -734,7 +730,7 @@ var BikVideoDecoder = class {
|
|
|
734
730
|
case 9:
|
|
735
731
|
for (let j = 0; j < 8; j++) for (let i = 0; i < 8; i++) tmpScalingBuf[i + (j << 3)] = this.#getValue(2);
|
|
736
732
|
break;
|
|
737
|
-
default: throw new Error(`
|
|
733
|
+
default: throw new Error(`Invalid sub-block type ${subBlk}`);
|
|
738
734
|
}
|
|
739
735
|
const dest = this.#data;
|
|
740
736
|
let srcPos = 0;
|
|
@@ -1222,7 +1218,7 @@ var BikDecoder = class BikDecoder {
|
|
|
1222
1218
|
}
|
|
1223
1219
|
async #ensureReadBytes(len) {
|
|
1224
1220
|
const bufBytes = await this.#readBytes(len);
|
|
1225
|
-
if (bufBytes?.byteLength !== len) throw new Error(`
|
|
1221
|
+
if (bufBytes?.byteLength !== len) throw new Error(`Read ${bufBytes?.byteLength ?? 0} bytes but expected ${len}`);
|
|
1226
1222
|
return bufBytes;
|
|
1227
1223
|
}
|
|
1228
1224
|
async #init() {
|
|
@@ -1232,7 +1228,7 @@ var BikDecoder = class BikDecoder {
|
|
|
1232
1228
|
this.#streamReader = null;
|
|
1233
1229
|
}
|
|
1234
1230
|
const streamReader = (await this.#getReadStreamFn(0))?.getReader();
|
|
1235
|
-
if (!streamReader) throw new Error("
|
|
1231
|
+
if (!streamReader) throw new Error("Invalid stream reader");
|
|
1236
1232
|
this.#streamReader = streamReader;
|
|
1237
1233
|
this.#seek(0);
|
|
1238
1234
|
const headerBytes = await this.#ensureReadBytes(44);
|
|
@@ -1240,13 +1236,16 @@ var BikDecoder = class BikDecoder {
|
|
|
1240
1236
|
const headerWords = new Uint32Array(11).fill(0).map((_, index) => headerDataView.getUint32(index << 2, true));
|
|
1241
1237
|
const magicUint = headerWords[0];
|
|
1242
1238
|
const version = [4933954, 3293771].indexOf(magicUint & 16777215) + 1;
|
|
1243
|
-
if (!version) throw new Error(`
|
|
1239
|
+
if (!version) throw new Error(`Invalid format`);
|
|
1244
1240
|
const subVersion = magicUint >>> 24;
|
|
1245
1241
|
const numFrames = headerWords[2];
|
|
1246
1242
|
const width = headerWords[5];
|
|
1247
1243
|
const height = headerWords[6];
|
|
1248
|
-
const
|
|
1244
|
+
const videoFlags = headerWords[9];
|
|
1245
|
+
const hasAlpha = !!(videoFlags & 1048576);
|
|
1249
1246
|
const hasSwappedUVPlanes = subVersion >= 104;
|
|
1247
|
+
const isGrayscale = !!(videoFlags & 131072);
|
|
1248
|
+
const scaling = videoFlags >>> 28 & 15;
|
|
1250
1249
|
const numAudioTracks = headerWords[10];
|
|
1251
1250
|
const audioTrackHeaderSize = numAudioTracks * 12;
|
|
1252
1251
|
const frameListSize = (numFrames + 1) * 4;
|
|
@@ -1302,7 +1301,9 @@ var BikDecoder = class BikDecoder {
|
|
|
1302
1301
|
fps: headerWords[7] / headerWords[8],
|
|
1303
1302
|
videoFlags: {
|
|
1304
1303
|
hasAlpha,
|
|
1305
|
-
hasSwappedUVPlanes
|
|
1304
|
+
hasSwappedUVPlanes,
|
|
1305
|
+
isGrayscale,
|
|
1306
|
+
scaling
|
|
1306
1307
|
},
|
|
1307
1308
|
numAudioTracks,
|
|
1308
1309
|
audioTracks,
|
|
@@ -1403,12 +1404,7 @@ var BikDecoder = class BikDecoder {
|
|
|
1403
1404
|
*/
|
|
1404
1405
|
static async open(getReadStreamFn) {
|
|
1405
1406
|
const decoder = new BikDecoder(getReadStreamFn);
|
|
1406
|
-
|
|
1407
|
-
await decoder.#init();
|
|
1408
|
-
} catch (err) {
|
|
1409
|
-
console.error("Error during parsing");
|
|
1410
|
-
throw err;
|
|
1411
|
-
}
|
|
1407
|
+
await decoder.#init();
|
|
1412
1408
|
return decoder;
|
|
1413
1409
|
}
|
|
1414
1410
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unbikit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Decoder for `.bik` video files.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"audio",
|
|
@@ -29,30 +29,29 @@
|
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@arethetypeswrong/core": "0.18.2",
|
|
31
31
|
"@astrojs/check": "0.9.5",
|
|
32
|
-
"@astrojs/mdx": "
|
|
33
|
-
"@astrojs/starlight": "
|
|
32
|
+
"@astrojs/mdx": "4.3.11",
|
|
33
|
+
"@astrojs/starlight": "0.36.2",
|
|
34
34
|
"@biomejs/biome": "2.3.6",
|
|
35
35
|
"@commitlint/config-conventional": "20.0.0",
|
|
36
36
|
"@commitlint/types": "20.0.0",
|
|
37
|
-
"@fontsource-variable/sora": "
|
|
38
|
-
"@mitata/counters": "0.0.8",
|
|
37
|
+
"@fontsource-variable/sora": "5.2.8",
|
|
39
38
|
"@types/audioworklet": "0.0.91",
|
|
40
39
|
"@types/node": "24.10.1",
|
|
41
40
|
"@types/pngjs": "6.0.5",
|
|
42
|
-
"@vitest/coverage-v8": "4.0.
|
|
43
|
-
"@vitest/ui": "4.0.
|
|
44
|
-
"astro": "5.15.
|
|
41
|
+
"@vitest/coverage-v8": "4.0.10",
|
|
42
|
+
"@vitest/ui": "4.0.10",
|
|
43
|
+
"astro": "5.15.9",
|
|
45
44
|
"commitlint": "20.1.0",
|
|
46
45
|
"globals": "16.5.0",
|
|
47
|
-
"mitata": "1.0.34",
|
|
48
46
|
"pngjs": "7.0.0",
|
|
49
47
|
"prettier": "3.6.2",
|
|
50
48
|
"publint": "0.3.15",
|
|
51
49
|
"rolldown": "1.0.0-beta.50",
|
|
52
50
|
"rollup-plugin-esbuild": "6.2.1",
|
|
53
|
-
"starlight-package-managers": "
|
|
54
|
-
"starlight-theme-rapide": "
|
|
55
|
-
"starlight-typedoc": "
|
|
51
|
+
"starlight-package-managers": "0.11.1",
|
|
52
|
+
"starlight-theme-rapide": "0.5.2",
|
|
53
|
+
"starlight-typedoc": "0.21.4",
|
|
54
|
+
"tinybench": "5.1.0",
|
|
56
55
|
"ts-extras": "0.16.0",
|
|
57
56
|
"tsdown": "0.16.5",
|
|
58
57
|
"type-fest": "5.2.0",
|
|
@@ -61,11 +60,7 @@
|
|
|
61
60
|
"typescript": "5.9.3",
|
|
62
61
|
"unplugin-unused": "0.5.6",
|
|
63
62
|
"vite": "npm:rolldown-vite@7.2.5",
|
|
64
|
-
"vitest": "4.0.
|
|
65
|
-
},
|
|
66
|
-
"overrides": {
|
|
67
|
-
"rolldown": "$rolldown",
|
|
68
|
-
"vite": "$vite"
|
|
63
|
+
"vitest": "4.0.10"
|
|
69
64
|
},
|
|
70
65
|
"exports": {
|
|
71
66
|
".": {
|
|
@@ -84,9 +79,7 @@
|
|
|
84
79
|
"dist/**/*.d.cts",
|
|
85
80
|
"dist/**/*.d.ts",
|
|
86
81
|
"dist/**/*.cjs",
|
|
87
|
-
"dist/**/*.
|
|
88
|
-
"dist/**/*.js",
|
|
89
|
-
"dist/**/*.js.map"
|
|
82
|
+
"dist/**/*.js"
|
|
90
83
|
],
|
|
91
84
|
"commitlint": {
|
|
92
85
|
"extends": [
|
|
@@ -105,6 +98,7 @@
|
|
|
105
98
|
"test": "vitest --ui --testTimeout 10000",
|
|
106
99
|
"test:coverage": "vitest --ui --coverage --testTimeout 20000",
|
|
107
100
|
"test:cli": "vitest --testTimeout 10000",
|
|
108
|
-
"ci:test": "vitest run --coverage --testTimeout 30000"
|
|
101
|
+
"ci:test": "vitest run --coverage --testTimeout 30000",
|
|
102
|
+
"bench": "vitest bench --run"
|
|
109
103
|
}
|
|
110
104
|
}
|