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
);
166 //-----------------------------------------------------------------------------
168 #define M_BMPDATA ((wxBitmapRefData *)m_refData)
170 IMPLEMENT_DYNAMIC_CLASS(wxBitmap
,wxBitmapBase
)
172 wxBitmap::wxBitmap(int width
, int height
, int depth
)
174 Create(width
, height
, depth
);
178 wxGDIRefData
*wxBitmap::CreateGDIRefData() const
180 return new wxBitmapRefData
;
183 wxGDIRefData
*wxBitmap::CloneGDIRefData(const wxGDIRefData
*data
) const
185 return new wxBitmapRefData(*wx_static_cast(const wxBitmapRefData
*, data
));
188 bool wxBitmap::Create(int width
, int height
, int depth
)
192 wxCHECK_MSG( (width
> 0) && (height
> 0), false, wxT("invalid bitmap size") );
194 m_refData
= new wxBitmapRefData(width
, height
, depth
);
198 // MGL does not support mono DCs, so we have to emulate them with
199 // 8bpp ones. We do that by using a special palette with color 0
200 // set to black and all other colors set to white.
201 SetMonoPalette(wxColour(255, 255, 255), wxColour(0, 0, 0));
207 wxBitmap::wxBitmap(const wxImage
& image
, int depth
)
211 wxCHECK_RET( image
.Ok(), wxT("invalid image") );
213 width
= image
.GetWidth();
214 height
= image
.GetHeight();
216 if ( !Create(width
, height
, depth
) ) return;
218 MGLMemoryDC
idc(width
, height
, 24, &gs_pixel_format_wxImage
,
219 width
* 3, (void*)image
.GetData(), NULL
);
220 wxASSERT_MSG( idc
.isValid(), wxT("cannot create custom MGLDC") );
222 MGLDevCtx
*bdc
= CreateTmpDC();
224 if ( GetDepth() <= 8 && image
.HasPalette() )
225 SetPalette(image
.GetPalette());
227 bdc
->bitBlt(idc
, 0, 0, width
, height
, 0, 0, MGL_REPLACE_MODE
);
230 if ( image
.HasMask() )
232 wxImage mask_image
= image
.ConvertToMono(image
.GetMaskRed(),
233 image
.GetMaskGreen(),
234 image
.GetMaskBlue());
235 mask_image
.SetMask(false);
236 wxBitmap
mask_bmp(mask_image
, 1);
237 SetMask(new wxMask(mask_bmp
));
241 wxImage
wxBitmap::ConvertToImage() const
243 wxCHECK_MSG( Ok(), wxImage(), wxT("invalid bitmap") );
247 height
= GetHeight();
249 wxImage
image(width
, height
);
250 wxASSERT_MSG( image
.Ok(), wxT("cannot create image") );
252 MGLMemoryDC
idc(width
, height
, 24, &gs_pixel_format_wxImage
,
253 width
* 3, (void*)image
.GetData(), NULL
);
254 wxASSERT_MSG( idc
.isValid(), wxT("cannot create custom MGLDC") );
256 if ( M_BMPDATA
->m_palette
)
257 image
.SetPalette(*(M_BMPDATA
->m_palette
));
261 // in consistency with other ports, we convert parts covered
262 // by the mask to <16,16,16> colour and set that colour to image's
263 // mask. We do that by OR-blitting the mask over image with
264 // bg colour set to black and fg colour to <16,16,16>
266 image
.SetMaskColour(16, 16, 16);
270 tmpDC
.SetMGLDC(&idc
, false);
271 tmpDC
.SetBackground(wxBrush(wxColour(16,16,16), wxSOLID
));
273 tmpDC
.DrawBitmap(*this, 0, 0, true);
277 image
.SetMask(false);
278 idc
.putBitmap(0, 0, M_BMPDATA
->m_bitmap
, MGL_REPLACE_MODE
);
284 wxBitmap::wxBitmap(const wxString
&filename
, wxBitmapType type
)
286 LoadFile(filename
, type
);
289 wxBitmap::wxBitmap(const char bits
[], int width
, int height
, int depth
)
291 wxCHECK_RET( depth
== 1, wxT("can only create mono bitmap from XBM data") );
293 if ( !Create(width
, height
, 1) ) return;
294 MGLDevCtx
*bdc
= CreateTmpDC();
295 wxCurrentDCSwitcher
curDC(bdc
);
297 bdc
->setBackColor(0);
299 bdc
->putMonoImage(0, 0, width
, (width
+ 7) / 8, height
, (void*)bits
);
303 int wxBitmap::GetHeight() const
305 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
307 return M_BMPDATA
->m_height
;
310 int wxBitmap::GetWidth() const
312 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
314 return M_BMPDATA
->m_width
;
317 int wxBitmap::GetDepth() const
319 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
321 return M_BMPDATA
->m_bpp
;
324 wxMask
*wxBitmap::GetMask() const
326 wxCHECK_MSG( Ok(), (wxMask
*) NULL
, wxT("invalid bitmap") );
328 return M_BMPDATA
->m_mask
;
331 void wxBitmap::SetMask(wxMask
*mask
)
333 wxCHECK_RET( Ok(), wxT("invalid bitmap") );
336 delete M_BMPDATA
->m_mask
;
337 M_BMPDATA
->m_mask
= mask
;
340 bool wxBitmap::CopyFromIcon(const wxIcon
& icon
)
342 wxBitmap
*bmp
= (wxBitmap
*)(&icon
);
347 wxBitmap
wxBitmap::GetSubBitmap(const wxRect
& rect
) const
350 (rect
.x
>= 0) && (rect
.y
>= 0) &&
351 (rect
.x
+rect
.width
<= M_BMPDATA
->m_width
) && (rect
.y
+rect
.height
<= M_BMPDATA
->m_height
),
352 wxNullBitmap
, wxT("invalid bitmap or bitmap region") );
354 wxBitmap
ret( rect
.width
, rect
.height
, M_BMPDATA
->m_bpp
);
355 wxASSERT_MSG( ret
.Ok(), wxT("GetSubBitmap error") );
358 ret
.SetPalette(*GetPalette());
360 MGLDevCtx
*tdc
= ret
.CreateTmpDC();
361 tdc
->putBitmapSection(rect
.x
, rect
.y
,
362 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
363 0, 0, M_BMPDATA
->m_bitmap
, MGL_REPLACE_MODE
);
368 wxBitmap submask
= GetMask()->GetBitmap().GetSubBitmap(rect
);
369 ret
.SetMask(new wxMask(submask
));
375 void wxBitmap::SetMonoPalette(const wxColour
& fg
, const wxColour
& bg
)
377 wxCHECK_RET( Ok(), wxT("invalid bitmap") );
380 palette_t
*mono
= M_BMPDATA
->m_bitmap
->pal
;
382 wxCHECK_RET( M_BMPDATA
->m_bpp
== 1, wxT("bitmap is not 1bpp") );
383 wxCHECK_RET( mono
!= NULL
, wxT("bitmap w/o palette") );
385 mono
[0].red
= bg
.Red();
386 mono
[0].green
= bg
.Green();
387 mono
[0].blue
= bg
.Blue();
389 for (size_t i
= 1; i
< 256; i
++)
391 mono
[i
].red
= fg
.Red();
392 mono
[i
].green
= fg
.Green();
393 mono
[i
].blue
= fg
.Blue();
398 MGLDevCtx
*wxBitmap::CreateTmpDC() const
400 wxCHECK_MSG( Ok(), NULL
, wxT("invalid bitmap") );
402 MGLDevCtx
*tdc
= new MGLMemoryDC(GetWidth(), GetHeight(),
403 M_BMPDATA
->m_bitmap
->bitsPerPixel
,
404 M_BMPDATA
->m_bitmap
->pf
,
405 M_BMPDATA
->m_bitmap
->bytesPerLine
,
406 M_BMPDATA
->m_bitmap
->surface
,
408 wxCHECK_MSG( tdc
->isValid(), NULL
, wxT("cannot create temporary MGLDC") );
410 if ( M_BMPDATA
->m_bitmap
->pal
!= NULL
)
414 switch (M_BMPDATA
->m_bitmap
->bitsPerPixel
)
416 case 2: cnt
= 2; break;
417 case 4: cnt
= 16; break;
418 case 8: cnt
= 256; break;
421 wxFAIL_MSG( wxT("bitmap with this depth cannot have palette") );
425 tdc
->setPalette(M_BMPDATA
->m_bitmap
->pal
, cnt
, 0);
426 tdc
->realizePalette(cnt
, 0, FALSE
);
432 bool wxBitmap::LoadFile(const wxString
&name
, wxBitmapType type
)
436 if ( type
== wxBITMAP_TYPE_BMP
|| type
== wxBITMAP_TYPE_PNG
||
437 type
== wxBITMAP_TYPE_PCX
|| type
== wxBITMAP_TYPE_JPEG
)
439 // prevent accidental loading of bitmap from $MGL_ROOT:
440 if ( !wxFileExists(name
) )
442 wxLogError(_("File %s does not exist."), name
.c_str());
447 wxBitmapHandler
*handler
= FindHandler(type
);
449 if ( handler
== NULL
)
452 if ( !image
.LoadFile(name
, type
) || !image
.Ok() )
454 wxLogError("no bitmap handler for type %d defined.", type
);
459 *this = wxBitmap(image
);
464 return handler
->LoadFile(this, name
, type
, -1, -1);
467 bool wxBitmap::SaveFile(const wxString
& filename
, wxBitmapType type
, const wxPalette
*palette
) const
469 wxCHECK_MSG( Ok(), false, wxT("invalid bitmap") );
471 wxBitmapHandler
*handler
= FindHandler(type
);
473 if ( handler
== NULL
)
475 wxImage image
= ConvertToImage();
477 image
.SetPalette(*palette
);
480 return image
.SaveFile(filename
, type
);
483 wxLogError("no bitmap handler for type %d defined.", type
);
488 return handler
->SaveFile(this, filename
, type
, palette
);
491 wxPalette
*wxBitmap::GetPalette() const
493 wxCHECK_MSG( Ok(), NULL
, wxT("invalid bitmap") );
495 return M_BMPDATA
->m_palette
;
498 void wxBitmap::SetPalette(const wxPalette
& palette
)
500 wxCHECK_RET( Ok(), wxT("invalid bitmap") );
501 wxCHECK_RET( GetDepth() > 1 && GetDepth() <= 8, wxT("cannot set palette for bitmap of this depth") );
504 delete M_BMPDATA
->m_palette
;
505 M_BMPDATA
->m_palette
= NULL
;
507 if ( !palette
.Ok() ) return;
509 M_BMPDATA
->m_palette
= new wxPalette(palette
);
511 int cnt
= palette
.GetColoursCount();
512 palette_t
*pal
= palette
.GetMGLpalette_t();
513 memcpy(M_BMPDATA
->m_bitmap
->pal
, pal
, cnt
* sizeof(palette_t
));
516 void wxBitmap::SetHeight(int height
)
520 M_BMPDATA
->m_height
= height
;
523 void wxBitmap::SetWidth(int width
)
527 M_BMPDATA
->m_width
= width
;
530 void wxBitmap::SetDepth(int depth
)
534 M_BMPDATA
->m_bpp
= depth
;
537 bitmap_t
*wxBitmap::GetMGLbitmap_t() const
539 return M_BMPDATA
->m_bitmap
;
542 // Convert wxColour into it's quantized value in lower-precision
543 // pixel format (needed for masking by colour).
544 wxColour
wxBitmap::QuantizeColour(const wxColour
& clr
) const
546 pixel_format_t
*pf
= GetMGLbitmap_t()->pf
;
548 if ( pf
->redAdjust
== 0 && pf
->greenAdjust
== 0 && pf
->blueAdjust
== 0 )
551 return wxColour((unsigned char)((clr
.Red() >> pf
->redAdjust
) << pf
->redAdjust
),
552 (unsigned char)((clr
.Green() >> pf
->greenAdjust
) << pf
->greenAdjust
),
553 (unsigned char)((clr
.Blue() >> pf
->blueAdjust
) << pf
->blueAdjust
));
557 //-----------------------------------------------------------------------------
558 // wxBitmap I/O handlers
559 //-----------------------------------------------------------------------------
561 class wxMGLBitmapHandler
: public wxBitmapHandler
564 wxMGLBitmapHandler(wxBitmapType type
,
565 const wxString
& extension
, const wxString
& name
);
567 virtual bool Create(wxBitmap
*WXUNUSED(bitmap
),
568 const void* WXUNUSED(data
),
569 long WXUNUSED(flags
),
571 int WXUNUSED(height
),
572 int WXUNUSED(depth
) = 1)
575 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
576 int desiredWidth
, int desiredHeight
);
577 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
578 int type
, const wxPalette
*palette
= NULL
);
581 wxMGLBitmapHandler::wxMGLBitmapHandler(wxBitmapType type
,
582 const wxString
& extension
,
583 const wxString
& name
)
588 SetExtension(extension
);
591 bool wxMGLBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
,
593 int WXUNUSED(desiredWidth
),
594 int WXUNUSED(desiredHeight
))
596 int width
, height
, bpp
;
603 case wxBITMAP_TYPE_BMP_RESOURCE
:
604 case wxBITMAP_TYPE_JPEG_RESOURCE
:
605 case wxBITMAP_TYPE_PNG_RESOURCE
:
606 case wxBITMAP_TYPE_PCX_RESOURCE
:
607 fullname
= name
+ wxT(".bmp");
616 case wxBITMAP_TYPE_BMP
:
617 case wxBITMAP_TYPE_BMP_RESOURCE
:
618 if ( !MGL_getBitmapSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
620 bitmap
->Create(width
, height
, -1);
621 if ( !bitmap
->Ok() ) return false;
622 dc
.SelectObject(*bitmap
);
623 if ( !dc
.GetMGLDC()->loadBitmapIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
627 case wxBITMAP_TYPE_JPEG
:
628 case wxBITMAP_TYPE_JPEG_RESOURCE
:
629 if ( !MGL_getJPEGSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
631 bitmap
->Create(width
, height
, -1);
632 if ( !bitmap
->Ok() ) return false;
633 dc
.SelectObject(*bitmap
);
634 if ( !dc
.GetMGLDC()->loadJPEGIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
638 case wxBITMAP_TYPE_PNG
:
639 case wxBITMAP_TYPE_PNG_RESOURCE
:
640 if ( !MGL_getPNGSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
642 bitmap
->Create(width
, height
, -1);
643 if ( !bitmap
->Ok() ) return false;
644 dc
.SelectObject(*bitmap
);
645 if ( !dc
.GetMGLDC()->loadPNGIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
649 case wxBITMAP_TYPE_PCX
:
650 case wxBITMAP_TYPE_PCX_RESOURCE
:
651 if ( !MGL_getPCXSize(fullname
.mb_str(), &width
, &height
, &bpp
) )
653 bitmap
->Create(width
, height
, -1);
654 if ( !bitmap
->Ok() ) return false;
655 dc
.SelectObject(*bitmap
);
656 if ( !dc
.GetMGLDC()->loadPCXIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
661 wxFAIL_MSG(wxT("Unsupported image format."));
668 bool wxMGLBitmapHandler::SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
669 int type
, const wxPalette
* WXUNUSED(palette
))
673 int w
= bitmap
->GetWidth(),
674 h
= bitmap
->GetHeight();
676 mem
.SelectObjectAsSource(*bitmap
);
677 tdc
= mem
.GetMGLDC();
681 case wxBITMAP_TYPE_BMP
:
682 return (bool)tdc
->saveBitmapFromDC(name
.mb_str(), 0, 0, w
, h
);
683 case wxBITMAP_TYPE_JPEG
:
684 return (bool)tdc
->saveJPEGFromDC(name
.mb_str(), 0, 0, w
, h
, 75);
685 case wxBITMAP_TYPE_PNG
:
686 return (bool)tdc
->savePNGFromDC(name
.mb_str(), 0, 0, w
, h
);
687 case wxBITMAP_TYPE_PCX
:
688 return (bool)tdc
->savePCXFromDC(name
.mb_str(), 0, 0, w
, h
);
696 // let's handle PNGs in special way because they have alpha channel
697 // which we can access via bitmap_t most easily
698 class wxPNGBitmapHandler
: public wxMGLBitmapHandler
701 wxPNGBitmapHandler(wxBitmapType type
,
702 const wxString
& extension
, const wxString
& name
)
703 : wxMGLBitmapHandler(type
, extension
, name
) {}
705 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
706 int desiredWidth
, int desiredHeight
);
709 bool wxPNGBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
,
711 int desiredWidth
, int desiredHeight
)
713 int width
, height
, bpp
;
717 if ( flags
== wxBITMAP_TYPE_PNG_RESOURCE
)
718 fullname
= name
+ wxT(".png");
722 if ( !MGL_getPNGSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
727 // We can load ordinary PNGs faster with 'normal' MGL handler.
728 // Only RGBA PNGs need to be processed in special way because
729 // we have to convert alpha channel to mask
730 return wxMGLBitmapHandler::LoadFile(bitmap
, name
, flags
,
731 desiredWidth
, desiredHeight
);
734 bitmap_t
*bmp
= MGL_loadPNG(fullname
.mb_str(), TRUE
);
736 if ( bmp
== NULL
) return false;
738 bitmap
->Create(bmp
->width
, bmp
->height
, -1);
739 if ( !bitmap
->Ok() ) return false;
741 // convert bmp to display's depth and write it to *bitmap:
743 dc
.SelectObject(*bitmap
);
744 dc
.GetMGLDC()->putBitmap(0, 0, bmp
, MGL_REPLACE_MODE
);
745 dc
.SelectObject(wxNullBitmap
);
747 // create mask, if bmp contains alpha channel (ARGB format):
748 if ( bmp
->bitsPerPixel
== 32 )
751 wxUint32
*s
= (wxUint32
*)bmp
->surface
;
752 for (y
= 0; y
< bmp
->height
; y
++)
754 s
= ((wxUint32
*)bmp
->surface
) + y
* bmp
->bytesPerLine
/4;
755 for (x
= 0; x
< bmp
->width
; x
++, s
++)
757 if ( ((((*s
) >> bmp
->pf
->alphaPos
) & bmp
->pf
->alphaMask
)
758 << bmp
->pf
->alphaAdjust
) < 128 )
761 *s
= 0x00FFFFFF; // white
764 wxBitmap
mask(bmp
->width
, bmp
->height
, 1);
765 dc
.SelectObject(mask
);
766 dc
.GetMGLDC()->putBitmap(0, 0, bmp
, MGL_REPLACE_MODE
);
767 dc
.SelectObject(wxNullBitmap
);
768 bitmap
->SetMask(new wxMask(mask
));
771 MGL_unloadBitmap(bmp
);
779 class wxICOBitmapHandler
: public wxBitmapHandler
782 wxICOBitmapHandler(wxBitmapType type
,
783 const wxString
& extension
, const wxString
& name
);
785 virtual bool Create(wxBitmap
*WXUNUSED(bitmap
),
786 const void* WXUNUSED(data
),
787 long WXUNUSED(flags
),
789 int WXUNUSED(height
),
790 int WXUNUSED(depth
) = 1)
793 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
794 int desiredWidth
, int desiredHeight
);
795 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
796 int type
, const wxPalette
*palette
= NULL
);
799 wxICOBitmapHandler::wxICOBitmapHandler(wxBitmapType type
,
800 const wxString
& extension
,
801 const wxString
& name
)
806 SetExtension(extension
);
809 bool wxICOBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
,
811 int WXUNUSED(desiredWidth
),
812 int WXUNUSED(desiredHeight
))
817 if ( flags
== wxBITMAP_TYPE_ICO_RESOURCE
)
818 icon
= MGL_loadIcon(wxString(name
+ wxT(".ico")).mb_str(), TRUE
);
820 icon
= MGL_loadIcon(name
.mb_str(), TRUE
);
822 if ( icon
== NULL
) return false;
824 bitmap
->Create(icon
->xorMask
.width
, icon
->xorMask
.height
);
827 mem
.SelectObject(*bitmap
);
829 dc
->putBitmap(0, 0, &(icon
->xorMask
), MGL_REPLACE_MODE
);
830 mem
.SelectObject(wxNullBitmap
);
832 wxBitmap
mask(icon
->xorMask
.width
, icon
->xorMask
.height
, 1);
833 mem
.SelectObject(mask
);
836 wxCurrentDCSwitcher
curDC(dc
);
840 dc
->putMonoImage(0, 0, icon
->xorMask
.width
, icon
->byteWidth
,
841 icon
->xorMask
.height
, (void*)icon
->andMask
);
843 bitmap
->SetMask(new wxMask(mask
));
845 MGL_unloadIcon(icon
);
850 bool wxICOBitmapHandler::SaveFile(const wxBitmap
*WXUNUSED(bitmap
),
851 const wxString
& WXUNUSED(name
),
853 const wxPalette
* WXUNUSED(palette
))
861 /*static*/ void wxBitmap::InitStandardHandlers()
863 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_BMP
, wxT("bmp"), wxT("Windows bitmap")));
864 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_BMP_RESOURCE
, wxEmptyString
, wxT("Windows bitmap resource")));
865 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_JPEG
, wxT("jpg"), wxT("JPEG image")));
866 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_JPEG_RESOURCE
, wxEmptyString
, wxT("JPEG resource")));
867 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_PCX
, wxT("pcx"), wxT("PCX image")));
868 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_PCX_RESOURCE
, wxEmptyString
, wxT("PCX resource")));
870 AddHandler(new wxPNGBitmapHandler(wxBITMAP_TYPE_PNG
, wxT("png"), wxT("PNG image")));
871 AddHandler(new wxPNGBitmapHandler(wxBITMAP_TYPE_PNG_RESOURCE
, wxEmptyString
, wxT("PNG resource")));
873 AddHandler(new wxICOBitmapHandler(wxBITMAP_TYPE_ICO
, wxT("ico"), wxT("Icon resource")));
874 AddHandler(new wxICOBitmapHandler(wxBITMAP_TYPE_ICO_RESOURCE
, wxEmptyString
, wxT("Icon resource")));