- Rect r ;
- GetPortBounds( image , &r ) ;
- LockPixels(GetGWorldPixMap(mask) ) ;
- CopyBits(GetPortBitMapForCopyBits(mask) ,
- &(**icon).iconBMap , &r , &r, srcCopy , nil ) ;
- CopyBits(GetPortBitMapForCopyBits(mask) ,
- &(**icon).iconMask , &r , &r, srcCopy , nil ) ;
- UnlockPixels(GetGWorldPixMap( mask ) ) ;
+ size_t imageSize = m_width * m_height * 4 ;
+ void * dataBuffer = m_memBuf.GetData() ;
+ int w = m_width ;
+ int h = m_height ;
+ CGImageAlphaInfo alphaInfo = kCGImageAlphaNoneSkipFirst ;
+ wxMemoryBuffer* membuf = NULL ;
+
+ if ( m_bitmapMask )
+ {
+ alphaInfo = kCGImageAlphaFirst ;
+ membuf = new wxMemoryBuffer( imageSize ) ;
+ memcpy( membuf->GetData() , dataBuffer , imageSize ) ;
+ unsigned char *sourcemaskstart = (unsigned char *) m_bitmapMask->GetRawAccess() ;
+ int maskrowbytes = m_bitmapMask->GetBytesPerRow() ;
+ unsigned char *destalpha = (unsigned char *) membuf->GetData() ;
+ for ( int y = 0 ; y < h ; ++y , sourcemaskstart += maskrowbytes)
+ {
+ unsigned char *sourcemask = sourcemaskstart ;
+ for ( int x = 0 ; x < w ; ++x , sourcemask += 4 , destalpha += 4 )
+ {
+ *destalpha = 0xFF - *sourcemask ;
+ }
+ }
+ }
+ else
+ {
+ if ( m_hasAlpha )
+ {
+#if wxMAC_USE_PREMULTIPLIED_ALPHA
+ alphaInfo = kCGImageAlphaPremultipliedFirst ;
+#else
+ alphaInfo = kCGImageAlphaFirst ;
+#endif
+ }
+
+ membuf = new wxMemoryBuffer( m_memBuf ) ;
+ }
+
+ CGDataProviderRef dataProvider = NULL ;
+ if ( m_depth == 1 )
+ {
+ wxMemoryBuffer* maskBuf = new wxMemoryBuffer( m_width * m_height );
+ unsigned char * maskBufData = (unsigned char *) maskBuf->GetData();
+ unsigned char * bufData = (unsigned char *) membuf->GetData() ;
+ // copy one color component
+ for( int i = 0 ; i < m_width * m_height ; ++i )
+ maskBufData[i] = bufData[i*4+3];
+ dataProvider =
+ CGDataProviderCreateWithData(
+ maskBuf , (const void *) maskBufData , m_width * m_height,
+ wxMacMemoryBufferReleaseProc );
+ // as we are now passing the mask buffer to the data provider, we have
+ // to release the membuf ourselves
+ delete membuf ;
+
+ image = ::CGImageMaskCreate( w, h, 8, 8, m_width , dataProvider, NULL, false );
+ }
+ else
+ {
+ CGColorSpaceRef colorSpace = wxMacGetGenericRGBColorSpace();
+ dataProvider =
+ CGDataProviderCreateWithData(
+ membuf , (const void *)membuf->GetData() , imageSize,
+ wxMacMemoryBufferReleaseProc );
+ image =
+ ::CGImageCreate(
+ w, h, 8 , 32 , 4 * m_width , colorSpace, alphaInfo ,
+ dataProvider, NULL , false , kCGRenderingIntentDefault );
+ }
+ CGDataProviderRelease( dataProvider);