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
67 wxBitmapRefData(int width
, int height
, int bpp
);
68 wxBitmapRefData(const wxBitmapRefData
& data
);
69 virtual ~wxBitmapRefData();
71 virtual bool IsOk() const { return m_bitmap
!= NULL
; }
81 void DoCreateBitmap();
84 void wxBitmapRefData::DoCreateBitmap()
86 pixel_format_t pf_dummy
;
93 wxASSERT_MSG( g_displayDC
, wxT("MGL display DC not created yet.") );
95 g_displayDC
->getPixelFormat(pf_dummy
);
96 mglDepth
= g_displayDC
->getBitsPerPixel();
102 mglDepth
= 8; // we emulate monochrome bitmaps using 8 bit ones
105 pf
= &gs_pixel_format_15
;
108 pf
= &gs_pixel_format_16
;
111 pf
= &gs_pixel_format_24
;
114 pf
= &gs_pixel_format_32
;
117 wxFAIL_MSG(wxT("invalid bitmap depth"));
122 m_bitmap
= MyMGL_createBitmap(width
, height
, mglDepth
, pf
);
125 wxBitmapRefData::wxBitmapRefData(int width
, int height
, int bpp
)
137 wxBitmapRefData::wxBitmapRefData(const wxBitmapRefData
& data
)
139 m_width
= data
.m_width
;
140 m_height
= data
.m_height
;
143 m_palette
= NULL
; // FIXME: should copy
144 m_mask
= NULL
; // FIXME: should copy
149 wxBitmapRefData::~wxBitmapRefData()
152 MGL_unloadBitmap(m_bitmap
);
157 //-----------------------------------------------------------------------------
159 #define M_BMPDATA ((wxBitmapRefData *)m_refData)
161 IMPLEMENT_DYNAMIC_CLASS(wxBitmap
,wxBitmapBase
)
163 wxBitmap::wxBitmap(int width
, int height
, int depth
)
165 Create(width
, height
, depth
);
169 wxGDIRefData
*wxBitmap::CreateGDIRefData() const
171 return new wxBitmapRefData
;
174 wxGDIRefData
*wxBitmap::CloneGDIRefData(const wxGDIRefData
*data
) const
176 return new wxBitmapRefData(*wx_static_cast(const wxBitmapRefData
*, data
));
179 bool wxBitmap::Create(int width
, int height
, int depth
)
183 wxCHECK_MSG( (width
> 0) && (height
> 0), false, wxT("invalid bitmap size") );
185 m_refData
= new wxBitmapRefData(width
, height
, depth
);
189 // MGL does not support mono DCs, so we have to emulate them with
190 // 8bpp ones. We do that by using a special palette with color 0
191 // set to black and all other colors set to white.
192 SetMonoPalette(wxColour(255, 255, 255), wxColour(0, 0, 0));
198 wxBitmap::wxBitmap(const wxImage
& image
, int depth
)
202 wxCHECK_RET( image
.Ok(), wxT("invalid image") );
204 width
= image
.GetWidth();
205 height
= image
.GetHeight();
207 if ( !Create(width
, height
, depth
) ) return;
209 MGLMemoryDC
idc(width
, height
, 24, &gs_pixel_format_wxImage
,
210 width
* 3, (void*)image
.GetData(), NULL
);
211 wxASSERT_MSG( idc
.isValid(), wxT("cannot create custom MGLDC") );
213 MGLDevCtx
*bdc
= CreateTmpDC();
215 if ( GetDepth() <= 8 && image
.HasPalette() )
216 SetPalette(image
.GetPalette());
218 bdc
->bitBlt(idc
, 0, 0, width
, height
, 0, 0, MGL_REPLACE_MODE
);
221 if ( image
.HasMask() )
223 wxImage mask_image
= image
.ConvertToMono(image
.GetMaskRed(),
224 image
.GetMaskGreen(),
225 image
.GetMaskBlue());
226 mask_image
.SetMask(false);
227 wxBitmap
mask_bmp(mask_image
, 1);
228 SetMask(new wxMask(mask_bmp
));
232 wxImage
wxBitmap::ConvertToImage() const
234 wxCHECK_MSG( Ok(), wxImage(), wxT("invalid bitmap") );
238 height
= GetHeight();
240 wxImage
image(width
, height
);
241 wxASSERT_MSG( image
.Ok(), wxT("cannot create image") );
243 MGLMemoryDC
idc(width
, height
, 24, &gs_pixel_format_wxImage
,
244 width
* 3, (void*)image
.GetData(), NULL
);
245 wxASSERT_MSG( idc
.isValid(), wxT("cannot create custom MGLDC") );
247 if ( M_BMPDATA
->m_palette
)
248 image
.SetPalette(*(M_BMPDATA
->m_palette
));
252 // in consistency with other ports, we convert parts covered
253 // by the mask to <16,16,16> colour and set that colour to image's
254 // mask. We do that by OR-blitting the mask over image with
255 // bg colour set to black and fg colour to <16,16,16>
257 image
.SetMaskColour(16, 16, 16);
261 tmpDC
.SetMGLDC(&idc
, false);
262 tmpDC
.SetBackground(wxBrush(wxColour(16,16,16), wxSOLID
));
264 tmpDC
.DrawBitmap(*this, 0, 0, true);
268 image
.SetMask(false);
269 idc
.putBitmap(0, 0, M_BMPDATA
->m_bitmap
, MGL_REPLACE_MODE
);
275 wxBitmap::wxBitmap(const wxString
&filename
, wxBitmapType type
)
277 LoadFile(filename
, type
);
280 wxBitmap::wxBitmap(const char bits
[], int width
, int height
, int depth
)
282 wxCHECK_RET( depth
== 1, wxT("can only create mono bitmap from XBM data") );
284 if ( !Create(width
, height
, 1) ) return;
285 MGLDevCtx
*bdc
= CreateTmpDC();
286 wxCurrentDCSwitcher
curDC(bdc
);
288 bdc
->setBackColor(0);
290 bdc
->putMonoImage(0, 0, width
, (width
+ 7) / 8, height
, (void*)bits
);
294 int wxBitmap::GetHeight() const
296 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
298 return M_BMPDATA
->m_height
;
301 int wxBitmap::GetWidth() const
303 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
305 return M_BMPDATA
->m_width
;
308 int wxBitmap::GetDepth() const
310 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
312 return M_BMPDATA
->m_bpp
;
315 wxMask
*wxBitmap::GetMask() const
317 wxCHECK_MSG( Ok(), (wxMask
*) NULL
, wxT("invalid bitmap") );
319 return M_BMPDATA
->m_mask
;
322 void wxBitmap::SetMask(wxMask
*mask
)
324 wxCHECK_RET( Ok(), wxT("invalid bitmap") );
327 delete M_BMPDATA
->m_mask
;
328 M_BMPDATA
->m_mask
= mask
;
331 bool wxBitmap::CopyFromIcon(const wxIcon
& icon
)
333 wxBitmap
*bmp
= (wxBitmap
*)(&icon
);
338 wxBitmap
wxBitmap::GetSubBitmap(const wxRect
& rect
) const
341 (rect
.x
>= 0) && (rect
.y
>= 0) &&
342 (rect
.x
+rect
.width
<= M_BMPDATA
->m_width
) && (rect
.y
+rect
.height
<= M_BMPDATA
->m_height
),
343 wxNullBitmap
, wxT("invalid bitmap or bitmap region") );
345 wxBitmap
ret( rect
.width
, rect
.height
, M_BMPDATA
->m_bpp
);
346 wxASSERT_MSG( ret
.Ok(), wxT("GetSubBitmap error") );
349 ret
.SetPalette(*GetPalette());
351 MGLDevCtx
*tdc
= ret
.CreateTmpDC();
352 tdc
->putBitmapSection(rect
.x
, rect
.y
,
353 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
354 0, 0, M_BMPDATA
->m_bitmap
, MGL_REPLACE_MODE
);
359 wxBitmap submask
= GetMask()->GetBitmap().GetSubBitmap(rect
);
360 ret
.SetMask(new wxMask(submask
));
366 void wxBitmap::SetMonoPalette(const wxColour
& fg
, const wxColour
& bg
)
368 wxCHECK_RET( Ok(), wxT("invalid bitmap") );
371 palette_t
*mono
= M_BMPDATA
->m_bitmap
->pal
;
373 wxCHECK_RET( M_BMPDATA
->m_bpp
== 1, wxT("bitmap is not 1bpp") );
374 wxCHECK_RET( mono
!= NULL
, wxT("bitmap w/o palette") );
376 mono
[0].red
= bg
.Red();
377 mono
[0].green
= bg
.Green();
378 mono
[0].blue
= bg
.Blue();
380 for (size_t i
= 1; i
< 256; i
++)
382 mono
[i
].red
= fg
.Red();
383 mono
[i
].green
= fg
.Green();
384 mono
[i
].blue
= fg
.Blue();
389 MGLDevCtx
*wxBitmap::CreateTmpDC() const
391 wxCHECK_MSG( Ok(), NULL
, wxT("invalid bitmap") );
393 MGLDevCtx
*tdc
= new MGLMemoryDC(GetWidth(), GetHeight(),
394 M_BMPDATA
->m_bitmap
->bitsPerPixel
,
395 M_BMPDATA
->m_bitmap
->pf
,
396 M_BMPDATA
->m_bitmap
->bytesPerLine
,
397 M_BMPDATA
->m_bitmap
->surface
,
399 wxCHECK_MSG( tdc
->isValid(), NULL
, wxT("cannot create temporary MGLDC") );
401 if ( M_BMPDATA
->m_bitmap
->pal
!= NULL
)
405 switch (M_BMPDATA
->m_bitmap
->bitsPerPixel
)
407 case 2: cnt
= 2; break;
408 case 4: cnt
= 16; break;
409 case 8: cnt
= 256; break;
412 wxFAIL_MSG( wxT("bitmap with this depth cannot have palette") );
416 tdc
->setPalette(M_BMPDATA
->m_bitmap
->pal
, cnt
, 0);
417 tdc
->realizePalette(cnt
, 0, FALSE
);
423 bool wxBitmap::LoadFile(const wxString
&name
, wxBitmapType type
)
427 if ( type
== wxBITMAP_TYPE_BMP
|| type
== wxBITMAP_TYPE_PNG
||
428 type
== wxBITMAP_TYPE_PCX
|| type
== wxBITMAP_TYPE_JPEG
)
430 // prevent accidental loading of bitmap from $MGL_ROOT:
431 if ( !wxFileExists(name
) )
433 wxLogError(_("File %s does not exist."), name
.c_str());
438 wxBitmapHandler
*handler
= FindHandler(type
);
440 if ( handler
== NULL
)
443 if ( !image
.LoadFile(name
, type
) || !image
.Ok() )
445 wxLogError("no bitmap handler for type %d defined.", type
);
450 *this = wxBitmap(image
);
455 return handler
->LoadFile(this, name
, type
, -1, -1);
458 bool wxBitmap::SaveFile(const wxString
& filename
, wxBitmapType type
, const wxPalette
*palette
) const
460 wxCHECK_MSG( Ok(), false, wxT("invalid bitmap") );
462 wxBitmapHandler
*handler
= FindHandler(type
);
464 if ( handler
== NULL
)
466 wxImage image
= ConvertToImage();
468 image
.SetPalette(*palette
);
471 return image
.SaveFile(filename
, type
);
474 wxLogError("no bitmap handler for type %d defined.", type
);
479 return handler
->SaveFile(this, filename
, type
, palette
);
482 wxPalette
*wxBitmap::GetPalette() const
484 wxCHECK_MSG( Ok(), NULL
, wxT("invalid bitmap") );
486 return M_BMPDATA
->m_palette
;
489 void wxBitmap::SetPalette(const wxPalette
& palette
)
491 wxCHECK_RET( Ok(), wxT("invalid bitmap") );
492 wxCHECK_RET( GetDepth() > 1 && GetDepth() <= 8, wxT("cannot set palette for bitmap of this depth") );
495 delete M_BMPDATA
->m_palette
;
496 M_BMPDATA
->m_palette
= NULL
;
498 if ( !palette
.Ok() ) return;
500 M_BMPDATA
->m_palette
= new wxPalette(palette
);
502 int cnt
= palette
.GetColoursCount();
503 palette_t
*pal
= palette
.GetMGLpalette_t();
504 memcpy(M_BMPDATA
->m_bitmap
->pal
, pal
, cnt
* sizeof(palette_t
));
507 void wxBitmap::SetHeight(int height
)
511 M_BMPDATA
->m_height
= height
;
514 void wxBitmap::SetWidth(int width
)
518 M_BMPDATA
->m_width
= width
;
521 void wxBitmap::SetDepth(int depth
)
525 M_BMPDATA
->m_bpp
= depth
;
528 bitmap_t
*wxBitmap::GetMGLbitmap_t() const
530 return M_BMPDATA
->m_bitmap
;
533 // Convert wxColour into it's quantized value in lower-precision
534 // pixel format (needed for masking by colour).
535 wxColour
wxBitmap::QuantizeColour(const wxColour
& clr
) const
537 pixel_format_t
*pf
= GetMGLbitmap_t()->pf
;
539 if ( pf
->redAdjust
== 0 && pf
->greenAdjust
== 0 && pf
->blueAdjust
== 0 )
542 return wxColour((unsigned char)((clr
.Red() >> pf
->redAdjust
) << pf
->redAdjust
),
543 (unsigned char)((clr
.Green() >> pf
->greenAdjust
) << pf
->greenAdjust
),
544 (unsigned char)((clr
.Blue() >> pf
->blueAdjust
) << pf
->blueAdjust
));
548 //-----------------------------------------------------------------------------
549 // wxBitmap I/O handlers
550 //-----------------------------------------------------------------------------
552 class wxMGLBitmapHandler
: public wxBitmapHandler
555 wxMGLBitmapHandler(wxBitmapType type
,
556 const wxString
& extension
, const wxString
& name
);
558 virtual bool Create(wxBitmap
*WXUNUSED(bitmap
),
559 const void* WXUNUSED(data
),
560 long WXUNUSED(flags
),
562 int WXUNUSED(height
),
563 int WXUNUSED(depth
) = 1)
566 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
567 int desiredWidth
, int desiredHeight
);
568 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
569 int type
, const wxPalette
*palette
= NULL
);
572 wxMGLBitmapHandler::wxMGLBitmapHandler(wxBitmapType type
,
573 const wxString
& extension
,
574 const wxString
& name
)
579 SetExtension(extension
);
582 bool wxMGLBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
,
584 int WXUNUSED(desiredWidth
),
585 int WXUNUSED(desiredHeight
))
587 int width
, height
, bpp
;
594 case wxBITMAP_TYPE_BMP_RESOURCE
:
595 case wxBITMAP_TYPE_JPEG_RESOURCE
:
596 case wxBITMAP_TYPE_PNG_RESOURCE
:
597 case wxBITMAP_TYPE_PCX_RESOURCE
:
598 fullname
= name
+ wxT(".bmp");
607 case wxBITMAP_TYPE_BMP
:
608 case wxBITMAP_TYPE_BMP_RESOURCE
:
609 if ( !MGL_getBitmapSize(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()->loadBitmapIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
618 case wxBITMAP_TYPE_JPEG
:
619 case wxBITMAP_TYPE_JPEG_RESOURCE
:
620 if ( !MGL_getJPEGSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
622 bitmap
->Create(width
, height
, -1);
623 if ( !bitmap
->Ok() ) return false;
624 dc
.SelectObject(*bitmap
);
625 if ( !dc
.GetMGLDC()->loadJPEGIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
629 case wxBITMAP_TYPE_PNG
:
630 case wxBITMAP_TYPE_PNG_RESOURCE
:
631 if ( !MGL_getPNGSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
633 bitmap
->Create(width
, height
, -1);
634 if ( !bitmap
->Ok() ) return false;
635 dc
.SelectObject(*bitmap
);
636 if ( !dc
.GetMGLDC()->loadPNGIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
640 case wxBITMAP_TYPE_PCX
:
641 case wxBITMAP_TYPE_PCX_RESOURCE
:
642 if ( !MGL_getPCXSize(fullname
.mb_str(), &width
, &height
, &bpp
) )
644 bitmap
->Create(width
, height
, -1);
645 if ( !bitmap
->Ok() ) return false;
646 dc
.SelectObject(*bitmap
);
647 if ( !dc
.GetMGLDC()->loadPCXIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
652 wxFAIL_MSG(wxT("Unsupported image format."));
659 bool wxMGLBitmapHandler::SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
660 int type
, const wxPalette
* WXUNUSED(palette
))
664 int w
= bitmap
->GetWidth(),
665 h
= bitmap
->GetHeight();
667 mem
.SelectObjectAsSource(*bitmap
);
668 tdc
= mem
.GetMGLDC();
672 case wxBITMAP_TYPE_BMP
:
673 return (bool)tdc
->saveBitmapFromDC(name
.mb_str(), 0, 0, w
, h
);
674 case wxBITMAP_TYPE_JPEG
:
675 return (bool)tdc
->saveJPEGFromDC(name
.mb_str(), 0, 0, w
, h
, 75);
676 case wxBITMAP_TYPE_PNG
:
677 return (bool)tdc
->savePNGFromDC(name
.mb_str(), 0, 0, w
, h
);
678 case wxBITMAP_TYPE_PCX
:
679 return (bool)tdc
->savePCXFromDC(name
.mb_str(), 0, 0, w
, h
);
687 // let's handle PNGs in special way because they have alpha channel
688 // which we can access via bitmap_t most easily
689 class wxPNGBitmapHandler
: public wxMGLBitmapHandler
692 wxPNGBitmapHandler(wxBitmapType type
,
693 const wxString
& extension
, const wxString
& name
)
694 : wxMGLBitmapHandler(type
, extension
, name
) {}
696 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
697 int desiredWidth
, int desiredHeight
);
700 bool wxPNGBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
,
702 int desiredWidth
, int desiredHeight
)
704 int width
, height
, bpp
;
708 if ( flags
== wxBITMAP_TYPE_PNG_RESOURCE
)
709 fullname
= name
+ wxT(".png");
713 if ( !MGL_getPNGSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
718 // We can load ordinary PNGs faster with 'normal' MGL handler.
719 // Only RGBA PNGs need to be processed in special way because
720 // we have to convert alpha channel to mask
721 return wxMGLBitmapHandler::LoadFile(bitmap
, name
, flags
,
722 desiredWidth
, desiredHeight
);
725 bitmap_t
*bmp
= MGL_loadPNG(fullname
.mb_str(), TRUE
);
727 if ( bmp
== NULL
) return false;
729 bitmap
->Create(bmp
->width
, bmp
->height
, -1);
730 if ( !bitmap
->Ok() ) return false;
732 // convert bmp to display's depth and write it to *bitmap:
734 dc
.SelectObject(*bitmap
);
735 dc
.GetMGLDC()->putBitmap(0, 0, bmp
, MGL_REPLACE_MODE
);
736 dc
.SelectObject(wxNullBitmap
);
738 // create mask, if bmp contains alpha channel (ARGB format):
739 if ( bmp
->bitsPerPixel
== 32 )
742 wxUint32
*s
= (wxUint32
*)bmp
->surface
;
743 for (y
= 0; y
< bmp
->height
; y
++)
745 s
= ((wxUint32
*)bmp
->surface
) + y
* bmp
->bytesPerLine
/4;
746 for (x
= 0; x
< bmp
->width
; x
++, s
++)
748 if ( ((((*s
) >> bmp
->pf
->alphaPos
) & bmp
->pf
->alphaMask
)
749 << bmp
->pf
->alphaAdjust
) < 128 )
752 *s
= 0x00FFFFFF; // white
755 wxBitmap
mask(bmp
->width
, bmp
->height
, 1);
756 dc
.SelectObject(mask
);
757 dc
.GetMGLDC()->putBitmap(0, 0, bmp
, MGL_REPLACE_MODE
);
758 dc
.SelectObject(wxNullBitmap
);
759 bitmap
->SetMask(new wxMask(mask
));
762 MGL_unloadBitmap(bmp
);
770 class wxICOBitmapHandler
: public wxBitmapHandler
773 wxICOBitmapHandler(wxBitmapType type
,
774 const wxString
& extension
, const wxString
& name
);
776 virtual bool Create(wxBitmap
*WXUNUSED(bitmap
),
777 const void* WXUNUSED(data
),
778 long WXUNUSED(flags
),
780 int WXUNUSED(height
),
781 int WXUNUSED(depth
) = 1)
784 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
785 int desiredWidth
, int desiredHeight
);
786 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
787 int type
, const wxPalette
*palette
= NULL
);
790 wxICOBitmapHandler::wxICOBitmapHandler(wxBitmapType type
,
791 const wxString
& extension
,
792 const wxString
& name
)
797 SetExtension(extension
);
800 bool wxICOBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
,
802 int WXUNUSED(desiredWidth
),
803 int WXUNUSED(desiredHeight
))
808 if ( flags
== wxBITMAP_TYPE_ICO_RESOURCE
)
809 icon
= MGL_loadIcon(wxString(name
+ wxT(".ico")).mb_str(), TRUE
);
811 icon
= MGL_loadIcon(name
.mb_str(), TRUE
);
813 if ( icon
== NULL
) return false;
815 bitmap
->Create(icon
->xorMask
.width
, icon
->xorMask
.height
);
818 mem
.SelectObject(*bitmap
);
820 dc
->putBitmap(0, 0, &(icon
->xorMask
), MGL_REPLACE_MODE
);
821 mem
.SelectObject(wxNullBitmap
);
823 wxBitmap
mask(icon
->xorMask
.width
, icon
->xorMask
.height
, 1);
824 mem
.SelectObject(mask
);
827 wxCurrentDCSwitcher
curDC(dc
);
831 dc
->putMonoImage(0, 0, icon
->xorMask
.width
, icon
->byteWidth
,
832 icon
->xorMask
.height
, (void*)icon
->andMask
);
834 bitmap
->SetMask(new wxMask(mask
));
836 MGL_unloadIcon(icon
);
841 bool wxICOBitmapHandler::SaveFile(const wxBitmap
*WXUNUSED(bitmap
),
842 const wxString
& WXUNUSED(name
),
844 const wxPalette
* WXUNUSED(palette
))
852 /*static*/ void wxBitmap::InitStandardHandlers()
854 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_BMP
, wxT("bmp"), wxT("Windows bitmap")));
855 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_BMP_RESOURCE
, wxEmptyString
, wxT("Windows bitmap resource")));
856 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_JPEG
, wxT("jpg"), wxT("JPEG image")));
857 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_JPEG_RESOURCE
, wxEmptyString
, wxT("JPEG resource")));
858 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_PCX
, wxT("pcx"), wxT("PCX image")));
859 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_PCX_RESOURCE
, wxEmptyString
, wxT("PCX resource")));
861 AddHandler(new wxPNGBitmapHandler(wxBITMAP_TYPE_PNG
, wxT("png"), wxT("PNG image")));
862 AddHandler(new wxPNGBitmapHandler(wxBITMAP_TYPE_PNG_RESOURCE
, wxEmptyString
, wxT("PNG resource")));
864 AddHandler(new wxICOBitmapHandler(wxBITMAP_TYPE_ICO
, wxT("ico"), wxT("Icon resource")));
865 AddHandler(new wxICOBitmapHandler(wxBITMAP_TYPE_ICO_RESOURCE
, wxEmptyString
, wxT("Icon resource")));