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 #ifdef wxHAVE_RAW_BITMAP
49 #include "wx/rawbmp.h"
52 // missing from mingw32 header
54 #define CLR_INVALID ((COLORREF)-1)
55 #endif // no CLR_INVALID
57 // ----------------------------------------------------------------------------
59 // ----------------------------------------------------------------------------
61 class WXDLLEXPORT wxBitmapRefData
: public wxGDIImageRefData
65 virtual ~wxBitmapRefData() { Free(); }
69 // set the mask object to use as the mask, we take ownership of it
70 void SetMask(wxMask
*mask
)
77 wxMask
*GetMask() const { return m_bitmapMask
; }
81 wxPalette m_bitmapPalette
;
82 #endif // wxUSE_PALETTE
99 DECLARE_NO_COPY_CLASS(wxBitmapRefData
)
102 // ----------------------------------------------------------------------------
104 // ----------------------------------------------------------------------------
106 IMPLEMENT_DYNAMIC_CLASS(wxBitmap
, wxGDIObject
)
107 IMPLEMENT_DYNAMIC_CLASS(wxMask
, wxObject
)
109 IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler
, wxObject
)
111 // ============================================================================
113 // ============================================================================
115 // ----------------------------------------------------------------------------
117 // ----------------------------------------------------------------------------
120 #define NEVER_USE_DIB
122 static inline bool wxShouldCreateDIB(int w
, int h
, int d
, WXHDC hdc
)
124 // here is the logic:
126 // (a) if hdc is specified, the caller explicitly wants DDB
127 // (b) otherwise, create a DIB if depth >= 24 (we don't support 16bpp
128 // or less DIBs anyhow)
129 // (c) finally, create DIBs under Win9x even if the depth hasn't been
130 // explicitly specified but the current display depth is 24 or
131 // more and the image is "big", i.e. > 16Mb which is the
132 // theoretical limit for DDBs under Win9x
134 // consequences (all of which seem to make sense):
136 // (i) by default, DDBs are created (depth == -1 usually)
137 // (ii) DIBs can be created by explicitly specifying the depth
138 // (iii) using a DC always forces creating a DDB
142 wxDIB::GetLineSize(w
, wxDisplayDepth())*h
> 16*1024*1024));
145 #define SOMETIMES_USE_DIB
146 #endif // different DIB usage scenarious
148 // ----------------------------------------------------------------------------
150 // ----------------------------------------------------------------------------
152 wxBitmapRefData::wxBitmapRefData()
155 m_selectedInto
= NULL
;
159 m_hBitmap
= (WXHBITMAP
) NULL
;
168 void wxBitmapRefData::Free()
172 // ----------------------------------------------------------------------------
174 // ----------------------------------------------------------------------------
176 // this function should be called from all wxBitmap ctors
177 void wxBitmap::Init()
181 wxGDIImageRefData
*wxBitmap::CreateData() const
186 bool wxBitmap::CopyFromCursor(const wxCursor
& cursor
)
191 bool wxBitmap::CopyFromIcon(const wxIcon
& icon
)
196 #ifndef NEVER_USE_DIB
198 bool wxBitmap::CopyFromDIB(const wxDIB
& dib
)
203 #endif // NEVER_USE_DIB
205 wxBitmap::~wxBitmap()
209 wxBitmap::wxBitmap(const char bits
[], int width
, int height
, int depth
)
214 wxBitmap::wxBitmap(int w
, int h
, int d
)
218 wxBitmap::wxBitmap(int w
, int h
, const wxDC
& dc
)
222 wxBitmap::wxBitmap(const void* data
, long type
, int width
, int height
, int depth
)
226 wxBitmap::wxBitmap(const wxString
& filename
, wxBitmapType type
)
230 bool wxBitmap::Create(int width
, int height
, int depth
)
235 bool wxBitmap::Create(int width
, int height
, const wxDC
& dc
)
240 bool wxBitmap::DoCreate(int w
, int h
, int d
, WXHDC hdc
)
247 // ----------------------------------------------------------------------------
248 // wxImage to/from conversions
249 // ----------------------------------------------------------------------------
253 bool wxBitmap::CreateFromImage(const wxImage
& image
, int depth
)
258 bool wxBitmap::CreateFromImage(const wxImage
& image
, const wxDC
& dc
)
263 bool wxBitmap::CreateFromImage(const wxImage
& image
, int depth
, WXHDC hdc
)
268 wxImage
wxBitmap::ConvertToImage() const
274 #endif // wxUSE_WXDIB
276 #endif // wxUSE_IMAGE
278 // ----------------------------------------------------------------------------
279 // loading and saving bitmaps
280 // ----------------------------------------------------------------------------
282 bool wxBitmap::LoadFile(const wxString
& filename
, long type
)
287 bool wxBitmap::Create(const void* data
, long type
, int width
, int height
, int depth
)
292 bool wxBitmap::SaveFile(const wxString
& filename
,
294 const wxPalette
*palette
)
299 // ----------------------------------------------------------------------------
300 // sub bitmap extraction
301 // ----------------------------------------------------------------------------
303 wxBitmap
wxBitmap::GetSubBitmap( const wxRect
& rect
) const
305 wxBitmap
ret( 0, 0 );
309 // ----------------------------------------------------------------------------
310 // wxBitmap accessors
311 // ----------------------------------------------------------------------------
314 wxPalette
* wxBitmap::GetPalette() const
316 return (wxPalette
*) NULL
;
320 wxMask
*wxBitmap::GetMask() const
322 return (wxMask
*) NULL
;
327 wxDC
*wxBitmap::GetSelectedInto() const
329 return (wxDC
*) NULL
;
334 void wxBitmap::UseAlpha()
338 bool wxBitmap::HasAlpha() const
343 // ----------------------------------------------------------------------------
345 // ----------------------------------------------------------------------------
349 void wxBitmap::SetSelectedInto(wxDC
*dc
)
357 void wxBitmap::SetPalette(const wxPalette
& palette
)
361 #endif // wxUSE_PALETTE
363 void wxBitmap::SetMask(wxMask
*mask
)
367 // ----------------------------------------------------------------------------
368 // raw bitmap access support
369 // ----------------------------------------------------------------------------
371 #ifdef wxHAVE_RAW_BITMAP
372 void *wxBitmap::GetRawData(wxPixelDataBase
& data
, int bpp
)
377 void wxBitmap::UngetRawData(wxPixelDataBase
& dataBase
)
381 #endif // #ifdef wxHAVE_RAW_BITMAP
383 // ----------------------------------------------------------------------------
385 // ----------------------------------------------------------------------------
392 // Construct a mask from a bitmap and a colour indicating
393 // the transparent area
394 wxMask::wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
)
398 // Construct a mask from a bitmap and a palette index indicating
399 // the transparent area
400 wxMask::wxMask(const wxBitmap
& bitmap
, int paletteIndex
)
404 // Construct a mask from a mono bitmap (copies the bitmap).
405 wxMask::wxMask(const wxBitmap
& bitmap
)
413 // Create a mask from a mono bitmap (copies the bitmap).
414 bool wxMask::Create(const wxBitmap
& bitmap
)
419 // Create a mask from a bitmap and a palette index indicating
420 // the transparent area
421 bool wxMask::Create(const wxBitmap
& bitmap
, int paletteIndex
)
426 // Create a mask from a bitmap and a colour indicating
427 // the transparent area
428 bool wxMask::Create(const wxBitmap
& bitmap
, const wxColour
& colour
)
433 // ----------------------------------------------------------------------------
435 // ----------------------------------------------------------------------------
437 bool wxBitmapHandler::Create(wxGDIImage
*image
,
440 int width
, int height
, int depth
)
445 bool wxBitmapHandler::Load(wxGDIImage
*image
,
446 const wxString
& name
,
448 int width
, int height
)
453 bool wxBitmapHandler::Save(wxGDIImage
*image
,
454 const wxString
& name
,
460 bool wxBitmapHandler::Create(wxBitmap
*WXUNUSED(bitmap
),
461 const void* WXUNUSED(data
),
464 int WXUNUSED(height
),
470 bool wxBitmapHandler::LoadFile(wxBitmap
*WXUNUSED(bitmap
),
471 const wxString
& WXUNUSED(name
),
473 int WXUNUSED(desiredWidth
),
474 int WXUNUSED(desiredHeight
))
479 bool wxBitmapHandler::SaveFile(wxBitmap
*WXUNUSED(bitmap
),
480 const wxString
& WXUNUSED(name
),
482 const wxPalette
*WXUNUSED(palette
))