mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 20:19:49 +02:00
fix: correct RGB565 PVR decoding
This commit is contained in:
1 parent
1920be28d8
commit
4205b16769
1 file changed
+12
-12
@@ -1,5 +1,5 @@
|
|||||||
import { clamp, isEqual, times } from 'lodash-es';
|
import { clamp, isEqual, times } from "lodash-es";
|
||||||
import { ReadStream } from './buffer';
|
import { ReadStream } from "./buffer";
|
||||||
|
|
||||||
export enum PvrFlags {
|
export enum PvrFlags {
|
||||||
NoFlag = 0,
|
NoFlag = 0,
|
||||||
@@ -96,7 +96,7 @@ export class PvrReadStream extends ReadStream {
|
|||||||
const header = this.header();
|
const header = this.header();
|
||||||
this.metadata();
|
this.metadata();
|
||||||
|
|
||||||
if (typeof header.pixelFormat === 'number') {
|
if (typeof header.pixelFormat === "number") {
|
||||||
switch (header.pixelFormat) {
|
switch (header.pixelFormat) {
|
||||||
default:
|
default:
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
@@ -142,12 +142,12 @@ export class PvrReadStream extends ReadStream {
|
|||||||
|
|
||||||
times(pixelCount, (index) => {
|
times(pixelCount, (index) => {
|
||||||
const buffer = this.consumeUint8Array(2);
|
const buffer = this.consumeUint8Array(2);
|
||||||
const bufferIndex = index * 4;
|
const bufferIndex = index * 3;
|
||||||
const r = ((buffer[1] & 0b11111000) >>> 3) / 31;
|
const r = ((buffer[1] & 0b11111000) >>> 3) / 31;
|
||||||
const g =
|
const g =
|
||||||
((buffer[1] & 0b111) << 3) |
|
(((buffer[1] & 0b111) << 3) | ((buffer[0] & 0b11100000) >>> 5)) /
|
||||||
(((buffer[0] & 0b11100000) >>> 5) / 31);
|
63;
|
||||||
const b = buffer[0] & 0b11111;
|
const b = (buffer[0] & 0b11111) / 31;
|
||||||
|
|
||||||
data[bufferIndex] = Math.round(clamp(r * 255, 0, 255));
|
data[bufferIndex] = Math.round(clamp(r * 255, 0, 255));
|
||||||
data[bufferIndex + 1] = Math.round(clamp(g * 255, 0, 255));
|
data[bufferIndex + 1] = Math.round(clamp(g * 255, 0, 255));
|
||||||
@@ -186,7 +186,7 @@ export class PvrReadStream extends ReadStream {
|
|||||||
metadataSize: this.uint32(),
|
metadataSize: this.uint32(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (header.version !== 'PVR\x03') throw new TypeError('Endian mismatch');
|
if (header.version !== "PVR\x03") throw new TypeError("Endian mismatch");
|
||||||
|
|
||||||
return header;
|
return header;
|
||||||
}
|
}
|
||||||
@@ -205,19 +205,19 @@ export class PvrReadStream extends ReadStream {
|
|||||||
resolveBitRatePixelFormat(
|
resolveBitRatePixelFormat(
|
||||||
pixelFormat: Exclude<ReturnType<typeof this.pixelFormat>, number>,
|
pixelFormat: Exclude<ReturnType<typeof this.pixelFormat>, number>,
|
||||||
) {
|
) {
|
||||||
if (pixelFormat.order === 'rgba') {
|
if (pixelFormat.order === "rgba") {
|
||||||
if (isEqual(pixelFormat.bitRates, [4, 4, 4, 4])) {
|
if (isEqual(pixelFormat.bitRates, [4, 4, 4, 4])) {
|
||||||
return ResolvedBitRatePixelFormat.R4G4B4A4;
|
return ResolvedBitRatePixelFormat.R4G4B4A4;
|
||||||
} else
|
} else
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
`Unhandled rgba bit rate ${pixelFormat.bitRates.join(', ')}`,
|
`Unhandled rgba bit rate ${pixelFormat.bitRates.join(", ")}`,
|
||||||
);
|
);
|
||||||
} else if (pixelFormat.order === 'rgb\0') {
|
} else if (pixelFormat.order === "rgb\0") {
|
||||||
if (isEqual(pixelFormat.bitRates, [5, 6, 5, 0])) {
|
if (isEqual(pixelFormat.bitRates, [5, 6, 5, 0])) {
|
||||||
return ResolvedBitRatePixelFormat.R5G6B5A0;
|
return ResolvedBitRatePixelFormat.R5G6B5A0;
|
||||||
} else
|
} else
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
`Unhandled rgb bit rate ${pixelFormat.bitRates.join(', ')}`,
|
`Unhandled rgb bit rate ${pixelFormat.bitRates.join(", ")}`,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
throw new TypeError(`Unhandled pixel order ${pixelFormat.order}`);
|
throw new TypeError(`Unhandled pixel order ${pixelFormat.order}`);
|
||||||
|
|||||||
Reference in new issue
Block a user