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
,wxObject
)
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 bool wxBitmap::CreateFromXpm(const char **bits
)
176 wxCHECK_MSG( bits
!= NULL
, false, wxT("invalid bitmap data") );
178 wxXPMDecoder decoder
;
179 wxImage img
= decoder
.ReadData(bits
);
180 wxCHECK_MSG( img
.Ok(), false, wxT("invalid bitmap data") );
182 *this = wxBitmap(img
);
187 wxBitmap::wxBitmap(const wxImage
& image
, int depth
)
191 wxCHECK_RET( image
.Ok(), wxT("invalid image") );
193 width
= image
.GetWidth();
194 height
= image
.GetHeight();
196 if ( !Create(width
, height
, depth
) ) return;
198 MGLMemoryDC
idc(width
, height
, 24, &gs_pixel_format_wxImage
,
199 width
* 3, (void*)image
.GetData(), NULL
);
200 wxASSERT_MSG( idc
.isValid(), wxT("cannot create custom MGLDC") );
202 MGLDevCtx
*bdc
= CreateTmpDC();
204 if ( GetDepth() <= 8 && image
.HasPalette() )
205 SetPalette(image
.GetPalette());
207 bdc
->bitBlt(idc
, 0, 0, width
, height
, 0, 0, MGL_REPLACE_MODE
);
210 if ( image
.HasMask() )
212 wxImage mask_image
= image
.ConvertToMono(image
.GetMaskRed(),
213 image
.GetMaskGreen(),
214 image
.GetMaskBlue());
215 mask_image
.SetMask(false);
216 wxBitmap
mask_bmp(mask_image
, 1);
217 SetMask(new wxMask(mask_bmp
));
221 wxImage
wxBitmap::ConvertToImage() const
223 wxCHECK_MSG( Ok(), wxImage(), wxT("invalid bitmap") );
227 height
= GetHeight();
229 wxImage
image(width
, height
);
230 wxASSERT_MSG( image
.Ok(), wxT("cannot create image") );
232 MGLMemoryDC
idc(width
, height
, 24, &gs_pixel_format_wxImage
,
233 width
* 3, (void*)image
.GetData(), NULL
);
234 wxASSERT_MSG( idc
.isValid(), wxT("cannot create custom MGLDC") );
236 if ( M_BMPDATA
->m_palette
)
237 image
.SetPalette(*(M_BMPDATA
->m_palette
));
241 // in consistency with other ports, we convert parts covered
242 // by the mask to <16,16,16> colour and set that colour to image's
243 // mask. We do that by OR-blitting the mask over image with
244 // bg colour set to black and fg colour to <16,16,16>
246 image
.SetMaskColour(16, 16, 16);
250 tmpDC
.SetMGLDC(&idc
, false);
251 tmpDC
.SetBackground(wxBrush(wxColour(16,16,16), wxSOLID
));
253 tmpDC
.DrawBitmap(*this, 0, 0, true);
257 image
.SetMask(false);
258 idc
.putBitmap(0, 0, M_BMPDATA
->m_bitmap
, MGL_REPLACE_MODE
);
264 wxBitmap::wxBitmap(const wxString
&filename
, wxBitmapType type
)
266 LoadFile(filename
, type
);
269 wxBitmap::wxBitmap(const char bits
[], int width
, int height
, int depth
)
271 wxCHECK_RET( depth
== 1, wxT("can only create mono bitmap from XBM data") );
273 if ( !Create(width
, height
, 1) ) return;
274 MGLDevCtx
*bdc
= CreateTmpDC();
275 wxCurrentDCSwitcher
curDC(bdc
);
277 bdc
->setBackColor(0);
279 bdc
->putMonoImage(0, 0, width
, (width
+ 7) / 8, height
, (void*)bits
);
283 bool wxBitmap::operator == (const wxBitmap
& bmp
) const
285 return (m_refData
== bmp
.m_refData
);
288 bool wxBitmap::operator != (const wxBitmap
& bmp
) const
290 return (m_refData
!= bmp
.m_refData
);
293 bool wxBitmap::Ok() const
295 return (m_refData
!= NULL
&& M_BMPDATA
->m_bitmap
!= NULL
);
298 int wxBitmap::GetHeight() const
300 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
302 return M_BMPDATA
->m_height
;
305 int wxBitmap::GetWidth() const
307 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
309 return M_BMPDATA
->m_width
;
312 int wxBitmap::GetDepth() const
314 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
316 return M_BMPDATA
->m_bpp
;
319 wxMask
*wxBitmap::GetMask() const
321 wxCHECK_MSG( Ok(), (wxMask
*) NULL
, wxT("invalid bitmap") );
323 return M_BMPDATA
->m_mask
;
326 void wxBitmap::SetMask(wxMask
*mask
)
328 wxCHECK_RET( Ok(), wxT("invalid bitmap") );
330 delete M_BMPDATA
->m_mask
;
331 M_BMPDATA
->m_mask
= mask
;
334 bool wxBitmap::CopyFromIcon(const wxIcon
& icon
)
336 wxBitmap
*bmp
= (wxBitmap
*)(&icon
);
341 wxBitmap
wxBitmap::GetSubBitmap(const wxRect
& rect
) const
344 (rect
.x
>= 0) && (rect
.y
>= 0) &&
345 (rect
.x
+rect
.width
<= M_BMPDATA
->m_width
) && (rect
.y
+rect
.height
<= M_BMPDATA
->m_height
),
346 wxNullBitmap
, wxT("invalid bitmap or bitmap region") );
348 wxBitmap
ret( rect
.width
, rect
.height
, M_BMPDATA
->m_bpp
);
349 wxASSERT_MSG( ret
.Ok(), wxT("GetSubBitmap error") );
352 ret
.SetPalette(*GetPalette());
354 MGLDevCtx
*tdc
= ret
.CreateTmpDC();
355 tdc
->putBitmapSection(rect
.x
, rect
.y
,
356 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
,
357 0, 0, M_BMPDATA
->m_bitmap
, MGL_REPLACE_MODE
);
362 wxBitmap submask
= GetMask()->GetBitmap().GetSubBitmap(rect
);
363 ret
.SetMask(new wxMask(submask
));
369 void wxBitmap::SetMonoPalette(const wxColour
& fg
, const wxColour
& bg
)
371 wxCHECK_RET( Ok(), wxT("invalid bitmap") );
373 palette_t
*mono
= M_BMPDATA
->m_bitmap
->pal
;
375 wxCHECK_RET( M_BMPDATA
->m_bpp
== 1, wxT("bitmap is not 1bpp") );
376 wxCHECK_RET( mono
!= NULL
, wxT("bitmap w/o palette") );
378 mono
[0].red
= bg
.Red();
379 mono
[0].green
= bg
.Green();
380 mono
[0].blue
= bg
.Blue();
382 for (size_t i
= 1; i
< 256; i
++)
384 mono
[i
].red
= fg
.Red();
385 mono
[i
].green
= fg
.Green();
386 mono
[i
].blue
= fg
.Blue();
391 MGLDevCtx
*wxBitmap::CreateTmpDC() const
393 wxCHECK_MSG( Ok(), NULL
, wxT("invalid bitmap") );
395 MGLDevCtx
*tdc
= new MGLMemoryDC(GetWidth(), GetHeight(),
396 M_BMPDATA
->m_bitmap
->bitsPerPixel
,
397 M_BMPDATA
->m_bitmap
->pf
,
398 M_BMPDATA
->m_bitmap
->bytesPerLine
,
399 M_BMPDATA
->m_bitmap
->surface
,
401 wxCHECK_MSG( tdc
->isValid(), NULL
, wxT("cannot create temporary MGLDC") );
403 if ( M_BMPDATA
->m_bitmap
->pal
!= NULL
)
407 switch (M_BMPDATA
->m_bitmap
->bitsPerPixel
)
409 case 2: cnt
= 2; break;
410 case 4: cnt
= 16; break;
411 case 8: cnt
= 256; break;
414 wxFAIL_MSG( wxT("bitmap with this depth cannot have palette") );
418 tdc
->setPalette(M_BMPDATA
->m_bitmap
->pal
, cnt
, 0);
419 tdc
->realizePalette(cnt
, 0, FALSE
);
425 bool wxBitmap::LoadFile(const wxString
&name
, wxBitmapType type
)
429 if ( type
== wxBITMAP_TYPE_BMP
|| type
== wxBITMAP_TYPE_PNG
||
430 type
== wxBITMAP_TYPE_PCX
|| type
== wxBITMAP_TYPE_JPEG
)
432 // prevent accidental loading of bitmap from $MGL_ROOT:
433 if ( !wxFileExists(name
) )
435 wxLogError(_("File %s does not exist."), name
.c_str());
440 wxBitmapHandler
*handler
= FindHandler(type
);
442 if ( handler
== NULL
)
445 if ( !image
.LoadFile(name
, type
) || !image
.Ok() )
447 wxLogError("no bitmap handler for type %d defined.", type
);
452 *this = wxBitmap(image
);
457 m_refData
= new wxBitmapRefData();
459 return handler
->LoadFile(this, name
, type
, -1, -1);
462 bool wxBitmap::SaveFile(const wxString
& filename
, wxBitmapType type
, const wxPalette
*palette
) const
464 wxCHECK_MSG( Ok(), false, wxT("invalid bitmap") );
466 wxBitmapHandler
*handler
= FindHandler(type
);
468 if ( handler
== NULL
)
470 wxImage image
= ConvertToImage();
472 image
.SetPalette(*palette
);
475 return image
.SaveFile(filename
, type
);
478 wxLogError("no bitmap handler for type %d defined.", type
);
483 return handler
->SaveFile(this, filename
, type
, palette
);
486 wxPalette
*wxBitmap::GetPalette() const
488 wxCHECK_MSG( Ok(), NULL
, wxT("invalid bitmap") );
490 return M_BMPDATA
->m_palette
;
493 void wxBitmap::SetPalette(const wxPalette
& palette
)
495 wxCHECK_RET( Ok(), wxT("invalid bitmap") );
496 wxCHECK_RET( GetDepth() > 1 && GetDepth() <= 8, wxT("cannot set palette for bitmap of this depth") );
498 delete M_BMPDATA
->m_palette
;
499 M_BMPDATA
->m_palette
= NULL
;
501 if ( !palette
.Ok() ) return;
503 M_BMPDATA
->m_palette
= new wxPalette(palette
);
505 int cnt
= palette
.GetColoursCount();
506 palette_t
*pal
= palette
.GetMGLpalette_t();
507 memcpy(M_BMPDATA
->m_bitmap
->pal
, pal
, cnt
* sizeof(palette_t
));
510 void wxBitmap::SetHeight(int height
)
512 if (!m_refData
) m_refData
= new wxBitmapRefData();
514 M_BMPDATA
->m_height
= height
;
517 void wxBitmap::SetWidth(int width
)
519 if (!m_refData
) m_refData
= new wxBitmapRefData();
521 M_BMPDATA
->m_width
= width
;
524 void wxBitmap::SetDepth(int depth
)
526 if (!m_refData
) m_refData
= new wxBitmapRefData();
528 M_BMPDATA
->m_bpp
= depth
;
531 bitmap_t
*wxBitmap::GetMGLbitmap_t() const
533 return M_BMPDATA
->m_bitmap
;
536 // Convert wxColour into it's quantized value in lower-precision
537 // pixel format (needed for masking by colour).
538 wxColour
wxBitmap::QuantizeColour(const wxColour
& clr
) const
540 pixel_format_t
*pf
= GetMGLbitmap_t()->pf
;
542 if ( pf
->redAdjust
== 0 && pf
->greenAdjust
== 0 && pf
->blueAdjust
== 0 )
545 return wxColour((unsigned char)((clr
.Red() >> pf
->redAdjust
) << pf
->redAdjust
),
546 (unsigned char)((clr
.Green() >> pf
->greenAdjust
) << pf
->greenAdjust
),
547 (unsigned char)((clr
.Blue() >> pf
->blueAdjust
) << pf
->blueAdjust
));
551 //-----------------------------------------------------------------------------
552 // wxBitmap I/O handlers
553 //-----------------------------------------------------------------------------
555 class wxMGLBitmapHandler
: public wxBitmapHandler
558 wxMGLBitmapHandler(wxBitmapType type
,
559 const wxString
& extension
, const wxString
& name
);
561 virtual bool Create(wxBitmap
*WXUNUSED(bitmap
),
562 void *WXUNUSED(data
),
563 long WXUNUSED(flags
),
565 int WXUNUSED(height
),
566 int WXUNUSED(depth
) = 1)
569 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
570 int desiredWidth
, int desiredHeight
);
571 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
572 int type
, const wxPalette
*palette
= NULL
);
575 wxMGLBitmapHandler::wxMGLBitmapHandler(wxBitmapType type
,
576 const wxString
& extension
,
577 const wxString
& name
)
582 SetExtension(extension
);
585 bool wxMGLBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
,
587 int WXUNUSED(desiredWidth
),
588 int WXUNUSED(desiredHeight
))
590 int width
, height
, bpp
;
597 case wxBITMAP_TYPE_BMP_RESOURCE
:
598 case wxBITMAP_TYPE_JPEG_RESOURCE
:
599 case wxBITMAP_TYPE_PNG_RESOURCE
:
600 case wxBITMAP_TYPE_PCX_RESOURCE
:
601 fullname
= name
+ wxT(".bmp");
610 case wxBITMAP_TYPE_BMP
:
611 case wxBITMAP_TYPE_BMP_RESOURCE
:
612 if ( !MGL_getBitmapSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
614 bitmap
->Create(width
, height
, -1);
615 if ( !bitmap
->Ok() ) return false;
616 dc
.SelectObject(*bitmap
);
617 if ( !dc
.GetMGLDC()->loadBitmapIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
621 case wxBITMAP_TYPE_JPEG
:
622 case wxBITMAP_TYPE_JPEG_RESOURCE
:
623 if ( !MGL_getJPEGSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
625 bitmap
->Create(width
, height
, -1);
626 if ( !bitmap
->Ok() ) return false;
627 dc
.SelectObject(*bitmap
);
628 if ( !dc
.GetMGLDC()->loadJPEGIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
632 case wxBITMAP_TYPE_PNG
:
633 case wxBITMAP_TYPE_PNG_RESOURCE
:
634 if ( !MGL_getPNGSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
636 bitmap
->Create(width
, height
, -1);
637 if ( !bitmap
->Ok() ) return false;
638 dc
.SelectObject(*bitmap
);
639 if ( !dc
.GetMGLDC()->loadPNGIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
643 case wxBITMAP_TYPE_PCX
:
644 case wxBITMAP_TYPE_PCX_RESOURCE
:
645 if ( !MGL_getPCXSize(fullname
.mb_str(), &width
, &height
, &bpp
) )
647 bitmap
->Create(width
, height
, -1);
648 if ( !bitmap
->Ok() ) return false;
649 dc
.SelectObject(*bitmap
);
650 if ( !dc
.GetMGLDC()->loadPCXIntoDC(fullname
.mb_str(), 0, 0, TRUE
) )
655 wxFAIL_MSG(wxT("Unsupported image format."));
662 bool wxMGLBitmapHandler::SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
663 int type
, const wxPalette
* WXUNUSED(palette
))
667 int w
= bitmap
->GetWidth(),
668 h
= bitmap
->GetHeight();
670 mem
.SelectObject(*bitmap
);
671 tdc
= mem
.GetMGLDC();
675 case wxBITMAP_TYPE_BMP
:
676 return (bool)tdc
->saveBitmapFromDC(name
.mb_str(), 0, 0, w
, h
);
677 case wxBITMAP_TYPE_JPEG
:
678 return (bool)tdc
->saveJPEGFromDC(name
.mb_str(), 0, 0, w
, h
, 75);
679 case wxBITMAP_TYPE_PNG
:
680 return (bool)tdc
->savePNGFromDC(name
.mb_str(), 0, 0, w
, h
);
681 case wxBITMAP_TYPE_PCX
:
682 return (bool)tdc
->savePCXFromDC(name
.mb_str(), 0, 0, w
, h
);
690 // let's handle PNGs in special way because they have alpha channel
691 // which we can access via bitmap_t most easily
692 class wxPNGBitmapHandler
: public wxMGLBitmapHandler
695 wxPNGBitmapHandler(wxBitmapType type
,
696 const wxString
& extension
, const wxString
& name
)
697 : wxMGLBitmapHandler(type
, extension
, name
) {}
699 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
700 int desiredWidth
, int desiredHeight
);
703 bool wxPNGBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
,
705 int desiredWidth
, int desiredHeight
)
707 int width
, height
, bpp
;
711 if ( flags
== wxBITMAP_TYPE_PNG_RESOURCE
)
712 fullname
= name
+ wxT(".png");
716 if ( !MGL_getPNGSize(fullname
.mb_str(), &width
, &height
, &bpp
, &pf
) )
721 // We can load ordinary PNGs faster with 'normal' MGL handler.
722 // Only RGBA PNGs need to be processed in special way because
723 // we have to convert alpha channel to mask
724 return wxMGLBitmapHandler::LoadFile(bitmap
, name
, flags
,
725 desiredWidth
, desiredHeight
);
728 bitmap_t
*bmp
= MGL_loadPNG(fullname
.mb_str(), TRUE
);
730 if ( bmp
== NULL
) return false;
732 bitmap
->Create(bmp
->width
, bmp
->height
, -1);
733 if ( !bitmap
->Ok() ) return false;
735 // convert bmp to display's depth and write it to *bitmap:
737 dc
.SelectObject(*bitmap
);
738 dc
.GetMGLDC()->putBitmap(0, 0, bmp
, MGL_REPLACE_MODE
);
739 dc
.SelectObject(wxNullBitmap
);
741 // create mask, if bmp contains alpha channel (ARGB format):
742 if ( bmp
->bitsPerPixel
== 32 )
745 wxUint32
*s
= (wxUint32
*)bmp
->surface
;
746 for (y
= 0; y
< bmp
->height
; y
++)
748 s
= ((wxUint32
*)bmp
->surface
) + y
* bmp
->bytesPerLine
/4;
749 for (x
= 0; x
< bmp
->width
; x
++, s
++)
751 if ( ((((*s
) >> bmp
->pf
->alphaPos
) & bmp
->pf
->alphaMask
)
752 << bmp
->pf
->alphaAdjust
) < 128 )
755 *s
= 0x00FFFFFF; // white
758 wxBitmap
mask(bmp
->width
, bmp
->height
, 1);
759 dc
.SelectObject(mask
);
760 dc
.GetMGLDC()->putBitmap(0, 0, bmp
, MGL_REPLACE_MODE
);
761 dc
.SelectObject(wxNullBitmap
);
762 bitmap
->SetMask(new wxMask(mask
));
765 MGL_unloadBitmap(bmp
);
773 class wxICOBitmapHandler
: public wxBitmapHandler
776 wxICOBitmapHandler(wxBitmapType type
,
777 const wxString
& extension
, const wxString
& name
);
779 virtual bool Create(wxBitmap
*WXUNUSED(bitmap
),
780 void *WXUNUSED(data
),
781 long WXUNUSED(flags
),
783 int WXUNUSED(height
),
784 int WXUNUSED(depth
) = 1)
787 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
788 int desiredWidth
, int desiredHeight
);
789 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
790 int type
, const wxPalette
*palette
= NULL
);
793 wxICOBitmapHandler::wxICOBitmapHandler(wxBitmapType type
,
794 const wxString
& extension
,
795 const wxString
& name
)
800 SetExtension(extension
);
803 bool wxICOBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
,
805 int WXUNUSED(desiredWidth
),
806 int WXUNUSED(desiredHeight
))
811 if ( flags
== wxBITMAP_TYPE_ICO_RESOURCE
)
812 icon
= MGL_loadIcon(wxString(name
+ wxT(".ico")).mb_str(), TRUE
);
814 icon
= MGL_loadIcon(name
.mb_str(), TRUE
);
816 if ( icon
== NULL
) return false;
818 bitmap
->Create(icon
->xorMask
.width
, icon
->xorMask
.height
);
821 mem
.SelectObject(*bitmap
);
823 dc
->putBitmap(0, 0, &(icon
->xorMask
), MGL_REPLACE_MODE
);
824 mem
.SelectObject(wxNullBitmap
);
826 wxBitmap
mask(icon
->xorMask
.width
, icon
->xorMask
.height
, 1);
827 mem
.SelectObject(mask
);
830 wxCurrentDCSwitcher
curDC(dc
);
834 dc
->putMonoImage(0, 0, icon
->xorMask
.width
, icon
->byteWidth
,
835 icon
->xorMask
.height
, (void*)icon
->andMask
);
837 bitmap
->SetMask(new wxMask(mask
));
839 MGL_unloadIcon(icon
);
844 bool wxICOBitmapHandler::SaveFile(const wxBitmap
*WXUNUSED(bitmap
),
845 const wxString
& WXUNUSED(name
),
847 const wxPalette
* WXUNUSED(palette
))
855 /*static*/ void wxBitmap::InitStandardHandlers()
857 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_BMP
, wxT("bmp"), wxT("Windows bitmap")));
858 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_BMP_RESOURCE
, wxEmptyString
, wxT("Windows bitmap resource")));
859 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_JPEG
, wxT("jpg"), wxT("JPEG image")));
860 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_JPEG_RESOURCE
, wxEmptyString
, wxT("JPEG resource")));
861 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_PCX
, wxT("pcx"), wxT("PCX image")));
862 AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_PCX_RESOURCE
, wxEmptyString
, wxT("PCX resource")));
864 AddHandler(new wxPNGBitmapHandler(wxBITMAP_TYPE_PNG
, wxT("png"), wxT("PNG image")));
865 AddHandler(new wxPNGBitmapHandler(wxBITMAP_TYPE_PNG_RESOURCE
, wxEmptyString
, wxT("PNG resource")));
867 AddHandler(new wxICOBitmapHandler(wxBITMAP_TYPE_ICO
, wxT("ico"), wxT("Icon resource")));
868 AddHandler(new wxICOBitmapHandler(wxBITMAP_TYPE_ICO_RESOURCE
, wxEmptyString
, wxT("Icon resource")));