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();
71 wxBitmapRefData::wxBitmapRefData()
81 wxBitmapRefData::~wxBitmapRefData()
84 MGL_unloadBitmap(m_bitmap
);
89 //-----------------------------------------------------------------------------
91 #define M_BMPDATA ((wxBitmapRefData *)m_refData)
94 IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandler
, wxBitmapHandlerBase
)
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 bool wxBitmap::IsOk() const
272 return (m_refData
!= NULL
&& M_BMPDATA
->m_bitmap
!= NULL
);
275 int wxBitmap::GetHeight() const
277 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
279 return M_BMPDATA
->m_height
;
282 int wxBitmap::GetWidth() const
284 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
286 return M_BMPDATA
->m_width
;
289 int wxBitmap::GetDepth() const
291 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
293 return M_BMPDATA
->m_bpp
;
296 wxMask
*wxBitmap::GetMask() const
298 wxCHECK_MSG( Ok(), (wxMask
*) NULL
, wxT("invalid bitmap") );
300 return M_BMPDATA
->m_mask
;
303 void wxBitmap::SetMask(wxMask
*mask
)
305 wxCHECK_RET( Ok(), wxT("invalid bitmap") );
308 delete M_BMPDATA
->m_mask
;
309 M_BMPDATA
->m_mask
= mask
;
312 bool wxBitmap::CopyFromIcon(const wxIcon
& icon
)
314 wxBitmap
*bmp
= (wxBitmap
*)(&icon
);
319 wxBitmap
wxBitmap::GetSubBitmap(const wxRect
& rect
) const
322 (rect
.x
>= 0) && (rect
.y
>= 0) &&
323 (rect
.x
+rect
.width
<= M_BMPDATA
->m_width
) && (rect
.y
+rect
.height
<= M_BMPDATA
->m_height
),
324 wxNullBitmap
, wxT("invalid bitmap or bitmap region") );
326 wxBitmap
ret( rect
.width
, rect
.height
, M_BMPDATA
->m_bpp
);
327 wxASSERT_MSG( ret
.Ok(), wxT("GetSubBitmap error") );
330 ret
.SetPalette(*GetPalette());
332 MGLDevCtx
*tdc
= ret
.CreateTmpDC();
333 tdc
->putBitmapSection(rect
.x
, rect
.y
,
334 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
335 0, 0, M_BMPDATA
->m_bitmap
, MGL_REPLACE_MODE
);
340 wxBitmap submask
= GetMask()->GetBitmap().GetSubBitmap(rect
);
341 ret
.SetMask(new wxMask(submask
));
347 void wxBitmap::SetMonoPalette(const wxColour
& fg
, const wxColour
& bg
)
349 wxCHECK_RET( Ok(), wxT("invalid bitmap") );
352 palette_t
*mono
= M_BMPDATA
->m_bitmap
->pal
;
354 wxCHECK_RET( M_BMPDATA
->m_bpp
== 1, wxT("bitmap is not 1bpp") );
355 wxCHECK_RET( mono
!= NULL
, wxT("bitmap w/o palette") );
357 mono
[0].red
= bg
.Red();
358 mono
[0].green
= bg
.Green();
359 mono
[0].blue
= bg
.Blue();
361 for (size_t i
= 1; i
< 256; i
++)
363 mono
[i
].red
= fg
.Red();
364 mono
[i
].green
= fg
.Green();
365 mono
[i
].blue
= fg
.Blue();
370 MGLDevCtx
*wxBitmap::CreateTmpDC() const
372 wxCHECK_MSG( Ok(), NULL
, wxT("invalid bitmap") );
374 MGLDevCtx
*tdc
= new MGLMemoryDC(GetWidth(), GetHeight(),
375 M_BMPDATA
->m_bitmap
->bitsPerPixel
,
376 M_BMPDATA
->m_bitmap
->pf
,
377 M_BMPDATA
->m_bitmap
->bytesPerLine
,
378 M_BMPDATA
->m_bitmap
->surface
,
380 wxCHECK_MSG( tdc
->isValid(), NULL
, wxT("cannot create temporary MGLDC") );
382 if ( M_BMPDATA
->m_bitmap
->pal
!= NULL
)
386 switch (M_BMPDATA
->m_bitmap
->bitsPerPixel
)
388 case 2: cnt
= 2; break;
389 case 4: cnt
= 16; break;
390 case 8: cnt
= 256; break;
393 wxFAIL_MSG( wxT("bitmap with this depth cannot have palette") );
397 tdc
->setPalette(M_BMPDATA
->m_bitmap
->pal
, cnt
, 0);
398 tdc
->realizePalette(cnt
, 0, FALSE
);
404 bool wxBitmap::LoadFile(const wxString
&name
, wxBitmapType type
)
408 if ( type
== wxBITMAP_TYPE_BMP
|| type
== wxBITMAP_TYPE_PNG
||
409 type
== wxBITMAP_TYPE_PCX
|| type
== wxBITMAP_TYPE_JPEG
)
411 // prevent accidental loading of bitmap from $MGL_ROOT:
412 if ( !wxFileExists(name
) )
414 wxLogError(_("File %s does not exist."), name
.c_str());
419 wxBitmapHandler
*handler
= FindHandler(type
);
421 if ( handler
== NULL
)
424 if ( !image
.LoadFile(name
, type
) || !image
.Ok() )
426 wxLogError("no bitmap handler for type %d defined.", type
);
431 *this = wxBitmap(image
);
436 m_refData
= new wxBitmapRefData();
438 return handler
->LoadFile(this, name
, type
, -1, -1);
441 bool wxBitmap::SaveFile(const wxString
& filename
, wxBitmapType type
, const wxPalette
*palette
) const
443 wxCHECK_MSG( Ok(), false, wxT("invalid bitmap") );
445 wxBitmapHandler
*handler
= FindHandler(type
);
447 if ( handler
== NULL
)
449 wxImage image
= ConvertToImage();
451 image
.SetPalette(*palette
);
454 return image
.SaveFile(filename
, type
);
457 wxLogError("no bitmap handler for type %d defined.", type
);
462 return handler
->SaveFile(this, filename
, type
, palette
);
465 wxPalette
*wxBitmap::GetPalette() const
467 wxCHECK_MSG( Ok(), NULL
, wxT("invalid bitmap") );
469 return M_BMPDATA
->m_palette
;
472 void wxBitmap::SetPalette(const wxPalette
& palette
)
474 wxCHECK_RET( Ok(), wxT("invalid bitmap") );
475 wxCHECK_RET( GetDepth() > 1 && GetDepth() <= 8, wxT("cannot set palette for bitmap of this depth") );
478 delete M_BMPDATA
->m_palette
;
479 M_BMPDATA
->m_palette
= NULL
;
481 if ( !palette
.Ok() ) return;
483 M_BMPDATA
->m_palette
= new wxPalette(palette
);
485 int cnt
= palette
.GetColoursCount();
486 palette_t
*pal
= palette
.GetMGLpalette_t();
487 memcpy(M_BMPDATA
->m_bitmap
->pal
, pal
, cnt
* sizeof(palette_t
));
490 void wxBitmap::SetHeight(int height
)
494 M_BMPDATA
->m_height
= height
;
497 void wxBitmap::SetWidth(int width
)
501 M_BMPDATA
->m_width
= width
;
504 void wxBitmap::SetDepth(int depth
)
508 M_BMPDATA
->m_bpp
= depth
;
511 bitmap_t
*wxBitmap::GetMGLbitmap_t() const
513 return M_BMPDATA
->m_bitmap
;
516 // Convert wxColour into it's quantized value in lower-precision
517 // pixel format (needed for masking by colour).
518 wxColour
wxBitmap::QuantizeColour(const wxColour
& clr
) const
520 pixel_format_t
*pf
= GetMGLbitmap_t()->pf
;
522 if ( pf
->redAdjust
== 0 && pf
->greenAdjust
== 0 && pf
->blueAdjust
== 0 )
525 return wxColour((unsigned char)((clr
.Red() >> pf
->redAdjust
) << pf
->redAdjust
),
526 (unsigned char)((clr
.Green() >> pf
->greenAdjust
) << pf
->greenAdjust
),
527 (unsigned char)((clr
.Blue() >> pf
->blueAdjust
) << pf
->blueAdjust
));
531 //-----------------------------------------------------------------------------
532 // wxBitmap I/O handlers
533 //-----------------------------------------------------------------------------
535 class wxMGLBitmapHandler
: public wxBitmapHandler
538 wxMGLBitmapHandler(wxBitmapType type
,
539 const wxString
& extension
, const wxString
& name
);
541 virtual bool Create(wxBitmap
*WXUNUSED(bitmap
),
542 const void* WXUNUSED(data
),
543 long WXUNUSED(flags
),
545 int WXUNUSED(height
),
546 int WXUNUSED(depth
) = 1)
549 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
550 int desiredWidth
, int desiredHeight
);
551 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
552 int type
, const wxPalette
*palette
= NULL
);
555 wxMGLBitmapHandler::wxMGLBitmapHandler(wxBitmapType type
,
556 const wxString
& extension
,
557 const wxString
& name
)
562 SetExtension(extension
);
565 bool wxMGLBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
,
567 int WXUNUSED(desiredWidth
),
568 int WXUNUSED(desiredHeight
))
570 int width
, height
, bpp
;
577 case wxBITMAP_TYPE_BMP_RESOURCE
:
578 case wxBITMAP_TYPE_JPEG_RESOURCE
:
579 case wxBITMAP_TYPE_PNG_RESOURCE
:
580 case wxBITMAP_TYPE_PCX_RESOURCE
:
581 fullname
= name
+ wxT(".bmp");
590 case wxBITMAP_TYPE_BMP
:
591 case wxBITMAP_TYPE_BMP_RESOURCE
:
592 if ( !MGL_getBitmapSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
594 bitmap
->Create(width
, height
, -1);
595 if ( !bitmap
->Ok() ) return false;
596 dc
.SelectObject(*bitmap
);
597 if ( !dc
.GetMGLDC()->loadBitmapIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
601 case wxBITMAP_TYPE_JPEG
:
602 case wxBITMAP_TYPE_JPEG_RESOURCE
:
603 if ( !MGL_getJPEGSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
605 bitmap
->Create(width
, height
, -1);
606 if ( !bitmap
->Ok() ) return false;
607 dc
.SelectObject(*bitmap
);
608 if ( !dc
.GetMGLDC()->loadJPEGIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
612 case wxBITMAP_TYPE_PNG
:
613 case wxBITMAP_TYPE_PNG_RESOURCE
:
614 if ( !MGL_getPNGSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
616 bitmap
->Create(width
, height
, -1);
617 if ( !bitmap
->Ok() ) return false;
618 dc
.SelectObject(*bitmap
);
619 if ( !dc
.GetMGLDC()->loadPNGIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
623 case wxBITMAP_TYPE_PCX
:
624 case wxBITMAP_TYPE_PCX_RESOURCE
:
625 if ( !MGL_getPCXSize(fullname
.mb_str(), &width
, &height
, &bpp
) )
627 bitmap
->Create(width
, height
, -1);
628 if ( !bitmap
->Ok() ) return false;
629 dc
.SelectObject(*bitmap
);
630 if ( !dc
.GetMGLDC()->loadPCXIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
635 wxFAIL_MSG(wxT("Unsupported image format."));
642 bool wxMGLBitmapHandler::SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
643 int type
, const wxPalette
* WXUNUSED(palette
))
647 int w
= bitmap
->GetWidth(),
648 h
= bitmap
->GetHeight();
650 mem
.SelectObjectAsSource(*bitmap
);
651 tdc
= mem
.GetMGLDC();
655 case wxBITMAP_TYPE_BMP
:
656 return (bool)tdc
->saveBitmapFromDC(name
.mb_str(), 0, 0, w
, h
);
657 case wxBITMAP_TYPE_JPEG
:
658 return (bool)tdc
->saveJPEGFromDC(name
.mb_str(), 0, 0, w
, h
, 75);
659 case wxBITMAP_TYPE_PNG
:
660 return (bool)tdc
->savePNGFromDC(name
.mb_str(), 0, 0, w
, h
);
661 case wxBITMAP_TYPE_PCX
:
662 return (bool)tdc
->savePCXFromDC(name
.mb_str(), 0, 0, w
, h
);
670 // let's handle PNGs in special way because they have alpha channel
671 // which we can access via bitmap_t most easily
672 class wxPNGBitmapHandler
: public wxMGLBitmapHandler
675 wxPNGBitmapHandler(wxBitmapType type
,
676 const wxString
& extension
, const wxString
& name
)
677 : wxMGLBitmapHandler(type
, extension
, name
) {}
679 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
680 int desiredWidth
, int desiredHeight
);
683 bool wxPNGBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
,
685 int desiredWidth
, int desiredHeight
)
687 int width
, height
, bpp
;
691 if ( flags
== wxBITMAP_TYPE_PNG_RESOURCE
)
692 fullname
= name
+ wxT(".png");
696 if ( !MGL_getPNGSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
701 // We can load ordinary PNGs faster with 'normal' MGL handler.
702 // Only RGBA PNGs need to be processed in special way because
703 // we have to convert alpha channel to mask
704 return wxMGLBitmapHandler::LoadFile(bitmap
, name
, flags
,
705 desiredWidth
, desiredHeight
);
708 bitmap_t
*bmp
= MGL_loadPNG(fullname
.mb_str(), TRUE
);
710 if ( bmp
== NULL
) return false;
712 bitmap
->Create(bmp
->width
, bmp
->height
, -1);
713 if ( !bitmap
->Ok() ) return false;
715 // convert bmp to display's depth and write it to *bitmap:
717 dc
.SelectObject(*bitmap
);
718 dc
.GetMGLDC()->putBitmap(0, 0, bmp
, MGL_REPLACE_MODE
);
719 dc
.SelectObject(wxNullBitmap
);
721 // create mask, if bmp contains alpha channel (ARGB format):
722 if ( bmp
->bitsPerPixel
== 32 )
725 wxUint32
*s
= (wxUint32
*)bmp
->surface
;
726 for (y
= 0; y
< bmp
->height
; y
++)
728 s
= ((wxUint32
*)bmp
->surface
) + y
* bmp
->bytesPerLine
/4;
729 for (x
= 0; x
< bmp
->width
; x
++, s
++)
731 if ( ((((*s
) >> bmp
->pf
->alphaPos
) & bmp
->pf
->alphaMask
)
732 << bmp
->pf
->alphaAdjust
) < 128 )
735 *s
= 0x00FFFFFF; // white
738 wxBitmap
mask(bmp
->width
, bmp
->height
, 1);
739 dc
.SelectObject(mask
);
740 dc
.GetMGLDC()->putBitmap(0, 0, bmp
, MGL_REPLACE_MODE
);
741 dc
.SelectObject(wxNullBitmap
);
742 bitmap
->SetMask(new wxMask(mask
));
745 MGL_unloadBitmap(bmp
);
753 class wxICOBitmapHandler
: public wxBitmapHandler
756 wxICOBitmapHandler(wxBitmapType type
,
757 const wxString
& extension
, const wxString
& name
);
759 virtual bool Create(wxBitmap
*WXUNUSED(bitmap
),
760 const void* WXUNUSED(data
),
761 long WXUNUSED(flags
),
763 int WXUNUSED(height
),
764 int WXUNUSED(depth
) = 1)
767 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
768 int desiredWidth
, int desiredHeight
);
769 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
770 int type
, const wxPalette
*palette
= NULL
);
773 wxICOBitmapHandler::wxICOBitmapHandler(wxBitmapType type
,
774 const wxString
& extension
,
775 const wxString
& name
)
780 SetExtension(extension
);
783 bool wxICOBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
,
785 int WXUNUSED(desiredWidth
),
786 int WXUNUSED(desiredHeight
))
791 if ( flags
== wxBITMAP_TYPE_ICO_RESOURCE
)
792 icon
= MGL_loadIcon(wxString(name
+ wxT(".ico")).mb_str(), TRUE
);
794 icon
= MGL_loadIcon(name
.mb_str(), TRUE
);
796 if ( icon
== NULL
) return false;
798 bitmap
->Create(icon
->xorMask
.width
, icon
->xorMask
.height
);
801 mem
.SelectObject(*bitmap
);
803 dc
->putBitmap(0, 0, &(icon
->xorMask
), MGL_REPLACE_MODE
);
804 mem
.SelectObject(wxNullBitmap
);
806 wxBitmap
mask(icon
->xorMask
.width
, icon
->xorMask
.height
, 1);
807 mem
.SelectObject(mask
);
810 wxCurrentDCSwitcher
curDC(dc
);
814 dc
->putMonoImage(0, 0, icon
->xorMask
.width
, icon
->byteWidth
,
815 icon
->xorMask
.height
, (void*)icon
->andMask
);
817 bitmap
->SetMask(new wxMask(mask
));
819 MGL_unloadIcon(icon
);
824 bool wxICOBitmapHandler::SaveFile(const wxBitmap
*WXUNUSED(bitmap
),
825 const wxString
& WXUNUSED(name
),
827 const wxPalette
* WXUNUSED(palette
))
835 /*static*/ void wxBitmap::InitStandardHandlers()
837 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_BMP
, wxT("bmp"), wxT("Windows bitmap")));
838 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_BMP_RESOURCE
, wxEmptyString
, wxT("Windows bitmap resource")));
839 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_JPEG
, wxT("jpg"), wxT("JPEG image")));
840 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_JPEG_RESOURCE
, wxEmptyString
, wxT("JPEG resource")));
841 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_PCX
, wxT("pcx"), wxT("PCX image")));
842 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_PCX_RESOURCE
, wxEmptyString
, wxT("PCX resource")));
844 AddHandler(new wxPNGBitmapHandler(wxBITMAP_TYPE_PNG
, wxT("png"), wxT("PNG image")));
845 AddHandler(new wxPNGBitmapHandler(wxBITMAP_TYPE_PNG_RESOURCE
, wxEmptyString
, wxT("PNG resource")));
847 AddHandler(new wxICOBitmapHandler(wxBITMAP_TYPE_ICO
, wxT("ico"), wxT("Icon resource")));
848 AddHandler(new wxICOBitmapHandler(wxBITMAP_TYPE_ICO_RESOURCE
, wxEmptyString
, wxT("Icon resource")));