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 GstElementDetails gst_revtv_details = {
86 "Filter/Video/Effect",
87 "A video waveform monitor for each line of video processed",
89 "Wim Taymans <wim.taymans@chello.be>",
90 "(C) 2001 FUKUCHI Kentarou,"
91 "(c) 2002 Ed Tannenbaum",
95 /* Filter signals and args */
110 static void gst_revtv_class_init (GstRevTVClass * klass);
111 static void gst_revtv_init (GstRevTV * filter);
113 static void gst_revtv_set_property (GObject * object, guint prop_id,
114 const GValue * value, GParamSpec * pspec);
115 static void gst_revtv_get_property (GObject * object, guint prop_id,
116 GValue * value, GParamSpec * pspec);
118 static void gst_revtv_chain (GstPad * pad, GstBuffer * buf);
120 static GstElementClass *parent_class = NULL;
121 /* static guint gst_revtv_signals[LAST_SIGNAL] = { 0 }; */
123 GType gst_revtv_get_type (void)
125 static GType revtv_type = 0;
128 static const GTypeInfo revtv_info = {
129 sizeof (GstRevTVClass), NULL,
131 (GClassInitFunc) gst_revtv_class_init,
136 (GInstanceInitFunc) gst_revtv_init,
139 revtv_type = g_type_register_static (GST_TYPE_ELEMENT, "GstRevTV", &revtv_info, 0);
145 gst_revtv_class_init (GstRevTVClass * klass)
147 GObjectClass *gobject_class;
148 GstElementClass *gstelement_class;
150 gobject_class = (GObjectClass *) klass;
151 gstelement_class = (GstElementClass *) klass;
153 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
155 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DELAY,
156 g_param_spec_int ("delay","Delay","Delay in frames between updates",
157 1, 100, 1, G_PARAM_READWRITE));
158 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LINESPACE,
159 g_param_spec_int ("linespace","Linespace","Control line spacing",
160 1, 100, 6, G_PARAM_READWRITE));
161 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_GAIN,
162 g_param_spec_int ("gain","Gain","Control gain",
163 1, 200, 50, G_PARAM_READWRITE));
165 gobject_class->set_property = gst_revtv_set_property;
166 gobject_class->get_property = gst_revtv_get_property;
169 static GstPadConnectReturn
170 gst_revtv_sinkconnect (GstPad * pad, GstCaps * caps)
174 filter = GST_REVTV (gst_pad_get_parent (pad));
176 if (!GST_CAPS_IS_FIXED (caps))
177 return GST_PAD_CONNECT_DELAYED;
179 gst_caps_get_int (caps, "width", &filter->width);
180 gst_caps_get_int (caps, "height", &filter->height);
182 if (gst_pad_try_set_caps (filter->srcpad, caps)) {
183 return GST_PAD_CONNECT_OK;
186 return GST_PAD_CONNECT_REFUSED;
190 gst_revtv_init (GstRevTV * filter)
192 filter->sinkpad = gst_pad_new_from_template (gst_effectv_sink_factory (), "sink");
193 gst_pad_set_chain_function (filter->sinkpad, gst_revtv_chain);
194 gst_pad_set_connect_function (filter->sinkpad, gst_revtv_sinkconnect);
195 gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
197 filter->srcpad = gst_pad_new_from_template (gst_effectv_src_factory (), "src");
198 gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
200 filter->vgrabtime = 1;
202 filter->linespace = 6;
208 gst_revtv_chain (GstPad * pad, GstBuffer * buf)
213 gint width, height, area;
215 gint y, x, R, G, B, yval;
217 filter = GST_REVTV (gst_pad_get_parent (pad));
219 src = (guint32 *) GST_BUFFER_DATA (buf);
221 width = filter->width;
222 height = filter->height;
223 area = width * height;
225 outbuf = gst_buffer_new ();
226 GST_BUFFER_SIZE (outbuf) = area * sizeof(guint32);
227 dest = (guint32 *) GST_BUFFER_DATA (outbuf) = g_malloc (GST_BUFFER_SIZE (outbuf));
228 GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf);
230 // draw the offset lines
231 for (y = 0; y < height ; y += filter->linespace){
232 for (x = 0; x <= width; x++) {
233 nsrc = src + (y * width) + x;
235 // Calc Y Value for curpix
236 R = ((*nsrc) & 0xff0000) >> (16 - 1);
237 G = ((*nsrc) & 0xff00) >> (8 - 2);
240 yval = y - ((short) (R + G + B) / filter->vscale) ;
243 dest[x + (yval * width)] = THE_COLOR;
248 gst_buffer_unref (buf);
250 gst_pad_push (filter->srcpad, outbuf);
254 gst_revtv_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec)
258 /* it's not null if we got it, but it might not be ours */
259 g_return_if_fail (GST_IS_REVTV (object));
261 filter = GST_REVTV (object);
265 filter->vgrabtime = g_value_get_int (value);
268 filter->linespace = g_value_get_int (value);
271 filter->vscale = g_value_get_int (value);
279 gst_revtv_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec)
283 /* it's not null if we got it, but it might not be ours */
284 g_return_if_fail (GST_IS_REVTV (object));
286 filter = GST_REVTV (object);
290 g_value_set_int (value, filter->vgrabtime);
293 g_value_set_int (value, filter->linespace);
296 g_value_set_int (value, filter->vscale);
299 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);