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
91 wxDECLARE_NO_COPY_CLASS(wxBitmapRefData
);
94 // ----------------------------------------------------------------------------
96 // ----------------------------------------------------------------------------
98 IMPLEMENT_DYNAMIC_CLASS(wxBitmap
, wxGDIObject
)
99 IMPLEMENT_DYNAMIC_CLASS(wxMask
, wxObject
)
101 IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler
, wxObject
)
103 // ============================================================================
105 // ============================================================================
107 // ----------------------------------------------------------------------------
109 // ----------------------------------------------------------------------------
112 #define NEVER_USE_DIB
114 static inline bool wxShouldCreateDIB(int w
, int h
, int d
, WXHDC hdc
)
116 // here is the logic:
118 // (a) if hdc is specified, the caller explicitly wants DDB
119 // (b) otherwise, create a DIB if depth >= 24 (we don't support 16bpp
120 // or less DIBs anyhow)
121 // (c) finally, create DIBs under Win9x even if the depth hasn't been
122 // explicitly specified but the current display depth is 24 or
123 // more and the image is "big", i.e. > 16Mb which is the
124 // theoretical limit for DDBs under Win9x
126 // consequences (all of which seem to make sense):
128 // (i) by default, DDBs are created (depth == -1 usually)
129 // (ii) DIBs can be created by explicitly specifying the depth
130 // (iii) using a DC always forces creating a DDB
134 wxDIB::GetLineSize(w
, wxDisplayDepth())*h
> 16*1024*1024));
137 #define SOMETIMES_USE_DIB
138 #endif // different DIB usage scenarious
140 // ----------------------------------------------------------------------------
142 // ----------------------------------------------------------------------------
144 wxBitmapRefData::wxBitmapRefData()
148 m_hBitmap
= (WXHBITMAP
) NULL
;
157 void wxBitmapRefData::Free()
161 // ----------------------------------------------------------------------------
163 // ----------------------------------------------------------------------------
165 // this function should be called from all wxBitmap ctors
166 void wxBitmap::Init()
170 wxGDIImageRefData
*wxBitmap::CreateData() const
175 bool wxBitmap::CopyFromCursor(const wxCursor
& cursor
)
180 bool wxBitmap::CopyFromIcon(const wxIcon
& icon
)
185 #ifndef NEVER_USE_DIB
187 bool wxBitmap::CopyFromDIB(const wxDIB
& dib
)
192 #endif // NEVER_USE_DIB
194 wxBitmap::wxBitmap(const char bits
[], int width
, int height
, int depth
)
199 wxBitmap::wxBitmap(int w
, int h
, const wxDC
& dc
)
203 wxBitmap::wxBitmap(const void* data
, long type
, int width
, int height
, int depth
)
207 wxBitmap::wxBitmap(const wxString
& filename
, wxBitmapType type
)
211 bool wxBitmap::Create(int width
, int height
, int depth
)
216 bool wxBitmap::Create(int width
, int height
, const wxDC
& dc
)
221 bool wxBitmap::DoCreate(int w
, int h
, int d
, WXHDC hdc
)
228 // ----------------------------------------------------------------------------
229 // wxImage to/from conversions
230 // ----------------------------------------------------------------------------
234 bool wxBitmap::CreateFromImage(const wxImage
& image
, int depth
)
239 bool wxBitmap::CreateFromImage(const wxImage
& image
, const wxDC
& dc
)
244 bool wxBitmap::CreateFromImage(const wxImage
& image
, int depth
, WXHDC hdc
)
249 wxImage
wxBitmap::ConvertToImage() const
255 #endif // wxUSE_WXDIB
257 #endif // wxUSE_IMAGE
259 // ----------------------------------------------------------------------------
260 // loading and saving bitmaps
261 // ----------------------------------------------------------------------------
263 bool wxBitmap::LoadFile(const wxString
& filename
, long type
)
268 bool wxBitmap::Create(const void* data
, long type
, int width
, int height
, int depth
)
273 bool wxBitmap::SaveFile(const wxString
& filename
,
275 const wxPalette
*palette
)
280 // ----------------------------------------------------------------------------
281 // sub bitmap extraction
282 // ----------------------------------------------------------------------------
284 wxBitmap
wxBitmap::GetSubBitmap( const wxRect
& rect
) const
286 wxBitmap
ret( 0, 0 );
290 // ----------------------------------------------------------------------------
291 // wxBitmap accessors
292 // ----------------------------------------------------------------------------
295 wxPalette
* wxBitmap::GetPalette() const
301 wxMask
*wxBitmap::GetMask() const
306 bool wxBitmap::HasAlpha() const
311 // ----------------------------------------------------------------------------
313 // ----------------------------------------------------------------------------
317 void wxBitmap::SetPalette(const wxPalette
& palette
)
321 #endif // wxUSE_PALETTE
323 void wxBitmap::SetMask(wxMask
*mask
)
327 // ----------------------------------------------------------------------------
328 // raw bitmap access support
329 // ----------------------------------------------------------------------------
331 // ----------------------------------------------------------------------------
333 // ----------------------------------------------------------------------------
340 // Construct a mask from a bitmap and a colour indicating
341 // the transparent area
342 wxMask::wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
)
346 // Construct a mask from a bitmap and a palette index indicating
347 // the transparent area
348 wxMask::wxMask(const wxBitmap
& bitmap
, int paletteIndex
)
352 // Construct a mask from a mono bitmap (copies the bitmap).
353 wxMask::wxMask(const wxBitmap
& bitmap
)
361 // Create a mask from a mono bitmap (copies the bitmap).
362 bool wxMask::Create(const wxBitmap
& bitmap
)
367 // Create a mask from a bitmap and a palette index indicating
368 // the transparent area
369 bool wxMask::Create(const wxBitmap
& bitmap
, int paletteIndex
)
374 // Create a mask from a bitmap and a colour indicating
375 // the transparent area
376 bool wxMask::Create(const wxBitmap
& bitmap
, const wxColour
& colour
)
381 // ----------------------------------------------------------------------------
383 // ----------------------------------------------------------------------------
385 bool wxBitmapHandler::Create(wxGDIImage
*image
,
388 int width
, int height
, int depth
)
393 bool wxBitmapHandler::Load(wxGDIImage
*image
,
394 const wxString
& name
,
396 int width
, int height
)
401 bool wxBitmapHandler::Save(wxGDIImage
*image
,
402 const wxString
& name
,
408 bool wxBitmapHandler::Create(wxBitmap
*WXUNUSED(bitmap
),
409 const void* WXUNUSED(data
),
412 int WXUNUSED(height
),
418 bool wxBitmapHandler::LoadFile(wxBitmap
*WXUNUSED(bitmap
),
419 const wxString
& WXUNUSED(name
),
421 int WXUNUSED(desiredWidth
),
422 int WXUNUSED(desiredHeight
))
427 bool wxBitmapHandler::SaveFile(wxBitmap
*WXUNUSED(bitmap
),
428 const wxString
& WXUNUSED(name
),
430 const wxPalette
*WXUNUSED(palette
))