X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/aaa7d63c519d50cec98b15c385b33e50b2f82c43..b236f090ed76944de442c06ff7d13e7cf87d9a16:/src/osx/core/bitmap.cpp diff --git a/src/osx/core/bitmap.cpp b/src/osx/core/bitmap.cpp index bb7903fac1..8ef77049d1 100644 --- a/src/osx/core/bitmap.cpp +++ b/src/osx/core/bitmap.cpp @@ -255,7 +255,7 @@ void wxBitmapRefData::Init() m_hasAlpha = false; } -wxBitmapRefData::wxBitmapRefData(const wxBitmapRefData &tocopy) +wxBitmapRefData::wxBitmapRefData(const wxBitmapRefData &tocopy) : wxGDIRefData() { Init(); Create(tocopy.m_width, tocopy.m_height, tocopy.m_depth); @@ -291,35 +291,38 @@ wxBitmapRefData::wxBitmapRefData(CGImageRef image) bool wxBitmapRefData::Create(CGImageRef image) { - m_width = CGImageGetWidth(image); - 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 ) + if ( image != 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); + m_width = CGImageGetWidth(image); + m_height = CGImageGetHeight(image); + m_depth = 32; + m_hBitmap = NULL; - wxASSERT_MSG( m_hBitmap , wxT("Unable to create CGBitmapContext context") ) ; - CGContextTranslateCTM( m_hBitmap, 0, m_height ); - CGContextScaleCTM( m_hBitmap, 1, -1 ); - } /* data != 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_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 ) ; return m_ok ; @@ -1011,6 +1014,11 @@ wxBitmap::wxBitmap(const wxString& filename, wxBitmapType type) LoadFile(filename, type); } +wxBitmap::wxBitmap(CGImageRef image) +{ + (void) Create(image); +} + wxGDIRefData* wxBitmap::CreateGDIRefData() const { return new wxBitmapRefData; @@ -1523,7 +1531,7 @@ wxMask::wxMask() Init() ; } -wxMask::wxMask(const wxMask &tocopy) +wxMask::wxMask(const wxMask &tocopy) : wxObject() { Init();