97ada3785cc8d6c78616f372235a206325610731
[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   /* FILL ME */
38   LAST_SIGNAL
39 };
40
41 enum {
42   ARG_0,
43   /* FILL ME */
44 };
45
46 static void     gst_navigationtest_base_init    (gpointer g_class);
47 static void     gst_navigationtest_class_init   (gpointer g_class, gpointer class_data);
48 static void     gst_navigationtest_init         (GTypeInstance *instance, gpointer g_class);
49
50 static gboolean gst_navigationtest_handle_src_event    (GstPad *pad, GstEvent *event);
51 static void     gst_navigationtest_set_property         (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
52 static void     gst_navigationtest_get_property         (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
53
54 static void gst_navigationtest_planar411(GstVideofilter *videofilter, void *dest, void *src);
55 static void gst_navigationtest_setup(GstVideofilter *videofilter);
56
57 GType
58 gst_navigationtest_get_type (void)
59 {
60   static GType navigationtest_type = 0;
61
62   if (!navigationtest_type) {
63     static const GTypeInfo navigationtest_info = {
64       sizeof(GstNavigationtestClass),
65       gst_navigationtest_base_init,
66       NULL,
67       gst_navigationtest_class_init,
68       NULL,
69       NULL,
70       sizeof(GstNavigationtest),
71       0,
72       gst_navigationtest_init,
73     };
74     navigationtest_type = g_type_register_static(GST_TYPE_VIDEOFILTER,
75         "GstNavigationtest", &navigationtest_info, 0);
76   }
77   return navigationtest_type;
78 }
79
80 static GstVideofilterFormat gst_navigationtest_formats[] = {
81   { "I420", 12, gst_navigationtest_planar411, },
82 };
83
84   
85 static void
86 gst_navigationtest_base_init (gpointer g_class)
87 {
88   static GstElementDetails navigationtest_details = GST_ELEMENT_DETAILS (
89     "Video Filter Template",
90     "Filter/Video",
91     "Template for a video filter",
92     "David Schleef <ds@schleef.org>"
93   );
94   GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
95   GstVideofilterClass *videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
96   int i;
97   
98   gst_element_class_set_details (element_class, &navigationtest_details);
99
100   for(i=0;i<G_N_ELEMENTS(gst_navigationtest_formats);i++){
101     gst_videofilter_class_add_format(videofilter_class,
102         gst_navigationtest_formats + i);
103   }
104
105   gst_videofilter_class_add_pad_templates (GST_VIDEOFILTER_CLASS (g_class));
106 }
107
108 static void
109 gst_navigationtest_class_init (gpointer g_class, gpointer class_data)
110 {
111   GObjectClass *gobject_class;
112   GstVideofilterClass *videofilter_class;
113
114   gobject_class = G_OBJECT_CLASS (g_class);
115   videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
116
117 #if 0
118   g_object_class_install_property(gobject_class, ARG_METHOD,
119       g_param_spec_enum("method","method","method",
120       GST_TYPE_NAVIGATIONTEST_METHOD, GST_NAVIGATIONTEST_METHOD_1,
121       G_PARAM_READWRITE));
122 #endif
123
124   gobject_class->set_property = gst_navigationtest_set_property;
125   gobject_class->get_property = gst_navigationtest_get_property;
126
127   videofilter_class->setup = gst_navigationtest_setup;
128 }
129
130 static void
131 gst_navigationtest_init (GTypeInstance *instance, gpointer g_class)
132 {
133   GstNavigationtest *navigationtest = GST_NAVIGATIONTEST (instance);
134   GstVideofilter *videofilter;
135
136   GST_DEBUG("gst_navigationtest_init");
137
138   videofilter = GST_VIDEOFILTER(navigationtest);
139
140   gst_pad_set_event_function (videofilter->srcpad,
141       gst_navigationtest_handle_src_event);
142
143   navigationtest->x = -1;
144   navigationtest->y = -1;
145 }
146
147 static gboolean
148 gst_navigationtest_handle_src_event (GstPad *pad, GstEvent *event)
149 {
150   GstNavigationtest *navigationtest;
151
152   navigationtest = GST_NAVIGATIONTEST (gst_pad_get_parent (pad));
153
154   switch (GST_EVENT_TYPE (event)) {
155     case GST_EVENT_NAVIGATION:
156       gst_structure_get_double(event->event_data.structure.structure,
157           "pointer_x", &navigationtest->x);
158       gst_structure_get_double(event->event_data.structure.structure,
159           "pointer_y", &navigationtest->y);
160       break;
161     default:
162       break;
163   }
164   return TRUE;
165 }
166
167 static void
168 gst_navigationtest_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
169 {
170   GstNavigationtest *src;
171
172   /* it's not null if we got it, but it might not be ours */
173   g_return_if_fail(GST_IS_NAVIGATIONTEST(object));
174   src = GST_NAVIGATIONTEST(object);
175
176   GST_DEBUG("gst_navigationtest_set_property");
177   switch (prop_id) {
178 #if 0
179     case ARG_METHOD:
180       src->method = g_value_get_enum (value);
181       break;
182 #endif
183     default:
184       break;
185   }
186 }
187
188 static void
189 gst_navigationtest_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
190 {
191   GstNavigationtest *src;
192
193   /* it's not null if we got it, but it might not be ours */
194   g_return_if_fail(GST_IS_NAVIGATIONTEST(object));
195   src = GST_NAVIGATIONTEST(object);
196
197   switch (prop_id) {
198 #if 0
199     case ARG_METHOD:
200       g_value_set_enum (value, src->method);
201       break;
202 #endif
203     default:
204       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
205       break;
206   }
207 }
208
209 static gboolean plugin_init (GstPlugin *plugin)
210 {
211   if(!gst_library_load("gstvideofilter"))
212     return FALSE;
213
214   return gst_element_register (plugin, "navigationtest", GST_RANK_NONE,
215       GST_TYPE_NAVIGATIONTEST);
216 }
217
218 GST_PLUGIN_DEFINE (
219   GST_VERSION_MAJOR,
220   GST_VERSION_MINOR,
221   "navigationtest",
222   "Template for a video filter",
223   plugin_init,
224   VERSION,
225   GST_LICENSE,
226   GST_COPYRIGHT,
227   GST_PACKAGE,
228   GST_ORIGIN
229 )
230
231 static void gst_navigationtest_setup(GstVideofilter *videofilter)
232 {
233   GstNavigationtest *navigationtest;
234
235   g_return_if_fail(GST_IS_NAVIGATIONTEST(videofilter));
236   navigationtest = GST_NAVIGATIONTEST(videofilter);
237
238   /* if any setup needs to be done, do it here */
239
240 }
241
242 static void gst_navigationtest_planar411(GstVideofilter *videofilter,
243     void *dest, void *src)
244 {
245   GstNavigationtest *navigationtest;
246   int width = gst_videofilter_get_input_width(videofilter);
247   int height = gst_videofilter_get_input_height(videofilter);
248   int x,y;
249   int x1, x2, y1, y2;
250
251   g_return_if_fail(GST_IS_NAVIGATIONTEST(videofilter));
252   navigationtest = GST_NAVIGATIONTEST(videofilter);
253
254   /* do something interesting here.  This simply copies the source
255    * to the destination. */
256   memcpy(dest,src,width * height + (width/2) * (height/2) * 2);
257
258   x = rint(navigationtest->x);
259   y = rint(navigationtest->y);
260
261   if(x<0 || y<0 || x>=width || y>=height)return;
262
263   x1 = MAX(x-5, 0);
264   x2 = MIN(x+5, width);
265   y1 = MAX(y-5, 0);
266   y2 = MIN(y+5, height);
267
268   for(y=y1;y<y2;y++){
269     for(x=x1;x<x2;x++){
270       ((guint8 *)dest)[y*width + x] = 0;
271     }
272   }
273
274   dest += height*width;
275   width /= 2;
276   height /= 2;
277   x1 /= 2;
278   x2 /= 2;
279   y1 /= 2;
280   y2 /= 2;
281   for(y=y1;y<y2;y++){
282     for(x=x1;x<x2;x++){
283       ((guint8 *)dest)[y*width + x] = 128;
284     }
285   }
286
287   dest += height*width;
288   for(y=y1;y<y2;y++){
289     for(x=x1;x<x2;x++){
290       ((guint8 *)dest)[y*width + x] = 128;
291     }
292   }
293
294 }
295