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 <gst/math-compat.h>
49 #include "gstvideobalance.h"
52 #include <gst/controller/gstcontroller.h>
53 #include <gst/interfaces/colorbalance.h>
55 GST_DEBUG_CATEGORY_STATIC (videobalance_debug);
56 #define GST_CAT_DEFAULT videobalance_debug
58 /* GstVideoBalance properties */
59 #define DEFAULT_PROP_CONTRAST 1.0
60 #define DEFAULT_PROP_BRIGHTNESS 0.0
61 #define DEFAULT_PROP_HUE 0.0
62 #define DEFAULT_PROP_SATURATION 1.0
73 static GstStaticPadTemplate gst_video_balance_src_template =
74 GST_STATIC_PAD_TEMPLATE ("src",
77 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("AYUV") ";"
78 GST_VIDEO_CAPS_ARGB ";" GST_VIDEO_CAPS_BGRA ";"
79 GST_VIDEO_CAPS_ABGR ";" GST_VIDEO_CAPS_RGBA ";"
80 GST_VIDEO_CAPS_YUV ("Y444") ";"
81 GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_RGBx ";"
82 GST_VIDEO_CAPS_xBGR ";" GST_VIDEO_CAPS_BGRx ";"
83 GST_VIDEO_CAPS_RGB ";" GST_VIDEO_CAPS_BGR ";"
84 GST_VIDEO_CAPS_YUV ("Y42B") ";"
85 GST_VIDEO_CAPS_YUV ("YUY2") ";"
86 GST_VIDEO_CAPS_YUV ("UYVY") ";"
87 GST_VIDEO_CAPS_YUV ("YVYU") ";"
88 GST_VIDEO_CAPS_YUV ("I420") ";"
89 GST_VIDEO_CAPS_YUV ("YV12") ";"
90 GST_VIDEO_CAPS_YUV ("IYUV") ";" GST_VIDEO_CAPS_YUV ("Y41B")
94 static GstStaticPadTemplate gst_video_balance_sink_template =
95 GST_STATIC_PAD_TEMPLATE ("sink",
98 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("AYUV") ";"
99 GST_VIDEO_CAPS_ARGB ";" GST_VIDEO_CAPS_BGRA ";"
100 GST_VIDEO_CAPS_ABGR ";" GST_VIDEO_CAPS_RGBA ";"
101 GST_VIDEO_CAPS_YUV ("Y444") ";"
102 GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_RGBx ";"
103 GST_VIDEO_CAPS_xBGR ";" GST_VIDEO_CAPS_BGRx ";"
104 GST_VIDEO_CAPS_RGB ";" GST_VIDEO_CAPS_BGR ";"
105 GST_VIDEO_CAPS_YUV ("Y42B") ";"
106 GST_VIDEO_CAPS_YUV ("YUY2") ";"
107 GST_VIDEO_CAPS_YUV ("UYVY") ";"
108 GST_VIDEO_CAPS_YUV ("YVYU") ";"
109 GST_VIDEO_CAPS_YUV ("I420") ";"
110 GST_VIDEO_CAPS_YUV ("YV12") ";"
111 GST_VIDEO_CAPS_YUV ("IYUV") ";" GST_VIDEO_CAPS_YUV ("Y41B")
115 static void gst_video_balance_colorbalance_init (GstColorBalanceClass * iface);
116 static void gst_video_balance_interface_init (GstImplementsInterfaceClass *
119 static void gst_video_balance_set_property (GObject * object, guint prop_id,
120 const GValue * value, GParamSpec * pspec);
121 static void gst_video_balance_get_property (GObject * object, guint prop_id,
122 GValue * value, GParamSpec * pspec);
124 #define gst_video_balance_parent_class parent_class
125 G_DEFINE_TYPE_WITH_CODE (GstVideoBalance, gst_video_balance,
126 GST_TYPE_VIDEO_FILTER,
127 G_IMPLEMENT_INTERFACE (GST_TYPE_IMPLEMENTS_INTERFACE,
128 gst_video_balance_interface_init);
129 G_IMPLEMENT_INTERFACE (GST_TYPE_COLOR_BALANCE,
130 gst_video_balance_colorbalance_init));
133 * look-up tables (LUT).
136 gst_video_balance_update_tables (GstVideoBalance * vb)
139 gdouble y, u, v, hue_cos, hue_sin;
142 for (i = 0; i < 256; i++) {
143 y = 16 + ((i - 16) * vb->contrast + vb->brightness * 255);
148 vb->tabley[i] = rint (y);
151 hue_cos = cos (G_PI * vb->hue);
152 hue_sin = sin (G_PI * vb->hue);
154 /* U/V lookup tables are 2D, since we need both U/V for each table
156 for (i = -128; i < 128; i++) {
157 for (j = -128; j < 128; j++) {
158 u = 128 + ((i * hue_cos + j * hue_sin) * vb->saturation);
159 v = 128 + ((-i * hue_sin + j * hue_cos) * vb->saturation);
168 vb->tableu[i + 128][j + 128] = rint (u);
169 vb->tablev[i + 128][j + 128] = rint (v);
175 gst_video_balance_is_passthrough (GstVideoBalance * videobalance)
177 return videobalance->contrast == 1.0 &&
178 videobalance->brightness == 0.0 &&
179 videobalance->hue == 0.0 && videobalance->saturation == 1.0;
183 gst_video_balance_update_properties (GstVideoBalance * videobalance)
185 gboolean passthrough = gst_video_balance_is_passthrough (videobalance);
186 GstBaseTransform *base = GST_BASE_TRANSFORM (videobalance);
188 base->passthrough = passthrough;
191 gst_video_balance_update_tables (videobalance);
195 gst_video_balance_planar_yuv (GstVideoBalance * videobalance, guint8 * data)
199 guint8 *udata, *vdata;
200 gint ystride, ustride, vstride;
201 GstVideoFormat format;
203 gint width2, height2;
204 guint8 *tabley = videobalance->tabley;
205 guint8 **tableu = videobalance->tableu;
206 guint8 **tablev = videobalance->tablev;
208 format = videobalance->format;
209 width = videobalance->width;
210 height = videobalance->height;
213 data + gst_video_format_get_component_offset (format, 0, width, height);
214 ystride = gst_video_format_get_row_stride (format, 0, width);
216 for (y = 0; y < height; y++) {
219 yptr = ydata + y * ystride;
220 for (x = 0; x < width; x++) {
221 *yptr = tabley[*yptr];
226 width2 = gst_video_format_get_component_width (format, 1, width);
227 height2 = gst_video_format_get_component_height (format, 1, height);
230 data + gst_video_format_get_component_offset (format, 1, width, height);
232 data + gst_video_format_get_component_offset (format, 2, width, height);
233 ustride = gst_video_format_get_row_stride (format, 1, width);
234 vstride = gst_video_format_get_row_stride (format, 1, width);
236 for (y = 0; y < height2; y++) {
240 uptr = udata + y * ustride;
241 vptr = vdata + y * vstride;
243 for (x = 0; x < width2; x++) {
247 *uptr++ = tableu[u1][v1];
248 *vptr++ = tablev[u1][v1];
254 gst_video_balance_packed_yuv (GstVideoBalance * videobalance, guint8 * data)
258 guint8 *udata, *vdata;
259 gint ystride, ustride, vstride;
260 gint yoff, uoff, voff;
261 GstVideoFormat format;
263 gint width2, height2;
264 guint8 *tabley = videobalance->tabley;
265 guint8 **tableu = videobalance->tableu;
266 guint8 **tablev = videobalance->tablev;
268 format = videobalance->format;
269 width = videobalance->width;
270 height = videobalance->height;
273 data + gst_video_format_get_component_offset (format, 0, width, height);
274 ystride = gst_video_format_get_row_stride (format, 0, width);
275 yoff = gst_video_format_get_pixel_stride (format, 0);
277 for (y = 0; y < height; y++) {
280 yptr = ydata + y * ystride;
281 for (x = 0; x < width; x++) {
282 *yptr = tabley[*yptr];
287 width2 = gst_video_format_get_component_width (format, 1, width);
288 height2 = gst_video_format_get_component_height (format, 1, height);
291 data + gst_video_format_get_component_offset (format, 1, width, height);
293 data + gst_video_format_get_component_offset (format, 2, width, height);
294 ustride = gst_video_format_get_row_stride (format, 1, width);
295 vstride = gst_video_format_get_row_stride (format, 1, width);
296 uoff = gst_video_format_get_pixel_stride (format, 1);
297 voff = gst_video_format_get_pixel_stride (format, 2);
299 for (y = 0; y < height2; y++) {
303 uptr = udata + y * ustride;
304 vptr = vdata + y * vstride;
306 for (x = 0; x < width2; x++) {
310 *uptr = tableu[u1][v1];
311 *vptr = tablev[u1][v1];
319 static const int cog_ycbcr_to_rgb_matrix_8bit_sdtv[] = {
321 298, -100, -208, 34707,
325 static const gint cog_rgb_to_ycbcr_matrix_8bit_sdtv[] = {
327 -38, -74, 112, 32768,
328 112, -94, -18, 32768,
331 #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)
334 gst_video_balance_packed_rgb (GstVideoBalance * videobalance, guint8 * data)
337 gint width, row_stride, row_wrap;
343 guint8 *tabley = videobalance->tabley;
344 guint8 **tableu = videobalance->tableu;
345 guint8 **tablev = videobalance->tablev;
347 offsets[0] = gst_video_format_get_component_offset (videobalance->format, 0,
348 videobalance->width, videobalance->height);
349 offsets[1] = gst_video_format_get_component_offset (videobalance->format, 1,
350 videobalance->width, videobalance->height);
351 offsets[2] = gst_video_format_get_component_offset (videobalance->format, 2,
352 videobalance->width, videobalance->height);
355 gst_video_format_get_component_width (videobalance->format, 0,
356 videobalance->width);
358 gst_video_format_get_component_height (videobalance->format, 0,
359 videobalance->height);
361 gst_video_format_get_row_stride (videobalance->format, 0,
362 videobalance->width);
363 pixel_stride = gst_video_format_get_pixel_stride (videobalance->format, 0);
364 row_wrap = row_stride - pixel_stride * width;
366 for (i = 0; i < height; i++) {
367 for (j = 0; j < width; j++) {
368 r = data[offsets[0]];
369 g = data[offsets[1]];
370 b = data[offsets[2]];
372 y = APPLY_MATRIX (cog_rgb_to_ycbcr_matrix_8bit_sdtv, 0, r, g, b);
373 u_tmp = APPLY_MATRIX (cog_rgb_to_ycbcr_matrix_8bit_sdtv, 1, r, g, b);
374 v_tmp = APPLY_MATRIX (cog_rgb_to_ycbcr_matrix_8bit_sdtv, 2, r, g, b);
376 y = CLAMP (y, 0, 255);
377 u_tmp = CLAMP (u_tmp, 0, 255);
378 v_tmp = CLAMP (v_tmp, 0, 255);
381 u = tableu[u_tmp][v_tmp];
382 v = tablev[u_tmp][v_tmp];
384 r = APPLY_MATRIX (cog_ycbcr_to_rgb_matrix_8bit_sdtv, 0, y, u, v);
385 g = APPLY_MATRIX (cog_ycbcr_to_rgb_matrix_8bit_sdtv, 1, y, u, v);
386 b = APPLY_MATRIX (cog_ycbcr_to_rgb_matrix_8bit_sdtv, 2, y, u, v);
388 data[offsets[0]] = CLAMP (r, 0, 255);
389 data[offsets[1]] = CLAMP (g, 0, 255);
390 data[offsets[2]] = CLAMP (b, 0, 255);
391 data += pixel_stride;
397 /* get notified of caps and plug in the correct process function */
399 gst_video_balance_set_caps (GstBaseTransform * base, GstCaps * incaps,
402 GstVideoBalance *videobalance = GST_VIDEO_BALANCE (base);
404 GST_DEBUG_OBJECT (videobalance,
405 "in %" GST_PTR_FORMAT " out %" GST_PTR_FORMAT, incaps, outcaps);
407 videobalance->process = NULL;
409 if (!gst_video_format_parse_caps (incaps, &videobalance->format,
410 &videobalance->width, &videobalance->height))
414 gst_video_format_get_size (videobalance->format, videobalance->width,
415 videobalance->height);
417 switch (videobalance->format) {
418 case GST_VIDEO_FORMAT_I420:
419 case GST_VIDEO_FORMAT_YV12:
420 case GST_VIDEO_FORMAT_Y41B:
421 case GST_VIDEO_FORMAT_Y42B:
422 case GST_VIDEO_FORMAT_Y444:
423 videobalance->process = gst_video_balance_planar_yuv;
425 case GST_VIDEO_FORMAT_YUY2:
426 case GST_VIDEO_FORMAT_UYVY:
427 case GST_VIDEO_FORMAT_AYUV:
428 case GST_VIDEO_FORMAT_YVYU:
429 videobalance->process = gst_video_balance_packed_yuv;
431 case GST_VIDEO_FORMAT_ARGB:
432 case GST_VIDEO_FORMAT_ABGR:
433 case GST_VIDEO_FORMAT_RGBA:
434 case GST_VIDEO_FORMAT_BGRA:
435 case GST_VIDEO_FORMAT_xRGB:
436 case GST_VIDEO_FORMAT_xBGR:
437 case GST_VIDEO_FORMAT_RGBx:
438 case GST_VIDEO_FORMAT_BGRx:
439 case GST_VIDEO_FORMAT_RGB:
440 case GST_VIDEO_FORMAT_BGR:
441 videobalance->process = gst_video_balance_packed_rgb;
447 return videobalance->process != NULL;
450 GST_ERROR_OBJECT (videobalance, "Invalid caps: %" GST_PTR_FORMAT, incaps);
455 gst_video_balance_before_transform (GstBaseTransform * base, GstBuffer * buf)
457 GstVideoBalance *balance = GST_VIDEO_BALANCE (base);
458 GstClockTime timestamp, stream_time;
460 timestamp = GST_BUFFER_TIMESTAMP (buf);
462 gst_segment_to_stream_time (&base->segment, GST_FORMAT_TIME, timestamp);
464 GST_DEBUG_OBJECT (balance, "sync to %" GST_TIME_FORMAT,
465 GST_TIME_ARGS (timestamp));
467 if (GST_CLOCK_TIME_IS_VALID (stream_time))
468 gst_object_sync_values (G_OBJECT (balance), stream_time);
472 gst_video_balance_transform_ip (GstBaseTransform * base, GstBuffer * outbuf)
474 GstVideoBalance *videobalance = GST_VIDEO_BALANCE (base);
478 if (!videobalance->process)
481 /* if no change is needed, we are done */
482 if (base->passthrough)
485 data = gst_buffer_map (outbuf, &size, NULL, GST_MAP_READWRITE);
487 if (size != videobalance->size)
490 GST_OBJECT_LOCK (videobalance);
491 videobalance->process (videobalance, data);
492 GST_OBJECT_UNLOCK (videobalance);
494 gst_buffer_unmap (outbuf, data, size);
502 GST_ELEMENT_ERROR (videobalance, STREAM, FORMAT,
503 (NULL), ("Invalid buffer size %d, expected %d", size,
504 videobalance->size));
505 gst_buffer_unmap (outbuf, data, size);
506 return GST_FLOW_ERROR;
509 GST_ERROR_OBJECT (videobalance, "Not negotiated yet");
510 return GST_FLOW_NOT_NEGOTIATED;
514 gst_video_balance_finalize (GObject * object)
516 GList *channels = NULL;
517 GstVideoBalance *balance = GST_VIDEO_BALANCE (object);
519 g_free (balance->tableu[0]);
521 channels = balance->channels;
523 GstColorBalanceChannel *channel = channels->data;
525 g_object_unref (channel);
526 channels->data = NULL;
527 channels = g_list_next (channels);
530 if (balance->channels)
531 g_list_free (balance->channels);
533 G_OBJECT_CLASS (parent_class)->finalize (object);
537 gst_video_balance_class_init (GstVideoBalanceClass * klass)
539 GObjectClass *gobject_class = (GObjectClass *) klass;
540 GstElementClass *gstelement_class = (GstElementClass *) klass;
541 GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
543 GST_DEBUG_CATEGORY_INIT (videobalance_debug, "videobalance", 0,
546 gobject_class->finalize = gst_video_balance_finalize;
547 gobject_class->set_property = gst_video_balance_set_property;
548 gobject_class->get_property = gst_video_balance_get_property;
550 g_object_class_install_property (gobject_class, PROP_CONTRAST,
551 g_param_spec_double ("contrast", "Contrast", "contrast",
552 0.0, 2.0, DEFAULT_PROP_CONTRAST,
553 GST_PARAM_CONTROLLABLE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
554 g_object_class_install_property (gobject_class, PROP_BRIGHTNESS,
555 g_param_spec_double ("brightness", "Brightness", "brightness", -1.0, 1.0,
556 DEFAULT_PROP_BRIGHTNESS,
557 GST_PARAM_CONTROLLABLE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
558 g_object_class_install_property (gobject_class, PROP_HUE,
559 g_param_spec_double ("hue", "Hue", "hue", -1.0, 1.0, DEFAULT_PROP_HUE,
560 GST_PARAM_CONTROLLABLE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
561 g_object_class_install_property (gobject_class, PROP_SATURATION,
562 g_param_spec_double ("saturation", "Saturation", "saturation", 0.0, 2.0,
563 DEFAULT_PROP_SATURATION,
564 GST_PARAM_CONTROLLABLE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
566 gst_element_class_set_details_simple (gstelement_class, "Video balance",
567 "Filter/Effect/Video",
568 "Adjusts brightness, contrast, hue, saturation on a video stream",
569 "David Schleef <ds@schleef.org>");
571 gst_element_class_add_pad_template (gstelement_class,
572 gst_static_pad_template_get (&gst_video_balance_sink_template));
573 gst_element_class_add_pad_template (gstelement_class,
574 gst_static_pad_template_get (&gst_video_balance_src_template));
576 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_video_balance_set_caps);
577 trans_class->transform_ip =
578 GST_DEBUG_FUNCPTR (gst_video_balance_transform_ip);
579 trans_class->before_transform =
580 GST_DEBUG_FUNCPTR (gst_video_balance_before_transform);
584 gst_video_balance_init (GstVideoBalance * videobalance)
586 const gchar *channels[4] = { "HUE", "SATURATION",
587 "BRIGHTNESS", "CONTRAST"
591 /* Initialize propertiews */
592 videobalance->contrast = DEFAULT_PROP_CONTRAST;
593 videobalance->brightness = DEFAULT_PROP_BRIGHTNESS;
594 videobalance->hue = DEFAULT_PROP_HUE;
595 videobalance->saturation = DEFAULT_PROP_SATURATION;
597 videobalance->tableu[0] = g_new (guint8, 256 * 256 * 2);
598 for (i = 0; i < 256; i++) {
599 videobalance->tableu[i] =
600 videobalance->tableu[0] + i * 256 * sizeof (guint8);
601 videobalance->tablev[i] =
602 videobalance->tableu[0] + 256 * 256 * sizeof (guint8) +
603 i * 256 * sizeof (guint8);
606 gst_video_balance_update_properties (videobalance);
608 /* Generate the channels list */
609 for (i = 0; i < G_N_ELEMENTS (channels); i++) {
610 GstColorBalanceChannel *channel;
612 channel = g_object_new (GST_TYPE_COLOR_BALANCE_CHANNEL, NULL);
613 channel->label = g_strdup (channels[i]);
614 channel->min_value = -1000;
615 channel->max_value = 1000;
617 videobalance->channels = g_list_append (videobalance->channels, channel);
622 gst_video_balance_interface_supported (GstImplementsInterface * iface,
625 g_assert (type == GST_TYPE_COLOR_BALANCE);
630 gst_video_balance_interface_init (GstImplementsInterfaceClass * klass)
632 klass->supported = gst_video_balance_interface_supported;
636 gst_video_balance_colorbalance_list_channels (GstColorBalance * balance)
638 GstVideoBalance *videobalance = GST_VIDEO_BALANCE (balance);
640 g_return_val_if_fail (videobalance != NULL, NULL);
641 g_return_val_if_fail (GST_IS_VIDEO_BALANCE (videobalance), NULL);
643 return videobalance->channels;
647 gst_video_balance_colorbalance_set_value (GstColorBalance * balance,
648 GstColorBalanceChannel * channel, gint value)
650 GstVideoBalance *vb = GST_VIDEO_BALANCE (balance);
652 gboolean changed = FALSE;
654 g_return_if_fail (vb != NULL);
655 g_return_if_fail (GST_IS_VIDEO_BALANCE (vb));
656 g_return_if_fail (GST_IS_VIDEO_FILTER (vb));
657 g_return_if_fail (channel->label != NULL);
659 GST_BASE_TRANSFORM_LOCK (vb);
660 GST_OBJECT_LOCK (vb);
661 if (!g_ascii_strcasecmp (channel->label, "HUE")) {
662 new_val = (value + 1000.0) * 2.0 / 2000.0 - 1.0;
663 changed = new_val != vb->hue;
665 } else if (!g_ascii_strcasecmp (channel->label, "SATURATION")) {
666 new_val = (value + 1000.0) * 2.0 / 2000.0;
667 changed = new_val != vb->saturation;
668 vb->saturation = new_val;
669 } else if (!g_ascii_strcasecmp (channel->label, "BRIGHTNESS")) {
670 new_val = (value + 1000.0) * 2.0 / 2000.0 - 1.0;
671 changed = new_val != vb->brightness;
672 vb->brightness = new_val;
673 } else if (!g_ascii_strcasecmp (channel->label, "CONTRAST")) {
674 new_val = (value + 1000.0) * 2.0 / 2000.0;
675 changed = new_val != vb->contrast;
676 vb->contrast = new_val;
680 gst_video_balance_update_properties (vb);
681 GST_OBJECT_UNLOCK (vb);
682 GST_BASE_TRANSFORM_UNLOCK (vb);
685 gst_color_balance_value_changed (balance, channel,
686 gst_color_balance_get_value (balance, channel));
691 gst_video_balance_colorbalance_get_value (GstColorBalance * balance,
692 GstColorBalanceChannel * channel)
694 GstVideoBalance *vb = GST_VIDEO_BALANCE (balance);
697 g_return_val_if_fail (vb != NULL, 0);
698 g_return_val_if_fail (GST_IS_VIDEO_BALANCE (vb), 0);
699 g_return_val_if_fail (channel->label != NULL, 0);
701 if (!g_ascii_strcasecmp (channel->label, "HUE")) {
702 value = (vb->hue + 1) * 2000.0 / 2.0 - 1000.0;
703 } else if (!g_ascii_strcasecmp (channel->label, "SATURATION")) {
704 value = vb->saturation * 2000.0 / 2.0 - 1000.0;
705 } else if (!g_ascii_strcasecmp (channel->label, "BRIGHTNESS")) {
706 value = (vb->brightness + 1) * 2000.0 / 2.0 - 1000.0;
707 } else if (!g_ascii_strcasecmp (channel->label, "CONTRAST")) {
708 value = vb->contrast * 2000.0 / 2.0 - 1000.0;
715 gst_video_balance_colorbalance_init (GstColorBalanceClass * iface)
717 GST_COLOR_BALANCE_TYPE (iface) = GST_COLOR_BALANCE_SOFTWARE;
718 iface->list_channels = gst_video_balance_colorbalance_list_channels;
719 iface->set_value = gst_video_balance_colorbalance_set_value;
720 iface->get_value = gst_video_balance_colorbalance_get_value;
723 static GstColorBalanceChannel *
724 gst_video_balance_find_channel (GstVideoBalance * balance, const gchar * label)
728 for (l = balance->channels; l; l = l->next) {
729 GstColorBalanceChannel *channel = l->data;
731 if (g_ascii_strcasecmp (channel->label, label) == 0)
738 gst_video_balance_set_property (GObject * object, guint prop_id,
739 const GValue * value, GParamSpec * pspec)
741 GstVideoBalance *balance = GST_VIDEO_BALANCE (object);
743 const gchar *label = NULL;
745 GST_BASE_TRANSFORM_LOCK (balance);
746 GST_OBJECT_LOCK (balance);
749 d = g_value_get_double (value);
750 GST_DEBUG_OBJECT (balance, "Changing contrast from %lf to %lf",
751 balance->contrast, d);
752 if (d != balance->contrast)
754 balance->contrast = d;
756 case PROP_BRIGHTNESS:
757 d = g_value_get_double (value);
758 GST_DEBUG_OBJECT (balance, "Changing brightness from %lf to %lf",
759 balance->brightness, d);
760 if (d != balance->brightness)
761 label = "BRIGHTNESS";
762 balance->brightness = d;
765 d = g_value_get_double (value);
766 GST_DEBUG_OBJECT (balance, "Changing hue from %lf to %lf", balance->hue,
768 if (d != balance->hue)
772 case PROP_SATURATION:
773 d = g_value_get_double (value);
774 GST_DEBUG_OBJECT (balance, "Changing saturation from %lf to %lf",
775 balance->saturation, d);
776 if (d != balance->saturation)
777 label = "SATURATION";
778 balance->saturation = d;
781 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
785 gst_video_balance_update_properties (balance);
786 GST_OBJECT_UNLOCK (balance);
787 GST_BASE_TRANSFORM_UNLOCK (balance);
790 GstColorBalanceChannel *channel =
791 gst_video_balance_find_channel (balance, label);
792 gst_color_balance_value_changed (GST_COLOR_BALANCE (balance), channel,
793 gst_color_balance_get_value (GST_COLOR_BALANCE (balance), channel));
798 gst_video_balance_get_property (GObject * object, guint prop_id, GValue * value,
801 GstVideoBalance *balance = GST_VIDEO_BALANCE (object);
805 g_value_set_double (value, balance->contrast);
807 case PROP_BRIGHTNESS:
808 g_value_set_double (value, balance->brightness);
811 g_value_set_double (value, balance->hue);
813 case PROP_SATURATION:
814 g_value_set_double (value, balance->saturation);
817 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);