+ if ( m_maskBitmap )
+ {
+ wxMacDestroyGWorld( m_maskBitmap ) ;
+ m_maskBitmap = NULL ;
+ }
+ wxASSERT( ((wxBitmapRefData*) bitmap.GetRefData())->m_bitmapType == kMacBitmapTypeGrafWorld ) ;
+ // other types would require a temporary bitmap. not yet implemented
+
+ if (!bitmap.Ok())
+ {
+ return FALSE;
+ }
+
+ m_maskBitmap = wxMacCreateGWorld( bitmap.GetWidth() , bitmap.GetHeight() , 1 ) ;
+ LockPixels( GetGWorldPixMap( (CGrafPtr) m_maskBitmap ) ) ;
+ LockPixels( GetGWorldPixMap( (CGrafPtr) ((wxBitmapRefData*) bitmap.GetRefData())->m_hBitmap ) ) ;
+ RGBColor maskColor = colour.GetPixel() ;
+
+ // this is not very efficient, but I can't think
+ // of a better way of doing it
+ CGrafPtr origPort ;
+ GDHandle origDevice ;
+
+ GetGWorld( &origPort , &origDevice ) ;
+ for (int w = 0; w < bitmap.GetWidth(); w++)
+ {
+ for (int h = 0; h < bitmap.GetHeight(); h++)
+ {
+ RGBColor colors[2] = {
+ { 0xFFFF , 0xFFFF , 0xFFFF } ,
+ { 0, 0 , 0 }
+ } ;
+
+ SetGWorld( ((wxBitmapRefData*) bitmap.GetRefData())->m_hBitmap , NULL ) ;
+ RGBColor col ;
+ GetCPixel( w , h , &col ) ;
+ SetGWorld( m_maskBitmap , NULL ) ;
+ if (col.red == maskColor.red && col.blue == maskColor.blue && col.green == maskColor.green)
+ {
+ SetCPixel( w , h , &colors[0] ) ;
+ }
+ else
+ {
+ SetCPixel( w , h , &colors[1] ) ;
+ }
+ }
+ }
+ UnlockPixels( GetGWorldPixMap( (CGrafPtr) m_maskBitmap ) ) ;
+ UnlockPixels( GetGWorldPixMap( ((wxBitmapRefData*) bitmap.GetRefData())->m_hBitmap ) ) ;
+ SetGWorld( origPort , origDevice ) ;
+
+ return TRUE;