1 /////////////////////////////////////////////////////////////////////////////
3 // Author: Vaclav Slavik
5 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
10 #pragma implementation "bitmap.h"
13 // For compilers that support precompilation, includes "wx.h".
14 #include "wx/wxprec.h"
20 #include "wx/bitmap.h"
22 #include "wx/filefn.h"
24 #include "wx/dcmemory.h"
29 #include "wx/xpmdecod.h"
31 #include "wx/mgl/private.h"
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
39 static pixel_format_t gs_pixel_format_15
=
40 {0x1F,0x0A,3, 0x1F,0x05,3, 0x1F,0x00,3, 0x01,0x0F,7}; // 555 15bpp
42 static pixel_format_t gs_pixel_format_16
=
43 {0x1F,0x0B,3, 0x3F,0x05,2, 0x1F,0x00,3, 0x00,0x00,0}; // 565 16bpp
45 static pixel_format_t gs_pixel_format_24
=
46 {0xFF,0x10,0, 0xFF,0x08,0, 0xFF,0x00,0, 0x00,0x00,0}; // RGB 24bpp
48 static pixel_format_t gs_pixel_format_32
=
49 {0xFF,0x18,0, 0xFF,0x10,0, 0xFF,0x08,0, 0xFF,0x00,0}; // RGBA 32bpp
51 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
55 IMPLEMENT_DYNAMIC_CLASS(wxMask
,wxObject
)
62 wxMask::wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
)
65 Create(bitmap
, colour
);
68 wxMask::wxMask(const wxBitmap
& bitmap
, int paletteIndex
)
71 Create(bitmap
, paletteIndex
);
74 wxMask::wxMask(const wxBitmap
& bitmap
)
85 bool wxMask::Create(const wxBitmap
& bitmap
, const wxColour
& colour
)
90 wxImage image
= bitmap
.ConvertToImage().ConvertToMono(
91 colour
.Red(), colour
.Green(), colour
.Blue());
92 if ( !image
.Ok() ) return FALSE
;
94 m_bitmap
= new wxBitmap(image
, 1);
96 return m_bitmap
->Ok();
99 bool wxMask::Create(const wxBitmap
& bitmap
, int paletteIndex
)
102 wxPalette
*pal
= bitmap
.GetPalette();
104 wxCHECK_MSG( pal
, FALSE
, wxT("Cannot create mask from bitmap without palette") );
106 pal
->GetRGB(paletteIndex
, &r
, &g
, &b
);
108 return Create(bitmap
, wxColour(r
, g
, b
));
111 bool wxMask::Create(const wxBitmap
& bitmap
)
116 wxCHECK_MSG( bitmap
.Ok(), FALSE
, wxT("Invalid bitmap") );
117 wxCHECK_MSG( bitmap
.GetDepth() == 1, FALSE
, wxT("Cannot create mask from colour bitmap") );
119 m_bitmap
= new wxBitmap(bitmap
);
124 //-----------------------------------------------------------------------------
126 //-----------------------------------------------------------------------------
128 class wxBitmapRefData
: public wxObjectRefData
137 wxPalette
*m_palette
;
142 wxBitmapRefData::wxBitmapRefData()
152 wxBitmapRefData::~wxBitmapRefData()
155 MGL_unloadBitmap(m_bitmap
);
160 //-----------------------------------------------------------------------------
162 #define M_BMPDATA ((wxBitmapRefData *)m_refData)
165 IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandler
,wxObject
)
166 IMPLEMENT_DYNAMIC_CLASS(wxBitmap
,wxBitmapBase
)
170 if ( wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
173 wxBitmap::wxBitmap(int width
, int height
, int depth
)
175 Create(width
, height
, depth
);
177 if ( wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
181 static bitmap_t
*MyMGL_createBitmap(int width
, int height
,
182 int bpp
, pixel_format_t
*pf
)
184 MGLMemoryDC
mdc(width
, height
, bpp
, pf
);
185 return MGL_getBitmapFromDC(mdc
.getDC(), 0, 0, width
, height
, TRUE
);
188 bool wxBitmap::Create(int width
, int height
, int depth
)
192 wxCHECK_MSG( (width
> 0) && (height
> 0), FALSE
, wxT("invalid bitmap size") )
194 pixel_format_t pf_dummy
, *pf
;
195 int mglDepth
= depth
;
200 wxASSERT_MSG( g_displayDC
, wxT("MGL display DC not created yet.") );
202 g_displayDC
->getPixelFormat(pf_dummy
);
203 mglDepth
= g_displayDC
->getBitsPerPixel();
211 pf
= &gs_pixel_format_15
;
214 pf
= &gs_pixel_format_16
;
217 pf
= &gs_pixel_format_24
;
220 pf
= &gs_pixel_format_32
;
223 wxASSERT_MSG( 0, wxT("invalid bitmap depth") );
228 m_refData
= new wxBitmapRefData();
229 M_BMPDATA
->m_mask
= (wxMask
*) NULL
;
230 M_BMPDATA
->m_palette
= (wxPalette
*) NULL
;
231 M_BMPDATA
->m_width
= width
;
232 M_BMPDATA
->m_height
= height
;
233 M_BMPDATA
->m_bpp
= mglDepth
;
237 M_BMPDATA
->m_bitmap
= MyMGL_createBitmap(width
, height
, mglDepth
, pf
);
241 // MGL does not support mono DCs, so we have to emulate them with
242 // 8bpp ones. We do that by using a special palette with color 0
243 // set to black and all other colors set to white.
245 M_BMPDATA
->m_bitmap
= MyMGL_createBitmap(width
, height
, 8, pf
);
246 SetMonoPalette(wxColour(255, 255, 255), wxColour(0, 0, 0));
252 bool wxBitmap::CreateFromXpm(const char **bits
)
254 wxCHECK_MSG( bits
!= NULL
, FALSE
, wxT("invalid bitmap data") )
256 wxXPMDecoder decoder
;
257 wxImage img
= decoder
.ReadData(bits
);
258 wxCHECK_MSG( img
.Ok(), FALSE
, wxT("invalid bitmap data") )
260 *this = wxBitmap(img
);
262 if ( wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
267 wxBitmap::wxBitmap(const wxImage
& image
, int depth
= -1)
271 wxCHECK_RET( image
.Ok(), wxT("invalid image") )
273 width
= image
.GetWidth();
274 height
= image
.GetHeight();
276 if ( !Create(width
, height
, depth
) ) return;
278 MGLMemoryDC
idc(width
, height
, 24, &gs_pixel_format_24
,
279 width
* 3, (void*)image
.GetData(), NULL
);
280 wxASSERT_MSG( idc
.isValid(), wxT("cannot create custom MGLDC") );
282 MGLDevCtx
*bdc
= CreateTmpDC();
284 if ( depth
<= 8 && image
.HasPalette() )
285 SetPalette(image
.GetPalette());
287 bdc
->bitBlt(idc
, 0, 0, width
, height
, 0, 0, MGL_REPLACE_MODE
);
290 if ( image
.HasMask() )
292 wxImage mask_image
= image
.ConvertToMono(image
.GetMaskRed(),
293 image
.GetMaskGreen(),
294 image
.GetMaskBlue());
295 mask_image
.SetMask(FALSE
);
296 wxBitmap
mask_bmp(mask_image
, 1);
297 SetMask(new wxMask(mask_bmp
));
301 wxImage
wxBitmap::ConvertToImage() const
303 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid bitmap") );
307 height
= GetHeight();
309 wxImage
image(width
, height
);
310 wxASSERT_MSG( image
.Ok(), wxT("cannot create image") );
312 MGLMemoryDC
idc(width
, height
, 24, &gs_pixel_format_24
,
313 width
* 3, (void*)image
.GetData(), NULL
);
314 wxASSERT_MSG( idc
.isValid(), wxT("cannot create custom MGLDC") );
316 if ( M_BMPDATA
->m_palette
)
317 image
.SetPalette(*(M_BMPDATA
->m_palette
));
321 // in consistency with other ports, we convert parts covered
322 // by the mask to <16,16,16> colour and set that colour to image's
323 // mask. We do that by OR-blitting the mask over image with
324 // bg colour set to black and fg colour to <16,16,16>
326 image
.SetMaskColour(16, 16, 16);
330 tmpDC
.SetMGLDC(&idc
, FALSE
);
331 tmpDC
.SetBackground(wxBrush(wxColour(16,16,16), wxSOLID
));
333 tmpDC
.DrawBitmap(*this, 0, 0, TRUE
);
337 image
.SetMask(FALSE
);
338 idc
.putBitmap(0, 0, M_BMPDATA
->m_bitmap
, MGL_REPLACE_MODE
);
344 wxBitmap::wxBitmap(const wxBitmap
& bmp
)
348 if ( wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
351 wxBitmap::wxBitmap(const wxString
&filename
, wxBitmapType type
)
353 LoadFile(filename
, type
);
355 if ( wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
358 wxBitmap::wxBitmap(const char bits
[], int width
, int height
, int depth
)
360 wxCHECK_RET( depth
== 1, wxT("can only create mono bitmap from XBM data") );
362 if ( !Create(width
, height
, 1) ) return;
363 MGLDevCtx
*bdc
= CreateTmpDC();
364 wxCurrentDCSwitcher
curDC(bdc
);
366 bdc
->setBackColor(0);
368 bdc
->putMonoImage(0, 0, width
, (width
+ 7) / 8, height
, (void*)bits
);
371 if ( wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
374 wxBitmap::~wxBitmap()
376 if ( wxTheBitmapList
) wxTheBitmapList
->DeleteObject(this);
379 wxBitmap
& wxBitmap::operator = (const wxBitmap
& bmp
)
381 if ( *this == bmp
) return (*this);
386 bool wxBitmap::operator == (const wxBitmap
& bmp
) const
388 return (m_refData
== bmp
.m_refData
);
391 bool wxBitmap::operator != (const wxBitmap
& bmp
) const
393 return (m_refData
!= bmp
.m_refData
);
396 bool wxBitmap::Ok() const
398 return (m_refData
!= NULL
&& M_BMPDATA
->m_bitmap
!= NULL
);
401 int wxBitmap::GetHeight() const
403 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
405 return M_BMPDATA
->m_height
;
408 int wxBitmap::GetWidth() const
410 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
412 return M_BMPDATA
->m_width
;
415 int wxBitmap::GetDepth() const
417 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
419 return M_BMPDATA
->m_bpp
;
422 wxMask
*wxBitmap::GetMask() const
424 wxCHECK_MSG( Ok(), (wxMask
*) NULL
, wxT("invalid bitmap") );
426 return M_BMPDATA
->m_mask
;
429 void wxBitmap::SetMask(wxMask
*mask
)
431 wxCHECK_RET( Ok(), wxT("invalid bitmap") );
433 delete M_BMPDATA
->m_mask
;
434 M_BMPDATA
->m_mask
= mask
;
437 bool wxBitmap::CopyFromIcon(const wxIcon
& icon
)
439 wxBitmap
*bmp
= (wxBitmap
*)(&icon
);
444 wxBitmap
wxBitmap::GetSubBitmap(const wxRect
& rect
) const
447 (rect
.x
>= 0) && (rect
.y
>= 0) &&
448 (rect
.x
+rect
.width
<= M_BMPDATA
->m_width
) && (rect
.y
+rect
.height
<= M_BMPDATA
->m_height
),
449 wxNullBitmap
, wxT("invalid bitmap or bitmap region") );
451 wxBitmap
ret( rect
.width
, rect
.height
, M_BMPDATA
->m_bpp
);
452 wxASSERT_MSG( ret
.Ok(), wxT("GetSubBitmap error") );
455 ret
.SetPalette(*GetPalette());
457 MGLDevCtx
*tdc
= ret
.CreateTmpDC();
458 tdc
->putBitmapSection(rect
.x
, rect
.y
,
459 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
460 0, 0, M_BMPDATA
->m_bitmap
, MGL_REPLACE_MODE
);
465 wxBitmap submask
= GetMask()->GetBitmap()->GetSubBitmap(rect
);
466 ret
.SetMask(new wxMask(submask
));
472 void wxBitmap::SetMonoPalette(const wxColour
& fg
, const wxColour
& bg
)
474 wxCHECK_RET( Ok(), wxT("invalid bitmap") );
476 palette_t
*mono
= M_BMPDATA
->m_bitmap
->pal
;
478 wxCHECK_RET( M_BMPDATA
->m_bpp
== 1, wxT("bitmap is not 1bpp") );
479 wxCHECK_RET( mono
!= NULL
, wxT("bitmap w/o palette") );
481 mono
[0].red
= bg
.Red();
482 mono
[0].green
= bg
.Green();
483 mono
[0].blue
= bg
.Blue();
485 for (size_t i
= 1; i
< 256; i
++)
487 mono
[i
].red
= fg
.Red();
488 mono
[i
].green
= fg
.Green();
489 mono
[i
].blue
= fg
.Blue();
494 MGLDevCtx
*wxBitmap::CreateTmpDC() const
496 wxCHECK_MSG( Ok(), NULL
, wxT("invalid bitmap") );
498 MGLDevCtx
*tdc
= new MGLMemoryDC(GetWidth(), GetHeight(),
499 M_BMPDATA
->m_bitmap
->bitsPerPixel
,
500 M_BMPDATA
->m_bitmap
->pf
,
501 M_BMPDATA
->m_bitmap
->bytesPerLine
,
502 M_BMPDATA
->m_bitmap
->surface
,
504 wxCHECK_MSG( tdc
->isValid(), NULL
, wxT("cannot create temporary MGLDC") );
506 if ( M_BMPDATA
->m_bitmap
->pal
!= NULL
)
510 switch (M_BMPDATA
->m_bitmap
->bitsPerPixel
)
512 case 2: cnt
= 2; break;
513 case 4: cnt
= 16; break;
514 case 8: cnt
= 256; break;
517 wxFAIL_MSG( wxT("bitmap with this depth cannot have palette") );
521 tdc
->setPalette(M_BMPDATA
->m_bitmap
->pal
, cnt
, 0);
522 tdc
->realizePalette(cnt
, 0, FALSE
);
528 bool wxBitmap::LoadFile(const wxString
&name
, wxBitmapType type
)
532 if ( type
== wxBITMAP_TYPE_BMP
|| type
== wxBITMAP_TYPE_PNG
||
533 type
== wxBITMAP_TYPE_PCX
|| type
== wxBITMAP_TYPE_JPEG
)
535 // prevent accidental loading of bitmap from $MGL_ROOT:
536 if ( !wxFileExists(name
) )
538 wxLogError(_("File %s does not exist."), name
.c_str());
543 wxBitmapHandler
*handler
= FindHandler(type
);
545 if ( handler
== NULL
)
548 if ( !image
.LoadFile(name
, type
) || !image
.Ok() )
550 wxLogError("no bitmap handler for type %d defined.", type
);
555 *this = wxBitmap(image
);
560 m_refData
= new wxBitmapRefData();
562 return handler
->LoadFile(this, name
, type
, -1, -1);
565 bool wxBitmap::SaveFile(const wxString
& filename
, wxBitmapType type
, const wxPalette
*palette
) const
567 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid bitmap") );
569 wxBitmapHandler
*handler
= FindHandler(type
);
571 if ( handler
== NULL
)
573 wxImage image
= ConvertToImage();
575 image
.SetPalette(*palette
);
578 return image
.SaveFile(filename
, type
);
581 wxLogError("no bitmap handler for type %d defined.", type
);
586 return handler
->SaveFile(this, filename
, type
, palette
);
589 wxPalette
*wxBitmap::GetPalette() const
591 wxCHECK_MSG( Ok(), NULL
, wxT("invalid bitmap") );
593 return M_BMPDATA
->m_palette
;
596 void wxBitmap::SetPalette(const wxPalette
& palette
)
598 wxCHECK_RET( Ok(), wxT("invalid bitmap") );
599 wxCHECK_RET( GetDepth() > 1 && GetDepth() <= 8, wxT("cannot set palette for bitmap of this depth") );
601 delete M_BMPDATA
->m_palette
;
602 M_BMPDATA
->m_palette
= NULL
;
604 if ( !palette
.Ok() ) return;
606 M_BMPDATA
->m_palette
= new wxPalette(palette
);
608 int cnt
= palette
.GetColoursCount();
609 palette_t
*pal
= palette
.GetMGLpalette_t();
610 memcpy(M_BMPDATA
->m_bitmap
->pal
, pal
, cnt
* sizeof(palette_t
));
613 void wxBitmap::SetHeight(int height
)
615 if (!m_refData
) m_refData
= new wxBitmapRefData();
617 M_BMPDATA
->m_height
= height
;
620 void wxBitmap::SetWidth(int width
)
622 if (!m_refData
) m_refData
= new wxBitmapRefData();
624 M_BMPDATA
->m_width
= width
;
627 void wxBitmap::SetDepth(int depth
)
629 if (!m_refData
) m_refData
= new wxBitmapRefData();
631 M_BMPDATA
->m_bpp
= depth
;
634 bitmap_t
*wxBitmap::GetMGLbitmap_t() const
636 return M_BMPDATA
->m_bitmap
;
641 //-----------------------------------------------------------------------------
642 // wxBitmap I/O handlers
643 //-----------------------------------------------------------------------------
645 class wxMGLBitmapHandler
: public wxBitmapHandler
648 wxMGLBitmapHandler(wxBitmapType type
,
649 const wxString
& extension
, const wxString
& name
);
651 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
,
652 int width
, int height
, int depth
= 1)
655 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
656 int desiredWidth
, int desiredHeight
);
657 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
658 int type
, const wxPalette
*palette
= NULL
);
661 wxMGLBitmapHandler::wxMGLBitmapHandler(wxBitmapType type
,
662 const wxString
& extension
,
663 const wxString
& name
)
668 SetExtension(extension
);
671 bool wxMGLBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
,
673 int WXUNUSED(desiredWidth
),
674 int WXUNUSED(desiredHeight
))
676 int width
, height
, bpp
;
683 case wxBITMAP_TYPE_BMP_RESOURCE
:
684 case wxBITMAP_TYPE_JPEG_RESOURCE
:
685 case wxBITMAP_TYPE_PNG_RESOURCE
:
686 case wxBITMAP_TYPE_PCX_RESOURCE
:
687 fullname
= name
+ wxT(".bmp");
696 case wxBITMAP_TYPE_BMP
:
697 case wxBITMAP_TYPE_BMP_RESOURCE
:
698 if ( !MGL_getBitmapSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
700 bitmap
->Create(width
, height
, -1);
701 if ( !bitmap
->Ok() ) return FALSE
;
702 dc
.SelectObject(*bitmap
);
703 if ( !dc
.GetMGLDC()->loadBitmapIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
707 case wxBITMAP_TYPE_JPEG
:
708 case wxBITMAP_TYPE_JPEG_RESOURCE
:
709 if ( !MGL_getJPEGSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
711 bitmap
->Create(width
, height
, -1);
712 if ( !bitmap
->Ok() ) return FALSE
;
713 dc
.SelectObject(*bitmap
);
714 if ( !dc
.GetMGLDC()->loadJPEGIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
718 case wxBITMAP_TYPE_PNG
:
719 case wxBITMAP_TYPE_PNG_RESOURCE
:
720 if ( !MGL_getPNGSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
722 bitmap
->Create(width
, height
, -1);
723 if ( !bitmap
->Ok() ) return FALSE
;
724 dc
.SelectObject(*bitmap
);
725 if ( !dc
.GetMGLDC()->loadPNGIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
729 case wxBITMAP_TYPE_PCX
:
730 case wxBITMAP_TYPE_PCX_RESOURCE
:
731 if ( !MGL_getPCXSize(fullname
.mb_str(), &width
, &height
, &bpp
) )
733 bitmap
->Create(width
, height
, -1);
734 if ( !bitmap
->Ok() ) return FALSE
;
735 dc
.SelectObject(*bitmap
);
736 if ( !dc
.GetMGLDC()->loadPCXIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
741 wxFAIL_MSG(wxT("Unsupported image format."));
748 bool wxMGLBitmapHandler::SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
749 int type
, const wxPalette
* WXUNUSED(palette
))
753 int w
= bitmap
->GetWidth(),
754 h
= bitmap
->GetHeight();
756 mem
.SelectObject(*bitmap
);
757 tdc
= mem
.GetMGLDC();
761 case wxBITMAP_TYPE_BMP
:
762 return tdc
->saveBitmapFromDC(name
.mb_str(), 0, 0, w
, h
);
764 case wxBITMAP_TYPE_JPEG
:
765 return tdc
->saveJPEGFromDC(name
.mb_str(), 0, 0, w
, h
, 75);
767 case wxBITMAP_TYPE_PNG
:
768 return tdc
->savePNGFromDC(name
.mb_str(), 0, 0, w
, h
);
770 case wxBITMAP_TYPE_PCX
:
771 return tdc
->savePCXFromDC(name
.mb_str(), 0, 0, w
, h
);
781 // let's handle PNGs in special way because they have alpha channel
782 // which we can access via bitmap_t most easily
783 class wxPNGBitmapHandler
: public wxMGLBitmapHandler
786 wxPNGBitmapHandler(wxBitmapType type
,
787 const wxString
& extension
, const wxString
& name
)
788 : wxMGLBitmapHandler(type
, extension
, name
) {}
790 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
791 int desiredWidth
, int desiredHeight
);
794 bool wxPNGBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
,
796 int desiredWidth
, int desiredHeight
)
798 int width
, height
, bpp
;
802 if ( flags
== wxBITMAP_TYPE_PNG_RESOURCE
)
803 fullname
= name
+ wxT(".png");
807 if ( !MGL_getPNGSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
812 // We can load ordinary PNGs faster with 'normal' MGL handler.
813 // Only RGBA PNGs need to be processed in special way because
814 // we have to convert alpha channel to mask
815 return wxMGLBitmapHandler::LoadFile(bitmap
, name
, flags
,
816 desiredWidth
, desiredHeight
);
819 bitmap_t
*bmp
= MGL_loadPNG(fullname
.mb_str(), TRUE
);
821 if ( bmp
== NULL
) return FALSE
;
823 bitmap
->Create(bmp
->width
, bmp
->height
, -1);
824 if ( !bitmap
->Ok() ) return FALSE
;
826 // convert bmp to display's depth and write it to *bitmap:
828 dc
.SelectObject(*bitmap
);
829 dc
.GetMGLDC()->putBitmap(0, 0, bmp
, MGL_REPLACE_MODE
);
830 dc
.SelectObject(wxNullBitmap
);
832 // create mask, if bmp contains alpha channel (ARGB format):
833 if ( bmp
->bitsPerPixel
== 32 )
836 wxUint32
*s
= (wxUint32
*)bmp
->surface
;
837 for (y
= 0; y
< bmp
->height
; y
++)
839 s
= ((wxUint32
*)bmp
->surface
) + y
* bmp
->bytesPerLine
/4;
840 for (x
= 0; x
< bmp
->width
; x
++, s
++)
842 if ( ((((*s
) >> bmp
->pf
->rsvdPos
) & bmp
->pf
->rsvdMask
)
843 << bmp
->pf
->rsvdAdjust
) < 128 )
846 *s
= 0x00FFFFFF; // white
849 wxBitmap
mask(bmp
->width
, bmp
->height
, 1);
850 dc
.SelectObject(mask
);
851 dc
.GetMGLDC()->putBitmap(0, 0, bmp
, MGL_REPLACE_MODE
);
852 dc
.SelectObject(wxNullBitmap
);
853 bitmap
->SetMask(new wxMask(mask
));
856 MGL_unloadBitmap(bmp
);
864 class wxICOBitmapHandler
: public wxBitmapHandler
867 wxICOBitmapHandler(wxBitmapType type
,
868 const wxString
& extension
, const wxString
& name
);
870 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
,
871 int width
, int height
, int depth
= 1)
874 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
875 int desiredWidth
, int desiredHeight
);
876 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
877 int type
, const wxPalette
*palette
= NULL
);
880 wxICOBitmapHandler::wxICOBitmapHandler(wxBitmapType type
,
881 const wxString
& extension
,
882 const wxString
& name
)
887 SetExtension(extension
);
890 bool wxICOBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
,
892 int WXUNUSED(desiredWidth
),
893 int WXUNUSED(desiredHeight
))
898 if ( flags
== wxBITMAP_TYPE_ICO_RESOURCE
)
899 icon
= MGL_loadIcon(wxString(name
+ wxT(".ico")).mb_str(), TRUE
);
901 icon
= MGL_loadIcon(name
.mb_str(), TRUE
);
903 if ( icon
== NULL
) return FALSE
;
905 bitmap
->Create(icon
->xorMask
.width
, icon
->xorMask
.height
);
908 mem
.SelectObject(*bitmap
);
910 dc
->putBitmap(0, 0, &(icon
->xorMask
), MGL_REPLACE_MODE
);
911 mem
.SelectObject(wxNullBitmap
);
913 wxBitmap
mask(icon
->xorMask
.width
, icon
->xorMask
.height
, 1);
914 mem
.SelectObject(mask
);
917 wxCurrentDCSwitcher
curDC(dc
);
921 dc
->putMonoImage(0, 0, icon
->xorMask
.width
, icon
->byteWidth
,
922 icon
->xorMask
.height
, (void*)icon
->andMask
);
924 bitmap
->SetMask(new wxMask(mask
));
926 MGL_unloadIcon(icon
);
931 bool wxICOBitmapHandler::SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
932 int type
, const wxPalette
* WXUNUSED(palette
))
940 /*static*/ void wxBitmap::InitStandardHandlers()
942 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_BMP
, wxT("bmp"), wxT("Windows bitmap")));
943 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_BMP_RESOURCE
, wxEmptyString
, wxT("Windows bitmap resource")));
944 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_JPEG
, wxT("jpg"), wxT("JPEG image")));
945 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_JPEG_RESOURCE
, wxEmptyString
, wxT("JPEG resource")));
946 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_PCX
, wxT("pcx"), wxT("PCX image")));
947 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_PCX_RESOURCE
, wxEmptyString
, wxT("PCX resource")));
949 AddHandler(new wxPNGBitmapHandler(wxBITMAP_TYPE_PNG
, wxT("png"), wxT("PNG image")));
950 AddHandler(new wxPNGBitmapHandler(wxBITMAP_TYPE_PNG_RESOURCE
, wxEmptyString
, wxT("PNG resource")));
952 AddHandler(new wxICOBitmapHandler(wxBITMAP_TYPE_ICO
, wxT("ico"), wxT("Icon resource")));
953 AddHandler(new wxICOBitmapHandler(wxBITMAP_TYPE_ICO_RESOURCE
, wxEmptyString
, wxT("Icon resource")));