t tagBmpFile & F)
{
os << F.bfType << F.bfSize << F.bfReserved1 << F.bfReserved2 << F.bfOffBits;
return os;
}
}bmpFile;
//位图信息头
typedef struct tagBmpInfo
{
DWORD biSize;
DWORD biWidth;
DWORD biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
DWORD biXPelsPerMeter;
DWORD biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
const struct tagBmpInfo & operator = (const struct tagBmpInfo & I)
{
if (&I != this)
{
biSize = I.biSize;
biWidth = I.biWidth;
biHeight = I.biHeight;
biPlanes = I.biPlanes;
biBitCount = I.biBitCount;
biCompression = I.biCompression;
biSizeImage = I.biSizeImage;
biXPelsPerMeter = I.biXPelsPerMeter;
biYPelsPerMeter = I.biYPelsPerMeter;
biClrUsed = I.biClrUsed;
biClrImportant = I.biClrImportant;
}
return *this;
}
friend std::istream & operator>>(std::istream & is,struct tagBmpInfo & F)
{
is >> F.biSize
>> F.biWidth
>> F.biHeight
>> F.biPlanes
>> F.biBitCount
>> F.biCompression
>> F.biSizeImage
>> F.biXPelsPerMeter
>> F.biYPelsPerMeter
>> F.biClrUsed
>> F.biClrImportant;
return is;
}
friend std::ostream & operator<<(std::ostream & os,const struct tagBmpInfo & F)
{
os << F.biSize
<< F.biWidth
<< F.biHeight
<< F.biPlanes
<< F.biBitCount
<< F.biCompression
<< F.biSizeImage
<< F.biXPelsPerMeter
<< F.biYPelsPerMeter
<< F.biClrUsed
<< F.biClrImportant;
return os;
}
}bmpInfo;
//调色板
typedef struct tagRGBQuad
{
BYTE rgbBlue;
BYTE rgbGreen;
BYTE rgbRed;
BYTE rgbReserved;
const struct tagRGBQuad & operator = (const struct tagRGBQuad & Q)
{
if (&Q != this)
{
rgbBlue = Q.rgbBlue;
rgbGreen = Q.rgbGreen;
rgbRed = Q.rgbRed;
rgbReserved = Q.rgbReserved;
}
return *this;
}
friend std::istream & operator>>(std::istream & is,struct tagRGBQuad & F)
{
is >> F.rgbBlue
>> F.rgbGreen
>> F.rgbRed
>> F.rgbReserved;
return is;
}
friend std::ostream & operator<<(std::ostream & os,const struct tagRGBQuad & F)
{
os << F.rgbBlue
<< F.rgbGreen
<< F.rgbRed
<< F.rgbReserved;
return os;
}
} RGBQuad;
//位图结构
typedef struct _CBmp
{
std::string filePass;
bmpFile bmpFileH;
bmpInfo bmpInfoH;
DWORD storeWidth;
bitField bmpBitField;
RGBQuad * bmpRGB;
BYTE * bmpData;
BYTE & gr
asp(DWORD i, DWORD j)
{
return bmpData[(i)*storeWidth+(j)];
}
}CBmp;
bool openBmp(CBmp & inBmp,const std::string fpass)
{
FILE * inbmpF;
WORD colorCount;
if ((inbmpF=fopen(fpass.c_str(),"rb"))==NULL)
return false;
else
{
fread(&inBmp.bmpFileH.bfType,2,1,inbmpF);
fread(&inBmp.bmpFileH.bfSize,4,1,inbmpF);
fread(&inBmp.bmpFileH.bfReserved1,2,1,inbmpF);
fread(&inBmp.bmpFileH.bfReserved2,2,1,inbmpF);
fread(&inBmp.bmpFileH.bfOffBits,4,1,inbmpF);
//fread(&bmpFileH,14,1,inbmpF);
fread(&inBmp.bmpInfoH,40,1,inbmpF);
if (0<inBmp.bmpInfoH.biBitCount&&inBmp.bmpInfoH.biBitCount<=8)
colorCount=(WORD)(pow(2,inBmp.bmpInfoH.biBitCount));
else
colorCo