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.
31 #include <gstvideofilter.h>
33 #define GST_TYPE_VERTIGOTV \
34 (gst_vertigotv_get_type())
35 #define GST_VERTIGOTV(obj) \
36 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_VERTIGOTV,GstVertigoTV))
37 #define GST_VERTIGOTV_CLASS(klass) \
38 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_VERTIGOTV,GstVertigoTVClass))
39 #define GST_IS_VERTIGOTV(obj) \
40 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_VERTIGOTV))
41 #define GST_IS_VERTIGOTV_CLASS(obj) \
42 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_VERTIGOTV))
44 typedef struct _GstVertigoTV GstVertigoTV;
45 typedef struct _GstVertigoTVClass GstVertigoTVClass;
49 GstVideofilter videofilter;
53 guint32 *current_buffer, *alt_buffer;
57 gdouble phase_increment;
61 struct _GstVertigoTVClass
63 GstVideofilterClass parent_class;
65 void (*reset) (GstElement *element);
68 /* Filter signals and args */
83 static void gst_vertigotv_base_init (gpointer g_class);
84 static void gst_vertigotv_class_init (GstVertigoTVClass * klass, gpointer class_data);
85 static void gst_vertigotv_init (GTypeInstance *instance, gpointer g_class);
86 static void gst_vertigotv_setup (GstVideofilter *videofilter);
88 static void gst_vertigotv_reset_handler (GstElement *element);
90 static void gst_vertigotv_set_property (GObject * object, guint prop_id,
91 const GValue * value, GParamSpec * pspec);
92 static void gst_vertigotv_get_property (GObject * object, guint prop_id,
93 GValue * value, GParamSpec * pspec);
94 static void gst_vertigotv_rgb32 (GstVideofilter *videofilter, void *d, void *s);
96 static guint gst_vertigotv_signals[LAST_SIGNAL] = { 0 };
98 GType gst_vertigotv_get_type (void)
100 static GType vertigotv_type = 0;
102 if (!vertigotv_type) {
103 static const GTypeInfo vertigotv_info = {
104 sizeof (GstVertigoTVClass),
105 gst_vertigotv_base_init,
107 (GClassInitFunc) gst_vertigotv_class_init,
110 sizeof (GstVertigoTV),
112 (GInstanceInitFunc) gst_vertigotv_init,
115 vertigotv_type = g_type_register_static (GST_TYPE_VIDEOFILTER, "GstVertigoTV", &vertigotv_info, 0);
117 return vertigotv_type;
120 static GstVideofilterFormat gst_vertigotv_formats[] = {
121 { "RGB ", 32, gst_vertigotv_rgb32, 24, G_BIG_ENDIAN, 0x0000ff00, 0x00ff0000, 0xff000000 }
125 gst_vertigotv_base_init (gpointer g_class)
127 /* elementfactory information */
128 static GstElementDetails vertigotv_details = GST_ELEMENT_DETAILS (
130 "Filter/Effect/Video",
131 "A loopback alpha blending effector with rotating and scaling",
132 "Wim Taymans <wim.taymans@chello.be>"
134 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
135 GstVideofilterClass *videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
138 gst_element_class_set_details (element_class, &vertigotv_details);
140 for(i=0;i<G_N_ELEMENTS(gst_vertigotv_formats);i++){
141 gst_videofilter_class_add_format(videofilter_class,
142 gst_vertigotv_formats + i);
145 gst_videofilter_class_add_pad_templates (GST_VIDEOFILTER_CLASS (g_class));
149 gst_vertigotv_class_init (GstVertigoTVClass * klass, gpointer class_data)
151 GObjectClass *gobject_class;
152 GstElementClass *gstelement_class;
153 GstVideofilterClass *videofilter_class;
155 gobject_class = (GObjectClass *) klass;
156 gstelement_class = (GstElementClass *) klass;
157 videofilter_class = GST_VIDEOFILTER_CLASS (klass);
159 gst_vertigotv_signals[RESET_SIGNAL] =
160 g_signal_new ("reset-parms",
161 G_TYPE_FROM_CLASS (klass),
162 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
163 G_STRUCT_OFFSET (GstVertigoTVClass, reset),
165 g_cclosure_marshal_VOID__VOID,
168 klass->reset = gst_vertigotv_reset_handler;
170 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SPEED,
171 g_param_spec_float ("speed","Speed","Control the speed of movement",
172 0.01, 100.0, 0.02, G_PARAM_READWRITE));
173 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ZOOM_SPEED,
174 g_param_spec_float ("zoom_speed","Zoom Speed","Control the rate of zooming",
175 1.01, 1.1, 1.01, G_PARAM_READWRITE));
177 gobject_class->set_property = gst_vertigotv_set_property;
178 gobject_class->get_property = gst_vertigotv_get_property;
180 videofilter_class->setup = gst_vertigotv_setup;
184 gst_vertigotv_reset_handler (GstElement *element)
186 GstVertigoTV *filter = GST_VERTIGOTV (element);
189 filter->phase_increment = 0.02;
190 filter->zoomrate = 1.01;
194 gst_vertigotv_setup(GstVideofilter *videofilter)
196 GstVertigoTV *filter;
198 int width = gst_videofilter_get_input_width(videofilter);
199 int height = gst_videofilter_get_input_height(videofilter);
201 g_return_if_fail(GST_IS_VERTIGOTV(videofilter));
202 filter = GST_VERTIGOTV(videofilter);
204 filter->width = width;
205 filter->height = height;
207 area = width * height;
209 g_free (filter->buffer);
210 filter->buffer = (guint32 *) g_malloc (area * 2 * sizeof(guint32));
212 memset (filter->buffer, 0, area * 2 * sizeof(guint32));
213 filter->current_buffer = filter->buffer;
214 filter->alt_buffer = filter->buffer + area;
219 gst_vertigotv_init (GTypeInstance *instance, gpointer g_class)
221 GstVertigoTV *filter = GST_VERTIGOTV (instance);
223 filter->buffer = NULL;
225 filter->phase_increment = 0.02;
226 filter->zoomrate = 1.01;
230 gst_vertigotv_set_parms (GstVertigoTV *filter)
237 dizz = sin (filter->phase) * 10 + sin (filter->phase*1.9+5) * 5;
239 x = filter->width / 2;
240 y = filter->height / 2;
242 t = (x*x + y*y) * filter->zoomrate;
244 if (filter->width > filter->height) {
246 if (dizz > x) dizz = x;
247 vx = (x * (x - dizz) + y * y) / t;
249 if (dizz < -x) dizz = -x;
250 vx = (x * (x + dizz) + y * y) / t;
255 if (dizz > y) dizz = y;
256 vx = (x * x + y * (y - dizz)) / t;
258 if (dizz < -y) dizz = -y;
259 vx = (x * x + y * (y + dizz)) / t;
263 filter->dx = vx * 65536;
264 filter->dy = vy * 65536;
265 filter->sx = (-vx * x + vy * y + x + cos (filter->phase * 5) * 2) * 65536;
266 filter->sy = (-vx * y - vy * x + y + sin (filter->phase * 6) * 2) * 65536;
268 filter->phase += filter->phase_increment;
269 if (filter->phase > 5700000) filter->phase = 0;
273 gst_vertigotv_rgb32 (GstVideofilter *videofilter, void *d, void *s)
275 GstVertigoTV *filter;
282 gint width, height, area;
284 filter = GST_VERTIGOTV (videofilter);
287 dest = (guint32 *) d;
289 width = filter->width;
290 height = filter->height;
291 area = width * height;
293 gst_vertigotv_set_parms (filter);
294 p = filter->alt_buffer;
296 for (y = height; y > 0; y--) {
300 for (x = width; x > 0; x--) {
301 i = (oy >> 16) * width + (ox >> 16);
303 if (i >= area) i = area;
305 v = filter->current_buffer[i] & 0xfcfcff;
306 v = (v * 3) + ((*src++) & 0xfcfcff);
312 filter->sx -= filter->dy;
313 filter->sy += filter->dx;
316 memcpy(dest, filter->alt_buffer, area * sizeof(guint32));
318 p = filter->current_buffer;
319 filter->current_buffer = filter->alt_buffer;
320 filter->alt_buffer = p;
324 gst_vertigotv_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec)
326 GstVertigoTV *filter;
328 /* it's not null if we got it, but it might not be ours */
329 g_return_if_fail (GST_IS_VERTIGOTV (object));
331 filter = GST_VERTIGOTV (object);
335 filter->phase_increment = g_value_get_float (value);
338 filter->zoomrate = g_value_get_float (value);
346 gst_vertigotv_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec)
348 GstVertigoTV *filter;
350 /* it's not null if we got it, but it might not be ours */
351 g_return_if_fail (GST_IS_VERTIGOTV (object));
353 filter = GST_VERTIGOTV (object);
357 g_value_set_float (value, filter->phase_increment);
360 g_value_set_float (value, filter->zoomrate);
363 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);