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 static bitmap_t
*MyMGL_createBitmap(int width
, int height
,
35 int bpp
, pixel_format_t
*pf
)
37 MGLMemoryDC
mdc(width
, height
, bpp
, pf
);
38 return MGL_getBitmapFromDC(mdc
.getDC(), 0, 0, width
, height
, TRUE
);
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
45 static pixel_format_t gs_pixel_format_15
=
46 {0x1F,0x0A,3, 0x1F,0x05,3, 0x1F,0x00,3, 0x01,0x0F,7}; // 555 15bpp
48 static pixel_format_t gs_pixel_format_16
=
49 {0x1F,0x0B,3, 0x3F,0x05,2, 0x1F,0x00,3, 0x00,0x00,0}; // 565 16bpp
51 static pixel_format_t gs_pixel_format_24
=
52 {0xFF,0x10,0, 0xFF,0x08,0, 0xFF,0x00,0, 0x00,0x00,0}; // RGB 24bpp
54 static pixel_format_t gs_pixel_format_32
=
55 {0xFF,0x18,0, 0xFF,0x10,0, 0xFF,0x08,0, 0xFF,0x00,0}; // RGBA 32bpp
57 static pixel_format_t gs_pixel_format_wxImage
=
58 {0xFF,0x00,0, 0xFF,0x08,0, 0xFF,0x10,0, 0x00,0x00,0}; // RGB 24bpp for wxImage
60 //-----------------------------------------------------------------------------
62 //-----------------------------------------------------------------------------
64 class wxBitmapRefData
: public wxGDIRefData
68 wxBitmapRefData(int width
, int height
, int bpp
);
69 wxBitmapRefData(const wxBitmapRefData
& data
);
70 virtual ~wxBitmapRefData();
72 virtual bool IsOk() const { return m_bitmap
!= NULL
; }
82 void DoCreateBitmap(int width
, int height
, int depth
);
85 void wxBitmapRefData::DoCreateBitmap(int width
, int height
, int depth
)
91 pixel_format_t pf_dummy
;
98 wxASSERT_MSG( g_displayDC
, wxT("MGL display DC not created yet.") );
100 g_displayDC
->getPixelFormat(pf_dummy
);
101 mglDepth
= g_displayDC
->getBitsPerPixel();
107 mglDepth
= 8; // we emulate monochrome bitmaps using 8 bit ones
110 pf
= &gs_pixel_format_15
;
113 pf
= &gs_pixel_format_16
;
116 pf
= &gs_pixel_format_24
;
119 pf
= &gs_pixel_format_32
;
122 wxFAIL_MSG(wxT("invalid bitmap depth"));
127 m_bitmap
= MyMGL_createBitmap(width
, height
, mglDepth
, pf
);
130 wxBitmapRefData::wxBitmapRefData()
142 wxBitmapRefData::wxBitmapRefData(int width
, int height
, int bpp
)
144 DoCreateBitmap(width
, height
, bpp
);
150 wxBitmapRefData::wxBitmapRefData(const wxBitmapRefData
& data
)
152 DoCreateBitmap(data
.m_width
, data
.m_height
, data
.m_bpp
);
154 m_palette
= NULL
; // FIXME: should copy
155 m_mask
= NULL
; // FIXME: should copy
158 wxBitmapRefData::~wxBitmapRefData()
161 MGL_unloadBitmap(m_bitmap
);
167 //-----------------------------------------------------------------------------
169 //-----------------------------------------------------------------------------
171 #define M_BMPDATA ((wxBitmapRefData *)m_refData)
173 IMPLEMENT_DYNAMIC_CLASS(wxBitmap
,wxBitmapBase
)
175 wxGDIRefData
*wxBitmap::CreateGDIRefData() const
177 return new wxBitmapRefData
;
180 wxGDIRefData
*wxBitmap::CloneGDIRefData(const wxGDIRefData
*data
) const
182 return new wxBitmapRefData(*static_cast<const wxBitmapRefData
*>(data
));
185 bool wxBitmap::Create(int width
, int height
, int depth
)
189 wxCHECK_MSG( (width
> 0) && (height
> 0), false, wxT("invalid bitmap size") );
191 m_refData
= new wxBitmapRefData(width
, height
, depth
);
195 // MGL does not support mono DCs, so we have to emulate them with
196 // 8bpp ones. We do that by using a special palette with color 0
197 // set to black and all other colors set to white.
198 SetMonoPalette(wxColour(255, 255, 255), wxColour(0, 0, 0));
204 wxBitmap::wxBitmap(const wxImage
& image
, int depth
)
208 wxCHECK_RET( image
.Ok(), wxT("invalid image") );
210 width
= image
.GetWidth();
211 height
= image
.GetHeight();
213 if ( !Create(width
, height
, depth
) ) return;
215 MGLMemoryDC
idc(width
, height
, 24, &gs_pixel_format_wxImage
,
216 width
* 3, (void*)image
.GetData(), NULL
);
217 wxASSERT_MSG( idc
.isValid(), wxT("cannot create custom MGLDC") );
219 MGLDevCtx
*bdc
= CreateTmpDC();
221 if ( GetDepth() <= 8 && image
.HasPalette() )
222 SetPalette(image
.GetPalette());
224 bdc
->bitBlt(idc
, 0, 0, width
, height
, 0, 0, MGL_REPLACE_MODE
);
227 if ( image
.HasMask() )
229 wxImage mask_image
= image
.ConvertToMono(image
.GetMaskRed(),
230 image
.GetMaskGreen(),
231 image
.GetMaskBlue());
232 mask_image
.SetMask(false);
233 wxBitmap
mask_bmp(mask_image
, 1);
234 SetMask(new wxMask(mask_bmp
));
238 wxImage
wxBitmap::ConvertToImage() const
240 wxCHECK_MSG( Ok(), wxImage(), wxT("invalid bitmap") );
244 height
= GetHeight();
246 wxImage
image(width
, height
);
247 wxASSERT_MSG( image
.Ok(), wxT("cannot create image") );
249 MGLMemoryDC
idc(width
, height
, 24, &gs_pixel_format_wxImage
,
250 width
* 3, (void*)image
.GetData(), NULL
);
251 wxASSERT_MSG( idc
.isValid(), wxT("cannot create custom MGLDC") );
253 if ( M_BMPDATA
->m_palette
)
254 image
.SetPalette(*(M_BMPDATA
->m_palette
));
258 // in consistency with other ports, we convert parts covered
259 // by the mask to <16,16,16> colour and set that colour to image's
260 // mask. We do that by OR-blitting the mask over image with
261 // bg colour set to black and fg colour to <16,16,16>
263 image
.SetMaskColour(16, 16, 16);
267 tmpDC
.SetMGLDC(&idc
, false);
268 tmpDC
.SetBackground(wxBrush(wxColour(16,16,16), wxSOLID
));
270 tmpDC
.DrawBitmap(*this, 0, 0, true);
274 image
.SetMask(false);
275 idc
.putBitmap(0, 0, M_BMPDATA
->m_bitmap
, MGL_REPLACE_MODE
);
281 wxBitmap::wxBitmap(const wxString
&filename
, wxBitmapType type
)
283 LoadFile(filename
, type
);
286 wxBitmap::wxBitmap(const char bits
[], int width
, int height
, int depth
)
288 wxCHECK_RET( depth
== 1, wxT("can only create mono bitmap from XBM data") );
290 if ( !Create(width
, height
, 1) ) return;
291 MGLDevCtx
*bdc
= CreateTmpDC();
292 wxCurrentDCSwitcher
curDC(bdc
);
294 bdc
->setBackColor(0);
296 bdc
->putMonoImage(0, 0, width
, (width
+ 7) / 8, height
, (void*)bits
);
300 int wxBitmap::GetHeight() const
302 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
304 return M_BMPDATA
->m_height
;
307 int wxBitmap::GetWidth() const
309 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
311 return M_BMPDATA
->m_width
;
314 int wxBitmap::GetDepth() const
316 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
318 return M_BMPDATA
->m_bpp
;
321 wxMask
*wxBitmap::GetMask() const
323 wxCHECK_MSG( Ok(), NULL
, wxT("invalid bitmap") );
325 return M_BMPDATA
->m_mask
;
328 void wxBitmap::SetMask(wxMask
*mask
)
330 wxCHECK_RET( Ok(), wxT("invalid bitmap") );
333 delete M_BMPDATA
->m_mask
;
334 M_BMPDATA
->m_mask
= mask
;
337 bool wxBitmap::CopyFromIcon(const wxIcon
& icon
)
339 wxBitmap
*bmp
= (wxBitmap
*)(&icon
);
344 wxBitmap
wxBitmap::GetSubBitmap(const wxRect
& rect
) const
347 (rect
.x
>= 0) && (rect
.y
>= 0) &&
348 (rect
.x
+rect
.width
<= M_BMPDATA
->m_width
) && (rect
.y
+rect
.height
<= M_BMPDATA
->m_height
),
349 wxNullBitmap
, wxT("invalid bitmap or bitmap region") );
351 wxBitmap
ret( rect
.width
, rect
.height
, M_BMPDATA
->m_bpp
);
352 wxASSERT_MSG( ret
.Ok(), wxT("GetSubBitmap error") );
355 ret
.SetPalette(*GetPalette());
357 MGLDevCtx
*tdc
= ret
.CreateTmpDC();
358 tdc
->putBitmapSection(rect
.x
, rect
.y
,
359 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
360 0, 0, M_BMPDATA
->m_bitmap
, MGL_REPLACE_MODE
);
365 wxBitmap submask
= GetMask()->GetBitmap().GetSubBitmap(rect
);
366 ret
.SetMask(new wxMask(submask
));
372 void wxBitmap::SetMonoPalette(const wxColour
& fg
, const wxColour
& bg
)
374 wxCHECK_RET( Ok(), wxT("invalid bitmap") );
377 palette_t
*mono
= M_BMPDATA
->m_bitmap
->pal
;
379 wxCHECK_RET( M_BMPDATA
->m_bpp
== 1, wxT("bitmap is not 1bpp") );
380 wxCHECK_RET( mono
!= NULL
, wxT("bitmap w/o palette") );
382 mono
[0].red
= bg
.Red();
383 mono
[0].green
= bg
.Green();
384 mono
[0].blue
= bg
.Blue();
386 for (size_t i
= 1; i
< 256; i
++)
388 mono
[i
].red
= fg
.Red();
389 mono
[i
].green
= fg
.Green();
390 mono
[i
].blue
= fg
.Blue();
395 MGLDevCtx
*wxBitmap::CreateTmpDC() const
397 wxCHECK_MSG( Ok(), NULL
, wxT("invalid bitmap") );
399 MGLDevCtx
*tdc
= new MGLMemoryDC(GetWidth(), GetHeight(),
400 M_BMPDATA
->m_bitmap
->bitsPerPixel
,
401 M_BMPDATA
->m_bitmap
->pf
,
402 M_BMPDATA
->m_bitmap
->bytesPerLine
,
403 M_BMPDATA
->m_bitmap
->surface
,
405 wxCHECK_MSG( tdc
->isValid(), NULL
, wxT("cannot create temporary MGLDC") );
407 if ( M_BMPDATA
->m_bitmap
->pal
!= NULL
)
411 switch (M_BMPDATA
->m_bitmap
->bitsPerPixel
)
413 case 2: cnt
= 2; break;
414 case 4: cnt
= 16; break;
415 case 8: cnt
= 256; break;
418 wxFAIL_MSG( wxT("bitmap with this depth cannot have palette") );
422 tdc
->setPalette(M_BMPDATA
->m_bitmap
->pal
, cnt
, 0);
423 tdc
->realizePalette(cnt
, 0, FALSE
);
429 bool wxBitmap::LoadFile(const wxString
&name
, wxBitmapType type
)
433 if ( type
== wxBITMAP_TYPE_BMP
|| type
== wxBITMAP_TYPE_PNG
||
434 type
== wxBITMAP_TYPE_PCX
|| type
== wxBITMAP_TYPE_JPEG
)
436 // prevent accidental loading of bitmap from $MGL_ROOT:
437 if ( !wxFileExists(name
) )
439 wxLogError(_("File %s does not exist."), name
.c_str());
444 wxBitmapHandler
*handler
= FindHandler(type
);
446 if ( handler
== NULL
)
449 if ( !image
.LoadFile(name
, type
) || !image
.Ok() )
451 wxLogError("no bitmap handler for type %d defined.", type
);
456 *this = wxBitmap(image
);
461 return handler
->LoadFile(this, name
, type
, -1, -1);
464 bool wxBitmap::SaveFile(const wxString
& filename
, wxBitmapType type
, const wxPalette
*palette
) const
466 wxCHECK_MSG( Ok(), false, wxT("invalid bitmap") );
468 wxBitmapHandler
*handler
= FindHandler(type
);
470 if ( handler
== NULL
)
472 wxImage image
= ConvertToImage();
474 image
.SetPalette(*palette
);
477 return image
.SaveFile(filename
, type
);
480 wxLogError("no bitmap handler for type %d defined.", type
);
485 return handler
->SaveFile(this, filename
, type
, palette
);
488 wxPalette
*wxBitmap::GetPalette() const
490 wxCHECK_MSG( Ok(), NULL
, wxT("invalid bitmap") );
492 return M_BMPDATA
->m_palette
;
495 void wxBitmap::SetPalette(const wxPalette
& palette
)
497 wxCHECK_RET( Ok(), wxT("invalid bitmap") );
498 wxCHECK_RET( GetDepth() > 1 && GetDepth() <= 8, wxT("cannot set palette for bitmap of this depth") );
501 delete M_BMPDATA
->m_palette
;
502 M_BMPDATA
->m_palette
= NULL
;
504 if ( !palette
.Ok() ) return;
506 M_BMPDATA
->m_palette
= new wxPalette(palette
);
508 int cnt
= palette
.GetColoursCount();
509 palette_t
*pal
= palette
.GetMGLpalette_t();
510 memcpy(M_BMPDATA
->m_bitmap
->pal
, pal
, cnt
* sizeof(palette_t
));
513 void wxBitmap::SetHeight(int height
)
517 M_BMPDATA
->m_height
= height
;
520 void wxBitmap::SetWidth(int width
)
524 M_BMPDATA
->m_width
= width
;
527 void wxBitmap::SetDepth(int depth
)
531 M_BMPDATA
->m_bpp
= depth
;
534 bitmap_t
*wxBitmap::GetMGLbitmap_t() const
536 return M_BMPDATA
->m_bitmap
;
539 // Convert wxColour into it's quantized value in lower-precision
540 // pixel format (needed for masking by colour).
541 wxColour
wxBitmap::QuantizeColour(const wxColour
& clr
) const
543 pixel_format_t
*pf
= GetMGLbitmap_t()->pf
;
545 if ( pf
->redAdjust
== 0 && pf
->greenAdjust
== 0 && pf
->blueAdjust
== 0 )
548 return wxColour((unsigned char)((clr
.Red() >> pf
->redAdjust
) << pf
->redAdjust
),
549 (unsigned char)((clr
.Green() >> pf
->greenAdjust
) << pf
->greenAdjust
),
550 (unsigned char)((clr
.Blue() >> pf
->blueAdjust
) << pf
->blueAdjust
));
554 //-----------------------------------------------------------------------------
555 // wxBitmap I/O handlers
556 //-----------------------------------------------------------------------------
558 class wxMGLBitmapHandler
: public wxBitmapHandler
561 wxMGLBitmapHandler(wxBitmapType type
,
562 const wxString
& extension
, const wxString
& name
);
564 virtual bool Create(wxBitmap
*WXUNUSED(bitmap
),
565 const void* WXUNUSED(data
),
566 long WXUNUSED(flags
),
568 int WXUNUSED(height
),
569 int WXUNUSED(depth
) = 1)
572 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
573 int desiredWidth
, int desiredHeight
);
574 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
575 int type
, const wxPalette
*palette
= NULL
);
578 wxMGLBitmapHandler::wxMGLBitmapHandler(wxBitmapType type
,
579 const wxString
& extension
,
580 const wxString
& name
)
585 SetExtension(extension
);
588 bool wxMGLBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
,
590 int WXUNUSED(desiredWidth
),
591 int WXUNUSED(desiredHeight
))
593 int width
, height
, bpp
;
600 case wxBITMAP_TYPE_BMP_RESOURCE
:
601 case wxBITMAP_TYPE_JPEG_RESOURCE
:
602 case wxBITMAP_TYPE_PNG_RESOURCE
:
603 case wxBITMAP_TYPE_PCX_RESOURCE
:
604 fullname
= name
+ wxT(".bmp");
613 case wxBITMAP_TYPE_BMP
:
614 case wxBITMAP_TYPE_BMP_RESOURCE
:
615 if ( !MGL_getBitmapSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
617 bitmap
->Create(width
, height
, -1);
618 if ( !bitmap
->Ok() ) return false;
619 dc
.SelectObject(*bitmap
);
620 if ( !dc
.GetMGLDC()->loadBitmapIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
624 case wxBITMAP_TYPE_JPEG
:
625 case wxBITMAP_TYPE_JPEG_RESOURCE
:
626 if ( !MGL_getJPEGSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
628 bitmap
->Create(width
, height
, -1);
629 if ( !bitmap
->Ok() ) return false;
630 dc
.SelectObject(*bitmap
);
631 if ( !dc
.GetMGLDC()->loadJPEGIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
635 case wxBITMAP_TYPE_PNG
:
636 case wxBITMAP_TYPE_PNG_RESOURCE
:
637 if ( !MGL_getPNGSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
639 bitmap
->Create(width
, height
, -1);
640 if ( !bitmap
->Ok() ) return false;
641 dc
.SelectObject(*bitmap
);
642 if ( !dc
.GetMGLDC()->loadPNGIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
646 case wxBITMAP_TYPE_PCX
:
647 case wxBITMAP_TYPE_PCX_RESOURCE
:
648 if ( !MGL_getPCXSize(fullname
.mb_str(), &width
, &height
, &bpp
) )
650 bitmap
->Create(width
, height
, -1);
651 if ( !bitmap
->Ok() ) return false;
652 dc
.SelectObject(*bitmap
);
653 if ( !dc
.GetMGLDC()->loadPCXIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
658 wxFAIL_MSG(wxT("Unsupported image format."));
665 bool wxMGLBitmapHandler::SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
666 int type
, const wxPalette
* WXUNUSED(palette
))
670 int w
= bitmap
->GetWidth(),
671 h
= bitmap
->GetHeight();
673 mem
.SelectObjectAsSource(*bitmap
);
674 tdc
= mem
.GetMGLDC();
678 case wxBITMAP_TYPE_BMP
:
679 return (bool)tdc
->saveBitmapFromDC(name
.mb_str(), 0, 0, w
, h
);
680 case wxBITMAP_TYPE_JPEG
:
681 return (bool)tdc
->saveJPEGFromDC(name
.mb_str(), 0, 0, w
, h
, 75);
682 case wxBITMAP_TYPE_PNG
:
683 return (bool)tdc
->savePNGFromDC(name
.mb_str(), 0, 0, w
, h
);
684 case wxBITMAP_TYPE_PCX
:
685 return (bool)tdc
->savePCXFromDC(name
.mb_str(), 0, 0, w
, h
);
693 // let's handle PNGs in special way because they have alpha channel
694 // which we can access via bitmap_t most easily
695 class wxPNGBitmapHandler
: public wxMGLBitmapHandler
698 wxPNGBitmapHandler(wxBitmapType type
,
699 const wxString
& extension
, const wxString
& name
)
700 : wxMGLBitmapHandler(type
, extension
, name
) {}
702 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
703 int desiredWidth
, int desiredHeight
);
706 bool wxPNGBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
,
708 int desiredWidth
, int desiredHeight
)
710 int width
, height
, bpp
;
714 if ( flags
== wxBITMAP_TYPE_PNG_RESOURCE
)
715 fullname
= name
+ wxT(".png");
719 if ( !MGL_getPNGSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
724 // We can load ordinary PNGs faster with 'normal' MGL handler.
725 // Only RGBA PNGs need to be processed in special way because
726 // we have to convert alpha channel to mask
727 return wxMGLBitmapHandler::LoadFile(bitmap
, name
, flags
,
728 desiredWidth
, desiredHeight
);
731 bitmap_t
*bmp
= MGL_loadPNG(fullname
.mb_str(), TRUE
);
733 if ( bmp
== NULL
) return false;
735 bitmap
->Create(bmp
->width
, bmp
->height
, -1);
736 if ( !bitmap
->Ok() ) return false;
738 // convert bmp to display's depth and write it to *bitmap:
740 dc
.SelectObject(*bitmap
);
741 dc
.GetMGLDC()->putBitmap(0, 0, bmp
, MGL_REPLACE_MODE
);
742 dc
.SelectObject(wxNullBitmap
);
744 // create mask, if bmp contains alpha channel (ARGB format):
745 if ( bmp
->bitsPerPixel
== 32 )
748 wxUint32
*s
= (wxUint32
*)bmp
->surface
;
749 for (y
= 0; y
< bmp
->height
; y
++)
751 s
= ((wxUint32
*)bmp
->surface
) + y
* bmp
->bytesPerLine
/4;
752 for (x
= 0; x
< bmp
->width
; x
++, s
++)
754 if ( ((((*s
) >> bmp
->pf
->alphaPos
) & bmp
->pf
->alphaMask
)
755 << bmp
->pf
->alphaAdjust
) < 128 )
758 *s
= 0x00FFFFFF; // white
761 wxBitmap
mask(bmp
->width
, bmp
->height
, 1);
762 dc
.SelectObject(mask
);
763 dc
.GetMGLDC()->putBitmap(0, 0, bmp
, MGL_REPLACE_MODE
);
764 dc
.SelectObject(wxNullBitmap
);
765 bitmap
->SetMask(new wxMask(mask
));
768 MGL_unloadBitmap(bmp
);
776 class wxICOBitmapHandler
: public wxBitmapHandler
779 wxICOBitmapHandler(wxBitmapType type
,
780 const wxString
& extension
, const wxString
& name
);
782 virtual bool Create(wxBitmap
*WXUNUSED(bitmap
),
783 const void* WXUNUSED(data
),
784 long WXUNUSED(flags
),
786 int WXUNUSED(height
),
787 int WXUNUSED(depth
) = 1)
790 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
791 int desiredWidth
, int desiredHeight
);
792 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
793 int type
, const wxPalette
*palette
= NULL
);
796 wxICOBitmapHandler::wxICOBitmapHandler(wxBitmapType type
,
797 const wxString
& extension
,
798 const wxString
& name
)
803 SetExtension(extension
);
806 bool wxICOBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
,
808 int WXUNUSED(desiredWidth
),
809 int WXUNUSED(desiredHeight
))
814 if ( flags
== wxBITMAP_TYPE_ICO_RESOURCE
)
815 icon
= MGL_loadIcon(wxString(name
+ wxT(".ico")).mb_str(), TRUE
);
817 icon
= MGL_loadIcon(name
.mb_str(), TRUE
);
819 if ( icon
== NULL
) return false;
821 bitmap
->Create(icon
->xorMask
.width
, icon
->xorMask
.height
);
824 mem
.SelectObject(*bitmap
);
826 dc
->putBitmap(0, 0, &(icon
->xorMask
), MGL_REPLACE_MODE
);
827 mem
.SelectObject(wxNullBitmap
);
829 wxBitmap
mask(icon
->xorMask
.width
, icon
->xorMask
.height
, 1);
830 mem
.SelectObject(mask
);
833 wxCurrentDCSwitcher
curDC(dc
);
837 dc
->putMonoImage(0, 0, icon
->xorMask
.width
, icon
->byteWidth
,
838 icon
->xorMask
.height
, (void*)icon
->andMask
);
840 bitmap
->SetMask(new wxMask(mask
));
842 MGL_unloadIcon(icon
);
847 bool wxICOBitmapHandler::SaveFile(const wxBitmap
*WXUNUSED(bitmap
),
848 const wxString
& WXUNUSED(name
),
850 const wxPalette
* WXUNUSED(palette
))
858 /*static*/ void wxBitmap::InitStandardHandlers()
860 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_BMP
, wxT("bmp"), wxT("Windows bitmap")));
861 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_BMP_RESOURCE
, wxEmptyString
, wxT("Windows bitmap resource")));
862 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_JPEG
, wxT("jpg"), wxT("JPEG image")));
863 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_JPEG_RESOURCE
, wxEmptyString
, wxT("JPEG resource")));
864 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_PCX
, wxT("pcx"), wxT("PCX image")));
865 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_PCX_RESOURCE
, wxEmptyString
, wxT("PCX resource")));
867 AddHandler(new wxPNGBitmapHandler(wxBITMAP_TYPE_PNG
, wxT("png"), wxT("PNG image")));
868 AddHandler(new wxPNGBitmapHandler(wxBITMAP_TYPE_PNG_RESOURCE
, wxEmptyString
, wxT("PNG resource")));
870 AddHandler(new wxICOBitmapHandler(wxBITMAP_TYPE_ICO
, wxT("ico"), wxT("Icon resource")));
871 AddHandler(new wxICOBitmapHandler(wxBITMAP_TYPE_ICO_RESOURCE
, wxEmptyString
, wxT("Icon resource")));