Patches to make GDK draw RGB images to ARGB drawables



GDK does just fine sending ARGB images to ARGB drawables, but when you've 
got an RGB image it leaves the alpha bits unfullfilled.

Performance could (obviously) be improved by writing special code for this 
case, but I figured I'd just fix the general code.

Also, havoc added another hack to set the non-rgb bits in pixel values to 
1 but it was broken when depth was 32.  I fixed that as well.

I'll send the fixes for metacity under separate cover.

-keith

? changes
Index: gdk/gdkrgb.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkrgb.c,v
retrieving revision 1.57
diff -u -r1.57 gdkrgb.c
--- gdk/gdkrgb.c	6 Mar 2004 03:36:59 -0000	1.57
+++ gdk/gdkrgb.c	18 Jun 2004 22:45:17 -0000
@@ -798,6 +798,17 @@
   gdk_gc_set_background (gc, &color);
 }
 
+#define FullMask(depth) ((depth == 32) ? (guint32) ~0 : ((guint32) 1 << (depth)) - 1)
+
+static guint32
+gdk_rgb_info_alpha (GdkRgbInfo *image_info)
+{
+  return (~(image_info->visual->red_mask |
+	    image_info->visual->green_mask |
+	    image_info->visual->blue_mask) & 
+	  FullMask (image_info->visual->depth));
+}
+
 /**
  * gdk_rgb_find_color:
  * @colormap: a #GdkColormap
@@ -2065,6 +2076,7 @@
   gint b_right, b_left;
   gint bpp;
   guint32 pixel;
+  guint32 alpha = gdk_rgb_info_alpha (image_info);
   gint i;
 
   r_right = 8 - image_info->visual->red_prec;
@@ -2088,7 +2100,7 @@
 	  b = bp2[2];
 	  pixel = ((r >> r_right) << r_left) |
 	    ((g >> g_right) << g_left) |
-	    ((b >> b_right) << b_left);
+	    ((b >> b_right) << b_left) | alpha;
 	  for (i = 0; i < bpp; i++)
 	    {
 	      *obptr++ = pixel & 0xff;
@@ -2118,6 +2130,7 @@
   gint b_right, b_left, b_prec;
   gint bpp;
   guint32 pixel;
+  guint32 alpha = gdk_rgb_info_alpha (image_info);
   gint i;
   gint dith;
   gint r1, g1, b1;
@@ -2152,7 +2165,7 @@
 	  b1 = b + (dith >> b_prec);
 	  pixel = (((r1 - (r1 >> r_prec)) >> r_right) << r_left) |
 	    (((g1 - (g1 >> g_prec)) >> g_right) << g_left) |
-	    (((b1 - (b1 >> b_prec)) >> b_right) << b_left);
+	    (((b1 - (b1 >> b_prec)) >> b_right) << b_left) | alpha;
 	  for (i = 0; i < bpp; i++)
 	    {
 	      *obptr++ = pixel & 0xff;
@@ -2182,6 +2195,7 @@
   gint b_right, b_left;
   gint bpp;
   guint32 pixel;
+  guint32 alpha = gdk_rgb_info_alpha (image_info);
   gint shift, shift_init;
 
   r_right = 8 - image_info->visual->red_prec;
@@ -2206,7 +2220,7 @@
 	  b = bp2[2];
 	  pixel = ((r >> r_right) << r_left) |
 	    ((g >> g_right) << g_left) |
-	    ((b >> b_right) << b_left);
+	    ((b >> b_right) << b_left) | alpha;
 	  for (shift = shift_init; shift >= 0; shift -= 8)
 	    {
 	      *obptr++ = (pixel >> shift) & 0xff;
@@ -2235,6 +2249,7 @@
   gint b_right, b_left, b_prec;
   gint bpp;
   guint32 pixel;
+  guint32 alpha = gdk_rgb_info_alpha (image_info);
   gint shift, shift_init;
   gint dith;
   gint r1, g1, b1;
@@ -2270,7 +2285,7 @@
 	  b1 = b + (dith >> b_prec);
 	  pixel = (((r1 - (r1 >> r_prec)) >> r_right) << r_left) |
 	    (((g1 - (g1 >> g_prec)) >> g_right) << g_left) |
-	    (((b1 - (b1 >> b_prec)) >> b_right) << b_left);
+	    (((b1 - (b1 >> b_prec)) >> b_right) << b_left) | alpha;
 	  for (shift = shift_init; shift >= 0; shift -= 8)
 	    {
 	      *obptr++ = (pixel >> shift) & 0xff;
Index: gdk/x11/gdkcolor-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkcolor-x11.c,v
retrieving revision 1.57
diff -u -r1.57 gdkcolor-x11.c
--- gdk/x11/gdkcolor-x11.c	27 May 2004 20:46:58 -0000	1.57
+++ gdk/x11/gdkcolor-x11.c	18 Jun 2004 22:45:17 -0000
@@ -1129,8 +1129,8 @@
 	  /* If bits not used for color are used for something other than padding,
 	   * it's likely alpha, so we set them to 1s.
 	   */
-	  guint32 unused = ~ (visual->red_mask | visual->green_mask | visual->blue_mask |
-			      (((~(guint32)0)) << visual->depth));
+	  guint32 beyond = visual->depth >= 32 ? 0 : (((~(guint32)0)) << visual->depth);
+	  guint32 unused = ~ (visual->red_mask | visual->green_mask | visual->blue_mask | beyond);
 	  colors[i].pixel = (unused +
 			     ((colors[i].red >> (16 - visual->red_prec)) << visual->red_shift) +
 			     ((colors[i].green >> (16 - visual->green_prec)) << visual->green_shift) +

Attachment: pgpyFJcfXYQlK.pgp
Description: PGP signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]