From 227b0dac8f6f67a0e2b9aa114f574a92e5e88476 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Fri, 22 Dec 2023 13:47:34 -0600 Subject: [PATCH] feat(blp): add helper to return all images from a BLP --- src/lib/blp/Blp.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/lib/blp/Blp.ts b/src/lib/blp/Blp.ts index 6fecc30..5473bd4 100644 --- a/src/lib/blp/Blp.ts +++ b/src/lib/blp/Blp.ts @@ -237,6 +237,25 @@ class Blp { } } + getImages( + startLevel: number = 0, + outputFormat: BLP_IMAGE_FORMAT = BLP_IMAGE_FORMAT.IMAGE_UNSPECIFIED, + ): BlpImage[] { + if (startLevel > this.#images.length - 1) { + throw new Error( + `Requested start level out of range: ${startLevel} > ${this.#images.length - 1}`, + ); + } + + const images: BlpImage[] = []; + + for (let level = startLevel; level < this.#images.length; level++) { + images.push(this.getImage(level, outputFormat)); + } + + return images; + } + /** * For a given mip level, return a BlpImage containing the unconverted image data from the Blp. If the Blp uses a * palette, the image data will be converted to IMAGE_FORMAT.IMAGE_ABGR8888 before being returned.