Merge branch 'master' into 0.11
[platform/upstream/gst-plugins-base.git] / gst-libs / gst / video / 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 "video-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 /* FIXME 0.11: check if we need to add API for sometimes-supportedness
45  * (aka making up for GstImplementsInterface removal) */
46
47 /* FIXME 0.11: replace signals with messages (+ make API thread-safe) */
48
49 enum
50 {
51   VALUE_CHANGED,
52   LAST_SIGNAL
53 };
54
55 static void gst_color_balance_class_init (GstColorBalanceInterface * iface);
56
57 static guint gst_color_balance_signals[LAST_SIGNAL] = { 0 };
58
59 GType
60 gst_color_balance_get_type (void)
61 {
62   static GType gst_color_balance_type = 0;
63
64   if (!gst_color_balance_type) {
65     static const GTypeInfo gst_color_balance_info = {
66       sizeof (GstColorBalanceInterface),
67       (GBaseInitFunc) gst_color_balance_class_init,
68       NULL,
69       NULL,
70       NULL,
71       NULL,
72       0,
73       0,
74       NULL,
75     };
76
77     gst_color_balance_type = g_type_register_static (G_TYPE_INTERFACE,
78         "GstColorBalance", &gst_color_balance_info, 0);
79   }
80
81   return gst_color_balance_type;
82 }
83
84 static void
85 gst_color_balance_class_init (GstColorBalanceInterface * iface)
86 {
87   static gboolean initialized = FALSE;
88
89   if (!initialized) {
90     /**
91      * GstColorBalance::value-changed:
92      * @colorbalance: The GstColorBalance instance
93      * @channel: The #GstColorBalanceChannel
94      * @value: The new value
95      *
96      * Fired when the value of the indicated channel has changed.
97      */
98     gst_color_balance_signals[VALUE_CHANGED] =
99         g_signal_new ("value-changed",
100         GST_TYPE_COLOR_BALANCE, G_SIGNAL_RUN_LAST,
101         G_STRUCT_OFFSET (GstColorBalanceInterface, value_changed),
102         NULL, NULL,
103         gst_video_marshal_VOID__OBJECT_INT,
104         G_TYPE_NONE, 2, GST_TYPE_COLOR_BALANCE_CHANNEL, G_TYPE_INT);
105
106     initialized = TRUE;
107   }
108
109   /* default virtual functions */
110   iface->list_channels = NULL;
111   iface->set_value = NULL;
112   iface->get_value = NULL;
113   iface->get_balance_type = NULL;
114 }
115
116 /**
117  * gst_color_balance_list_channels:
118  * @balance: A #GstColorBalance instance
119  * 
120  * Retrieve a list of the available channels.
121  *
122  * Returns: A GList containing pointers to #GstColorBalanceChannel objects.
123  *          The list is owned by the #GstColorBalance instance and must not
124  *          be freed.
125  */
126 const GList *
127 gst_color_balance_list_channels (GstColorBalance * balance)
128 {
129   GstColorBalanceInterface *iface;
130
131   g_return_val_if_fail (GST_IS_COLOR_BALANCE (balance), NULL);
132
133   iface = GST_COLOR_BALANCE_GET_INTERFACE (balance);
134
135   if (iface->list_channels) {
136     return iface->list_channels (balance);
137   }
138
139   return NULL;
140 }
141
142 /**
143  * gst_color_balance_set_value:
144  * @balance: A #GstColorBalance instance
145  * @channel: A #GstColorBalanceChannel instance
146  * @value: The new value for the channel.
147  *
148  * Sets the current value of the channel to the passed value, which must
149  * be between min_value and max_value.
150  * 
151  * See Also: The #GstColorBalanceChannel.min_value and
152  *         #GstColorBalanceChannel.max_value members of the
153  *         #GstColorBalanceChannel object.
154  */
155 void
156 gst_color_balance_set_value (GstColorBalance * balance,
157     GstColorBalanceChannel * channel, gint value)
158 {
159   GstColorBalanceInterface *iface = GST_COLOR_BALANCE_GET_INTERFACE (balance);
160
161   if (iface->set_value) {
162     iface->set_value (balance, channel, value);
163   }
164 }
165
166 /**
167  * gst_color_balance_get_value:
168  * @balance: A #GstColorBalance instance
169  * @channel: A #GstColorBalanceChannel instance
170  *
171  * Retrieve the current value of the indicated channel, between min_value
172  * and max_value.
173  * 
174  * See Also: The #GstColorBalanceChannel.min_value and
175  *         #GstColorBalanceChannel.max_value members of the
176  *         #GstColorBalanceChannel object.
177  * 
178  * Returns: The current value of the channel.
179  */
180 gint
181 gst_color_balance_get_value (GstColorBalance * balance,
182     GstColorBalanceChannel * channel)
183 {
184   GstColorBalanceInterface *iface;
185
186   g_return_val_if_fail (GST_IS_COLOR_BALANCE (balance), 0);
187
188   iface = GST_COLOR_BALANCE_GET_INTERFACE (balance);
189
190   if (iface->get_value) {
191     return iface->get_value (balance, channel);
192   }
193
194   return channel->min_value;
195 }
196
197 /**
198  * gst_color_balance_get_balance_type:
199  * @balance: The #GstColorBalance implementation
200  *
201  * Get the #GstColorBalanceType of this implementation.
202  *
203  * Returns: A the #GstColorBalanceType.
204  *
205  * Since: 0.10.24
206  */
207 GstColorBalanceType
208 gst_color_balance_get_balance_type (GstColorBalance * balance)
209 {
210   GstColorBalanceInterface *iface;
211
212   g_return_val_if_fail (GST_IS_COLOR_BALANCE (balance),
213       GST_COLOR_BALANCE_SOFTWARE);
214
215   iface = GST_COLOR_BALANCE_GET_INTERFACE (balance);
216
217   g_return_val_if_fail (iface->get_balance_type != NULL,
218       GST_COLOR_BALANCE_SOFTWARE);
219
220   return iface->get_balance_type (balance);
221 }
222
223 /**
224  * gst_color_balance_value_changed:
225  * @balance: A #GstColorBalance instance
226  * @channel: A #GstColorBalanceChannel whose value has changed
227  * @value: The new value of the channel
228  *
229  * A helper function called by implementations of the GstColorBalance
230  * interface. It fires the #GstColorBalance::value-changed signal on the
231  * instance, and the #GstColorBalanceChannel::value-changed signal on the
232  * channel object.
233  */
234 void
235 gst_color_balance_value_changed (GstColorBalance * balance,
236     GstColorBalanceChannel * channel, gint value)
237 {
238
239   g_return_if_fail (GST_IS_COLOR_BALANCE (balance));
240
241   g_signal_emit (G_OBJECT (balance),
242       gst_color_balance_signals[VALUE_CHANGED], 0, channel, value);
243
244   g_signal_emit_by_name (G_OBJECT (channel), "value_changed", value);
245 }