]> git.0d.be Git - empathy.git/commitdiff
Add support for changing various color channels of the video device
authorSjoerd Simons <sjoerd.simons@collabora.co.uk>
Tue, 3 Mar 2009 17:34:44 +0000 (17:34 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Tue, 3 Mar 2009 17:34:44 +0000 (17:34 +0000)
Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
svn path=/trunk/; revision=2562

libempathy-gtk/empathy-video-src.c
libempathy-gtk/empathy-video-src.h

index 8614b6b4361e2a8eb0e040f91887e5d7bdc3cdc4..d2d03026b407b21c663f19d7f3f295129b8cd884 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 
+#include <gst/interfaces/colorbalance.h>
+
 #include "empathy-video-src.h"
 
 G_DEFINE_TYPE(EmpathyGstVideoSrc, empathy_video_src, GST_TYPE_BIN)
 
+/* Keep in sync with EmpathyGstVideoSrcChannel */
+static gchar *channel_names[NR_EMPATHY_GST_VIDEO_SRC_CHANNELS] = { "contrast",
+  "brightness", "gamma" };
+
 /* signal enum */
 #if 0
 enum
@@ -43,6 +49,8 @@ struct _EmpathyGstVideoSrcPrivate
 {
   gboolean dispose_has_run;
   GstElement *src;
+  /* Element implementing a ColorBalance interface */
+  GstElement *balance;
 };
 
 #define EMPATHY_GST_VIDEO_SRC_GET_PRIVATE(o) \
@@ -131,3 +139,120 @@ empathy_video_src_new (void)
 {
   return GST_ELEMENT (g_object_new (EMPATHY_TYPE_GST_VIDEO_SRC, NULL));
 }
+
+void
+empathy_video_src_set_channel (GstElement *src,
+  EmpathyGstVideoSrcChannel channel, guint percent)
+{
+  GstElement *color;
+  GstColorBalance *balance;
+  const GList *channels;
+  GList *l;
+
+  /* Find something supporting GstColorBalance */
+  color = gst_bin_get_by_interface (GST_BIN (src), GST_TYPE_COLOR_BALANCE);
+
+  if (color == NULL)
+    return;
+
+  balance = GST_COLOR_BALANCE (color);
+
+  channels = gst_color_balance_list_channels (balance);
+
+  for (l = (GList *)channels; l != NULL; l = g_list_next (l))
+    {
+      GstColorBalanceChannel *c = GST_COLOR_BALANCE_CHANNEL (l->data);
+
+      if (g_ascii_strcasecmp (c->label, channel_names[channel]) == 0)
+        {
+          gst_color_balance_set_value (balance, c,
+            ((c->max_value - c->min_value) * percent)/100
+              + c->min_value);
+          break;
+        }
+    }
+
+  g_object_unref (color);
+}
+
+guint
+empathy_video_src_get_channel (GstElement *src,
+  EmpathyGstVideoSrcChannel channel)
+{
+  GstElement *color;
+  GstColorBalance *balance;
+  const GList *channels;
+  GList *l;
+  guint percent = 0;
+
+  /* Find something supporting GstColorBalance */
+  color = gst_bin_get_by_interface (GST_BIN (src), GST_TYPE_COLOR_BALANCE);
+
+  if (color == NULL)
+    return percent;
+
+  balance = GST_COLOR_BALANCE (color);
+
+  channels = gst_color_balance_list_channels (balance);
+
+  for (l = (GList *)channels; l != NULL; l = g_list_next (l))
+    {
+      GstColorBalanceChannel *c = GST_COLOR_BALANCE_CHANNEL (l->data);
+
+      if (g_ascii_strcasecmp (c->label, channel_names[channel]) == 0)
+        {
+          percent =
+            ((gst_color_balance_get_value (balance, c)
+                - c->min_value) * 100) /
+              (c->max_value - c->min_value);
+
+          break;
+        }
+    }
+
+  g_object_unref (color);
+
+  return percent;
+}
+
+
+guint
+empathy_video_src_get_supported_channels (GstElement *src)
+{
+  GstElement *color;
+  GstColorBalance *balance;
+  const GList *channels;
+  GList *l;
+  guint result = 0;
+
+  /* Find something supporting GstColorBalance */
+  color = gst_bin_get_by_interface (GST_BIN (src), GST_TYPE_COLOR_BALANCE);
+
+  if (color == NULL)
+    goto out;
+
+  balance = GST_COLOR_BALANCE (color);
+
+  channels = gst_color_balance_list_channels (balance);
+
+  for (l = (GList *)channels; l != NULL; l = g_list_next (l))
+    {
+      GstColorBalanceChannel *channel = GST_COLOR_BALANCE_CHANNEL (l->data);
+      int i;
+
+      for (i = 0; i < NR_EMPATHY_GST_VIDEO_SRC_CHANNELS; i++)
+        {
+          if (g_ascii_strcasecmp (channel->label, channel_names[i]) == 0)
+            {
+              result |= (1 << i);
+              break;
+            }
+        }
+    }
+
+  g_object_unref (color);
+
+out:
+  return result;
+}
+
index 48c41f45722c3c52f8135fefe0c0599d89fc08cf..fef0b84ddfc50fd5cdd07af42eea8060dcad7a23 100644 (file)
@@ -29,6 +29,20 @@ G_BEGIN_DECLS
 typedef struct _EmpathyGstVideoSrc EmpathyGstVideoSrc;
 typedef struct _EmpathyGstVideoSrcClass EmpathyGstVideoSrcClass;
 
+typedef enum {
+  EMPATHY_GST_VIDEO_SRC_CHANNEL_CONTRAST = 0,
+  EMPATHY_GST_VIDEO_SRC_CHANNEL_BRIGHTNESS = 1,
+  EMPATHY_GST_VIDEO_SRC_CHANNEL_GAMMA = 2,
+  NR_EMPATHY_GST_VIDEO_SRC_CHANNELS
+} EmpathyGstVideoSrcChannel;
+
+#define  EMPATHY_GST_VIDEO_SRC_SUPPORTS_CONTRAST \
+  (1 << EMPATHY_GST_VIDEO_SRC_CHANNEL_CONTRAST)
+#define  EMPATHY_GST_VIDEO_SRC_SUPPORTS_BRIGHTNESS \
+  (1 << EMPATHY_GST_VIDEO_SRC_CHANNEL_BRIGHTNESS)
+#define  EMPATHY_GST_VIDEO_SRC_SUPPORTS_GAMMA \
+  (1 << EMPATHY_GST_VIDEO_SRC_CHANNEL_GAMMA)
+
 struct _EmpathyGstVideoSrcClass {
     GstBinClass parent_class;
 };
@@ -58,6 +72,16 @@ GType empathy_video_src_get_type (void);
 
 GstElement *empathy_video_src_new (void);
 
+guint
+empathy_video_src_get_supported_channels (GstElement *src);
+
+void empathy_video_src_set_channel (GstElement *src,
+  EmpathyGstVideoSrcChannel channel, guint percent);
+
+guint empathy_video_src_get_channel (GstElement *src,
+  EmpathyGstVideoSrcChannel channel);
+
+
 G_END_DECLS
 
 #endif /* #ifndef __EMPATHY_GST_VIDEO_SRC_H__*/