]> git.saurik.com Git - wxWidgets.git/commitdiff
better mask handling in wxBitmap to wxImage conversion (patch 754881)
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 18 Jun 2003 00:41:37 +0000 (00:41 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 18 Jun 2003 00:41:37 +0000 (00:41 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21219 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/msw/bitmap.cpp

index dd6423fff72696176bd3e717ae3b81adafac0fad..af64aeb6f93f1af2993911b0a595a1fe8216cae5 100644 (file)
@@ -827,6 +827,13 @@ bool wxBitmap::CreateFromImage(const wxImage& image, int depth, WXHDC hdc )
 
 wxImage wxBitmap::ConvertToImage() const
 {
+    // the colour used as transparent one in wxImage and the one it is replaced
+    // with when it really occurs in the bitmap
+    static const int MASK_RED = 1;
+    static const int MASK_GREEN = 2;
+    static const int MASK_BLUE = 3;
+    static const int MASK_BLUE_REPLACEMENT = 2;
+
     wxImage image;
 
     wxCHECK_MSG( Ok(), wxNullImage, wxT("invalid bitmap") );
@@ -918,27 +925,39 @@ wxImage wxBitmap::ConvertToImage() const
         ::SetBkColor( memdc, RGB( 255, 255, 255 ) );
         ::GetDIBits( memdc, hbitmap, 0, height, lpBits, lpDIBh, DIB_RGB_COLORS );
         ::DeleteDC( memdc );
-        // background color set to RGB(16,16,16) in consistent with wxGTK
-        unsigned char r=16, g=16, b=16;
+        // background color set to mask colour
+        unsigned char r=MASK_RED, g=MASK_GREEN, b=MASK_BLUE;
         ptdata = data;
         ptbits = lpBits;
         for( i=0; i<height; i++ )
         {
             for( j=0; j<width; j++ )
             {
-                if( *ptbits != 0 )
+                // is this pixel transparent?
+                if ( *ptbits != 0 )
+                {
+                    if ( (ptdata[0] == MASK_RED) &&
+                            (ptdata[1] == MASK_GREEN) &&
+                                (ptdata[2] == MASK_BLUE) )
+                    {
+                        // we have to fudge the colour a bit to prevent this
+                        // pixel from appearing transparent
+                        ptdata[2] = MASK_BLUE_REPLACEMENT;
+                    }
                     ptdata += 3;
-                else
+                }
+                else // masked pixel
                 {
-                    *(ptdata++)  = r;
-                    *(ptdata++)  = g;
-                    *(ptdata++)  = b;
+                    *(ptdata++)  = MASK_RED;
+                    *(ptdata++)  = MASK_GREEN;
+                    *(ptdata++)  = MASK_BLUE;
                 }
                 ptbits += 3;
             }
             ptbits += padding;
         }
-        image.SetMaskColour( r, g, b );
+
+        image.SetMaskColour( MASK_RED, MASK_GREEN, MASK_BLUE );
         image.SetMask( TRUE );
     }
     else