tizen 2.0 init
[framework/multimedia/gst-plugins-base0.10.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 /**
31  * SECTION:gstcolorbalance
32  * @short_description: Interface for adjusting color balance settings
33  *
34  * <refsect2><para>
35  * This interface is implemented by elements which can perform some color
36  * balance operation on video frames they process. For example, modifying
37  * the brightness, contrast, hue or saturation.
38  * </para><para>
39  * Example elements are 'xvimagesink' and 'colorbalance'
40  * </para>
41  * </refsect2>
42  */
43
44 enum
45 {
46   VALUE_CHANGED,
47   LAST_SIGNAL
48 };
49
50 static void gst_color_balance_class_init (GstColorBalanceClass * klass);
51
52 static guint gst_color_balance_signals[LAST_SIGNAL] = { 0 };
53
54 GType
55 gst_color_balance_get_type (void)
56 {
57   static GType gst_color_balance_type = 0;
58
59   if (!gst_color_balance_type) {
60     static const GTypeInfo gst_color_balance_info = {
61       sizeof (GstColorBalanceClass),
62       (GBaseInitFunc) gst_color_balance_class_init,
63       NULL,
64       NULL,
65       NULL,
66       NULL,
67       0,
68       0,
69       NULL,
70     };
71
72     gst_color_balance_type = g_type_register_static (G_TYPE_INTERFACE,
73         "GstColorBalance", &gst_color_balance_info, 0);
74     g_type_interface_add_prerequisite (gst_color_balance_type,
75         GST_TYPE_IMPLEMENTS_INTERFACE);
76   }
77
78   return gst_color_balance_type;
79 }
80
81 static void
82 gst_color_balance_class_init (GstColorBalanceClass * klass)
83 {
84   static gboolean initialized = FALSE;
85
86   if (!initialized) {
87     /**
88      * GstColorBalance::value-changed:
89      * @colorbalance: The GstColorBalance instance
90      * @channel: The #GstColorBalanceChannel
91      * @value: The new value
92      *
93      * Fired when the value of the indicated channel has changed.
94      */
95     gst_color_balance_signals[VALUE_CHANGED] =
96         g_signal_new ("value-changed",
97         GST_TYPE_COLOR_BALANCE, G_SIGNAL_RUN_LAST,
98         G_STRUCT_OFFSET (GstColorBalanceClass, value_changed),
99         NULL, NULL,
100         gst_interfaces_marshal_VOID__OBJECT_INT,
101         G_TYPE_NONE, 2, GST_TYPE_COLOR_BALANCE_CHANNEL, G_TYPE_INT);
102
103     initialized = TRUE;
104   }
105
106   klass->balance_type = GST_COLOR_BALANCE_SOFTWARE;
107
108   /* default virtual functions */
109   klass->list_channels = NULL;
110   klass->set_value = NULL;
111   klass->get_value = NULL;
112 }
113
114 /**
115  * gst_color_balance_list_channels:
116  * @balance: A #GstColorBalance instance
117  * 
118  * Retrieve a list of the available channels.
119  *
120  * Returns: A GList containing pointers to #GstColorBalanceChannel objects.
121  *          The list is owned by the #GstColorBalance instance and must not
122  *          be freed.
123  */
124 const GList *
125 gst_color_balance_list_channels (GstColorBalance * balance)
126 {
127   GstColorBalanceClass *klass;
128
129   g_return_val_if_fail (GST_IS_COLOR_BALANCE (balance), NULL);
130
131   klass = GST_COLOR_BALANCE_GET_CLASS (balance);
132
133   if (klass->list_channels) {
134     return klass->list_channels (balance);
135   }
136
137   return NULL;
138 }
139
140 /**
141  * gst_color_balance_set_value:
142  * @balance: A #GstColorBalance instance
143  * @channel: A #GstColorBalanceChannel instance
144  * @value: The new value for the channel.
145  *
146  * Sets the current value of the channel to the passed value, which must
147  * be between min_value and max_value.
148  * 
149  * See Also: The #GstColorBalanceChannel.min_value and
150  *         #GstColorBalanceChannel.max_value members of the
151  *         #GstColorBalanceChannel object.
152  */
153 void
154 gst_color_balance_set_value (GstColorBalance * balance,
155     GstColorBalanceChannel * channel, gint value)
156 {
157   GstColorBalanceClass *klass = GST_COLOR_BALANCE_GET_CLASS (balance);
158
159   if (klass->set_value) {
160     klass->set_value (balance, channel, value);
161   }
162 }
163
164 /**
165  * gst_color_balance_get_value:
166  * @balance: A #GstColorBalance instance
167  * @channel: A #GstColorBalanceChannel instance
168  *
169  * Retrieve the current value of the indicated channel, between min_value
170  * and max_value.
171  * 
172  * See Also: The #GstColorBalanceChannel.min_value and
173  *         #GstColorBalanceChannel.max_value members of the
174  *         #GstColorBalanceChannel object.
175  * 
176  * Returns: The current value of the channel.
177  */
178 gint
179 gst_color_balance_get_value (GstColorBalance * balance,
180     GstColorBalanceChannel * channel)
181 {
182   GstColorBalanceClass *klass;
183
184   g_return_val_if_fail (GST_IS_COLOR_BALANCE (balance), 0);
185
186   klass = GST_COLOR_BALANCE_GET_CLASS (balance);
187
188   if (klass->get_value) {
189     return klass->get_value (balance, channel);
190   }
191
192   return channel->min_value;
193 }
194
195 /**
196  * gst_color_balance_get_balance_type:
197  * @balance: The #GstColorBalance implementation
198  *
199  * Get the #GstColorBalanceType of this implementation.
200  *
201  * Returns: A the #GstColorBalanceType.
202  *
203  * Since: 0.10.24
204  */
205 GstColorBalanceType
206 gst_color_balance_get_balance_type (GstColorBalance * balance)
207 {
208   GstColorBalanceClass *klass;
209
210   g_return_val_if_fail (GST_IS_COLOR_BALANCE (balance),
211       GST_COLOR_BALANCE_SOFTWARE);
212
213   klass = GST_COLOR_BALANCE_GET_CLASS (balance);
214
215   return klass->balance_type;
216 }
217
218 /**
219  * gst_color_balance_value_changed:
220  * @balance: A #GstColorBalance instance
221  * @channel: A #GstColorBalanceChannel whose value has changed
222  * @value: The new value of the channel
223  *
224  * A helper function called by implementations of the GstColorBalance
225  * interface. It fires the #GstColorBalance::value-changed signal on the
226  * instance, and the #GstColorBalanceChannel::value-changed signal on the
227  * channel object.
228  */
229 void
230 gst_color_balance_value_changed (GstColorBalance * balance,
231     GstColorBalanceChannel * channel, gint value)
232 {
233
234   g_return_if_fail (GST_IS_COLOR_BALANCE (balance));
235
236   g_signal_emit (G_OBJECT (balance),
237       gst_color_balance_signals[VALUE_CHANGED], 0, channel, value);
238
239   g_signal_emit_by_name (G_OBJECT (channel), "value_changed", value);
240 }