1 /* GStreamer
2 *
3 * Copyright (C) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
4 * 2006 Edgard Lima <edgard.lima@gmail.com>
5 *
6 * gstv4l2colorbalance.c: color balance interface implementation for V4L2
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 */
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <gst/gst.h>
29 #include "gstv4l2colorbalance.h"
30 #include "gstv4l2object.h"
31
32 #define gst_v4l2_color_balance_channel_parent_class parent_class
33 G_DEFINE_TYPE (GstV4l2ColorBalanceChannel,
34 gst_v4l2_color_balance_channel, GST_TYPE_COLOR_BALANCE_CHANNEL);
35
36 static void
gst_v4l2_color_balance_channel_class_init(GstV4l2ColorBalanceChannelClass * klass)37 gst_v4l2_color_balance_channel_class_init (GstV4l2ColorBalanceChannelClass *
38 klass)
39 {
40 }
41
42 static void
gst_v4l2_color_balance_channel_init(GstV4l2ColorBalanceChannel * channel)43 gst_v4l2_color_balance_channel_init (GstV4l2ColorBalanceChannel * channel)
44 {
45 channel->id = (guint32) - 1;
46 }
47
48 static G_GNUC_UNUSED gboolean
gst_v4l2_color_balance_contains_channel(GstV4l2Object * v4l2object,GstV4l2ColorBalanceChannel * v4l2channel)49 gst_v4l2_color_balance_contains_channel (GstV4l2Object * v4l2object,
50 GstV4l2ColorBalanceChannel * v4l2channel)
51 {
52 const GList *item;
53
54 for (item = v4l2object->colors; item != NULL; item = item->next)
55 if (item->data == v4l2channel)
56 return TRUE;
57
58 return FALSE;
59 }
60
61 const GList *
gst_v4l2_color_balance_list_channels(GstV4l2Object * v4l2object)62 gst_v4l2_color_balance_list_channels (GstV4l2Object * v4l2object)
63 {
64 return v4l2object->colors;
65 }
66
67 void
gst_v4l2_color_balance_set_value(GstV4l2Object * v4l2object,GstColorBalanceChannel * channel,gint value)68 gst_v4l2_color_balance_set_value (GstV4l2Object * v4l2object,
69 GstColorBalanceChannel * channel, gint value)
70 {
71
72 GstV4l2ColorBalanceChannel *v4l2channel =
73 GST_V4L2_COLOR_BALANCE_CHANNEL (channel);
74
75 /* assert that we're opened and that we're using a known item */
76 g_return_if_fail (GST_V4L2_IS_OPEN (v4l2object));
77 g_return_if_fail (gst_v4l2_color_balance_contains_channel (v4l2object,
78 v4l2channel));
79
80 gst_v4l2_set_attribute (v4l2object, v4l2channel->id, value);
81 }
82
83 gint
gst_v4l2_color_balance_get_value(GstV4l2Object * v4l2object,GstColorBalanceChannel * channel)84 gst_v4l2_color_balance_get_value (GstV4l2Object * v4l2object,
85 GstColorBalanceChannel * channel)
86 {
87 GstV4l2ColorBalanceChannel *v4l2channel =
88 GST_V4L2_COLOR_BALANCE_CHANNEL (channel);
89 gint value;
90
91 /* assert that we're opened and that we're using a known item */
92 g_return_val_if_fail (GST_V4L2_IS_OPEN (v4l2object), 0);
93 g_return_val_if_fail (gst_v4l2_color_balance_contains_channel (v4l2object,
94 v4l2channel), 0);
95
96 if (!gst_v4l2_get_attribute (v4l2object, v4l2channel->id, &value))
97 return 0;
98
99 return value;
100 }
101