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.
46 #include "gsteffectv.h"
48 #define GST_TYPE_REVTV \
49 (gst_revtv_get_type())
50 #define GST_REVTV(obj) \
51 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_REVTV,GstRevTV))
52 #define GST_REVTV_CLASS(klass) \
53 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_ULAW,GstRevTV))
54 #define GST_IS_REVTV(obj) \
55 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_REVTV))
56 #define GST_IS_REVTV_CLASS(obj) \
57 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_REVTV))
59 #define THE_COLOR 0xffffffff
61 typedef struct _GstRevTV GstRevTV;
62 typedef struct _GstRevTVClass GstRevTVClass;
68 GstPad *sinkpad, *srcpad;
79 GstElementClass parent_class;
81 void (*reset) (GstElement *element);
84 /* elementfactory information */
85 GstElementDetails gst_revtv_details = {
87 "Filter/Video/Effect",
89 "A video waveform monitor for each line of video processed",
91 "Wim Taymans <wim.taymans@chello.be>",
92 "(C) 2001 FUKUCHI Kentarou,"
93 "(c) 2002 Ed Tannenbaum",
97 /* Filter signals and args */
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, GstBuffer * buf);
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), NULL,
133 (GClassInitFunc) gst_revtv_class_init,
138 (GInstanceInitFunc) gst_revtv_init,
141 revtv_type = g_type_register_static (GST_TYPE_ELEMENT, "GstRevTV", &revtv_info, 0);
147 gst_revtv_class_init (GstRevTVClass * klass)
149 GObjectClass *gobject_class;
150 GstElementClass *gstelement_class;
152 gobject_class = (GObjectClass *) klass;
153 gstelement_class = (GstElementClass *) klass;
155 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
157 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DELAY,
158 g_param_spec_int ("delay","Delay","Delay in frames between updates",
159 1, 100, 1, G_PARAM_READWRITE));
160 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LINESPACE,
161 g_param_spec_int ("linespace","Linespace","Control line spacing",
162 1, 100, 6, G_PARAM_READWRITE));
163 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_GAIN,
164 g_param_spec_int ("gain","Gain","Control gain",
165 1, 200, 50, G_PARAM_READWRITE));
167 gobject_class->set_property = gst_revtv_set_property;
168 gobject_class->get_property = gst_revtv_get_property;
171 static GstPadConnectReturn
172 gst_revtv_sinkconnect (GstPad * pad, GstCaps * caps)
176 filter = GST_REVTV (gst_pad_get_parent (pad));
178 if (!GST_CAPS_IS_FIXED (caps))
179 return GST_PAD_LINK_DELAYED;
181 gst_caps_get_int (caps, "width", &filter->width);
182 gst_caps_get_int (caps, "height", &filter->height);
184 return gst_pad_try_set_caps (filter->srcpad, caps);
188 gst_revtv_init (GstRevTV * filter)
190 filter->sinkpad = gst_pad_new_from_template (gst_effectv_sink_factory (), "sink");
191 gst_pad_set_chain_function (filter->sinkpad, gst_revtv_chain);
192 gst_pad_set_link_function (filter->sinkpad, gst_revtv_sinkconnect);
193 gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
195 filter->srcpad = gst_pad_new_from_template (gst_effectv_src_factory (), "src");
196 gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
198 filter->vgrabtime = 1;
200 filter->linespace = 6;
206 gst_revtv_chain (GstPad * pad, GstBuffer * buf)
211 gint width, height, area;
213 gint y, x, R, G, B, yval;
215 filter = GST_REVTV (gst_pad_get_parent (pad));
217 src = (guint32 *) GST_BUFFER_DATA (buf);
219 width = filter->width;
220 height = filter->height;
221 area = width * height;
223 outbuf = gst_buffer_new ();
224 GST_BUFFER_SIZE (outbuf) = area * sizeof(guint32);
225 dest = (guint32 *) GST_BUFFER_DATA (outbuf) = g_malloc (GST_BUFFER_SIZE (outbuf));
226 GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf);
228 // draw the offset lines
229 for (y = 0; y < height ; y += filter->linespace){
230 for (x = 0; x <= width; x++) {
231 nsrc = src + (y * width) + x;
233 // Calc Y Value for curpix
234 R = ((*nsrc) & 0xff0000) >> (16 - 1);
235 G = ((*nsrc) & 0xff00) >> (8 - 2);
238 yval = y - ((short) (R + G + B) / filter->vscale) ;
241 dest[x + (yval * width)] = THE_COLOR;
246 gst_buffer_unref (buf);
248 gst_pad_push (filter->srcpad, outbuf);
252 gst_revtv_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec)
256 /* it's not null if we got it, but it might not be ours */
257 g_return_if_fail (GST_IS_REVTV (object));
259 filter = GST_REVTV (object);
263 filter->vgrabtime = g_value_get_int (value);
266 filter->linespace = g_value_get_int (value);
269 filter->vscale = g_value_get_int (value);
277 gst_revtv_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec)
281 /* it's not null if we got it, but it might not be ours */
282 g_return_if_fail (GST_IS_REVTV (object));
284 filter = GST_REVTV (object);
288 g_value_set_int (value, filter->vgrabtime);
291 g_value_set_int (value, filter->linespace);
294 g_value_set_int (value, filter->vscale);
297 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);