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
192 bool wxBitmap::CopyFromIconOrCursor(const wxGDIImage
& icon
)
199 bool wxBitmap::CopyFromCursor(const wxCursor
& cursor
)
204 bool wxBitmap::CopyFromIcon(const wxIcon
& icon
)
209 #ifndef NEVER_USE_DIB
211 bool wxBitmap::CopyFromDIB(const wxDIB
& dib
)
216 #endif // NEVER_USE_DIB
218 wxBitmap::~wxBitmap()
222 wxBitmap::wxBitmap(const char bits
[], int width
, int height
, int depth
)
227 // Create from XPM data
228 #if wxUSE_IMAGE && wxUSE_XPM
229 bool wxBitmap::CreateFromXpm(const char **data
)
231 bool wxBitmap::CreateFromXpm(const char **WXUNUSED(data
))
237 wxBitmap::wxBitmap(int w
, int h
, int d
)
241 wxBitmap::wxBitmap(int w
, int h
, const wxDC
& dc
)
245 wxBitmap::wxBitmap(void *data
, long type
, int width
, int height
, int depth
)
249 wxBitmap::wxBitmap(const wxString
& filename
, wxBitmapType type
)
253 bool wxBitmap::Create(int width
, int height
, int depth
)
258 bool wxBitmap::Create(int width
, int height
, const wxDC
& dc
)
263 bool wxBitmap::DoCreate(int w
, int h
, int d
, WXHDC hdc
)
270 // ----------------------------------------------------------------------------
271 // wxImage to/from conversions
272 // ----------------------------------------------------------------------------
276 bool wxBitmap::CreateFromImage(const wxImage
& image
, int depth
)
281 bool wxBitmap::CreateFromImage(const wxImage
& image
, const wxDC
& dc
)
286 bool wxBitmap::CreateFromImage(const wxImage
& image
, int depth
, WXHDC hdc
)
291 wxImage
wxBitmap::ConvertToImage() const
297 #endif // wxUSE_WXDIB
299 #endif // wxUSE_IMAGE
301 // ----------------------------------------------------------------------------
302 // loading and saving bitmaps
303 // ----------------------------------------------------------------------------
305 bool wxBitmap::LoadFile(const wxString
& filename
, long type
)
310 bool wxBitmap::Create(void *data
, long type
, int width
, int height
, int depth
)
315 bool wxBitmap::SaveFile(const wxString
& filename
,
317 const wxPalette
*palette
)
322 // ----------------------------------------------------------------------------
323 // sub bitmap extraction
324 // ----------------------------------------------------------------------------
326 wxBitmap
wxBitmap::GetSubBitmap( const wxRect
& rect
) const
328 wxBitmap
ret( 0, 0 );
332 // ----------------------------------------------------------------------------
333 // wxBitmap accessors
334 // ----------------------------------------------------------------------------
337 wxPalette
* wxBitmap::GetPalette() const
339 return (wxPalette
*) NULL
;
343 wxMask
*wxBitmap::GetMask() const
345 return (wxMask
*) NULL
;
350 wxDC
*wxBitmap::GetSelectedInto() const
352 return (wxDC
*) NULL
;
357 #if WXWIN_COMPATIBILITY_2_4
359 int wxBitmap::GetQuality() const
364 #endif // WXWIN_COMPATIBILITY_2_4
366 void wxBitmap::UseAlpha()
370 bool wxBitmap::HasAlpha() const
375 // ----------------------------------------------------------------------------
377 // ----------------------------------------------------------------------------
381 void wxBitmap::SetSelectedInto(wxDC
*dc
)
389 void wxBitmap::SetPalette(const wxPalette
& palette
)
393 #endif // wxUSE_PALETTE
395 void wxBitmap::SetMask(wxMask
*mask
)
399 #if WXWIN_COMPATIBILITY_2_4
401 void wxBitmap::SetQuality(int WXUNUSED(quality
))
405 #endif // WXWIN_COMPATIBILITY_2_4
407 // ----------------------------------------------------------------------------
408 // raw bitmap access support
409 // ----------------------------------------------------------------------------
411 #ifdef wxHAVE_RAW_BITMAP
412 void *wxBitmap::GetRawData(wxPixelDataBase
& data
, int bpp
)
417 void wxBitmap::UngetRawData(wxPixelDataBase
& dataBase
)
421 #endif // #ifdef wxHAVE_RAW_BITMAP
423 // ----------------------------------------------------------------------------
425 // ----------------------------------------------------------------------------
432 // Construct a mask from a bitmap and a colour indicating
433 // the transparent area
434 wxMask::wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
)
438 // Construct a mask from a bitmap and a palette index indicating
439 // the transparent area
440 wxMask::wxMask(const wxBitmap
& bitmap
, int paletteIndex
)
444 // Construct a mask from a mono bitmap (copies the bitmap).
445 wxMask::wxMask(const wxBitmap
& bitmap
)
453 // Create a mask from a mono bitmap (copies the bitmap).
454 bool wxMask::Create(const wxBitmap
& bitmap
)
459 // Create a mask from a bitmap and a palette index indicating
460 // the transparent area
461 bool wxMask::Create(const wxBitmap
& bitmap
, int paletteIndex
)
466 // Create a mask from a bitmap and a colour indicating
467 // the transparent area
468 bool wxMask::Create(const wxBitmap
& bitmap
, const wxColour
& colour
)
473 // ----------------------------------------------------------------------------
475 // ----------------------------------------------------------------------------
477 bool wxBitmapHandler::Create(wxGDIImage
*image
,
480 int width
, int height
, int depth
)
485 bool wxBitmapHandler::Load(wxGDIImage
*image
,
486 const wxString
& name
,
488 int width
, int height
)
493 bool wxBitmapHandler::Save(wxGDIImage
*image
,
494 const wxString
& name
,
500 bool wxBitmapHandler::Create(wxBitmap
*WXUNUSED(bitmap
),
501 void *WXUNUSED(data
),
504 int WXUNUSED(height
),
510 bool wxBitmapHandler::LoadFile(wxBitmap
*WXUNUSED(bitmap
),
511 const wxString
& WXUNUSED(name
),
513 int WXUNUSED(desiredWidth
),
514 int WXUNUSED(desiredHeight
))
519 bool wxBitmapHandler::SaveFile(wxBitmap
*WXUNUSED(bitmap
),
520 const wxString
& WXUNUSED(name
),
522 const wxPalette
*WXUNUSED(palette
))