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"
42 #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 // Create from XPM data
215 #if wxUSE_IMAGE && wxUSE_XPM
216 bool wxBitmap::CreateFromXpm(const char **data
)
218 bool wxBitmap::CreateFromXpm(const char **WXUNUSED(data
))
224 wxBitmap::wxBitmap(int w
, int h
, int d
)
228 wxBitmap::wxBitmap(int w
, int h
, const wxDC
& dc
)
232 wxBitmap::wxBitmap(void *data
, long type
, int width
, int height
, int depth
)
236 wxBitmap::wxBitmap(const wxString
& filename
, wxBitmapType type
)
240 bool wxBitmap::Create(int width
, int height
, int depth
)
245 bool wxBitmap::Create(int width
, int height
, const wxDC
& dc
)
250 bool wxBitmap::DoCreate(int w
, int h
, int d
, WXHDC hdc
)
257 // ----------------------------------------------------------------------------
258 // wxImage to/from conversions
259 // ----------------------------------------------------------------------------
263 bool wxBitmap::CreateFromImage(const wxImage
& image
, int depth
)
268 bool wxBitmap::CreateFromImage(const wxImage
& image
, const wxDC
& dc
)
273 bool wxBitmap::CreateFromImage(const wxImage
& image
, int depth
, WXHDC hdc
)
278 wxImage
wxBitmap::ConvertToImage() const
284 #endif // wxUSE_WXDIB
286 #endif // wxUSE_IMAGE
288 // ----------------------------------------------------------------------------
289 // loading and saving bitmaps
290 // ----------------------------------------------------------------------------
292 bool wxBitmap::LoadFile(const wxString
& filename
, long type
)
297 bool wxBitmap::Create(void *data
, long type
, int width
, int height
, int depth
)
302 bool wxBitmap::SaveFile(const wxString
& filename
,
304 const wxPalette
*palette
)
309 // ----------------------------------------------------------------------------
310 // sub bitmap extraction
311 // ----------------------------------------------------------------------------
313 wxBitmap
wxBitmap::GetSubBitmap( const wxRect
& rect
) const
315 wxBitmap
ret( 0, 0 );
319 // ----------------------------------------------------------------------------
320 // wxBitmap accessors
321 // ----------------------------------------------------------------------------
324 wxPalette
* wxBitmap::GetPalette() const
326 return (wxPalette
*) NULL
;
330 wxMask
*wxBitmap::GetMask() const
332 return (wxMask
*) NULL
;
337 wxDC
*wxBitmap::GetSelectedInto() const
339 return (wxDC
*) NULL
;
344 void wxBitmap::UseAlpha()
348 bool wxBitmap::HasAlpha() const
353 // ----------------------------------------------------------------------------
355 // ----------------------------------------------------------------------------
359 void wxBitmap::SetSelectedInto(wxDC
*dc
)
367 void wxBitmap::SetPalette(const wxPalette
& palette
)
371 #endif // wxUSE_PALETTE
373 void wxBitmap::SetMask(wxMask
*mask
)
377 // ----------------------------------------------------------------------------
378 // raw bitmap access support
379 // ----------------------------------------------------------------------------
381 #ifdef wxHAVE_RAW_BITMAP
382 void *wxBitmap::GetRawData(wxPixelDataBase
& data
, int bpp
)
387 void wxBitmap::UngetRawData(wxPixelDataBase
& dataBase
)
391 #endif // #ifdef wxHAVE_RAW_BITMAP
393 // ----------------------------------------------------------------------------
395 // ----------------------------------------------------------------------------
402 // Construct a mask from a bitmap and a colour indicating
403 // the transparent area
404 wxMask::wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
)
408 // Construct a mask from a bitmap and a palette index indicating
409 // the transparent area
410 wxMask::wxMask(const wxBitmap
& bitmap
, int paletteIndex
)
414 // Construct a mask from a mono bitmap (copies the bitmap).
415 wxMask::wxMask(const wxBitmap
& bitmap
)
423 // Create a mask from a mono bitmap (copies the bitmap).
424 bool wxMask::Create(const wxBitmap
& bitmap
)
429 // Create a mask from a bitmap and a palette index indicating
430 // the transparent area
431 bool wxMask::Create(const wxBitmap
& bitmap
, int paletteIndex
)
436 // Create a mask from a bitmap and a colour indicating
437 // the transparent area
438 bool wxMask::Create(const wxBitmap
& bitmap
, const wxColour
& colour
)
443 // ----------------------------------------------------------------------------
445 // ----------------------------------------------------------------------------
447 bool wxBitmapHandler::Create(wxGDIImage
*image
,
450 int width
, int height
, int depth
)
455 bool wxBitmapHandler::Load(wxGDIImage
*image
,
456 const wxString
& name
,
458 int width
, int height
)
463 bool wxBitmapHandler::Save(wxGDIImage
*image
,
464 const wxString
& name
,
470 bool wxBitmapHandler::Create(wxBitmap
*WXUNUSED(bitmap
),
471 void *WXUNUSED(data
),
474 int WXUNUSED(height
),
480 bool wxBitmapHandler::LoadFile(wxBitmap
*WXUNUSED(bitmap
),
481 const wxString
& WXUNUSED(name
),
483 int WXUNUSED(desiredWidth
),
484 int WXUNUSED(desiredHeight
))
489 bool wxBitmapHandler::SaveFile(wxBitmap
*WXUNUSED(bitmap
),
490 const wxString
& WXUNUSED(name
),
492 const wxPalette
*WXUNUSED(palette
))