6 #endif // _MSC_VER > 1000
8 // CDIB.h : header file
11 // Copyright © Dundas Software Ltd. 1999, All Rights Reserved
13 // //////////////////////////////////////////////////////////////////////////
16 // NO Abstract class (does not have any objects)
17 // NO Derived from CWnd
19 // NO Two stage creation (constructor & Create())
20 // NO Has a message map
21 // NO Needs a resource (template)
22 // YES Persistent objects (saveable on disk)
23 // YES Uses exceptions
25 // //////////////////////////////////////////////////////////////////////////
29 // CDIBSectionLite is DIBSection wrapper class for win32 and WinCE platforms.
30 // This class provides a simple interface to DIBSections including loading,
31 // saving and displaying DIBsections.
33 // Full palette support is provided for Win32 and CE 2.11 and above.
35 // Using CDIBSectionLite :
37 // This class is very simple to use. The bitmap can be set using either SetBitmap()
38 // (which accepts either a Device dependant or device independant bitmap, or a
39 // resource ID) or by using Load(), which allows an image to be loaded from disk.
40 // To display the bitmap simply use Draw or Stretch.
44 // CDIBsection dibsection;
45 // dibsection.Load(_T("image.bmp"));
46 // dibsection.Draw(pDC, CPoint(0,0)); // pDC is of type CDC*
48 // CDIBsection dibsection;
49 // dibsection.SetBitmap(IDB_BITMAP);
50 // dibsection.Draw(pDC, CPoint(0,0)); // pDC is of type CDC*
52 // The CDIBsection API includes many methods to extract information about the
53 // image, as well as palette options for getting and setting the current palette.
55 // Author : Chris Maunder (cmaunder@mail.com)
56 // Date : 12 April 1999
58 // Modified : Kenny Goers (kennyg@magenic.com)
59 // Date : 12 December 2000
60 // Why : Remove all MFC bloat
62 // CDIB.h : header file
65 /////////////////////////////////////////////////////////////////////////////
68 //#define DIBSECTION_NO_DITHER // Disallow dithering via DrawDib functions
69 #define DIBSECTION_NO_MEMDC_REUSE // Disallow the reuse of memory DC's
70 //#define DIBSECTION_NO_PALETTE // Remove palette support
72 // Only provide palette support for non-CE platforms, or for CE 2.11 and above
73 #define DIBSECTION_NO_DITHER // DrawDib not supported on CE
74 #if (_WIN32_WCE < 211)
75 # define DIBSECTION_NO_PALETTE // No palette support on early CE devices
78 #define DS_BITMAP_FILEMARKER ((WORD) ('M' << 8) | 'B') // is always "BM" = 0x4D42
80 /////////////////////////////////////////////////////////////////////////////
83 struct DIBINFO
: public BITMAPINFO
85 RGBQUAD arColors
[255]; // Color table info - adds an extra 255 entries to palette
87 operator LPBITMAPINFO() { return (LPBITMAPINFO
) this; }
88 operator LPBITMAPINFOHEADER() { return &bmiHeader
; }
89 RGBQUAD
* ColorTable() { return bmiColors
; }
92 /////////////////////////////////////////////////////////////////////////////
95 #ifndef DIBSECTION_NO_PALETTE
96 struct PALETTEINFO
: public LOGPALETTE
98 PALETTEENTRY arPalEntries
[255]; // Palette entries
102 palVersion
= (WORD
) 0x300;
104 ::memset(palPalEntry
, 0, 256*sizeof(PALETTEENTRY
));
107 operator LPLOGPALETTE() { return (LPLOGPALETTE
) this; }
108 operator LPPALETTEENTRY() { return (LPPALETTEENTRY
) (palPalEntry
); }
110 #endif // DIBSECTION_NO_PALETTE
113 /////////////////////////////////////////////////////////////////////////////
125 static int BytesPerLine(int nWidth
, int nBitsPerPixel
);
126 static int NumColorEntries(int nBitsPerPixel
, int nCompression
);
128 static RGBQUAD ms_StdColors
[];
129 #ifndef DIBSECTION_NO_PALETTE
130 static BOOL
UsesPalette(HDC hDC
)
131 { return (GetDeviceCaps(hDC
, RASTERCAPS
) & RC_PALETTE
); }
132 static BOOL
CreateHalftonePalette(HPALETTE palette
, int nNumColors
);
133 #endif // DIBSECTION_NO_PALETTE
137 HBITMAP
GetSafeHandle() const { return (this)? m_hBitmap
: NULL
; }
138 operator HBITMAP() const { return GetSafeHandle(); }
139 void GetSize(SIZE
& size
) const { size
.cx
= GetWidth(); size
.cy
= GetHeight(); }
140 int GetHeight() const { return m_DIBinfo
.bmiHeader
.biHeight
; }
141 int GetWidth() const { return m_DIBinfo
.bmiHeader
.biWidth
; }
142 int GetPlanes() const { return m_DIBinfo
.bmiHeader
.biPlanes
; }
143 int GetBitCount() const { return m_DIBinfo
.bmiHeader
.biBitCount
; }
144 LPVOID
GetDIBits() { return m_ppvBits
; }
145 LPBITMAPINFO
GetBitmapInfo() { return (BITMAPINFO
*) m_DIBinfo
; }
146 DWORD
GetImageSize() const { return m_DIBinfo
.bmiHeader
.biSizeImage
; }
147 LPBITMAPINFOHEADER
GetBitmapInfoHeader() { return (BITMAPINFOHEADER
*) m_DIBinfo
; }
149 // Operations (Palette)
151 LPRGBQUAD
GetColorTable() { return m_DIBinfo
.ColorTable(); }
152 BOOL
SetColorTable(UINT nNumColors
, RGBQUAD
*pColors
);
153 int GetColorTableSize() { return m_iColorTableSize
; }
154 #ifndef DIBSECTION_NO_PALETTE
155 HPALETTE
GetPalette() { return m_hPal
; }
156 BOOL
SetPalette(HPALETTE pPalette
);
157 BOOL
SetLogPalette(LOGPALETTE
* pLogPalette
);
158 #endif // DIBSECTION_NO_PALETTE
160 // Operations (Setting the bitmap)
162 BOOL
SetBitmap(UINT nIDResource
, HINSTANCE hInst
= NULL
);
163 BOOL
SetBitmap(LPCTSTR lpszResourceName
, HINSTANCE hInst
= NULL
);
164 BOOL
SetBitmap(HBITMAP hBitmap
, HPALETTE hPal
= NULL
);
165 BOOL
SetBitmap(LPBITMAPINFO lpBitmapInfo
, LPVOID lpBits
);
167 BOOL
Load(LPCTSTR lpszFileName
);
168 BOOL
Save(LPCTSTR lpszFileName
);
169 BOOL
Copy(CeDIB
& Bitmap
);
171 // Operations (Display)
173 BOOL
Draw(HDC hDC
, POINT
& ptDest
, BOOL bForceBackground
= FALSE
);
174 BOOL
Stretch(HDC hDC
, POINT
& ptDest
, SIZE
& size
, BOOL bForceBackground
= FALSE
);
176 HDC
GetMemoryDC(HDC hDC
= NULL
, BOOL bSelectPalette
= TRUE
);
177 BOOL
ReleaseMemoryDC(BOOL bForceRelease
= FALSE
);
186 #ifndef DIBSECTION_NO_PALETTE
187 BOOL
CreatePalette();
188 BOOL
FillDIBColorTable(UINT nNumColors
, RGBQUAD
*pRGB
);
189 #endif // DIBSECTION_NO_PALETTE
190 UINT
GetColorTableEntries(HDC hdc
, HBITMAP hBitmap
);
193 HBITMAP m_hBitmap
; // Handle to DIBSECTION
194 DIBINFO m_DIBinfo
; // Bitmap header & color table info
195 VOID
*m_ppvBits
; // Pointer to bitmap bits
196 UINT m_iColorDataType
; // color data type (palette or RGB values)
197 UINT m_iColorTableSize
; // Size of color table
199 HDC m_hMemDC
; // Memory DC for drawing on bitmap
201 #ifndef DIBSECTION_NO_MEMDC_REUSE
202 BOOL m_bReuseMemDC
; // Reeuse the memory DC? (Quicker, but not fully tested)
205 #ifndef DIBSECTION_NO_PALETTE
206 HPALETTE m_hPal
; // Color palette
208 #endif // DIBSECTION_NO_PALETTE
211 HBITMAP m_hOldBitmap
; // Storage for previous bitmap in Memory DC
214 /////////////////////////////////////////////////////////////////////////////
216 //{{AFX_INSERT_LOCATION}}
217 // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
219 #endif // !defined(AFX_CeDIB_H__35D9F3D4_B960_11D2_A981_2C4476000000__INCLUDED_)