Way, way, way too many files: Remove crack comment from the 2000 era.
[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 typedef struct
49 {
50   double x;
51   double y;
52   gint images_left;
53   guint8 cy, cu, cv;
54 } ButtonClick;
55
56 static void gst_navigationtest_base_init (gpointer g_class);
57 static void gst_navigationtest_class_init (gpointer g_class,
58     gpointer class_data);
59 static void gst_navigationtest_init (GTypeInstance * instance,
60     gpointer g_class);
61
62 static gboolean gst_navigationtest_handle_src_event (GstPad * pad,
63     GstEvent * event);
64 static void gst_navigationtest_set_property (GObject * object, guint prop_id,
65     const GValue * value, GParamSpec * pspec);
66 static void gst_navigationtest_get_property (GObject * object, guint prop_id,
67     GValue * value, GParamSpec * pspec);
68
69 static GstElementStateReturn
70 gst_navigationtest_change_state (GstElement * element);
71
72 static void gst_navigationtest_planar411 (GstVideofilter * videofilter,
73     void *dest, void *src);
74 static void gst_navigationtest_setup (GstVideofilter * videofilter);
75
76 static GstVideofilterClass *parent_class = NULL;
77
78 GType
79 gst_navigationtest_get_type (void)
80 {
81   static GType navigationtest_type = 0;
82
83   if (!navigationtest_type) {
84     static const GTypeInfo navigationtest_info = {
85       sizeof (GstNavigationtestClass),
86       gst_navigationtest_base_init,
87       NULL,
88       gst_navigationtest_class_init,
89       NULL,
90       NULL,
91       sizeof (GstNavigationtest),
92       0,
93       gst_navigationtest_init,
94     };
95
96     navigationtest_type = g_type_register_static (GST_TYPE_VIDEOFILTER,
97         "GstNavigationtest", &navigationtest_info, 0);
98   }
99   return navigationtest_type;
100 }
101
102 static GstVideofilterFormat gst_navigationtest_formats[] = {
103   {"I420", 12, gst_navigationtest_planar411,},
104 };
105
106
107 static void
108 gst_navigationtest_base_init (gpointer g_class)
109 {
110   static GstElementDetails navigationtest_details =
111       GST_ELEMENT_DETAILS ("Video Filter Template",
112       "Filter/Video",
113       "Template for a video filter",
114       "David Schleef <ds@schleef.org>");
115   GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
116   GstVideofilterClass *videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
117   int i;
118
119   gst_element_class_set_details (element_class, &navigationtest_details);
120
121   for (i = 0; i < G_N_ELEMENTS (gst_navigationtest_formats); i++) {
122     gst_videofilter_class_add_format (videofilter_class,
123         gst_navigationtest_formats + i);
124   }
125
126   gst_videofilter_class_add_pad_templates (GST_VIDEOFILTER_CLASS (g_class));
127 }
128
129 static void
130 gst_navigationtest_class_init (gpointer g_class, gpointer class_data)
131 {
132   GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
133   GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
134   GstVideofilterClass *videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
135
136   parent_class = g_type_class_peek_parent (g_class);
137
138   gobject_class->set_property = gst_navigationtest_set_property;
139   gobject_class->get_property = gst_navigationtest_get_property;
140
141   element_class->change_state = gst_navigationtest_change_state;
142
143   videofilter_class->setup = gst_navigationtest_setup;
144 }
145
146 static void
147 gst_navigationtest_init (GTypeInstance * instance, gpointer g_class)
148 {
149   GstNavigationtest *navigationtest = GST_NAVIGATIONTEST (instance);
150   GstVideofilter *videofilter;
151
152   GST_DEBUG ("gst_navigationtest_init");
153
154   videofilter = GST_VIDEOFILTER (navigationtest);
155
156   gst_pad_set_event_function (videofilter->srcpad,
157       gst_navigationtest_handle_src_event);
158
159   navigationtest->x = -1;
160   navigationtest->y = -1;
161 }
162
163 static gboolean
164 gst_navigationtest_handle_src_event (GstPad * pad, GstEvent * event)
165 {
166   GstNavigationtest *navigationtest;
167   const gchar *type;
168
169   navigationtest = GST_NAVIGATIONTEST (gst_pad_get_parent (pad));
170
171   switch (GST_EVENT_TYPE (event)) {
172     case GST_EVENT_NAVIGATION:
173       type = gst_structure_get_string (event->event_data.structure.structure,
174           "event");
175       if (g_str_equal (type, "mouse-move")) {
176         gst_structure_get_double (event->event_data.structure.structure,
177             "pointer_x", &navigationtest->x);
178         gst_structure_get_double (event->event_data.structure.structure,
179             "pointer_y", &navigationtest->y);
180       } else if (g_str_equal (type, "mouse-button-press")) {
181         ButtonClick *click = g_new (ButtonClick, 1);
182
183         gst_structure_get_double (event->event_data.structure.structure,
184             "pointer_x", &click->x);
185         gst_structure_get_double (event->event_data.structure.structure,
186             "pointer_y", &click->y);
187         click->images_left = ceil (GST_VIDEOFILTER (navigationtest)->framerate);
188         /* green */
189         click->cy = 150;
190         click->cu = 46;
191         click->cv = 21;
192         navigationtest->clicks =
193             g_slist_prepend (navigationtest->clicks, click);
194       } else if (g_str_equal (type, "mouse-button-release")) {
195         ButtonClick *click = g_new (ButtonClick, 1);
196
197         gst_structure_get_double (event->event_data.structure.structure,
198             "pointer_x", &click->x);
199         gst_structure_get_double (event->event_data.structure.structure,
200             "pointer_y", &click->y);
201         click->images_left = ceil (GST_VIDEOFILTER (navigationtest)->framerate);
202         /* red */
203         click->cy = 76;
204         click->cu = 85;
205         click->cv = 255;
206         navigationtest->clicks =
207             g_slist_prepend (navigationtest->clicks, click);
208       }
209       break;
210     default:
211       break;
212   }
213   return gst_pad_event_default (pad, event);
214 }
215
216 static void
217 gst_navigationtest_set_property (GObject * object, guint prop_id,
218     const GValue * value, GParamSpec * pspec)
219 {
220   GstNavigationtest *src;
221
222   g_return_if_fail (GST_IS_NAVIGATIONTEST (object));
223   src = GST_NAVIGATIONTEST (object);
224
225   GST_DEBUG ("gst_navigationtest_set_property");
226   switch (prop_id) {
227 #if 0
228     case ARG_METHOD:
229       src->method = g_value_get_enum (value);
230       break;
231 #endif
232     default:
233       break;
234   }
235 }
236
237 static void
238 gst_navigationtest_get_property (GObject * object, guint prop_id,
239     GValue * value, GParamSpec * pspec)
240 {
241   GstNavigationtest *src;
242
243   g_return_if_fail (GST_IS_NAVIGATIONTEST (object));
244   src = GST_NAVIGATIONTEST (object);
245
246   switch (prop_id) {
247 #if 0
248     case ARG_METHOD:
249       g_value_set_enum (value, src->method);
250       break;
251 #endif
252     default:
253       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
254       break;
255   }
256 }
257
258 static gboolean
259 plugin_init (GstPlugin * plugin)
260 {
261   if (!gst_library_load ("gstvideofilter"))
262     return FALSE;
263
264   return gst_element_register (plugin, "navigationtest", GST_RANK_NONE,
265       GST_TYPE_NAVIGATIONTEST);
266 }
267
268 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
269     GST_VERSION_MINOR,
270     "navigationtest",
271     "Template for a video filter",
272     plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN)
273
274      static void gst_navigationtest_setup (GstVideofilter * videofilter)
275 {
276   GstNavigationtest *navigationtest;
277
278   g_return_if_fail (GST_IS_NAVIGATIONTEST (videofilter));
279   navigationtest = GST_NAVIGATIONTEST (videofilter);
280
281   /* if any setup needs to be done, do it here */
282
283 }
284
285 static void
286 draw_box_planar411 (guint8 * dest, int width, int height, int x, int y,
287     guint8 colory, guint8 coloru, guint8 colorv)
288 {
289   int x1, x2, y1, y2;
290
291   if (x < 0 || y < 0 || x >= width || y >= height)
292     return;
293
294   x1 = MAX (x - 5, 0);
295   x2 = MIN (x + 5, width);
296   y1 = MAX (y - 5, 0);
297   y2 = MIN (y + 5, height);
298
299   for (y = y1; y < y2; y++) {
300     for (x = x1; x < x2; x++) {
301       ((guint8 *) dest)[y * width + x] = colory;
302     }
303   }
304
305   dest += height * width;
306   width /= 2;
307   height /= 2;
308   x1 /= 2;
309   x2 /= 2;
310   y1 /= 2;
311   y2 /= 2;
312   for (y = y1; y < y2; y++) {
313     for (x = x1; x < x2; x++) {
314       ((guint8 *) dest)[y * width + x] = coloru;
315     }
316   }
317
318   dest += height * width;
319   for (y = y1; y < y2; y++) {
320     for (x = x1; x < x2; x++) {
321       ((guint8 *) dest)[y * width + x] = colorv;
322     }
323   }
324 }
325
326 static void
327 gst_navigationtest_planar411 (GstVideofilter * videofilter,
328     void *dest, void *src)
329 {
330   GstNavigationtest *navigationtest;
331   int width = gst_videofilter_get_input_width (videofilter);
332   int height = gst_videofilter_get_input_height (videofilter);
333   GSList *walk;
334
335   g_return_if_fail (GST_IS_NAVIGATIONTEST (videofilter));
336   navigationtest = GST_NAVIGATIONTEST (videofilter);
337
338   /* do something interesting here.  This simply copies the source
339    * to the destination. */
340   memcpy (dest, src, width * height + (width / 2) * (height / 2) * 2);
341
342   walk = navigationtest->clicks;
343   while (walk) {
344     ButtonClick *click = walk->data;
345
346     walk = g_slist_next (walk);
347     draw_box_planar411 (dest, width, height, rint (click->x),
348         rint (click->y), click->cy, click->cu, click->cv);
349     if (--click->images_left < 1) {
350       navigationtest->clicks = g_slist_remove (navigationtest->clicks, click);
351       g_free (click);
352     }
353   }
354   draw_box_planar411 (dest, width, height, rint (navigationtest->x),
355       rint (navigationtest->y), 0, 128, 128);
356 }
357
358 static GstElementStateReturn
359 gst_navigationtest_change_state (GstElement * element)
360 {
361   GstNavigationtest *navigation = GST_NAVIGATIONTEST (element);
362
363   switch (GST_STATE_TRANSITION (element)) {
364     case GST_STATE_PAUSED_TO_READY:
365       while (navigation->clicks) {
366         g_free (navigation->clicks->data);
367         navigation->clicks =
368             g_slist_remove (navigation->clicks, navigation->clicks->data);
369       }
370       break;
371   }
372
373   if (GST_ELEMENT_CLASS (parent_class)->change_state)
374     return GST_ELEMENT_CLASS (parent_class)->change_state (element);
375
376   return GST_STATE_SUCCESS;
377 }