1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBitmap class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #include "wx/palette.h"
18 class WXDLLEXPORT wxBitmap
;
19 class wxBitmapRefData
;
20 class WXDLLEXPORT wxBitmapHandler
;
21 class WXDLLEXPORT wxControl
;
22 class WXDLLEXPORT wxCursor
;
23 class WXDLLEXPORT wxDC
;
24 class WXDLLEXPORT wxIcon
;
25 class WXDLLEXPORT wxImage
;
26 class WXDLLEXPORT wxPixelDataBase
;
28 // A mask is a bitmap used for drawing bitmaps
29 // Internally it is stored as a 8 bit deep memory chunk, 0 = black means the source will be drawn
30 // 255 = white means the source will not be drawn, no other values will be present
31 // 8 bit is chosen only for performance reasons, note also that this is the inverse value range
32 // from alpha, where 0 = invisible , 255 = fully drawn
34 class WXDLLEXPORT wxMask
: public wxObject
36 DECLARE_DYNAMIC_CLASS(wxMask
)
37 DECLARE_NO_COPY_CLASS(wxMask
)
42 // Construct a mask from a bitmap and a colour indicating
43 // the transparent area
44 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
46 // Construct a mask from a mono bitmap (black meaning show pixels, white meaning transparent)
47 wxMask(const wxBitmap
& bitmap
);
49 // implementation helper only : construct a mask from a 32 bit memory buffer
50 wxMask(const wxMemoryBuffer
& buf
, int width
, int height
, int bytesPerRow
) ;
54 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
55 bool Create(const wxBitmap
& bitmap
);
56 bool Create(const wxMemoryBuffer
& buf
, int width
, int height
, int bytesPerRow
) ;
58 // Implementation below
63 void* GetRawAccess() const;
64 int GetBytesPerRow() const { return m_bytesPerRow
; }
65 // renders/updates native representation when necessary
66 void RealizeNative() ;
68 WXHBITMAP
GetHBITMAP() const ;
72 wxMemoryBuffer m_memBuf
;
77 WXHBITMAP m_maskBitmap
;
81 class WXDLLEXPORT wxBitmapHandler
: public wxBitmapHandlerBase
85 virtual ~wxBitmapHandler();
87 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
= 1);
88 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
89 int desiredWidth
, int desiredHeight
);
90 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
= NULL
);
93 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
96 #define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
98 class WXDLLEXPORT wxBitmap
: public wxBitmapBase
100 DECLARE_DYNAMIC_CLASS(wxBitmap
)
102 friend class WXDLLEXPORT wxBitmapHandler
;
105 wxBitmap(); // Platform-specific
107 // Initialize with raw data.
108 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
110 // Initialize with XPM data
111 bool CreateFromXpm(const char **bits
);
112 wxBitmap(const char **bits
);
113 wxBitmap(char **bits
);
115 // Load a file or resource
116 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_PICT_RESOURCE
);
118 // Constructor for generalised creation from data
119 wxBitmap(void *data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
121 // If depth is omitted, will create a bitmap compatible with the display
122 wxBitmap(int width
, int height
, int depth
= -1);
124 // Convert from wxImage:
125 wxBitmap(const wxImage
& image
, int depth
= -1);
127 // Convert from wxIcon
128 wxBitmap(const wxIcon
& icon
) { CopyFromIcon(icon
); }
132 wxImage
ConvertToImage() const;
134 // get the given part of bitmap
135 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
137 virtual bool Create(int width
, int height
, int depth
= -1);
138 virtual bool Create(void *data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
139 // virtual bool Create( WXHICON icon) ;
140 virtual bool LoadFile(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_BMP_RESOURCE
);
141 virtual bool SaveFile(const wxString
& name
, wxBitmapType type
, const wxPalette
*cmap
= NULL
) const;
143 wxBitmapRefData
*GetBitmapData() const
144 { return (wxBitmapRefData
*)m_refData
; }
146 // copies the contents and mask of the given (colour) icon to the bitmap
147 virtual bool CopyFromIcon(const wxIcon
& icon
);
150 int GetWidth() const;
151 int GetHeight() const;
152 int GetDepth() const;
153 void SetWidth(int w
);
154 void SetHeight(int h
);
155 void SetDepth(int d
);
156 void SetOk(bool isOk
);
158 #if WXWIN_COMPATIBILITY_2_4
159 // these functions do nothing and are only there for backwards
161 wxDEPRECATED( int GetQuality() const );
162 wxDEPRECATED( void SetQuality(int quality
) );
163 #endif // WXWIN_COMPATIBILITY_2_4
166 wxPalette
* GetPalette() const;
167 void SetPalette(const wxPalette
& palette
);
168 #endif // wxUSE_PALETTE
170 wxMask
*GetMask() const;
171 void SetMask(wxMask
*mask
) ;
173 inline bool operator == (const wxBitmap
& bitmap
) const { return m_refData
== bitmap
.m_refData
; }
174 inline bool operator != (const wxBitmap
& bitmap
) const { return m_refData
!= bitmap
.m_refData
; }
176 static void InitStandardHandlers();
178 // raw bitmap access support functions, for internal use only
179 void *GetRawData(wxPixelDataBase
& data
, int bpp
);
180 void UngetRawData(wxPixelDataBase
& data
);
182 // these functions are internal and shouldn't be used, they risk to
183 // disappear in the future
184 bool HasAlpha() const;
187 // returns the 'native' implementation, a GWorldPtr for the content and one for the mask
188 WXHBITMAP
GetHBITMAP( WXHBITMAP
* mask
= NULL
) const;
191 // returns a CGImageRef which must released after usage with CGImageRelease
192 WXCGIMAGEREF
CGImageCreate() const ;
194 // get read only access to the underlying buffer
195 void *GetRawAccess() const ;
196 // brackets to the underlying OS structure for read/write access
197 // makes sure that no cached images will be constructed until terminated
198 void *BeginRawAccess() ;
199 void EndRawAccess() ;