expand tabs
[platform/upstream/gstreamer.git] / gst-libs / gst / interfaces / colorbalance.c
1 /* GStreamer Color Balance
2  * Copyright (C) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
3  *
4  * colorbalance.c: image color balance interface design
5  *                 virtual class function wrappers
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include "colorbalance.h"
28 #include "interfaces-marshal.h"
29
30 enum
31 {
32   VALUE_CHANGED,
33   LAST_SIGNAL
34 };
35
36 static void gst_color_balance_class_init (GstColorBalanceClass * klass);
37
38 static guint gst_color_balance_signals[LAST_SIGNAL] = { 0 };
39
40 GType
41 gst_color_balance_get_type (void)
42 {
43   static GType gst_color_balance_type = 0;
44
45   if (!gst_color_balance_type) {
46     static const GTypeInfo gst_color_balance_info = {
47       sizeof (GstColorBalanceClass),
48       (GBaseInitFunc) gst_color_balance_class_init,
49       NULL,
50       NULL,
51       NULL,
52       NULL,
53       0,
54       0,
55       NULL,
56     };
57
58     gst_color_balance_type = g_type_register_static (G_TYPE_INTERFACE,
59         "GstColorBalance", &gst_color_balance_info, 0);
60     g_type_interface_add_prerequisite (gst_color_balance_type,
61         GST_TYPE_IMPLEMENTS_INTERFACE);
62   }
63
64   return gst_color_balance_type;
65 }
66
67 static void
68 gst_color_balance_class_init (GstColorBalanceClass * klass)
69 {
70   static gboolean initialized = FALSE;
71
72   if (!initialized) {
73     gst_color_balance_signals[VALUE_CHANGED] =
74         g_signal_new ("value-changed",
75         GST_TYPE_COLOR_BALANCE, G_SIGNAL_RUN_LAST,
76         G_STRUCT_OFFSET (GstColorBalanceClass, value_changed),
77         NULL, NULL,
78         gst_interfaces_marshal_VOID__OBJECT_INT,
79         G_TYPE_NONE, 2, GST_TYPE_COLOR_BALANCE_CHANNEL, G_TYPE_INT);
80
81     initialized = TRUE;
82   }
83
84   klass->balance_type = GST_COLOR_BALANCE_SOFTWARE;
85
86   /* default virtual functions */
87   klass->list_channels = NULL;
88   klass->set_value = NULL;
89   klass->get_value = NULL;
90 }
91
92 const GList *
93 gst_color_balance_list_channels (GstColorBalance * balance)
94 {
95   GstColorBalanceClass *klass = GST_COLOR_BALANCE_GET_CLASS (balance);
96
97   if (klass->list_channels) {
98     return klass->list_channels (balance);
99   }
100
101   return NULL;
102 }
103
104 void
105 gst_color_balance_set_value (GstColorBalance * balance,
106     GstColorBalanceChannel * channel, gint value)
107 {
108   GstColorBalanceClass *klass = GST_COLOR_BALANCE_GET_CLASS (balance);
109
110   if (klass->set_value) {
111     klass->set_value (balance, channel, value);
112   }
113 }
114
115 gint
116 gst_color_balance_get_value (GstColorBalance * balance,
117     GstColorBalanceChannel * channel)
118 {
119   GstColorBalanceClass *klass = GST_COLOR_BALANCE_GET_CLASS (balance);
120
121   if (klass->get_value) {
122     return klass->get_value (balance, channel);
123   }
124
125   return channel->min_value;
126 }
127
128 void
129 gst_color_balance_value_changed (GstColorBalance * balance,
130     GstColorBalanceChannel * channel, gint value)
131 {
132   g_signal_emit (G_OBJECT (balance),
133       gst_color_balance_signals[VALUE_CHANGED], 0, channel, value);
134
135   g_signal_emit_by_name (G_OBJECT (channel), "value_changed", value);
136 }