[PATCH] user32: Create a mask from alpha channel when loading a 32 bpp icon. (v2)

Dmitry Timoshkov dmitry at baikal.ru
Fri Jul 20 03:38:36 CDT 2018


This patch fixes an application that draws 32 bpp icons manually.

Signed-off-by: Dmitry Timoshkov <dmitry at baikal.ru>
---
 dlls/user32/cursoricon.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/dlls/user32/cursoricon.c b/dlls/user32/cursoricon.c
index 0adb73bf56..62576a341a 100644
--- a/dlls/user32/cursoricon.c
+++ b/dlls/user32/cursoricon.c
@@ -1296,6 +1296,36 @@ static HICON create_icon_from_bmi( const BITMAPINFO *bmi, DWORD maxsize, HMODULE
                        0, 0, bmi_width, bmi_height,
                        mask_bits, bmi_copy, DIB_RGB_COLORS, SRCCOPY );
     }
+    else
+    {
+        if (bmi_has_alpha( bmi, color_bits ))
+        {
+            unsigned char *alpha_mask_bits = HeapAlloc( GetProcessHeap(), 0, bmi_width * bmi_height * 4 );
+            if (alpha_mask_bits)
+            {
+                const unsigned char *src;
+                unsigned char *dst;
+                LONG i;
+
+                for (i = 0, src = color_bits, dst = alpha_mask_bits; i < bmi_width * bmi_height; i++, src += 4, dst += 4)
+                {
+                    if (src[3] == 0xff)
+                        dst[0] = dst[1] = dst[2] = 0;
+                    else
+                        dst[0] = dst[1] = dst[2] = 0xff;
+
+                    dst[3] = 0;
+                }
+
+                SelectObject( hdc, mask );
+                StretchDIBits( hdc, 0, 0, width, height,
+                               0, 0, bmi_width, bmi_height,
+                               alpha_mask_bits, bmi, DIB_RGB_COLORS, SRCCOPY );
+
+                HeapFree( GetProcessHeap(), 0, alpha_mask_bits );
+            }
+        }
+    }
     ret = TRUE;
 
 done:
-- 
2.17.1




More information about the wine-devel mailing list