2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) <2003> David Schleef <ds@schleef.org>
4 * Copyright (C) <2010> Sebastian Dröge <sebastian.droege@collabora.co.uk>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 * This file was (probably) generated from gstvideobalance.c,
24 * gstvideobalance.c,v 1.7 2003/11/08 02:48:59 dschleef Exp
28 * SECTION:element-videobalance
30 * Adjusts brightness, contrast, hue, saturation on a video stream.
33 * <title>Example launch line</title>
35 * gst-launch videotestsrc ! videobalance saturation=0.0 ! ffmpegcolorspace ! ximagesink
36 * ]| This pipeline converts the image to black and white by setting the
40 * Last reviewed on 2010-04-18 (0.10.22)
47 #include "gstvideobalance.h"
51 #include <gst/controller/gstcontroller.h>
52 #include <gst/interfaces/colorbalance.h>
55 #define M_PI 3.14159265358979323846
59 #define rint(x) (floor((x)+0.5))
62 GST_DEBUG_CATEGORY_STATIC (videobalance_debug);
63 #define GST_CAT_DEFAULT videobalance_debug
65 /* GstVideoBalance properties */
66 #define DEFAULT_PROP_CONTRAST 1.0
67 #define DEFAULT_PROP_BRIGHTNESS 0.0
68 #define DEFAULT_PROP_HUE 0.0
69 #define DEFAULT_PROP_SATURATION 1.0
80 static GstStaticPadTemplate gst_video_balance_src_template =
81 GST_STATIC_PAD_TEMPLATE ("src",
84 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("AYUV") ";"
85 GST_VIDEO_CAPS_ARGB ";" GST_VIDEO_CAPS_BGRA ";"
86 GST_VIDEO_CAPS_ABGR ";" GST_VIDEO_CAPS_RGBA ";"
87 GST_VIDEO_CAPS_YUV ("Y444") ";"
88 GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_RGBx ";"
89 GST_VIDEO_CAPS_xBGR ";" GST_VIDEO_CAPS_BGRx ";"
90 GST_VIDEO_CAPS_RGB ";" GST_VIDEO_CAPS_BGR ";"
91 GST_VIDEO_CAPS_YUV ("Y42B") ";"
92 GST_VIDEO_CAPS_YUV ("YUY2") ";"
93 GST_VIDEO_CAPS_YUV ("UYVY") ";"
94 GST_VIDEO_CAPS_YUV ("YVYU") ";"
95 GST_VIDEO_CAPS_YUV ("I420") ";"
96 GST_VIDEO_CAPS_YUV ("YV12") ";"
97 GST_VIDEO_CAPS_YUV ("IYUV") ";" GST_VIDEO_CAPS_YUV ("Y41B")
101 static GstStaticPadTemplate gst_video_balance_sink_template =
102 GST_STATIC_PAD_TEMPLATE ("sink",
105 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("AYUV") ";"
106 GST_VIDEO_CAPS_ARGB ";" GST_VIDEO_CAPS_BGRA ";"
107 GST_VIDEO_CAPS_ABGR ";" GST_VIDEO_CAPS_RGBA ";"
108 GST_VIDEO_CAPS_YUV ("Y444") ";"
109 GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_RGBx ";"
110 GST_VIDEO_CAPS_xBGR ";" GST_VIDEO_CAPS_BGRx ";"
111 GST_VIDEO_CAPS_RGB ";" GST_VIDEO_CAPS_BGR ";"
112 GST_VIDEO_CAPS_YUV ("Y42B") ";"
113 GST_VIDEO_CAPS_YUV ("YUY2") ";"
114 GST_VIDEO_CAPS_YUV ("UYVY") ";"
115 GST_VIDEO_CAPS_YUV ("YVYU") ";"
116 GST_VIDEO_CAPS_YUV ("I420") ";"
117 GST_VIDEO_CAPS_YUV ("YV12") ";"
118 GST_VIDEO_CAPS_YUV ("IYUV") ";" GST_VIDEO_CAPS_YUV ("Y41B")
122 static void gst_video_balance_colorbalance_init (GstColorBalanceClass * iface);
123 static void gst_video_balance_interface_init (GstImplementsInterfaceClass *
126 static void gst_video_balance_set_property (GObject * object, guint prop_id,
127 const GValue * value, GParamSpec * pspec);
128 static void gst_video_balance_get_property (GObject * object, guint prop_id,
129 GValue * value, GParamSpec * pspec);
132 _do_init (GType video_balance_type)
134 static const GInterfaceInfo iface_info = {
135 (GInterfaceInitFunc) gst_video_balance_interface_init,
139 static const GInterfaceInfo colorbalance_info = {
140 (GInterfaceInitFunc) gst_video_balance_colorbalance_init,
145 g_type_add_interface_static (video_balance_type,
146 GST_TYPE_IMPLEMENTS_INTERFACE, &iface_info);
147 g_type_add_interface_static (video_balance_type, GST_TYPE_COLOR_BALANCE,
151 GST_BOILERPLATE_FULL (GstVideoBalance, gst_video_balance, GstVideoFilter,
152 GST_TYPE_VIDEO_FILTER, _do_init);
155 * look-up tables (LUT).
158 gst_video_balance_update_tables (GstVideoBalance * vb)
161 gdouble y, u, v, hue_cos, hue_sin;
164 for (i = 0; i < 256; i++) {
165 y = 16 + ((i - 16) * vb->contrast + vb->brightness * 255);
170 vb->tabley[i] = rint (y);
173 hue_cos = cos (M_PI * vb->hue);
174 hue_sin = sin (M_PI * vb->hue);
176 /* U/V lookup tables are 2D, since we need both U/V for each table
178 for (i = -128; i < 128; i++) {
179 for (j = -128; j < 128; j++) {
180 u = 128 + ((i * hue_cos + j * hue_sin) * vb->saturation);
181 v = 128 + ((-i * hue_sin + j * hue_cos) * vb->saturation);
190 vb->tableu[i + 128][j + 128] = rint (u);
191 vb->tablev[i + 128][j + 128] = rint (v);
197 gst_video_balance_is_passthrough (GstVideoBalance * videobalance)
199 return videobalance->contrast == 1.0 &&
200 videobalance->brightness == 0.0 &&
201 videobalance->hue == 0.0 && videobalance->saturation == 1.0;
205 gst_video_balance_update_properties (GstVideoBalance * videobalance)
207 gboolean passthrough = gst_video_balance_is_passthrough (videobalance);
208 GstBaseTransform *base = GST_BASE_TRANSFORM (videobalance);
210 GST_BASE_TRANSFORM_LOCK (base);
211 base->passthrough = passthrough;
212 GST_BASE_TRANSFORM_UNLOCK (base);
215 gst_video_balance_update_tables (videobalance);
219 gst_video_balance_planar_yuv (GstVideoBalance * videobalance, guint8 * data)
223 guint8 *udata, *vdata;
224 gint ystride, ustride, vstride;
225 GstVideoFormat format;
227 gint width2, height2;
228 guint8 *tabley = videobalance->tabley;
229 guint8 **tableu = videobalance->tableu;
230 guint8 **tablev = videobalance->tablev;
232 format = videobalance->format;
233 width = videobalance->width;
234 height = videobalance->height;
237 data + gst_video_format_get_component_offset (format, 0, width, height);
238 ystride = gst_video_format_get_row_stride (format, 0, width);
240 for (y = 0; y < height; y++) {
243 yptr = ydata + y * ystride;
244 for (x = 0; x < width; x++) {
245 *ydata = tabley[*ydata];
250 width2 = gst_video_format_get_component_width (format, 1, width);
251 height2 = gst_video_format_get_component_height (format, 1, height);
254 data + gst_video_format_get_component_offset (format, 1, width, height);
256 data + gst_video_format_get_component_offset (format, 2, width, height);
257 ustride = gst_video_format_get_row_stride (format, 1, width);
258 vstride = gst_video_format_get_row_stride (format, 1, width);
260 for (y = 0; y < height2; y++) {
264 uptr = udata + y * ustride;
265 vptr = vdata + y * vstride;
267 for (x = 0; x < width2; x++) {
271 *uptr++ = tableu[u1][v1];
272 *vptr++ = tablev[u1][v1];
278 gst_video_balance_packed_yuv (GstVideoBalance * videobalance, guint8 * data)
282 guint8 *udata, *vdata;
283 gint ystride, ustride, vstride;
284 gint yoff, uoff, voff;
285 GstVideoFormat format;
287 gint width2, height2;
288 guint8 *tabley = videobalance->tabley;
289 guint8 **tableu = videobalance->tableu;
290 guint8 **tablev = videobalance->tablev;
292 format = videobalance->format;
293 width = videobalance->width;
294 height = videobalance->height;
297 data + gst_video_format_get_component_offset (format, 0, width, height);
298 ystride = gst_video_format_get_row_stride (format, 0, width);
299 yoff = gst_video_format_get_pixel_stride (format, 0);
301 for (y = 0; y < height; y++) {
304 yptr = ydata + y * ystride;
305 for (x = 0; x < width; x++) {
306 *ydata = tabley[*ydata];
311 width2 = gst_video_format_get_component_width (format, 1, width);
312 height2 = gst_video_format_get_component_height (format, 1, height);
315 data + gst_video_format_get_component_offset (format, 1, width, height);
317 data + gst_video_format_get_component_offset (format, 2, width, height);
318 ustride = gst_video_format_get_row_stride (format, 1, width);
319 vstride = gst_video_format_get_row_stride (format, 1, width);
320 uoff = gst_video_format_get_pixel_stride (format, 1);
321 voff = gst_video_format_get_pixel_stride (format, 2);
323 for (y = 0; y < height2; y++) {
327 uptr = udata + y * ustride;
328 vptr = vdata + y * vstride;
330 for (x = 0; x < width2; x++) {
334 *uptr = tableu[u1][v1];
335 *vptr = tablev[u1][v1];
343 static const int cog_ycbcr_to_rgb_matrix_8bit_sdtv[] = {
345 298, -100, -208, 34707,
349 static const gint cog_rgb_to_ycbcr_matrix_8bit_sdtv[] = {
351 -38, -74, 112, 32768,
352 112, -94, -18, 32768,
355 #define APPLY_MATRIX(m,o,v1,v2,v3) ((m[o*4] * v1 + m[o*4+1] * v2 + m[o*4+2] * v3 + m[o*4+3]) >> 8)
358 gst_video_balance_packed_rgb (GstVideoBalance * videobalance, guint8 * data)
361 gint width, row_stride, row_wrap;
367 guint8 *tabley = videobalance->tabley;
368 guint8 **tableu = videobalance->tableu;
369 guint8 **tablev = videobalance->tablev;
371 offsets[0] = gst_video_format_get_component_offset (videobalance->format, 0,
372 videobalance->width, videobalance->height);
373 offsets[1] = gst_video_format_get_component_offset (videobalance->format, 1,
374 videobalance->width, videobalance->height);
375 offsets[2] = gst_video_format_get_component_offset (videobalance->format, 2,
376 videobalance->width, videobalance->height);
379 gst_video_format_get_component_width (videobalance->format, 0,
380 videobalance->width);
382 gst_video_format_get_component_height (videobalance->format, 0,
383 videobalance->height);
385 gst_video_format_get_row_stride (videobalance->format, 0,
386 videobalance->width);
387 pixel_stride = gst_video_format_get_pixel_stride (videobalance->format, 0);
388 row_wrap = row_stride - pixel_stride * width;
390 for (i = 0; i < height; i++) {
391 for (j = 0; j < width; j++) {
392 r = data[offsets[0]];
393 g = data[offsets[1]];
394 b = data[offsets[2]];
396 y = APPLY_MATRIX (cog_rgb_to_ycbcr_matrix_8bit_sdtv, 0, r, g, b);
397 u_tmp = APPLY_MATRIX (cog_rgb_to_ycbcr_matrix_8bit_sdtv, 1, r, g, b);
398 v_tmp = APPLY_MATRIX (cog_rgb_to_ycbcr_matrix_8bit_sdtv, 2, r, g, b);
400 y = CLAMP (y, 0, 255);
401 u_tmp = CLAMP (u_tmp, 0, 255);
402 v_tmp = CLAMP (v_tmp, 0, 255);
405 u = tableu[u_tmp][v_tmp];
406 v = tablev[u_tmp][v_tmp];
408 r = APPLY_MATRIX (cog_ycbcr_to_rgb_matrix_8bit_sdtv, 0, y, u, v);
409 g = APPLY_MATRIX (cog_ycbcr_to_rgb_matrix_8bit_sdtv, 1, y, u, v);
410 b = APPLY_MATRIX (cog_ycbcr_to_rgb_matrix_8bit_sdtv, 2, y, u, v);
412 data[offsets[0]] = CLAMP (r, 0, 255);
413 data[offsets[1]] = CLAMP (g, 0, 255);
414 data[offsets[2]] = CLAMP (b, 0, 255);
415 data += pixel_stride;
421 /* get notified of caps and plug in the correct process function */
423 gst_video_balance_set_caps (GstBaseTransform * base, GstCaps * incaps,
426 GstVideoBalance *videobalance = GST_VIDEO_BALANCE (base);
428 GST_DEBUG_OBJECT (videobalance,
429 "in %" GST_PTR_FORMAT " out %" GST_PTR_FORMAT, incaps, outcaps);
431 videobalance->process = NULL;
433 if (!gst_video_format_parse_caps (incaps, &videobalance->format,
434 &videobalance->width, &videobalance->height))
438 gst_video_format_get_size (videobalance->format, videobalance->width,
439 videobalance->height);
441 switch (videobalance->format) {
442 case GST_VIDEO_FORMAT_I420:
443 case GST_VIDEO_FORMAT_YV12:
444 case GST_VIDEO_FORMAT_Y41B:
445 case GST_VIDEO_FORMAT_Y42B:
446 case GST_VIDEO_FORMAT_Y444:
447 videobalance->process = gst_video_balance_planar_yuv;
449 case GST_VIDEO_FORMAT_YUY2:
450 case GST_VIDEO_FORMAT_UYVY:
451 case GST_VIDEO_FORMAT_AYUV:
452 case GST_VIDEO_FORMAT_YVYU:
453 videobalance->process = gst_video_balance_packed_yuv;
455 case GST_VIDEO_FORMAT_ARGB:
456 case GST_VIDEO_FORMAT_ABGR:
457 case GST_VIDEO_FORMAT_RGBA:
458 case GST_VIDEO_FORMAT_BGRA:
459 case GST_VIDEO_FORMAT_xRGB:
460 case GST_VIDEO_FORMAT_xBGR:
461 case GST_VIDEO_FORMAT_RGBx:
462 case GST_VIDEO_FORMAT_BGRx:
463 case GST_VIDEO_FORMAT_RGB:
464 case GST_VIDEO_FORMAT_BGR:
465 videobalance->process = gst_video_balance_packed_rgb;
471 return videobalance->process != NULL;
474 GST_ERROR_OBJECT (videobalance, "Invalid caps: %" GST_PTR_FORMAT, incaps);
479 gst_video_balance_before_transform (GstBaseTransform * base, GstBuffer * buf)
481 GstVideoBalance *balance = GST_VIDEO_BALANCE (base);
482 GstClockTime timestamp, stream_time;
484 timestamp = GST_BUFFER_TIMESTAMP (buf);
486 gst_segment_to_stream_time (&base->segment, GST_FORMAT_TIME, timestamp);
488 GST_DEBUG_OBJECT (balance, "sync to %" GST_TIME_FORMAT,
489 GST_TIME_ARGS (timestamp));
491 if (GST_CLOCK_TIME_IS_VALID (stream_time))
492 gst_object_sync_values (G_OBJECT (balance), stream_time);
496 gst_video_balance_transform_ip (GstBaseTransform * base, GstBuffer * outbuf)
498 GstVideoBalance *videobalance = GST_VIDEO_BALANCE (base);
502 if (!videobalance->process)
505 /* if no change is needed, we are done */
506 if (base->passthrough)
509 data = GST_BUFFER_DATA (outbuf);
510 size = GST_BUFFER_SIZE (outbuf);
512 if (size != videobalance->size)
515 GST_OBJECT_LOCK (videobalance);
516 videobalance->process (videobalance, data);
517 GST_OBJECT_UNLOCK (videobalance);
525 GST_ELEMENT_ERROR (videobalance, STREAM, FORMAT,
526 (NULL), ("Invalid buffer size %d, expected %d", size,
527 videobalance->size));
528 return GST_FLOW_ERROR;
531 GST_ERROR_OBJECT (videobalance, "Not negotiated yet");
532 return GST_FLOW_NOT_NEGOTIATED;
536 gst_video_balance_base_init (gpointer g_class)
538 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
540 gst_element_class_set_details_simple (element_class, "Video balance",
541 "Filter/Effect/Video",
542 "Adjusts brightness, contrast, hue, saturation on a video stream",
543 "David Schleef <ds@schleef.org>");
545 gst_element_class_add_pad_template (element_class,
546 gst_static_pad_template_get (&gst_video_balance_sink_template));
547 gst_element_class_add_pad_template (element_class,
548 gst_static_pad_template_get (&gst_video_balance_src_template));
552 gst_video_balance_finalize (GObject * object)
554 GList *channels = NULL;
555 GstVideoBalance *balance = GST_VIDEO_BALANCE (object);
557 g_free (balance->tableu[0]);
559 channels = balance->channels;
561 GstColorBalanceChannel *channel = channels->data;
563 g_object_unref (channel);
564 channels->data = NULL;
565 channels = g_list_next (channels);
568 if (balance->channels)
569 g_list_free (balance->channels);
571 G_OBJECT_CLASS (parent_class)->finalize (object);
575 gst_video_balance_class_init (GstVideoBalanceClass * klass)
577 GObjectClass *gobject_class = (GObjectClass *) klass;
578 GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
580 GST_DEBUG_CATEGORY_INIT (videobalance_debug, "videobalance", 0,
583 gobject_class->finalize = gst_video_balance_finalize;
584 gobject_class->set_property = gst_video_balance_set_property;
585 gobject_class->get_property = gst_video_balance_get_property;
587 g_object_class_install_property (gobject_class, PROP_CONTRAST,
588 g_param_spec_double ("contrast", "Contrast", "contrast",
589 0.0, 2.0, DEFAULT_PROP_CONTRAST,
590 GST_PARAM_CONTROLLABLE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
591 g_object_class_install_property (gobject_class, PROP_BRIGHTNESS,
592 g_param_spec_double ("brightness", "Brightness", "brightness", -1.0, 1.0,
593 DEFAULT_PROP_BRIGHTNESS,
594 GST_PARAM_CONTROLLABLE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
595 g_object_class_install_property (gobject_class, PROP_HUE,
596 g_param_spec_double ("hue", "Hue", "hue", -1.0, 1.0, DEFAULT_PROP_HUE,
597 GST_PARAM_CONTROLLABLE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
598 g_object_class_install_property (gobject_class, PROP_SATURATION,
599 g_param_spec_double ("saturation", "Saturation", "saturation", 0.0, 2.0,
600 DEFAULT_PROP_SATURATION,
601 GST_PARAM_CONTROLLABLE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
603 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_video_balance_set_caps);
604 trans_class->transform_ip =
605 GST_DEBUG_FUNCPTR (gst_video_balance_transform_ip);
606 trans_class->before_transform =
607 GST_DEBUG_FUNCPTR (gst_video_balance_before_transform);
611 gst_video_balance_init (GstVideoBalance * videobalance,
612 GstVideoBalanceClass * klass)
614 const gchar *channels[4] = { "HUE", "SATURATION",
615 "BRIGHTNESS", "CONTRAST"
619 /* Initialize propertiews */
620 videobalance->contrast = DEFAULT_PROP_CONTRAST;
621 videobalance->brightness = DEFAULT_PROP_BRIGHTNESS;
622 videobalance->hue = DEFAULT_PROP_HUE;
623 videobalance->saturation = DEFAULT_PROP_SATURATION;
625 videobalance->tableu[0] = g_new (guint8, 256 * 256 * 2);
626 for (i = 0; i < 256; i++) {
627 videobalance->tableu[i] =
628 videobalance->tableu[0] + i * 256 * sizeof (guint8);
629 videobalance->tablev[i] =
630 videobalance->tableu[0] + 256 * 256 * sizeof (guint8) +
631 i * 256 * sizeof (guint8);
634 gst_video_balance_update_properties (videobalance);
636 /* Generate the channels list */
637 for (i = 0; i < G_N_ELEMENTS (channels); i++) {
638 GstColorBalanceChannel *channel;
640 channel = g_object_new (GST_TYPE_COLOR_BALANCE_CHANNEL, NULL);
641 channel->label = g_strdup (channels[i]);
642 channel->min_value = -1000;
643 channel->max_value = 1000;
645 videobalance->channels = g_list_append (videobalance->channels, channel);
650 gst_video_balance_interface_supported (GstImplementsInterface * iface,
653 g_assert (type == GST_TYPE_COLOR_BALANCE);
658 gst_video_balance_interface_init (GstImplementsInterfaceClass * klass)
660 klass->supported = gst_video_balance_interface_supported;
664 gst_video_balance_colorbalance_list_channels (GstColorBalance * balance)
666 GstVideoBalance *videobalance = GST_VIDEO_BALANCE (balance);
668 g_return_val_if_fail (videobalance != NULL, NULL);
669 g_return_val_if_fail (GST_IS_VIDEO_BALANCE (videobalance), NULL);
671 return videobalance->channels;
675 gst_video_balance_colorbalance_set_value (GstColorBalance * balance,
676 GstColorBalanceChannel * channel, gint value)
678 GstVideoBalance *vb = GST_VIDEO_BALANCE (balance);
682 g_return_if_fail (vb != NULL);
683 g_return_if_fail (GST_IS_VIDEO_BALANCE (vb));
684 g_return_if_fail (GST_IS_VIDEO_FILTER (vb));
685 g_return_if_fail (channel->label != NULL);
687 GST_OBJECT_LOCK (vb);
688 if (!g_ascii_strcasecmp (channel->label, "HUE")) {
689 new_val = (value + 1000.0) * 2.0 / 2000.0 - 1.0;
690 changed = new_val != vb->hue;
692 } else if (!g_ascii_strcasecmp (channel->label, "SATURATION")) {
693 new_val = (value + 1000.0) * 2.0 / 2000.0;
694 changed = new_val != vb->saturation;
695 vb->saturation = new_val;
696 } else if (!g_ascii_strcasecmp (channel->label, "BRIGHTNESS")) {
697 new_val = (value + 1000.0) * 2.0 / 2000.0 - 1.0;
698 changed = new_val != vb->brightness;
699 vb->brightness = new_val;
700 } else if (!g_ascii_strcasecmp (channel->label, "CONTRAST")) {
701 new_val = (value + 1000.0) * 2.0 / 2000.0;
702 changed = new_val != vb->contrast;
703 vb->contrast = new_val;
706 gst_video_balance_update_properties (vb);
707 GST_OBJECT_UNLOCK (vb);
709 gst_color_balance_value_changed (balance, channel,
710 gst_color_balance_get_value (balance, channel));
714 gst_video_balance_colorbalance_get_value (GstColorBalance * balance,
715 GstColorBalanceChannel * channel)
717 GstVideoBalance *vb = GST_VIDEO_BALANCE (balance);
720 g_return_val_if_fail (vb != NULL, 0);
721 g_return_val_if_fail (GST_IS_VIDEO_BALANCE (vb), 0);
722 g_return_val_if_fail (channel->label != NULL, 0);
724 if (!g_ascii_strcasecmp (channel->label, "HUE")) {
725 value = (vb->hue + 1) * 2000.0 / 2.0 - 1000.0;
726 } else if (!g_ascii_strcasecmp (channel->label, "SATURATION")) {
727 value = vb->saturation * 2000.0 / 2.0 - 1000.0;
728 } else if (!g_ascii_strcasecmp (channel->label, "BRIGHTNESS")) {
729 value = (vb->brightness + 1) * 2000.0 / 2.0 - 1000.0;
730 } else if (!g_ascii_strcasecmp (channel->label, "CONTRAST")) {
731 value = vb->contrast * 2000.0 / 2.0 - 1000.0;
738 gst_video_balance_colorbalance_init (GstColorBalanceClass * iface)
740 GST_COLOR_BALANCE_TYPE (iface) = GST_COLOR_BALANCE_SOFTWARE;
741 iface->list_channels = gst_video_balance_colorbalance_list_channels;
742 iface->set_value = gst_video_balance_colorbalance_set_value;
743 iface->get_value = gst_video_balance_colorbalance_get_value;
746 static GstColorBalanceChannel *
747 gst_video_balance_find_channel (GstVideoBalance * balance, const gchar * label)
751 for (l = balance->channels; l; l = l->next) {
752 GstColorBalanceChannel *channel = l->data;
754 if (g_ascii_strcasecmp (channel->label, label) == 0)
761 gst_video_balance_set_property (GObject * object, guint prop_id,
762 const GValue * value, GParamSpec * pspec)
764 GstVideoBalance *balance = GST_VIDEO_BALANCE (object);
766 const gchar *label = NULL;
768 GST_OBJECT_LOCK (balance);
771 d = g_value_get_double (value);
772 GST_DEBUG_OBJECT (balance, "Changing contrast from %lf to %lf",
773 balance->contrast, d);
774 if (d != balance->contrast)
776 balance->contrast = d;
778 case PROP_BRIGHTNESS:
779 d = g_value_get_double (value);
780 GST_DEBUG_OBJECT (balance, "Changing brightness from %lf to %lf",
781 balance->brightness, d);
782 if (d != balance->brightness)
783 label = "BRIGHTNESS";
784 balance->brightness = d;
787 d = g_value_get_double (value);
788 GST_DEBUG_OBJECT (balance, "Changing hue from %lf to %lf", balance->hue,
790 if (d != balance->hue)
794 case PROP_SATURATION:
795 d = g_value_get_double (value);
796 GST_DEBUG_OBJECT (balance, "Changing saturation from %lf to %lf",
797 balance->saturation, d);
798 if (d != balance->saturation)
799 label = "SATURATION";
800 balance->saturation = d;
803 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
807 gst_video_balance_update_properties (balance);
808 GST_OBJECT_UNLOCK (balance);
811 GstColorBalanceChannel *channel =
812 gst_video_balance_find_channel (balance, label);
813 gst_color_balance_value_changed (GST_COLOR_BALANCE (balance), channel,
814 gst_color_balance_get_value (GST_COLOR_BALANCE (balance), channel));
819 gst_video_balance_get_property (GObject * object, guint prop_id, GValue * value,
822 GstVideoBalance *balance = GST_VIDEO_BALANCE (object);
826 g_value_set_double (value, balance->contrast);
828 case PROP_BRIGHTNESS:
829 g_value_set_double (value, balance->brightness);
832 g_value_set_double (value, balance->hue);
834 case PROP_SATURATION:
835 g_value_set_double (value, balance->saturation);
838 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);