Remove unused variables in _class_init
[platform/upstream/gstreamer.git] / gst / effectv / gstrev.c
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  *
4  * EffecTV:
5  * Copyright (C) 2001 FUKUCHI Kentarou
6  *
7  * EffecTV - Realtime Digital Video Effector
8  * Copyright (C) 2001 FUKUCHI Kentarou
9  *
10  * revTV based on Rutt-Etra Video Synthesizer 1974?
11
12  * (c)2002 Ed Tannenbaum
13  *
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.
18
19  * Experimaental tapes were made with this system by Bill and 
20  * Louise Etra and Woody and Steina Vasulka
21
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.
25  
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.
31  *
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.
36  *
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.
41  */
42
43 #ifdef HAVE_CONFIG_H
44 #include "config.h"
45 #endif
46
47 #include <gst/video/gstvideofilter.h>
48
49 #include <math.h>
50 #include <string.h>
51
52 #include <gst/video/video.h>
53
54 #define GST_TYPE_REVTV \
55   (gst_revtv_get_type())
56 #define GST_REVTV(obj) \
57   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_REVTV,GstRevTV))
58 #define GST_REVTV_CLASS(klass) \
59   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_REVTV,GstRevTVClass))
60 #define GST_IS_REVTV(obj) \
61   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_REVTV))
62 #define GST_IS_REVTV_CLASS(klass) \
63   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_REVTV))
64
65 #define THE_COLOR 0xffffffff
66
67 typedef struct _GstRevTV GstRevTV;
68 typedef struct _GstRevTVClass GstRevTVClass;
69
70 struct _GstRevTV
71 {
72   GstVideoFilter videofilter;
73
74   gint width, height;
75   gint vgrabtime;
76   gint vgrab;
77   gint linespace;
78   gint vscale;
79 };
80
81 struct _GstRevTVClass
82 {
83   GstVideoFilterClass parent_class;
84 };
85
86 enum
87 {
88   ARG_0,
89   ARG_DELAY,
90   ARG_LINESPACE,
91   ARG_GAIN
92 };
93
94 GType gst_revtv_get_type (void);
95
96 static const GstElementDetails gst_revtv_details =
97 GST_ELEMENT_DETAILS ("RevTV effect",
98     "Filter/Effect/Video",
99     "A video waveform monitor for each line of video processed",
100     "Wim Taymans <wim.taymans@chello.be>");
101
102 static GstStaticPadTemplate gst_revtv_src_template =
103 GST_STATIC_PAD_TEMPLATE ("src",
104     GST_PAD_SRC,
105     GST_PAD_ALWAYS,
106     GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx)
107     );
108
109 static GstStaticPadTemplate gst_revtv_sink_template =
110 GST_STATIC_PAD_TEMPLATE ("sink",
111     GST_PAD_SINK,
112     GST_PAD_ALWAYS,
113     GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx)
114     );
115
116 static GstVideoFilterClass *parent_class = NULL;
117
118 static gboolean
119 gst_revtv_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
120     GstCaps * outcaps)
121 {
122   GstRevTV *filter = GST_REVTV (btrans);
123   GstStructure *structure;
124   gboolean ret = FALSE;
125
126   structure = gst_caps_get_structure (incaps, 0);
127
128   if (gst_structure_get_int (structure, "width", &filter->width) &&
129       gst_structure_get_int (structure, "height", &filter->height)) {
130     ret = TRUE;
131   }
132
133   return ret;
134 }
135
136 static gboolean
137 gst_revtv_get_unit_size (GstBaseTransform * btrans, GstCaps * caps,
138     guint * size)
139 {
140   GstRevTV *filter;
141   GstStructure *structure;
142   gboolean ret = FALSE;
143   gint width, height;
144
145   filter = GST_REVTV (btrans);
146
147   structure = gst_caps_get_structure (caps, 0);
148
149   if (gst_structure_get_int (structure, "width", &width) &&
150       gst_structure_get_int (structure, "height", &height)) {
151     *size = width * height * 32 / 8;
152     ret = TRUE;
153     GST_DEBUG_OBJECT (filter, "our frame size is %d bytes (%dx%d)", *size,
154         width, height);
155   }
156
157   return ret;
158 }
159
160 static GstFlowReturn
161 gst_revtv_transform (GstBaseTransform * trans, GstBuffer * in, GstBuffer * out)
162 {
163   GstRevTV *filter;
164   guint32 *src, *dest;
165   gint width, height;
166   guint32 *nsrc;
167   gint y, x, R, G, B, yval;
168   GstFlowReturn ret = GST_FLOW_OK;
169
170   filter = GST_REVTV (trans);
171
172   gst_buffer_copy_metadata (out, in, GST_BUFFER_COPY_TIMESTAMPS);
173
174   src = (guint32 *) GST_BUFFER_DATA (in);
175   dest = (guint32 *) GST_BUFFER_DATA (out);
176
177   width = filter->width;
178   height = filter->height;
179
180   /* Clear everything to black */
181   memset (dest, 0, width * height * sizeof (guint32));
182
183   // draw the offset lines
184   for (y = 0; y < height; y += filter->linespace) {
185     for (x = 0; x <= width; x++) {
186       nsrc = src + (y * width) + x;
187
188       // Calc Y Value for curpix
189       R = ((*nsrc) & 0xff0000) >> (16 - 1);
190       G = ((*nsrc) & 0xff00) >> (8 - 2);
191       B = (*nsrc) & 0xff;
192
193       yval = y - ((short) (R + G + B) / filter->vscale);
194
195       if (yval > 0) {
196         dest[x + (yval * width)] = THE_COLOR;
197       }
198     }
199   }
200
201   return ret;
202 }
203
204 static void
205 gst_revtv_set_property (GObject * object, guint prop_id, const GValue * value,
206     GParamSpec * pspec)
207 {
208   GstRevTV *filter;
209
210   g_return_if_fail (GST_IS_REVTV (object));
211
212   filter = GST_REVTV (object);
213
214   switch (prop_id) {
215     case ARG_DELAY:
216       filter->vgrabtime = g_value_get_int (value);
217       break;
218     case ARG_LINESPACE:
219       filter->linespace = g_value_get_int (value);
220       break;
221     case ARG_GAIN:
222       filter->vscale = g_value_get_int (value);
223       break;
224     default:
225       break;
226   }
227 }
228
229 static void
230 gst_revtv_get_property (GObject * object, guint prop_id, GValue * value,
231     GParamSpec * pspec)
232 {
233   GstRevTV *filter;
234
235   g_return_if_fail (GST_IS_REVTV (object));
236
237   filter = GST_REVTV (object);
238
239   switch (prop_id) {
240     case ARG_DELAY:
241       g_value_set_int (value, filter->vgrabtime);
242       break;
243     case ARG_LINESPACE:
244       g_value_set_int (value, filter->linespace);
245       break;
246     case ARG_GAIN:
247       g_value_set_int (value, filter->vscale);
248       break;
249     default:
250       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
251       break;
252   }
253 }
254
255 static void
256 gst_revtv_base_init (gpointer g_class)
257 {
258   GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
259
260   gst_element_class_set_details (element_class, &gst_revtv_details);
261
262   gst_element_class_add_pad_template (element_class,
263       gst_static_pad_template_get (&gst_revtv_sink_template));
264   gst_element_class_add_pad_template (element_class,
265       gst_static_pad_template_get (&gst_revtv_src_template));
266 }
267
268 static void
269 gst_revtv_class_init (gpointer klass, gpointer class_data)
270 {
271   GObjectClass *gobject_class;
272   GstBaseTransformClass *trans_class;
273
274   gobject_class = (GObjectClass *) klass;
275   trans_class = (GstBaseTransformClass *) klass;
276
277   parent_class = g_type_class_peek_parent (klass);
278
279   gobject_class->set_property = gst_revtv_set_property;
280   gobject_class->get_property = gst_revtv_get_property;
281
282   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DELAY,
283       g_param_spec_int ("delay", "Delay", "Delay in frames between updates",
284           1, 100, 1, G_PARAM_READWRITE));
285   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LINESPACE,
286       g_param_spec_int ("linespace", "Linespace", "Control line spacing",
287           1, 100, 6, G_PARAM_READWRITE));
288   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_GAIN,
289       g_param_spec_int ("gain", "Gain", "Control gain",
290           1, 200, 50, G_PARAM_READWRITE));
291
292   trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_revtv_set_caps);
293   trans_class->get_unit_size = GST_DEBUG_FUNCPTR (gst_revtv_get_unit_size);
294   trans_class->transform = GST_DEBUG_FUNCPTR (gst_revtv_transform);
295 }
296
297 static void
298 gst_revtv_init (GTypeInstance * instance, gpointer g_class)
299 {
300   GstRevTV *restv = GST_REVTV (instance);
301
302   restv->vgrabtime = 1;
303   restv->vgrab = 0;
304   restv->linespace = 6;
305   restv->vscale = 50;
306 }
307
308 GType
309 gst_revtv_get_type (void)
310 {
311   static GType revtv_type = 0;
312
313   if (!revtv_type) {
314     static const GTypeInfo revtv_info = {
315       sizeof (GstRevTVClass),
316       gst_revtv_base_init,
317       NULL,
318       (GClassInitFunc) gst_revtv_class_init,
319       NULL,
320       NULL,
321       sizeof (GstRevTV),
322       0,
323       (GInstanceInitFunc) gst_revtv_init,
324     };
325
326     revtv_type =
327         g_type_register_static (GST_TYPE_VIDEO_FILTER, "GstRevTV", &revtv_info,
328         0);
329   }
330   return revtv_type;
331 }