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 // same as ctor but with return value
39 bool Create(int width
, int height
, int depth
);
41 // dtor is not virtual, this class is not meant to be used polymorphically
44 if ( m_handle
&& !::DeleteObject(m_handle
) )
46 wxLogLastError(wxT("DeleteObject(hDIB)"));
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
; }
62 // return true if DIB was successfully created, false otherwise
63 bool IsOk() const { return m_handle
!= 0; }
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
; }
70 // get the number of bits per pixel, or depth
71 int GetDepth() const { DoGetObject(); return m_depth
; }
74 HBITMAP
GetHandle() const { return m_handle
; }
76 // get raw pointer to bitmap bits, you should know what you do if you
78 void *GetData() const { DoGetObject(); return m_data
; }
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
); }
89 // same as the above ctor but with the return code
90 bool Create(const wxImage
& image
);
92 // create wxImage having the same data as this DIB
93 wxImage
ConvertToImage() const;
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
)
105 return ((width
*depth
+ 31) & ~31) >> 3;
109 // common part of all ctors
121 // the DIB section handle, 0 if invalid
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
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;
135 // pointer to DIB bits, may be NULL
138 // size and depth of the image
144 // DIBs can't be copied
146 wxDIB
& operator=(const wxDIB
&);
150 // ----------------------------------------------------------------------------
151 // Functions for working with DIBs
152 // ----------------------------------------------------------------------------
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!
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)
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
);
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
);
170 // the rest is defined in dib.cpp
172 // Save (device dependent) wxBitmap as a DIB
173 bool wxSaveBitmap(wxChar
*filename
, wxBitmap
*bitmap
, wxPalette
*colourmap
= NULL
);
175 // Load device independent bitmap into device dependent bitmap
176 wxBitmap
*wxLoadBitmap(wxChar
*filename
, wxPalette
**colourmap
= NULL
);
178 // Load into existing bitmap;
179 bool wxLoadIntoBitmap(wxChar
*filename
, wxBitmap
*bitmap
, wxPalette
**pal
= NULL
);
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
);
187 #endif // _WX_MSW_DIB_H_