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.
49 #include "gsteffectv.h"
51 #define GST_TYPE_REVTV \
52 (gst_revtv_get_type())
53 #define GST_REVTV(obj) \
54 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_REVTV,GstRevTV))
55 #define GST_REVTV_CLASS(klass) \
56 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_ULAW,GstRevTV))
57 #define GST_IS_REVTV(obj) \
58 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_REVTV))
59 #define GST_IS_REVTV_CLASS(obj) \
60 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_REVTV))
62 #define THE_COLOR 0xffffffff
64 typedef struct _GstRevTV GstRevTV;
65 typedef struct _GstRevTVClass GstRevTVClass;
71 GstPad *sinkpad, *srcpad;
82 GstElementClass parent_class;
84 void (*reset) (GstElement *element);
87 /* elementfactory information */
88 static GstElementDetails gst_revtv_details = GST_ELEMENT_DETAILS (
90 "Filter/Effect/Video",
91 "A video waveform monitor for each line of video processed",
92 "Wim Taymans <wim.taymans@chello.be>"
96 /* Filter signals and args */
111 static void gst_revtv_base_init (gpointer g_class);
112 static void gst_revtv_class_init (GstRevTVClass * klass);
113 static void gst_revtv_init (GstRevTV * filter);
115 static void gst_revtv_set_property (GObject * object, guint prop_id,
116 const GValue * value, GParamSpec * pspec);
117 static void gst_revtv_get_property (GObject * object, guint prop_id,
118 GValue * value, GParamSpec * pspec);
120 static void gst_revtv_chain (GstPad * pad, GstData *_data);
122 static GstElementClass *parent_class = NULL;
123 /* static guint gst_revtv_signals[LAST_SIGNAL] = { 0 }; */
125 GType gst_revtv_get_type (void)
127 static GType revtv_type = 0;
130 static const GTypeInfo revtv_info = {
131 sizeof (GstRevTVClass),
134 (GClassInitFunc) gst_revtv_class_init,
139 (GInstanceInitFunc) gst_revtv_init,
142 revtv_type = g_type_register_static (GST_TYPE_ELEMENT, "GstRevTV", &revtv_info, 0);
148 gst_revtv_base_init (gpointer g_class)
150 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
152 gst_element_class_add_pad_template (element_class, gst_effectv_src_factory ());
153 gst_element_class_add_pad_template (element_class, gst_effectv_sink_factory ());
155 gst_element_class_set_details (element_class, &gst_revtv_details);
159 gst_revtv_class_init (GstRevTVClass * klass)
161 GObjectClass *gobject_class;
162 GstElementClass *gstelement_class;
164 gobject_class = (GObjectClass *) klass;
165 gstelement_class = (GstElementClass *) klass;
167 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
169 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DELAY,
170 g_param_spec_int ("delay","Delay","Delay in frames between updates",
171 1, 100, 1, G_PARAM_READWRITE));
172 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LINESPACE,
173 g_param_spec_int ("linespace","Linespace","Control line spacing",
174 1, 100, 6, G_PARAM_READWRITE));
175 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_GAIN,
176 g_param_spec_int ("gain","Gain","Control gain",
177 1, 200, 50, G_PARAM_READWRITE));
179 gobject_class->set_property = gst_revtv_set_property;
180 gobject_class->get_property = gst_revtv_get_property;
183 static GstPadLinkReturn
184 gst_revtv_sinkconnect (GstPad * pad, GstCaps * caps)
188 filter = GST_REVTV (gst_pad_get_parent (pad));
190 if (!GST_CAPS_IS_FIXED (caps))
191 return GST_PAD_LINK_DELAYED;
193 gst_caps_get_int (caps, "width", &filter->width);
194 gst_caps_get_int (caps, "height", &filter->height);
196 return gst_pad_try_set_caps (filter->srcpad, gst_caps_ref (caps));
200 gst_revtv_init (GstRevTV * filter)
202 filter->sinkpad = gst_pad_new_from_template (gst_effectv_sink_factory (), "sink");
203 gst_pad_set_chain_function (filter->sinkpad, gst_revtv_chain);
204 gst_pad_set_link_function (filter->sinkpad, gst_revtv_sinkconnect);
205 gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
207 filter->srcpad = gst_pad_new_from_template (gst_effectv_src_factory (), "src");
208 gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
210 filter->vgrabtime = 1;
212 filter->linespace = 6;
218 gst_revtv_chain (GstPad * pad, GstData *_data)
220 GstBuffer *buf = GST_BUFFER (_data);
224 gint width, height, area;
226 gint y, x, R, G, B, yval;
228 filter = GST_REVTV (gst_pad_get_parent (pad));
230 src = (guint32 *) GST_BUFFER_DATA (buf);
232 width = filter->width;
233 height = filter->height;
234 area = width * height;
236 outbuf = gst_buffer_new ();
237 GST_BUFFER_SIZE (outbuf) = area * sizeof(guint32);
238 dest = (guint32 *) GST_BUFFER_DATA (outbuf) = g_malloc (GST_BUFFER_SIZE (outbuf));
239 GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf);
241 // draw the offset lines
242 for (y = 0; y < height ; y += filter->linespace){
243 for (x = 0; x <= width; x++) {
244 nsrc = src + (y * width) + x;
246 // Calc Y Value for curpix
247 R = ((*nsrc) & 0xff0000) >> (16 - 1);
248 G = ((*nsrc) & 0xff00) >> (8 - 2);
251 yval = y - ((short) (R + G + B) / filter->vscale) ;
254 dest[x + (yval * width)] = THE_COLOR;
259 gst_buffer_unref (buf);
261 gst_pad_push (filter->srcpad, GST_DATA (outbuf));
265 gst_revtv_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec)
269 /* it's not null if we got it, but it might not be ours */
270 g_return_if_fail (GST_IS_REVTV (object));
272 filter = GST_REVTV (object);
276 filter->vgrabtime = g_value_get_int (value);
279 filter->linespace = g_value_get_int (value);
282 filter->vscale = g_value_get_int (value);
290 gst_revtv_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec)
294 /* it's not null if we got it, but it might not be ours */
295 g_return_if_fail (GST_IS_REVTV (object));
297 filter = GST_REVTV (object);
301 g_value_set_int (value, filter->vgrabtime);
304 g_value_set_int (value, filter->linespace);
307 g_value_set_int (value, filter->vscale);
310 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);