1 ////////////////////////////////////////////////////////////////////////////
2 // Name: src/palmos/bitmap.cpp
4 // Author: William Osborne - minimal working wxPalmOS port
8 // Copyright: (c) William Osborne
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/bitmap.h"
35 #include "wx/palette.h"
36 #include "wx/dcmemory.h"
43 #include "wx/palmos/dib.h"
46 #include "wx/xpmdecod.h"
48 // missing from mingw32 header
50 #define CLR_INVALID ((COLORREF)-1)
51 #endif // no CLR_INVALID
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
57 class WXDLLEXPORT wxBitmapRefData
: public wxGDIImageRefData
61 virtual ~wxBitmapRefData() { Free(); }
65 // set the mask object to use as the mask, we take ownership of it
66 void SetMask(wxMask
*mask
)
73 wxMask
*GetMask() const { return m_bitmapMask
; }
77 wxPalette m_bitmapPalette
;
78 #endif // wxUSE_PALETTE
95 wxDECLARE_NO_COPY_CLASS(wxBitmapRefData
);
98 // ----------------------------------------------------------------------------
100 // ----------------------------------------------------------------------------
102 IMPLEMENT_DYNAMIC_CLASS(wxBitmap
, wxGDIObject
)
103 IMPLEMENT_DYNAMIC_CLASS(wxMask
, wxObject
)
105 IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler
, wxObject
)
107 // ============================================================================
109 // ============================================================================
111 // ----------------------------------------------------------------------------
113 // ----------------------------------------------------------------------------
116 #define NEVER_USE_DIB
118 static inline bool wxShouldCreateDIB(int w
, int h
, int d
, WXHDC hdc
)
120 // here is the logic:
122 // (a) if hdc is specified, the caller explicitly wants DDB
123 // (b) otherwise, create a DIB if depth >= 24 (we don't support 16bpp
124 // or less DIBs anyhow)
125 // (c) finally, create DIBs under Win9x even if the depth hasn't been
126 // explicitly specified but the current display depth is 24 or
127 // more and the image is "big", i.e. > 16Mb which is the
128 // theoretical limit for DDBs under Win9x
130 // consequences (all of which seem to make sense):
132 // (i) by default, DDBs are created (depth == -1 usually)
133 // (ii) DIBs can be created by explicitly specifying the depth
134 // (iii) using a DC always forces creating a DDB
138 wxDIB::GetLineSize(w
, wxDisplayDepth())*h
> 16*1024*1024));
141 #define SOMETIMES_USE_DIB
142 #endif // different DIB usage scenarious
144 // ----------------------------------------------------------------------------
146 // ----------------------------------------------------------------------------
148 wxBitmapRefData::wxBitmapRefData()
151 m_selectedInto
= NULL
;
155 m_hBitmap
= (WXHBITMAP
) NULL
;
164 void wxBitmapRefData::Free()
168 // ----------------------------------------------------------------------------
170 // ----------------------------------------------------------------------------
172 // this function should be called from all wxBitmap ctors
173 void wxBitmap::Init()
177 wxGDIImageRefData
*wxBitmap::CreateData() const
182 bool wxBitmap::CopyFromCursor(const wxCursor
& cursor
)
187 bool wxBitmap::CopyFromIcon(const wxIcon
& icon
)
192 #ifndef NEVER_USE_DIB
194 bool wxBitmap::CopyFromDIB(const wxDIB
& dib
)
199 #endif // NEVER_USE_DIB
201 wxBitmap::~wxBitmap()
205 wxBitmap::wxBitmap(const char bits
[], int width
, int height
, int depth
)
210 wxBitmap::wxBitmap(int w
, int h
, int d
)
214 wxBitmap::wxBitmap(int w
, int h
, const wxDC
& dc
)
218 wxBitmap::wxBitmap(const void* data
, long type
, int width
, int height
, int depth
)
222 wxBitmap::wxBitmap(const wxString
& filename
, wxBitmapType type
)
226 bool wxBitmap::Create(int width
, int height
, int depth
)
231 bool wxBitmap::Create(int width
, int height
, const wxDC
& dc
)
236 bool wxBitmap::DoCreate(int w
, int h
, int d
, WXHDC hdc
)
243 // ----------------------------------------------------------------------------
244 // wxImage to/from conversions
245 // ----------------------------------------------------------------------------
249 bool wxBitmap::CreateFromImage(const wxImage
& image
, int depth
)
254 bool wxBitmap::CreateFromImage(const wxImage
& image
, const wxDC
& dc
)
259 bool wxBitmap::CreateFromImage(const wxImage
& image
, int depth
, WXHDC hdc
)
264 wxImage
wxBitmap::ConvertToImage() const
270 #endif // wxUSE_WXDIB
272 #endif // wxUSE_IMAGE
274 // ----------------------------------------------------------------------------
275 // loading and saving bitmaps
276 // ----------------------------------------------------------------------------
278 bool wxBitmap::LoadFile(const wxString
& filename
, long type
)
283 bool wxBitmap::Create(const void* data
, long type
, int width
, int height
, int depth
)
288 bool wxBitmap::SaveFile(const wxString
& filename
,
290 const wxPalette
*palette
)
295 // ----------------------------------------------------------------------------
296 // sub bitmap extraction
297 // ----------------------------------------------------------------------------
299 wxBitmap
wxBitmap::GetSubBitmap( const wxRect
& rect
) const
301 wxBitmap
ret( 0, 0 );
305 // ----------------------------------------------------------------------------
306 // wxBitmap accessors
307 // ----------------------------------------------------------------------------
310 wxPalette
* wxBitmap::GetPalette() const
316 wxMask
*wxBitmap::GetMask() const
323 wxDC
*wxBitmap::GetSelectedInto() const
330 bool wxBitmap::HasAlpha() const
335 // ----------------------------------------------------------------------------
337 // ----------------------------------------------------------------------------
341 void wxBitmap::SetSelectedInto(wxDC
*dc
)
349 void wxBitmap::SetPalette(const wxPalette
& palette
)
353 #endif // wxUSE_PALETTE
355 void wxBitmap::SetMask(wxMask
*mask
)
359 // ----------------------------------------------------------------------------
360 // raw bitmap access support
361 // ----------------------------------------------------------------------------
363 // ----------------------------------------------------------------------------
365 // ----------------------------------------------------------------------------
372 // Construct a mask from a bitmap and a colour indicating
373 // the transparent area
374 wxMask::wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
)
378 // Construct a mask from a bitmap and a palette index indicating
379 // the transparent area
380 wxMask::wxMask(const wxBitmap
& bitmap
, int paletteIndex
)
384 // Construct a mask from a mono bitmap (copies the bitmap).
385 wxMask::wxMask(const wxBitmap
& bitmap
)
393 // Create a mask from a mono bitmap (copies the bitmap).
394 bool wxMask::Create(const wxBitmap
& bitmap
)
399 // Create a mask from a bitmap and a palette index indicating
400 // the transparent area
401 bool wxMask::Create(const wxBitmap
& bitmap
, int paletteIndex
)
406 // Create a mask from a bitmap and a colour indicating
407 // the transparent area
408 bool wxMask::Create(const wxBitmap
& bitmap
, const wxColour
& colour
)
413 // ----------------------------------------------------------------------------
415 // ----------------------------------------------------------------------------
417 bool wxBitmapHandler::Create(wxGDIImage
*image
,
420 int width
, int height
, int depth
)
425 bool wxBitmapHandler::Load(wxGDIImage
*image
,
426 const wxString
& name
,
428 int width
, int height
)
433 bool wxBitmapHandler::Save(wxGDIImage
*image
,
434 const wxString
& name
,
440 bool wxBitmapHandler::Create(wxBitmap
*WXUNUSED(bitmap
),
441 const void* WXUNUSED(data
),
444 int WXUNUSED(height
),
450 bool wxBitmapHandler::LoadFile(wxBitmap
*WXUNUSED(bitmap
),
451 const wxString
& WXUNUSED(name
),
453 int WXUNUSED(desiredWidth
),
454 int WXUNUSED(desiredHeight
))
459 bool wxBitmapHandler::SaveFile(wxBitmap
*WXUNUSED(bitmap
),
460 const wxString
& WXUNUSED(name
),
462 const wxPalette
*WXUNUSED(palette
))