Blp Uncompressed is bgra, not rgba
Posted: Thu Sep 09, 2021 3:57 pm
				
				XnView: MP 0.98.4 - 64 bit
OS: Windows - 64bit
XnViewMP load BLP pictures with the wrong colors
Effect: just getting wrong picture colors
To reproduce:
1. Download original blp file from: https://wow.tools/casc/file/chash?conte ... les915.blp
2. This is how the image should look https://wow.tools/casc/preview/chash?bu ... 04dd466d8f
3. XnViewMP show up wrong colors when u open blp file.
I have attached how the image looks when u open that blp in XNViewMP Expected colors: Solution:
The header of blp
if preferredFormat is 8 and colorEncoding is 3, the data is in BGRA format and it needs flipping to RGBA
For example:
			OS: Windows - 64bit
XnViewMP load BLP pictures with the wrong colors
Effect: just getting wrong picture colors
To reproduce:
1. Download original blp file from: https://wow.tools/casc/file/chash?conte ... les915.blp
2. This is how the image should look https://wow.tools/casc/preview/chash?bu ... 04dd466d8f
3. XnViewMP show up wrong colors when u open blp file.
I have attached how the image looks when u open that blp in XNViewMP Expected colors: Solution:
The header of blp
Code: Select all
struct BlpFile{
    uint32_t fileIdent;
    int32_t version;
    uint8_t colorEncoding;
    uint8_t alphaChannelBitDepth;
    uint8_t preferredFormat;
    uint8_t mipmap_level_and_flags;
    int32_t width;
    int32_t height;
    int32_t offsets[16];
    int32_t lengths[16];
    uint8_t palette[1024];
};For example:
Code: Select all
if (blpFile->colorEncoding == 3) {
    //Turn BGRA into RGBA
    validSize = 4 * width * height;
    mipmapStruct.texture = std::vector<uint8_t>(validSize, 0);
    for (int j = 0; j < width * height; j++) {
        uint8_t b = data[j * 4 + 0];
        uint8_t g = data[j * 4 + 1];
        uint8_t r = data[j * 4 + 2];
        uint8_t a = data[j * 4 + 3];
        mipmapStruct.texture[j * 4 + 0] = r;
        mipmapStruct.texture[j * 4 + 1] = g;
        mipmapStruct.texture[j * 4 + 2] = b;
        mipmapStruct.texture[j * 4 + 3] = a;
    }
}