2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
5 * Copyright (C) 2001 FUKUCHI Kentarou
7 * EffecTV is free software. This library is free software;
8 * you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
29 #include <gstvideofilter.h>
34 #include <gst/video/video.h>
36 #define GST_TYPE_VERTIGOTV \
37 (gst_vertigotv_get_type())
38 #define GST_VERTIGOTV(obj) \
39 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_VERTIGOTV,GstVertigoTV))
40 #define GST_VERTIGOTV_CLASS(klass) \
41 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_VERTIGOTV,GstVertigoTVClass))
42 #define GST_IS_VERTIGOTV(obj) \
43 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_VERTIGOTV))
44 #define GST_IS_VERTIGOTV_CLASS(obj) \
45 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_VERTIGOTV))
47 typedef struct _GstVertigoTV GstVertigoTV;
48 typedef struct _GstVertigoTVClass GstVertigoTVClass;
52 GstVideofilter videofilter;
56 guint32 *current_buffer, *alt_buffer;
60 gdouble phase_increment;
64 struct _GstVertigoTVClass
66 GstVideofilterClass parent_class;
69 GType gst_vertigotv_get_type (void);
71 /* Filter signals and args */
79 static GstElementDetails vertigotv_details = GST_ELEMENT_DETAILS ("VertigoTV",
80 "Filter/Effect/Video",
81 "A loopback alpha blending effector with rotating and scaling",
82 "Wim Taymans <wim.taymans@chello.be>");
84 static GstStaticPadTemplate gst_vertigotv_src_template =
85 GST_STATIC_PAD_TEMPLATE ("src",
88 GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx)
91 static GstStaticPadTemplate gst_vertigotv_sink_template =
92 GST_STATIC_PAD_TEMPLATE ("sink",
95 GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx)
98 static GstVideofilterClass *parent_class = NULL;
101 gst_vertigotv_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
104 GstVertigoTV *filter = GST_VERTIGOTV (btrans);
105 GstStructure *structure;
106 gboolean ret = FALSE;
108 structure = gst_caps_get_structure (incaps, 0);
110 if (gst_structure_get_int (structure, "width", &filter->width) &&
111 gst_structure_get_int (structure, "height", &filter->height)) {
112 gint area = filter->width * filter->height;
114 g_free (filter->buffer);
115 filter->buffer = (guint32 *) g_malloc (area * 2 * sizeof (guint32));
117 memset (filter->buffer, 0, area * 2 * sizeof (guint32));
118 filter->current_buffer = filter->buffer;
119 filter->alt_buffer = filter->buffer + area;
129 gst_vertigotv_get_unit_size (GstBaseTransform * btrans, GstCaps * caps,
132 GstVertigoTV *filter;
133 GstStructure *structure;
134 gboolean ret = FALSE;
137 filter = GST_VERTIGOTV (btrans);
139 structure = gst_caps_get_structure (caps, 0);
141 if (gst_structure_get_int (structure, "width", &width) &&
142 gst_structure_get_int (structure, "height", &height)) {
143 *size = width * height * 32 / 8;
145 GST_DEBUG_OBJECT (filter, "our frame size is %d bytes (%dx%d)", *size,
153 gst_vertigotv_set_parms (GstVertigoTV * filter)
160 dizz = sin (filter->phase) * 10 + sin (filter->phase * 1.9 + 5) * 5;
162 x = filter->width / 2;
163 y = filter->height / 2;
165 t = (x * x + y * y) * filter->zoomrate;
167 if (filter->width > filter->height) {
171 vx = (x * (x - dizz) + y * y) / t;
175 vx = (x * (x + dizz) + y * y) / t;
182 vx = (x * x + y * (y - dizz)) / t;
186 vx = (x * x + y * (y + dizz)) / t;
190 filter->dx = vx * 65536;
191 filter->dy = vy * 65536;
192 filter->sx = (-vx * x + vy * y + x + cos (filter->phase * 5) * 2) * 65536;
193 filter->sy = (-vx * y - vy * x + y + sin (filter->phase * 6) * 2) * 65536;
195 filter->phase += filter->phase_increment;
196 if (filter->phase > 5700000)
201 gst_vertigotv_transform (GstBaseTransform * trans, GstBuffer * in,
204 GstVertigoTV *filter;
205 guint32 *src, *dest, *p;
207 gint x, y, ox, oy, i, width, height, area;
208 GstFlowReturn ret = GST_FLOW_OK;
210 filter = GST_VERTIGOTV (trans);
212 gst_buffer_stamp (out, in);
214 src = (guint32 *) GST_BUFFER_DATA (in);
215 dest = (guint32 *) GST_BUFFER_DATA (out);
217 width = filter->width;
218 height = filter->height;
219 area = width * height;
221 gst_vertigotv_set_parms (filter);
222 p = filter->alt_buffer;
224 for (y = height; y > 0; y--) {
228 for (x = width; x > 0; x--) {
229 i = (oy >> 16) * width + (ox >> 16);
235 v = filter->current_buffer[i] & 0xfcfcff;
236 v = (v * 3) + ((*src++) & 0xfcfcff);
242 filter->sx -= filter->dy;
243 filter->sy += filter->dx;
246 memcpy (dest, filter->alt_buffer, area * sizeof (guint32));
248 p = filter->current_buffer;
249 filter->current_buffer = filter->alt_buffer;
250 filter->alt_buffer = p;
256 gst_vertigotv_set_property (GObject * object, guint prop_id,
257 const GValue * value, GParamSpec * pspec)
259 GstVertigoTV *filter;
261 g_return_if_fail (GST_IS_VERTIGOTV (object));
263 filter = GST_VERTIGOTV (object);
267 filter->phase_increment = g_value_get_float (value);
270 filter->zoomrate = g_value_get_float (value);
278 gst_vertigotv_get_property (GObject * object, guint prop_id, GValue * value,
281 GstVertigoTV *filter;
283 g_return_if_fail (GST_IS_VERTIGOTV (object));
285 filter = GST_VERTIGOTV (object);
289 g_value_set_float (value, filter->phase_increment);
292 g_value_set_float (value, filter->zoomrate);
295 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
301 gst_vertigotv_base_init (gpointer g_class)
303 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
305 gst_element_class_set_details (element_class, &vertigotv_details);
307 gst_element_class_add_pad_template (element_class,
308 gst_static_pad_template_get (&gst_vertigotv_sink_template));
309 gst_element_class_add_pad_template (element_class,
310 gst_static_pad_template_get (&gst_vertigotv_src_template));
314 gst_vertigotv_class_init (gpointer klass, gpointer class_data)
316 GObjectClass *gobject_class;
317 GstElementClass *element_class;
318 GstBaseTransformClass *trans_class;
320 gobject_class = (GObjectClass *) klass;
321 element_class = (GstElementClass *) klass;
322 trans_class = (GstBaseTransformClass *) klass;
324 parent_class = g_type_class_peek_parent (klass);
326 gobject_class->set_property = gst_vertigotv_set_property;
327 gobject_class->get_property = gst_vertigotv_get_property;
329 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SPEED,
330 g_param_spec_float ("speed", "Speed", "Control the speed of movement",
331 0.01, 100.0, 0.02, G_PARAM_READWRITE));
332 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ZOOM_SPEED,
333 g_param_spec_float ("zoom_speed", "Zoom Speed",
334 "Control the rate of zooming", 1.01, 1.1, 1.01, G_PARAM_READWRITE));
336 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_vertigotv_set_caps);
337 trans_class->get_unit_size = GST_DEBUG_FUNCPTR (gst_vertigotv_get_unit_size);
338 trans_class->transform = GST_DEBUG_FUNCPTR (gst_vertigotv_transform);
342 gst_vertigotv_init (GTypeInstance * instance, gpointer g_class)
344 GstVertigoTV *filter = GST_VERTIGOTV (instance);
346 filter->buffer = NULL;
348 filter->phase_increment = 0.02;
349 filter->zoomrate = 1.01;
353 gst_vertigotv_get_type (void)
355 static GType vertigotv_type = 0;
357 if (!vertigotv_type) {
358 static const GTypeInfo vertigotv_info = {
359 sizeof (GstVertigoTVClass),
360 gst_vertigotv_base_init,
362 (GClassInitFunc) gst_vertigotv_class_init,
365 sizeof (GstVertigoTV),
367 (GInstanceInitFunc) gst_vertigotv_init,
371 g_type_register_static (GST_TYPE_VIDEOFILTER, "GstVertigoTV",
374 return vertigotv_type;