1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mgl/bitmap.cpp
3 // Author: Vaclav Slavik
5 // Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
9 // For compilers that support precompilation, includes "wx.h".
10 #include "wx/wxprec.h"
16 #include "wx/bitmap.h"
22 #include "wx/dcmemory.h"
27 #include "wx/filefn.h"
28 #include "wx/xpmdecod.h"
30 #include "wx/mgl/private.h"
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 static pixel_format_t gs_pixel_format_15
=
39 {0x1F,0x0A,3, 0x1F,0x05,3, 0x1F,0x00,3, 0x01,0x0F,7}; // 555 15bpp
41 static pixel_format_t gs_pixel_format_16
=
42 {0x1F,0x0B,3, 0x3F,0x05,2, 0x1F,0x00,3, 0x00,0x00,0}; // 565 16bpp
44 static pixel_format_t gs_pixel_format_24
=
45 {0xFF,0x10,0, 0xFF,0x08,0, 0xFF,0x00,0, 0x00,0x00,0}; // RGB 24bpp
47 static pixel_format_t gs_pixel_format_32
=
48 {0xFF,0x18,0, 0xFF,0x10,0, 0xFF,0x08,0, 0xFF,0x00,0}; // RGBA 32bpp
50 static pixel_format_t gs_pixel_format_wxImage
=
51 {0xFF,0x00,0, 0xFF,0x08,0, 0xFF,0x10,0, 0x00,0x00,0}; // RGB 24bpp for wxImage
53 //-----------------------------------------------------------------------------
55 //-----------------------------------------------------------------------------
57 class wxBitmapRefData
: public wxObjectRefData
61 virtual ~wxBitmapRefData();
63 virtual bool IsOk() const { return m_bitmap
!= NULL
; }
73 wxBitmapRefData::wxBitmapRefData()
83 wxBitmapRefData::~wxBitmapRefData()
86 MGL_unloadBitmap(m_bitmap
);
91 //-----------------------------------------------------------------------------
93 #define M_BMPDATA ((wxBitmapRefData *)m_refData)
96 IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandler
, wxBitmapHandlerBase
)
97 IMPLEMENT_DYNAMIC_CLASS(wxBitmap
,wxBitmapBase
)
99 wxBitmap::wxBitmap(int width
, int height
, int depth
)
101 Create(width
, height
, depth
);
105 static bitmap_t
*MyMGL_createBitmap(int width
, int height
,
106 int bpp
, pixel_format_t
*pf
)
108 MGLMemoryDC
mdc(width
, height
, bpp
, pf
);
109 return MGL_getBitmapFromDC(mdc
.getDC(), 0, 0, width
, height
, TRUE
);
112 bool wxBitmap::Create(int width
, int height
, int depth
)
116 wxCHECK_MSG( (width
> 0) && (height
> 0), false, wxT("invalid bitmap size") );
118 pixel_format_t pf_dummy
;
120 int mglDepth
= depth
;
125 wxASSERT_MSG( g_displayDC
, wxT("MGL display DC not created yet.") );
127 g_displayDC
->getPixelFormat(pf_dummy
);
128 mglDepth
= g_displayDC
->getBitsPerPixel();
136 pf
= &gs_pixel_format_15
;
139 pf
= &gs_pixel_format_16
;
142 pf
= &gs_pixel_format_24
;
145 pf
= &gs_pixel_format_32
;
148 wxFAIL_MSG(wxT("invalid bitmap depth"));
152 m_refData
= new wxBitmapRefData();
153 M_BMPDATA
->m_mask
= (wxMask
*) NULL
;
154 M_BMPDATA
->m_palette
= (wxPalette
*) NULL
;
155 M_BMPDATA
->m_width
= width
;
156 M_BMPDATA
->m_height
= height
;
157 M_BMPDATA
->m_bpp
= mglDepth
;
161 M_BMPDATA
->m_bitmap
= MyMGL_createBitmap(width
, height
, mglDepth
, pf
);
165 // MGL does not support mono DCs, so we have to emulate them with
166 // 8bpp ones. We do that by using a special palette with color 0
167 // set to black and all other colors set to white.
169 M_BMPDATA
->m_bitmap
= MyMGL_createBitmap(width
, height
, 8, pf
);
170 SetMonoPalette(wxColour(255, 255, 255), wxColour(0, 0, 0));
176 wxBitmap::wxBitmap(const wxImage
& image
, int depth
)
180 wxCHECK_RET( image
.Ok(), wxT("invalid image") );
182 width
= image
.GetWidth();
183 height
= image
.GetHeight();
185 if ( !Create(width
, height
, depth
) ) return;
187 MGLMemoryDC
idc(width
, height
, 24, &gs_pixel_format_wxImage
,
188 width
* 3, (void*)image
.GetData(), NULL
);
189 wxASSERT_MSG( idc
.isValid(), wxT("cannot create custom MGLDC") );
191 MGLDevCtx
*bdc
= CreateTmpDC();
193 if ( GetDepth() <= 8 && image
.HasPalette() )
194 SetPalette(image
.GetPalette());
196 bdc
->bitBlt(idc
, 0, 0, width
, height
, 0, 0, MGL_REPLACE_MODE
);
199 if ( image
.HasMask() )
201 wxImage mask_image
= image
.ConvertToMono(image
.GetMaskRed(),
202 image
.GetMaskGreen(),
203 image
.GetMaskBlue());
204 mask_image
.SetMask(false);
205 wxBitmap
mask_bmp(mask_image
, 1);
206 SetMask(new wxMask(mask_bmp
));
210 wxImage
wxBitmap::ConvertToImage() const
212 wxCHECK_MSG( Ok(), wxImage(), wxT("invalid bitmap") );
216 height
= GetHeight();
218 wxImage
image(width
, height
);
219 wxASSERT_MSG( image
.Ok(), wxT("cannot create image") );
221 MGLMemoryDC
idc(width
, height
, 24, &gs_pixel_format_wxImage
,
222 width
* 3, (void*)image
.GetData(), NULL
);
223 wxASSERT_MSG( idc
.isValid(), wxT("cannot create custom MGLDC") );
225 if ( M_BMPDATA
->m_palette
)
226 image
.SetPalette(*(M_BMPDATA
->m_palette
));
230 // in consistency with other ports, we convert parts covered
231 // by the mask to <16,16,16> colour and set that colour to image's
232 // mask. We do that by OR-blitting the mask over image with
233 // bg colour set to black and fg colour to <16,16,16>
235 image
.SetMaskColour(16, 16, 16);
239 tmpDC
.SetMGLDC(&idc
, false);
240 tmpDC
.SetBackground(wxBrush(wxColour(16,16,16), wxSOLID
));
242 tmpDC
.DrawBitmap(*this, 0, 0, true);
246 image
.SetMask(false);
247 idc
.putBitmap(0, 0, M_BMPDATA
->m_bitmap
, MGL_REPLACE_MODE
);
253 wxBitmap::wxBitmap(const wxString
&filename
, wxBitmapType type
)
255 LoadFile(filename
, type
);
258 wxBitmap::wxBitmap(const char bits
[], int width
, int height
, int depth
)
260 wxCHECK_RET( depth
== 1, wxT("can only create mono bitmap from XBM data") );
262 if ( !Create(width
, height
, 1) ) return;
263 MGLDevCtx
*bdc
= CreateTmpDC();
264 wxCurrentDCSwitcher
curDC(bdc
);
266 bdc
->setBackColor(0);
268 bdc
->putMonoImage(0, 0, width
, (width
+ 7) / 8, height
, (void*)bits
);
272 int wxBitmap::GetHeight() const
274 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
276 return M_BMPDATA
->m_height
;
279 int wxBitmap::GetWidth() const
281 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
283 return M_BMPDATA
->m_width
;
286 int wxBitmap::GetDepth() const
288 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
290 return M_BMPDATA
->m_bpp
;
293 wxMask
*wxBitmap::GetMask() const
295 wxCHECK_MSG( Ok(), (wxMask
*) NULL
, wxT("invalid bitmap") );
297 return M_BMPDATA
->m_mask
;
300 void wxBitmap::SetMask(wxMask
*mask
)
302 wxCHECK_RET( Ok(), wxT("invalid bitmap") );
305 delete M_BMPDATA
->m_mask
;
306 M_BMPDATA
->m_mask
= mask
;
309 bool wxBitmap::CopyFromIcon(const wxIcon
& icon
)
311 wxBitmap
*bmp
= (wxBitmap
*)(&icon
);
316 wxBitmap
wxBitmap::GetSubBitmap(const wxRect
& rect
) const
319 (rect
.x
>= 0) && (rect
.y
>= 0) &&
320 (rect
.x
+rect
.width
<= M_BMPDATA
->m_width
) && (rect
.y
+rect
.height
<= M_BMPDATA
->m_height
),
321 wxNullBitmap
, wxT("invalid bitmap or bitmap region") );
323 wxBitmap
ret( rect
.width
, rect
.height
, M_BMPDATA
->m_bpp
);
324 wxASSERT_MSG( ret
.Ok(), wxT("GetSubBitmap error") );
327 ret
.SetPalette(*GetPalette());
329 MGLDevCtx
*tdc
= ret
.CreateTmpDC();
330 tdc
->putBitmapSection(rect
.x
, rect
.y
,
331 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
332 0, 0, M_BMPDATA
->m_bitmap
, MGL_REPLACE_MODE
);
337 wxBitmap submask
= GetMask()->GetBitmap().GetSubBitmap(rect
);
338 ret
.SetMask(new wxMask(submask
));
344 void wxBitmap::SetMonoPalette(const wxColour
& fg
, const wxColour
& bg
)
346 wxCHECK_RET( Ok(), wxT("invalid bitmap") );
349 palette_t
*mono
= M_BMPDATA
->m_bitmap
->pal
;
351 wxCHECK_RET( M_BMPDATA
->m_bpp
== 1, wxT("bitmap is not 1bpp") );
352 wxCHECK_RET( mono
!= NULL
, wxT("bitmap w/o palette") );
354 mono
[0].red
= bg
.Red();
355 mono
[0].green
= bg
.Green();
356 mono
[0].blue
= bg
.Blue();
358 for (size_t i
= 1; i
< 256; i
++)
360 mono
[i
].red
= fg
.Red();
361 mono
[i
].green
= fg
.Green();
362 mono
[i
].blue
= fg
.Blue();
367 MGLDevCtx
*wxBitmap::CreateTmpDC() const
369 wxCHECK_MSG( Ok(), NULL
, wxT("invalid bitmap") );
371 MGLDevCtx
*tdc
= new MGLMemoryDC(GetWidth(), GetHeight(),
372 M_BMPDATA
->m_bitmap
->bitsPerPixel
,
373 M_BMPDATA
->m_bitmap
->pf
,
374 M_BMPDATA
->m_bitmap
->bytesPerLine
,
375 M_BMPDATA
->m_bitmap
->surface
,
377 wxCHECK_MSG( tdc
->isValid(), NULL
, wxT("cannot create temporary MGLDC") );
379 if ( M_BMPDATA
->m_bitmap
->pal
!= NULL
)
383 switch (M_BMPDATA
->m_bitmap
->bitsPerPixel
)
385 case 2: cnt
= 2; break;
386 case 4: cnt
= 16; break;
387 case 8: cnt
= 256; break;
390 wxFAIL_MSG( wxT("bitmap with this depth cannot have palette") );
394 tdc
->setPalette(M_BMPDATA
->m_bitmap
->pal
, cnt
, 0);
395 tdc
->realizePalette(cnt
, 0, FALSE
);
401 bool wxBitmap::LoadFile(const wxString
&name
, wxBitmapType type
)
405 if ( type
== wxBITMAP_TYPE_BMP
|| type
== wxBITMAP_TYPE_PNG
||
406 type
== wxBITMAP_TYPE_PCX
|| type
== wxBITMAP_TYPE_JPEG
)
408 // prevent accidental loading of bitmap from $MGL_ROOT:
409 if ( !wxFileExists(name
) )
411 wxLogError(_("File %s does not exist."), name
.c_str());
416 wxBitmapHandler
*handler
= FindHandler(type
);
418 if ( handler
== NULL
)
421 if ( !image
.LoadFile(name
, type
) || !image
.Ok() )
423 wxLogError("no bitmap handler for type %d defined.", type
);
428 *this = wxBitmap(image
);
433 m_refData
= new wxBitmapRefData();
435 return handler
->LoadFile(this, name
, type
, -1, -1);
438 bool wxBitmap::SaveFile(const wxString
& filename
, wxBitmapType type
, const wxPalette
*palette
) const
440 wxCHECK_MSG( Ok(), false, wxT("invalid bitmap") );
442 wxBitmapHandler
*handler
= FindHandler(type
);
444 if ( handler
== NULL
)
446 wxImage image
= ConvertToImage();
448 image
.SetPalette(*palette
);
451 return image
.SaveFile(filename
, type
);
454 wxLogError("no bitmap handler for type %d defined.", type
);
459 return handler
->SaveFile(this, filename
, type
, palette
);
462 wxPalette
*wxBitmap::GetPalette() const
464 wxCHECK_MSG( Ok(), NULL
, wxT("invalid bitmap") );
466 return M_BMPDATA
->m_palette
;
469 void wxBitmap::SetPalette(const wxPalette
& palette
)
471 wxCHECK_RET( Ok(), wxT("invalid bitmap") );
472 wxCHECK_RET( GetDepth() > 1 && GetDepth() <= 8, wxT("cannot set palette for bitmap of this depth") );
475 delete M_BMPDATA
->m_palette
;
476 M_BMPDATA
->m_palette
= NULL
;
478 if ( !palette
.Ok() ) return;
480 M_BMPDATA
->m_palette
= new wxPalette(palette
);
482 int cnt
= palette
.GetColoursCount();
483 palette_t
*pal
= palette
.GetMGLpalette_t();
484 memcpy(M_BMPDATA
->m_bitmap
->pal
, pal
, cnt
* sizeof(palette_t
));
487 void wxBitmap::SetHeight(int height
)
491 M_BMPDATA
->m_height
= height
;
494 void wxBitmap::SetWidth(int width
)
498 M_BMPDATA
->m_width
= width
;
501 void wxBitmap::SetDepth(int depth
)
505 M_BMPDATA
->m_bpp
= depth
;
508 bitmap_t
*wxBitmap::GetMGLbitmap_t() const
510 return M_BMPDATA
->m_bitmap
;
513 // Convert wxColour into it's quantized value in lower-precision
514 // pixel format (needed for masking by colour).
515 wxColour
wxBitmap::QuantizeColour(const wxColour
& clr
) const
517 pixel_format_t
*pf
= GetMGLbitmap_t()->pf
;
519 if ( pf
->redAdjust
== 0 && pf
->greenAdjust
== 0 && pf
->blueAdjust
== 0 )
522 return wxColour((unsigned char)((clr
.Red() >> pf
->redAdjust
) << pf
->redAdjust
),
523 (unsigned char)((clr
.Green() >> pf
->greenAdjust
) << pf
->greenAdjust
),
524 (unsigned char)((clr
.Blue() >> pf
->blueAdjust
) << pf
->blueAdjust
));
528 //-----------------------------------------------------------------------------
529 // wxBitmap I/O handlers
530 //-----------------------------------------------------------------------------
532 class wxMGLBitmapHandler
: public wxBitmapHandler
535 wxMGLBitmapHandler(wxBitmapType type
,
536 const wxString
& extension
, const wxString
& name
);
538 virtual bool Create(wxBitmap
*WXUNUSED(bitmap
),
539 const void* WXUNUSED(data
),
540 long WXUNUSED(flags
),
542 int WXUNUSED(height
),
543 int WXUNUSED(depth
) = 1)
546 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
547 int desiredWidth
, int desiredHeight
);
548 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
549 int type
, const wxPalette
*palette
= NULL
);
552 wxMGLBitmapHandler::wxMGLBitmapHandler(wxBitmapType type
,
553 const wxString
& extension
,
554 const wxString
& name
)
559 SetExtension(extension
);
562 bool wxMGLBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
,
564 int WXUNUSED(desiredWidth
),
565 int WXUNUSED(desiredHeight
))
567 int width
, height
, bpp
;
574 case wxBITMAP_TYPE_BMP_RESOURCE
:
575 case wxBITMAP_TYPE_JPEG_RESOURCE
:
576 case wxBITMAP_TYPE_PNG_RESOURCE
:
577 case wxBITMAP_TYPE_PCX_RESOURCE
:
578 fullname
= name
+ wxT(".bmp");
587 case wxBITMAP_TYPE_BMP
:
588 case wxBITMAP_TYPE_BMP_RESOURCE
:
589 if ( !MGL_getBitmapSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
591 bitmap
->Create(width
, height
, -1);
592 if ( !bitmap
->Ok() ) return false;
593 dc
.SelectObject(*bitmap
);
594 if ( !dc
.GetMGLDC()->loadBitmapIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
598 case wxBITMAP_TYPE_JPEG
:
599 case wxBITMAP_TYPE_JPEG_RESOURCE
:
600 if ( !MGL_getJPEGSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
602 bitmap
->Create(width
, height
, -1);
603 if ( !bitmap
->Ok() ) return false;
604 dc
.SelectObject(*bitmap
);
605 if ( !dc
.GetMGLDC()->loadJPEGIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
609 case wxBITMAP_TYPE_PNG
:
610 case wxBITMAP_TYPE_PNG_RESOURCE
:
611 if ( !MGL_getPNGSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
613 bitmap
->Create(width
, height
, -1);
614 if ( !bitmap
->Ok() ) return false;
615 dc
.SelectObject(*bitmap
);
616 if ( !dc
.GetMGLDC()->loadPNGIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
620 case wxBITMAP_TYPE_PCX
:
621 case wxBITMAP_TYPE_PCX_RESOURCE
:
622 if ( !MGL_getPCXSize(fullname
.mb_str(), &width
, &height
, &bpp
) )
624 bitmap
->Create(width
, height
, -1);
625 if ( !bitmap
->Ok() ) return false;
626 dc
.SelectObject(*bitmap
);
627 if ( !dc
.GetMGLDC()->loadPCXIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
632 wxFAIL_MSG(wxT("Unsupported image format."));
639 bool wxMGLBitmapHandler::SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
640 int type
, const wxPalette
* WXUNUSED(palette
))
644 int w
= bitmap
->GetWidth(),
645 h
= bitmap
->GetHeight();
647 mem
.SelectObjectAsSource(*bitmap
);
648 tdc
= mem
.GetMGLDC();
652 case wxBITMAP_TYPE_BMP
:
653 return (bool)tdc
->saveBitmapFromDC(name
.mb_str(), 0, 0, w
, h
);
654 case wxBITMAP_TYPE_JPEG
:
655 return (bool)tdc
->saveJPEGFromDC(name
.mb_str(), 0, 0, w
, h
, 75);
656 case wxBITMAP_TYPE_PNG
:
657 return (bool)tdc
->savePNGFromDC(name
.mb_str(), 0, 0, w
, h
);
658 case wxBITMAP_TYPE_PCX
:
659 return (bool)tdc
->savePCXFromDC(name
.mb_str(), 0, 0, w
, h
);
667 // let's handle PNGs in special way because they have alpha channel
668 // which we can access via bitmap_t most easily
669 class wxPNGBitmapHandler
: public wxMGLBitmapHandler
672 wxPNGBitmapHandler(wxBitmapType type
,
673 const wxString
& extension
, const wxString
& name
)
674 : wxMGLBitmapHandler(type
, extension
, name
) {}
676 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
677 int desiredWidth
, int desiredHeight
);
680 bool wxPNGBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
,
682 int desiredWidth
, int desiredHeight
)
684 int width
, height
, bpp
;
688 if ( flags
== wxBITMAP_TYPE_PNG_RESOURCE
)
689 fullname
= name
+ wxT(".png");
693 if ( !MGL_getPNGSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
698 // We can load ordinary PNGs faster with 'normal' MGL handler.
699 // Only RGBA PNGs need to be processed in special way because
700 // we have to convert alpha channel to mask
701 return wxMGLBitmapHandler::LoadFile(bitmap
, name
, flags
,
702 desiredWidth
, desiredHeight
);
705 bitmap_t
*bmp
= MGL_loadPNG(fullname
.mb_str(), TRUE
);
707 if ( bmp
== NULL
) return false;
709 bitmap
->Create(bmp
->width
, bmp
->height
, -1);
710 if ( !bitmap
->Ok() ) return false;
712 // convert bmp to display's depth and write it to *bitmap:
714 dc
.SelectObject(*bitmap
);
715 dc
.GetMGLDC()->putBitmap(0, 0, bmp
, MGL_REPLACE_MODE
);
716 dc
.SelectObject(wxNullBitmap
);
718 // create mask, if bmp contains alpha channel (ARGB format):
719 if ( bmp
->bitsPerPixel
== 32 )
722 wxUint32
*s
= (wxUint32
*)bmp
->surface
;
723 for (y
= 0; y
< bmp
->height
; y
++)
725 s
= ((wxUint32
*)bmp
->surface
) + y
* bmp
->bytesPerLine
/4;
726 for (x
= 0; x
< bmp
->width
; x
++, s
++)
728 if ( ((((*s
) >> bmp
->pf
->alphaPos
) & bmp
->pf
->alphaMask
)
729 << bmp
->pf
->alphaAdjust
) < 128 )
732 *s
= 0x00FFFFFF; // white
735 wxBitmap
mask(bmp
->width
, bmp
->height
, 1);
736 dc
.SelectObject(mask
);
737 dc
.GetMGLDC()->putBitmap(0, 0, bmp
, MGL_REPLACE_MODE
);
738 dc
.SelectObject(wxNullBitmap
);
739 bitmap
->SetMask(new wxMask(mask
));
742 MGL_unloadBitmap(bmp
);
750 class wxICOBitmapHandler
: public wxBitmapHandler
753 wxICOBitmapHandler(wxBitmapType type
,
754 const wxString
& extension
, const wxString
& name
);
756 virtual bool Create(wxBitmap
*WXUNUSED(bitmap
),
757 const void* WXUNUSED(data
),
758 long WXUNUSED(flags
),
760 int WXUNUSED(height
),
761 int WXUNUSED(depth
) = 1)
764 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
765 int desiredWidth
, int desiredHeight
);
766 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
767 int type
, const wxPalette
*palette
= NULL
);
770 wxICOBitmapHandler::wxICOBitmapHandler(wxBitmapType type
,
771 const wxString
& extension
,
772 const wxString
& name
)
777 SetExtension(extension
);
780 bool wxICOBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
,
782 int WXUNUSED(desiredWidth
),
783 int WXUNUSED(desiredHeight
))
788 if ( flags
== wxBITMAP_TYPE_ICO_RESOURCE
)
789 icon
= MGL_loadIcon(wxString(name
+ wxT(".ico")).mb_str(), TRUE
);
791 icon
= MGL_loadIcon(name
.mb_str(), TRUE
);
793 if ( icon
== NULL
) return false;
795 bitmap
->Create(icon
->xorMask
.width
, icon
->xorMask
.height
);
798 mem
.SelectObject(*bitmap
);
800 dc
->putBitmap(0, 0, &(icon
->xorMask
), MGL_REPLACE_MODE
);
801 mem
.SelectObject(wxNullBitmap
);
803 wxBitmap
mask(icon
->xorMask
.width
, icon
->xorMask
.height
, 1);
804 mem
.SelectObject(mask
);
807 wxCurrentDCSwitcher
curDC(dc
);
811 dc
->putMonoImage(0, 0, icon
->xorMask
.width
, icon
->byteWidth
,
812 icon
->xorMask
.height
, (void*)icon
->andMask
);
814 bitmap
->SetMask(new wxMask(mask
));
816 MGL_unloadIcon(icon
);
821 bool wxICOBitmapHandler::SaveFile(const wxBitmap
*WXUNUSED(bitmap
),
822 const wxString
& WXUNUSED(name
),
824 const wxPalette
* WXUNUSED(palette
))
832 /*static*/ void wxBitmap::InitStandardHandlers()
834 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_BMP
, wxT("bmp"), wxT("Windows bitmap")));
835 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_BMP_RESOURCE
, wxEmptyString
, wxT("Windows bitmap resource")));
836 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_JPEG
, wxT("jpg"), wxT("JPEG image")));
837 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_JPEG_RESOURCE
, wxEmptyString
, wxT("JPEG resource")));
838 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_PCX
, wxT("pcx"), wxT("PCX image")));
839 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_PCX_RESOURCE
, wxEmptyString
, wxT("PCX resource")));
841 AddHandler(new wxPNGBitmapHandler(wxBITMAP_TYPE_PNG
, wxT("png"), wxT("PNG image")));
842 AddHandler(new wxPNGBitmapHandler(wxBITMAP_TYPE_PNG_RESOURCE
, wxEmptyString
, wxT("PNG resource")));
844 AddHandler(new wxICOBitmapHandler(wxBITMAP_TYPE_ICO
, wxT("ico"), wxT("Icon resource")));
845 AddHandler(new wxICOBitmapHandler(wxBITMAP_TYPE_ICO_RESOURCE
, wxEmptyString
, wxT("Icon resource")));