Change the translation of the "Help" menu item to "?", so that the menu can be displa...
[reactos.git] / rosapps / smartpdf / baseutils / win_dib.h
1 #ifndef __DIB_h__
2 #define __DIB_h__
3
4 #if _MSC_VER > 1000
5 #pragma once
6 #endif // _MSC_VER > 1000
7
8 // CDIB.h : header file
9 //
10
11 // Copyright © Dundas Software Ltd. 1999, All Rights Reserved
12
13 // //////////////////////////////////////////////////////////////////////////
14
15 // Properties:
16 // NO Abstract class (does not have any objects)
17 // NO Derived from CWnd
18 // NO Is a 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
24
25 // //////////////////////////////////////////////////////////////////////////
26
27 // Desciption :
28
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.
32 //
33 // Full palette support is provided for Win32 and CE 2.11 and above.
34
35 // Using CDIBSectionLite :
36
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.
41 //
42 // eg.
43 //
44 // CDIBsection dibsection;
45 // dibsection.Load(_T("image.bmp"));
46 // dibsection.Draw(pDC, CPoint(0,0)); // pDC is of type CDC*
47 //
48 // CDIBsection dibsection;
49 // dibsection.SetBitmap(IDB_BITMAP);
50 // dibsection.Draw(pDC, CPoint(0,0)); // pDC is of type CDC*
51 //
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.
54 //
55 // Author : Chris Maunder (cmaunder@mail.com)
56 // Date : 12 April 1999
57
58 // Modified : Kenny Goers (kennyg@magenic.com)
59 // Date : 12 December 2000
60 // Why : Remove all MFC bloat
61
62 // CDIB.h : header file
63 //
64
65 /////////////////////////////////////////////////////////////////////////////
66 // defines
67
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
71
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
76 #endif
77
78 #define DS_BITMAP_FILEMARKER ((WORD) ('M' << 8) | 'B') // is always "BM" = 0x4D42
79
80 /////////////////////////////////////////////////////////////////////////////
81 // BITMAPINFO wrapper
82
83 struct DIBINFO : public BITMAPINFO
84 {
85 RGBQUAD arColors[255]; // Color table info - adds an extra 255 entries to palette
86
87 operator LPBITMAPINFO() { return (LPBITMAPINFO) this; }
88 operator LPBITMAPINFOHEADER() { return &bmiHeader; }
89 RGBQUAD* ColorTable() { return bmiColors; }
90 };
91
92 /////////////////////////////////////////////////////////////////////////////
93 // LOGPALETTE wrapper
94
95 #ifndef DIBSECTION_NO_PALETTE
96 struct PALETTEINFO : public LOGPALETTE
97 {
98 PALETTEENTRY arPalEntries[255]; // Palette entries
99
100 PALETTEINFO()
101 {
102 palVersion = (WORD) 0x300;
103 palNumEntries = 0;
104 ::memset(palPalEntry, 0, 256*sizeof(PALETTEENTRY));
105 }
106
107 operator LPLOGPALETTE() { return (LPLOGPALETTE) this; }
108 operator LPPALETTEENTRY() { return (LPPALETTEENTRY) (palPalEntry); }
109 };
110 #endif // DIBSECTION_NO_PALETTE
111
112
113 /////////////////////////////////////////////////////////////////////////////
114 // CeDIB object
115
116 class CeDIB
117 {
118 // Construction
119 public:
120 CeDIB();
121 virtual ~CeDIB();
122
123 // static helpers
124 public:
125 static int BytesPerLine(int nWidth, int nBitsPerPixel);
126 static int NumColorEntries(int nBitsPerPixel, int nCompression);
127
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
134
135 // Attributes
136 public:
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; }
148
149 // Operations (Palette)
150 public:
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
159
160 // Operations (Setting the bitmap)
161 public:
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);
166
167 BOOL Load(LPCTSTR lpszFileName);
168 BOOL Save(LPCTSTR lpszFileName);
169 BOOL Copy(CeDIB& Bitmap);
170
171 // Operations (Display)
172 public:
173 BOOL Draw(HDC hDC, POINT& ptDest, BOOL bForceBackground = FALSE);
174 BOOL Stretch(HDC hDC, POINT& ptDest, SIZE& size, BOOL bForceBackground = FALSE);
175
176 HDC GetMemoryDC(HDC hDC = NULL, BOOL bSelectPalette = TRUE);
177 BOOL ReleaseMemoryDC(BOOL bForceRelease = FALSE);
178
179 // Overrideables
180
181 // Implementation
182 public:
183
184 // Implementation
185 protected:
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);
191
192 protected:
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
198
199 HDC m_hMemDC; // Memory DC for drawing on bitmap
200
201 #ifndef DIBSECTION_NO_MEMDC_REUSE
202 BOOL m_bReuseMemDC; // Reeuse the memory DC? (Quicker, but not fully tested)
203 #endif
204
205 #ifndef DIBSECTION_NO_PALETTE
206 HPALETTE m_hPal; // Color palette
207 HPALETTE m_hOldPal;
208 #endif // DIBSECTION_NO_PALETTE
209
210 private:
211 HBITMAP m_hOldBitmap; // Storage for previous bitmap in Memory DC
212 };
213
214 /////////////////////////////////////////////////////////////////////////////
215
216 //{{AFX_INSERT_LOCATION}}
217 // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
218
219 #endif // !defined(AFX_CeDIB_H__35D9F3D4_B960_11D2_A981_2C4476000000__INCLUDED_)