1 ////////////////////////////////////////////////////////////////////////////
4 // Author: William Osborne
8 // Copyright: (c) William Osborne
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "bitmap.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
37 #include "wx/palette.h"
38 #include "wx/dcmemory.h"
39 #include "wx/bitmap.h"
46 #include "wx/palmos/dib.h"
50 #include "wx/xpmdecod.h"
52 #ifdef wxHAVE_RAW_BITMAP
53 #include "wx/rawbmp.h"
56 // missing from mingw32 header
58 #define CLR_INVALID ((COLORREF)-1)
59 #endif // no CLR_INVALID
61 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
65 class WXDLLEXPORT wxBitmapRefData
: public wxGDIImageRefData
69 virtual ~wxBitmapRefData() { Free(); }
73 // set the mask object to use as the mask, we take ownership of it
74 void SetMask(wxMask
*mask
)
81 wxMask
*GetMask() const { return m_bitmapMask
; }
85 wxPalette m_bitmapPalette
;
86 #endif // wxUSE_PALETTE
101 wxMask
*m_bitmapMask
;
103 DECLARE_NO_COPY_CLASS(wxBitmapRefData
)
106 // ----------------------------------------------------------------------------
108 // ----------------------------------------------------------------------------
110 IMPLEMENT_DYNAMIC_CLASS(wxBitmap
, wxGDIObject
)
111 IMPLEMENT_DYNAMIC_CLASS(wxMask
, wxObject
)
113 IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler
, wxObject
)
115 // ============================================================================
117 // ============================================================================
119 // ----------------------------------------------------------------------------
121 // ----------------------------------------------------------------------------
124 #define NEVER_USE_DIB
126 static inline bool wxShouldCreateDIB(int w
, int h
, int d
, WXHDC hdc
)
128 // here is the logic:
130 // (a) if hdc is specified, the caller explicitly wants DDB
131 // (b) otherwise, create a DIB if depth >= 24 (we don't support 16bpp
132 // or less DIBs anyhow)
133 // (c) finally, create DIBs under Win9x even if the depth hasn't been
134 // explicitly specified but the current display depth is 24 or
135 // more and the image is "big", i.e. > 16Mb which is the
136 // theoretical limit for DDBs under Win9x
138 // consequences (all of which seem to make sense):
140 // (i) by default, DDBs are created (depth == -1 usually)
141 // (ii) DIBs can be created by explicitly specifying the depth
142 // (iii) using a DC always forces creating a DDB
146 wxDIB::GetLineSize(w
, wxDisplayDepth())*h
> 16*1024*1024));
149 #define SOMETIMES_USE_DIB
150 #endif // different DIB usage scenarious
152 // ----------------------------------------------------------------------------
154 // ----------------------------------------------------------------------------
156 wxBitmapRefData::wxBitmapRefData()
159 m_selectedInto
= NULL
;
163 m_hBitmap
= (WXHBITMAP
) NULL
;
172 void wxBitmapRefData::Free()
176 // ----------------------------------------------------------------------------
178 // ----------------------------------------------------------------------------
180 // this function should be called from all wxBitmap ctors
181 void wxBitmap::Init()
185 wxGDIImageRefData
*wxBitmap::CreateData() const
190 bool wxBitmap::CopyFromCursor(const wxCursor
& cursor
)
195 bool wxBitmap::CopyFromIcon(const wxIcon
& icon
)
200 #ifndef NEVER_USE_DIB
202 bool wxBitmap::CopyFromDIB(const wxDIB
& dib
)
207 #endif // NEVER_USE_DIB
209 wxBitmap::~wxBitmap()
213 wxBitmap::wxBitmap(const char bits
[], int width
, int height
, int depth
)
218 // Create from XPM data
219 #if wxUSE_IMAGE && wxUSE_XPM
220 bool wxBitmap::CreateFromXpm(const char **data
)
222 bool wxBitmap::CreateFromXpm(const char **WXUNUSED(data
))
228 wxBitmap::wxBitmap(int w
, int h
, int d
)
232 wxBitmap::wxBitmap(int w
, int h
, const wxDC
& dc
)
236 wxBitmap::wxBitmap(void *data
, long type
, int width
, int height
, int depth
)
240 wxBitmap::wxBitmap(const wxString
& filename
, wxBitmapType type
)
244 bool wxBitmap::Create(int width
, int height
, int depth
)
249 bool wxBitmap::Create(int width
, int height
, const wxDC
& dc
)
254 bool wxBitmap::DoCreate(int w
, int h
, int d
, WXHDC hdc
)
261 // ----------------------------------------------------------------------------
262 // wxImage to/from conversions
263 // ----------------------------------------------------------------------------
267 bool wxBitmap::CreateFromImage(const wxImage
& image
, int depth
)
272 bool wxBitmap::CreateFromImage(const wxImage
& image
, const wxDC
& dc
)
277 bool wxBitmap::CreateFromImage(const wxImage
& image
, int depth
, WXHDC hdc
)
282 wxImage
wxBitmap::ConvertToImage() const
288 #endif // wxUSE_WXDIB
290 #endif // wxUSE_IMAGE
292 // ----------------------------------------------------------------------------
293 // loading and saving bitmaps
294 // ----------------------------------------------------------------------------
296 bool wxBitmap::LoadFile(const wxString
& filename
, long type
)
301 bool wxBitmap::Create(void *data
, long type
, int width
, int height
, int depth
)
306 bool wxBitmap::SaveFile(const wxString
& filename
,
308 const wxPalette
*palette
)
313 // ----------------------------------------------------------------------------
314 // sub bitmap extraction
315 // ----------------------------------------------------------------------------
317 wxBitmap
wxBitmap::GetSubBitmap( const wxRect
& rect
) const
319 wxBitmap
ret( 0, 0 );
323 // ----------------------------------------------------------------------------
324 // wxBitmap accessors
325 // ----------------------------------------------------------------------------
328 wxPalette
* wxBitmap::GetPalette() const
330 return (wxPalette
*) NULL
;
334 wxMask
*wxBitmap::GetMask() const
336 return (wxMask
*) NULL
;
341 wxDC
*wxBitmap::GetSelectedInto() const
343 return (wxDC
*) NULL
;
348 void wxBitmap::UseAlpha()
352 bool wxBitmap::HasAlpha() const
357 // ----------------------------------------------------------------------------
359 // ----------------------------------------------------------------------------
363 void wxBitmap::SetSelectedInto(wxDC
*dc
)
371 void wxBitmap::SetPalette(const wxPalette
& palette
)
375 #endif // wxUSE_PALETTE
377 void wxBitmap::SetMask(wxMask
*mask
)
381 // ----------------------------------------------------------------------------
382 // raw bitmap access support
383 // ----------------------------------------------------------------------------
385 #ifdef wxHAVE_RAW_BITMAP
386 void *wxBitmap::GetRawData(wxPixelDataBase
& data
, int bpp
)
391 void wxBitmap::UngetRawData(wxPixelDataBase
& dataBase
)
395 #endif // #ifdef wxHAVE_RAW_BITMAP
397 // ----------------------------------------------------------------------------
399 // ----------------------------------------------------------------------------
406 // Construct a mask from a bitmap and a colour indicating
407 // the transparent area
408 wxMask::wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
)
412 // Construct a mask from a bitmap and a palette index indicating
413 // the transparent area
414 wxMask::wxMask(const wxBitmap
& bitmap
, int paletteIndex
)
418 // Construct a mask from a mono bitmap (copies the bitmap).
419 wxMask::wxMask(const wxBitmap
& bitmap
)
427 // Create a mask from a mono bitmap (copies the bitmap).
428 bool wxMask::Create(const wxBitmap
& bitmap
)
433 // Create a mask from a bitmap and a palette index indicating
434 // the transparent area
435 bool wxMask::Create(const wxBitmap
& bitmap
, int paletteIndex
)
440 // Create a mask from a bitmap and a colour indicating
441 // the transparent area
442 bool wxMask::Create(const wxBitmap
& bitmap
, const wxColour
& colour
)
447 // ----------------------------------------------------------------------------
449 // ----------------------------------------------------------------------------
451 bool wxBitmapHandler::Create(wxGDIImage
*image
,
454 int width
, int height
, int depth
)
459 bool wxBitmapHandler::Load(wxGDIImage
*image
,
460 const wxString
& name
,
462 int width
, int height
)
467 bool wxBitmapHandler::Save(wxGDIImage
*image
,
468 const wxString
& name
,
474 bool wxBitmapHandler::Create(wxBitmap
*WXUNUSED(bitmap
),
475 void *WXUNUSED(data
),
478 int WXUNUSED(height
),
484 bool wxBitmapHandler::LoadFile(wxBitmap
*WXUNUSED(bitmap
),
485 const wxString
& WXUNUSED(name
),
487 int WXUNUSED(desiredWidth
),
488 int WXUNUSED(desiredHeight
))
493 bool wxBitmapHandler::SaveFile(wxBitmap
*WXUNUSED(bitmap
),
494 const wxString
& WXUNUSED(name
),
496 const wxPalette
*WXUNUSED(palette
))