guarding agains NULL

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71767 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2012-06-14 21:51:19 +00:00
parent 7d5b794ce4
commit f5fac4471b

View File

@@ -1035,20 +1035,23 @@ wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const
{ {
unsigned char *sourcedata = (unsigned char*) GetRawAccess() ; unsigned char *sourcedata = (unsigned char*) GetRawAccess() ;
unsigned char *destdata = (unsigned char*) ret.BeginRawAccess() ; unsigned char *destdata = (unsigned char*) ret.BeginRawAccess() ;
wxASSERT( (sourcedata != NULL) && (destdata != NULL) ) ; wxASSERT((sourcedata != NULL) && (destdata != NULL));
int sourcelinesize = GetBitmapData()->GetBytesPerRow() ; if ( (sourcedata != NULL) && (destdata != NULL) )
int destlinesize = ret.GetBitmapData()->GetBytesPerRow() ;
unsigned char *source = sourcedata + rect.x * 4 + rect.y * sourcelinesize ;
unsigned char *dest = destdata ;
for (int yy = 0; yy < destheight; ++yy, source += sourcelinesize , dest += destlinesize)
{ {
memcpy( dest , source , destlinesize ) ; int sourcelinesize = GetBitmapData()->GetBytesPerRow() ;
int destlinesize = ret.GetBitmapData()->GetBytesPerRow() ;
unsigned char *source = sourcedata + rect.x * 4 + rect.y * sourcelinesize ;
unsigned char *dest = destdata ;
for (int yy = 0; yy < destheight; ++yy, source += sourcelinesize , dest += destlinesize)
{
memcpy( dest , source , destlinesize ) ;
}
} }
ret.EndRawAccess() ;
} }
ret.EndRawAccess() ;
if ( M_BITMAPDATA->m_bitmapMask ) if ( M_BITMAPDATA->m_bitmapMask )
{ {
@@ -1063,15 +1066,18 @@ wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const
unsigned char *destdata = (unsigned char * ) maskbuf.GetWriteBuf( maskbufsize ) ; unsigned char *destdata = (unsigned char * ) maskbuf.GetWriteBuf( maskbufsize ) ;
wxASSERT( (source != NULL) && (destdata != NULL) ) ; wxASSERT( (source != NULL) && (destdata != NULL) ) ;
source += rect.x * kMaskBytesPerPixel + rect.y * sourcelinesize ; if ( (source != NULL) && (destdata != NULL) )
unsigned char *dest = destdata ;
for (int yy = 0; yy < destheight; ++yy, source += sourcelinesize , dest += destlinesize)
{ {
memcpy( dest , source , destlinesize ) ; source += rect.x * kMaskBytesPerPixel + rect.y * sourcelinesize ;
} unsigned char *dest = destdata ;
maskbuf.UngetWriteBuf( maskbufsize ) ; for (int yy = 0; yy < destheight; ++yy, source += sourcelinesize , dest += destlinesize)
{
memcpy( dest , source , destlinesize ) ;
}
maskbuf.UngetWriteBuf( maskbufsize ) ;
}
ret.SetMask( new wxMask( maskbuf , destwidth , destheight , rowBytes ) ) ; ret.SetMask( new wxMask( maskbuf , destwidth , destheight , rowBytes ) ) ;
} }
else if ( HasAlpha() ) else if ( HasAlpha() )
@@ -1607,31 +1613,32 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
size_t size = m_bytesPerRow * m_height ; size_t size = m_bytesPerRow * m_height ;
unsigned char * destdatabase = (unsigned char*) m_memBuf.GetWriteBuf( size ) ; unsigned char * destdatabase = (unsigned char*) m_memBuf.GetWriteBuf( size ) ;
wxASSERT( destdatabase != NULL ) ; wxASSERT( destdatabase != NULL ) ;
if ( destdatabase != NULL)
memset( destdatabase , 0 , size ) ;
unsigned char * srcdatabase = (unsigned char*) bitmap.GetRawAccess() ;
size_t sourceBytesRow = bitmap.GetBitmapData()->GetBytesPerRow();
for ( int y = 0 ; y < m_height ; ++y , srcdatabase+= sourceBytesRow, destdatabase += m_bytesPerRow)
{ {
unsigned char *srcdata = srcdatabase ; memset( destdatabase , 0 , size ) ;
unsigned char *destdata = destdatabase ; unsigned char * srcdatabase = (unsigned char*) bitmap.GetRawAccess() ;
unsigned char r, g, b; size_t sourceBytesRow = bitmap.GetBitmapData()->GetBytesPerRow();
for ( int x = 0 ; x < m_width ; ++x ) for ( int y = 0 ; y < m_height ; ++y , srcdatabase+= sourceBytesRow, destdatabase += m_bytesPerRow)
{ {
srcdata++ ; unsigned char *srcdata = srcdatabase ;
r = *srcdata++ ; unsigned char *destdata = destdatabase ;
g = *srcdata++ ; unsigned char r, g, b;
b = *srcdata++ ;
if ( colour == wxColour( r , g , b ) ) for ( int x = 0 ; x < m_width ; ++x )
*destdata++ = 0xFF ; {
else srcdata++ ;
*destdata++ = 0x00 ; r = *srcdata++ ;
g = *srcdata++ ;
b = *srcdata++ ;
if ( colour == wxColour( r , g , b ) )
*destdata++ = 0xFF ;
else
*destdata++ = 0x00 ;
}
} }
} }
m_memBuf.UngetWriteBuf( size ) ; m_memBuf.UngetWriteBuf( size ) ;
RealizeNative() ; RealizeNative() ;