supporting a null cgimage so that we don't get exceptions, only an wxbitmap that is !Ok()
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66761 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -291,35 +291,38 @@ wxBitmapRefData::wxBitmapRefData(CGImageRef image)
|
|||||||
|
|
||||||
bool wxBitmapRefData::Create(CGImageRef image)
|
bool wxBitmapRefData::Create(CGImageRef image)
|
||||||
{
|
{
|
||||||
m_width = CGImageGetWidth(image);
|
if ( image != NULL )
|
||||||
m_height = CGImageGetHeight(image);
|
|
||||||
m_depth = 32;
|
|
||||||
m_hBitmap = NULL;
|
|
||||||
|
|
||||||
m_bytesPerRow = GetBestBytesPerRow( m_width * 4 ) ;
|
|
||||||
size_t size = m_bytesPerRow * m_height ;
|
|
||||||
void* data = m_memBuf.GetWriteBuf( size ) ;
|
|
||||||
if ( data != NULL )
|
|
||||||
{
|
{
|
||||||
memset( data , 0 , size ) ;
|
m_width = CGImageGetWidth(image);
|
||||||
m_memBuf.UngetWriteBuf( size ) ;
|
m_height = CGImageGetHeight(image);
|
||||||
CGImageAlphaInfo alpha = CGImageGetAlphaInfo(image);
|
m_depth = 32;
|
||||||
if ( alpha == kCGImageAlphaNone || alpha == kCGImageAlphaNoneSkipLast || alpha == kCGImageAlphaNoneSkipLast )
|
m_hBitmap = NULL;
|
||||||
{
|
|
||||||
m_hBitmap = CGBitmapContextCreate((char*) data, m_width, m_height, 8, m_bytesPerRow, wxMacGetGenericRGBColorSpace(), kCGImageAlphaNoneSkipFirst );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_hasAlpha = true;
|
|
||||||
m_hBitmap = CGBitmapContextCreate((char*) data, m_width, m_height, 8, m_bytesPerRow, wxMacGetGenericRGBColorSpace(), kCGImageAlphaPremultipliedFirst );
|
|
||||||
}
|
|
||||||
CGRect rect = {{0,0},{m_width,m_height}};
|
|
||||||
CGContextDrawImage(m_hBitmap, rect, image);
|
|
||||||
|
|
||||||
wxASSERT_MSG( m_hBitmap , wxT("Unable to create CGBitmapContext context") ) ;
|
m_bytesPerRow = GetBestBytesPerRow( m_width * 4 ) ;
|
||||||
CGContextTranslateCTM( m_hBitmap, 0, m_height );
|
size_t size = m_bytesPerRow * m_height ;
|
||||||
CGContextScaleCTM( m_hBitmap, 1, -1 );
|
void* data = m_memBuf.GetWriteBuf( size ) ;
|
||||||
} /* data != NULL */
|
if ( data != NULL )
|
||||||
|
{
|
||||||
|
memset( data , 0 , size ) ;
|
||||||
|
m_memBuf.UngetWriteBuf( size ) ;
|
||||||
|
CGImageAlphaInfo alpha = CGImageGetAlphaInfo(image);
|
||||||
|
if ( alpha == kCGImageAlphaNone || alpha == kCGImageAlphaNoneSkipLast || alpha == kCGImageAlphaNoneSkipLast )
|
||||||
|
{
|
||||||
|
m_hBitmap = CGBitmapContextCreate((char*) data, m_width, m_height, 8, m_bytesPerRow, wxMacGetGenericRGBColorSpace(), kCGImageAlphaNoneSkipFirst );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_hasAlpha = true;
|
||||||
|
m_hBitmap = CGBitmapContextCreate((char*) data, m_width, m_height, 8, m_bytesPerRow, wxMacGetGenericRGBColorSpace(), kCGImageAlphaPremultipliedFirst );
|
||||||
|
}
|
||||||
|
CGRect rect = {{0,0},{m_width,m_height}};
|
||||||
|
CGContextDrawImage(m_hBitmap, rect, image);
|
||||||
|
|
||||||
|
wxASSERT_MSG( m_hBitmap , wxT("Unable to create CGBitmapContext context") ) ;
|
||||||
|
CGContextTranslateCTM( m_hBitmap, 0, m_height );
|
||||||
|
CGContextScaleCTM( m_hBitmap, 1, -1 );
|
||||||
|
} /* data != NULL */
|
||||||
|
}
|
||||||
m_ok = ( m_hBitmap != NULL ) ;
|
m_ok = ( m_hBitmap != NULL ) ;
|
||||||
|
|
||||||
return m_ok ;
|
return m_ok ;
|
||||||
|
|||||||
Reference in New Issue
Block a user