/*
* Function: ComputePaletteSize
* Purpose¡GCompulates the Color palette's size of specified Bitmap
* Entry: [in] int nBitCount:specified the bit deepth of the bitmap
* Return¡GNULL
* External Ref.: NULL
*
*/
void CxBitmap::ComputePaletteSize(int nBitCount)
{
switch(nBitCount)
{
case 1:
m_nColorTableEntries = 2;
break;
case 4:
m_nColorTableEntries = 16;
break;
case 8:
m_nColorTableEntries = 256;
break;
case 16:
case 24:
case 32:
m_nColorTableEntries = 0;
break;
default:
ASSERT(FALSE);
}
}
/*
* Function: LoadBitmapFile
* Purpose¡Gthe main interface,Load a bitmap from a file,
* Entry: NULL
* Return¡GTRUE if successful ,otherwise,FALSE
* External Ref.: NULL
*
*/
BOOL CxBitmap::LoadBitmapFile()
{
CFileDialog fileBitmapDlg(true,
"bmp",
NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"Bitmap files(*.bmp)|*.bmp",
NULL);
if (fileBitmapDlg.DoModal() != IDOK)
{
return false;
}
/*
* Function: Read
* Purpose¡GRead a bitmap from a file,
* Entry: [in],CFile *pFile:the file pointer to the specified bitmap file
* Return¡GTRUE if successful ,otherwise,FALSE
* External Ref.: called in the function:LoadBitmapFile and Serialize
*
*/
BOOL CxBitmap::Read(CFile *pFile)
{
FreeAll();
BITMAPFILEHEADER bmfh;
try
{
int nCount,nSize;
nCount=pFile->Read((LPVOID)&bmfh,sizeof(BITMAPFILEHEADER));
nSize = bmfh.bfOffBits - sizeof(BITMAPFILEHEADER);
//conform BMP file
if(bmfh.bfType!=0x4d42)
throw new CFileException;
//Firstly, conform the format: windows BMP ? IBM OS2 BMP
DWORD dwSize=0;
int n=sizeof(DWORD);
pFile->Read(&dwSize,n);
this->m_bIsWindowBMP=(dwSize==40)?true:false;
//rewind
pFile->Seek(-n,CFile::current);
//Get the image data
m_lpImage = (LPBYTE) new char[m_dwSizeImage];
nCount = pFile->ReadHuge(m_lpImage, m_dwSizeImage);
}
catch(CFileException *pe)
{
AfxMessageBox("Failed to load the file : "+pFile->GetFileName());
pe->Delete();
return false;
}
return true;
}
/*
* Function: Write
* Purpose¡GWrite a bitmap to a file,
* Entry: [in],CFile *pFile:the file pointer to the specified bitmap file
* Return¡GTRUE if successful ,otherwise,FALSE
* External Ref.: called in the function: Serialize
*
*/
BOOL CxBitmap::Write(CFile *pFile)
{
BITMAPFILEHEADER bmfh;
bmfh.bfType = 0x4d42; // 'BM'
bmfh.bfSize = 0;//not important in here
bmfh.bfReserved1 = bmfh.bfReserved2 = 0;
/*
* Project: MPG
* Module: bitmap process
* File Name: xBitmap.cpp
* Author: Song,Ye Wen
* Start Date: June 30,2003
* Language: Microsoft Visual C++ 6.0/C for ARM-gcc
* Target: Implemention of the CxBitmap class used for bitmap inverting process
* Summary: This file contains the functions's implemention to invert bitmap file/picture
* Ref document:
* 1. << ying xiang dang bao dian---windows shizuo>> tp31-0188
*
* Change Note:
* Copyright: Copyright 2001-2003 Inventec Electronics (NanJing) Co. Ltd.
* All rights reserved.
*/
/*
* Project: MPG
* Module: bitmap process
* File Name: xBitmap.h
* Author: Song,Ye Wen
* Start Date: June 30,2003
* Language: Microsoft Visual C++ 6.0/C for ARM-gcc
* Target: Declare the interface of the CxBitmap class used for bitmap inverting process
* Summary: This file contains the functions interface to invert bitmap file/picture
* Ref document:
* 1. << ying xiang dang bao dian---windows shizuo>> tp31-0188
*
* Change Note:
* Copyright: Copyright 2001-2003 Inventec Electronics (NanJing) Co. Ltd.
* All rights reserved.
*/
class CxBitmap : public CObject
{
DECLARE_SERIAL(CxBitmap)
private:
//Common data: same to window and os2
BOOL m_bIsWindowBMP;
LPVOID m_lpvColorTable;
// the pixel buffer
LPBYTE m_lpImage;
//the bitmap size
DWORD m_dwSizeImage;
//the items of color table
int m_nColorTableEntries;
//-----------------------------------------------------------------
//Window format bitmap
LPBITMAPINFOHEADER m_lpBMIH;
//OS2 format bitmap
BITMAPCOREHEADER *m_lpBCIH;
private:
void ComputePaletteSize(int nBitCount);
void FreeAll();
public:
CxBitmap();
virtual ~CxBitmap();
// can read /write automaticly
void Serialize(CArchive& ar);
// get the bitmap's property
int GetSizeHeader();
CSize GetDimensions();
int GetSizeImage();