[PATCH] Added icon alpha blend support functions

Joel Holdsworth joel at airwebreathe.org.uk
Sun May 31 11:00:17 CDT 2009


---
 dlls/user32/cursoricon.c |   68 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 68 insertions(+), 0 deletions(-)

diff --git a/dlls/user32/cursoricon.c b/dlls/user32/cursoricon.c
index 707d2bb..3cdd623 100644
--- a/dlls/user32/cursoricon.c
+++ b/dlls/user32/cursoricon.c
@@ -1598,6 +1598,74 @@ BOOL WINAPI DestroyCursor( HCURSOR hCursor )
     return DestroyIcon32(HCURSOR_16(hCursor), CID_WIN32);
 }
 
+/***********************************************************************
+ *      bitmap_has_alpha_channel
+ *
+ * Analyses bits bitmap to determine if alpha data is present.
+ *
+ * PARAMS
+ *      bpp          [I] The bits-per-pixel of the bitmap
+ *      bitmapBits   [I] A pointer to the bitmap data
+ *      bitmapLength [I] The length of the bitmap in bytes
+ *
+ * RETURNS
+ *      TRUE if an alpha channel is discovered, FALSE
+ *
+ * NOTE
+ *      Windows' behaviour is that if the icon bitmap is 32-bit and at
+ *      least one pixel has a non-zero alpha, then the bitmap is a
+ *      treated as having an alpha channel transparentcy. Otherwise,
+ *      it's treated as being completely opaque.
+ *
+ */
+static BOOL bitmap_has_alpha_channel( int bpp, unsigned char *bitmapBits,
+                                      unsigned int bitmapLength )
+{
+    /* Detect an alpha channel by looking for non-zero alpha pixels */
+    if(bpp == 32)
+    {
+        unsigned int offset;
+        for(offset = 3; offset < bitmapLength; offset += 4)
+        {
+            if(bitmapBits[offset] != 0)
+            {
+                return TRUE;
+                break;
+            }
+        }
+    }
+    return FALSE;
+}
+
+/***********************************************************************
+ *          premultiply_alpha_channel
+ *
+ * Premultiplies the color channels of a 32-bit bitmap by the alpha
+ * channel. This is a necessary step that must be carried out on
+ * the image before it is passed to GdiAlphaBlend
+ *
+ * PARAMS
+ *      destBitmap   [I] The destination bitmap buffer
+ *      srcBitmap    [I] The source bitmap buffer
+ *      bitmapLength [I] The length of the bitmap in bytes
+ *
+ */
+static void premultiply_alpha_channel( unsigned char *destBitmap,
+                                       unsigned char *srcBitmap,
+                                       unsigned int bitmapLength )
+{
+    unsigned char *destPixel = destBitmap;
+    unsigned char *srcPixel = srcBitmap;
+
+    while(destPixel < destBitmap + bitmapLength)
+    {
+        unsigned char alpha = srcPixel[3];
+        *(destPixel++) = *(srcPixel++) * alpha / 255;
+        *(destPixel++) = *(srcPixel++) * alpha / 255;
+        *(destPixel++) = *(srcPixel++) * alpha / 255;
+        *(destPixel++) = *(srcPixel++);
+    }
+}
 
 /***********************************************************************
  *		DrawIcon (USER32.@)
-- 
1.6.0.4


--=-BZQCtUG7Nz/qsg8UfIfN
Content-Disposition: attachment; filename="0003-Added-DrawIcon-alpha-blending-support.patch"
Content-Type: text/x-patch; name="0003-Added-DrawIcon-alpha-blending-support.patch"; charset="UTF-8"
Content-Transfer-Encoding: 7bit



More information about the wine-devel mailing list