3 * Copyright (C) <2010-2015> Luis de Bethencourt <luis@debethencourt.com>
5 * Burn - curve adjustment video effect.
6 * Based on Pete Warden's FreeFrame plugin with the same name.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
26 * Alternatively, the contents of this file may be used under the
27 * GNU Lesser General Public License Version 2.1 (the "LGPL"), in
28 * which case the following provisions apply instead of the ones
31 * This library is free software; you can redistribute it and/or
32 * modify it under the terms of the GNU Library General Public
33 * License as published by the Free Software Foundation; either
34 * version 2 of the License, or (at your option) any later version.
36 * This library is distributed in the hope that it will be useful,
37 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
39 * Library General Public License for more details.
41 * You should have received a copy of the GNU Library General Public
42 * License along with this library; if not, write to the
43 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
44 * Boston, MA 02110-1301, USA.
48 * SECTION:element-burn
51 * Burn adjusts the colors of a video stream in realtime.
53 * ## Example launch line
55 * gst-launch-1.0 -v videotestsrc ! burn ! videoconvert ! autovideosink
56 * ]| This pipeline shows the effect of burn on a test stream
69 #include "gstgaudieffectsorc.h"
71 GST_DEBUG_CATEGORY_STATIC (gst_burn_debug);
72 #define GST_CAT_DEFAULT gst_burn_debug
74 #define gst_burn_parent_class parent_class
75 G_DEFINE_TYPE (GstBurn, gst_burn, GST_TYPE_VIDEO_FILTER);
76 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (burn, "burn", GST_RANK_NONE,
77 GST_TYPE_BURN, GST_DEBUG_CATEGORY_INIT (gst_burn_debug, "burn", 0,
80 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
81 #define CAPS_STR GST_VIDEO_CAPS_MAKE ("{ BGRx, RGBx }")
83 #define CAPS_STR GST_VIDEO_CAPS_MAKE ("{ xBGR, xRGB }")
86 /* Filter signals and args. */
100 #define DEFAULT_ADJUSTMENT 175
102 /* The capabilities of the inputs and outputs. */
104 static GstStaticPadTemplate gst_burn_sink_template =
105 GST_STATIC_PAD_TEMPLATE ("sink",
108 GST_STATIC_CAPS (CAPS_STR)
111 static GstStaticPadTemplate gst_burn_src_template =
112 GST_STATIC_PAD_TEMPLATE ("src",
115 GST_STATIC_CAPS (CAPS_STR)
118 static void gst_burn_set_property (GObject * object, guint prop_id,
119 const GValue * value, GParamSpec * pspec);
120 static void gst_burn_get_property (GObject * object, guint prop_id,
121 GValue * value, GParamSpec * pspec);
123 static void gst_burn_finalize (GObject * object);
125 static GstFlowReturn gst_burn_transform_frame (GstVideoFilter * vfilter,
126 GstVideoFrame * in_frame, GstVideoFrame * out_frame);
128 /* GObject vmethod implementations */
130 /* Initialize the burn's class. */
132 gst_burn_class_init (GstBurnClass * klass)
134 GObjectClass *gobject_class = (GObjectClass *) klass;
135 GstElementClass *gstelement_class = (GstElementClass *) klass;
136 GstVideoFilterClass *vfilter_class = (GstVideoFilterClass *) klass;
138 gst_element_class_set_static_metadata (gstelement_class, "Burn",
139 "Filter/Effect/Video",
140 "Burn adjusts the colors in the video signal.",
141 "Luis de Bethencourt <luis@debethencourt.com>");
143 gst_element_class_add_static_pad_template (gstelement_class,
144 &gst_burn_sink_template);
145 gst_element_class_add_static_pad_template (gstelement_class,
146 &gst_burn_src_template);
148 gobject_class->set_property = gst_burn_set_property;
149 gobject_class->get_property = gst_burn_get_property;
150 gobject_class->finalize = gst_burn_finalize;
152 g_object_class_install_property (gobject_class, PROP_ADJUSTMENT,
153 g_param_spec_uint ("adjustment", "Adjustment",
154 "Adjustment parameter", 0, 256, DEFAULT_ADJUSTMENT,
155 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
157 vfilter_class->transform_frame = GST_DEBUG_FUNCPTR (gst_burn_transform_frame);
160 /* Initialize the element,
161 * instantiate pads and add them to element,
162 * set pad callback functions, and
163 * initialize instance structure.
166 gst_burn_init (GstBurn * filter)
168 filter->adjustment = DEFAULT_ADJUSTMENT;
172 gst_burn_set_property (GObject * object, guint prop_id,
173 const GValue * value, GParamSpec * pspec)
175 GstBurn *filter = GST_BURN (object);
178 case PROP_ADJUSTMENT:
179 filter->adjustment = g_value_get_uint (value);
182 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
188 gst_burn_get_property (GObject * object, guint prop_id,
189 GValue * value, GParamSpec * pspec)
191 GstBurn *filter = GST_BURN (object);
193 GST_OBJECT_LOCK (filter);
195 case PROP_ADJUSTMENT:
196 g_value_set_uint (value, filter->adjustment);
199 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
202 GST_OBJECT_UNLOCK (filter);
206 gst_burn_finalize (GObject * object)
208 G_OBJECT_CLASS (parent_class)->finalize (object);
211 /* GstElement vmethod implementations */
213 /* Actual processing. */
215 gst_burn_transform_frame (GstVideoFilter * vfilter,
216 GstVideoFrame * in_frame, GstVideoFrame * out_frame)
218 GstBurn *filter = GST_BURN (vfilter);
219 gint video_size, adjustment;
221 GstClockTime timestamp;
224 src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
225 dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
227 video_size = GST_VIDEO_FRAME_WIDTH (in_frame) *
228 GST_VIDEO_FRAME_HEIGHT (in_frame);
230 /* GstController: update the properties */
231 timestamp = GST_BUFFER_TIMESTAMP (in_frame->buffer);
233 gst_segment_to_stream_time (&GST_BASE_TRANSFORM (filter)->segment,
234 GST_FORMAT_TIME, timestamp);
236 GST_DEBUG_OBJECT (filter, "sync to %" GST_TIME_FORMAT,
237 GST_TIME_ARGS (timestamp));
239 if (GST_CLOCK_TIME_IS_VALID (stream_time))
240 gst_object_sync_values (GST_OBJECT (filter), stream_time);
242 GST_OBJECT_LOCK (filter);
243 adjustment = filter->adjustment;
244 GST_OBJECT_UNLOCK (filter);
246 /*** Now the image processing work.... ***/
247 gaudi_orc_burn (dest, src, adjustment, video_size);