1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "bitmap.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
29 #include "wx/palette.h"
30 #include "wx/bitmap.h"
34 #include "wx/msw/private.h"
41 #include "../src/xpm/xpm34.h"
44 #include "wx/msw/dib.h"
46 #if !USE_SHARED_LIBRARIES
47 IMPLEMENT_DYNAMIC_CLASS(wxBitmap
, wxGDIObject
)
48 IMPLEMENT_DYNAMIC_CLASS(wxMask
, wxObject
)
51 wxBitmapRefData::wxBitmapRefData(void)
59 m_selectedInto
= NULL
;
64 wxBitmapRefData::~wxBitmapRefData(void)
69 sprintf(buf
, "Bitmap was deleted without selecting out of wxMemoryDC %X.", (unsigned int) m_selectedInto
);
74 DeleteObject((HBITMAP
) m_hBitmap
);
83 wxList
wxBitmap::sm_handlers
;
85 wxBitmap::wxBitmap(void)
87 if ( wxTheBitmapList
)
88 wxTheBitmapList
->AddBitmap(this);
91 wxBitmap::~wxBitmap(void)
94 wxTheBitmapList
->DeleteObject(this);
97 bool wxBitmap::FreeResource(bool force
)
102 if (M_BITMAPDATA
->m_selectedInto
)
105 sprintf(buf
, "Bitmap %X was deleted without selecting out of wxMemoryDC %X.", (unsigned int) this, (unsigned int) M_BITMAPDATA
->m_selectedInto
);
108 if (M_BITMAPDATA
->m_hBitmap
)
110 DeleteObject((HBITMAP
) M_BITMAPDATA
->m_hBitmap
);
112 M_BITMAPDATA
->m_hBitmap
= 0 ;
115 if (M_BITMAPDATA->m_bitmapPalette)
116 delete M_BITMAPDATA->m_bitmapPalette;
118 M_BITMAPDATA->m_bitmapPalette = NULL ;
125 wxBitmap::wxBitmap(const char bits
[], int the_width
, int the_height
, int no_bits
)
127 m_refData
= new wxBitmapRefData
;
129 M_BITMAPDATA
->m_width
= the_width
;
130 M_BITMAPDATA
->m_height
= the_height
;
131 M_BITMAPDATA
->m_depth
= no_bits
;
132 M_BITMAPDATA
->m_numColors
= 0;
134 M_BITMAPDATA
->m_hBitmap
= (WXHBITMAP
) CreateBitmap(the_width
, the_height
, 1, no_bits
, bits
);
136 if (M_BITMAPDATA
->m_hBitmap
)
137 M_BITMAPDATA
->m_ok
= TRUE
;
139 M_BITMAPDATA
->m_ok
= FALSE
;
141 M_BITMAPDATA
->m_selectedInto
= NULL
;
143 if ( wxTheBitmapList
)
144 wxTheBitmapList
->AddBitmap(this);
147 wxBitmap::wxBitmap(int w
, int h
, int d
)
149 (void)Create(w
, h
, d
);
151 if ( wxTheBitmapList
)
152 wxTheBitmapList
->AddBitmap(this);
155 wxBitmap::wxBitmap(void *data
, long type
, int width
, int height
, int depth
)
157 (void) Create(data
, type
, width
, height
, depth
);
159 if ( wxTheBitmapList
)
160 wxTheBitmapList
->AddBitmap(this);
163 wxBitmap::wxBitmap(const wxString
& filename
, long type
)
165 LoadFile(filename
, (int)type
);
167 if ( wxTheBitmapList
)
168 wxTheBitmapList
->AddBitmap(this);
173 wxBitmap::wxBitmap(char **data
, wxItem
*WXUNUSED(anItem
))
175 (void) Create((void *)data
, wxBITMAP_TYPE_XPM_DATA
, 0, 0, 0);
179 bool wxBitmap::Create(int w
, int h
, int d
)
183 m_refData
= new wxBitmapRefData
;
185 M_BITMAPDATA
->m_width
= w
;
186 M_BITMAPDATA
->m_height
= h
;
187 M_BITMAPDATA
->m_depth
= d
;
191 M_BITMAPDATA
->m_hBitmap
= (WXHBITMAP
) CreateBitmap(w
, h
, 1, d
, NULL
);
195 HDC dc
= GetDC(NULL
);
196 M_BITMAPDATA
->m_hBitmap
= (WXHBITMAP
) CreateCompatibleBitmap(dc
, w
, h
);
198 M_BITMAPDATA
->m_depth
= wxDisplayDepth();
200 if (M_BITMAPDATA
->m_hBitmap
)
201 M_BITMAPDATA
->m_ok
= TRUE
;
203 M_BITMAPDATA
->m_ok
= FALSE
;
204 return M_BITMAPDATA
->m_ok
;
207 bool wxBitmap::LoadFile(const wxString
& filename
, long type
)
211 m_refData
= new wxBitmapRefData
;
213 wxBitmapHandler
*handler
= FindHandler(type
);
215 if ( handler
== NULL
) {
216 wxLogWarning("no bitmap handler for type %d defined.", type
);
221 return handler
->LoadFile(this, filename
, type
, -1, -1);
224 bool wxBitmap::Create(void *data
, long type
, int width
, int height
, int depth
)
228 m_refData
= new wxBitmapRefData
;
230 wxBitmapHandler
*handler
= FindHandler(type
);
232 if ( handler
== NULL
) {
233 wxLogWarning("no bitmap handler for type %d defined.", type
);
238 return handler
->Create(this, data
, type
, width
, height
, depth
);
241 bool wxBitmap::SaveFile(const wxString
& filename
, int type
, const wxPalette
*palette
)
243 wxBitmapHandler
*handler
= FindHandler(type
);
245 if ( handler
== NULL
) {
246 wxLogWarning("no bitmap handler for type %d defined.", type
);
251 return handler
->SaveFile(this, filename
, type
, palette
);
254 void wxBitmap::SetWidth(int w
)
257 m_refData
= new wxBitmapRefData
;
259 M_BITMAPDATA
->m_width
= w
;
262 void wxBitmap::SetHeight(int h
)
265 m_refData
= new wxBitmapRefData
;
267 M_BITMAPDATA
->m_height
= h
;
270 void wxBitmap::SetDepth(int d
)
273 m_refData
= new wxBitmapRefData
;
275 M_BITMAPDATA
->m_depth
= d
;
278 void wxBitmap::SetQuality(int q
)
281 m_refData
= new wxBitmapRefData
;
283 M_BITMAPDATA
->m_quality
= q
;
286 void wxBitmap::SetOk(bool isOk
)
289 m_refData
= new wxBitmapRefData
;
291 M_BITMAPDATA
->m_ok
= isOk
;
294 void wxBitmap::SetPalette(const wxPalette
& palette
)
297 m_refData
= new wxBitmapRefData
;
299 M_BITMAPDATA
->m_bitmapPalette
= palette
;
302 void wxBitmap::SetMask(wxMask
*mask
)
305 m_refData
= new wxBitmapRefData
;
307 M_BITMAPDATA
->m_bitmapMask
= mask
;
310 void wxBitmap::SetHBITMAP(WXHBITMAP bmp
)
313 m_refData
= new wxBitmapRefData
;
315 M_BITMAPDATA
->m_hBitmap
= bmp
;
318 void wxBitmap::AddHandler(wxBitmapHandler
*handler
)
320 sm_handlers
.Append(handler
);
323 void wxBitmap::InsertHandler(wxBitmapHandler
*handler
)
325 sm_handlers
.Insert(handler
);
328 bool wxBitmap::RemoveHandler(const wxString
& name
)
330 wxBitmapHandler
*handler
= FindHandler(name
);
333 sm_handlers
.DeleteObject(handler
);
340 wxBitmapHandler
*wxBitmap::FindHandler(const wxString
& name
)
342 wxNode
*node
= sm_handlers
.First();
345 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
346 if ( handler
->GetName() == name
)
353 wxBitmapHandler
*wxBitmap::FindHandler(const wxString
& extension
, long bitmapType
)
355 wxNode
*node
= sm_handlers
.First();
358 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
359 if ( handler
->GetExtension() == extension
&&
360 (bitmapType
== -1 || handler
->GetType() == bitmapType
) )
367 wxBitmapHandler
*wxBitmap::FindHandler(long bitmapType
)
369 wxNode
*node
= sm_handlers
.First();
372 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
373 if (handler
->GetType() == bitmapType
)
380 // New Create/FreeDIB functions since ones in dibutils.cpp are confusing
381 static long createDIB(long xSize
, long ySize
, long bitsPerPixel
,
382 HPALETTE hPal
, LPBITMAPINFO
* lpDIBHeader
);
383 static long freeDIB(LPBITMAPINFO lpDIBHeader
);
385 // Creates a bitmap that matches the device context, from
386 // an arbitray bitmap. At present, the original bitmap must have an
387 // associated palette. TODO: use a default palette if no palette exists.
388 // Contributed by Frederic Villeneuve <frederic.villeneuve@natinst.com>
389 wxBitmap
wxBitmap::GetBitmapForDC(wxDC
& dc
) const
392 wxBitmap
tmpBitmap(this->GetWidth(), this->GetHeight(), dc
.GetDepth());
393 HPALETTE hPal
= NULL
;
398 wxASSERT( this->GetPalette() && this->GetPalette()->Ok() && (this->GetPalette()->GetHPALETTE() != 0) );
400 tmpBitmap.SetPalette(this->GetPalette());
401 memDC.SelectObject(tmpBitmap);
402 memDC.SetPalette(this->GetPalette());
404 hPal = (HPALETTE) this->GetPalette()->GetHPALETTE();
406 if( this->GetPalette() && this->GetPalette()->Ok() && (this->GetPalette()->GetHPALETTE() != 0) )
408 tmpBitmap
.SetPalette(* this->GetPalette());
409 memDC
.SelectObject(tmpBitmap
);
410 memDC
.SetPalette(* this->GetPalette());
411 hPal
= (HPALETTE
) this->GetPalette()->GetHPALETTE();
415 hPal
= (HPALETTE
) ::GetStockObject(DEFAULT_PALETTE
);
417 palette
.SetHPALETTE( (WXHPALETTE
)hPal
);
418 tmpBitmap
.SetPalette( palette
);
419 memDC
.SelectObject(tmpBitmap
);
420 memDC
.SetPalette( palette
);
423 // set the height negative because in a DIB the order of the lines is reversed
424 createDIB(this->GetWidth(), -this->GetHeight(), this->GetDepth(), hPal
, &lpDib
);
426 lpBits
= malloc(lpDib
->bmiHeader
.biSizeImage
);
428 ::GetBitmapBits((HBITMAP
)GetHBITMAP(), lpDib
->bmiHeader
.biSizeImage
, lpBits
);
430 ::SetDIBitsToDevice((HDC
) memDC
.GetHDC(), 0, 0, this->GetWidth(), this->GetHeight(),
431 0, 0, 0, this->GetHeight(), lpBits
, lpDib
, DIB_RGB_COLORS
);
448 // Construct a mask from a bitmap and a colour indicating
449 // the transparent area
450 wxMask::wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
)
453 Create(bitmap
, colour
);
456 // Construct a mask from a bitmap and a palette index indicating
457 // the transparent area
458 wxMask::wxMask(const wxBitmap
& bitmap
, int paletteIndex
)
461 Create(bitmap
, paletteIndex
);
464 // Construct a mask from a mono bitmap (copies the bitmap).
465 wxMask::wxMask(const wxBitmap
& bitmap
)
471 wxMask::~wxMask(void)
474 ::DeleteObject((HBITMAP
) m_maskBitmap
);
477 // Create a mask from a mono bitmap (copies the bitmap).
478 bool wxMask::Create(const wxBitmap
& bitmap
)
482 ::DeleteObject((HBITMAP
) m_maskBitmap
);
485 if (!bitmap
.Ok() || bitmap
.GetDepth() != 1)
489 m_maskBitmap
= (WXHBITMAP
) CreateBitmap(
494 HDC srcDC
= CreateCompatibleDC(0);
495 SelectObject(srcDC
, (HBITMAP
) bitmap
.GetHBITMAP());
496 HDC destDC
= CreateCompatibleDC(0);
497 SelectObject(destDC
, (HBITMAP
) m_maskBitmap
);
498 BitBlt(destDC
, 0, 0, bitmap
.GetWidth(), bitmap
.GetHeight(), srcDC
, 0, 0, SRCCOPY
);
499 SelectObject(srcDC
, 0);
501 SelectObject(destDC
, 0);
506 // Create a mask from a bitmap and a palette index indicating
507 // the transparent area
508 bool wxMask::Create(const wxBitmap
& bitmap
, int paletteIndex
)
512 ::DeleteObject((HBITMAP
) m_maskBitmap
);
515 if (bitmap
.Ok() && bitmap
.GetPalette()->Ok())
517 unsigned char red
, green
, blue
;
518 if (bitmap
.GetPalette()->GetRGB(paletteIndex
, &red
, &green
, &blue
))
520 wxColour
transparentColour(red
, green
, blue
);
521 return Create(bitmap
, transparentColour
);
527 // Create a mask from a bitmap and a colour indicating
528 // the transparent area
529 bool wxMask::Create(const wxBitmap
& bitmap
, const wxColour
& colour
)
533 ::DeleteObject((HBITMAP
) m_maskBitmap
);
541 // scan the bitmap for the transparent colour and set
542 // the corresponding pixels in the mask to BLACK and
544 COLORREF maskColour
= RGB(colour
.Red(), colour
.Green(), colour
.Blue());
545 m_maskBitmap
= (WXHBITMAP
) ::CreateBitmap(
550 HDC srcDC
= ::CreateCompatibleDC(0);
551 ::SelectObject(srcDC
, (HBITMAP
) bitmap
.GetHBITMAP());
552 HDC destDC
= ::CreateCompatibleDC(0);
553 ::SelectObject(destDC
, (HBITMAP
) m_maskBitmap
);
555 // this is not very efficient, but I can't think
556 // of a better way of doing it
557 for (int w
= 0; w
< bitmap
.GetWidth(); w
++)
559 for (int h
= 0; h
< bitmap
.GetHeight(); h
++)
561 COLORREF col
= GetPixel(srcDC
, w
, h
);
562 if (col
== maskColour
)
564 ::SetPixel(destDC
, w
, h
, RGB(0, 0, 0));
568 ::SetPixel(destDC
, w
, h
, RGB(255, 255, 255));
572 ::SelectObject(srcDC
, 0);
574 ::SelectObject(destDC
, 0);
583 IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler
, wxObject
)
585 bool wxBitmapHandler::Create(wxBitmap
*bitmap
, void *data
, long type
, int width
, int height
, int depth
)
590 bool wxBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long type
,
591 int desiredWidth
, int desiredHeight
)
596 bool wxBitmapHandler::SaveFile(wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
)
605 class WXDLLEXPORT wxBMPResourceHandler
: public wxBitmapHandler
607 DECLARE_DYNAMIC_CLASS(wxBMPResourceHandler
)
609 inline wxBMPResourceHandler(void)
611 m_name
= "Windows bitmap resource";
613 m_type
= wxBITMAP_TYPE_BMP_RESOURCE
;
616 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
617 int desiredWidth
, int desiredHeight
);
619 IMPLEMENT_DYNAMIC_CLASS(wxBMPResourceHandler
, wxBitmapHandler
)
621 bool wxBMPResourceHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
622 int desiredWidth
, int desiredHeight
)
624 // TODO: load colourmap.
625 M_BITMAPHANDLERDATA
->m_hBitmap
= (WXHBITMAP
) ::LoadBitmap(wxGetInstance(), name
);
626 if (M_BITMAPHANDLERDATA
->m_hBitmap
)
628 M_BITMAPHANDLERDATA
->m_ok
= TRUE
;
630 GetObject((HBITMAP
) M_BITMAPHANDLERDATA
->m_hBitmap
, sizeof(BITMAP
), (LPSTR
) &bm
);
631 M_BITMAPHANDLERDATA
->m_width
= bm
.bmWidth
;
632 M_BITMAPHANDLERDATA
->m_height
= bm
.bmHeight
;
633 M_BITMAPHANDLERDATA
->m_depth
= bm
.bmBitsPixel
;
637 // it's probably not found
638 wxLogError("Can't load bitmap '%s' from resources! Check .rc file.", name
.c_str());
643 class WXDLLEXPORT wxBMPFileHandler
: public wxBitmapHandler
645 DECLARE_DYNAMIC_CLASS(wxBMPFileHandler
)
647 inline wxBMPFileHandler(void)
649 m_name
= "Windows bitmap file";
651 m_type
= wxBITMAP_TYPE_BMP
;
654 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
655 int desiredWidth
, int desiredHeight
);
656 virtual bool SaveFile(wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
= NULL
);
658 IMPLEMENT_DYNAMIC_CLASS(wxBMPFileHandler
, wxBitmapHandler
)
660 bool wxBMPFileHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
661 int desiredWidth
, int desiredHeight
)
663 #if wxUSE_IMAGE_LOADING_IN_MSW
664 wxPalette
*palette
= NULL
;
665 bool success
= FALSE
;
667 if (type & wxBITMAP_DISCARD_COLOURMAP)
668 success = wxLoadIntoBitmap(WXSTRINGCAST name, bitmap);
671 success
= (wxLoadIntoBitmap(WXSTRINGCAST name
, bitmap
, &palette
) != 0);
672 if (!success
&& palette
)
678 M_BITMAPHANDLERDATA
->m_bitmapPalette
= *palette
;
685 bool wxBMPFileHandler::SaveFile(wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*pal
)
687 #if wxUSE_IMAGE_LOADING_IN_MSW
688 wxPalette
*actualPalette
= (wxPalette
*)pal
;
689 if (!actualPalette
&& (!M_BITMAPHANDLERDATA
->m_bitmapPalette
.IsNull()))
690 actualPalette
= & (M_BITMAPHANDLERDATA
->m_bitmapPalette
);
691 return (wxSaveBitmap(WXSTRINGCAST name
, bitmap
, actualPalette
) != 0);
697 class WXDLLEXPORT wxXPMFileHandler
: public wxBitmapHandler
699 DECLARE_DYNAMIC_CLASS(wxXPMFileHandler
)
701 inline wxXPMFileHandler(void)
703 m_name
= "XPM bitmap file";
705 m_type
= wxBITMAP_TYPE_XPM
;
708 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
709 int desiredWidth
= -1, int desiredHeight
= -1);
710 virtual bool SaveFile(wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
= NULL
);
712 IMPLEMENT_DYNAMIC_CLASS(wxXPMFileHandler
, wxBitmapHandler
)
714 bool wxXPMFileHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
715 int desiredWidth
, int desiredHeight
)
719 XpmAttributes xpmAttr
;
722 M_BITMAPHANDLERDATA
->m_ok
= FALSE
;
723 dc
= CreateCompatibleDC(NULL
);
726 xpmAttr
.valuemask
= XpmReturnPixels
;
727 int errorStatus
= XpmReadFileToImage(&dc
, WXSTRINGCAST name
, &ximage
, (XImage
**) NULL
, &xpmAttr
);
729 if (errorStatus
== XpmSuccess
)
731 M_BITMAPHANDLERDATA
->m_hBitmap
= (WXHBITMAP
) ximage
->bitmap
;
734 GetObject((HBITMAP
)M_BITMAPHANDLERDATA
->m_hBitmap
, sizeof(bm
), (LPSTR
) & bm
);
736 M_BITMAPHANDLERDATA
->m_width
= (bm
.bmWidth
);
737 M_BITMAPHANDLERDATA
->m_height
= (bm
.bmHeight
);
738 M_BITMAPHANDLERDATA
->m_depth
= (bm
.bmPlanes
* bm
.bmBitsPixel
);
739 M_BITMAPHANDLERDATA
->m_numColors
= xpmAttr
.npixels
;
740 XpmFreeAttributes(&xpmAttr
);
743 M_BITMAPHANDLERDATA
->m_ok
= TRUE
;
748 M_BITMAPHANDLERDATA
->m_ok
= FALSE
;
757 bool wxXPMFileHandler::SaveFile(wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
)
764 dc
= CreateCompatibleDC(NULL
);
767 if (SelectObject(dc
, (HBITMAP
) M_BITMAPHANDLERDATA
->m_hBitmap
))
769 /* for following SetPixel */
770 /* fill the XImage struct 'by hand' */
771 ximage
.width
= M_BITMAPHANDLERDATA
->m_width
;
772 ximage
.height
= M_BITMAPHANDLERDATA
->m_height
;
773 ximage
.depth
= M_BITMAPHANDLERDATA
->m_depth
;
774 ximage
.bitmap
= (HBITMAP
)M_BITMAPHANDLERDATA
->m_hBitmap
;
775 int errorStatus
= XpmWriteFileFromImage(&dc
, WXSTRINGCAST name
,
776 &ximage
, (XImage
*) NULL
, (XpmAttributes
*) NULL
);
781 if (errorStatus
== XpmSuccess
)
782 return TRUE
; /* no error */
792 class WXDLLEXPORT wxXPMDataHandler
: public wxBitmapHandler
794 DECLARE_DYNAMIC_CLASS(wxXPMDataHandler
)
796 inline wxXPMDataHandler(void)
798 m_name
= "XPM bitmap data";
800 m_type
= wxBITMAP_TYPE_XPM_DATA
;
803 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
= 1);
805 IMPLEMENT_DYNAMIC_CLASS(wxXPMDataHandler
, wxBitmapHandler
)
807 bool wxXPMDataHandler::Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
)
812 XpmAttributes xpmAttr
;
815 M_BITMAPHANDLERDATA
->m_ok
= FALSE
;
816 M_BITMAPHANDLERDATA
->m_numColors
= 0;
818 dc
= CreateCompatibleDC(NULL
); /* memory DC */
822 xpmAttr
.valuemask
= XpmReturnInfos
; /* get infos back */
823 ErrorStatus
= XpmCreateImageFromData(&dc
, (char **)data
,
824 &ximage
, (XImage
**) NULL
, &xpmAttr
);
826 if (ErrorStatus
== XpmSuccess
)
828 /* ximage is malloced and contains bitmap and attributes */
829 M_BITMAPHANDLERDATA
->m_hBitmap
= (WXHBITMAP
) ximage
->bitmap
;
832 GetObject((HBITMAP
) M_BITMAPHANDLERDATA
->m_hBitmap
, sizeof(bm
), (LPSTR
) & bm
);
834 M_BITMAPHANDLERDATA
->m_width
= (bm
.bmWidth
);
835 M_BITMAPHANDLERDATA
->m_height
= (bm
.bmHeight
);
836 M_BITMAPHANDLERDATA
->m_depth
= (bm
.bmPlanes
* bm
.bmBitsPixel
);
837 M_BITMAPHANDLERDATA
->m_numColors
= xpmAttr
.npixels
;
838 XpmFreeAttributes(&xpmAttr
);
840 XImageFree(ximage
); // releases the malloc, but does not detroy
842 M_BITMAPHANDLERDATA
->m_ok
= TRUE
;
849 M_BITMAPHANDLERDATA
->m_ok
= FALSE
;
850 // XpmDebugError(ErrorStatus, NULL);
860 void wxBitmap::CleanUpHandlers(void)
862 wxNode
*node
= sm_handlers
.First();
865 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
866 wxNode
*next
= node
->Next();
873 void wxBitmap::InitStandardHandlers(void)
875 AddHandler(new wxBMPResourceHandler
);
876 AddHandler(new wxBMPFileHandler
);
877 AddHandler(new wxXPMFileHandler
);
878 AddHandler(new wxXPMDataHandler
);
879 AddHandler(new wxICOResourceHandler
);
880 AddHandler(new wxICOFileHandler
);
883 static long createDIB(long xSize
, long ySize
, long bitsPerPixel
,
884 HPALETTE hPal
, LPBITMAPINFO
* lpDIBHeader
)
886 unsigned long i
, headerSize
;
887 LPBITMAPINFO lpDIBheader
= NULL
;
888 LPPALETTEENTRY lpPe
= NULL
;
891 // Allocate space for a DIB header
892 headerSize
= (sizeof(BITMAPINFOHEADER
) + (256 * sizeof(PALETTEENTRY
)));
893 lpDIBheader
= (BITMAPINFO
*) malloc(headerSize
);
894 lpPe
= (PALETTEENTRY
*)((BYTE
*)lpDIBheader
+ sizeof(BITMAPINFOHEADER
));
896 GetPaletteEntries(hPal
, 0, 256, lpPe
);
899 memset(lpDIBheader
, 0x00, sizeof(BITMAPINFOHEADER
));
902 // Fill in the static parts of the DIB header
903 lpDIBheader
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
904 lpDIBheader
->bmiHeader
.biWidth
= xSize
;
905 lpDIBheader
->bmiHeader
.biHeight
= ySize
;
906 lpDIBheader
->bmiHeader
.biPlanes
= 1;
908 // this value must be 1, 4, 8 or 24 so PixelDepth can only be
909 lpDIBheader
->bmiHeader
.biBitCount
= (WORD
)(bitsPerPixel
);
910 lpDIBheader
->bmiHeader
.biCompression
= BI_RGB
;
911 lpDIBheader
->bmiHeader
.biSizeImage
= xSize
* abs(ySize
) * bitsPerPixel
>>
913 lpDIBheader
->bmiHeader
.biClrUsed
= 256;
916 // Initialize the DIB palette
917 for (i
= 0; i
< 256; i
++) {
918 lpDIBheader
->bmiColors
[i
].rgbReserved
= lpPe
[i
].peFlags
;
919 lpDIBheader
->bmiColors
[i
].rgbRed
= lpPe
[i
].peRed
;
920 lpDIBheader
->bmiColors
[i
].rgbGreen
= lpPe
[i
].peGreen
;
921 lpDIBheader
->bmiColors
[i
].rgbBlue
= lpPe
[i
].peBlue
;
924 *lpDIBHeader
= lpDIBheader
;
933 static long freeDIB(LPBITMAPINFO lpDIBHeader
)
936 if (lpDIBHeader
!= NULL
) {