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::operator == (const wxBitmap
& bmp
) const
272 return (m_refData
== bmp
.m_refData
);
275 bool wxBitmap::operator != (const wxBitmap
& bmp
) const
277 return (m_refData
!= bmp
.m_refData
);
280 bool wxBitmap::IsOk() const
282 return (m_refData
!= NULL
&& M_BMPDATA
->m_bitmap
!= NULL
);
285 int wxBitmap::GetHeight() const
287 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
289 return M_BMPDATA
->m_height
;
292 int wxBitmap::GetWidth() const
294 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
296 return M_BMPDATA
->m_width
;
299 int wxBitmap::GetDepth() const
301 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
303 return M_BMPDATA
->m_bpp
;
306 wxMask
*wxBitmap::GetMask() const
308 wxCHECK_MSG( Ok(), (wxMask
*) NULL
, wxT("invalid bitmap") );
310 return M_BMPDATA
->m_mask
;
313 void wxBitmap::SetMask(wxMask
*mask
)
315 wxCHECK_RET( Ok(), wxT("invalid bitmap") );
317 delete M_BMPDATA
->m_mask
;
318 M_BMPDATA
->m_mask
= mask
;
321 bool wxBitmap::CopyFromIcon(const wxIcon
& icon
)
323 wxBitmap
*bmp
= (wxBitmap
*)(&icon
);
328 wxBitmap
wxBitmap::GetSubBitmap(const wxRect
& rect
) const
331 (rect
.x
>= 0) && (rect
.y
>= 0) &&
332 (rect
.x
+rect
.width
<= M_BMPDATA
->m_width
) && (rect
.y
+rect
.height
<= M_BMPDATA
->m_height
),
333 wxNullBitmap
, wxT("invalid bitmap or bitmap region") );
335 wxBitmap
ret( rect
.width
, rect
.height
, M_BMPDATA
->m_bpp
);
336 wxASSERT_MSG( ret
.Ok(), wxT("GetSubBitmap error") );
339 ret
.SetPalette(*GetPalette());
341 MGLDevCtx
*tdc
= ret
.CreateTmpDC();
342 tdc
->putBitmapSection(rect
.x
, rect
.y
,
343 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
344 0, 0, M_BMPDATA
->m_bitmap
, MGL_REPLACE_MODE
);
349 wxBitmap submask
= GetMask()->GetBitmap().GetSubBitmap(rect
);
350 ret
.SetMask(new wxMask(submask
));
356 void wxBitmap::SetMonoPalette(const wxColour
& fg
, const wxColour
& bg
)
358 wxCHECK_RET( Ok(), wxT("invalid bitmap") );
360 palette_t
*mono
= M_BMPDATA
->m_bitmap
->pal
;
362 wxCHECK_RET( M_BMPDATA
->m_bpp
== 1, wxT("bitmap is not 1bpp") );
363 wxCHECK_RET( mono
!= NULL
, wxT("bitmap w/o palette") );
365 mono
[0].red
= bg
.Red();
366 mono
[0].green
= bg
.Green();
367 mono
[0].blue
= bg
.Blue();
369 for (size_t i
= 1; i
< 256; i
++)
371 mono
[i
].red
= fg
.Red();
372 mono
[i
].green
= fg
.Green();
373 mono
[i
].blue
= fg
.Blue();
378 MGLDevCtx
*wxBitmap::CreateTmpDC() const
380 wxCHECK_MSG( Ok(), NULL
, wxT("invalid bitmap") );
382 MGLDevCtx
*tdc
= new MGLMemoryDC(GetWidth(), GetHeight(),
383 M_BMPDATA
->m_bitmap
->bitsPerPixel
,
384 M_BMPDATA
->m_bitmap
->pf
,
385 M_BMPDATA
->m_bitmap
->bytesPerLine
,
386 M_BMPDATA
->m_bitmap
->surface
,
388 wxCHECK_MSG( tdc
->isValid(), NULL
, wxT("cannot create temporary MGLDC") );
390 if ( M_BMPDATA
->m_bitmap
->pal
!= NULL
)
394 switch (M_BMPDATA
->m_bitmap
->bitsPerPixel
)
396 case 2: cnt
= 2; break;
397 case 4: cnt
= 16; break;
398 case 8: cnt
= 256; break;
401 wxFAIL_MSG( wxT("bitmap with this depth cannot have palette") );
405 tdc
->setPalette(M_BMPDATA
->m_bitmap
->pal
, cnt
, 0);
406 tdc
->realizePalette(cnt
, 0, FALSE
);
412 bool wxBitmap::LoadFile(const wxString
&name
, wxBitmapType type
)
416 if ( type
== wxBITMAP_TYPE_BMP
|| type
== wxBITMAP_TYPE_PNG
||
417 type
== wxBITMAP_TYPE_PCX
|| type
== wxBITMAP_TYPE_JPEG
)
419 // prevent accidental loading of bitmap from $MGL_ROOT:
420 if ( !wxFileExists(name
) )
422 wxLogError(_("File %s does not exist."), name
.c_str());
427 wxBitmapHandler
*handler
= FindHandler(type
);
429 if ( handler
== NULL
)
432 if ( !image
.LoadFile(name
, type
) || !image
.Ok() )
434 wxLogError("no bitmap handler for type %d defined.", type
);
439 *this = wxBitmap(image
);
444 m_refData
= new wxBitmapRefData();
446 return handler
->LoadFile(this, name
, type
, -1, -1);
449 bool wxBitmap::SaveFile(const wxString
& filename
, wxBitmapType type
, const wxPalette
*palette
) const
451 wxCHECK_MSG( Ok(), false, wxT("invalid bitmap") );
453 wxBitmapHandler
*handler
= FindHandler(type
);
455 if ( handler
== NULL
)
457 wxImage image
= ConvertToImage();
459 image
.SetPalette(*palette
);
462 return image
.SaveFile(filename
, type
);
465 wxLogError("no bitmap handler for type %d defined.", type
);
470 return handler
->SaveFile(this, filename
, type
, palette
);
473 wxPalette
*wxBitmap::GetPalette() const
475 wxCHECK_MSG( Ok(), NULL
, wxT("invalid bitmap") );
477 return M_BMPDATA
->m_palette
;
480 void wxBitmap::SetPalette(const wxPalette
& palette
)
482 wxCHECK_RET( Ok(), wxT("invalid bitmap") );
483 wxCHECK_RET( GetDepth() > 1 && GetDepth() <= 8, wxT("cannot set palette for bitmap of this depth") );
485 delete M_BMPDATA
->m_palette
;
486 M_BMPDATA
->m_palette
= NULL
;
488 if ( !palette
.Ok() ) return;
490 M_BMPDATA
->m_palette
= new wxPalette(palette
);
492 int cnt
= palette
.GetColoursCount();
493 palette_t
*pal
= palette
.GetMGLpalette_t();
494 memcpy(M_BMPDATA
->m_bitmap
->pal
, pal
, cnt
* sizeof(palette_t
));
497 void wxBitmap::SetHeight(int height
)
499 if (!m_refData
) m_refData
= new wxBitmapRefData();
501 M_BMPDATA
->m_height
= height
;
504 void wxBitmap::SetWidth(int width
)
506 if (!m_refData
) m_refData
= new wxBitmapRefData();
508 M_BMPDATA
->m_width
= width
;
511 void wxBitmap::SetDepth(int depth
)
513 if (!m_refData
) m_refData
= new wxBitmapRefData();
515 M_BMPDATA
->m_bpp
= depth
;
518 bitmap_t
*wxBitmap::GetMGLbitmap_t() const
520 return M_BMPDATA
->m_bitmap
;
523 // Convert wxColour into it's quantized value in lower-precision
524 // pixel format (needed for masking by colour).
525 wxColour
wxBitmap::QuantizeColour(const wxColour
& clr
) const
527 pixel_format_t
*pf
= GetMGLbitmap_t()->pf
;
529 if ( pf
->redAdjust
== 0 && pf
->greenAdjust
== 0 && pf
->blueAdjust
== 0 )
532 return wxColour((unsigned char)((clr
.Red() >> pf
->redAdjust
) << pf
->redAdjust
),
533 (unsigned char)((clr
.Green() >> pf
->greenAdjust
) << pf
->greenAdjust
),
534 (unsigned char)((clr
.Blue() >> pf
->blueAdjust
) << pf
->blueAdjust
));
538 //-----------------------------------------------------------------------------
539 // wxBitmap I/O handlers
540 //-----------------------------------------------------------------------------
542 class wxMGLBitmapHandler
: public wxBitmapHandler
545 wxMGLBitmapHandler(wxBitmapType type
,
546 const wxString
& extension
, const wxString
& name
);
548 virtual bool Create(wxBitmap
*WXUNUSED(bitmap
),
549 const void* WXUNUSED(data
),
550 long WXUNUSED(flags
),
552 int WXUNUSED(height
),
553 int WXUNUSED(depth
) = 1)
556 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
557 int desiredWidth
, int desiredHeight
);
558 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
559 int type
, const wxPalette
*palette
= NULL
);
562 wxMGLBitmapHandler::wxMGLBitmapHandler(wxBitmapType type
,
563 const wxString
& extension
,
564 const wxString
& name
)
569 SetExtension(extension
);
572 bool wxMGLBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
,
574 int WXUNUSED(desiredWidth
),
575 int WXUNUSED(desiredHeight
))
577 int width
, height
, bpp
;
584 case wxBITMAP_TYPE_BMP_RESOURCE
:
585 case wxBITMAP_TYPE_JPEG_RESOURCE
:
586 case wxBITMAP_TYPE_PNG_RESOURCE
:
587 case wxBITMAP_TYPE_PCX_RESOURCE
:
588 fullname
= name
+ wxT(".bmp");
597 case wxBITMAP_TYPE_BMP
:
598 case wxBITMAP_TYPE_BMP_RESOURCE
:
599 if ( !MGL_getBitmapSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
601 bitmap
->Create(width
, height
, -1);
602 if ( !bitmap
->Ok() ) return false;
603 dc
.SelectObject(*bitmap
);
604 if ( !dc
.GetMGLDC()->loadBitmapIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
608 case wxBITMAP_TYPE_JPEG
:
609 case wxBITMAP_TYPE_JPEG_RESOURCE
:
610 if ( !MGL_getJPEGSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
612 bitmap
->Create(width
, height
, -1);
613 if ( !bitmap
->Ok() ) return false;
614 dc
.SelectObject(*bitmap
);
615 if ( !dc
.GetMGLDC()->loadJPEGIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
619 case wxBITMAP_TYPE_PNG
:
620 case wxBITMAP_TYPE_PNG_RESOURCE
:
621 if ( !MGL_getPNGSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
623 bitmap
->Create(width
, height
, -1);
624 if ( !bitmap
->Ok() ) return false;
625 dc
.SelectObject(*bitmap
);
626 if ( !dc
.GetMGLDC()->loadPNGIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
630 case wxBITMAP_TYPE_PCX
:
631 case wxBITMAP_TYPE_PCX_RESOURCE
:
632 if ( !MGL_getPCXSize(fullname
.mb_str(), &width
, &height
, &bpp
) )
634 bitmap
->Create(width
, height
, -1);
635 if ( !bitmap
->Ok() ) return false;
636 dc
.SelectObject(*bitmap
);
637 if ( !dc
.GetMGLDC()->loadPCXIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
642 wxFAIL_MSG(wxT("Unsupported image format."));
649 bool wxMGLBitmapHandler::SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
650 int type
, const wxPalette
* WXUNUSED(palette
))
654 int w
= bitmap
->GetWidth(),
655 h
= bitmap
->GetHeight();
657 mem
.SelectObject(*bitmap
);
658 tdc
= mem
.GetMGLDC();
662 case wxBITMAP_TYPE_BMP
:
663 return (bool)tdc
->saveBitmapFromDC(name
.mb_str(), 0, 0, w
, h
);
664 case wxBITMAP_TYPE_JPEG
:
665 return (bool)tdc
->saveJPEGFromDC(name
.mb_str(), 0, 0, w
, h
, 75);
666 case wxBITMAP_TYPE_PNG
:
667 return (bool)tdc
->savePNGFromDC(name
.mb_str(), 0, 0, w
, h
);
668 case wxBITMAP_TYPE_PCX
:
669 return (bool)tdc
->savePCXFromDC(name
.mb_str(), 0, 0, w
, h
);
677 // let's handle PNGs in special way because they have alpha channel
678 // which we can access via bitmap_t most easily
679 class wxPNGBitmapHandler
: public wxMGLBitmapHandler
682 wxPNGBitmapHandler(wxBitmapType type
,
683 const wxString
& extension
, const wxString
& name
)
684 : wxMGLBitmapHandler(type
, extension
, name
) {}
686 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
687 int desiredWidth
, int desiredHeight
);
690 bool wxPNGBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
,
692 int desiredWidth
, int desiredHeight
)
694 int width
, height
, bpp
;
698 if ( flags
== wxBITMAP_TYPE_PNG_RESOURCE
)
699 fullname
= name
+ wxT(".png");
703 if ( !MGL_getPNGSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
708 // We can load ordinary PNGs faster with 'normal' MGL handler.
709 // Only RGBA PNGs need to be processed in special way because
710 // we have to convert alpha channel to mask
711 return wxMGLBitmapHandler::LoadFile(bitmap
, name
, flags
,
712 desiredWidth
, desiredHeight
);
715 bitmap_t
*bmp
= MGL_loadPNG(fullname
.mb_str(), TRUE
);
717 if ( bmp
== NULL
) return false;
719 bitmap
->Create(bmp
->width
, bmp
->height
, -1);
720 if ( !bitmap
->Ok() ) return false;
722 // convert bmp to display's depth and write it to *bitmap:
724 dc
.SelectObject(*bitmap
);
725 dc
.GetMGLDC()->putBitmap(0, 0, bmp
, MGL_REPLACE_MODE
);
726 dc
.SelectObject(wxNullBitmap
);
728 // create mask, if bmp contains alpha channel (ARGB format):
729 if ( bmp
->bitsPerPixel
== 32 )
732 wxUint32
*s
= (wxUint32
*)bmp
->surface
;
733 for (y
= 0; y
< bmp
->height
; y
++)
735 s
= ((wxUint32
*)bmp
->surface
) + y
* bmp
->bytesPerLine
/4;
736 for (x
= 0; x
< bmp
->width
; x
++, s
++)
738 if ( ((((*s
) >> bmp
->pf
->alphaPos
) & bmp
->pf
->alphaMask
)
739 << bmp
->pf
->alphaAdjust
) < 128 )
742 *s
= 0x00FFFFFF; // white
745 wxBitmap
mask(bmp
->width
, bmp
->height
, 1);
746 dc
.SelectObject(mask
);
747 dc
.GetMGLDC()->putBitmap(0, 0, bmp
, MGL_REPLACE_MODE
);
748 dc
.SelectObject(wxNullBitmap
);
749 bitmap
->SetMask(new wxMask(mask
));
752 MGL_unloadBitmap(bmp
);
760 class wxICOBitmapHandler
: public wxBitmapHandler
763 wxICOBitmapHandler(wxBitmapType type
,
764 const wxString
& extension
, const wxString
& name
);
766 virtual bool Create(wxBitmap
*WXUNUSED(bitmap
),
767 const void* WXUNUSED(data
),
768 long WXUNUSED(flags
),
770 int WXUNUSED(height
),
771 int WXUNUSED(depth
) = 1)
774 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
775 int desiredWidth
, int desiredHeight
);
776 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
777 int type
, const wxPalette
*palette
= NULL
);
780 wxICOBitmapHandler::wxICOBitmapHandler(wxBitmapType type
,
781 const wxString
& extension
,
782 const wxString
& name
)
787 SetExtension(extension
);
790 bool wxICOBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
,
792 int WXUNUSED(desiredWidth
),
793 int WXUNUSED(desiredHeight
))
798 if ( flags
== wxBITMAP_TYPE_ICO_RESOURCE
)
799 icon
= MGL_loadIcon(wxString(name
+ wxT(".ico")).mb_str(), TRUE
);
801 icon
= MGL_loadIcon(name
.mb_str(), TRUE
);
803 if ( icon
== NULL
) return false;
805 bitmap
->Create(icon
->xorMask
.width
, icon
->xorMask
.height
);
808 mem
.SelectObject(*bitmap
);
810 dc
->putBitmap(0, 0, &(icon
->xorMask
), MGL_REPLACE_MODE
);
811 mem
.SelectObject(wxNullBitmap
);
813 wxBitmap
mask(icon
->xorMask
.width
, icon
->xorMask
.height
, 1);
814 mem
.SelectObject(mask
);
817 wxCurrentDCSwitcher
curDC(dc
);
821 dc
->putMonoImage(0, 0, icon
->xorMask
.width
, icon
->byteWidth
,
822 icon
->xorMask
.height
, (void*)icon
->andMask
);
824 bitmap
->SetMask(new wxMask(mask
));
826 MGL_unloadIcon(icon
);
831 bool wxICOBitmapHandler::SaveFile(const wxBitmap
*WXUNUSED(bitmap
),
832 const wxString
& WXUNUSED(name
),
834 const wxPalette
* WXUNUSED(palette
))
842 /*static*/ void wxBitmap::InitStandardHandlers()
844 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_BMP
, wxT("bmp"), wxT("Windows bitmap")));
845 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_BMP_RESOURCE
, wxEmptyString
, wxT("Windows bitmap resource")));
846 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_JPEG
, wxT("jpg"), wxT("JPEG image")));
847 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_JPEG_RESOURCE
, wxEmptyString
, wxT("JPEG resource")));
848 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_PCX
, wxT("pcx"), wxT("PCX image")));
849 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_PCX_RESOURCE
, wxEmptyString
, wxT("PCX resource")));
851 AddHandler(new wxPNGBitmapHandler(wxBITMAP_TYPE_PNG
, wxT("png"), wxT("PNG image")));
852 AddHandler(new wxPNGBitmapHandler(wxBITMAP_TYPE_PNG_RESOURCE
, wxEmptyString
, wxT("PNG resource")));
854 AddHandler(new wxICOBitmapHandler(wxBITMAP_TYPE_ICO
, wxT("ico"), wxT("Icon resource")));
855 AddHandler(new wxICOBitmapHandler(wxBITMAP_TYPE_ICO_RESOURCE
, wxEmptyString
, wxT("Icon resource")));