first batch : remove ',' at end of enums as they could confuse older gcc, foreign...
[platform/upstream/gst-plugins-good.git] / gst / debug / gstnavigationtest.c
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  * Copyright (C) <2003> David Schleef <ds@schleef.org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 /*
22  * This file was (probably) generated from gstnavigationtest.c,
23  * gstnavigationtest.c,v 1.7 2003/11/08 02:48:59 dschleef Exp 
24  */
25
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29
30 /*#define DEBUG_ENABLED */
31 #include <gstnavigationtest.h>
32 #include <string.h>
33 #include <math.h>
34
35 /* GstNavigationtest signals and args */
36 enum
37 {
38   /* FILL ME */
39   LAST_SIGNAL
40 };
41
42 enum
43 {
44   ARG_0
45       /* FILL ME */
46 };
47
48 static void gst_navigationtest_base_init (gpointer g_class);
49 static void gst_navigationtest_class_init (gpointer g_class,
50     gpointer class_data);
51 static void gst_navigationtest_init (GTypeInstance * instance,
52     gpointer g_class);
53
54 static gboolean gst_navigationtest_handle_src_event (GstPad * pad,
55     GstEvent * event);
56 static void gst_navigationtest_set_property (GObject * object, guint prop_id,
57     const GValue * value, GParamSpec * pspec);
58 static void gst_navigationtest_get_property (GObject * object, guint prop_id,
59     GValue * value, GParamSpec * pspec);
60
61 static void gst_navigationtest_planar411 (GstVideofilter * videofilter,
62     void *dest, void *src);
63 static void gst_navigationtest_setup (GstVideofilter * videofilter);
64
65 GType
66 gst_navigationtest_get_type (void)
67 {
68   static GType navigationtest_type = 0;
69
70   if (!navigationtest_type) {
71     static const GTypeInfo navigationtest_info = {
72       sizeof (GstNavigationtestClass),
73       gst_navigationtest_base_init,
74       NULL,
75       gst_navigationtest_class_init,
76       NULL,
77       NULL,
78       sizeof (GstNavigationtest),
79       0,
80       gst_navigationtest_init,
81     };
82
83     navigationtest_type = g_type_register_static (GST_TYPE_VIDEOFILTER,
84         "GstNavigationtest", &navigationtest_info, 0);
85   }
86   return navigationtest_type;
87 }
88
89 static GstVideofilterFormat gst_navigationtest_formats[] = {
90   {"I420", 12, gst_navigationtest_planar411,},
91 };
92
93
94 static void
95 gst_navigationtest_base_init (gpointer g_class)
96 {
97   static GstElementDetails navigationtest_details =
98       GST_ELEMENT_DETAILS ("Video Filter Template",
99       "Filter/Video",
100       "Template for a video filter",
101       "David Schleef <ds@schleef.org>");
102   GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
103   GstVideofilterClass *videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
104   int i;
105
106   gst_element_class_set_details (element_class, &navigationtest_details);
107
108   for (i = 0; i < G_N_ELEMENTS (gst_navigationtest_formats); i++) {
109     gst_videofilter_class_add_format (videofilter_class,
110         gst_navigationtest_formats + i);
111   }
112
113   gst_videofilter_class_add_pad_templates (GST_VIDEOFILTER_CLASS (g_class));
114 }
115
116 static void
117 gst_navigationtest_class_init (gpointer g_class, gpointer class_data)
118 {
119   GObjectClass *gobject_class;
120   GstVideofilterClass *videofilter_class;
121
122   gobject_class = G_OBJECT_CLASS (g_class);
123   videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
124
125 #if 0
126   g_object_class_install_property (gobject_class, ARG_METHOD,
127       g_param_spec_enum ("method", "method", "method",
128           GST_TYPE_NAVIGATIONTEST_METHOD, GST_NAVIGATIONTEST_METHOD_1,
129           G_PARAM_READWRITE));
130 #endif
131
132   gobject_class->set_property = gst_navigationtest_set_property;
133   gobject_class->get_property = gst_navigationtest_get_property;
134
135   videofilter_class->setup = gst_navigationtest_setup;
136 }
137
138 static void
139 gst_navigationtest_init (GTypeInstance * instance, gpointer g_class)
140 {
141   GstNavigationtest *navigationtest = GST_NAVIGATIONTEST (instance);
142   GstVideofilter *videofilter;
143
144   GST_DEBUG ("gst_navigationtest_init");
145
146   videofilter = GST_VIDEOFILTER (navigationtest);
147
148   gst_pad_set_event_function (videofilter->srcpad,
149       gst_navigationtest_handle_src_event);
150
151   navigationtest->x = -1;
152   navigationtest->y = -1;
153 }
154
155 static gboolean
156 gst_navigationtest_handle_src_event (GstPad * pad, GstEvent * event)
157 {
158   GstNavigationtest *navigationtest;
159
160   navigationtest = GST_NAVIGATIONTEST (gst_pad_get_parent (pad));
161
162   switch (GST_EVENT_TYPE (event)) {
163     case GST_EVENT_NAVIGATION:
164       gst_structure_get_double (event->event_data.structure.structure,
165           "pointer_x", &navigationtest->x);
166       gst_structure_get_double (event->event_data.structure.structure,
167           "pointer_y", &navigationtest->y);
168       break;
169     default:
170       break;
171   }
172   return TRUE;
173 }
174
175 static void
176 gst_navigationtest_set_property (GObject * object, guint prop_id,
177     const GValue * value, GParamSpec * pspec)
178 {
179   GstNavigationtest *src;
180
181   /* it's not null if we got it, but it might not be ours */
182   g_return_if_fail (GST_IS_NAVIGATIONTEST (object));
183   src = GST_NAVIGATIONTEST (object);
184
185   GST_DEBUG ("gst_navigationtest_set_property");
186   switch (prop_id) {
187 #if 0
188     case ARG_METHOD:
189       src->method = g_value_get_enum (value);
190       break;
191 #endif
192     default:
193       break;
194   }
195 }
196
197 static void
198 gst_navigationtest_get_property (GObject * object, guint prop_id,
199     GValue * value, GParamSpec * pspec)
200 {
201   GstNavigationtest *src;
202
203   /* it's not null if we got it, but it might not be ours */
204   g_return_if_fail (GST_IS_NAVIGATIONTEST (object));
205   src = GST_NAVIGATIONTEST (object);
206
207   switch (prop_id) {
208 #if 0
209     case ARG_METHOD:
210       g_value_set_enum (value, src->method);
211       break;
212 #endif
213     default:
214       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
215       break;
216   }
217 }
218
219 static gboolean
220 plugin_init (GstPlugin * plugin)
221 {
222   if (!gst_library_load ("gstvideofilter"))
223     return FALSE;
224
225   return gst_element_register (plugin, "navigationtest", GST_RANK_NONE,
226       GST_TYPE_NAVIGATIONTEST);
227 }
228
229 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
230     GST_VERSION_MINOR,
231     "navigationtest",
232     "Template for a video filter",
233     plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN)
234
235      static void gst_navigationtest_setup (GstVideofilter * videofilter)
236 {
237   GstNavigationtest *navigationtest;
238
239   g_return_if_fail (GST_IS_NAVIGATIONTEST (videofilter));
240   navigationtest = GST_NAVIGATIONTEST (videofilter);
241
242   /* if any setup needs to be done, do it here */
243
244 }
245
246 static void
247 gst_navigationtest_planar411 (GstVideofilter * videofilter,
248     void *dest, void *src)
249 {
250   GstNavigationtest *navigationtest;
251   int width = gst_videofilter_get_input_width (videofilter);
252   int height = gst_videofilter_get_input_height (videofilter);
253   int x, y;
254   int x1, x2, y1, y2;
255
256   g_return_if_fail (GST_IS_NAVIGATIONTEST (videofilter));
257   navigationtest = GST_NAVIGATIONTEST (videofilter);
258
259   /* do something interesting here.  This simply copies the source
260    * to the destination. */
261   memcpy (dest, src, width * height + (width / 2) * (height / 2) * 2);
262
263   x = rint (navigationtest->x);
264   y = rint (navigationtest->y);
265
266   if (x < 0 || y < 0 || x >= width || y >= height)
267     return;
268
269   x1 = MAX (x - 5, 0);
270   x2 = MIN (x + 5, width);
271   y1 = MAX (y - 5, 0);
272   y2 = MIN (y + 5, height);
273
274   for (y = y1; y < y2; y++) {
275     for (x = x1; x < x2; x++) {
276       ((guint8 *) dest)[y * width + x] = 0;
277     }
278   }
279
280   dest += height * width;
281   width /= 2;
282   height /= 2;
283   x1 /= 2;
284   x2 /= 2;
285   y1 /= 2;
286   y2 /= 2;
287   for (y = y1; y < y2; y++) {
288     for (x = x1; x < x2; x++) {
289       ((guint8 *) dest)[y * width + x] = 128;
290     }
291   }
292
293   dest += height * width;
294   for (y = y1; y < y2; y++) {
295     for (x = x1; x < x2; x++) {
296       ((guint8 *) dest)[y * width + x] = 128;
297     }
298   }
299
300 }