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 "../../contrib/wxxpm/libxpm.34b/lib/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(const 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
;
397 wxASSERT( this->GetPalette() && this->GetPalette()->Ok() && (this->GetPalette()->GetHPALETTE() != 0) );
399 tmpBitmap
.SetPalette(this->GetPalette());
400 memDC
.SelectObject(tmpBitmap
);
401 memDC
.SetPalette(this->GetPalette());
403 hPal
= (HPALETTE
) this->GetPalette()->GetHPALETTE();
405 // set the height negative because in a DIB the order of the lines is reversed
406 createDIB(this->GetWidth(), -this->GetHeight(), this->GetDepth(), hPal
, &lpDib
);
408 lpBits
= malloc(lpDib
->bmiHeader
.biSizeImage
);
410 ::GetBitmapBits((HBITMAP
)GetHBITMAP(), lpDib
->bmiHeader
.biSizeImage
, lpBits
);
412 ::SetDIBitsToDevice((HDC
) memDC
.GetHDC(), 0, 0, this->GetWidth(), this->GetHeight(),
413 0, 0, 0, this->GetHeight(), lpBits
, lpDib
, DIB_RGB_COLORS
);
430 // Construct a mask from a bitmap and a colour indicating
431 // the transparent area
432 wxMask::wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
)
435 Create(bitmap
, colour
);
438 // Construct a mask from a bitmap and a palette index indicating
439 // the transparent area
440 wxMask::wxMask(const wxBitmap
& bitmap
, int paletteIndex
)
443 Create(bitmap
, paletteIndex
);
446 // Construct a mask from a mono bitmap (copies the bitmap).
447 wxMask::wxMask(const wxBitmap
& bitmap
)
453 wxMask::~wxMask(void)
456 ::DeleteObject((HBITMAP
) m_maskBitmap
);
459 // Create a mask from a mono bitmap (copies the bitmap).
460 bool wxMask::Create(const wxBitmap
& bitmap
)
464 ::DeleteObject((HBITMAP
) m_maskBitmap
);
467 if (!bitmap
.Ok() || bitmap
.GetDepth() != 1)
471 m_maskBitmap
= (WXHBITMAP
) CreateBitmap(
476 HDC srcDC
= CreateCompatibleDC(0);
477 SelectObject(srcDC
, (HBITMAP
) bitmap
.GetHBITMAP());
478 HDC destDC
= CreateCompatibleDC(0);
479 SelectObject(destDC
, (HBITMAP
) m_maskBitmap
);
480 BitBlt(destDC
, 0, 0, bitmap
.GetWidth(), bitmap
.GetHeight(), srcDC
, 0, 0, SRCCOPY
);
481 SelectObject(srcDC
, 0);
483 SelectObject(destDC
, 0);
488 // Create a mask from a bitmap and a palette index indicating
489 // the transparent area
490 bool wxMask::Create(const wxBitmap
& bitmap
, int paletteIndex
)
494 ::DeleteObject((HBITMAP
) m_maskBitmap
);
497 if (bitmap
.Ok() && bitmap
.GetPalette()->Ok())
499 unsigned char red
, green
, blue
;
500 if (bitmap
.GetPalette()->GetRGB(paletteIndex
, &red
, &green
, &blue
))
502 wxColour
transparentColour(red
, green
, blue
);
503 return Create(bitmap
, transparentColour
);
509 // Create a mask from a bitmap and a colour indicating
510 // the transparent area
511 bool wxMask::Create(const wxBitmap
& bitmap
, const wxColour
& colour
)
515 ::DeleteObject((HBITMAP
) m_maskBitmap
);
523 // scan the bitmap for the transparent colour and set
524 // the corresponding pixels in the mask to BLACK and
526 COLORREF maskColour
= RGB(colour
.Red(), colour
.Green(), colour
.Blue());
527 m_maskBitmap
= (WXHBITMAP
) ::CreateBitmap(
532 HDC srcDC
= ::CreateCompatibleDC(0);
533 ::SelectObject(srcDC
, (HBITMAP
) bitmap
.GetHBITMAP());
534 HDC destDC
= ::CreateCompatibleDC(0);
535 ::SelectObject(destDC
, (HBITMAP
) m_maskBitmap
);
537 // this is not very efficient, but I can't think
538 // of a better way of doing it
539 for (int w
= 0; w
< bitmap
.GetWidth(); w
++)
541 for (int h
= 0; h
< bitmap
.GetHeight(); h
++)
543 COLORREF col
= GetPixel(srcDC
, w
, h
);
544 if (col
== maskColour
)
546 ::SetPixel(destDC
, w
, h
, RGB(0, 0, 0));
550 ::SetPixel(destDC
, w
, h
, RGB(255, 255, 255));
554 ::SelectObject(srcDC
, 0);
556 ::SelectObject(destDC
, 0);
565 IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler
, wxObject
)
567 bool wxBitmapHandler::Create(wxBitmap
*bitmap
, void *data
, long type
, int width
, int height
, int depth
)
572 bool wxBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long type
,
573 int desiredWidth
, int desiredHeight
)
578 bool wxBitmapHandler::SaveFile(wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
)
587 class WXDLLEXPORT wxBMPResourceHandler
: public wxBitmapHandler
589 DECLARE_DYNAMIC_CLASS(wxBMPResourceHandler
)
591 inline wxBMPResourceHandler(void)
593 m_name
= "Windows bitmap resource";
595 m_type
= wxBITMAP_TYPE_BMP_RESOURCE
;
598 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
599 int desiredWidth
, int desiredHeight
);
601 IMPLEMENT_DYNAMIC_CLASS(wxBMPResourceHandler
, wxBitmapHandler
)
603 bool wxBMPResourceHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
604 int desiredWidth
, int desiredHeight
)
606 // TODO: load colourmap.
607 M_BITMAPHANDLERDATA
->m_hBitmap
= (WXHBITMAP
) ::LoadBitmap(wxGetInstance(), name
);
608 if (M_BITMAPHANDLERDATA
->m_hBitmap
)
610 M_BITMAPHANDLERDATA
->m_ok
= TRUE
;
612 GetObject((HBITMAP
) M_BITMAPHANDLERDATA
->m_hBitmap
, sizeof(BITMAP
), (LPSTR
) &bm
);
613 M_BITMAPHANDLERDATA
->m_width
= bm
.bmWidth
;
614 M_BITMAPHANDLERDATA
->m_height
= bm
.bmHeight
;
615 M_BITMAPHANDLERDATA
->m_depth
= bm
.bmBitsPixel
;
619 // it's probably not found
620 wxLogError("Can't load bitmap '%s' from resources! Check .rc file.", name
.c_str());
625 class WXDLLEXPORT wxBMPFileHandler
: public wxBitmapHandler
627 DECLARE_DYNAMIC_CLASS(wxBMPFileHandler
)
629 inline wxBMPFileHandler(void)
631 m_name
= "Windows bitmap file";
633 m_type
= wxBITMAP_TYPE_BMP
;
636 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
637 int desiredWidth
, int desiredHeight
);
638 virtual bool SaveFile(wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
= NULL
);
640 IMPLEMENT_DYNAMIC_CLASS(wxBMPFileHandler
, wxBitmapHandler
)
642 bool wxBMPFileHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
643 int desiredWidth
, int desiredHeight
)
645 #if wxUSE_IMAGE_LOADING_IN_MSW
646 wxPalette
*palette
= NULL
;
647 bool success
= FALSE
;
649 if (type & wxBITMAP_DISCARD_COLOURMAP)
650 success = wxLoadIntoBitmap(WXSTRINGCAST name, bitmap);
653 success
= (wxLoadIntoBitmap(WXSTRINGCAST name
, bitmap
, &palette
) != 0);
654 if (!success
&& palette
)
660 M_BITMAPHANDLERDATA
->m_bitmapPalette
= *palette
;
667 bool wxBMPFileHandler::SaveFile(wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*pal
)
669 #if wxUSE_IMAGE_LOADING_IN_MSW
670 wxPalette
*actualPalette
= (wxPalette
*)pal
;
671 if (!actualPalette
&& (!M_BITMAPHANDLERDATA
->m_bitmapPalette
.IsNull()))
672 actualPalette
= & (M_BITMAPHANDLERDATA
->m_bitmapPalette
);
673 return (wxSaveBitmap(WXSTRINGCAST name
, bitmap
, actualPalette
) != 0);
679 class WXDLLEXPORT wxXPMFileHandler
: public wxBitmapHandler
681 DECLARE_DYNAMIC_CLASS(wxXPMFileHandler
)
683 inline wxXPMFileHandler(void)
685 m_name
= "XPM bitmap file";
687 m_type
= wxBITMAP_TYPE_XPM
;
690 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
691 int desiredWidth
= -1, int desiredHeight
= -1);
692 virtual bool SaveFile(wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
= NULL
);
694 IMPLEMENT_DYNAMIC_CLASS(wxXPMFileHandler
, wxBitmapHandler
)
696 bool wxXPMFileHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
697 int desiredWidth
, int desiredHeight
)
701 XpmAttributes xpmAttr
;
704 M_BITMAPHANDLERDATA
->m_ok
= FALSE
;
705 dc
= CreateCompatibleDC(NULL
);
708 xpmAttr
.valuemask
= XpmReturnPixels
;
709 int errorStatus
= XpmReadFileToImage(&dc
, WXSTRINGCAST name
, &ximage
, (XImage
**) NULL
, &xpmAttr
);
711 if (errorStatus
== XpmSuccess
)
713 M_BITMAPHANDLERDATA
->m_hBitmap
= (WXHBITMAP
) ximage
->bitmap
;
716 GetObject((HBITMAP
)M_BITMAPHANDLERDATA
->m_hBitmap
, sizeof(bm
), (LPSTR
) & bm
);
718 M_BITMAPHANDLERDATA
->m_width
= (bm
.bmWidth
);
719 M_BITMAPHANDLERDATA
->m_height
= (bm
.bmHeight
);
720 M_BITMAPHANDLERDATA
->m_depth
= (bm
.bmPlanes
* bm
.bmBitsPixel
);
721 M_BITMAPHANDLERDATA
->m_numColors
= xpmAttr
.npixels
;
722 XpmFreeAttributes(&xpmAttr
);
725 M_BITMAPHANDLERDATA
->m_ok
= TRUE
;
730 M_BITMAPHANDLERDATA
->m_ok
= FALSE
;
739 bool wxXPMFileHandler::SaveFile(wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
)
744 Visual
*visual
= NULL
;
747 dc
= CreateCompatibleDC(NULL
);
750 if (SelectObject(dc
, (HBITMAP
) M_BITMAPHANDLERDATA
->m_hBitmap
))
751 { /* for following SetPixel */
752 /* fill the XImage struct 'by hand' */
753 ximage
.width
= M_BITMAPHANDLERDATA
->m_width
;
754 ximage
.height
= M_BITMAPHANDLERDATA
->m_height
;
755 ximage
.depth
= M_BITMAPHANDLERDATA
->m_depth
;
756 ximage
.bitmap
= (void *)M_BITMAPHANDLERDATA
->m_hBitmap
;
757 int errorStatus
= XpmWriteFileFromImage(&dc
, WXSTRINGCAST name
,
758 &ximage
, (XImage
*) NULL
, (XpmAttributes
*) NULL
);
763 if (errorStatus
== XpmSuccess
)
764 return TRUE
; /* no error */
774 class WXDLLEXPORT wxXPMDataHandler
: public wxBitmapHandler
776 DECLARE_DYNAMIC_CLASS(wxXPMDataHandler
)
778 inline wxXPMDataHandler(void)
780 m_name
= "XPM bitmap data";
782 m_type
= wxBITMAP_TYPE_XPM_DATA
;
785 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
= 1);
787 IMPLEMENT_DYNAMIC_CLASS(wxXPMDataHandler
, wxBitmapHandler
)
789 bool wxXPMDataHandler::Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
)
794 XpmAttributes xpmAttr
;
797 M_BITMAPHANDLERDATA
->m_ok
= FALSE
;
798 M_BITMAPHANDLERDATA
->m_numColors
= 0;
800 dc
= CreateCompatibleDC(NULL
); /* memory DC */
804 xpmAttr
.valuemask
= XpmReturnInfos
; /* get infos back */
805 ErrorStatus
= XpmCreateImageFromData(&dc
, (char **)data
,
806 &ximage
, (XImage
**) NULL
, &xpmAttr
);
808 if (ErrorStatus
== XpmSuccess
)
810 /* ximage is malloced and contains bitmap and attributes */
811 M_BITMAPHANDLERDATA
->m_hBitmap
= (WXHBITMAP
) ximage
->bitmap
;
814 GetObject((HBITMAP
) M_BITMAPHANDLERDATA
->m_hBitmap
, sizeof(bm
), (LPSTR
) & bm
);
816 M_BITMAPHANDLERDATA
->m_width
= (bm
.bmWidth
);
817 M_BITMAPHANDLERDATA
->m_height
= (bm
.bmHeight
);
818 M_BITMAPHANDLERDATA
->m_depth
= (bm
.bmPlanes
* bm
.bmBitsPixel
);
819 M_BITMAPHANDLERDATA
->m_numColors
= xpmAttr
.npixels
;
820 XpmFreeAttributes(&xpmAttr
);
822 XImageFree(ximage
); // releases the malloc, but does not detroy
824 M_BITMAPHANDLERDATA
->m_ok
= TRUE
;
831 M_BITMAPHANDLERDATA
->m_ok
= FALSE
;
832 // XpmDebugError(ErrorStatus, NULL);
842 void wxBitmap::CleanUpHandlers(void)
844 wxNode
*node
= sm_handlers
.First();
847 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
848 wxNode
*next
= node
->Next();
855 void wxBitmap::InitStandardHandlers(void)
857 AddHandler(new wxBMPResourceHandler
);
858 AddHandler(new wxBMPFileHandler
);
859 AddHandler(new wxXPMFileHandler
);
860 AddHandler(new wxXPMDataHandler
);
861 AddHandler(new wxICOResourceHandler
);
862 AddHandler(new wxICOFileHandler
);
865 static long createDIB(long xSize
, long ySize
, long bitsPerPixel
,
866 HPALETTE hPal
, LPBITMAPINFO
* lpDIBHeader
)
868 unsigned long i
, headerSize
;
869 LPBITMAPINFO lpDIBheader
= NULL
;
870 LPPALETTEENTRY lpPe
= NULL
;
873 // Allocate space for a DIB header
874 headerSize
= (sizeof(BITMAPINFOHEADER
) + (256 * sizeof(PALETTEENTRY
)));
875 lpDIBheader
= (BITMAPINFO
*) malloc(headerSize
);
876 lpPe
= (PALETTEENTRY
*)((BYTE
*)lpDIBheader
+ sizeof(BITMAPINFOHEADER
));
878 GetPaletteEntries(hPal
, 0, 256, lpPe
);
881 memset(lpDIBheader
, 0x00, sizeof(BITMAPINFOHEADER
));
884 // Fill in the static parts of the DIB header
885 lpDIBheader
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
886 lpDIBheader
->bmiHeader
.biWidth
= xSize
;
887 lpDIBheader
->bmiHeader
.biHeight
= ySize
;
888 lpDIBheader
->bmiHeader
.biPlanes
= 1;
890 // this value must be 1, 4, 8 or 24 so PixelDepth can only be
891 lpDIBheader
->bmiHeader
.biBitCount
= (WORD
)(bitsPerPixel
);
892 lpDIBheader
->bmiHeader
.biCompression
= BI_RGB
;
893 lpDIBheader
->bmiHeader
.biSizeImage
= xSize
* abs(ySize
) * bitsPerPixel
>>
895 lpDIBheader
->bmiHeader
.biClrUsed
= 256;
898 // Initialize the DIB palette
899 for (i
= 0; i
< 256; i
++) {
900 lpDIBheader
->bmiColors
[i
].rgbReserved
= lpPe
[i
].peFlags
;
901 lpDIBheader
->bmiColors
[i
].rgbRed
= lpPe
[i
].peRed
;
902 lpDIBheader
->bmiColors
[i
].rgbGreen
= lpPe
[i
].peGreen
;
903 lpDIBheader
->bmiColors
[i
].rgbBlue
= lpPe
[i
].peBlue
;
906 *lpDIBHeader
= lpDIBheader
;
915 static long freeDIB(LPBITMAPINFO lpDIBHeader
)
918 if (lpDIBHeader
!= NULL
) {