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., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, 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-1.0 videotestsrc ! videobalance saturation=0.0 ! videoconvert ! ximagesink
36 * ]| This pipeline converts the image to black and white by setting the
45 #include <gst/math-compat.h>
47 #include "gstvideobalance.h"
50 #include <gst/video/colorbalance.h>
52 GST_DEBUG_CATEGORY_STATIC (videobalance_debug);
53 #define GST_CAT_DEFAULT videobalance_debug
55 /* GstVideoBalance properties */
56 #define DEFAULT_PROP_CONTRAST 1.0
57 #define DEFAULT_PROP_BRIGHTNESS 0.0
58 #define DEFAULT_PROP_HUE 0.0
59 #define DEFAULT_PROP_SATURATION 1.0
70 #define PROCESSING_CAPS \
71 "{ AYUV, ARGB, BGRA, ABGR, RGBA, Y444, xRGB, RGBx, " \
72 "xBGR, BGRx, RGB, BGR, Y42B, YUY2, UYVY, YVYU, " \
73 "I420, YV12, IYUV, Y41B, NV12, NV21 }"
75 static GstStaticPadTemplate gst_video_balance_src_template =
76 GST_STATIC_PAD_TEMPLATE ("src",
79 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (PROCESSING_CAPS) ";"
83 static GstStaticPadTemplate gst_video_balance_sink_template =
84 GST_STATIC_PAD_TEMPLATE ("sink",
87 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (PROCESSING_CAPS) ";"
91 static void gst_video_balance_colorbalance_init (GstColorBalanceInterface *
94 static void gst_video_balance_set_property (GObject * object, guint prop_id,
95 const GValue * value, GParamSpec * pspec);
96 static void gst_video_balance_get_property (GObject * object, guint prop_id,
97 GValue * value, GParamSpec * pspec);
99 #define gst_video_balance_parent_class parent_class
100 G_DEFINE_TYPE_WITH_CODE (GstVideoBalance, gst_video_balance,
101 GST_TYPE_VIDEO_FILTER,
102 G_IMPLEMENT_INTERFACE (GST_TYPE_COLOR_BALANCE,
103 gst_video_balance_colorbalance_init));
106 * look-up tables (LUT).
109 gst_video_balance_update_tables (GstVideoBalance * vb)
112 gdouble y, u, v, hue_cos, hue_sin;
115 for (i = 0; i < 256; i++) {
116 y = 16 + ((i - 16) * vb->contrast + vb->brightness * 255);
121 vb->tabley[i] = rint (y);
124 hue_cos = cos (G_PI * vb->hue);
125 hue_sin = sin (G_PI * vb->hue);
127 /* U/V lookup tables are 2D, since we need both U/V for each table
129 for (i = -128; i < 128; i++) {
130 for (j = -128; j < 128; j++) {
131 u = 128 + ((i * hue_cos + j * hue_sin) * vb->saturation);
132 v = 128 + ((-i * hue_sin + j * hue_cos) * vb->saturation);
141 vb->tableu[i + 128][j + 128] = rint (u);
142 vb->tablev[i + 128][j + 128] = rint (v);
148 gst_video_balance_is_passthrough (GstVideoBalance * videobalance)
150 return videobalance->contrast == 1.0 &&
151 videobalance->brightness == 0.0 &&
152 videobalance->hue == 0.0 && videobalance->saturation == 1.0;
156 gst_video_balance_update_properties (GstVideoBalance * videobalance)
158 gboolean passthrough;
159 GstBaseTransform *base = GST_BASE_TRANSFORM (videobalance);
161 GST_OBJECT_LOCK (videobalance);
162 passthrough = gst_video_balance_is_passthrough (videobalance);
164 gst_video_balance_update_tables (videobalance);
165 GST_OBJECT_UNLOCK (videobalance);
167 gst_base_transform_set_passthrough (base, passthrough);
171 gst_video_balance_planar_yuv (GstVideoBalance * videobalance,
172 GstVideoFrame * frame)
176 guint8 *udata, *vdata;
177 gint ystride, ustride, vstride;
179 gint width2, height2;
180 guint8 *tabley = videobalance->tabley;
181 guint8 **tableu = videobalance->tableu;
182 guint8 **tablev = videobalance->tablev;
184 width = GST_VIDEO_FRAME_WIDTH (frame);
185 height = GST_VIDEO_FRAME_HEIGHT (frame);
187 ydata = GST_VIDEO_FRAME_PLANE_DATA (frame, 0);
188 ystride = GST_VIDEO_FRAME_PLANE_STRIDE (frame, 0);
190 for (y = 0; y < height; y++) {
193 yptr = ydata + y * ystride;
194 for (x = 0; x < width; x++) {
195 *yptr = tabley[*yptr];
200 width2 = GST_VIDEO_FRAME_COMP_WIDTH (frame, 1);
201 height2 = GST_VIDEO_FRAME_COMP_HEIGHT (frame, 1);
203 udata = GST_VIDEO_FRAME_PLANE_DATA (frame, 1);
204 vdata = GST_VIDEO_FRAME_PLANE_DATA (frame, 2);
205 ustride = GST_VIDEO_FRAME_PLANE_STRIDE (frame, 1);
206 vstride = GST_VIDEO_FRAME_PLANE_STRIDE (frame, 2);
208 for (y = 0; y < height2; y++) {
212 uptr = udata + y * ustride;
213 vptr = vdata + y * vstride;
215 for (x = 0; x < width2; x++) {
219 *uptr++ = tableu[u1][v1];
220 *vptr++ = tablev[u1][v1];
226 gst_video_balance_semiplanar_yuv (GstVideoBalance * videobalance,
227 GstVideoFrame * frame)
232 gint ystride, uvstride;
234 gint width2, height2;
235 guint8 *tabley = videobalance->tabley;
236 guint8 **tableu = videobalance->tableu;
237 guint8 **tablev = videobalance->tablev;
240 width = GST_VIDEO_FRAME_WIDTH (frame);
241 height = GST_VIDEO_FRAME_HEIGHT (frame);
243 ydata = GST_VIDEO_FRAME_PLANE_DATA (frame, 0);
244 ystride = GST_VIDEO_FRAME_PLANE_STRIDE (frame, 0);
246 for (y = 0; y < height; y++) {
249 yptr = ydata + y * ystride;
250 for (x = 0; x < width; x++) {
251 *yptr = tabley[*yptr];
256 width2 = GST_VIDEO_FRAME_COMP_WIDTH (frame, 1);
257 height2 = GST_VIDEO_FRAME_COMP_HEIGHT (frame, 1);
259 uvdata = GST_VIDEO_FRAME_PLANE_DATA (frame, 1);
260 uvstride = GST_VIDEO_FRAME_PLANE_STRIDE (frame, 1);
262 upos = GST_VIDEO_INFO_FORMAT (&frame->info) == GST_VIDEO_FORMAT_NV12 ? 0 : 1;
263 vpos = GST_VIDEO_INFO_FORMAT (&frame->info) == GST_VIDEO_FORMAT_NV12 ? 1 : 0;
265 for (y = 0; y < height2; y++) {
269 uvptr = uvdata + y * uvstride;
271 for (x = 0; x < width2; x++) {
275 uvptr[upos] = tableu[u1][v1];
276 uvptr[vpos] = tablev[u1][v1];
283 gst_video_balance_packed_yuv (GstVideoBalance * videobalance,
284 GstVideoFrame * frame)
287 guint8 *ydata, *udata, *vdata;
288 gint yoff, uoff, voff;
290 gint width2, height2;
291 guint8 *tabley = videobalance->tabley;
292 guint8 **tableu = videobalance->tableu;
293 guint8 **tablev = videobalance->tablev;
295 width = GST_VIDEO_FRAME_WIDTH (frame);
296 height = GST_VIDEO_FRAME_HEIGHT (frame);
298 stride = GST_VIDEO_FRAME_PLANE_STRIDE (frame, 0);
299 ydata = GST_VIDEO_FRAME_COMP_DATA (frame, 0);
300 yoff = GST_VIDEO_FRAME_COMP_PSTRIDE (frame, 0);
302 for (y = 0; y < height; y++) {
305 yptr = ydata + y * stride;
306 for (x = 0; x < width; x++) {
307 *yptr = tabley[*yptr];
312 width2 = GST_VIDEO_FRAME_COMP_WIDTH (frame, 1);
313 height2 = GST_VIDEO_FRAME_COMP_HEIGHT (frame, 1);
315 udata = GST_VIDEO_FRAME_COMP_DATA (frame, 1);
316 vdata = GST_VIDEO_FRAME_COMP_DATA (frame, 2);
317 uoff = GST_VIDEO_FRAME_COMP_PSTRIDE (frame, 1);
318 voff = GST_VIDEO_FRAME_COMP_PSTRIDE (frame, 2);
320 for (y = 0; y < height2; y++) {
324 uptr = udata + y * stride;
325 vptr = vdata + y * stride;
327 for (x = 0; x < width2; x++) {
331 *uptr = tableu[u1][v1];
332 *vptr = tablev[u1][v1];
340 static const int cog_ycbcr_to_rgb_matrix_8bit_sdtv[] = {
342 298, -100, -208, 34707,
346 static const gint cog_rgb_to_ycbcr_matrix_8bit_sdtv[] = {
348 -38, -74, 112, 32768,
349 112, -94, -18, 32768,
352 #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)
355 gst_video_balance_packed_rgb (GstVideoBalance * videobalance,
356 GstVideoFrame * frame)
359 gint width, stride, row_wrap;
366 guint8 *tabley = videobalance->tabley;
367 guint8 **tableu = videobalance->tableu;
368 guint8 **tablev = videobalance->tablev;
370 width = GST_VIDEO_FRAME_WIDTH (frame);
371 height = GST_VIDEO_FRAME_HEIGHT (frame);
373 offsets[0] = GST_VIDEO_FRAME_COMP_OFFSET (frame, 0);
374 offsets[1] = GST_VIDEO_FRAME_COMP_OFFSET (frame, 1);
375 offsets[2] = GST_VIDEO_FRAME_COMP_OFFSET (frame, 2);
377 data = GST_VIDEO_FRAME_PLANE_DATA (frame, 0);
378 stride = GST_VIDEO_FRAME_PLANE_STRIDE (frame, 0);
380 pixel_stride = GST_VIDEO_FRAME_COMP_PSTRIDE (frame, 0);
381 row_wrap = stride - pixel_stride * width;
383 for (i = 0; i < height; i++) {
384 for (j = 0; j < width; j++) {
385 r = data[offsets[0]];
386 g = data[offsets[1]];
387 b = data[offsets[2]];
389 y = APPLY_MATRIX (cog_rgb_to_ycbcr_matrix_8bit_sdtv, 0, r, g, b);
390 u_tmp = APPLY_MATRIX (cog_rgb_to_ycbcr_matrix_8bit_sdtv, 1, r, g, b);
391 v_tmp = APPLY_MATRIX (cog_rgb_to_ycbcr_matrix_8bit_sdtv, 2, r, g, b);
393 y = CLAMP (y, 0, 255);
394 u_tmp = CLAMP (u_tmp, 0, 255);
395 v_tmp = CLAMP (v_tmp, 0, 255);
398 u = tableu[u_tmp][v_tmp];
399 v = tablev[u_tmp][v_tmp];
401 r = APPLY_MATRIX (cog_ycbcr_to_rgb_matrix_8bit_sdtv, 0, y, u, v);
402 g = APPLY_MATRIX (cog_ycbcr_to_rgb_matrix_8bit_sdtv, 1, y, u, v);
403 b = APPLY_MATRIX (cog_ycbcr_to_rgb_matrix_8bit_sdtv, 2, y, u, v);
405 data[offsets[0]] = CLAMP (r, 0, 255);
406 data[offsets[1]] = CLAMP (g, 0, 255);
407 data[offsets[2]] = CLAMP (b, 0, 255);
408 data += pixel_stride;
414 /* get notified of caps and plug in the correct process function */
416 gst_video_balance_set_info (GstVideoFilter * vfilter, GstCaps * incaps,
417 GstVideoInfo * in_info, GstCaps * outcaps, GstVideoInfo * out_info)
419 GstVideoBalance *videobalance = GST_VIDEO_BALANCE (vfilter);
421 GST_DEBUG_OBJECT (videobalance,
422 "in %" GST_PTR_FORMAT " out %" GST_PTR_FORMAT, incaps, outcaps);
424 videobalance->process = NULL;
426 switch (GST_VIDEO_INFO_FORMAT (in_info)) {
427 case GST_VIDEO_FORMAT_I420:
428 case GST_VIDEO_FORMAT_YV12:
429 case GST_VIDEO_FORMAT_Y41B:
430 case GST_VIDEO_FORMAT_Y42B:
431 case GST_VIDEO_FORMAT_Y444:
432 videobalance->process = gst_video_balance_planar_yuv;
434 case GST_VIDEO_FORMAT_YUY2:
435 case GST_VIDEO_FORMAT_UYVY:
436 case GST_VIDEO_FORMAT_AYUV:
437 case GST_VIDEO_FORMAT_YVYU:
438 videobalance->process = gst_video_balance_packed_yuv;
440 case GST_VIDEO_FORMAT_NV12:
441 case GST_VIDEO_FORMAT_NV21:
442 videobalance->process = gst_video_balance_semiplanar_yuv;
444 case GST_VIDEO_FORMAT_ARGB:
445 case GST_VIDEO_FORMAT_ABGR:
446 case GST_VIDEO_FORMAT_RGBA:
447 case GST_VIDEO_FORMAT_BGRA:
448 case GST_VIDEO_FORMAT_xRGB:
449 case GST_VIDEO_FORMAT_xBGR:
450 case GST_VIDEO_FORMAT_RGBx:
451 case GST_VIDEO_FORMAT_BGRx:
452 case GST_VIDEO_FORMAT_RGB:
453 case GST_VIDEO_FORMAT_BGR:
454 videobalance->process = gst_video_balance_packed_rgb;
457 if (!gst_video_balance_is_passthrough (videobalance))
467 GST_ERROR_OBJECT (videobalance, "unknown format %" GST_PTR_FORMAT, incaps);
473 gst_video_balance_before_transform (GstBaseTransform * base, GstBuffer * buf)
475 GstVideoBalance *balance = GST_VIDEO_BALANCE (base);
476 GstClockTime timestamp, stream_time;
478 timestamp = GST_BUFFER_TIMESTAMP (buf);
480 gst_segment_to_stream_time (&base->segment, GST_FORMAT_TIME, timestamp);
482 GST_DEBUG_OBJECT (balance, "sync to %" GST_TIME_FORMAT,
483 GST_TIME_ARGS (timestamp));
485 if (GST_CLOCK_TIME_IS_VALID (stream_time))
486 gst_object_sync_values (GST_OBJECT (balance), stream_time);
490 gst_video_balance_transform_caps (GstBaseTransform * trans,
491 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
493 GstVideoBalance *balance = GST_VIDEO_BALANCE (trans);
496 if (!gst_video_balance_is_passthrough (balance)) {
497 static GstStaticCaps raw_caps =
498 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (PROCESSING_CAPS));
499 GstCaps *tmp = gst_static_caps_get (&raw_caps);
501 caps = gst_caps_intersect (caps, tmp);
502 gst_caps_unref (tmp);
505 ret = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
506 gst_caps_unref (caps);
512 ret = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
514 ret = gst_caps_ref (caps);
522 gst_video_balance_transform_frame_ip (GstVideoFilter * vfilter,
523 GstVideoFrame * frame)
525 GstVideoBalance *videobalance = GST_VIDEO_BALANCE (vfilter);
527 if (!videobalance->process)
530 GST_OBJECT_LOCK (videobalance);
531 videobalance->process (videobalance, frame);
532 GST_OBJECT_UNLOCK (videobalance);
539 GST_ERROR_OBJECT (videobalance, "Not negotiated yet");
540 return GST_FLOW_NOT_NEGOTIATED;
545 gst_video_balance_finalize (GObject * object)
547 GList *channels = NULL;
548 GstVideoBalance *balance = GST_VIDEO_BALANCE (object);
550 g_free (balance->tableu[0]);
552 channels = balance->channels;
554 GstColorBalanceChannel *channel = channels->data;
556 g_object_unref (channel);
557 channels->data = NULL;
558 channels = g_list_next (channels);
561 if (balance->channels)
562 g_list_free (balance->channels);
564 G_OBJECT_CLASS (parent_class)->finalize (object);
568 gst_video_balance_class_init (GstVideoBalanceClass * klass)
570 GObjectClass *gobject_class = (GObjectClass *) klass;
571 GstElementClass *gstelement_class = (GstElementClass *) klass;
572 GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
573 GstVideoFilterClass *vfilter_class = (GstVideoFilterClass *) klass;
575 GST_DEBUG_CATEGORY_INIT (videobalance_debug, "videobalance", 0,
578 gobject_class->finalize = gst_video_balance_finalize;
579 gobject_class->set_property = gst_video_balance_set_property;
580 gobject_class->get_property = gst_video_balance_get_property;
582 g_object_class_install_property (gobject_class, PROP_CONTRAST,
583 g_param_spec_double ("contrast", "Contrast", "contrast",
584 0.0, 2.0, DEFAULT_PROP_CONTRAST,
585 GST_PARAM_CONTROLLABLE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
586 g_object_class_install_property (gobject_class, PROP_BRIGHTNESS,
587 g_param_spec_double ("brightness", "Brightness", "brightness", -1.0, 1.0,
588 DEFAULT_PROP_BRIGHTNESS,
589 GST_PARAM_CONTROLLABLE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
590 g_object_class_install_property (gobject_class, PROP_HUE,
591 g_param_spec_double ("hue", "Hue", "hue", -1.0, 1.0, DEFAULT_PROP_HUE,
592 GST_PARAM_CONTROLLABLE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
593 g_object_class_install_property (gobject_class, PROP_SATURATION,
594 g_param_spec_double ("saturation", "Saturation", "saturation", 0.0, 2.0,
595 DEFAULT_PROP_SATURATION,
596 GST_PARAM_CONTROLLABLE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
598 gst_element_class_set_static_metadata (gstelement_class, "Video balance",
599 "Filter/Effect/Video",
600 "Adjusts brightness, contrast, hue, saturation on a video stream",
601 "David Schleef <ds@schleef.org>");
603 gst_element_class_add_pad_template (gstelement_class,
604 gst_static_pad_template_get (&gst_video_balance_sink_template));
605 gst_element_class_add_pad_template (gstelement_class,
606 gst_static_pad_template_get (&gst_video_balance_src_template));
608 trans_class->before_transform =
609 GST_DEBUG_FUNCPTR (gst_video_balance_before_transform);
610 trans_class->transform_ip_on_passthrough = FALSE;
611 trans_class->transform_caps =
612 GST_DEBUG_FUNCPTR (gst_video_balance_transform_caps);
614 vfilter_class->set_info = GST_DEBUG_FUNCPTR (gst_video_balance_set_info);
615 vfilter_class->transform_frame_ip =
616 GST_DEBUG_FUNCPTR (gst_video_balance_transform_frame_ip);
620 gst_video_balance_init (GstVideoBalance * videobalance)
622 const gchar *channels[4] = { "HUE", "SATURATION",
623 "BRIGHTNESS", "CONTRAST"
627 /* Initialize propertiews */
628 videobalance->contrast = DEFAULT_PROP_CONTRAST;
629 videobalance->brightness = DEFAULT_PROP_BRIGHTNESS;
630 videobalance->hue = DEFAULT_PROP_HUE;
631 videobalance->saturation = DEFAULT_PROP_SATURATION;
633 videobalance->tableu[0] = g_new (guint8, 256 * 256 * 2);
634 for (i = 0; i < 256; i++) {
635 videobalance->tableu[i] =
636 videobalance->tableu[0] + i * 256 * sizeof (guint8);
637 videobalance->tablev[i] =
638 videobalance->tableu[0] + 256 * 256 * sizeof (guint8) +
639 i * 256 * sizeof (guint8);
642 gst_video_balance_update_properties (videobalance);
644 /* Generate the channels list */
645 for (i = 0; i < G_N_ELEMENTS (channels); i++) {
646 GstColorBalanceChannel *channel;
648 channel = g_object_new (GST_TYPE_COLOR_BALANCE_CHANNEL, NULL);
649 channel->label = g_strdup (channels[i]);
650 channel->min_value = -1000;
651 channel->max_value = 1000;
653 videobalance->channels = g_list_append (videobalance->channels, channel);
658 gst_video_balance_colorbalance_list_channels (GstColorBalance * balance)
660 GstVideoBalance *videobalance = GST_VIDEO_BALANCE (balance);
662 g_return_val_if_fail (videobalance != NULL, NULL);
663 g_return_val_if_fail (GST_IS_VIDEO_BALANCE (videobalance), NULL);
665 return videobalance->channels;
669 gst_video_balance_colorbalance_set_value (GstColorBalance * balance,
670 GstColorBalanceChannel * channel, gint value)
672 GstVideoBalance *vb = GST_VIDEO_BALANCE (balance);
674 gboolean changed = FALSE;
676 g_return_if_fail (vb != NULL);
677 g_return_if_fail (GST_IS_VIDEO_BALANCE (vb));
678 g_return_if_fail (GST_IS_VIDEO_FILTER (vb));
679 g_return_if_fail (channel->label != NULL);
681 GST_OBJECT_LOCK (vb);
682 if (!g_ascii_strcasecmp (channel->label, "HUE")) {
683 new_val = (value + 1000.0) * 2.0 / 2000.0 - 1.0;
684 changed = new_val != vb->hue;
686 } else if (!g_ascii_strcasecmp (channel->label, "SATURATION")) {
687 new_val = (value + 1000.0) * 2.0 / 2000.0;
688 changed = new_val != vb->saturation;
689 vb->saturation = new_val;
690 } else if (!g_ascii_strcasecmp (channel->label, "BRIGHTNESS")) {
691 new_val = (value + 1000.0) * 2.0 / 2000.0 - 1.0;
692 changed = new_val != vb->brightness;
693 vb->brightness = new_val;
694 } else if (!g_ascii_strcasecmp (channel->label, "CONTRAST")) {
695 new_val = (value + 1000.0) * 2.0 / 2000.0;
696 changed = new_val != vb->contrast;
697 vb->contrast = new_val;
699 GST_OBJECT_UNLOCK (vb);
702 gst_video_balance_update_properties (vb);
705 gst_color_balance_value_changed (balance, channel,
706 gst_color_balance_get_value (balance, channel));
711 gst_video_balance_colorbalance_get_value (GstColorBalance * balance,
712 GstColorBalanceChannel * channel)
714 GstVideoBalance *vb = GST_VIDEO_BALANCE (balance);
717 g_return_val_if_fail (vb != NULL, 0);
718 g_return_val_if_fail (GST_IS_VIDEO_BALANCE (vb), 0);
719 g_return_val_if_fail (channel->label != NULL, 0);
721 if (!g_ascii_strcasecmp (channel->label, "HUE")) {
722 value = (vb->hue + 1) * 2000.0 / 2.0 - 1000.0;
723 } else if (!g_ascii_strcasecmp (channel->label, "SATURATION")) {
724 value = vb->saturation * 2000.0 / 2.0 - 1000.0;
725 } else if (!g_ascii_strcasecmp (channel->label, "BRIGHTNESS")) {
726 value = (vb->brightness + 1) * 2000.0 / 2.0 - 1000.0;
727 } else if (!g_ascii_strcasecmp (channel->label, "CONTRAST")) {
728 value = vb->contrast * 2000.0 / 2.0 - 1000.0;
734 static GstColorBalanceType
735 gst_video_balance_colorbalance_get_balance_type (GstColorBalance * balance)
737 return GST_COLOR_BALANCE_SOFTWARE;
741 gst_video_balance_colorbalance_init (GstColorBalanceInterface * iface)
743 iface->list_channels = gst_video_balance_colorbalance_list_channels;
744 iface->set_value = gst_video_balance_colorbalance_set_value;
745 iface->get_value = gst_video_balance_colorbalance_get_value;
746 iface->get_balance_type = gst_video_balance_colorbalance_get_balance_type;
749 static GstColorBalanceChannel *
750 gst_video_balance_find_channel (GstVideoBalance * balance, const gchar * label)
754 for (l = balance->channels; l; l = l->next) {
755 GstColorBalanceChannel *channel = l->data;
757 if (g_ascii_strcasecmp (channel->label, label) == 0)
764 gst_video_balance_set_property (GObject * object, guint prop_id,
765 const GValue * value, GParamSpec * pspec)
767 GstVideoBalance *balance = GST_VIDEO_BALANCE (object);
769 const gchar *label = NULL;
771 GST_OBJECT_LOCK (balance);
774 d = g_value_get_double (value);
775 GST_DEBUG_OBJECT (balance, "Changing contrast from %lf to %lf",
776 balance->contrast, d);
777 if (d != balance->contrast)
779 balance->contrast = d;
781 case PROP_BRIGHTNESS:
782 d = g_value_get_double (value);
783 GST_DEBUG_OBJECT (balance, "Changing brightness from %lf to %lf",
784 balance->brightness, d);
785 if (d != balance->brightness)
786 label = "BRIGHTNESS";
787 balance->brightness = d;
790 d = g_value_get_double (value);
791 GST_DEBUG_OBJECT (balance, "Changing hue from %lf to %lf", balance->hue,
793 if (d != balance->hue)
797 case PROP_SATURATION:
798 d = g_value_get_double (value);
799 GST_DEBUG_OBJECT (balance, "Changing saturation from %lf to %lf",
800 balance->saturation, d);
801 if (d != balance->saturation)
802 label = "SATURATION";
803 balance->saturation = d;
806 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
810 GST_OBJECT_UNLOCK (balance);
811 gst_video_balance_update_properties (balance);
814 GstColorBalanceChannel *channel =
815 gst_video_balance_find_channel (balance, label);
816 gst_color_balance_value_changed (GST_COLOR_BALANCE (balance), channel,
817 gst_color_balance_get_value (GST_COLOR_BALANCE (balance), channel));
822 gst_video_balance_get_property (GObject * object, guint prop_id, GValue * value,
825 GstVideoBalance *balance = GST_VIDEO_BALANCE (object);
829 g_value_set_double (value, balance->contrast);
831 case PROP_BRIGHTNESS:
832 g_value_set_double (value, balance->brightness);
835 g_value_set_double (value, balance->hue);
837 case PROP_SATURATION:
838 g_value_set_double (value, balance->saturation);
841 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);