--- eclipse/workspace/gst-plugins-good/gst/alpha/gstalphacolor.c	2007-04-17 13:04:29.000000000 +0200
+++ programming/gst-plugins-good-0.10.5/gst/alpha/mygstalphacolor.c	2007-04-18 11:44:48.000000000 +0200
@@ -49,7 +49,8 @@
 
   /* caps */
   gint in_width, in_height;
-  gboolean in_rgba;
+  gboolean in_rgb;
+  gint depth;
   gint out_width, out_height;
 };
 
@@ -69,7 +70,7 @@
     GST_STATIC_PAD_TEMPLATE ("sink",
     GST_PAD_SINK,
     GST_PAD_ALWAYS,
-    GST_STATIC_CAPS (GST_VIDEO_CAPS_RGBA ";" GST_VIDEO_CAPS_BGRA ";" GST_VIDEO_CAPS_RGB)
+    GST_STATIC_CAPS (GST_VIDEO_CAPS_RGBA ";" GST_VIDEO_CAPS_BGRA ";" GST_VIDEO_CAPS_RGB ";" GST_VIDEO_CAPS_BGR)
     );
 
 static GstStaticPadTemplate gst_alpha_color_src_template =
@@ -194,7 +195,7 @@
   gboolean ret;
   const GValue *fps;
   gint red_mask;
-  gint depth;
+  gint depth = 0;
 
   alpha = GST_ALPHA_COLOR (btrans);
   structure = gst_caps_get_structure (incaps, 0);
@@ -205,19 +206,21 @@
   fps = gst_structure_get_value (structure, "framerate");
   ret &= (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
   ret &= gst_structure_get_int (structure, "red_mask", &red_mask);
+  
 
-  g_print("Depth is: %d\n", depth);
+  GST_DEBUG("Input depth is: %d", depth);
 
   if (!ret)
     return FALSE;
 
-  alpha->in_rgba = TRUE;
+  alpha->depth = depth;
+  alpha->in_rgb = TRUE;
 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
   if (red_mask != 0x000000ff)
 #else
   if (red_mask != 0x00ff0000)
 #endif
-    alpha->in_rgba = FALSE;
+    alpha->in_rgb = FALSE;
 
   return TRUE;
 }
@@ -242,7 +245,7 @@
   }
 }
 
-/*static void
+static void
 transform_bgra (guint8 * data, gint size)
 {
   guint8 y, u, v;
@@ -257,15 +260,14 @@
     data[2] = u;
     data[3] = v;
 
-    data += -4;
+    data += 4;
     size -= 4;
   }
-}*/
+}
 
 static guint8*
 transform_rgb (guint8 * data, gint size)
 {
-
   gint old_size = size;
   gint new_size = size + size/3;
 
@@ -273,8 +275,8 @@
 
   old_size -= 3;
   new_size -= 4;
-  
-  while(old_size >= 0)
+
+  while(old_size > 0)
   {
     guint8 *from_loc = &data[old_size];
     guint8 *to_loc = &data1[new_size];
@@ -289,7 +291,34 @@
     new_size -= 4;
   }
 
-  g_free(data);
+  return data1;
+}
+
+static guint8*
+transform_bgr (guint8 * data, gint size)
+{
+  gint old_size = size;
+  gint new_size = size + size/3;
+
+  guint8 * data1 = g_malloc(new_size);
+
+  old_size -= 3;
+  new_size -= 4;
+
+  while(old_size > 0)
+  {
+    guint8 *from_loc = &data[old_size];
+    guint8 *to_loc = &data1[new_size];
+
+    to_loc[1] = from_loc[2] * 0.299 + from_loc[1] * 0.587 + from_loc[0] * 0.114 + 0;
+    to_loc[2] = from_loc[2] * -0.169 + from_loc[1] * -0.332 + from_loc[0] * 0.500 + 128;
+    to_loc[3] = from_loc[2] * 0.500 + from_loc[1] * -0.419 + from_loc[0] * -0.0813 + 128;
+    
+    to_loc[0] = 255;
+    
+    old_size -= 3;
+    new_size -= 4;
+  }
 
   return data1;
 }
@@ -304,11 +333,27 @@
   alpha = GST_ALPHA_COLOR (btrans);
 
   /* Transform in place */
-  if (alpha->in_rgba)
-    transform_rgba (GST_BUFFER_DATA (inbuf), GST_BUFFER_SIZE (inbuf));
-  else
-    //transform_bgra (GST_BUFFER_DATA (inbuf), GST_BUFFER_SIZE (inbuf));
-    transform_rgb (GST_BUFFER_DATA (inbuf), GST_BUFFER_SIZE (inbuf));
+  if(alpha->depth == 32){
+    if (alpha->in_rgb)
+      transform_rgba (GST_BUFFER_DATA (inbuf), GST_BUFFER_SIZE (inbuf));
+    else
+      transform_bgra (GST_BUFFER_DATA (inbuf), GST_BUFFER_SIZE (inbuf));
+  }else{
+
+    if (alpha->in_rgb){
+      guint8 *newdata = transform_rgb (GST_BUFFER_DATA (inbuf), GST_BUFFER_SIZE (inbuf));
+
+      inbuf->size = GST_BUFFER_SIZE (inbuf) + (GST_BUFFER_SIZE (inbuf)/3);
+      inbuf->data = newdata;
+
+    }else{
+      guint8 *newdata = transform_bgr (GST_BUFFER_DATA (inbuf), GST_BUFFER_SIZE (inbuf));
+
+      inbuf->size = GST_BUFFER_SIZE (inbuf) + (GST_BUFFER_SIZE (inbuf)/3);
+      inbuf->data = newdata;
+
+    }
+  }
 
   return ret;
 }
