#ifndef DIB_H_
#define DIB_H_

class CDIBitmap : public CObject
{
	DECLARE_SERIAL(CDIBitmap)
public: //CopyScreen()中的多线函数程使用
	HWND hWnd;
	CDC *pDC;
	int x0;
	int y0;
	int copyStatus;
public:
	CDIBitmap();
	~CDIBitmap();
	BITMAPINFO *m_pBMI;
	BYTE *m_pBits; //主缓冲区
	bool isTwoBuffer; //是否支持双缓冲区,默认不支持
	BYTE *m_p2Bits; //第二缓冲区
	//LoadDIB中初始化
	int width;
	int height;
	unsigned long bmBitsSize;
public:
	void ChangeColor(COLORREF s, COLORREF d,int range);
	int widthBytes;
	int remainBytes; //缓冲区三元组没有构成DWORD的填充部分长度
	void BltBmpToBuf(int x, int y,CDIBitmap *pSrcDIB,COLORREF crTrsp = -1);
	void SetTwoBuffer(bool isTowBuffer = true);
	void Buf2ToBuf1();
	void Buf1ToBuf2();

	BITMAPINFO* GetBMHdrPtr() {return m_pBMI;}
	BYTE* GetBMBitsPtr() {return m_pBits;}
	virtual void Serialize(CArchive&ar);
	RGBQUAD* GetBMColorTabPtr();
	int GetNumClrEntries();
	int GetBMWidth();
	int GetBMHeight();


	virtual BOOL LoadDIB(CString fileName);
	virtual void DrawBitmap(CDC *pDC,int x,int y);
	virtual void DrawBitmap(CDC *pDC, int destX, int destY,int srcX,int srcY,int srcCx,int srcCy);
	virtual void StretchBitmap(CDC *pDC, int x, int y,int cx,int cy);

	CWinThread *pMyThread;
	void CopyScreen(CDC *pDC,int x0,int y0,CString fileNme);
	bool FastCopyScreen(CDC *pDC,int x = 0,int y = 0,int cx = 800,int cy = 600);
	CDIBitmap* CopyDIB(int x,int y,int width,int height);
	void ChangeColor(COLORREF s,COLORREF d);
};

#endif