From: Stefan Csomor Date: Wed, 27 Feb 2008 08:11:33 +0000 (+0000) Subject: applying patch 1873285 X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/0d0b1695e01f1572540e79cbb7bd360c1f2d5979 applying patch 1873285 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@52135 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/mac/carbon/bitmap.cpp b/src/mac/carbon/bitmap.cpp index 22ed227e5e..7fd7536644 100644 --- a/src/mac/carbon/bitmap.cpp +++ b/src/mac/carbon/bitmap.cpp @@ -272,19 +272,21 @@ bool wxBitmapRefData::Create( int w , int h , int d ) m_width = wxMax(1, w); m_height = wxMax(1, h); m_depth = d ; + m_hBitmap = NULL ; m_bytesPerRow = GetBestBytesPerRow( w * 4 ) ; size_t size = m_bytesPerRow * h ; void* data = m_memBuf.GetWriteBuf( size ) ; - memset( data , 0 , size ) ; - m_memBuf.UngetWriteBuf( size ) ; - - m_hBitmap = NULL ; - m_hBitmap = CGBitmapContextCreate((char*) data, m_width, m_height, 8, m_bytesPerRow, wxMacGetGenericRGBColorSpace(), kCGImageAlphaNoneSkipFirst ); - wxASSERT_MSG( m_hBitmap , wxT("Unable to create CGBitmapContext context") ) ; - CGContextTranslateCTM( m_hBitmap, 0, m_height ); - CGContextScaleCTM( m_hBitmap, 1, -1 ); - + if ( data != NULL ) + { + memset( data , 0 , size ) ; + m_memBuf.UngetWriteBuf( size ) ; + + m_hBitmap = CGBitmapContextCreate((char*) data, m_width, m_height, 8, m_bytesPerRow, wxMacGetGenericRGBColorSpace(), kCGImageAlphaNoneSkipFirst ); + 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 ; @@ -881,51 +883,56 @@ wxBitmap::~wxBitmap() wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits) { - m_refData = new wxBitmapRefData( the_width , the_height , no_bits ) ; - - if ( no_bits == 1 ) - { - int linesize = ( the_width / (sizeof(unsigned char) * 8)) ; - if ( the_width % (sizeof(unsigned char) * 8) ) - linesize += sizeof(unsigned char); + wxBitmapRefData* bitmapRefData; - unsigned char* linestart = (unsigned char*) bits ; - unsigned char* destptr = (unsigned char*) BeginRawAccess() ; + m_refData = bitmapRefData = new wxBitmapRefData( the_width , the_height , no_bits ) ; - for ( int y = 0 ; y < the_height ; ++y , linestart += linesize, destptr += M_BITMAPDATA->GetBytesPerRow() ) + if (bitmapRefData->IsOk()) + { + if ( no_bits == 1 ) { - unsigned char* destination = destptr; - int index, bit, mask; + int linesize = ( the_width / (sizeof(unsigned char) * 8)) ; + if ( the_width % (sizeof(unsigned char) * 8) ) + linesize += sizeof(unsigned char); - for ( int x = 0 ; x < the_width ; ++x ) + unsigned char* linestart = (unsigned char*) bits ; + unsigned char* destptr = (unsigned char*) BeginRawAccess() ; + + for ( int y = 0 ; y < the_height ; ++y , linestart += linesize, destptr += M_BITMAPDATA->GetBytesPerRow() ) { - index = x / 8 ; - bit = x % 8 ; - mask = 1 << bit ; + unsigned char* destination = destptr; + int index, bit, mask; - if ( linestart[index] & mask ) - { - *destination++ = 0xFF ; - *destination++ = 0 ; - *destination++ = 0 ; - *destination++ = 0 ; - } - else + for ( int x = 0 ; x < the_width ; ++x ) { - *destination++ = 0xFF ; - *destination++ = 0xFF ; - *destination++ = 0xFF ; - *destination++ = 0xFF ; + index = x / 8 ; + bit = x % 8 ; + mask = 1 << bit ; + + if ( linestart[index] & mask ) + { + *destination++ = 0xFF ; + *destination++ = 0 ; + *destination++ = 0 ; + *destination++ = 0 ; + } + else + { + *destination++ = 0xFF ; + *destination++ = 0xFF ; + *destination++ = 0xFF ; + *destination++ = 0xFF ; + } } } - } - EndRawAccess() ; - } - else - { - wxFAIL_MSG(wxT("multicolor BITMAPs not yet implemented")); - } + EndRawAccess() ; + } + else + { + wxFAIL_MSG(wxT("multicolor BITMAPs not yet implemented")); + } + } /* bitmapRefData->IsOk() */ } wxBitmap::wxBitmap(int w, int h, int d) @@ -1127,63 +1134,68 @@ wxBitmap::wxBitmap(const wxImage& image, int depth) int width = image.GetWidth(); int height = image.GetHeight(); - m_refData = new wxBitmapRefData( width , height , depth ) ; + wxBitmapRefData* bitmapRefData; + + m_refData = bitmapRefData = new wxBitmapRefData( width , height , depth ) ; - // Create picture + if ( bitmapRefData->IsOk()) + { + // Create picture - bool hasAlpha = false ; + bool hasAlpha = false ; - if ( image.HasMask() ) - { - // takes precedence, don't mix with alpha info - } - else - { - hasAlpha = image.HasAlpha() ; - } + if ( image.HasMask() ) + { + // takes precedence, don't mix with alpha info + } + else + { + hasAlpha = image.HasAlpha() ; + } - if ( hasAlpha ) - UseAlpha() ; + if ( hasAlpha ) + UseAlpha() ; - unsigned char* destinationstart = (unsigned char*) BeginRawAccess() ; - register unsigned char* data = image.GetData(); - if ( destinationstart != NULL && data != NULL ) - { - const unsigned char *alpha = hasAlpha ? image.GetAlpha() : NULL ; - for (int y = 0; y < height; destinationstart += M_BITMAPDATA->GetBytesPerRow(), y++) + unsigned char* destinationstart = (unsigned char*) BeginRawAccess() ; + register unsigned char* data = image.GetData(); + if ( destinationstart != NULL && data != NULL ) { - unsigned char * destination = destinationstart; - for (int x = 0; x < width; x++) + const unsigned char *alpha = hasAlpha ? image.GetAlpha() : NULL ; + for (int y = 0; y < height; destinationstart += M_BITMAPDATA->GetBytesPerRow(), y++) { - if ( hasAlpha ) + unsigned char * destination = destinationstart; + for (int x = 0; x < width; x++) { - const unsigned char a = *alpha++; - *destination++ = a ; - -#if wxMAC_USE_PREMULTIPLIED_ALPHA - *destination++ = ((*data++) * a + 127) / 255 ; - *destination++ = ((*data++) * a + 127) / 255 ; - *destination++ = ((*data++) * a + 127) / 255 ; -#else - *destination++ = *data++ ; - *destination++ = *data++ ; - *destination++ = *data++ ; -#endif - } - else - { - *destination++ = 0xFF ; - *destination++ = *data++ ; - *destination++ = *data++ ; - *destination++ = *data++ ; + if ( hasAlpha ) + { + const unsigned char a = *alpha++; + *destination++ = a ; + + #if wxMAC_USE_PREMULTIPLIED_ALPHA + *destination++ = ((*data++) * a + 127) / 255 ; + *destination++ = ((*data++) * a + 127) / 255 ; + *destination++ = ((*data++) * a + 127) / 255 ; + #else + *destination++ = *data++ ; + *destination++ = *data++ ; + *destination++ = *data++ ; + #endif + } + else + { + *destination++ = 0xFF ; + *destination++ = *data++ ; + *destination++ = *data++ ; + *destination++ = *data++ ; + } } } - } - EndRawAccess() ; - } - if ( image.HasMask() ) - SetMask( new wxMask( *this , wxColour( image.GetMaskRed() , image.GetMaskGreen() , image.GetMaskBlue() ) ) ) ; + EndRawAccess() ; + } + if ( image.HasMask() ) + SetMask( new wxMask( *this , wxColour( image.GetMaskRed() , image.GetMaskGreen() , image.GetMaskBlue() ) ) ) ; + } /* bitmapRefData->IsOk() */ } wxImage wxBitmap::ConvertToImage() const