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 m_refData
= NULL
; // new wxBitmapRefData;
89 if ( wxTheBitmapList
)
90 wxTheBitmapList
->AddBitmap(this);
93 wxBitmap::~wxBitmap(void)
96 wxTheBitmapList
->DeleteObject(this);
99 bool wxBitmap::FreeResource(bool force
)
104 if (M_BITMAPDATA
->m_selectedInto
)
107 sprintf(buf
, "Bitmap %X was deleted without selecting out of wxMemoryDC %X.", (unsigned int) this, (unsigned int) M_BITMAPDATA
->m_selectedInto
);
110 if (M_BITMAPDATA
->m_hBitmap
)
112 DeleteObject((HBITMAP
) M_BITMAPDATA
->m_hBitmap
);
114 M_BITMAPDATA
->m_hBitmap
= 0 ;
117 if (M_BITMAPDATA->m_bitmapPalette)
118 delete M_BITMAPDATA->m_bitmapPalette;
120 M_BITMAPDATA->m_bitmapPalette = NULL ;
127 wxBitmap::wxBitmap(const char bits
[], int the_width
, int the_height
, int no_bits
)
129 m_refData
= new wxBitmapRefData
;
131 M_BITMAPDATA
->m_width
= the_width
;
132 M_BITMAPDATA
->m_height
= the_height
;
133 M_BITMAPDATA
->m_depth
= no_bits
;
134 M_BITMAPDATA
->m_numColors
= 0;
136 M_BITMAPDATA
->m_hBitmap
= (WXHBITMAP
) CreateBitmap(the_width
, the_height
, 1, no_bits
, bits
);
138 if (M_BITMAPDATA
->m_hBitmap
)
139 M_BITMAPDATA
->m_ok
= TRUE
;
141 M_BITMAPDATA
->m_ok
= FALSE
;
143 M_BITMAPDATA
->m_selectedInto
= NULL
;
145 if ( wxTheBitmapList
)
146 wxTheBitmapList
->AddBitmap(this);
149 wxBitmap::wxBitmap(int w
, int h
, int d
)
151 (void)Create(w
, h
, d
);
153 if ( wxTheBitmapList
)
154 wxTheBitmapList
->AddBitmap(this);
157 wxBitmap::wxBitmap(void *data
, long type
, int width
, int height
, int depth
)
159 (void) Create(data
, type
, width
, height
, depth
);
161 if ( wxTheBitmapList
)
162 wxTheBitmapList
->AddBitmap(this);
165 wxBitmap::wxBitmap(const wxString
& filename
, long type
)
167 LoadFile(filename
, (int)type
);
169 if ( wxTheBitmapList
)
170 wxTheBitmapList
->AddBitmap(this);
175 wxBitmap::wxBitmap(const char **data
, wxItem
*WXUNUSED(anItem
))
177 (void) Create((void *)data
, wxBITMAP_TYPE_XPM_DATA
, 0, 0, 0);
181 bool wxBitmap::Create(int w
, int h
, int d
)
185 m_refData
= new wxBitmapRefData
;
187 M_BITMAPDATA
->m_width
= w
;
188 M_BITMAPDATA
->m_height
= h
;
189 M_BITMAPDATA
->m_depth
= d
;
193 M_BITMAPDATA
->m_hBitmap
= (WXHBITMAP
) CreateBitmap(w
, h
, 1, d
, NULL
);
197 HDC dc
= GetDC(NULL
);
198 M_BITMAPDATA
->m_hBitmap
= (WXHBITMAP
) CreateCompatibleBitmap(dc
, w
, h
);
200 M_BITMAPDATA
->m_depth
= wxDisplayDepth();
202 if (M_BITMAPDATA
->m_hBitmap
)
203 M_BITMAPDATA
->m_ok
= TRUE
;
205 M_BITMAPDATA
->m_ok
= FALSE
;
206 return M_BITMAPDATA
->m_ok
;
209 bool wxBitmap::LoadFile(const wxString
& filename
, long type
)
213 m_refData
= new wxBitmapRefData
;
215 wxBitmapHandler
*handler
= FindHandler(type
);
217 if ( handler
== NULL
) {
218 wxLogWarning("no bitmap handler for type %d defined.", type
);
223 return handler
->LoadFile(this, filename
, type
, -1, -1);
226 bool wxBitmap::Create(void *data
, long type
, int width
, int height
, int depth
)
230 m_refData
= new wxBitmapRefData
;
232 wxBitmapHandler
*handler
= FindHandler(type
);
234 if ( handler
== NULL
) {
235 wxLogWarning("no bitmap handler for type %d defined.", type
);
240 return handler
->Create(this, data
, type
, width
, height
, depth
);
243 bool wxBitmap::SaveFile(const wxString
& filename
, int type
, const wxPalette
*palette
)
245 wxBitmapHandler
*handler
= FindHandler(type
);
247 if ( handler
== NULL
) {
248 wxLogWarning("no bitmap handler for type %d defined.", type
);
253 return handler
->SaveFile(this, filename
, type
, palette
);
256 void wxBitmap::SetWidth(int w
)
259 m_refData
= new wxBitmapRefData
;
261 M_BITMAPDATA
->m_width
= w
;
264 void wxBitmap::SetHeight(int h
)
267 m_refData
= new wxBitmapRefData
;
269 M_BITMAPDATA
->m_height
= h
;
272 void wxBitmap::SetDepth(int d
)
275 m_refData
= new wxBitmapRefData
;
277 M_BITMAPDATA
->m_depth
= d
;
280 void wxBitmap::SetQuality(int q
)
283 m_refData
= new wxBitmapRefData
;
285 M_BITMAPDATA
->m_quality
= q
;
288 void wxBitmap::SetOk(bool isOk
)
291 m_refData
= new wxBitmapRefData
;
293 M_BITMAPDATA
->m_ok
= isOk
;
296 void wxBitmap::SetPalette(const wxPalette
& palette
)
299 m_refData
= new wxBitmapRefData
;
301 M_BITMAPDATA
->m_bitmapPalette
= palette
;
304 void wxBitmap::SetMask(wxMask
*mask
)
307 m_refData
= new wxBitmapRefData
;
309 M_BITMAPDATA
->m_bitmapMask
= mask
;
312 void wxBitmap::SetHBITMAP(WXHBITMAP bmp
)
315 m_refData
= new wxBitmapRefData
;
317 M_BITMAPDATA
->m_hBitmap
= bmp
;
320 void wxBitmap::AddHandler(wxBitmapHandler
*handler
)
322 sm_handlers
.Append(handler
);
325 void wxBitmap::InsertHandler(wxBitmapHandler
*handler
)
327 sm_handlers
.Insert(handler
);
330 bool wxBitmap::RemoveHandler(const wxString
& name
)
332 wxBitmapHandler
*handler
= FindHandler(name
);
335 sm_handlers
.DeleteObject(handler
);
342 wxBitmapHandler
*wxBitmap::FindHandler(const wxString
& name
)
344 wxNode
*node
= sm_handlers
.First();
347 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
348 if ( handler
->GetName() == name
)
355 wxBitmapHandler
*wxBitmap::FindHandler(const wxString
& extension
, long bitmapType
)
357 wxNode
*node
= sm_handlers
.First();
360 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
361 if ( handler
->GetExtension() == extension
&&
362 (bitmapType
== -1 || handler
->GetType() == bitmapType
) )
369 wxBitmapHandler
*wxBitmap::FindHandler(long bitmapType
)
371 wxNode
*node
= sm_handlers
.First();
374 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
375 if (handler
->GetType() == bitmapType
)
382 // New Create/FreeDIB functions since ones in dibutils.cpp are confusing
383 static long createDIB(long xSize
, long ySize
, long bitsPerPixel
,
384 HPALETTE hPal
, LPBITMAPINFO
* lpDIBHeader
);
385 static long freeDIB(LPBITMAPINFO lpDIBHeader
);
387 // Creates a bitmap that matches the device context, from
388 // an arbitray bitmap. At present, the original bitmap must have an
389 // associated palette. TODO: use a default palette if no palette exists.
390 // Contributed by Frederic Villeneuve <frederic.villeneuve@natinst.com>
391 wxBitmap
wxBitmap::GetBitmapForDC(wxDC
& dc
) const
394 wxBitmap
tmpBitmap(this->GetWidth(), this->GetHeight(), dc
.GetDepth());
395 HPALETTE hPal
= NULL
;
399 wxASSERT( this->GetPalette() && this->GetPalette()->Ok() && (this->GetPalette()->GetHPALETTE() != NULL
) );
401 tmpBitmap
.SetPalette(this->GetPalette());
402 memDC
.SelectObject(tmpBitmap
);
403 memDC
.SetPalette(this->GetPalette());
405 hPal
= (HPALETTE
) this->GetPalette()->GetHPALETTE();
407 // set the height negative because in a DIB the order of the lines is reversed
408 createDIB(this->GetWidth(), -this->GetHeight(), this->GetDepth(), hPal
, &lpDib
);
410 lpBits
= malloc(lpDib
->bmiHeader
.biSizeImage
);
412 ::GetBitmapBits((HBITMAP
)GetHBITMAP(), lpDib
->bmiHeader
.biSizeImage
, lpBits
);
414 ::SetDIBitsToDevice((HDC
) memDC
.GetHDC(), 0, 0, this->GetWidth(), this->GetHeight(),
415 0, 0, 0, this->GetHeight(), lpBits
, lpDib
, DIB_RGB_COLORS
);
432 // Construct a mask from a bitmap and a colour indicating
433 // the transparent area
434 wxMask::wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
)
437 Create(bitmap
, colour
);
440 // Construct a mask from a bitmap and a palette index indicating
441 // the transparent area
442 wxMask::wxMask(const wxBitmap
& bitmap
, int paletteIndex
)
445 Create(bitmap
, paletteIndex
);
448 // Construct a mask from a mono bitmap (copies the bitmap).
449 wxMask::wxMask(const wxBitmap
& bitmap
)
455 wxMask::~wxMask(void)
458 ::DeleteObject((HBITMAP
) m_maskBitmap
);
461 // Create a mask from a mono bitmap (copies the bitmap).
462 bool wxMask::Create(const wxBitmap
& bitmap
)
466 ::DeleteObject((HBITMAP
) m_maskBitmap
);
469 if (!bitmap
.Ok() || bitmap
.GetDepth() != 1)
473 m_maskBitmap
= (WXHBITMAP
) CreateBitmap(
478 HDC srcDC
= CreateCompatibleDC(0);
479 SelectObject(srcDC
, (HBITMAP
) bitmap
.GetHBITMAP());
480 HDC destDC
= CreateCompatibleDC(0);
481 SelectObject(destDC
, (HBITMAP
) m_maskBitmap
);
482 BitBlt(destDC
, 0, 0, bitmap
.GetWidth(), bitmap
.GetHeight(), srcDC
, 0, 0, SRCCOPY
);
483 SelectObject(srcDC
, 0);
485 SelectObject(destDC
, 0);
490 // Create a mask from a bitmap and a palette index indicating
491 // the transparent area
492 bool wxMask::Create(const wxBitmap
& bitmap
, int paletteIndex
)
496 ::DeleteObject((HBITMAP
) m_maskBitmap
);
499 if (bitmap
.Ok() && bitmap
.GetPalette()->Ok())
501 unsigned char red
, green
, blue
;
502 if (bitmap
.GetPalette()->GetRGB(paletteIndex
, &red
, &green
, &blue
))
504 wxColour
transparentColour(red
, green
, blue
);
505 return Create(bitmap
, transparentColour
);
511 // Create a mask from a bitmap and a colour indicating
512 // the transparent area
513 bool wxMask::Create(const wxBitmap
& bitmap
, const wxColour
& colour
)
517 ::DeleteObject((HBITMAP
) m_maskBitmap
);
525 // scan the bitmap for the transparent colour and set
526 // the corresponding pixels in the mask to BLACK and
528 COLORREF maskColour
= RGB(colour
.Red(), colour
.Green(), colour
.Blue());
529 m_maskBitmap
= (WXHBITMAP
) ::CreateBitmap(
534 HDC srcDC
= ::CreateCompatibleDC(0);
535 ::SelectObject(srcDC
, (HBITMAP
) bitmap
.GetHBITMAP());
536 HDC destDC
= ::CreateCompatibleDC(0);
537 ::SelectObject(destDC
, (HBITMAP
) m_maskBitmap
);
539 // this is not very efficient, but I can't think
540 // of a better way of doing it
541 for (int w
= 0; w
< bitmap
.GetWidth(); w
++)
543 for (int h
= 0; h
< bitmap
.GetHeight(); h
++)
545 COLORREF col
= GetPixel(srcDC
, w
, h
);
546 if (col
== maskColour
)
548 ::SetPixel(destDC
, w
, h
, RGB(0, 0, 0));
552 ::SetPixel(destDC
, w
, h
, RGB(255, 255, 255));
556 ::SelectObject(srcDC
, 0);
558 ::SelectObject(destDC
, 0);
567 IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler
, wxObject
)
569 bool wxBitmapHandler::Create(wxBitmap
*bitmap
, void *data
, long type
, int width
, int height
, int depth
)
574 bool wxBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long type
,
575 int desiredWidth
, int desiredHeight
)
580 bool wxBitmapHandler::SaveFile(wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
)
589 class WXDLLEXPORT wxBMPResourceHandler
: public wxBitmapHandler
591 DECLARE_DYNAMIC_CLASS(wxBMPResourceHandler
)
593 inline wxBMPResourceHandler(void)
595 m_name
= "Windows bitmap resource";
597 m_type
= wxBITMAP_TYPE_BMP_RESOURCE
;
600 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
601 int desiredWidth
, int desiredHeight
);
603 IMPLEMENT_DYNAMIC_CLASS(wxBMPResourceHandler
, wxBitmapHandler
)
605 bool wxBMPResourceHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
606 int desiredWidth
, int desiredHeight
)
608 // TODO: load colourmap.
609 M_BITMAPHANDLERDATA
->m_hBitmap
= (WXHBITMAP
) ::LoadBitmap(wxGetInstance(), name
);
610 if (M_BITMAPHANDLERDATA
->m_hBitmap
)
612 M_BITMAPHANDLERDATA
->m_ok
= TRUE
;
614 GetObject((HBITMAP
) M_BITMAPHANDLERDATA
->m_hBitmap
, sizeof(BITMAP
), (LPSTR
) &bm
);
615 M_BITMAPHANDLERDATA
->m_width
= bm
.bmWidth
;
616 M_BITMAPHANDLERDATA
->m_height
= bm
.bmHeight
;
617 M_BITMAPHANDLERDATA
->m_depth
= bm
.bmBitsPixel
;
621 // it's probably not found
622 wxLogError("Can't load bitmap '%s' from resources! Check .rc file.", name
.c_str());
627 class WXDLLEXPORT wxBMPFileHandler
: public wxBitmapHandler
629 DECLARE_DYNAMIC_CLASS(wxBMPFileHandler
)
631 inline wxBMPFileHandler(void)
633 m_name
= "Windows bitmap file";
635 m_type
= wxBITMAP_TYPE_BMP
;
638 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
639 int desiredWidth
, int desiredHeight
);
640 virtual bool SaveFile(wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
= NULL
);
642 IMPLEMENT_DYNAMIC_CLASS(wxBMPFileHandler
, wxBitmapHandler
)
644 bool wxBMPFileHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
645 int desiredWidth
, int desiredHeight
)
647 #if USE_IMAGE_LOADING_IN_MSW
648 wxPalette
*palette
= NULL
;
649 bool success
= FALSE
;
651 if (type & wxBITMAP_DISCARD_COLOURMAP)
652 success = wxLoadIntoBitmap(WXSTRINGCAST name, bitmap);
655 success
= (wxLoadIntoBitmap(WXSTRINGCAST name
, bitmap
, &palette
) != 0);
656 if (!success
&& palette
)
662 M_BITMAPHANDLERDATA
->m_bitmapPalette
= *palette
;
669 bool wxBMPFileHandler::SaveFile(wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*pal
)
671 #if USE_IMAGE_LOADING_IN_MSW
672 wxPalette
*actualPalette
= (wxPalette
*)pal
;
673 if (!actualPalette
&& (!M_BITMAPHANDLERDATA
->m_bitmapPalette
.IsNull()))
674 actualPalette
= & (M_BITMAPHANDLERDATA
->m_bitmapPalette
);
675 return (wxSaveBitmap(WXSTRINGCAST name
, bitmap
, actualPalette
) != 0);
681 class WXDLLEXPORT wxXPMFileHandler
: public wxBitmapHandler
683 DECLARE_DYNAMIC_CLASS(wxXPMFileHandler
)
685 inline wxXPMFileHandler(void)
687 m_name
= "XPM bitmap file";
689 m_type
= wxBITMAP_TYPE_XPM
;
692 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
693 int desiredWidth
= -1, int desiredHeight
= -1);
694 virtual bool SaveFile(wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
= NULL
);
696 IMPLEMENT_DYNAMIC_CLASS(wxXPMFileHandler
, wxBitmapHandler
)
698 bool wxXPMFileHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
699 int desiredWidth
, int desiredHeight
)
703 XpmAttributes xpmAttr
;
706 M_BITMAPHANDLERDATA
->m_ok
= FALSE
;
707 dc
= CreateCompatibleDC(NULL
);
710 xpmAttr
.valuemask
= XpmReturnPixels
;
711 int errorStatus
= XpmReadFileToImage(&dc
, WXSTRINGCAST name
, &ximage
, (XImage
**) NULL
, &xpmAttr
);
713 if (errorStatus
== XpmSuccess
)
715 M_BITMAPHANDLERDATA
->m_hBitmap
= (WXHBITMAP
) ximage
->bitmap
;
718 GetObject((HBITMAP
)M_BITMAPHANDLERDATA
->m_hBitmap
, sizeof(bm
), (LPSTR
) & bm
);
720 M_BITMAPHANDLERDATA
->m_width
= (bm
.bmWidth
);
721 M_BITMAPHANDLERDATA
->m_height
= (bm
.bmHeight
);
722 M_BITMAPHANDLERDATA
->m_depth
= (bm
.bmPlanes
* bm
.bmBitsPixel
);
723 M_BITMAPHANDLERDATA
->m_numColors
= xpmAttr
.npixels
;
724 XpmFreeAttributes(&xpmAttr
);
727 M_BITMAPHANDLERDATA
->m_ok
= TRUE
;
732 M_BITMAPHANDLERDATA
->m_ok
= FALSE
;
741 bool wxXPMFileHandler::SaveFile(wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
)
746 Visual
*visual
= NULL
;
749 dc
= CreateCompatibleDC(NULL
);
752 if (SelectObject(dc
, (HBITMAP
) M_BITMAPHANDLERDATA
->m_hBitmap
))
753 { /* for following SetPixel */
754 /* fill the XImage struct 'by hand' */
755 ximage
.width
= M_BITMAPHANDLERDATA
->m_width
;
756 ximage
.height
= M_BITMAPHANDLERDATA
->m_height
;
757 ximage
.depth
= M_BITMAPHANDLERDATA
->m_depth
;
758 ximage
.bitmap
= (void *)M_BITMAPHANDLERDATA
->m_hBitmap
;
759 int errorStatus
= XpmWriteFileFromImage(&dc
, WXSTRINGCAST name
,
760 &ximage
, (XImage
*) NULL
, (XpmAttributes
*) NULL
);
765 if (errorStatus
== XpmSuccess
)
766 return TRUE
; /* no error */
776 class WXDLLEXPORT wxXPMDataHandler
: public wxBitmapHandler
778 DECLARE_DYNAMIC_CLASS(wxXPMDataHandler
)
780 inline wxXPMDataHandler(void)
782 m_name
= "XPM bitmap data";
784 m_type
= wxBITMAP_TYPE_XPM_DATA
;
787 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
= 1);
789 IMPLEMENT_DYNAMIC_CLASS(wxXPMDataHandler
, wxBitmapHandler
)
791 bool wxXPMDataHandler::Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
)
796 XpmAttributes xpmAttr
;
799 M_BITMAPHANDLERDATA
->m_ok
= FALSE
;
800 M_BITMAPHANDLERDATA
->m_numColors
= 0;
802 dc
= CreateCompatibleDC(NULL
); /* memory DC */
806 xpmAttr
.valuemask
= XpmReturnInfos
; /* get infos back */
807 ErrorStatus
= XpmCreateImageFromData(&dc
, (char **)data
,
808 &ximage
, (XImage
**) NULL
, &xpmAttr
);
810 if (ErrorStatus
== XpmSuccess
)
812 /* ximage is malloced and contains bitmap and attributes */
813 M_BITMAPHANDLERDATA
->m_hBitmap
= (WXHBITMAP
) ximage
->bitmap
;
816 GetObject((HBITMAP
) M_BITMAPHANDLERDATA
->m_hBitmap
, sizeof(bm
), (LPSTR
) & bm
);
818 M_BITMAPHANDLERDATA
->m_width
= (bm
.bmWidth
);
819 M_BITMAPHANDLERDATA
->m_height
= (bm
.bmHeight
);
820 M_BITMAPHANDLERDATA
->m_depth
= (bm
.bmPlanes
* bm
.bmBitsPixel
);
821 M_BITMAPHANDLERDATA
->m_numColors
= xpmAttr
.npixels
;
822 XpmFreeAttributes(&xpmAttr
);
824 XImageFree(ximage
); // releases the malloc, but does not detroy
826 M_BITMAPHANDLERDATA
->m_ok
= TRUE
;
833 M_BITMAPHANDLERDATA
->m_ok
= FALSE
;
834 // XpmDebugError(ErrorStatus, NULL);
844 void wxBitmap::CleanUpHandlers(void)
846 wxNode
*node
= sm_handlers
.First();
849 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
850 wxNode
*next
= node
->Next();
857 void wxBitmap::InitStandardHandlers(void)
859 AddHandler(new wxBMPResourceHandler
);
860 AddHandler(new wxBMPFileHandler
);
861 AddHandler(new wxXPMFileHandler
);
862 AddHandler(new wxXPMDataHandler
);
863 AddHandler(new wxICOResourceHandler
);
864 AddHandler(new wxICOFileHandler
);
867 static long createDIB(long xSize
, long ySize
, long bitsPerPixel
,
868 HPALETTE hPal
, LPBITMAPINFO
* lpDIBHeader
)
870 unsigned long i
, headerSize
;
871 LPBITMAPINFO lpDIBheader
= NULL
;
872 LPPALETTEENTRY lpPe
= NULL
;
875 // Allocate space for a DIB header
876 headerSize
= (sizeof(BITMAPINFOHEADER
) + (256 * sizeof(PALETTEENTRY
)));
877 lpDIBheader
= (BITMAPINFO
*) malloc(headerSize
);
878 lpPe
= (PALETTEENTRY
*)((BYTE
*)lpDIBheader
+ sizeof(BITMAPINFOHEADER
));
880 GetPaletteEntries(hPal
, 0, 256, lpPe
);
883 memset(lpDIBheader
, 0x00, sizeof(BITMAPINFOHEADER
));
886 // Fill in the static parts of the DIB header
887 lpDIBheader
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
888 lpDIBheader
->bmiHeader
.biWidth
= xSize
;
889 lpDIBheader
->bmiHeader
.biHeight
= ySize
;
890 lpDIBheader
->bmiHeader
.biPlanes
= 1;
892 // this value must be 1, 4, 8 or 24 so PixelDepth can only be
893 lpDIBheader
->bmiHeader
.biBitCount
= (WORD
)(bitsPerPixel
);
894 lpDIBheader
->bmiHeader
.biCompression
= BI_RGB
;
895 lpDIBheader
->bmiHeader
.biSizeImage
= xSize
* abs(ySize
) * bitsPerPixel
>>
897 lpDIBheader
->bmiHeader
.biClrUsed
= 256;
900 // Initialize the DIB palette
901 for (i
= 0; i
< 256; i
++) {
902 lpDIBheader
->bmiColors
[i
].rgbReserved
= lpPe
[i
].peFlags
;
903 lpDIBheader
->bmiColors
[i
].rgbRed
= lpPe
[i
].peRed
;
904 lpDIBheader
->bmiColors
[i
].rgbGreen
= lpPe
[i
].peGreen
;
905 lpDIBheader
->bmiColors
[i
].rgbBlue
= lpPe
[i
].peBlue
;
908 *lpDIBHeader
= lpDIBheader
;
917 static long freeDIB(LPBITMAPINFO lpDIBHeader
)
920 if (lpDIBHeader
!= NULL
) {