war3-model-blp
v0.1.0
Published
Lightweight BLP1 decoder extracted from war3-model.
Maintainers
Readme
war3-model-blp
Lightweight BLP functionality extracted from war3-model, focused on BLP image decoding without the full model viewer/runtime.
This package currently exposes the BLP1 decoder bundled from war3-model 4.0.1.
Install
npm install war3-model-blpUsage
Node.js
const fs = require("node:fs");
const { decodeBLP, getBLPImageData } = require("war3-model-blp");
const buffer = fs.readFileSync("ReplaceableTextures/CommandButtons/BTNFootman.blp");
const blp = decodeBLP(buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength));
const imageData = getBLPImageData(blp, 0);
console.log(imageData.width, imageData.height, imageData.data);Run the Node example with a local BLP file:
node examples/node.cjs path/to/file.blpBrowser
<script src="dist/war3-model-blp.js"></script>
<script>
const { decodeBLP, getBLPImageData } = globalThis.war3modelBlp;
</script>Browser demo
Open examples/browser.html in a browser, choose a .blp file, and the demo will decode mipmap 0 onto a canvas.
Tests
npm testThe automated test is Node-only and verifies the package entry plus a synthetic 1x1 red BLP1 fixture stored at test/fixtures/red-1x1.blp. The browser test case is intentionally kept as examples/browser.html, because it needs a real browser and a local .blp file selected by the user.
API
decodeBLP(arrayBuffer)
Parses a BLP1 image from an ArrayBuffer and returns decoded metadata plus mipmap information.
getBLPImageData(blp, mipmapIndex)
Decodes one mipmap from the object returned by decodeBLP.
Returns an ImageData object when ImageData is available. In non-browser runtimes it returns an ImageData-like object:
{
width: number,
height: number,
data: Uint8ClampedArray,
colorSpace: "srgb"
}Scope
- BLP1 is supported.
- BLP0 and BLP2 are not supported by this extracted decoder.
- This package is intended as a small decoder bundle, not a full
war3-modelreplacement.
Attribution
The decoder is extracted from war3-model 4.0.1.
