1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBitmap class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "bitmap.h"
19 #include "wx/palette.h"
22 class WXDLLEXPORT wxBitmap
;
23 class wxBitmapRefData
;
24 class WXDLLEXPORT wxBitmapHandler
;
25 class WXDLLEXPORT wxControl
;
26 class WXDLLEXPORT wxCursor
;
27 class WXDLLEXPORT wxDC
;
28 class WXDLLEXPORT wxIcon
;
29 class WXDLLEXPORT wxImage
;
30 class WXDLLEXPORT wxPixelDataBase
;
32 // A mask is a bitmap used for drawing bitmaps
33 // Internally it is stored as a 8 bit deep memory chunk, 0 = black means the source will be drawn
34 // 255 = white means the source will not be drawn, no other values will be present
35 // 8 bit is chosen only for performance reasons, note also that this is the inverse value range
36 // from alpha, where 0 = invisible , 255 = fully drawn
38 class WXDLLEXPORT wxMask
: public wxObject
40 DECLARE_DYNAMIC_CLASS(wxMask
)
41 DECLARE_NO_COPY_CLASS(wxMask
)
46 // Construct a mask from a bitmap and a colour indicating
47 // the transparent area
48 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
50 // Construct a mask from a mono bitmap (black meaning show pixels, white meaning transparent)
51 wxMask(const wxBitmap
& bitmap
);
53 // implementation helper only : construct a mask from a 8 bit memory buffer
54 wxMask(const wxMemoryBuffer
& buf
, int width
, int height
, int bytesPerRow
) ;
58 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
59 bool Create(const wxBitmap
& bitmap
);
60 bool Create(const wxMemoryBuffer
& buf
, int width
, int height
, int bytesPerRow
) ;
62 // Implementation below
67 void* GetRawAccess() const;
68 int GetBytesPerRow() const { return m_bytesPerRow
; }
69 // renders/updates native representation when necessary
70 void RealizeNative() ;
72 WXHBITMAP
GetHBITMAP() const ;
76 wxMemoryBuffer m_memBuf
;
81 WXHBITMAP m_maskBitmap
;
85 class WXDLLEXPORT wxBitmapHandler
: public wxBitmapHandlerBase
89 virtual ~wxBitmapHandler();
91 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
= 1);
92 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
93 int desiredWidth
, int desiredHeight
);
94 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
= NULL
);
97 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
100 #define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
102 class WXDLLEXPORT wxBitmap
: public wxBitmapBase
104 DECLARE_DYNAMIC_CLASS(wxBitmap
)
106 friend class WXDLLEXPORT wxBitmapHandler
;
109 wxBitmap(); // Platform-specific
112 wxBitmap(const wxBitmap
& bitmap
)
118 // Initialize with raw data.
119 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
121 // Initialize with XPM data
122 bool CreateFromXpm(const char **bits
);
123 wxBitmap(const char **bits
);
124 wxBitmap(char **bits
);
126 // Load a file or resource
127 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_PICT_RESOURCE
);
129 // Constructor for generalised creation from data
130 wxBitmap(void *data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
132 // If depth is omitted, will create a bitmap compatible with the display
133 wxBitmap(int width
, int height
, int depth
= -1);
135 // Convert from wxImage:
136 wxBitmap(const wxImage
& image
, int depth
= -1);
138 // Convert from wxIcon
139 wxBitmap(const wxIcon
& icon
) { CopyFromIcon(icon
); }
143 wxImage
ConvertToImage() const;
145 // get the given part of bitmap
146 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
148 virtual bool Create(int width
, int height
, int depth
= -1);
149 virtual bool Create(void *data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
150 // virtual bool Create( WXHICON icon) ;
151 virtual bool LoadFile(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_BMP_RESOURCE
);
152 virtual bool SaveFile(const wxString
& name
, wxBitmapType type
, const wxPalette
*cmap
= NULL
) const;
154 wxBitmapRefData
*GetBitmapData() const
155 { return (wxBitmapRefData
*)m_refData
; }
157 // copies the contents and mask of the given (colour) icon to the bitmap
158 virtual bool CopyFromIcon(const wxIcon
& icon
);
161 int GetWidth() const;
162 int GetHeight() const;
163 int GetDepth() const;
164 void SetWidth(int w
);
165 void SetHeight(int h
);
166 void SetDepth(int d
);
167 void SetOk(bool isOk
);
169 #if WXWIN_COMPATIBILITY_2_4
170 // these functions do nothing and are only there for backwards
172 wxDEPRECATED( int GetQuality() const );
173 wxDEPRECATED( void SetQuality(int quality
) );
174 #endif // WXWIN_COMPATIBILITY_2_4
177 wxPalette
* GetPalette() const;
178 void SetPalette(const wxPalette
& palette
);
179 #endif // wxUSE_PALETTE
181 wxMask
*GetMask() const;
182 void SetMask(wxMask
*mask
) ;
184 inline wxBitmap
& operator = (const wxBitmap
& bitmap
) { if (*this == bitmap
) return (*this); Ref(bitmap
); return *this; }
185 inline bool operator == (const wxBitmap
& bitmap
) const { return m_refData
== bitmap
.m_refData
; }
186 inline bool operator != (const wxBitmap
& bitmap
) const { return m_refData
!= bitmap
.m_refData
; }
188 static void InitStandardHandlers();
190 // raw bitmap access support functions, for internal use only
191 void *GetRawData(wxPixelDataBase
& data
, int bpp
);
192 void UngetRawData(wxPixelDataBase
& data
);
194 // these functions are internal and shouldn't be used, they risk to
195 // disappear in the future
196 bool HasAlpha() const;
199 // returns the 'native' implementation, a GWorldPtr for the content and one for the mask
200 WXHBITMAP
GetHBITMAP( WXHBITMAP
* mask
= NULL
) const;
203 // returns a CGImageRef which must released after usage with CGImageRelease
204 WXCGIMAGEREF
CGImageCreate() const ;
206 // get read only access to the underlying buffer
207 void *GetRawAccess() const ;
208 // brackets to the underlying OS structure for read/write access
209 // makes sure that no cached images will be constructed until terminated
210 void *BeginRawAccess() ;
211 void EndRawAccess() ;