2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) <2003> David Schleef <ds@schleef.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * This file was (probably) generated from gstvideobalance.c,
23 * gstvideobalance.c,v 1.7 2003/11/08 02:48:59 dschleef Exp
30 /*#define DEBUG_ENABLED */
31 #include <gstvideobalance.h>
35 /* GstVideobalance signals and args */
50 static void gst_videobalance_base_init (gpointer g_class);
51 static void gst_videobalance_class_init (gpointer g_class, gpointer class_data);
52 static void gst_videobalance_init (GTypeInstance *instance, gpointer g_class);
54 static void gst_videobalance_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
55 static void gst_videobalance_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
57 static void gst_videobalance_planar411(GstVideofilter *videofilter, void *dest, void *src);
58 static void gst_videobalance_setup(GstVideofilter *videofilter);
61 gst_videobalance_get_type (void)
63 static GType videobalance_type = 0;
65 if (!videobalance_type) {
66 static const GTypeInfo videobalance_info = {
67 sizeof(GstVideobalanceClass),
68 gst_videobalance_base_init,
70 gst_videobalance_class_init,
73 sizeof(GstVideobalance),
75 gst_videobalance_init,
77 videobalance_type = g_type_register_static(GST_TYPE_VIDEOFILTER,
78 "GstVideobalance", &videobalance_info, 0);
80 return videobalance_type;
83 static GstVideofilterFormat gst_videobalance_formats[] = {
84 { "I420", 12, gst_videobalance_planar411, },
89 gst_videobalance_base_init (gpointer g_class)
91 static GstElementDetails videobalance_details = GST_ELEMENT_DETAILS (
92 "Video Balance Control",
93 "Filter/Effect/Video",
94 "Adjusts brightness, contrast, hue, saturation on a video stream",
95 "David Schleef <ds@schleef.org>"
97 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
98 GstVideofilterClass *videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
101 gst_element_class_set_details (element_class, &videobalance_details);
103 for(i=0;i<G_N_ELEMENTS(gst_videobalance_formats);i++){
104 gst_videofilter_class_add_format(videofilter_class,
105 gst_videobalance_formats + i);
108 gst_videofilter_class_add_pad_templates (GST_VIDEOFILTER_CLASS (g_class));
112 gst_videobalance_class_init (gpointer g_class, gpointer class_data)
114 GObjectClass *gobject_class;
115 GstVideofilterClass *videofilter_class;
117 gobject_class = G_OBJECT_CLASS (g_class);
118 videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
120 g_object_class_install_property(gobject_class, ARG_CONTRAST,
121 g_param_spec_double("contrast","Contrast","contrast",
122 0, 2, 1, G_PARAM_READWRITE));
123 g_object_class_install_property(gobject_class, ARG_BRIGHTNESS,
124 g_param_spec_double("brightness","Brightness","brightness",
125 -1, 1, 0, G_PARAM_READWRITE));
126 g_object_class_install_property(gobject_class, ARG_HUE,
127 g_param_spec_double("hue","Hue","hue",
128 -1, 1, 0, G_PARAM_READWRITE));
129 g_object_class_install_property(gobject_class, ARG_SATURATION,
130 g_param_spec_double("saturation","Saturation","saturation",
131 0, 2, 1, G_PARAM_READWRITE));
133 gobject_class->set_property = gst_videobalance_set_property;
134 gobject_class->get_property = gst_videobalance_get_property;
136 videofilter_class->setup = gst_videobalance_setup;
140 gst_videobalance_init (GTypeInstance *instance, gpointer g_class)
142 GstVideobalance *videobalance = GST_VIDEOBALANCE (instance);
143 GstVideofilter *videofilter;
145 GST_DEBUG("gst_videobalance_init");
147 videofilter = GST_VIDEOFILTER(videobalance);
150 videobalance->contrast = 1;
151 videobalance->brightness = 0;
152 videobalance->saturation = 1;
153 videobalance->hue = 0;
158 gst_videobalance_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
160 GstVideobalance *src;
162 /* it's not null if we got it, but it might not be ours */
163 g_return_if_fail(GST_IS_VIDEOBALANCE(object));
164 src = GST_VIDEOBALANCE(object);
166 GST_DEBUG("gst_videobalance_set_property");
169 src->contrast = g_value_get_double (value);
172 src->brightness = g_value_get_double (value);
175 src->hue = g_value_get_double (value);
178 src->saturation = g_value_get_double (value);
186 gst_videobalance_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
188 GstVideobalance *src;
190 /* it's not null if we got it, but it might not be ours */
191 g_return_if_fail(GST_IS_VIDEOBALANCE(object));
192 src = GST_VIDEOBALANCE(object);
196 g_value_set_double (value, src->contrast);
199 g_value_set_double (value, src->brightness);
202 g_value_set_double (value, src->hue);
205 g_value_set_double (value, src->saturation);
208 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
213 static gboolean plugin_init (GstPlugin *plugin)
215 if(!gst_library_load("gstvideofilter"))
218 return gst_element_register (plugin, "videobalance", GST_RANK_NONE,
219 GST_TYPE_VIDEOBALANCE);
226 "Changes hue, saturation, brightness etc. on video images",
235 static void gst_videobalance_setup(GstVideofilter *videofilter)
237 GstVideobalance *videobalance;
239 g_return_if_fail(GST_IS_VIDEOBALANCE(videofilter));
240 videobalance = GST_VIDEOBALANCE(videofilter);
242 /* if any setup needs to be done, do it here */
246 static void gst_videobalance_planar411(GstVideofilter *videofilter,
247 void *dest, void *src)
249 GstVideobalance *videobalance;
254 g_return_if_fail(GST_IS_VIDEOBALANCE(videofilter));
255 videobalance = GST_VIDEOBALANCE(videofilter);
257 width = videofilter->from_width;
258 height = videofilter->from_height;
264 guint8 *cdest = dest;
267 contrast = videobalance->contrast;
268 brightness = videobalance->brightness;
270 for(y=0;y<height;y++){
271 for(x=0;x<width;x++){
272 Y = csrc[y*width + x];
273 Y = 16 + ((Y-16) * contrast + brightness*255);
276 cdest[y*width + x] = rint(Y);
285 double hue_cos, hue_sin;
287 guint8 *udest, *vdest;
289 saturation = videobalance->saturation;
291 usrc = src + width*height;
292 udest = dest + width*height;
293 vsrc = src + width*height + (width/2)*(height/2);
294 vdest = dest + width*height + (width/2)*(height/2);
296 /* FIXME this is a bogus transformation for hue, but you get
298 hue_cos = cos(M_PI*videobalance->hue);
299 hue_sin = sin(M_PI*videobalance->hue);
301 for(y=0;y<height/2;y++){
302 for(x=0;x<width/2;x++){
303 u1 = usrc[y*(width/2) + x] - 128;
304 v1 = vsrc[y*(width/2) + x] - 128;
305 u = 128 + (( u1 * hue_cos + v1 * hue_sin) * saturation);
306 v = 128 + ((-u1 * hue_sin + v1 * hue_cos) * saturation);
311 udest[y*(width/2) + x] = rint(u);
312 vdest[y*(width/2) + x] = rint(v);