2 * Copyright (C) <2009> Sebastian Dröge <sebastian.droege@collabora.co.uk>
4 * EffecTV - Realtime Digital Video Effector
5 * Copyright (C) 2001-2006 FUKUCHI Kentaro
7 * StreakTV - afterimage effector.
8 * Copyright (C) 2001-2002 FUKUCHI Kentaro
10 * This combines the StreakTV and BaltanTV effects, which are
11 * very similar. BaltanTV is used if the feedback property is set
12 * to TRUE, otherwise StreakTV is used.
14 * EffecTV is free software. This library is free software;
15 * you can redistribute it and/or
16 * modify it under the terms of the GNU Library General Public
17 * License as published by the Free Software Foundation; either
18 * version 2 of the License, or (at your option) any later version.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Library General Public License for more details.
25 * You should have received a copy of the GNU Library General Public
26 * License along with this library; if not, write to the
27 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
28 * Boston, MA 02110-1301, USA.
32 * SECTION:element-streaktv
35 * StreakTV makes after images of moving objects.
37 * ## Example launch line
39 * gst-launch-1.0 -v videotestsrc ! streaktv ! videoconvert ! autovideosink
40 * ]| This pipeline shows the effect of streaktv on a test stream.
51 #include "gststreak.h"
52 #include "gsteffectv.h"
54 #define DEFAULT_FEEDBACK FALSE
62 #define gst_streaktv_parent_class parent_class
63 G_DEFINE_TYPE (GstStreakTV, gst_streaktv, GST_TYPE_VIDEO_FILTER);
64 GST_ELEMENT_REGISTER_DEFINE (streaktv, "streaktv", GST_RANK_NONE,
67 static GstStaticPadTemplate gst_streaktv_src_template =
68 GST_STATIC_PAD_TEMPLATE ("src",
71 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ BGRx, RGBx, xBGR, xRGB }"))
74 static GstStaticPadTemplate gst_streaktv_sink_template =
75 GST_STATIC_PAD_TEMPLATE ("sink",
78 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ BGRx, RGBx, xBGR, xRGB }"))
83 gst_streaktv_transform_frame (GstVideoFilter * vfilter,
84 GstVideoFrame * in_frame, GstVideoFrame * out_frame)
86 GstStreakTV *filter = GST_STREAKTV (vfilter);
89 gint video_area, width, height;
90 guint32 **planetable = filter->planetable;
91 gint plane = filter->plane;
92 guint stride_mask, stride_shift, stride;
94 src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
95 dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
97 width = GST_VIDEO_FRAME_WIDTH (in_frame);
98 height = GST_VIDEO_FRAME_HEIGHT (in_frame);
100 video_area = width * height;
102 GST_OBJECT_LOCK (filter);
103 if (filter->feedback) {
104 stride_mask = 0xfcfcfcfc;
108 stride_mask = 0xf8f8f8f8;
113 for (i = 0; i < video_area; i++) {
114 planetable[plane][i] = (src[i] & stride_mask) >> stride_shift;
117 cf = plane & (stride - 1);
118 if (filter->feedback) {
119 for (i = 0; i < video_area; i++) {
120 dest[i] = planetable[cf][i]
121 + planetable[cf + stride][i]
122 + planetable[cf + stride * 2][i]
123 + planetable[cf + stride * 3][i];
124 planetable[plane][i] = (dest[i] & stride_mask) >> stride_shift;
127 for (i = 0; i < video_area; i++) {
128 dest[i] = planetable[cf][i]
129 + planetable[cf + stride][i]
130 + planetable[cf + stride * 2][i]
131 + planetable[cf + stride * 3][i]
132 + planetable[cf + stride * 4][i]
133 + planetable[cf + stride * 5][i]
134 + planetable[cf + stride * 6][i]
135 + planetable[cf + stride * 7][i];
140 filter->plane = plane & (PLANES - 1);
141 GST_OBJECT_UNLOCK (filter);
147 gst_streaktv_set_info (GstVideoFilter * vfilter, GstCaps * incaps,
148 GstVideoInfo * in_info, GstCaps * outcaps, GstVideoInfo * out_info)
150 GstStreakTV *filter = GST_STREAKTV (vfilter);
151 gint i, width, height;
153 width = GST_VIDEO_INFO_WIDTH (in_info);
154 height = GST_VIDEO_INFO_HEIGHT (in_info);
156 g_free (filter->planebuffer);
158 filter->planebuffer = g_new0 (guint32, width * height * 4 * PLANES);
160 for (i = 0; i < PLANES; i++)
161 filter->planetable[i] = &filter->planebuffer[width * height * i];
167 gst_streaktv_start (GstBaseTransform * trans)
169 GstStreakTV *filter = GST_STREAKTV (trans);
177 gst_streaktv_finalize (GObject * object)
179 GstStreakTV *filter = GST_STREAKTV (object);
181 if (filter->planebuffer) {
182 g_free (filter->planebuffer);
183 filter->planebuffer = NULL;
186 G_OBJECT_CLASS (parent_class)->finalize (object);
190 gst_streaktv_set_property (GObject * object, guint prop_id,
191 const GValue * value, GParamSpec * pspec)
193 GstStreakTV *filter = GST_STREAKTV (object);
197 if (G_UNLIKELY (GST_STATE (filter) >= GST_STATE_PAUSED)) {
198 g_warning ("Changing the \"feedback\" property only allowed "
199 "in state < PLAYING");
203 filter->feedback = g_value_get_boolean (value);
206 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
212 gst_streaktv_get_property (GObject * object, guint prop_id, GValue * value,
215 GstStreakTV *filter = GST_STREAKTV (object);
219 g_value_set_boolean (value, filter->feedback);
222 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
228 gst_streaktv_class_init (GstStreakTVClass * klass)
230 GObjectClass *gobject_class = (GObjectClass *) klass;
231 GstElementClass *gstelement_class = (GstElementClass *) klass;
232 GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
233 GstVideoFilterClass *vfilter_class = (GstVideoFilterClass *) klass;
235 gobject_class->set_property = gst_streaktv_set_property;
236 gobject_class->get_property = gst_streaktv_get_property;
238 gobject_class->finalize = gst_streaktv_finalize;
240 g_object_class_install_property (gobject_class, PROP_FEEDBACK,
241 g_param_spec_boolean ("feedback", "Feedback",
242 "Feedback", DEFAULT_FEEDBACK,
243 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
245 gst_element_class_set_static_metadata (gstelement_class, "StreakTV effect",
246 "Filter/Effect/Video",
247 "StreakTV makes after images of moving objects",
248 "FUKUCHI, Kentarou <fukuchi@users.sourceforge.net>, "
249 "Sebastian Dröge <sebastian.droege@collabora.co.uk>");
251 gst_element_class_add_static_pad_template (gstelement_class,
252 &gst_streaktv_sink_template);
253 gst_element_class_add_static_pad_template (gstelement_class,
254 &gst_streaktv_src_template);
256 trans_class->start = GST_DEBUG_FUNCPTR (gst_streaktv_start);
258 vfilter_class->set_info = GST_DEBUG_FUNCPTR (gst_streaktv_set_info);
259 vfilter_class->transform_frame =
260 GST_DEBUG_FUNCPTR (gst_streaktv_transform_frame);
264 gst_streaktv_init (GstStreakTV * filter)
266 filter->feedback = DEFAULT_FEEDBACK;