gst_plugins_base/sys/v4l/gstv4lcolorbalance.c
branchRCL_3
changeset 30 7e817e7e631c
parent 0 0e761a78d257
equal deleted inserted replaced
29:567bb019e3e3 30:7e817e7e631c
       
     1 /* GStreamer
       
     2  *
       
     3  * gstv4lcolorbalance.c: color balance interface implementation for V4L
       
     4  *
       
     5  * Copyright (C) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
       
     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 <gst/gst.h>
       
    28 #include "gstv4lcolorbalance.h"
       
    29 #include "gstv4lelement.h"
       
    30 
       
    31 static void
       
    32 gst_v4l_color_balance_channel_class_init (GstV4lColorBalanceChannelClass *
       
    33     klass);
       
    34 static void gst_v4l_color_balance_channel_init (GstV4lColorBalanceChannel *
       
    35     channel);
       
    36 
       
    37 static const GList *gst_v4l_color_balance_list_channels (GstColorBalance *
       
    38     balance);
       
    39 static void gst_v4l_color_balance_set_value (GstColorBalance * balance,
       
    40     GstColorBalanceChannel * channel, gint value);
       
    41 static gint gst_v4l_color_balance_get_value (GstColorBalance * balance,
       
    42     GstColorBalanceChannel * channel);
       
    43 
       
    44 static GstColorBalanceChannelClass *parent_class = NULL;
       
    45 
       
    46 GType
       
    47 gst_v4l_color_balance_channel_get_type (void)
       
    48 {
       
    49   static GType gst_v4l_color_balance_channel_type = 0;
       
    50 
       
    51   if (!gst_v4l_color_balance_channel_type) {
       
    52     static const GTypeInfo v4l_tuner_channel_info = {
       
    53       sizeof (GstV4lColorBalanceChannelClass),
       
    54       NULL,
       
    55       NULL,
       
    56       (GClassInitFunc) gst_v4l_color_balance_channel_class_init,
       
    57       NULL,
       
    58       NULL,
       
    59       sizeof (GstV4lColorBalanceChannel),
       
    60       0,
       
    61       (GInstanceInitFunc) gst_v4l_color_balance_channel_init,
       
    62       NULL
       
    63     };
       
    64 
       
    65     gst_v4l_color_balance_channel_type =
       
    66         g_type_register_static (GST_TYPE_COLOR_BALANCE_CHANNEL,
       
    67         "GstV4lColorBalanceChannel", &v4l_tuner_channel_info, 0);
       
    68   }
       
    69 
       
    70   return gst_v4l_color_balance_channel_type;
       
    71 }
       
    72 
       
    73 static void
       
    74 gst_v4l_color_balance_channel_class_init (GstV4lColorBalanceChannelClass *
       
    75     klass)
       
    76 {
       
    77   parent_class = g_type_class_peek_parent (klass);
       
    78 }
       
    79 
       
    80 static void
       
    81 gst_v4l_color_balance_channel_init (GstV4lColorBalanceChannel * channel)
       
    82 {
       
    83   channel->index = 0;
       
    84 }
       
    85 
       
    86 void
       
    87 gst_v4l_color_balance_interface_init (GstColorBalanceClass * klass)
       
    88 {
       
    89   GST_COLOR_BALANCE_TYPE (klass) = GST_COLOR_BALANCE_HARDWARE;
       
    90 
       
    91   /* default virtual functions */
       
    92   klass->list_channels = gst_v4l_color_balance_list_channels;
       
    93   klass->set_value = gst_v4l_color_balance_set_value;
       
    94   klass->get_value = gst_v4l_color_balance_get_value;
       
    95 }
       
    96 
       
    97 static G_GNUC_UNUSED gboolean
       
    98 gst_v4l_color_balance_contains_channel (GstV4lElement * v4lelement,
       
    99     GstV4lColorBalanceChannel * v4lchannel)
       
   100 {
       
   101   const GList *item;
       
   102 
       
   103   for (item = v4lelement->colors; item != NULL; item = item->next)
       
   104     if (item->data == v4lchannel)
       
   105       return TRUE;
       
   106 
       
   107   return FALSE;
       
   108 }
       
   109 
       
   110 static const GList *
       
   111 gst_v4l_color_balance_list_channels (GstColorBalance * balance)
       
   112 {
       
   113   return GST_V4LELEMENT (balance)->colors;
       
   114 }
       
   115 
       
   116 static void
       
   117 gst_v4l_color_balance_set_value (GstColorBalance * balance,
       
   118     GstColorBalanceChannel * channel, gint value)
       
   119 {
       
   120   GstV4lElement *v4lelement = GST_V4LELEMENT (balance);
       
   121   GstV4lColorBalanceChannel *v4lchannel =
       
   122       GST_V4L_COLOR_BALANCE_CHANNEL (channel);
       
   123 
       
   124   /* assert that we're opened and that we're using a known item */
       
   125   g_return_if_fail (GST_V4L_IS_OPEN (v4lelement));
       
   126   g_return_if_fail (gst_v4l_color_balance_contains_channel (v4lelement,
       
   127           v4lchannel));
       
   128 
       
   129   gst_v4l_set_picture (v4lelement, v4lchannel->index, value);
       
   130 }
       
   131 
       
   132 static gint
       
   133 gst_v4l_color_balance_get_value (GstColorBalance * balance,
       
   134     GstColorBalanceChannel * channel)
       
   135 {
       
   136   GstV4lElement *v4lelement = GST_V4LELEMENT (balance);
       
   137   GstV4lColorBalanceChannel *v4lchannel =
       
   138       GST_V4L_COLOR_BALANCE_CHANNEL (channel);
       
   139   gint value;
       
   140 
       
   141   /* assert that we're opened and that we're using a known item */
       
   142   g_return_val_if_fail (GST_V4L_IS_OPEN (v4lelement), 0);
       
   143   g_return_val_if_fail (gst_v4l_color_balance_contains_channel (v4lelement,
       
   144           v4lchannel), 0);
       
   145 
       
   146   if (!gst_v4l_get_picture (v4lelement, v4lchannel->index, &value))
       
   147     return 0;
       
   148 
       
   149   return value;
       
   150 }