From 0dce033f650a7cb36689b9a51db756e5e6155a51 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Tue, 5 Dec 2023 22:45:04 -0600 Subject: [PATCH] fix(blp): use little-endian naming convention in BLP_IMAGE_FORMAT --- src/lib/blp/Blp.ts | 22 +++++++++++----------- src/lib/blp/const.ts | 2 +- src/lib/blp/dxt.ts | 16 ++++++++-------- src/lib/blp/pal.ts | 20 ++++++++++---------- src/spec/blp/Blp.spec.ts | 36 ++++++++++++++++++------------------ 5 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/lib/blp/Blp.ts b/src/lib/blp/Blp.ts index 98beec0..043f3b9 100644 --- a/src/lib/blp/Blp.ts +++ b/src/lib/blp/Blp.ts @@ -6,8 +6,8 @@ import { BLP_PIXEL_FORMAT, MAX_MIPS, } from './const.js'; -import { dxt1ToRgba8888, dxt3ToRgba8888, dxt5ToRgba8888 } from './dxt.js'; -import { palToRgba8888 } from './pal.js'; +import { dxt1ToAbgr8888, dxt3ToAbgr8888, dxt5ToAbgr8888 } from './dxt.js'; +import { palToAbgr8888 } from './pal.js'; import * as blpIo from './io.js'; import { getSizeAtMipLevel } from './util.js'; import BlpImage from './BlpImage.js'; @@ -152,7 +152,7 @@ class Blp { switch (this.#colorFormat) { case BLP_COLOR_FORMAT.COLOR_PAL: // Images using palettes are only useful when decoded - return this.#getPalImage(level, BLP_IMAGE_FORMAT.IMAGE_RGBA8888); + return this.#getPalImage(level, BLP_IMAGE_FORMAT.IMAGE_ABGR8888); case BLP_COLOR_FORMAT.COLOR_DXT: switch (this.#preferredFormat) { @@ -204,8 +204,8 @@ class Blp { case BLP_IMAGE_FORMAT.IMAGE_DXT1: return new BlpImage(width, height, data, outputFormat); - case BLP_IMAGE_FORMAT.IMAGE_RGBA8888: - return new BlpImage(width, height, dxt1ToRgba8888(width, height, data), outputFormat); + case BLP_IMAGE_FORMAT.IMAGE_ABGR8888: + return new BlpImage(width, height, dxt1ToAbgr8888(width, height, data), outputFormat); default: throw new Error(`Unsupported output format: ${outputFormat}`); @@ -221,8 +221,8 @@ class Blp { case BLP_IMAGE_FORMAT.IMAGE_DXT3: return new BlpImage(width, height, data, outputFormat); - case BLP_IMAGE_FORMAT.IMAGE_RGBA8888: - return new BlpImage(width, height, dxt3ToRgba8888(width, height, data), outputFormat); + case BLP_IMAGE_FORMAT.IMAGE_ABGR8888: + return new BlpImage(width, height, dxt3ToAbgr8888(width, height, data), outputFormat); default: throw new Error(`Unsupported output format: ${outputFormat}`); @@ -238,8 +238,8 @@ class Blp { case BLP_IMAGE_FORMAT.IMAGE_DXT5: return new BlpImage(width, height, data, outputFormat); - case BLP_IMAGE_FORMAT.IMAGE_RGBA8888: - return new BlpImage(width, height, dxt5ToRgba8888(width, height, data), outputFormat); + case BLP_IMAGE_FORMAT.IMAGE_ABGR8888: + return new BlpImage(width, height, dxt5ToAbgr8888(width, height, data), outputFormat); default: throw new Error(`Unsupported output format: ${outputFormat}`); @@ -252,11 +252,11 @@ class Blp { const data = this.#images[level]; switch (outputFormat) { - case BLP_IMAGE_FORMAT.IMAGE_RGBA8888: + case BLP_IMAGE_FORMAT.IMAGE_ABGR8888: return new BlpImage( width, height, - palToRgba8888(width, height, data, this.#palette, this.#alphaSize), + palToAbgr8888(width, height, data, this.#palette, this.#alphaSize), outputFormat, ); default: diff --git a/src/lib/blp/const.ts b/src/lib/blp/const.ts index ff723fb..35fc85d 100644 --- a/src/lib/blp/const.ts +++ b/src/lib/blp/const.ts @@ -26,7 +26,7 @@ enum BLP_PIXEL_FORMAT { enum BLP_IMAGE_FORMAT { IMAGE_UNSPECIFIED = 0, IMAGE_JPEG, - IMAGE_RGBA8888, + IMAGE_ABGR8888, IMAGE_DXT1, IMAGE_DXT3, IMAGE_DXT5, diff --git a/src/lib/blp/dxt.ts b/src/lib/blp/dxt.ts index b715fbd..3d3ae11 100644 --- a/src/lib/blp/dxt.ts +++ b/src/lib/blp/dxt.ts @@ -143,7 +143,7 @@ const dxt5DecompressBlock = (block: Uint8Array) => { DECOMPRESSED[35] = ALPHA_LOOKUP[ (block[5] & 0b00000111) >> 0]; }; -const dxtToRgba8888 = ( +const dxtToAbgr8888 = ( width: number, height: number, input: Uint8Array, @@ -195,13 +195,13 @@ const dxtToRgba8888 = ( return output; }; -const dxt1ToRgba8888 = (width: number, height: number, input: Uint8Array) => - dxtToRgba8888(width, height, input, DXT1_BLOCK_SIZE, dxt1DecompressBlock); +const dxt1ToAbgr8888 = (width: number, height: number, input: Uint8Array) => + dxtToAbgr8888(width, height, input, DXT1_BLOCK_SIZE, dxt1DecompressBlock); -const dxt3ToRgba8888 = (width: number, height: number, input: Uint8Array) => - dxtToRgba8888(width, height, input, DXT3_BLOCK_SIZE, dxt3DecompressBlock); +const dxt3ToAbgr8888 = (width: number, height: number, input: Uint8Array) => + dxtToAbgr8888(width, height, input, DXT3_BLOCK_SIZE, dxt3DecompressBlock); -const dxt5ToRgba8888 = (width: number, height: number, input: Uint8Array) => - dxtToRgba8888(width, height, input, DXT5_BLOCK_SIZE, dxt5DecompressBlock); +const dxt5ToAbgr8888 = (width: number, height: number, input: Uint8Array) => + dxtToAbgr8888(width, height, input, DXT5_BLOCK_SIZE, dxt5DecompressBlock); -export { dxt1ToRgba8888, dxt3ToRgba8888, dxt5ToRgba8888 }; +export { dxt1ToAbgr8888, dxt3ToAbgr8888, dxt5ToAbgr8888 }; diff --git a/src/lib/blp/pal.ts b/src/lib/blp/pal.ts index f81f430..c95ae8d 100644 --- a/src/lib/blp/pal.ts +++ b/src/lib/blp/pal.ts @@ -1,4 +1,4 @@ -const pala0toRgba8888 = (width: number, height: number, input: Uint8Array, palette: Uint8Array) => { +const pala0toAbgr8888 = (width: number, height: number, input: Uint8Array, palette: Uint8Array) => { const output = new Uint8Array(width * height * 4); for (let i = 0; i < width * height; i++) { @@ -17,7 +17,7 @@ const pala0toRgba8888 = (width: number, height: number, input: Uint8Array, palet return output; }; -const pala1toRgba8888 = (width: number, height: number, input: Uint8Array, palette: Uint8Array) => { +const pala1toAbgr8888 = (width: number, height: number, input: Uint8Array, palette: Uint8Array) => { const output = new Uint8Array(width * height * 4); const alphaOfs = width * height; @@ -38,7 +38,7 @@ const pala1toRgba8888 = (width: number, height: number, input: Uint8Array, palet return output; }; -const pala4toRgba8888 = (width: number, height: number, input: Uint8Array, palette: Uint8Array) => { +const pala4toAbgr8888 = (width: number, height: number, input: Uint8Array, palette: Uint8Array) => { const output = new Uint8Array(width * height * 4); const alphaOfs = width * height; @@ -60,7 +60,7 @@ const pala4toRgba8888 = (width: number, height: number, input: Uint8Array, palet return output; }; -const pala8toRgba8888 = (width: number, height: number, input: Uint8Array, palette: Uint8Array) => { +const pala8toAbgr8888 = (width: number, height: number, input: Uint8Array, palette: Uint8Array) => { const output = new Uint8Array(width * height * 4); const alphaOfs = width * height; @@ -80,7 +80,7 @@ const pala8toRgba8888 = (width: number, height: number, input: Uint8Array, palet return output; }; -const palToRgba8888 = ( +const palToAbgr8888 = ( width: number, height: number, input: Uint8Array, @@ -89,16 +89,16 @@ const palToRgba8888 = ( ) => { switch (alphaSize) { case 0: - return pala0toRgba8888(width, height, input, palette); + return pala0toAbgr8888(width, height, input, palette); case 1: - return pala1toRgba8888(width, height, input, palette); + return pala1toAbgr8888(width, height, input, palette); case 4: - return pala4toRgba8888(width, height, input, palette); + return pala4toAbgr8888(width, height, input, palette); case 8: - return pala8toRgba8888(width, height, input, palette); + return pala8toAbgr8888(width, height, input, palette); default: throw new Error(`Unsupported alpha size: ${alphaSize}`); } }; -export { palToRgba8888 }; +export { palToAbgr8888 }; diff --git a/src/spec/blp/Blp.spec.ts b/src/spec/blp/Blp.spec.ts index 3270379..b4a1239 100644 --- a/src/spec/blp/Blp.spec.ts +++ b/src/spec/blp/Blp.spec.ts @@ -120,19 +120,19 @@ describe('Blp', () => { expect(image.width).toBe(512); expect(image.height).toBe(512); expect(image.data.byteLength).toBe(512 * 512 * 4); - expect(image.format).toBe(BLP_IMAGE_FORMAT.IMAGE_RGBA8888); + expect(image.format).toBe(BLP_IMAGE_FORMAT.IMAGE_ABGR8888); }); test('should return image for level 1 and RGBA8888 format', () => { const blp = new Blp(); blp.load('./fixture/pala0.blp'); - const image = blp.getImage(1, BLP_IMAGE_FORMAT.IMAGE_RGBA8888); + const image = blp.getImage(1, BLP_IMAGE_FORMAT.IMAGE_ABGR8888); expect(image.width).toBe(256); expect(image.height).toBe(256); expect(image.data.byteLength).toBe(256 * 256 * 4); - expect(image.format).toBe(BLP_IMAGE_FORMAT.IMAGE_RGBA8888); + expect(image.format).toBe(BLP_IMAGE_FORMAT.IMAGE_ABGR8888); }); }); @@ -146,19 +146,19 @@ describe('Blp', () => { expect(image.width).toBe(32); expect(image.height).toBe(32); expect(image.data.byteLength).toBe(32 * 32 * 4); - expect(image.format).toBe(BLP_IMAGE_FORMAT.IMAGE_RGBA8888); + expect(image.format).toBe(BLP_IMAGE_FORMAT.IMAGE_ABGR8888); }); test('should return image for level 1 and RGBA8888 format', () => { const blp = new Blp(); blp.load('./fixture/pala1.blp'); - const image = blp.getImage(1, BLP_IMAGE_FORMAT.IMAGE_RGBA8888); + const image = blp.getImage(1, BLP_IMAGE_FORMAT.IMAGE_ABGR8888); expect(image.width).toBe(16); expect(image.height).toBe(16); expect(image.data.byteLength).toBe(16 * 16 * 4); - expect(image.format).toBe(BLP_IMAGE_FORMAT.IMAGE_RGBA8888); + expect(image.format).toBe(BLP_IMAGE_FORMAT.IMAGE_ABGR8888); }); }); @@ -172,19 +172,19 @@ describe('Blp', () => { expect(image.width).toBe(128); expect(image.height).toBe(128); expect(image.data.byteLength).toBe(128 * 128 * 4); - expect(image.format).toBe(BLP_IMAGE_FORMAT.IMAGE_RGBA8888); + expect(image.format).toBe(BLP_IMAGE_FORMAT.IMAGE_ABGR8888); }); test('should return image for level 1 and RGBA8888 format', () => { const blp = new Blp(); blp.load('./fixture/pala4.blp'); - const image = blp.getImage(1, BLP_IMAGE_FORMAT.IMAGE_RGBA8888); + const image = blp.getImage(1, BLP_IMAGE_FORMAT.IMAGE_ABGR8888); expect(image.width).toBe(64); expect(image.height).toBe(64); expect(image.data.byteLength).toBe(64 * 64 * 4); - expect(image.format).toBe(BLP_IMAGE_FORMAT.IMAGE_RGBA8888); + expect(image.format).toBe(BLP_IMAGE_FORMAT.IMAGE_ABGR8888); }); }); @@ -198,19 +198,19 @@ describe('Blp', () => { expect(image.width).toBe(128); expect(image.height).toBe(64); expect(image.data.byteLength).toBe(128 * 64 * 4); - expect(image.format).toBe(BLP_IMAGE_FORMAT.IMAGE_RGBA8888); + expect(image.format).toBe(BLP_IMAGE_FORMAT.IMAGE_ABGR8888); }); test('should return image for level 1 and RGBA8888 format', () => { const blp = new Blp(); blp.load('./fixture/pala8.blp'); - const image = blp.getImage(1, BLP_IMAGE_FORMAT.IMAGE_RGBA8888); + const image = blp.getImage(1, BLP_IMAGE_FORMAT.IMAGE_ABGR8888); expect(image.width).toBe(64); expect(image.height).toBe(32); expect(image.data.byteLength).toBe(64 * 32 * 4); - expect(image.format).toBe(BLP_IMAGE_FORMAT.IMAGE_RGBA8888); + expect(image.format).toBe(BLP_IMAGE_FORMAT.IMAGE_ABGR8888); }); }); @@ -231,12 +231,12 @@ describe('Blp', () => { const blp = new Blp(); blp.load('./fixture/dxt1a.blp'); - const image = blp.getImage(1, BLP_IMAGE_FORMAT.IMAGE_RGBA8888); + const image = blp.getImage(1, BLP_IMAGE_FORMAT.IMAGE_ABGR8888); expect(image.width).toBe(8); expect(image.height).toBe(8); expect(image.data.byteLength).toBe(8 * 8 * 4); - expect(image.format).toBe(BLP_IMAGE_FORMAT.IMAGE_RGBA8888); + expect(image.format).toBe(BLP_IMAGE_FORMAT.IMAGE_ABGR8888); }); }); @@ -257,12 +257,12 @@ describe('Blp', () => { const blp = new Blp(); blp.load('./fixture/dxt3.blp'); - const image = blp.getImage(1, BLP_IMAGE_FORMAT.IMAGE_RGBA8888); + const image = blp.getImage(1, BLP_IMAGE_FORMAT.IMAGE_ABGR8888); expect(image.width).toBe(128); expect(image.height).toBe(128); expect(image.data.byteLength).toBe(128 * 128 * 4); - expect(image.format).toBe(BLP_IMAGE_FORMAT.IMAGE_RGBA8888); + expect(image.format).toBe(BLP_IMAGE_FORMAT.IMAGE_ABGR8888); }); }); @@ -283,12 +283,12 @@ describe('Blp', () => { const blp = new Blp(); blp.load('./fixture/dxt5.blp'); - const image = blp.getImage(1, BLP_IMAGE_FORMAT.IMAGE_RGBA8888); + const image = blp.getImage(1, BLP_IMAGE_FORMAT.IMAGE_ABGR8888); expect(image.width).toBe(256); expect(image.height).toBe(256); expect(image.data.byteLength).toBe(256 * 256 * 4); - expect(image.format).toBe(BLP_IMAGE_FORMAT.IMAGE_RGBA8888); + expect(image.format).toBe(BLP_IMAGE_FORMAT.IMAGE_ABGR8888); }); }); });