WoW:BLP file: Difference between revisions
m (→Sample Files: 1a) |
(the data in .BLP file is ARGB instead of RGBA) |
||
| Line 21: | Line 21: | ||
=== The .BLP color palette === | === The .BLP color palette === | ||
The header is always followed by a 256-entry color table. Each entry a 32-bit | The header is always followed by a 256-entry color table. Each entry a 32-bit ARGB 8888 value. This table is only used for RAW images, but is present in all BLPs regardless. | ||
=== RAW compression === | === RAW compression === | ||
Revision as of 14:35, 16 January 2009
BLPs are Blizzard's texture format, used for many games. World of Warcraft uses the BLP2 format in particular. The BLP file structure consists of a header, up to 16 mipmaps of the texture, and a palette. Texture sizes must be powers of two, though the two dimensions do not have to be equal; 512x256 is valid, but 512x200 is not. The first mipmap (mipmap #0) is the full size image; each subsequent mipmap halves both dimensions. The final mipmap should be 1x1.
The .BLP header
struct blp2header {
uint8_t ident[4]; // "BLP2" magic number
uint32_t type; // Texture type: 0 = JPG, 1 = S3TC
uint8_t compression; // Compression mode: 1 = raw, 2 = DXTC
uint8_t alpha_bits; // 0, 1, or 8
uint8_t alpha_type; // 0, 1, 7 or 8
uint8_t uknown1; // Unknown flag
uint32_t width; // Image width in pixels
uint32_t height; // Image height in pixels
uint32_t mipmap_offsets[16]; // The file offsets of each mipmap, 0 for unused
uint32_t mipmap_lengths[16]; // The length of each mipmap data block
} blp2header;
World of Warcraft does not use JPG textures. A discussion of BLP files using JPG compression is beyond the scope of this article. The type flag should always be 1, which indicates the use of either RAW, DXT1, DXT3 or DXT5 compression. Each compression type will be covered separately.
The .BLP color palette
The header is always followed by a 256-entry color table. Each entry a 32-bit ARGB 8888 value. This table is only used for RAW images, but is present in all BLPs regardless.
RAW compression
If the compression flag is 1, each mipmap is stored as an array of 8-bit values, one per pixel, left to right, top to bottom. Each value is an index to the palette. This is by far the simplest format.
DXT1 compression
If the compression flag is 2, all mipmaps are stored using one of DXT1, DXT3 or DXT5. DXT1 offers either no alpha or 1-bit alpha, and so if the alpha_bits value is 0 or 1, the mipmap data will be stored as DXT1. See Wikipedia's entry on DXT compression for the technical details.
DXT3 compression
If the alpha_bits value is 8, the mipmap data may be in either a DXT3 or DXT5 format. DXT3 alpha data is stored as 4 bits per pixel; DXT3 is identified by an alpha_type value of 0, 1 or 8. Again, see Wikipedia's entry on DXT compression for the technical details.
DXT5 compression
If the alpha_type value is 7, the mipmap data is in DXT5 format. This format was first used for Burning Crusade images. Wikipedia's entry on DXT compression has the goods again.
DXT2 and DXT4
DXT2 and DXT4 are identical to DXT3 and DXT5, respectively, save that pixel data winds up being premultiplied by alpha -- that is, each RGBA pixel is not represented by (r, g, b, a) but instead by (ar, ag, ab, a) where all values are normalised to lie between 0 and 1. World of Warcraft does not use these formats.
Sample Files
| File | Encoding |
|---|---|
| GLUES\LoadingBar\Loading-BarGlow.blp | RAW |
| Icons\Trade_Alchemy.blp | DXT1 |
| AuctionFrame\BuyoutIcon.blp | DXT1a |
| Icons\INV_Fishingpole_02.blp | DXT3 |
| Icons\Ability_Rogue_Shadowstep.blp | DXT5 |
Conversion Tools
There exist BLP tools to convert both from and to the BLP format. They can be found in the UI Authors resource list: http://www.wowwiki.com/UI_FAQ/AddOn_Author_Resources#Resources