Index: ximagesrc.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins/sys/ximage/Attic/ximagesrc.c,v
retrieving revision 1.1.2.5
diff -u -r1.1.2.5 ximagesrc.c
--- ximagesrc.c	14 Jul 2005 19:43:52 -0000	1.1.2.5
+++ ximagesrc.c	19 Jul 2005 20:59:39 -0000
@@ -220,16 +220,72 @@
 /* ifdeff'ed to prevent warnings of not being used when xfixes not there */
 #ifdef HAVE_XFIXES
 static void
-composite_pixel (guchar * dest, guchar * src)
+composite_pixel (GstXContext *xcontext, guchar * dest, guchar * src)
 {
   guint8 r = src[2];
   guint8 g = src[1];
   guint8 b = src[0];
   guint8 a = src[3];
+  gint dr, dg, db;
+  guint32 color;
+  gint r_shift, r_max;
+  gint g_shift, g_max;
+  gint b_shift, b_max;
+  
+  switch (xcontext->bpp) {
+  case 8:
+    color = *dest;
+    break;
+  case 16:
+    color = GUINT16_FROM_LE (*(guint32 *)(dest));
+    break;
+  case 32:
+    color = GUINT32_FROM_LE (*(guint32 *)(dest));
+    break;
+  default:
+    g_warning ("bpp %d not supported\n", xcontext->bpp);
+    color = 0;
+  }
+
+  /* FIXME: move the code that finds shift and max in the _link function */
+  for (r_shift=0; !(xcontext->visual->red_mask & (1 << r_shift)); r_shift++);
+  for (g_shift=0; !(xcontext->visual->green_mask & (1 << g_shift)); g_shift++);
+  for (b_shift=0; !(xcontext->visual->blue_mask & (1 << b_shift)); b_shift++);
+  
+  r_max = (xcontext->visual->red_mask >> r_shift);
+  b_max = (xcontext->visual->blue_mask >> b_shift);
+  g_max = (xcontext->visual->green_mask >> g_shift);
+    
+#define RGBXXX_R(x)  (((x)>>r_shift) & (r_max))
+#define RGBXXX_G(x)  (((x)>>g_shift) & (g_max))
+#define RGBXXX_B(x)  (((x)>>b_shift) & (b_max))
+  
+  dr = (RGBXXX_R (color) * 255) / r_max;
+  dg = (RGBXXX_G (color) * 255) / g_max;
+  db = (RGBXXX_B (color) * 255) / b_max;
+
+  dr = (r * a + (0xff - a) * dr) / 0xff;
+  dg = (g * a + (0xff - a) * dg) / 0xff;
+  db = (b * a + (0xff - a) * db) / 0xff;
+  
+  color = (((dr * r_max)/255) << r_shift) +
+    (((dg * g_max)/255) << g_shift) + 
+    (((db * b_max)/255) << b_shift);
+    
+  switch (xcontext->bpp) {
+  case 8:
+    *dest = color;
+    break;
+  case 16:
+    * (guint16 *)(dest) = color;
+    break;
+  case 32:
+    * (guint32 *)(dest) = color;
+    break;
+  default:
+    g_warning ("bpp %d not supported\n", xcontext->bpp);
+  }
 
-  dest[0] = (b + (0xff - a) * dest[0]) / 0xff;
-  dest[1] = (g + (0xff - a) * dest[1]) / 0xff;
-  dest[2] = (r + (0xff - a) * dest[2]) / 0xff;
 }
 #endif
 
@@ -253,17 +309,23 @@
 
       cx = cursor_image->x - cursor_image->xhot;
       cy = cursor_image->y - cursor_image->yhot;
-      count = image->width * image->height;
+      //count = image->width * image->height;
+      count = cursor_image->width * cursor_image->height;
       for (i = 0; i < count; i++)
         cursor_image->pixels[i] = GUINT_TO_LE (cursor_image->pixels[i]);
 
       /* copy those pixels across */
       for (j = cy; j < cy + cursor_image->height; j++) {
         for (i = cx; i < cx + cursor_image->width; i++) {
-          composite_pixel ((guchar *) & (((guint32 *) image->ximage->data)[j *
-                      s->width + i]),
-              (guchar *) & (((guint32 *) cursor_image->pixels)[(j -
-                          cy) * cursor_image->width + (i - cx)]));
+	  guint8 *src, *dest;
+
+	  src = (guint8 *) & (cursor_image->pixels[((j - cy) * cursor_image->width + (i - cx))]);
+	  dest = (guint8 *) & (image->ximage->data[(j * s->width + i)*(s->xcontext->bpp / 8)]);
+	  
+          composite_pixel (s->xcontext,
+			   (guint8 *) dest,
+			   (guint8 *) src);
+			   
         }
       }
     }
