]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/bitmap.cpp
correct hhp2cached path
[wxWidgets.git] / src / mac / carbon / bitmap.cpp
index 22ed227e5e082afb5c4e1826bc8b1820b81b228f..19334a0f7c88909ce1efc6fbdc03509a30680821 100644 (file)
@@ -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 ;
@@ -563,8 +565,9 @@ IconRef wxBitmapRefData::GetIconRef()
         HLock((Handle) iconFamily);
         OSStatus err = GetIconRefFromIconFamilyPtr( *iconFamily, GetHandleSize((Handle) iconFamily), &m_iconRef );
         HUnlock((Handle) iconFamily);
-        wxASSERT_MSG( err == noErr , wxT("Error when constructing icon ref") );
         DisposeHandle( (Handle) iconFamily ) ;
+
+        wxCHECK_MSG( err == noErr, NULL, wxT("Error when constructing icon ref") );
     }
 
     return m_iconRef ;
@@ -881,51 +884,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);
+
+            unsigned char* linestart = (unsigned char*) bits ;
+            unsigned char* destptr = (unsigned char*) BeginRawAccess() ;
 
-            for ( int x = 0 ; x < the_width ; ++x )
+            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 )
+                for ( int x = 0 ; x < the_width ; ++x )
                 {
-                    *destination++ = 0xFF ;
-                    *destination++ = 0 ;
-                    *destination++ = 0 ;
-                    *destination++ = 0 ;
-                }
-                else
-                {
-                    *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 +1135,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