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 bool wxBitmap::HasAlpha() const
339 // ----------------------------------------------------------------------------
341 // ----------------------------------------------------------------------------
345 void wxBitmap::SetSelectedInto(wxDC
*dc
)
353 void wxBitmap::SetPalette(const wxPalette
& palette
)
357 #endif // wxUSE_PALETTE
359 void wxBitmap::SetMask(wxMask
*mask
)
363 // ----------------------------------------------------------------------------
364 // raw bitmap access support
365 // ----------------------------------------------------------------------------
367 #ifdef wxHAVE_RAW_BITMAP
368 void *wxBitmap::GetRawData(wxPixelDataBase
& data
, int bpp
)
373 void wxBitmap::UngetRawData(wxPixelDataBase
& dataBase
)
377 #endif // #ifdef wxHAVE_RAW_BITMAP
379 // ----------------------------------------------------------------------------
381 // ----------------------------------------------------------------------------
388 // Construct a mask from a bitmap and a colour indicating
389 // the transparent area
390 wxMask::wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
)
394 // Construct a mask from a bitmap and a palette index indicating
395 // the transparent area
396 wxMask::wxMask(const wxBitmap
& bitmap
, int paletteIndex
)
400 // Construct a mask from a mono bitmap (copies the bitmap).
401 wxMask::wxMask(const wxBitmap
& bitmap
)
409 // Create a mask from a mono bitmap (copies the bitmap).
410 bool wxMask::Create(const wxBitmap
& bitmap
)
415 // Create a mask from a bitmap and a palette index indicating
416 // the transparent area
417 bool wxMask::Create(const wxBitmap
& bitmap
, int paletteIndex
)
422 // Create a mask from a bitmap and a colour indicating
423 // the transparent area
424 bool wxMask::Create(const wxBitmap
& bitmap
, const wxColour
& colour
)
429 // ----------------------------------------------------------------------------
431 // ----------------------------------------------------------------------------
433 bool wxBitmapHandler::Create(wxGDIImage
*image
,
436 int width
, int height
, int depth
)
441 bool wxBitmapHandler::Load(wxGDIImage
*image
,
442 const wxString
& name
,
444 int width
, int height
)
449 bool wxBitmapHandler::Save(wxGDIImage
*image
,
450 const wxString
& name
,
456 bool wxBitmapHandler::Create(wxBitmap
*WXUNUSED(bitmap
),
457 const void* WXUNUSED(data
),
460 int WXUNUSED(height
),
466 bool wxBitmapHandler::LoadFile(wxBitmap
*WXUNUSED(bitmap
),
467 const wxString
& WXUNUSED(name
),
469 int WXUNUSED(desiredWidth
),
470 int WXUNUSED(desiredHeight
))
475 bool wxBitmapHandler::SaveFile(wxBitmap
*WXUNUSED(bitmap
),
476 const wxString
& WXUNUSED(name
),
478 const wxPalette
*WXUNUSED(palette
))