#include "bitmap.h" #include #include using namespace std; int LoadBitmap(const char * filename, char * &buffer, int &width, int &height) { ifstream fin; // Open the file fin.open(filename, ios::binary); if (!fin.good()) { cout << "Could not open the file" << endl; return 0; } BITMAPFILEHEADERDV bfh; // Read the bitmap headers BITMAPINFOHEADERDV bih; fin.read((char*)&bfh, sizeof(BITMAPFILEHEADERDV)-2); fin.read((char*)&bih, sizeof(BITMAPINFOHEADERDV)); width = bih.Width; height = bih.Height; // Make sure we can use this bitmap if ((bfh.Type != 0x4D42) || // hexidecimal for 'BM' or BitMap (bih.Planes != 1) || (bih.BitCount != 24) || (bih.Compression != 0)) { cout << "Could not read bitmap" << endl; fin.close(); return false; } // Read the image data into a buffer buffer = new char[bih.Width*bih.Height*3]; fin.read(buffer, bih.Width*bih.Height*3); fin.close(); // Swap red and blue values in the buffer unsigned char temp; for(int i = 0; i < bih.Width*bih.Height*3; i += 3) { temp = buffer[i]; buffer[i] = buffer[i+2]; buffer[i+2] = temp; } return 1; }