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., 59 Temple Place - Suite 330,
28 * Boston, MA 02111-1307, USA.
32 * SECTION:element-streaktv
34 * StreakTV makes after images of moving objects.
37 * <title>Example launch line</title>
39 * gst-launch -v videotestsrc ! streaktv ! ffmpegcolorspace ! autovideosink
40 * ]| This pipeline shows the effect of streaktv on a test stream.
51 #include "gststreak.h"
52 #include "gsteffectv.h"
54 #include <gst/video/video.h>
56 #define DEFAULT_FEEDBACK FALSE
64 GST_BOILERPLATE (GstStreakTV, gst_streaktv, GstVideoFilter,
65 GST_TYPE_VIDEO_FILTER);
67 static GstStaticPadTemplate gst_streaktv_src_template =
68 GST_STATIC_PAD_TEMPLATE ("src",
71 GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx "; " GST_VIDEO_CAPS_RGBx ";"
72 GST_VIDEO_CAPS_xBGR "; " GST_VIDEO_CAPS_xRGB)
75 static GstStaticPadTemplate gst_streaktv_sink_template =
76 GST_STATIC_PAD_TEMPLATE ("sink",
79 GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx "; " GST_VIDEO_CAPS_RGBx ";"
80 GST_VIDEO_CAPS_xBGR "; " GST_VIDEO_CAPS_xRGB)
86 gst_streaktv_transform (GstBaseTransform * trans, GstBuffer * in,
89 GstStreakTV *filter = GST_STREAKTV (trans);
91 GstFlowReturn ret = GST_FLOW_OK;
93 gint video_area = filter->width * filter->height;
94 guint32 **planetable = filter->planetable;
95 gint plane = filter->plane;
96 guint stride_mask, stride_shift, stride;
98 GST_OBJECT_LOCK (filter);
99 if (filter->feedback) {
100 stride_mask = 0xfcfcfcfc;
104 stride_mask = 0xf8f8f8f8;
109 src = (guint32 *) GST_BUFFER_DATA (in);
110 dest = (guint32 *) GST_BUFFER_DATA (out);
112 for (i = 0; i < video_area; i++) {
113 planetable[plane][i] = (src[i] & stride_mask) >> stride_shift;
116 cf = plane & (stride - 1);
117 if (filter->feedback) {
118 for (i = 0; i < video_area; i++) {
119 dest[i] = planetable[cf][i]
120 + planetable[cf + stride][i]
121 + planetable[cf + stride * 2][i]
122 + planetable[cf + stride * 3][i];
123 planetable[plane][i] = (dest[i] & stride_mask) >> stride_shift;
126 for (i = 0; i < video_area; i++) {
127 dest[i] = planetable[cf][i]
128 + planetable[cf + stride][i]
129 + planetable[cf + stride * 2][i]
130 + planetable[cf + stride * 3][i]
131 + planetable[cf + stride * 4][i]
132 + planetable[cf + stride * 5][i]
133 + planetable[cf + stride * 6][i]
134 + planetable[cf + stride * 7][i];
139 filter->plane = plane & (PLANES - 1);
140 GST_OBJECT_UNLOCK (filter);
146 gst_streaktv_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
149 GstStreakTV *filter = GST_STREAKTV (btrans);
150 GstStructure *structure;
151 gboolean ret = FALSE;
153 structure = gst_caps_get_structure (incaps, 0);
155 GST_OBJECT_LOCK (filter);
156 if (gst_structure_get_int (structure, "width", &filter->width) &&
157 gst_structure_get_int (structure, "height", &filter->height)) {
160 if (filter->planebuffer)
161 g_free (filter->planebuffer);
163 filter->planebuffer =
164 g_new0 (guint32, filter->width * filter->height * 4 * PLANES);
165 for (i = 0; i < PLANES; i++)
166 filter->planetable[i] =
167 &filter->planebuffer[filter->width * filter->height * i];
171 GST_OBJECT_UNLOCK (filter);
177 gst_streaktv_start (GstBaseTransform * trans)
179 GstStreakTV *filter = GST_STREAKTV (trans);
187 gst_streaktv_finalize (GObject * object)
189 GstStreakTV *filter = GST_STREAKTV (object);
191 if (filter->planebuffer) {
192 g_free (filter->planebuffer);
193 filter->planebuffer = NULL;
196 G_OBJECT_CLASS (parent_class)->finalize (object);
200 gst_streaktv_set_property (GObject * object, guint prop_id,
201 const GValue * value, GParamSpec * pspec)
203 GstStreakTV *filter = GST_STREAKTV (object);
207 if (G_UNLIKELY (GST_STATE (filter) >= GST_STATE_PAUSED)) {
208 g_warning ("Changing the \"feedback\" property only allowed "
209 "in state < PLAYING");
213 filter->feedback = g_value_get_boolean (value);
216 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
222 gst_streaktv_get_property (GObject * object, guint prop_id, GValue * value,
225 GstStreakTV *filter = GST_STREAKTV (object);
229 g_value_set_boolean (value, filter->feedback);
232 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
238 gst_streaktv_base_init (gpointer g_class)
240 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
242 gst_element_class_set_details_simple (element_class, "StreakTV effect",
243 "Filter/Effect/Video",
244 "StreakTV makes after images of moving objects",
245 "FUKUCHI, Kentarou <fukuchi@users.sourceforge.net>, "
246 "Sebastian Dröge <sebastian.droege@collabora.co.uk>");
248 gst_element_class_add_pad_template (element_class,
249 gst_static_pad_template_get (&gst_streaktv_sink_template));
250 gst_element_class_add_pad_template (element_class,
251 gst_static_pad_template_get (&gst_streaktv_src_template));
255 gst_streaktv_class_init (GstStreakTVClass * klass)
257 GObjectClass *gobject_class = (GObjectClass *) klass;
258 GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
260 gobject_class->set_property = gst_streaktv_set_property;
261 gobject_class->get_property = gst_streaktv_get_property;
263 gobject_class->finalize = gst_streaktv_finalize;
265 g_object_class_install_property (gobject_class, PROP_FEEDBACK,
266 g_param_spec_boolean ("feedback", "Feedback",
267 "Feedback", DEFAULT_FEEDBACK,
268 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
270 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_streaktv_set_caps);
271 trans_class->transform = GST_DEBUG_FUNCPTR (gst_streaktv_transform);
272 trans_class->start = GST_DEBUG_FUNCPTR (gst_streaktv_start);
276 gst_streaktv_init (GstStreakTV * filter, GstStreakTVClass * klass)
278 filter->feedback = DEFAULT_FEEDBACK;
280 gst_pad_use_fixed_caps (GST_BASE_TRANSFORM_SRC_PAD (filter));
281 gst_pad_use_fixed_caps (GST_BASE_TRANSFORM_SINK_PAD (filter));