Rust library for working with BLP files (Blizzard texture format) with C/C++ interface for use in other projects.
This library provides a C-compatible API for working with BLP files, using the Rust crate blp. Supports loading BLP files from data buffer or filesystem and converting them to RGBA format.
cargo build --releaseAfter compilation, local artifacts are placed in target/release (crate name based):
libblp_lib.a- static librarylibblp_lib.dylib(macOS) /libblp_lib.so(Linux) /blp_lib.dll(Windows) - dynamic library
For cross-platform, ready-to-ship artifacts with simplified names, use the distribution builder below.
Use ./build-only.sh to create distribution packages for all platforms:
libblp-macos.a- static library (arm64 + x86_64)libblp-macos.dylib- dynamic library (arm64 + x86_64)
libblp-windows.a- static libraryblp-windows.dll- dynamic library
libblp-linux.a- static library (musl)
blp.h- C/C++ header file (cross-platform)
Header files:
- Local developer build: include
include/blp_lib.h - Distribution build: include
dist/blp.h
Example of loading a BLP file:
#include <stdio.h>
#include <stdlib.h>
#include "blp.h"
int main() {
BlpImage image;
BlpResult result = blp_load_from_file("texture.blp", &image);
if (result == BLP_SUCCESS) {
printf("Loaded image %dx%d, data size: %d bytes\n",
image.width, image.height, image.data_len);
// Use image.data (RGBA format)
// Don't forget to free memory
blp_free_image(&image);
} else {
printf("Error loading BLP file: %d\n", result);
}
return 0;
}# Static linking (recommended for simple tests)
gcc -I./include -L./target/release your_program.c -o your_program -lblp_libmacOS:
gcc -I./dist -L./dist your_program.c -o your_program -lblp-macos -ldlLinux:
gcc -I./dist -L./dist your_program.c -o your_program -lblp-linux -ldl -lpthreadWindows:
# Using MinGW (static)
gcc -I./dist -L./dist your_program.c -o your_program.exe -lblp-windowsNote on mipmaps:
- By default, decoding loads only the base (top) mip for performance.
- Encoding APIs let you specify how many mip levels to generate or pass explicit flags.
Structure for storing BLP image data:
uint32_t width- image widthuint32_t height- image heightuint8_t* data- pointer to data in RGBA formatuint32_t data_len- data size in bytes
Operation result codes:
BLP_SUCCESS = 0- operation completed successfullyBLP_INVALID_INPUT = -1- invalid input parametersBLP_PARSE_ERROR = -2- BLP file parsing errorBLP_MEMORY_ERROR = -3- memory allocation errorBLP_UNKNOWN_ERROR = -99- unknown error
Loads BLP file from data buffer into memory.
Parameters:
const uint8_t* data- pointer to BLP file datauint32_t data_len- data length in bytesBlpImage* out_image- pointer to structure for storing result
Returns: BlpResult
Loads BLP file from filesystem.
Parameters:
const char* filename- path to BLP fileBlpImage* out_image- pointer to structure for storing result
Returns: BlpResult
Frees memory allocated for BlpImage.
Parameters:
BlpImage* image- pointer to structure to free
Returns library version string.
Returns: const char* - pointer to version string
Checks if data buffer is a valid BLP file.
Parameters:
const uint8_t* data- pointer to data to checkuint32_t data_len- data length in bytes
Returns: int - 1 if valid BLP, 0 otherwise
Generate BLP from a source image (PNG/JPEG/etc.):
-
blp_encode_file_to_blp(input_path, output_path, quality, mip_count)- Create a BLP with the first
mip_countlevels (min 1).qualityis 0..100.
- Create a BLP with the first
-
blp_encode_file_to_blp_with_flags(input_path, output_path, quality, mip_flags, mip_flags_len)mip_flagsis an array of 0/1 values, each enabling a mip level by index.
-
blp_encode_bytes_to_blp(image_bytes, image_len, output_path, quality, mip_count)- Encode image content already in memory.
-
blp_encode_bytes_to_blp_with_flags(image_bytes, image_len, output_path, quality, mip_flags, mip_flags_len)- Same as above, but with explicit mip visibility flags.
-
blp_decode_mip_to_png_from_file(blp_path, mip_index, output_png_path)- Decode selected mip into a PNG file. Loads only the requested mip.
-
blp_decode_mip_to_png_from_buffer(blp_bytes, blp_len, mip_index, output_png_path)- Same as above, but takes the .blp data from memory.
-
blp_extract_mip_to_jpg_from_file(blp_path, mip_index, output_jpg_path)- For JPEG-BLP: extract raw JPEG stream of the chosen mip without decoding.
-
blp_extract_mip_to_jpg_from_buffer(blp_bytes, blp_len, mip_index, output_jpg_path)- Same as above for in-memory .blp data.
cargo test