Add static_data flag to SetData and SetAlpha so Python buffer objects

can be used in wxPython without double free()'s.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33250 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn 2005-04-02 02:04:52 +00:00
parent 2809785e15
commit 4013de1217
2 changed files with 10 additions and 6 deletions

View File

@ -282,12 +282,12 @@ public:
// these functions provide fastest access to wxImage data but should be // these functions provide fastest access to wxImage data but should be
// used carefully as no checks are done // used carefully as no checks are done
unsigned char *GetData() const; unsigned char *GetData() const;
void SetData( unsigned char *data ); void SetData( unsigned char *data, bool static_data=false );
void SetData( unsigned char *data, int new_width, int new_height ); void SetData( unsigned char *data, int new_width, int new_height, bool static_data=false );
unsigned char *GetAlpha() const; // may return NULL! unsigned char *GetAlpha() const; // may return NULL!
bool HasAlpha() const { return GetAlpha() != NULL; } bool HasAlpha() const { return GetAlpha() != NULL; }
void SetAlpha(unsigned char *alpha = NULL); void SetAlpha(unsigned char *alpha = NULL, bool static_data=false);
void InitAlpha(); void InitAlpha();
// Mask functions // Mask functions

View File

@ -891,7 +891,7 @@ unsigned char *wxImage::GetData() const
return M_IMGDATA->m_data; return M_IMGDATA->m_data;
} }
void wxImage::SetData( unsigned char *data ) void wxImage::SetData( unsigned char *data, bool static_data )
{ {
wxCHECK_RET( Ok(), wxT("invalid image") ); wxCHECK_RET( Ok(), wxT("invalid image") );
@ -905,13 +905,14 @@ void wxImage::SetData( unsigned char *data )
newRefData->m_maskGreen = M_IMGDATA->m_maskGreen; newRefData->m_maskGreen = M_IMGDATA->m_maskGreen;
newRefData->m_maskBlue = M_IMGDATA->m_maskBlue; newRefData->m_maskBlue = M_IMGDATA->m_maskBlue;
newRefData->m_hasMask = M_IMGDATA->m_hasMask; newRefData->m_hasMask = M_IMGDATA->m_hasMask;
newRefData->m_static = static_data;
UnRef(); UnRef();
m_refData = newRefData; m_refData = newRefData;
} }
void wxImage::SetData( unsigned char *data, int new_width, int new_height ) void wxImage::SetData( unsigned char *data, int new_width, int new_height, bool static_data )
{ {
wxImageRefData *newRefData = new wxImageRefData(); wxImageRefData *newRefData = new wxImageRefData();
@ -933,6 +934,7 @@ void wxImage::SetData( unsigned char *data, int new_width, int new_height )
newRefData->m_data = data; newRefData->m_data = data;
newRefData->m_ok = true; newRefData->m_ok = true;
} }
newRefData->m_static = static_data;
UnRef(); UnRef();
@ -994,7 +996,7 @@ bool wxImage::ConvertColourToAlpha( unsigned char r, unsigned char g, unsigned c
return true; return true;
} }
void wxImage::SetAlpha( unsigned char *alpha ) void wxImage::SetAlpha( unsigned char *alpha, bool static_data )
{ {
wxCHECK_RET( Ok(), wxT("invalid image") ); wxCHECK_RET( Ok(), wxT("invalid image") );
@ -1005,6 +1007,8 @@ void wxImage::SetAlpha( unsigned char *alpha )
free(M_IMGDATA->m_alpha); free(M_IMGDATA->m_alpha);
M_IMGDATA->m_alpha = alpha; M_IMGDATA->m_alpha = alpha;
M_IMGDATA->m_static = static_data;
} }
unsigned char *wxImage::GetAlpha() const unsigned char *wxImage::GetAlpha() const