//
//  Class:      CCeXDib
//
//  Compiler:   Visual C++
//              eMbedded Visual C++
//  Tested on:  Visual C++ 6.0
//              Windows CE 3.0
//
//  Author:     Davide Calabro'     davide_calabro@yahoo.com
//                                  http://www.softechsoftware.it
//
//  Note:       This class uses code snippets taken from a similar class written
//              for the Win32 enviroment by Davide Pizzolato (ing.davide.pizzolato@libero.it)
//
//  Disclaimer
//  ----------
//  THIS SOFTWARE AND THE ACCOMPANYING FILES ARE DISTRIBUTED "AS IS" AND WITHOUT
//  ANY WARRANTIES WHETHER EXPRESSED OR IMPLIED. NO REPONSIBILITIES FOR POSSIBLE
//  DAMAGES OR EVEN FUNCTIONALITY CAN BE TAKEN. THE USER MUST ASSUME THE ENTIRE
//  RISK OF USING THIS SOFTWARE.
//
//  Terms of use
//  ------------
//  THIS SOFTWARE IS FREE FOR PERSONAL USE OR FREEWARE APPLICATIONS.
//  IF YOU USE THIS SOFTWARE IN COMMERCIAL OR SHAREWARE APPLICATIONS YOU
//  ARE GENTLY ASKED TO DONATE 1$ (ONE U.S. DOLLAR) TO THE AUTHOR:
//
//      Davide Calabro'
//      P.O. Box 65
//      21019 Somma Lombardo (VA)
//      Italy
//
//
#ifndef _CEXDIB_H_
#define _CEXDIB_H_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef HDIB
#define HDIB    HANDLE
#endif

#ifndef WIDTHBYTES
#define WIDTHBYTES(bits) (((bits) + 31) / 32 * 4)
#endif

#ifndef BFT_BITMAP
#define BFT_BITMAP 0x4d42 // 'BM'
#endif

class CCeXDib
{
public:
    CCeXDib();
    virtual ~CCeXDib();

    HDIB   Create(DWORD dwWidth, DWORD dwHeight, WORD wBitCount);
    void   Clone(CCeXDib* src);
    void   Draw(HDC hDC, DWORD dwX, DWORD dwY);
    LPBYTE GetBits();
    void   Clear(BYTE byVal = 0);

    void SetGrayPalette();
    void SetPaletteIndex(BYTE byIdx, BYTE byR, BYTE byG, BYTE byB);
    void SetPixelIndex(DWORD dwX, DWORD dwY, BYTE byI);
    void BlendPalette(COLORREF crColor, DWORD dwPerc);

    WORD  GetBitCount();
    DWORD GetLineWidth();
    DWORD GetWidth();
    DWORD GetHeight();
    WORD  GetNumColors();

    BOOL WriteBMP(LPCTSTR bmpFileName);

private:
    void FreeResources();

    DWORD GetPaletteSize();
    DWORD GetSize();

    RGBQUAD RGB2RGBQUAD(COLORREF cr);

    HDIB             m_hDib;
    BITMAPINFOHEADER m_bi;
    DWORD            m_dwLineWidth;
    WORD             m_wColors;

    HBITMAP m_hBitmap; // Handle to bitmap
    HDC     m_hMemDC;  // Handle to memory DC
    LPVOID  m_lpBits;  // Pointer to actual bitmap bits
};

#endif
