]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/dib.h
Removed erroneous copyright names and corrected licence spelling
[wxWidgets.git] / include / wx / msw / dib.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/dib.h
3 // Purpose: wxDIB class representing Win32 device independent bitmaps
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 03.03.03 (replaces the old file with the same name)
7 // RCS-ID: $Id$
8 // Copyright: (c) 1997-2003 wxWindows team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_MSW_DIB_H_
13 #define _WX_MSW_DIB_H_
14
15 class WXDLLEXPORT wxBitmap;
16 class WXDLLEXPORT wxPalette;
17
18 #include "wx/msw/private.h"
19
20 // ----------------------------------------------------------------------------
21 // wxDIB: represents a DIB section
22 // ----------------------------------------------------------------------------
23
24 class WXDLLEXPORT wxDIB
25 {
26 public:
27 // ctors and such
28 // --------------
29
30 // create an uninitialized DIB with the given width, height and depth (only
31 // 24 and 32 bpp DIBs are currently supported)
32 //
33 // after using this ctor, GetData() and GetHandle() may be used if IsOk()
34 // returns true
35 wxDIB(int width, int height, int depth)
36 { Init(); (void)Create(width, height, depth); }
37
38 // same as ctor but with return value
39 bool Create(int width, int height, int depth);
40
41 // dtor is not virtual, this class is not meant to be used polymorphically
42 ~wxDIB()
43 {
44 if ( m_handle && !::DeleteObject(m_handle) )
45 {
46 wxLogLastError(wxT("DeleteObject(hDIB)"));
47 }
48 }
49
50
51 // operations
52 // ----------
53
54 // get the handle from the DIB and reset it, i.e. this object won't destroy
55 // the DIB after this (but the caller should do it)
56 HBITMAP Detach() { HBITMAP hbmp = m_handle; m_handle = 0; return hbmp; }
57
58
59 // accessors
60 // ---------
61
62 // return true if DIB was successfully created, false otherwise
63 bool IsOk() const { return m_handle != 0; }
64
65 // get the bitmap size
66 wxSize GetSize() const { DoGetObject(); return wxSize(m_width, m_height); }
67 int GetWidth() const { DoGetObject(); return m_width; }
68 int GetHeight() const { DoGetObject(); return m_height; }
69
70 // get the number of bits per pixel, or depth
71 int GetDepth() const { DoGetObject(); return m_depth; }
72
73 // get the DIB handle
74 HBITMAP GetHandle() const { return m_handle; }
75
76 // get raw pointer to bitmap bits, you should know what you do if you
77 // decide to use it
78 void *GetData() const { DoGetObject(); return m_data; }
79
80
81 // wxImage conversion
82 // ------------------
83
84 #if wxUSE_IMAGE
85 // create a DIB from the given image, the DIB will be either 24 or 32 (if
86 // the image has alpha channel) bpp
87 wxDIB(const wxImage& image) { Init(); (void)Create(image); }
88
89 // same as the above ctor but with the return code
90 bool Create(const wxImage& image);
91
92 // create wxImage having the same data as this DIB
93 wxImage ConvertToImage() const;
94 #endif // wxUSE_IMAGE
95
96
97 // helper functions
98 // ----------------
99
100 // return the size of one line in a DIB with given width and depth: the
101 // point here is that as the scan lines need to be DWORD aligned so we may
102 // need to add some padding
103 static unsigned long GetLineSize(int width, int depth)
104 {
105 return ((width*depth + 31) & ~31) >> 3;
106 }
107
108 private:
109 // common part of all ctors
110 void Init()
111 {
112 m_handle = 0;
113
114 m_data = NULL;
115
116 m_width =
117 m_height =
118 m_depth = 0;
119 }
120
121 // the DIB section handle, 0 if invalid
122 HBITMAP m_handle;
123
124 // NB: we could store only m_handle and not any of the other fields as
125 // we may always retrieve them from it using ::GetObject(), but we
126 // decide to still store them for efficiency concerns -- however if we
127 // don't have them from the very beginning (e.g. DIB constructed from a
128 // bitmap), we only retrieve them when necessary and so these fields
129 // should *never* be accessed directly, even from inside wxDIB code
130
131 // function which must be called before accessing any members and which
132 // gets their values from m_handle, if not done yet
133 void DoGetObject() const;
134
135 // pointer to DIB bits, may be NULL
136 void *m_data;
137
138 // size and depth of the image
139 int m_width,
140 m_height,
141 m_depth;
142
143
144 // DIBs can't be copied
145 wxDIB(const wxDIB&);
146 wxDIB& operator=(const wxDIB&);
147 };
148
149
150 // ----------------------------------------------------------------------------
151 // Functions for working with DIBs
152 // ----------------------------------------------------------------------------
153
154 // WARNING: these functions are private to wxWindows and shouldn't be used
155 // by the user code, they risk to disappear in the next versions!
156
157 // VZ: we have 3 different sets of functions: from bitmap.cpp (wxCreateDIB and
158 // wxFreeDIB), from dib.cpp and from dataobj.cpp - surely there is some
159 // redundancy between them? (FIXME)
160
161 // defined in bitmap.cpp
162 extern bool wxCreateDIB(long xSize, long ySize, long bitsPerPixel,
163 HPALETTE hPal, LPBITMAPINFO* lpDIBHeader);
164 extern void wxFreeDIB(LPBITMAPINFO lpDIBHeader);
165
166 // defined in ole/dataobj.cpp
167 extern WXDLLEXPORT size_t wxConvertBitmapToDIB(LPBITMAPINFO pbi, const wxBitmap& bitmap);
168 extern WXDLLEXPORT wxBitmap wxConvertDIBToBitmap(const LPBITMAPINFO pbi);
169
170 // the rest is defined in dib.cpp
171
172 // Save (device dependent) wxBitmap as a DIB
173 bool wxSaveBitmap(wxChar *filename, wxBitmap *bitmap, wxPalette *colourmap = NULL);
174
175 // Load device independent bitmap into device dependent bitmap
176 wxBitmap *wxLoadBitmap(wxChar *filename, wxPalette **colourmap = NULL);
177
178 // Load into existing bitmap;
179 bool wxLoadIntoBitmap(wxChar *filename, wxBitmap *bitmap, wxPalette **pal = NULL);
180
181 HANDLE wxBitmapToDIB (HBITMAP hBitmap, HPALETTE hPal);
182 BOOL wxReadDIB(LPTSTR lpFileName, HBITMAP *bitmap, HPALETTE *palette);
183 HANDLE wxReadDIB2(LPTSTR lpFileName);
184 LPSTR wxFindDIBBits (LPSTR lpbi);
185 HPALETTE wxMakeDIBPalette(LPBITMAPINFOHEADER lpInfo);
186
187 #endif // _WX_MSW_DIB_H_
188