Class BLP
A BLP2 texture file — every WoW client release reads the same layout, so the class carries no client-version axis. read()/write() move the file whole with a byte-perfect round-trip while the mip payloads are unmodified; decode(level) produces an RGBA8 Image from a stored level (palettized, DXT1/3/5, BC5 and raw BGRA all decode); encode(image, settings) rebuilds the palette/compression/mip chain from one. Raw payload access goes through mip()/set_mip(). See https://wowdev.wiki/BLP.
public class BLP : FileEntity, IDisposable
- Inheritance
-
BLP
- Implements
- Inherited Members
Constructors
BLP()
public BLP()
BLP(BLP)
Copy-construct: a deep copy of other (the C++ copy constructor).
public BLP(BLP other)
Parameters
otherBLP
Properties
AlphaDepth
Alpha bits per pixel (0, 1, 4 or 8): the alpha plane depth for Palettized files, and a selection hint for DXT.
public byte AlphaDepth { get; set; }
Property Value
ColorEncoding
How the pixel payload is encoded.
public ColorEncoding ColorEncoding { get; set; }
Property Value
Height
The level-0 height in pixels.
public uint Height { get; set; }
Property Value
MipCount
The number of stored mip levels (level indices 0 .. count - 1).
public ulong MipCount { get; }
Property Value
MipFlags
The header's mip byte: 0 = level 0 only, 1 = generated mips, 2 = handmade mips (plus rare high flag bits, preserved verbatim).
public byte MipFlags { get; set; }
Property Value
Palette
The 256-entry color table of Palettized files (b, g, r + a padding byte, preserved verbatim). Present but unused for Dxt/Bgra files.
public FixedArray<CImVector> Palette { get; set; }
Property Value
PreferredFormat
The client-side pixel format hint; selects the DXT block format for Dxt-encoded files.
public PixelFormat PreferredFormat { get; set; }
Property Value
Version
The header version field; 1 in every shipped file.
public uint Version { get; set; }
Property Value
Width
The level-0 width in pixels.
public uint Width { get; set; }
Property Value
Methods
Decode()
Decode mip level 0 to an RGBA8 Image.
public Image Decode()
Returns
- Image
the decoded image
Decode(uint)
Decode one stored mip level to an RGBA8 Image.
public Image Decode(uint level)
Parameters
leveluintthe mip level to decode
Returns
- Image
the decoded image
Dispose()
Release the native object now. Optional: the finalizer releases it on
collection anyway - dispose (or using) when you want native memory back
promptly.
public override void Dispose()
Encode(Image)
Rebuild the whole texture from an RGBA8 image with the default settings (DXT, alpha depth 8 -> BC3, full mip chain).
public void Encode(Image image)
Parameters
imageImagethe level-0 image; width * height * 4 pixel bytes
Encode(Image, EncodeSettings)
Rebuild the whole texture from an RGBA8 image: sets the header fields, quantizes/compresses every level and generates the mip chain per the settings.
public void Encode(Image image, EncodeSettings settings)
Parameters
imageImagethe level-0 image; width * height * 4 pixel bytes
settingsEncodeSettingsencoding, block format, alpha depth and mip generation choices
EnsureValid()
Validate and raise on the first error instead of returning a report — the assert-style face of validate().
public void EnsureValid()
Mip(uint)
One level's raw payload bytes (palette indices + alpha plane, DXT blocks, or BGRA pixels, per colorEncoding).
public byte[] Mip(uint level)
Parameters
leveluintthe mip level
Returns
- byte[]
a copy of the payload bytes
MipHeight(uint)
The pixel height of a mip level (level 0 halves per step, floored at 1).
public uint MipHeight(uint level)
Parameters
leveluintthe mip level
Returns
MipWidth(uint)
The pixel width of a mip level (level 0 halves per step, floored at 1).
public uint MipWidth(uint level)
Parameters
leveluintthe mip level
Returns
Read(byte[])
Parse a BLP2 file from memory, replacing this entity's contents.
public void Read(byte[] data)
Parameters
databyte[]the complete file bytes
Read(FileSystem, FileKey)
Load the BLP from a client filesystem, replacing this entity's contents.
public void Read(FileSystem fs, FileKey key)
Parameters
fsFileSystemthe filesystem gateway
keyFileKeythe file identity (path and/or FileDataID)
SetMip(uint, byte[])
Replace one level's raw payload bytes verbatim. The caller owns their consistency with the header fields; changing a payload's size switches write() to the canonical contiguous layout.
public void SetMip(uint level, byte[] data)
Parameters
Validate()
Check the logical integrity contracts this texture must satisfy for the client to decode it — the base level's presence, the dimensions, and every stored level covering the pixels its size implies. write() never runs this; call it before writing when you want to know the result will load.
public ValidationReport Validate()
Returns
- ValidationReport
every violated contract, in level order
Write()
Serialize this entity. While the mip payloads are unmodified the original file's exact layout is replayed, so an unmodified read rewrites byte-for-byte.
public byte[] Write()
Returns
- byte[]
the file bytes
Write(FileSystem, FileKey)
Serialize and store the BLP through the filesystem's project overlay.
public void Write(FileSystem fs, FileKey key)
Parameters
fsFileSystemthe filesystem gateway
keyFileKeythe file identity; must resolve to a path