Question

I got a working loader for 24 bit bmps, however it seems fairly common that the pictures I download to try is 8 bit and with compression BI_RLE8 (I dont know if there is a correlation between does 2 values? Are all 8 bit bmps compressed with BI_RLE8?), so I wanted to add functionality to it aswell, but it doesnt really come out rigth.

Rigth now I'm calculating the number of colors with:

numColours = 1 << bitmapInfoHeader.biBitCount;

then reading them in to colour tablet array:

rgbquad = new RGBQUAD[numColours];
in.read((char*)rgbquad, sizeof(RGBQUAD)*numColours);

Reading the pixels

LONG imageSize = (LONG)((float)bitmapInfoHeader.biHeight * (float)bitmapInfoHeader.biWidth * ((float)bitmapInfoHeader.biBitCount/8));
BYTE *bitmapImage=new BYTE[imageSize];
in.seekg(bitmapFileHeader.bfOffBits, std::ios::beg);
in.read((char*)bitmapImage, imageSize);

then when I extract the data like this

for(int j=0, k = 0; j< bitmapInfoHeader.biHeight; j++){
    for(int i=0; i < bitmapInfoHeader.biWidth; i++){
        index = ( bitmapInfoHeader.biWidth * j) + i;
        pixelMap[index].setR(rgbquad[bitmapImage[k]].rgbRed);
        pixelMap[index].setG(rgbquad[bitmapImage[k]].rgbGreen);
        pixelMap[index].setB(rgbquad[bitmapImage[k]].rgbBlue);
        pixelMap[index].setA(255);
        ++k;
    }
}

Some pictures for comparision:

Original image:

Original image

After Loading an rewritting: After Loading an rewritting

I seems that the pixels are being read wrong, So could anyone show me how you are suppose to load them, or point me in the direction of a guide that does ?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top