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 ! videoconvert ! autovideosink
54 * ]| This pipeline shows the effect of revtv on a test stream.
67 #define THE_COLOR 0xffffffff
77 #define gst_revtv_parent_class parent_class
78 G_DEFINE_TYPE (GstRevTV, gst_revtv, GST_TYPE_VIDEO_FILTER);
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 static GstStaticPadTemplate gst_revtv_src_template =
87 GST_STATIC_PAD_TEMPLATE ("src",
90 GST_STATIC_CAPS (CAPS_STR)
93 static GstStaticPadTemplate gst_revtv_sink_template =
94 GST_STATIC_PAD_TEMPLATE ("sink",
97 GST_STATIC_CAPS (CAPS_STR)
101 gst_revtv_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
104 GstRevTV *filter = GST_REVTV (btrans);
107 if (!gst_video_info_from_caps (&info, incaps))
117 GST_DEBUG_OBJECT (filter, "invalid caps received");
123 gst_revtv_transform (GstBaseTransform * trans, GstBuffer * in, GstBuffer * out)
125 GstRevTV *filter = GST_REVTV (trans);
127 gint width, height, sstride, dstride;
129 gint y, x, R, G, B, yval;
130 gint linespace, vscale;
131 GstClockTime timestamp, stream_time;
132 GstVideoFrame in_frame, out_frame;
134 timestamp = GST_BUFFER_TIMESTAMP (in);
136 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME, timestamp);
138 GST_DEBUG_OBJECT (filter, "sync to %" GST_TIME_FORMAT,
139 GST_TIME_ARGS (timestamp));
141 if (GST_CLOCK_TIME_IS_VALID (stream_time))
142 gst_object_sync_values (GST_OBJECT (filter), stream_time);
144 if (!gst_video_frame_map (&in_frame, &filter->info, in, GST_MAP_READ))
147 if (!gst_video_frame_map (&out_frame, &filter->info, out, GST_MAP_WRITE))
150 src = GST_VIDEO_FRAME_PLANE_DATA (&in_frame, 0);
151 sstride = GST_VIDEO_FRAME_PLANE_STRIDE (&in_frame, 0);
152 dest = GST_VIDEO_FRAME_PLANE_DATA (&out_frame, 0);
153 dstride = GST_VIDEO_FRAME_PLANE_STRIDE (&out_frame, 0);
155 width = GST_VIDEO_FRAME_WIDTH (&in_frame);
156 height = GST_VIDEO_FRAME_HEIGHT (&in_frame);
158 /* Clear everything to black */
159 memset (dest, 0, dstride * height * sizeof (guint32));
161 GST_OBJECT_LOCK (filter);
162 linespace = filter->linespace;
163 vscale = filter->vscale;
165 /* draw the offset lines */
166 for (y = 0; y < height; y += linespace) {
167 for (x = 0; x <= width; x++) {
168 nsrc = src + (y * sstride) + x;
170 /* Calc Y Value for curpix */
171 R = ((*nsrc) & 0xff0000) >> (16 - 1);
172 G = ((*nsrc) & 0xff00) >> (8 - 2);
175 yval = y - ((short) (R + G + B) / vscale);
178 dest[x + (yval * dstride)] = THE_COLOR;
182 GST_OBJECT_UNLOCK (filter);
184 gst_video_frame_unmap (&in_frame);
185 gst_video_frame_unmap (&out_frame);
192 GST_DEBUG_OBJECT (filter, "invalid input frame");
193 return GST_FLOW_ERROR;
197 GST_DEBUG_OBJECT (filter, "invalid output frame");
198 gst_video_frame_unmap (&in_frame);
199 return GST_FLOW_ERROR;
204 gst_revtv_set_property (GObject * object, guint prop_id, const GValue * value,
207 GstRevTV *filter = GST_REVTV (object);
209 GST_OBJECT_LOCK (filter);
212 filter->vgrabtime = g_value_get_int (value);
215 filter->linespace = g_value_get_int (value);
218 filter->vscale = g_value_get_int (value);
221 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
224 GST_OBJECT_UNLOCK (filter);
228 gst_revtv_get_property (GObject * object, guint prop_id, GValue * value,
231 GstRevTV *filter = GST_REVTV (object);
235 g_value_set_int (value, filter->vgrabtime);
238 g_value_set_int (value, filter->linespace);
241 g_value_set_int (value, filter->vscale);
244 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
250 gst_revtv_class_init (GstRevTVClass * klass)
252 GObjectClass *gobject_class = (GObjectClass *) klass;
253 GstElementClass *gstelement_class = (GstElementClass *) klass;
254 GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
256 gobject_class->set_property = gst_revtv_set_property;
257 gobject_class->get_property = gst_revtv_get_property;
259 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_DELAY,
260 g_param_spec_int ("delay", "Delay", "Delay in frames between updates",
262 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
263 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_LINESPACE,
264 g_param_spec_int ("linespace", "Linespace", "Control line spacing", 1,
266 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
267 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_GAIN,
268 g_param_spec_int ("gain", "Gain", "Control gain", 1, 200, 50,
269 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
271 gst_element_class_set_details_simple (gstelement_class, "RevTV effect",
272 "Filter/Effect/Video",
273 "A video waveform monitor for each line of video processed",
274 "Wim Taymans <wim.taymans@gmail.be>");
276 gst_element_class_add_pad_template (gstelement_class,
277 gst_static_pad_template_get (&gst_revtv_sink_template));
278 gst_element_class_add_pad_template (gstelement_class,
279 gst_static_pad_template_get (&gst_revtv_src_template));
281 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_revtv_set_caps);
282 trans_class->transform = GST_DEBUG_FUNCPTR (gst_revtv_transform);
286 gst_revtv_init (GstRevTV * restv)
288 restv->vgrabtime = 1;
290 restv->linespace = 6;