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., 51 Franklin St, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26 
27 #include "colorbalance.h"
28 
29 /**
30  * SECTION:gstcolorbalance
31  * @title: GstColorBalance
32  * @short_description: Interface for adjusting color balance settings
33  *
34  * This interface is implemented by elements which can perform some color
35  * balance operation on video frames they process. For example, modifying
36  * the brightness, contrast, hue or saturation.
37  *
38  * Example elements are 'xvimagesink' and 'colorbalance'
39  *
40  */
41 
42 /* FIXME 0.11: check if we need to add API for sometimes-supportedness
43  * (aka making up for GstImplementsInterface removal) */
44 
45 /* FIXME 0.11: replace signals with messages (+ make API thread-safe) */
46 
47 enum
48 {
49   VALUE_CHANGED,
50   LAST_SIGNAL
51 };
52 
53 static void gst_color_balance_base_init (GstColorBalanceInterface * iface);
54 
55 static guint gst_color_balance_signals[LAST_SIGNAL] = { 0 };
56 
57 GType
gst_color_balance_get_type(void)58 gst_color_balance_get_type (void)
59 {
60   static GType gst_color_balance_type = 0;
61 
62   if (!gst_color_balance_type) {
63     static const GTypeInfo gst_color_balance_info = {
64       sizeof (GstColorBalanceInterface),
65       (GBaseInitFunc) gst_color_balance_base_init,
66       NULL,
67       NULL,
68       NULL,
69       NULL,
70       0,
71       0,
72       NULL,
73     };
74 
75     gst_color_balance_type = g_type_register_static (G_TYPE_INTERFACE,
76         "GstColorBalance", &gst_color_balance_info, 0);
77   }
78 
79   return gst_color_balance_type;
80 }
81 
82 static void
gst_color_balance_base_init(GstColorBalanceInterface * iface)83 gst_color_balance_base_init (GstColorBalanceInterface * iface)
84 {
85   static gboolean initialized = FALSE;
86 
87   if (!initialized) {
88     /**
89      * GstColorBalance::value-changed:
90      * @colorbalance: The GstColorBalance instance
91      * @channel: The #GstColorBalanceChannel
92      * @value: The new value
93      *
94      * Fired when the value of the indicated channel has changed.
95      */
96     gst_color_balance_signals[VALUE_CHANGED] =
97         g_signal_new ("value-changed",
98         GST_TYPE_COLOR_BALANCE, G_SIGNAL_RUN_LAST,
99         G_STRUCT_OFFSET (GstColorBalanceInterface, value_changed),
100         NULL, NULL, NULL,
101         G_TYPE_NONE, 2, GST_TYPE_COLOR_BALANCE_CHANNEL, G_TYPE_INT);
102 
103     initialized = TRUE;
104   }
105 
106   /* default virtual functions */
107   iface->list_channels = NULL;
108   iface->set_value = NULL;
109   iface->get_value = NULL;
110   iface->get_balance_type = NULL;
111 }
112 
113 /**
114  * gst_color_balance_list_channels:
115  * @balance: A #GstColorBalance instance
116  *
117  * Retrieve a list of the available channels.
118  *
119  * Returns: (element-type GstColorBalanceChannel) (transfer none): A
120  *          GList containing pointers to #GstColorBalanceChannel
121  *          objects. The list is owned by the #GstColorBalance
122  *          instance and must not be freed.
123  */
124 const GList *
gst_color_balance_list_channels(GstColorBalance * balance)125 gst_color_balance_list_channels (GstColorBalance * balance)
126 {
127   GstColorBalanceInterface *iface;
128 
129   g_return_val_if_fail (GST_IS_COLOR_BALANCE (balance), NULL);
130 
131   iface = GST_COLOR_BALANCE_GET_INTERFACE (balance);
132 
133   if (iface->list_channels) {
134     return iface->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
gst_color_balance_set_value(GstColorBalance * balance,GstColorBalanceChannel * channel,gint value)154 gst_color_balance_set_value (GstColorBalance * balance,
155     GstColorBalanceChannel * channel, gint value)
156 {
157   GstColorBalanceInterface *iface = GST_COLOR_BALANCE_GET_INTERFACE (balance);
158 
159   if (iface->set_value) {
160     iface->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
gst_color_balance_get_value(GstColorBalance * balance,GstColorBalanceChannel * channel)179 gst_color_balance_get_value (GstColorBalance * balance,
180     GstColorBalanceChannel * channel)
181 {
182   GstColorBalanceInterface *iface;
183 
184   g_return_val_if_fail (GST_IS_COLOR_BALANCE (balance), 0);
185 
186   iface = GST_COLOR_BALANCE_GET_INTERFACE (balance);
187 
188   if (iface->get_value) {
189     return iface->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 GstColorBalanceType
gst_color_balance_get_balance_type(GstColorBalance * balance)204 gst_color_balance_get_balance_type (GstColorBalance * balance)
205 {
206   GstColorBalanceInterface *iface;
207 
208   g_return_val_if_fail (GST_IS_COLOR_BALANCE (balance),
209       GST_COLOR_BALANCE_SOFTWARE);
210 
211   iface = GST_COLOR_BALANCE_GET_INTERFACE (balance);
212 
213   g_return_val_if_fail (iface->get_balance_type != NULL,
214       GST_COLOR_BALANCE_SOFTWARE);
215 
216   return iface->get_balance_type (balance);
217 }
218 
219 /**
220  * gst_color_balance_value_changed:
221  * @balance: A #GstColorBalance instance
222  * @channel: A #GstColorBalanceChannel whose value has changed
223  * @value: The new value of the channel
224  *
225  * A helper function called by implementations of the GstColorBalance
226  * interface. It fires the #GstColorBalance::value-changed signal on the
227  * instance, and the #GstColorBalanceChannel::value-changed signal on the
228  * channel object.
229  */
230 void
gst_color_balance_value_changed(GstColorBalance * balance,GstColorBalanceChannel * channel,gint value)231 gst_color_balance_value_changed (GstColorBalance * balance,
232     GstColorBalanceChannel * channel, gint value)
233 {
234 
235   g_return_if_fail (GST_IS_COLOR_BALANCE (balance));
236 
237   g_signal_emit (G_OBJECT (balance),
238       gst_color_balance_signals[VALUE_CHANGED], 0, channel, value);
239 
240   g_signal_emit_by_name (G_OBJECT (channel), "value_changed", value);
241 }
242