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)
95 IMPLEMENT_DYNAMIC_CLASS(wxBitmap
,wxBitmapBase
)
97 wxBitmap::wxBitmap(int width
, int height
, int depth
)
99 Create(width
, height
, depth
);
103 static bitmap_t
*MyMGL_createBitmap(int width
, int height
,
104 int bpp
, pixel_format_t
*pf
)
106 MGLMemoryDC
mdc(width
, height
, bpp
, pf
);
107 return MGL_getBitmapFromDC(mdc
.getDC(), 0, 0, width
, height
, TRUE
);
110 bool wxBitmap::Create(int width
, int height
, int depth
)
114 wxCHECK_MSG( (width
> 0) && (height
> 0), false, wxT("invalid bitmap size") );
116 pixel_format_t pf_dummy
;
118 int mglDepth
= depth
;
123 wxASSERT_MSG( g_displayDC
, wxT("MGL display DC not created yet.") );
125 g_displayDC
->getPixelFormat(pf_dummy
);
126 mglDepth
= g_displayDC
->getBitsPerPixel();
134 pf
= &gs_pixel_format_15
;
137 pf
= &gs_pixel_format_16
;
140 pf
= &gs_pixel_format_24
;
143 pf
= &gs_pixel_format_32
;
146 wxFAIL_MSG(wxT("invalid bitmap depth"));
150 m_refData
= new wxBitmapRefData();
151 M_BMPDATA
->m_mask
= (wxMask
*) NULL
;
152 M_BMPDATA
->m_palette
= (wxPalette
*) NULL
;
153 M_BMPDATA
->m_width
= width
;
154 M_BMPDATA
->m_height
= height
;
155 M_BMPDATA
->m_bpp
= mglDepth
;
159 M_BMPDATA
->m_bitmap
= MyMGL_createBitmap(width
, height
, mglDepth
, pf
);
163 // MGL does not support mono DCs, so we have to emulate them with
164 // 8bpp ones. We do that by using a special palette with color 0
165 // set to black and all other colors set to white.
167 M_BMPDATA
->m_bitmap
= MyMGL_createBitmap(width
, height
, 8, pf
);
168 SetMonoPalette(wxColour(255, 255, 255), wxColour(0, 0, 0));
174 wxBitmap::wxBitmap(const wxImage
& image
, int depth
)
178 wxCHECK_RET( image
.Ok(), wxT("invalid image") );
180 width
= image
.GetWidth();
181 height
= image
.GetHeight();
183 if ( !Create(width
, height
, depth
) ) return;
185 MGLMemoryDC
idc(width
, height
, 24, &gs_pixel_format_wxImage
,
186 width
* 3, (void*)image
.GetData(), NULL
);
187 wxASSERT_MSG( idc
.isValid(), wxT("cannot create custom MGLDC") );
189 MGLDevCtx
*bdc
= CreateTmpDC();
191 if ( GetDepth() <= 8 && image
.HasPalette() )
192 SetPalette(image
.GetPalette());
194 bdc
->bitBlt(idc
, 0, 0, width
, height
, 0, 0, MGL_REPLACE_MODE
);
197 if ( image
.HasMask() )
199 wxImage mask_image
= image
.ConvertToMono(image
.GetMaskRed(),
200 image
.GetMaskGreen(),
201 image
.GetMaskBlue());
202 mask_image
.SetMask(false);
203 wxBitmap
mask_bmp(mask_image
, 1);
204 SetMask(new wxMask(mask_bmp
));
208 wxImage
wxBitmap::ConvertToImage() const
210 wxCHECK_MSG( Ok(), wxImage(), wxT("invalid bitmap") );
214 height
= GetHeight();
216 wxImage
image(width
, height
);
217 wxASSERT_MSG( image
.Ok(), wxT("cannot create image") );
219 MGLMemoryDC
idc(width
, height
, 24, &gs_pixel_format_wxImage
,
220 width
* 3, (void*)image
.GetData(), NULL
);
221 wxASSERT_MSG( idc
.isValid(), wxT("cannot create custom MGLDC") );
223 if ( M_BMPDATA
->m_palette
)
224 image
.SetPalette(*(M_BMPDATA
->m_palette
));
228 // in consistency with other ports, we convert parts covered
229 // by the mask to <16,16,16> colour and set that colour to image's
230 // mask. We do that by OR-blitting the mask over image with
231 // bg colour set to black and fg colour to <16,16,16>
233 image
.SetMaskColour(16, 16, 16);
237 tmpDC
.SetMGLDC(&idc
, false);
238 tmpDC
.SetBackground(wxBrush(wxColour(16,16,16), wxSOLID
));
240 tmpDC
.DrawBitmap(*this, 0, 0, true);
244 image
.SetMask(false);
245 idc
.putBitmap(0, 0, M_BMPDATA
->m_bitmap
, MGL_REPLACE_MODE
);
251 wxBitmap::wxBitmap(const wxString
&filename
, wxBitmapType type
)
253 LoadFile(filename
, type
);
256 wxBitmap::wxBitmap(const char bits
[], int width
, int height
, int depth
)
258 wxCHECK_RET( depth
== 1, wxT("can only create mono bitmap from XBM data") );
260 if ( !Create(width
, height
, 1) ) return;
261 MGLDevCtx
*bdc
= CreateTmpDC();
262 wxCurrentDCSwitcher
curDC(bdc
);
264 bdc
->setBackColor(0);
266 bdc
->putMonoImage(0, 0, width
, (width
+ 7) / 8, height
, (void*)bits
);
270 int wxBitmap::GetHeight() const
272 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
274 return M_BMPDATA
->m_height
;
277 int wxBitmap::GetWidth() const
279 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
281 return M_BMPDATA
->m_width
;
284 int wxBitmap::GetDepth() const
286 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
288 return M_BMPDATA
->m_bpp
;
291 wxMask
*wxBitmap::GetMask() const
293 wxCHECK_MSG( Ok(), (wxMask
*) NULL
, wxT("invalid bitmap") );
295 return M_BMPDATA
->m_mask
;
298 void wxBitmap::SetMask(wxMask
*mask
)
300 wxCHECK_RET( Ok(), wxT("invalid bitmap") );
303 delete M_BMPDATA
->m_mask
;
304 M_BMPDATA
->m_mask
= mask
;
307 bool wxBitmap::CopyFromIcon(const wxIcon
& icon
)
309 wxBitmap
*bmp
= (wxBitmap
*)(&icon
);
314 wxBitmap
wxBitmap::GetSubBitmap(const wxRect
& rect
) const
317 (rect
.x
>= 0) && (rect
.y
>= 0) &&
318 (rect
.x
+rect
.width
<= M_BMPDATA
->m_width
) && (rect
.y
+rect
.height
<= M_BMPDATA
->m_height
),
319 wxNullBitmap
, wxT("invalid bitmap or bitmap region") );
321 wxBitmap
ret( rect
.width
, rect
.height
, M_BMPDATA
->m_bpp
);
322 wxASSERT_MSG( ret
.Ok(), wxT("GetSubBitmap error") );
325 ret
.SetPalette(*GetPalette());
327 MGLDevCtx
*tdc
= ret
.CreateTmpDC();
328 tdc
->putBitmapSection(rect
.x
, rect
.y
,
329 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
330 0, 0, M_BMPDATA
->m_bitmap
, MGL_REPLACE_MODE
);
335 wxBitmap submask
= GetMask()->GetBitmap().GetSubBitmap(rect
);
336 ret
.SetMask(new wxMask(submask
));
342 void wxBitmap::SetMonoPalette(const wxColour
& fg
, const wxColour
& bg
)
344 wxCHECK_RET( Ok(), wxT("invalid bitmap") );
347 palette_t
*mono
= M_BMPDATA
->m_bitmap
->pal
;
349 wxCHECK_RET( M_BMPDATA
->m_bpp
== 1, wxT("bitmap is not 1bpp") );
350 wxCHECK_RET( mono
!= NULL
, wxT("bitmap w/o palette") );
352 mono
[0].red
= bg
.Red();
353 mono
[0].green
= bg
.Green();
354 mono
[0].blue
= bg
.Blue();
356 for (size_t i
= 1; i
< 256; i
++)
358 mono
[i
].red
= fg
.Red();
359 mono
[i
].green
= fg
.Green();
360 mono
[i
].blue
= fg
.Blue();
365 MGLDevCtx
*wxBitmap::CreateTmpDC() const
367 wxCHECK_MSG( Ok(), NULL
, wxT("invalid bitmap") );
369 MGLDevCtx
*tdc
= new MGLMemoryDC(GetWidth(), GetHeight(),
370 M_BMPDATA
->m_bitmap
->bitsPerPixel
,
371 M_BMPDATA
->m_bitmap
->pf
,
372 M_BMPDATA
->m_bitmap
->bytesPerLine
,
373 M_BMPDATA
->m_bitmap
->surface
,
375 wxCHECK_MSG( tdc
->isValid(), NULL
, wxT("cannot create temporary MGLDC") );
377 if ( M_BMPDATA
->m_bitmap
->pal
!= NULL
)
381 switch (M_BMPDATA
->m_bitmap
->bitsPerPixel
)
383 case 2: cnt
= 2; break;
384 case 4: cnt
= 16; break;
385 case 8: cnt
= 256; break;
388 wxFAIL_MSG( wxT("bitmap with this depth cannot have palette") );
392 tdc
->setPalette(M_BMPDATA
->m_bitmap
->pal
, cnt
, 0);
393 tdc
->realizePalette(cnt
, 0, FALSE
);
399 bool wxBitmap::LoadFile(const wxString
&name
, wxBitmapType type
)
403 if ( type
== wxBITMAP_TYPE_BMP
|| type
== wxBITMAP_TYPE_PNG
||
404 type
== wxBITMAP_TYPE_PCX
|| type
== wxBITMAP_TYPE_JPEG
)
406 // prevent accidental loading of bitmap from $MGL_ROOT:
407 if ( !wxFileExists(name
) )
409 wxLogError(_("File %s does not exist."), name
.c_str());
414 wxBitmapHandler
*handler
= FindHandler(type
);
416 if ( handler
== NULL
)
419 if ( !image
.LoadFile(name
, type
) || !image
.Ok() )
421 wxLogError("no bitmap handler for type %d defined.", type
);
426 *this = wxBitmap(image
);
431 m_refData
= new wxBitmapRefData();
433 return handler
->LoadFile(this, name
, type
, -1, -1);
436 bool wxBitmap::SaveFile(const wxString
& filename
, wxBitmapType type
, const wxPalette
*palette
) const
438 wxCHECK_MSG( Ok(), false, wxT("invalid bitmap") );
440 wxBitmapHandler
*handler
= FindHandler(type
);
442 if ( handler
== NULL
)
444 wxImage image
= ConvertToImage();
446 image
.SetPalette(*palette
);
449 return image
.SaveFile(filename
, type
);
452 wxLogError("no bitmap handler for type %d defined.", type
);
457 return handler
->SaveFile(this, filename
, type
, palette
);
460 wxPalette
*wxBitmap::GetPalette() const
462 wxCHECK_MSG( Ok(), NULL
, wxT("invalid bitmap") );
464 return M_BMPDATA
->m_palette
;
467 void wxBitmap::SetPalette(const wxPalette
& palette
)
469 wxCHECK_RET( Ok(), wxT("invalid bitmap") );
470 wxCHECK_RET( GetDepth() > 1 && GetDepth() <= 8, wxT("cannot set palette for bitmap of this depth") );
473 delete M_BMPDATA
->m_palette
;
474 M_BMPDATA
->m_palette
= NULL
;
476 if ( !palette
.Ok() ) return;
478 M_BMPDATA
->m_palette
= new wxPalette(palette
);
480 int cnt
= palette
.GetColoursCount();
481 palette_t
*pal
= palette
.GetMGLpalette_t();
482 memcpy(M_BMPDATA
->m_bitmap
->pal
, pal
, cnt
* sizeof(palette_t
));
485 void wxBitmap::SetHeight(int height
)
489 M_BMPDATA
->m_height
= height
;
492 void wxBitmap::SetWidth(int width
)
496 M_BMPDATA
->m_width
= width
;
499 void wxBitmap::SetDepth(int depth
)
503 M_BMPDATA
->m_bpp
= depth
;
506 bitmap_t
*wxBitmap::GetMGLbitmap_t() const
508 return M_BMPDATA
->m_bitmap
;
511 // Convert wxColour into it's quantized value in lower-precision
512 // pixel format (needed for masking by colour).
513 wxColour
wxBitmap::QuantizeColour(const wxColour
& clr
) const
515 pixel_format_t
*pf
= GetMGLbitmap_t()->pf
;
517 if ( pf
->redAdjust
== 0 && pf
->greenAdjust
== 0 && pf
->blueAdjust
== 0 )
520 return wxColour((unsigned char)((clr
.Red() >> pf
->redAdjust
) << pf
->redAdjust
),
521 (unsigned char)((clr
.Green() >> pf
->greenAdjust
) << pf
->greenAdjust
),
522 (unsigned char)((clr
.Blue() >> pf
->blueAdjust
) << pf
->blueAdjust
));
526 //-----------------------------------------------------------------------------
527 // wxBitmap I/O handlers
528 //-----------------------------------------------------------------------------
530 class wxMGLBitmapHandler
: public wxBitmapHandler
533 wxMGLBitmapHandler(wxBitmapType type
,
534 const wxString
& extension
, const wxString
& name
);
536 virtual bool Create(wxBitmap
*WXUNUSED(bitmap
),
537 const void* WXUNUSED(data
),
538 long WXUNUSED(flags
),
540 int WXUNUSED(height
),
541 int WXUNUSED(depth
) = 1)
544 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
545 int desiredWidth
, int desiredHeight
);
546 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
547 int type
, const wxPalette
*palette
= NULL
);
550 wxMGLBitmapHandler::wxMGLBitmapHandler(wxBitmapType type
,
551 const wxString
& extension
,
552 const wxString
& name
)
557 SetExtension(extension
);
560 bool wxMGLBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
,
562 int WXUNUSED(desiredWidth
),
563 int WXUNUSED(desiredHeight
))
565 int width
, height
, bpp
;
572 case wxBITMAP_TYPE_BMP_RESOURCE
:
573 case wxBITMAP_TYPE_JPEG_RESOURCE
:
574 case wxBITMAP_TYPE_PNG_RESOURCE
:
575 case wxBITMAP_TYPE_PCX_RESOURCE
:
576 fullname
= name
+ wxT(".bmp");
585 case wxBITMAP_TYPE_BMP
:
586 case wxBITMAP_TYPE_BMP_RESOURCE
:
587 if ( !MGL_getBitmapSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
589 bitmap
->Create(width
, height
, -1);
590 if ( !bitmap
->Ok() ) return false;
591 dc
.SelectObject(*bitmap
);
592 if ( !dc
.GetMGLDC()->loadBitmapIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
596 case wxBITMAP_TYPE_JPEG
:
597 case wxBITMAP_TYPE_JPEG_RESOURCE
:
598 if ( !MGL_getJPEGSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
600 bitmap
->Create(width
, height
, -1);
601 if ( !bitmap
->Ok() ) return false;
602 dc
.SelectObject(*bitmap
);
603 if ( !dc
.GetMGLDC()->loadJPEGIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
607 case wxBITMAP_TYPE_PNG
:
608 case wxBITMAP_TYPE_PNG_RESOURCE
:
609 if ( !MGL_getPNGSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
611 bitmap
->Create(width
, height
, -1);
612 if ( !bitmap
->Ok() ) return false;
613 dc
.SelectObject(*bitmap
);
614 if ( !dc
.GetMGLDC()->loadPNGIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
618 case wxBITMAP_TYPE_PCX
:
619 case wxBITMAP_TYPE_PCX_RESOURCE
:
620 if ( !MGL_getPCXSize(fullname
.mb_str(), &width
, &height
, &bpp
) )
622 bitmap
->Create(width
, height
, -1);
623 if ( !bitmap
->Ok() ) return false;
624 dc
.SelectObject(*bitmap
);
625 if ( !dc
.GetMGLDC()->loadPCXIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
630 wxFAIL_MSG(wxT("Unsupported image format."));
637 bool wxMGLBitmapHandler::SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
638 int type
, const wxPalette
* WXUNUSED(palette
))
642 int w
= bitmap
->GetWidth(),
643 h
= bitmap
->GetHeight();
645 mem
.SelectObjectAsSource(*bitmap
);
646 tdc
= mem
.GetMGLDC();
650 case wxBITMAP_TYPE_BMP
:
651 return (bool)tdc
->saveBitmapFromDC(name
.mb_str(), 0, 0, w
, h
);
652 case wxBITMAP_TYPE_JPEG
:
653 return (bool)tdc
->saveJPEGFromDC(name
.mb_str(), 0, 0, w
, h
, 75);
654 case wxBITMAP_TYPE_PNG
:
655 return (bool)tdc
->savePNGFromDC(name
.mb_str(), 0, 0, w
, h
);
656 case wxBITMAP_TYPE_PCX
:
657 return (bool)tdc
->savePCXFromDC(name
.mb_str(), 0, 0, w
, h
);
665 // let's handle PNGs in special way because they have alpha channel
666 // which we can access via bitmap_t most easily
667 class wxPNGBitmapHandler
: public wxMGLBitmapHandler
670 wxPNGBitmapHandler(wxBitmapType type
,
671 const wxString
& extension
, const wxString
& name
)
672 : wxMGLBitmapHandler(type
, extension
, name
) {}
674 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
675 int desiredWidth
, int desiredHeight
);
678 bool wxPNGBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
,
680 int desiredWidth
, int desiredHeight
)
682 int width
, height
, bpp
;
686 if ( flags
== wxBITMAP_TYPE_PNG_RESOURCE
)
687 fullname
= name
+ wxT(".png");
691 if ( !MGL_getPNGSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
696 // We can load ordinary PNGs faster with 'normal' MGL handler.
697 // Only RGBA PNGs need to be processed in special way because
698 // we have to convert alpha channel to mask
699 return wxMGLBitmapHandler::LoadFile(bitmap
, name
, flags
,
700 desiredWidth
, desiredHeight
);
703 bitmap_t
*bmp
= MGL_loadPNG(fullname
.mb_str(), TRUE
);
705 if ( bmp
== NULL
) return false;
707 bitmap
->Create(bmp
->width
, bmp
->height
, -1);
708 if ( !bitmap
->Ok() ) return false;
710 // convert bmp to display's depth and write it to *bitmap:
712 dc
.SelectObject(*bitmap
);
713 dc
.GetMGLDC()->putBitmap(0, 0, bmp
, MGL_REPLACE_MODE
);
714 dc
.SelectObject(wxNullBitmap
);
716 // create mask, if bmp contains alpha channel (ARGB format):
717 if ( bmp
->bitsPerPixel
== 32 )
720 wxUint32
*s
= (wxUint32
*)bmp
->surface
;
721 for (y
= 0; y
< bmp
->height
; y
++)
723 s
= ((wxUint32
*)bmp
->surface
) + y
* bmp
->bytesPerLine
/4;
724 for (x
= 0; x
< bmp
->width
; x
++, s
++)
726 if ( ((((*s
) >> bmp
->pf
->alphaPos
) & bmp
->pf
->alphaMask
)
727 << bmp
->pf
->alphaAdjust
) < 128 )
730 *s
= 0x00FFFFFF; // white
733 wxBitmap
mask(bmp
->width
, bmp
->height
, 1);
734 dc
.SelectObject(mask
);
735 dc
.GetMGLDC()->putBitmap(0, 0, bmp
, MGL_REPLACE_MODE
);
736 dc
.SelectObject(wxNullBitmap
);
737 bitmap
->SetMask(new wxMask(mask
));
740 MGL_unloadBitmap(bmp
);
748 class wxICOBitmapHandler
: public wxBitmapHandler
751 wxICOBitmapHandler(wxBitmapType type
,
752 const wxString
& extension
, const wxString
& name
);
754 virtual bool Create(wxBitmap
*WXUNUSED(bitmap
),
755 const void* WXUNUSED(data
),
756 long WXUNUSED(flags
),
758 int WXUNUSED(height
),
759 int WXUNUSED(depth
) = 1)
762 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
763 int desiredWidth
, int desiredHeight
);
764 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
765 int type
, const wxPalette
*palette
= NULL
);
768 wxICOBitmapHandler::wxICOBitmapHandler(wxBitmapType type
,
769 const wxString
& extension
,
770 const wxString
& name
)
775 SetExtension(extension
);
778 bool wxICOBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
,
780 int WXUNUSED(desiredWidth
),
781 int WXUNUSED(desiredHeight
))
786 if ( flags
== wxBITMAP_TYPE_ICO_RESOURCE
)
787 icon
= MGL_loadIcon(wxString(name
+ wxT(".ico")).mb_str(), TRUE
);
789 icon
= MGL_loadIcon(name
.mb_str(), TRUE
);
791 if ( icon
== NULL
) return false;
793 bitmap
->Create(icon
->xorMask
.width
, icon
->xorMask
.height
);
796 mem
.SelectObject(*bitmap
);
798 dc
->putBitmap(0, 0, &(icon
->xorMask
), MGL_REPLACE_MODE
);
799 mem
.SelectObject(wxNullBitmap
);
801 wxBitmap
mask(icon
->xorMask
.width
, icon
->xorMask
.height
, 1);
802 mem
.SelectObject(mask
);
805 wxCurrentDCSwitcher
curDC(dc
);
809 dc
->putMonoImage(0, 0, icon
->xorMask
.width
, icon
->byteWidth
,
810 icon
->xorMask
.height
, (void*)icon
->andMask
);
812 bitmap
->SetMask(new wxMask(mask
));
814 MGL_unloadIcon(icon
);
819 bool wxICOBitmapHandler::SaveFile(const wxBitmap
*WXUNUSED(bitmap
),
820 const wxString
& WXUNUSED(name
),
822 const wxPalette
* WXUNUSED(palette
))
830 /*static*/ void wxBitmap::InitStandardHandlers()
832 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_BMP
, wxT("bmp"), wxT("Windows bitmap")));
833 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_BMP_RESOURCE
, wxEmptyString
, wxT("Windows bitmap resource")));
834 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_JPEG
, wxT("jpg"), wxT("JPEG image")));
835 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_JPEG_RESOURCE
, wxEmptyString
, wxT("JPEG resource")));
836 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_PCX
, wxT("pcx"), wxT("PCX image")));
837 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_PCX_RESOURCE
, wxEmptyString
, wxT("PCX resource")));
839 AddHandler(new wxPNGBitmapHandler(wxBITMAP_TYPE_PNG
, wxT("png"), wxT("PNG image")));
840 AddHandler(new wxPNGBitmapHandler(wxBITMAP_TYPE_PNG_RESOURCE
, wxEmptyString
, wxT("PNG resource")));
842 AddHandler(new wxICOBitmapHandler(wxBITMAP_TYPE_ICO
, wxT("ico"), wxT("Icon resource")));
843 AddHandler(new wxICOBitmapHandler(wxBITMAP_TYPE_ICO_RESOURCE
, wxEmptyString
, wxT("Icon resource")));