I'm trying to write a program that reads in a BMP file and outputs some simple data specs, like height and width in pixels. This is just to make sure I'm reading in the file correctly before I move forward in manipulating it and so forth. My program is compiling, but when I put in a 640 x 480 image, the program says that the image is 31457280 x 65536. Clearly something's going wrong. Can anyone see a problem?
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
usingnamespace std;
// #pragma pack(2) // found this as a 2 byte alignment... no idea what this is
// bitmap header
struct bmpFileHeader
{
unsignedshort bfType; // file type
unsignedint bfSize; // size in bytes of bmp
unsignedshort bfReserved1; // still don't fully understand this
unsignedshort bfReserved2; // or this...
unsignedint bfOffBits; // or this... depends on color palette?
};
// bitmap information specific to image data
struct bmpInfoHeader
{
unsignedint biSize; // number of bytes required by InfoHeader
int biWidth; // width in pixels
int biHeight; // height in pixels
unsignedshort biPlanes; // number of color (bit) planes (?)
unsignedshort biBitCount; // number of bits per pixel
unsignedint biCompression; // type of compression
unsignedint biSizeImage; // size of image in bytes
int biXPixelsPerMeter; // pixels per meter in x axis
int biYPixelsPerMeter; // pixels per meter in y axis
unsignedint biColorsUsed; // number of colors used by the bitmap
unsignedint biColorsImportant; // number of colors that are important
};
// color palette
// I found unsigned char to be equivalent to byte
struct RGBQUAD
{
unsignedchar rgbRed;
unsignedchar rgbGreen;
unsignedchar rgbBlue;
unsignedchar rgbReserved; // not sure about this one
};
class bitMap
{
public:
bitMap();
~bitMap();
void loadBitMap(char *fileName); // loads the bmp file
private:
bmpFileHeader bmfh;
bmpInfoHeader bmih;
};
// #pragma pack()