mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 12:09:51 +02:00
fix: a few bit swaps
This commit is contained in:
1 parent
def75da1d8
commit
ce4f7a55b6
2 files changed
+26
-17
No files matched your search
@@ -8,9 +8,7 @@ export async function readTexture(path: string) {
|
|||||||
const stream = new DdsStream(decompressedDvpl);
|
const stream = new DdsStream(decompressedDvpl);
|
||||||
const ddsRaw = await stream.dds();
|
const ddsRaw = await stream.dds();
|
||||||
|
|
||||||
const png = await sharp(ddsRaw.data, { raw: ddsRaw }).png().toBuffer();
|
return await sharp(ddsRaw.data, { raw: ddsRaw }).png().toBuffer();
|
||||||
|
|
||||||
return png;
|
|
||||||
|
|
||||||
// const isDds = existsSync(ddsTexturePath);
|
// const isDds = existsSync(ddsTexturePath);
|
||||||
// const resolvedTexturePath = isDds
|
// const resolvedTexturePath = isDds
|
||||||
|
|||||||
+25
-14
@@ -218,7 +218,7 @@ export class DdsStream extends WindowsStream {
|
|||||||
const colorKeys = this.bc1ColorKeys();
|
const colorKeys = this.bc1ColorKeys();
|
||||||
return (index) => [
|
return (index) => [
|
||||||
...colorInterpolations[colorKeys[index]],
|
...colorInterpolations[colorKeys[index]],
|
||||||
alphaInterpolations[colorKeys[index]],
|
alphaInterpolations[index],
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -335,12 +335,12 @@ export class DdsStream extends WindowsStream {
|
|||||||
}
|
}
|
||||||
R5G6B5() {
|
R5G6B5() {
|
||||||
const buffer = this.consume(2);
|
const buffer = this.consume(2);
|
||||||
|
const b = (buffer[0] & 0b11111) / 0x1f;
|
||||||
|
const r = ((buffer[1] & 0b11111000) >>> 3) / 0x1f;
|
||||||
|
const g =
|
||||||
|
(((buffer[1] & 0b111) << 3) | ((buffer[0] & 0b11100000) >>> 5)) / 0x3f;
|
||||||
|
|
||||||
return [
|
return [r, g, b] as Vector3Tuple;
|
||||||
((buffer[1] & 0b11111000) >>> 3) / 0x1f,
|
|
||||||
(((buffer[1] & 0b111) << 3) | ((buffer[0] & 0b11100000) >>> 5)) / 0x3f,
|
|
||||||
(buffer[0] & 0b11111) / 0x1f,
|
|
||||||
] as Vector3Tuple;
|
|
||||||
}
|
}
|
||||||
R5G6B5A0() {
|
R5G6B5A0() {
|
||||||
return [...this.R5G6B5(), 1] as Vector4Tuple;
|
return [...this.R5G6B5(), 1] as Vector4Tuple;
|
||||||
@@ -363,7 +363,7 @@ export class DdsStream extends WindowsStream {
|
|||||||
(channel0, index) => (2 * channel0 + color1[index]) / 3,
|
(channel0, index) => (2 * channel0 + color1[index]) / 3,
|
||||||
) as Vector4Tuple);
|
) as Vector4Tuple);
|
||||||
const color3 = alpha
|
const color3 = alpha
|
||||||
? ([0, 0, 0, 0] as const)
|
? ([0, 0, 0, 0] as Vector4Tuple)
|
||||||
: (color0.map(
|
: (color0.map(
|
||||||
(channel0, index) => (channel0 + 2 * color1[index]) / 3,
|
(channel0, index) => (channel0 + 2 * color1[index]) / 3,
|
||||||
) as Vector4Tuple);
|
) as Vector4Tuple);
|
||||||
@@ -397,14 +397,25 @@ export class DdsStream extends WindowsStream {
|
|||||||
return [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p];
|
return [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p];
|
||||||
}
|
}
|
||||||
bc2AlphaInterpolations() {
|
bc2AlphaInterpolations() {
|
||||||
const alphaBuffer = this.consume(8);
|
const buffer = this.consume(8);
|
||||||
|
const d = (buffer[0] & 0b11110000) >>> 4;
|
||||||
|
const c = buffer[0] & 0b1111;
|
||||||
|
const b = (buffer[1] & 0b11110000) >>> 4;
|
||||||
|
const a = buffer[1] & 0b1111;
|
||||||
|
const h = (buffer[2] & 0b11110000) >>> 4;
|
||||||
|
const g = buffer[2] & 0b1111;
|
||||||
|
const f = (buffer[3] & 0b11110000) >>> 4;
|
||||||
|
const e = buffer[3] & 0b1111;
|
||||||
|
const l = (buffer[4] & 0b11110000) >>> 4;
|
||||||
|
const k = buffer[4] & 0b1111;
|
||||||
|
const j = (buffer[5] & 0b11110000) >>> 4;
|
||||||
|
const i = buffer[5] & 0b1111;
|
||||||
|
const p = (buffer[6] & 0b11110000) >>> 4;
|
||||||
|
const o = buffer[6] & 0b1111;
|
||||||
|
const n = (buffer[7] & 0b11110000) >>> 4;
|
||||||
|
const m = buffer[7] & 0b1111;
|
||||||
|
|
||||||
return times(16, (index) => {
|
return [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p];
|
||||||
const bufferIndex = Math.floor(index / 2);
|
|
||||||
const buffer = alphaBuffer[bufferIndex];
|
|
||||||
const alpha = index % 2 ? buffer & 0b1111 : (buffer & 0b11110000) >>> 4;
|
|
||||||
return alpha / 0xf;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
bc2ColorInterpolations() {
|
bc2ColorInterpolations() {
|
||||||
const color0 = this.R5G6B5();
|
const color0 = this.R5G6B5();
|
||||||
|
|||||||
Reference in new issue
Block a user