Move files from gst-plugins-bad into the "subprojects/gst-plugins-bad/" subdir
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-bad / gst / gaudieffects / gstburn.c
1 /*
2  * GStreamer
3  * Copyright (C) <2010-2015> Luis de Bethencourt <luis@debethencourt.com>
4  *
5  * Burn - curve adjustment video effect.
6  * Based on Pete Warden's FreeFrame plugin with the same name.
7  *
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:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
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.
25  *
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
29  * mentioned above:
30  *
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.
35  *
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.
40  *
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.
45  */
46
47 /**
48  * SECTION:element-burn
49  * @title: burn
50  *
51  * Burn adjusts the colors of a video stream in realtime.
52  *
53  * ## Example launch line
54  * |[
55  * gst-launch-1.0 -v videotestsrc ! burn ! videoconvert ! autovideosink
56  * ]| This pipeline shows the effect of burn on a test stream
57  *
58  */
59
60 #ifdef HAVE_CONFIG_H
61 #  include <config.h>
62 #endif
63
64 #include <gst/gst.h>
65 #include <math.h>
66
67 #include "gstburn.h"
68
69 #include "gstgaudieffectsorc.h"
70
71 GST_DEBUG_CATEGORY_STATIC (gst_burn_debug);
72 #define GST_CAT_DEFAULT gst_burn_debug
73
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,
78         "Template burn"));
79
80 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
81 #define CAPS_STR GST_VIDEO_CAPS_MAKE ("{  BGRx, RGBx }")
82 #else
83 #define CAPS_STR GST_VIDEO_CAPS_MAKE ("{  xBGR, xRGB }")
84 #endif
85
86 /* Filter signals and args. */
87 enum
88 {
89   LAST_SIGNAL
90 };
91
92 enum
93 {
94   PROP_0 = 0,
95   PROP_ADJUSTMENT,
96 };
97
98 /* Initializations */
99
100 #define DEFAULT_ADJUSTMENT 175
101
102 /* The capabilities of the inputs and outputs. */
103
104 static GstStaticPadTemplate gst_burn_sink_template =
105 GST_STATIC_PAD_TEMPLATE ("sink",
106     GST_PAD_SINK,
107     GST_PAD_ALWAYS,
108     GST_STATIC_CAPS (CAPS_STR)
109     );
110
111 static GstStaticPadTemplate gst_burn_src_template =
112 GST_STATIC_PAD_TEMPLATE ("src",
113     GST_PAD_SRC,
114     GST_PAD_ALWAYS,
115     GST_STATIC_CAPS (CAPS_STR)
116     );
117
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);
122
123 static void gst_burn_finalize (GObject * object);
124
125 static GstFlowReturn gst_burn_transform_frame (GstVideoFilter * vfilter,
126     GstVideoFrame * in_frame, GstVideoFrame * out_frame);
127
128 /* GObject vmethod implementations */
129
130 /* Initialize the burn's class. */
131 static void
132 gst_burn_class_init (GstBurnClass * klass)
133 {
134   GObjectClass *gobject_class = (GObjectClass *) klass;
135   GstElementClass *gstelement_class = (GstElementClass *) klass;
136   GstVideoFilterClass *vfilter_class = (GstVideoFilterClass *) klass;
137
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>");
142
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);
147
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;
151
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));
156
157   vfilter_class->transform_frame = GST_DEBUG_FUNCPTR (gst_burn_transform_frame);
158 }
159
160 /* Initialize the element,
161  * instantiate pads and add them to element,
162  * set pad callback functions, and
163  * initialize instance structure.
164  */
165 static void
166 gst_burn_init (GstBurn * filter)
167 {
168   filter->adjustment = DEFAULT_ADJUSTMENT;
169 }
170
171 static void
172 gst_burn_set_property (GObject * object, guint prop_id,
173     const GValue * value, GParamSpec * pspec)
174 {
175   GstBurn *filter = GST_BURN (object);
176
177   switch (prop_id) {
178     case PROP_ADJUSTMENT:
179       filter->adjustment = g_value_get_uint (value);
180       break;
181     default:
182       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
183       break;
184   }
185 }
186
187 static void
188 gst_burn_get_property (GObject * object, guint prop_id,
189     GValue * value, GParamSpec * pspec)
190 {
191   GstBurn *filter = GST_BURN (object);
192
193   GST_OBJECT_LOCK (filter);
194   switch (prop_id) {
195     case PROP_ADJUSTMENT:
196       g_value_set_uint (value, filter->adjustment);
197       break;
198     default:
199       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
200       break;
201   }
202   GST_OBJECT_UNLOCK (filter);
203 }
204
205 static void
206 gst_burn_finalize (GObject * object)
207 {
208   G_OBJECT_CLASS (parent_class)->finalize (object);
209 }
210
211 /* GstElement vmethod implementations */
212
213 /* Actual processing. */
214 static GstFlowReturn
215 gst_burn_transform_frame (GstVideoFilter * vfilter,
216     GstVideoFrame * in_frame, GstVideoFrame * out_frame)
217 {
218   GstBurn *filter = GST_BURN (vfilter);
219   gint video_size, adjustment;
220   guint32 *src, *dest;
221   GstClockTime timestamp;
222   gint64 stream_time;
223
224   src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
225   dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
226
227   video_size = GST_VIDEO_FRAME_WIDTH (in_frame) *
228       GST_VIDEO_FRAME_HEIGHT (in_frame);
229
230   /* GstController: update the properties */
231   timestamp = GST_BUFFER_TIMESTAMP (in_frame->buffer);
232   stream_time =
233       gst_segment_to_stream_time (&GST_BASE_TRANSFORM (filter)->segment,
234       GST_FORMAT_TIME, timestamp);
235
236   GST_DEBUG_OBJECT (filter, "sync to %" GST_TIME_FORMAT,
237       GST_TIME_ARGS (timestamp));
238
239   if (GST_CLOCK_TIME_IS_VALID (stream_time))
240     gst_object_sync_values (GST_OBJECT (filter), stream_time);
241
242   GST_OBJECT_LOCK (filter);
243   adjustment = filter->adjustment;
244   GST_OBJECT_UNLOCK (filter);
245
246   /*** Now the image processing work.... ***/
247   gaudi_orc_burn (dest, src, adjustment, video_size);
248
249   return GST_FLOW_OK;
250 }