In my function "format24BMP" there is an if statement "x == byteWidth"... it should enter it 100 times but it appears to only enter it once.
Here are my relevant functions to loading the bitmap:
bool Bitmap::readBMP(char* fn){ fname = fn; ifstream inf(fname,ios::binary|ios::in); if(!inf.is_open()){ return false; } //read in BITMAPFILEHEADER inf.read((char*)&bmfh->bfType,2); if(bmfh->bfType!=BITMAP_ID){ return false; } inf.read((char*)&bmfh->bfSize,4); inf.read((char*)&bmfh->bfReserved1,2); inf.read((char*)&bmfh->bfReserved2,2); inf.read((char*)&bmfh->bfOffBits,4); //read in BITMAPINFOHEADER inf.read((char*)&bmih->biSize,4); inf.read((char*)&bmih->biWidth,4); inf.read((char*)&bmih->biHeight,4); inf.read((char*)&bmih->biPlanes,2); inf.read((char*)&bmih->biBitCount,2); inf.read((char*)&bmih->biCompression,4); inf.read((char*)&bmih->biSizeImage,4); inf.read((char*)&bmih->biXPelsPerMeter,4); inf.read((char*)&bmih->biYPelsPerMeter,4); inf.read((char*)&bmih->biClrUsed,4); inf.read((char*)&bmih->biClrImportant,4); //has no color table and 3 bytes represents 1 pixel if(bmih->biBitCount == 24){ byteWidth = bmih->biWidth*3; //get the length of the padded byte rows if(bmih->biWidth%4!=0){ padWidth = byteWidth; padWidth = (int)((padWidth/4)+1); padWidth *= 4; } //no padded bytes else{ padWidth = byteWidth; } //get the absolute value of height if(bmih->biHeight < 0) { byteHeight = (bmih->biHeight*-1); } else { byteHeight = (bmih->biHeight); } pImgSize = bmfh->bfSize - bmfh->bfOffBits; imgSize = byteWidth*byteHeight; //get the number of padded bytes per row padBytes = padWidth - byteWidth; //read in unformated data char* tPData = new char[pImgSize]; inf.read(tPData,pImgSize); //now format pixel data format24BMP(tPData); //stores formatted data in aColors } return true;}
void Bitmap::format24BMP(char* tPData){ aColors = new char[imgSize]; //if bmih->biHeight is positive, the pixel data is backwards if(bmih->biHeight > 0){ int end = imgSize - 3; for(int x = 0; x < pImgSize; x+=3){ if(x == byteWidth){ x+=padBytes; //skip the padded bytes } aColors[end] = tPData[x+2]; aColors[end+1] = tPData[x+1]; aColors[end+2] = tPData[x]; end -= 3; } } else{ }}
I admit I followed one of the tutorials on gamedev but I tried to do most of it on my own. Right now I'm only trying to get it to work with 24bpp and I have a specific file I'm working with just trying to make sure it works with it and I know it won't go into the empty else statement etc.
I didn't pack my structures so I had to read my data in the way I did in my function.