1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDIB class representing Win32 device independent bitmaps
4 // Author: Vadim Zeitlin
6 // Created: 03.03.03 (replaces the old file with the same name)
8 // Copyright: (c) 1997-2003 wxWindows team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_MSW_DIB_H_
13 #define _WX_MSW_DIB_H_
15 class WXDLLEXPORT wxBitmap
;
16 class WXDLLEXPORT wxPalette
;
18 #include "wx/msw/private.h"
20 // ----------------------------------------------------------------------------
21 // wxDIB: represents a DIB section
22 // ----------------------------------------------------------------------------
24 class WXDLLEXPORT wxDIB
30 // create an uninitialized DIB with the given width, height and depth (only
31 // 24 and 32 bpp DIBs are currently supported)
33 // after using this ctor, GetData() and GetHandle() may be used if IsOk()
35 wxDIB(int width
, int height
, int depth
)
36 { Init(); (void)Create(width
, height
, depth
); }
38 // load a DIB from file (any depth is supoprted here unlike above)
40 // as above, use IsOk() to see if the bitmap was loaded successfully
41 wxDIB(const wxString
& filename
)
42 { Init(); (void)Load(filename
); }
44 // same as the corresponding ctors but with return value
45 bool Create(int width
, int height
, int depth
);
46 bool Load(const wxString
& filename
);
48 // dtor is not virtual, this class is not meant to be used polymorphically
55 // create a bitmap compatiblr with the given HDC (or screen by default) and
56 // return its handle, the caller is responsible for freeing it (using
58 HBITMAP
CreateDDB(HDC hdc
= NULL
) const;
60 // get the handle from the DIB and reset it, i.e. this object won't destroy
61 // the DIB after this (but the caller should do it)
62 HBITMAP
Detach() { HBITMAP hbmp
= m_handle
; m_handle
= 0; return hbmp
; }
65 // create a palette for this DIB (always a trivial/default one for 24bpp)
66 wxPalette
*CreatePalette() const;
67 #endif // wxUSE_PALETTE
73 // return true if DIB was successfully created, false otherwise
74 bool IsOk() const { return m_handle
!= 0; }
76 // get the bitmap size
77 wxSize
GetSize() const { DoGetObject(); return wxSize(m_width
, m_height
); }
78 int GetWidth() const { DoGetObject(); return m_width
; }
79 int GetHeight() const { DoGetObject(); return m_height
; }
81 // get the number of bits per pixel, or depth
82 int GetDepth() const { DoGetObject(); return m_depth
; }
85 HBITMAP
GetHandle() const { return m_handle
; }
87 // get raw pointer to bitmap bits, you should know what you do if you
89 void *GetData() const { DoGetObject(); return m_data
; }
96 // create a DIB from the given image, the DIB will be either 24 or 32 (if
97 // the image has alpha channel) bpp
98 wxDIB(const wxImage
& image
) { Init(); (void)Create(image
); }
100 // same as the above ctor but with the return code
101 bool Create(const wxImage
& image
);
103 // create wxImage having the same data as this DIB
104 wxImage
ConvertToImage() const;
105 #endif // wxUSE_IMAGE
111 // return the size of one line in a DIB with given width and depth: the
112 // point here is that as the scan lines need to be DWORD aligned so we may
113 // need to add some padding
114 static unsigned long GetLineSize(int width
, int depth
)
116 return ((width
*depth
+ 31) & ~31) >> 3;
120 // common part of all ctors
137 if ( !::DeleteObject(m_handle
) )
139 wxLogLastError(wxT("DeleteObject(hDIB)"));
146 // the DIB section handle, 0 if invalid
149 // NB: we could store only m_handle and not any of the other fields as
150 // we may always retrieve them from it using ::GetObject(), but we
151 // decide to still store them for efficiency concerns -- however if we
152 // don't have them from the very beginning (e.g. DIB constructed from a
153 // bitmap), we only retrieve them when necessary and so these fields
154 // should *never* be accessed directly, even from inside wxDIB code
156 // function which must be called before accessing any members and which
157 // gets their values from m_handle, if not done yet
158 void DoGetObject() const;
160 // pointer to DIB bits, may be NULL
163 // size and depth of the image
169 // DIBs can't be copied
171 wxDIB
& operator=(const wxDIB
&);
174 // ----------------------------------------------------------------------------
175 // inline functions implementation
176 // ----------------------------------------------------------------------------
178 inline wxDIB::~wxDIB()
183 // ----------------------------------------------------------------------------
184 // Functions for working with DIBs
185 // ----------------------------------------------------------------------------
187 // WARNING: these functions are private to wxWindows and shouldn't be used
188 // by the user code, they risk to disappear in the next versions!
190 // VZ: we have 3 different sets of functions: from bitmap.cpp (wxCreateDIB and
191 // wxFreeDIB), from dib.cpp and from dataobj.cpp - surely there is some
192 // redundancy between them? (FIXME)
194 // defined in ole/dataobj.cpp
195 extern WXDLLEXPORT
size_t wxConvertBitmapToDIB(LPBITMAPINFO pbi
, const wxBitmap
& bitmap
);
196 extern WXDLLEXPORT wxBitmap
wxConvertDIBToBitmap(const LPBITMAPINFO pbi
);
198 // the rest is defined in dib.cpp
200 // Save (device dependent) wxBitmap as a DIB
201 bool wxSaveBitmap(wxChar
*filename
, wxBitmap
*bitmap
, wxPalette
*palette
= NULL
);
203 // Load device independent bitmap into device dependent bitmap
204 wxBitmap
*wxLoadBitmap(wxChar
*filename
, wxPalette
**palette
= NULL
);
206 // Load into existing bitmap;
207 bool wxLoadIntoBitmap(wxChar
*filename
, wxBitmap
*bitmap
, wxPalette
**pal
= NULL
);
209 HANDLE
wxBitmapToDIB (HBITMAP hBitmap
, HPALETTE hPal
);
210 bool wxReadDIB(LPTSTR lpFileName
, HBITMAP
*bitmap
, HPALETTE
*palette
);
211 HANDLE
wxReadDIB2(LPTSTR lpFileName
);
212 LPSTR
wxFindDIBBits (LPSTR lpbi
);
213 HPALETTE
wxMakeDIBPalette(LPBITMAPINFOHEADER lpInfo
);
215 #endif // _WX_MSW_DIB_H_