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 <gst/video/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(klass) \
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 const GstElementDetails vertigotv_details =
80 GST_ELEMENT_DETAILS ("VertigoTV effect",
81 "Filter/Effect/Video",
82 "A loopback alpha blending effector with rotating and scaling",
83 "Wim Taymans <wim.taymans@chello.be>");
85 static GstStaticPadTemplate gst_vertigotv_src_template =
86 GST_STATIC_PAD_TEMPLATE ("src",
89 GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx)
92 static GstStaticPadTemplate gst_vertigotv_sink_template =
93 GST_STATIC_PAD_TEMPLATE ("sink",
96 GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx)
99 static GstVideoFilterClass *parent_class = NULL;
102 gst_vertigotv_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
105 GstVertigoTV *filter = GST_VERTIGOTV (btrans);
106 GstStructure *structure;
107 gboolean ret = FALSE;
109 structure = gst_caps_get_structure (incaps, 0);
111 if (gst_structure_get_int (structure, "width", &filter->width) &&
112 gst_structure_get_int (structure, "height", &filter->height)) {
113 gint area = filter->width * filter->height;
115 g_free (filter->buffer);
116 filter->buffer = (guint32 *) g_malloc (area * 2 * sizeof (guint32));
118 memset (filter->buffer, 0, area * 2 * sizeof (guint32));
119 filter->current_buffer = filter->buffer;
120 filter->alt_buffer = filter->buffer + area;
130 gst_vertigotv_get_unit_size (GstBaseTransform * btrans, GstCaps * caps,
133 GstVertigoTV *filter;
134 GstStructure *structure;
135 gboolean ret = FALSE;
138 filter = GST_VERTIGOTV (btrans);
140 structure = gst_caps_get_structure (caps, 0);
142 if (gst_structure_get_int (structure, "width", &width) &&
143 gst_structure_get_int (structure, "height", &height)) {
144 *size = width * height * 32 / 8;
146 GST_DEBUG_OBJECT (filter, "our frame size is %d bytes (%dx%d)", *size,
154 gst_vertigotv_set_parms (GstVertigoTV * filter)
161 dizz = sin (filter->phase) * 10 + sin (filter->phase * 1.9 + 5) * 5;
163 x = filter->width / 2;
164 y = filter->height / 2;
166 t = (x * x + y * y) * filter->zoomrate;
168 if (filter->width > filter->height) {
172 vx = (x * (x - dizz) + y * y) / t;
176 vx = (x * (x + dizz) + y * y) / t;
183 vx = (x * x + y * (y - dizz)) / t;
187 vx = (x * x + y * (y + dizz)) / t;
191 filter->dx = vx * 65536;
192 filter->dy = vy * 65536;
193 filter->sx = (-vx * x + vy * y + x + cos (filter->phase * 5) * 2) * 65536;
194 filter->sy = (-vx * y - vy * x + y + sin (filter->phase * 6) * 2) * 65536;
196 filter->phase += filter->phase_increment;
197 if (filter->phase > 5700000)
202 gst_vertigotv_transform (GstBaseTransform * trans, GstBuffer * in,
205 GstVertigoTV *filter;
206 guint32 *src, *dest, *p;
208 gint x, y, ox, oy, i, width, height, area;
209 GstFlowReturn ret = GST_FLOW_OK;
211 filter = GST_VERTIGOTV (trans);
213 gst_buffer_copy_metadata (out, in, GST_BUFFER_COPY_TIMESTAMPS);
215 src = (guint32 *) GST_BUFFER_DATA (in);
216 dest = (guint32 *) GST_BUFFER_DATA (out);
218 width = filter->width;
219 height = filter->height;
220 area = width * height;
222 gst_vertigotv_set_parms (filter);
223 p = filter->alt_buffer;
225 for (y = height; y > 0; y--) {
229 for (x = width; x > 0; x--) {
230 i = (oy >> 16) * width + (ox >> 16);
236 v = filter->current_buffer[i] & 0xfcfcff;
237 v = (v * 3) + ((*src++) & 0xfcfcff);
243 filter->sx -= filter->dy;
244 filter->sy += filter->dx;
247 memcpy (dest, filter->alt_buffer, area * sizeof (guint32));
249 p = filter->current_buffer;
250 filter->current_buffer = filter->alt_buffer;
251 filter->alt_buffer = p;
257 gst_vertigotv_set_property (GObject * object, guint prop_id,
258 const GValue * value, GParamSpec * pspec)
260 GstVertigoTV *filter;
262 g_return_if_fail (GST_IS_VERTIGOTV (object));
264 filter = GST_VERTIGOTV (object);
268 filter->phase_increment = g_value_get_float (value);
271 filter->zoomrate = g_value_get_float (value);
279 gst_vertigotv_get_property (GObject * object, guint prop_id, GValue * value,
282 GstVertigoTV *filter;
284 g_return_if_fail (GST_IS_VERTIGOTV (object));
286 filter = GST_VERTIGOTV (object);
290 g_value_set_float (value, filter->phase_increment);
293 g_value_set_float (value, filter->zoomrate);
296 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
302 gst_vertigotv_base_init (gpointer g_class)
304 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
306 gst_element_class_set_details (element_class, &vertigotv_details);
308 gst_element_class_add_pad_template (element_class,
309 gst_static_pad_template_get (&gst_vertigotv_sink_template));
310 gst_element_class_add_pad_template (element_class,
311 gst_static_pad_template_get (&gst_vertigotv_src_template));
315 gst_vertigotv_class_init (gpointer klass, gpointer class_data)
317 GObjectClass *gobject_class;
318 GstBaseTransformClass *trans_class;
320 gobject_class = (GObjectClass *) klass;
321 trans_class = (GstBaseTransformClass *) klass;
323 parent_class = g_type_class_peek_parent (klass);
325 gobject_class->set_property = gst_vertigotv_set_property;
326 gobject_class->get_property = gst_vertigotv_get_property;
328 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SPEED,
329 g_param_spec_float ("speed", "Speed", "Control the speed of movement",
330 0.01, 100.0, 0.02, G_PARAM_READWRITE));
331 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ZOOM_SPEED,
332 g_param_spec_float ("zoom_speed", "Zoom Speed",
333 "Control the rate of zooming", 1.01, 1.1, 1.01, G_PARAM_READWRITE));
335 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_vertigotv_set_caps);
336 trans_class->get_unit_size = GST_DEBUG_FUNCPTR (gst_vertigotv_get_unit_size);
337 trans_class->transform = GST_DEBUG_FUNCPTR (gst_vertigotv_transform);
341 gst_vertigotv_init (GTypeInstance * instance, gpointer g_class)
343 GstVertigoTV *filter = GST_VERTIGOTV (instance);
345 filter->buffer = NULL;
347 filter->phase_increment = 0.02;
348 filter->zoomrate = 1.01;
352 gst_vertigotv_get_type (void)
354 static GType vertigotv_type = 0;
356 if (!vertigotv_type) {
357 static const GTypeInfo vertigotv_info = {
358 sizeof (GstVertigoTVClass),
359 gst_vertigotv_base_init,
361 (GClassInitFunc) gst_vertigotv_class_init,
364 sizeof (GstVertigoTV),
366 (GInstanceInitFunc) gst_vertigotv_init,
370 g_type_register_static (GST_TYPE_VIDEO_FILTER, "GstVertigoTV",
373 return vertigotv_type;