2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
5 * Copyright (C) 2001 FUKUCHI Kentarou
7 * EffecTV - Realtime Digital Video Effector
8 * Copyright (C) 2001 FUKUCHI Kentarou
10 * revTV based on Rutt-Etra Video Synthesizer 1974?
12 * (c)2002 Ed Tannenbaum
14 * This effect acts like a waveform monitor on each line.
15 * It was originally done by deflecting the electron beam on a monitor using
16 * additional electromagnets on the yoke of a b/w CRT.
17 * Here it is emulated digitally.
19 * Experimaental tapes were made with this system by Bill and
20 * Louise Etra and Woody and Steina Vasulka
22 * The line spacing can be controlled using the 1 and 2 Keys.
23 * The gain is controlled using the 3 and 4 keys.
24 * The update rate is controlled using the 0 and - keys.
26 * EffecTV is free software. This library is free software;
27 * you can redistribute it and/or
28 * modify it under the terms of the GNU Library General Public
29 * License as published by the Free Software Foundation; either
30 * version 2 of the License, or (at your option) any later version.
32 * This library is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
35 * Library General Public License for more details.
37 * You should have received a copy of the GNU Library General Public
38 * License along with this library; if not, write to the
39 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
40 * Boston, MA 02111-1307, USA.
44 * SECTION:element-quarktv
46 * RevTV acts like a video waveform monitor for each line of video
47 * processed. This creates a pseudo 3D effect based on the brightness
48 * of the video along each line.
51 * <title>Example launch line</title>
53 * gst-launch -v videotestsrc ! revtv ! ffmpegcolorspace ! autovideosink
54 * ]| This pipeline shows the effect of revtv on a test stream.
67 #include <gst/controller/gstcontroller.h>
69 #define THE_COLOR 0xffffffff
79 #define gst_revtv_parent_class parent_class
80 G_DEFINE_TYPE (GstRevTV, gst_revtv, GST_TYPE_VIDEO_FILTER);
82 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
83 #define CAPS_STR GST_VIDEO_CAPS_MAKE ("{ BGRx, RGBx }")
85 #define CAPS_STR GST_VIDEO_CAPS_MAKE ("{ xBGR, xRGB }")
88 static GstStaticPadTemplate gst_revtv_src_template =
89 GST_STATIC_PAD_TEMPLATE ("src",
92 GST_STATIC_CAPS (CAPS_STR)
95 static GstStaticPadTemplate gst_revtv_sink_template =
96 GST_STATIC_PAD_TEMPLATE ("sink",
99 GST_STATIC_CAPS (CAPS_STR)
103 gst_revtv_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
106 GstRevTV *filter = GST_REVTV (btrans);
109 if (!gst_video_info_from_caps (&info, incaps))
119 GST_DEBUG_OBJECT (filter, "invalid caps received");
125 gst_revtv_transform (GstBaseTransform * trans, GstBuffer * in, GstBuffer * out)
127 GstRevTV *filter = GST_REVTV (trans);
129 gint width, height, sstride, dstride;
131 gint y, x, R, G, B, yval;
132 gint linespace, vscale;
133 GstClockTime timestamp, stream_time;
134 GstVideoFrame in_frame, out_frame;
136 timestamp = GST_BUFFER_TIMESTAMP (in);
138 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME, timestamp);
140 GST_DEBUG_OBJECT (filter, "sync to %" GST_TIME_FORMAT,
141 GST_TIME_ARGS (timestamp));
143 if (GST_CLOCK_TIME_IS_VALID (stream_time))
144 gst_object_sync_values (G_OBJECT (filter), stream_time);
146 if (!gst_video_frame_map (&in_frame, &filter->info, in, GST_MAP_READ))
149 if (!gst_video_frame_map (&out_frame, &filter->info, out, GST_MAP_WRITE))
152 src = GST_VIDEO_FRAME_PLANE_DATA (&in_frame, 0);
153 sstride = GST_VIDEO_FRAME_PLANE_STRIDE (&in_frame, 0);
154 dest = GST_VIDEO_FRAME_PLANE_DATA (&out_frame, 0);
155 dstride = GST_VIDEO_FRAME_PLANE_STRIDE (&out_frame, 0);
157 width = GST_VIDEO_FRAME_WIDTH (&in_frame);
158 height = GST_VIDEO_FRAME_HEIGHT (&in_frame);
160 /* Clear everything to black */
161 memset (dest, 0, dstride * height * sizeof (guint32));
163 GST_OBJECT_LOCK (filter);
164 linespace = filter->linespace;
165 vscale = filter->vscale;
167 /* draw the offset lines */
168 for (y = 0; y < height; y += linespace) {
169 for (x = 0; x <= width; x++) {
170 nsrc = src + (y * sstride) + x;
172 /* Calc Y Value for curpix */
173 R = ((*nsrc) & 0xff0000) >> (16 - 1);
174 G = ((*nsrc) & 0xff00) >> (8 - 2);
177 yval = y - ((short) (R + G + B) / vscale);
180 dest[x + (yval * dstride)] = THE_COLOR;
184 GST_OBJECT_UNLOCK (filter);
191 GST_DEBUG_OBJECT (filter, "invalid input frame");
192 return GST_FLOW_ERROR;
196 GST_DEBUG_OBJECT (filter, "invalid output frame");
197 gst_video_frame_unmap (&in_frame);
198 return GST_FLOW_ERROR;
203 gst_revtv_set_property (GObject * object, guint prop_id, const GValue * value,
206 GstRevTV *filter = GST_REVTV (object);
208 GST_OBJECT_LOCK (filter);
211 filter->vgrabtime = g_value_get_int (value);
214 filter->linespace = g_value_get_int (value);
217 filter->vscale = g_value_get_int (value);
220 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
223 GST_OBJECT_UNLOCK (filter);
227 gst_revtv_get_property (GObject * object, guint prop_id, GValue * value,
230 GstRevTV *filter = GST_REVTV (object);
234 g_value_set_int (value, filter->vgrabtime);
237 g_value_set_int (value, filter->linespace);
240 g_value_set_int (value, filter->vscale);
243 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
249 gst_revtv_class_init (GstRevTVClass * klass)
251 GObjectClass *gobject_class = (GObjectClass *) klass;
252 GstElementClass *gstelement_class = (GstElementClass *) klass;
253 GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
255 gobject_class->set_property = gst_revtv_set_property;
256 gobject_class->get_property = gst_revtv_get_property;
258 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_DELAY,
259 g_param_spec_int ("delay", "Delay", "Delay in frames between updates",
261 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
262 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_LINESPACE,
263 g_param_spec_int ("linespace", "Linespace", "Control line spacing", 1,
265 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
266 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_GAIN,
267 g_param_spec_int ("gain", "Gain", "Control gain", 1, 200, 50,
268 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
270 gst_element_class_set_details_simple (gstelement_class, "RevTV effect",
271 "Filter/Effect/Video",
272 "A video waveform monitor for each line of video processed",
273 "Wim Taymans <wim.taymans@gmail.be>");
275 gst_element_class_add_pad_template (gstelement_class,
276 gst_static_pad_template_get (&gst_revtv_sink_template));
277 gst_element_class_add_pad_template (gstelement_class,
278 gst_static_pad_template_get (&gst_revtv_src_template));
280 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_revtv_set_caps);
281 trans_class->transform = GST_DEBUG_FUNCPTR (gst_revtv_transform);
285 gst_revtv_init (GstRevTV * restv)
287 restv->vgrabtime = 1;
289 restv->linespace = 6;