+wxBitmap::wxBitmap(const wxImage& image, int depth)
+{
+ wxCHECK_RET( image.Ok(), wxT("invalid image") )
+ wxCHECK_RET( depth == -1, wxT("invalid bitmap depth") )
+
+ m_refData = new wxBitmapRefData();
+
+ if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this);
+
+ // width and height of the device-dependent bitmap
+ int width = image.GetWidth();
+ int height = image.GetHeight();
+
+ // Create picture
+
+ Create( width , height , 32 ) ;
+
+ CGrafPtr origPort ;
+ GDHandle origDevice ;
+
+ PixMapHandle pixMap = GetGWorldPixMap(GetHBITMAP()) ;
+ LockPixels( pixMap );
+
+ GetGWorld( &origPort , &origDevice ) ;
+ SetGWorld( GetHBITMAP() , NULL ) ;
+
+ // Render image
+ RGBColor colorRGB ;
+
+ register unsigned char* data = image.GetData();
+ char* destinationBase = GetPixBaseAddr( pixMap );
+ register unsigned char* destination = (unsigned char*) destinationBase ;
+ for (int y = 0; y < height; y++)
+ {
+ for (int x = 0; x < width; x++)
+ {
+ *destination++ = 0 ;
+ *destination++ = *data++ ;
+ *destination++ = *data++ ;
+ *destination++ = *data++ ;
+ }
+ destinationBase += ((**pixMap).rowBytes & 0x7fff);
+ destination = (unsigned char*) destinationBase ;
+ }
+ if ( image.HasMask() )
+ {
+ data = image.GetData();
+
+ wxColour maskcolor(image.GetMaskRed(), image.GetMaskGreen(), image.GetMaskBlue());
+ RGBColor white = { 0xffff, 0xffff, 0xffff };
+ RGBColor black = { 0 , 0 , 0 };
+ wxBitmap maskBitmap ;
+
+ maskBitmap.Create( width, height, 1);
+ LockPixels( GetGWorldPixMap(maskBitmap.GetHBITMAP()) );
+ SetGWorld(maskBitmap.GetHBITMAP(), NULL);
+
+ for (int y = 0; y < height; y++)
+ {
+ for (int x = 0; x < width; x++)
+ {
+ if ( data[0] == image.GetMaskRed() && data[1] == image.GetMaskGreen() && data[2] == image.GetMaskBlue() )
+ {
+ SetCPixel(x,y, &white);
+ }
+ else {
+ SetCPixel(x,y, &black);
+ }
+ data += 3 ;
+ }
+ } // for height
+ SetGWorld(GetHBITMAP(), NULL);
+ SetMask(new wxMask( maskBitmap ));
+ UnlockPixels( GetGWorldPixMap(maskBitmap.GetHBITMAP()) );
+ }
+
+ UnlockPixels( GetGWorldPixMap(GetHBITMAP()) );
+ SetGWorld( origPort, origDevice );
+}
+
+wxImage wxBitmap::ConvertToImage() const
+{
+ wxImage image;
+
+ wxCHECK_MSG( Ok(), wxNullImage, wxT("invalid bitmap") );
+
+ // create an wxImage object
+ int width = GetWidth();
+ int height = GetHeight();
+ image.Create( width, height );
+
+ unsigned char *data = image.GetData();
+
+ wxCHECK_MSG( data, wxNullImage, wxT("Could not allocate data for image") );
+
+ WXHBITMAP origPort;
+ GDHandle origDevice;
+ int index;
+ RGBColor color;
+ // background color set to RGB(16,16,16) in consistent with wxGTK
+ unsigned char mask_r=16, mask_g=16, mask_b=16;
+ SInt16 r,g,b;
+ wxMask *mask = GetMask();
+
+ GetGWorld( &origPort, &origDevice );
+ LockPixels(GetGWorldPixMap(GetHBITMAP()));
+ SetGWorld( GetHBITMAP(), NULL);
+
+ // Copy data into image
+ index = 0;
+ for (int yy = 0; yy < height; yy++)
+ {
+ for (int xx = 0; xx < width; xx++)
+ {
+ GetCPixel(xx,yy, &color);
+ r = ((color.red ) >> 8);
+ g = ((color.green ) >> 8);
+ b = ((color.blue ) >> 8);
+ data[index ] = r;
+ data[index + 1] = g;
+ data[index + 2] = b;
+ if (mask)
+ {
+ if (mask->PointMasked(xx,yy))
+ {
+ data[index ] = mask_r;
+ data[index + 1] = mask_g;
+ data[index + 2] = mask_b;
+ }
+ }
+ index += 3;
+ }
+ }
+ if (mask)
+ {
+ image.SetMaskColour( mask_r, mask_g, mask_b );
+ image.SetMask( true );
+ }
+
+ // Free resources
+ UnlockPixels(GetGWorldPixMap(GetHBITMAP()));
+ SetGWorld(origPort, origDevice);
+
+ return image;
+}
+
+
+bool wxBitmap::SaveFile(const wxString& filename, wxBitmapType type,
+ const wxPalette *palette) const