.NET 8.0+ library for decoding BLP textures. Uses TinyBCSharp for fast texture decompression.
Initially created under the name of SereniaBLPLib by Xalcon & later maintained by hazzik & tomrus88.
Available on NuGet.
Due to not relying on any specific image library anymore, support for BLPs containing JPEG-encoded data was removed and will throw a NYI exception. If someone wants to add this back without relying on a specific image library, feel free to open a PR.
using (var fs = File.OpenRead("test.blp"))
{
var blp = new BLPFile(fs);
var pixels = blp.GetPixels(mipmapLevel, out int w, out int h);
// Pixel handling code, see below!
}
Bitmap bmp = new Bitmap(w, h);
BitmapData bmpdata = bmp.LockBits(new System.Drawing.Rectangle(0, 0, w, h), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
Marshal.Copy(pixels, 0, bmpdata.Scan0, pixels.Length);
bmp.UnlockBits(bmpdata);
var image = SixLabors.ImageSharp.Image.LoadPixelData<Bgra32>(pixels, w, h);
var bitmap = new SKBitmap(w, h, SKColorType.Bgra8888, SKAlphaType.Unpremul);
using var pixmap = bitmap.PeekPixels();
var data = pixmap.GetPixelSpan<byte>();
pixels.CopyTo(data);