]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/bitmap.cpp
Enable variadic macros for VC9 and later.
[wxWidgets.git] / src / msw / bitmap.cpp
index 10756fee7ca3cbb1e2bd3bb850efac72e281a58e..98c813fd9d6a25a3344c4df9c32a6f626f9def3f 100644 (file)
@@ -342,8 +342,9 @@ bool wxBitmap::CopyFromIconOrCursor(const wxGDIImage& icon,
                     wxDIB dib(iconInfo.hbmColor);
                     if (dib.IsOk())
                     {
-                        const unsigned char* pixels = dib.GetData();
-                        for (int idx = 0; idx < w*h*4; idx+=4)
+                        unsigned char* const pixels = dib.GetData();
+                        int idx;
+                        for ( idx = 0; idx < w*h*4; idx += 4 )
                         {
                             if (pixels[idx+3] != 0)
                             {
@@ -353,6 +354,25 @@ bool wxBitmap::CopyFromIconOrCursor(const wxGDIImage& icon,
                                 break;
                             }
                         }
+
+                        if ( refData->m_hasAlpha )
+                        {
+                            // If we do have alpha, ensure we use premultiplied
+                            // data for our pixels as this is what the bitmaps
+                            // created in other ways do and this is necessary
+                            // for e.g. AlphaBlend() to work with this bitmap.
+                            for ( idx = 0; idx < w*h*4; idx += 4 )
+                            {
+                                const unsigned char a = pixels[idx+3];
+
+                                pixels[idx]   = ((pixels[idx]  *a) + 127)/255;
+                                pixels[idx+1] = ((pixels[idx+1]*a) + 127)/255;
+                                pixels[idx+2] = ((pixels[idx+2]*a) + 127)/255;
+                            }
+
+                            ::DeleteObject(refData->m_hBitmap);
+                            refData->m_hBitmap = dib.Detach();
+                        }
                     }
                 }
             }