X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dbda9e86f0e5ec1184bc16d135bb7205bc99236e..7708abe9cd1ff4bf3c657db8e8ffeeb4bbcbb4bc:/src/common/image.cpp diff --git a/src/common/image.cpp b/src/common/image.cpp index 0b4956dad2..151ba3b73e 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -34,6 +34,10 @@ extern "C" { #include "wx/filefn.h" #include "wx/wfstream.h" #include "wx/intl.h" +#include "wx/module.h" + +// For memcpy +#include #ifdef __SALFORDC__ #ifdef FAR @@ -255,9 +259,11 @@ char unsigned *wxImage::GetData() const return M_IMGDATA->m_data; } -void wxImage::SetData( char unsigned *WXUNUSED(data) ) +void wxImage::SetData( char unsigned *data ) { wxCHECK_RET( Ok(), "invalid image" ); + + memcpy(M_IMGDATA->m_data, data, M_IMGDATA->m_width * M_IMGDATA->m_height * 3); } void wxImage::SetMaskColour( unsigned char r, unsigned char g, unsigned char b ) @@ -1957,7 +1963,7 @@ wxBitmap wxImage::ConvertToBitmap() const wxBitmap bitmap; wxCHECK_MSG( Ok(), bitmap, "invalid image" ); - + int width = GetWidth(); int height = GetHeight(); @@ -1971,10 +1977,10 @@ wxBitmap wxImage::ConvertToBitmap() const // Create image XImage *data_image = XCreateImage( dpy, vis, bpp, ZPixmap, 0, 0, width, height, 32, 0 ); - data_image->data = new char[ data_image->bytes_per_line * data_image->height ]; + data_image->data = (char*) malloc( data_image->bytes_per_line * data_image->height ); bitmap.Create( width, height, bpp ); - + /* // Create mask @@ -2012,7 +2018,7 @@ wxBitmap wxImage::ConvertToBitmap() const } XFree( vi ); - + if ((bpp == 16) && (vi->red_mask != 0xf800)) bpp = 15; if (bpp < 8) bpp = 8; @@ -2278,3 +2284,19 @@ wxImage::wxImage( const wxBitmap &bitmap ) */ } #endif + +// A module to allow wxImage initialization/cleanup +// without calling these functions from app.cpp or from +// the user's application. + +class wxImageModule: public wxModule +{ +DECLARE_DYNAMIC_CLASS(wxImageModule) +public: + wxImageModule() {} + bool OnInit() { wxImage::InitStandardHandlers(); return TRUE; }; + void OnExit() { wxImage::CleanUpHandlers(); }; +}; + +IMPLEMENT_DYNAMIC_CLASS(wxImageModule, wxModule) +