HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Having issues with reading BLP format

11-28-2009, 03:41 PM#1
Barade
Hi,
I recently read a lot about Blizzard's Warcraft related binary formats and started writing a library.
Now I'm having some issues with reading BLP files.
As I've already read there is three different compression types: JPEG, paletted with alpha and paletted without alpha.
My current problem is about reading paletted BLP files (and maybe JPEG, was unable to test it since either my JPEG library is crap or I didn't understand the BLP format correctly and reading the wrong data).
First of all my program reads the header data which should be equal for all formats (Use this URL if you want to see the C++ code):
identifier
compression
flags
width
height
pictureType
pictureSubType

Now it calculates the required mip maps by using width and height. Afterwards it adds mip map offset and size 16 times and if the counter variable is smaller than the calculated mip map size, it adds a mip map to the mip map list.
If the compression is paletted it reads 256 color values into palette.
Afterwards it reads index and (if expected) alpha lists of each mip map. Index and alpha lists both have the size mip map height * mip map width which was calculated before.
My program skips all 0 bytes between the current stream position and the read mip map offset (which are actually a lot).
Now the problem is that my program wants to read more data (more mip map data) than the file consists of.
12-02-2009, 11:02 AM#2
arch
it seems that you can only read first mipmap (as the one with the best quality). And calculate others using first when you want to save blp.
i didn't understand why you're reading 16 mipmaps. Their count depends on the size of the image (for image 32*32 there sre only 6 mipmaps - 32*32,16*16,8*8,4*4,2*2,1*1)

not to create a new thread - are WoW jpeg compressed textures same as wc3? i can't find any jpeg wow textures...
12-02-2009, 03:14 PM#3
Barade
Quote:
Originally Posted by arch
it seems that you can only read first mipmap (as the one with the best quality). And calculate others using first when you want to save blp.
i didn't understand why you're reading 16 mipmaps. Their count depends on the size of the image (for image 32*32 there sre only 6 mipmaps - 32*32,16*16,8*8,4*4,2*2,1*1)

not to create a new thread - are WoW jpeg compressed textures same as wc3? i can't find any jpeg wow textures...
I'm just reading the calculated mip maps but always 16 mip map offsets and sizes in the header.

Don't know anything about WoW stuff.
12-05-2009, 04:24 AM#4
midiway
I had already sucefully read the BLP format in windows, to the JPEG format I used IJGlibrary

If you want I can post the code in c++
I know some library that you can check: DevIL and libblp
12-05-2009, 09:35 AM#5
Barade
Thanks, but why does this use "dword flags" and this "dword nummipmaps" instead and flags for BLP2 header.
I've used "flags" in my library, too but BLPPaletter also uses "nummipmaps".
Besides your posted BLP lib seems to read only one mip map when reading for example the uncompressed format. Just another question: your posted lib reads (when reading file with alpha) alternately one normal pixel data and then the alpha pixel data but the specification (on Wc3C.net) looks like there's first the normal data pixel list and after that the alpha pixel list. So which one is the proper way?

edit:
Hmm, I was wrong, I'm reading alpha pixel data exactly after normal pixel data and it seems to work.