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.
25 * SECTION:element-vertigotv
27 * VertigoTV is a loopback alpha blending effector with rotating and scaling.
30 * <title>Example launch line</title>
32 * gst-launch -v videotestsrc ! vertigotv ! ffmpegcolorspace ! autovideosink
33 * ]| This pipeline shows the effect of vertigotv on a test stream.
44 #include "gstvertigo.h"
46 #include <gst/video/video.h>
47 #include <gst/controller/gstcontroller.h>
49 GST_BOILERPLATE (GstVertigoTV, gst_vertigotv, GstVideoFilter,
50 GST_TYPE_VIDEO_FILTER);
52 /* Filter signals and args */
60 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
61 #define CAPS_STR GST_VIDEO_CAPS_RGBx ";" GST_VIDEO_CAPS_BGRx
63 #define CAPS_STR GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_xBGR
66 static GstStaticPadTemplate gst_vertigotv_src_template =
67 GST_STATIC_PAD_TEMPLATE ("src",
70 GST_STATIC_CAPS (CAPS_STR)
73 static GstStaticPadTemplate gst_vertigotv_sink_template =
74 GST_STATIC_PAD_TEMPLATE ("sink",
77 GST_STATIC_CAPS (CAPS_STR)
81 gst_vertigotv_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
84 GstVertigoTV *filter = GST_VERTIGOTV (btrans);
85 GstStructure *structure;
88 structure = gst_caps_get_structure (incaps, 0);
90 GST_OBJECT_LOCK (filter);
91 if (gst_structure_get_int (structure, "width", &filter->width) &&
92 gst_structure_get_int (structure, "height", &filter->height)) {
93 gint area = filter->width * filter->height;
95 g_free (filter->buffer);
96 filter->buffer = (guint32 *) g_malloc0 (area * 2 * sizeof (guint32));
98 filter->current_buffer = filter->buffer;
99 filter->alt_buffer = filter->buffer + area;
104 GST_OBJECT_UNLOCK (filter);
110 gst_vertigotv_set_parms (GstVertigoTV * filter)
117 dizz = sin (filter->phase) * 10 + sin (filter->phase * 1.9 + 5) * 5;
119 x = filter->width / 2;
120 y = filter->height / 2;
122 t = (x * x + y * y) * filter->zoomrate;
124 if (filter->width > filter->height) {
128 vx = (x * (x - dizz) + y * y) / t;
132 vx = (x * (x + dizz) + y * y) / t;
139 vx = (x * x + y * (y - dizz)) / t;
143 vx = (x * x + y * (y + dizz)) / t;
147 filter->dx = vx * 65536;
148 filter->dy = vy * 65536;
149 filter->sx = (-vx * x + vy * y + x + cos (filter->phase * 5) * 2) * 65536;
150 filter->sy = (-vx * y - vy * x + y + sin (filter->phase * 6) * 2) * 65536;
152 filter->phase += filter->phase_increment;
153 if (filter->phase > 5700000)
158 gst_vertigotv_transform (GstBaseTransform * trans, GstBuffer * in,
161 GstVertigoTV *filter = GST_VERTIGOTV (trans);
162 guint32 *src, *dest, *p;
164 gint x, y, ox, oy, i, width, height, area;
165 GstFlowReturn ret = GST_FLOW_OK;
166 GstClockTime timestamp, stream_time;
168 timestamp = GST_BUFFER_TIMESTAMP (in);
170 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME, timestamp);
172 GST_DEBUG_OBJECT (filter, "sync to %" GST_TIME_FORMAT,
173 GST_TIME_ARGS (timestamp));
175 if (GST_CLOCK_TIME_IS_VALID (stream_time))
176 gst_object_sync_values (G_OBJECT (filter), stream_time);
178 src = (guint32 *) GST_BUFFER_DATA (in);
179 dest = (guint32 *) GST_BUFFER_DATA (out);
181 GST_OBJECT_LOCK (filter);
183 width = filter->width;
184 height = filter->height;
185 area = width * height;
187 gst_vertigotv_set_parms (filter);
188 p = filter->alt_buffer;
190 for (y = height; y > 0; y--) {
194 for (x = width; x > 0; x--) {
195 i = (oy >> 16) * width + (ox >> 16);
201 v = filter->current_buffer[i] & 0xfcfcff;
202 v = (v * 3) + ((*src++) & 0xfcfcff);
208 filter->sx -= filter->dy;
209 filter->sy += filter->dx;
212 memcpy (dest, filter->alt_buffer, area * sizeof (guint32));
214 p = filter->current_buffer;
215 filter->current_buffer = filter->alt_buffer;
216 filter->alt_buffer = p;
217 GST_OBJECT_UNLOCK (filter);
223 gst_vertigotv_start (GstBaseTransform * trans)
225 GstVertigoTV *filter = GST_VERTIGOTV (trans);
233 gst_vertigotv_set_property (GObject * object, guint prop_id,
234 const GValue * value, GParamSpec * pspec)
236 GstVertigoTV *filter = GST_VERTIGOTV (object);
238 GST_OBJECT_LOCK (filter);
241 filter->phase_increment = g_value_get_float (value);
243 case PROP_ZOOM_SPEED:
244 filter->zoomrate = g_value_get_float (value);
249 GST_OBJECT_UNLOCK (filter);
253 gst_vertigotv_get_property (GObject * object, guint prop_id, GValue * value,
256 GstVertigoTV *filter = GST_VERTIGOTV (object);
260 g_value_set_float (value, filter->phase_increment);
262 case PROP_ZOOM_SPEED:
263 g_value_set_float (value, filter->zoomrate);
266 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
272 gst_vertigotv_finalize (GObject * object)
274 GstVertigoTV *filter = GST_VERTIGOTV (object);
276 g_free (filter->buffer);
277 filter->buffer = NULL;
279 G_OBJECT_CLASS (parent_class)->finalize (object);
283 gst_vertigotv_base_init (gpointer g_class)
285 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
287 gst_element_class_set_details_simple (element_class, "VertigoTV effect",
288 "Filter/Effect/Video",
289 "A loopback alpha blending effector with rotating and scaling",
290 "Wim Taymans <wim.taymans@chello.be>");
292 gst_element_class_add_pad_template (element_class,
293 gst_static_pad_template_get (&gst_vertigotv_sink_template));
294 gst_element_class_add_pad_template (element_class,
295 gst_static_pad_template_get (&gst_vertigotv_src_template));
299 gst_vertigotv_class_init (GstVertigoTVClass * klass)
301 GObjectClass *gobject_class = (GObjectClass *) klass;
302 GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
304 gobject_class->set_property = gst_vertigotv_set_property;
305 gobject_class->get_property = gst_vertigotv_get_property;
306 gobject_class->finalize = gst_vertigotv_finalize;
308 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SPEED,
309 g_param_spec_float ("speed", "Speed", "Control the speed of movement",
310 0.01, 100.0, 0.02, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
311 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_ZOOM_SPEED,
312 g_param_spec_float ("zoom-speed", "Zoom Speed",
313 "Control the rate of zooming", 1.01, 1.1, 1.01,
314 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
316 trans_class->start = GST_DEBUG_FUNCPTR (gst_vertigotv_start);
317 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_vertigotv_set_caps);
318 trans_class->transform = GST_DEBUG_FUNCPTR (gst_vertigotv_transform);
322 gst_vertigotv_init (GstVertigoTV * filter, GstVertigoTVClass * klass)
324 filter->buffer = NULL;
326 filter->phase_increment = 0.02;
327 filter->zoomrate = 1.01;
329 gst_pad_use_fixed_caps (GST_BASE_TRANSFORM_SRC_PAD (filter));
330 gst_pad_use_fixed_caps (GST_BASE_TRANSFORM_SINK_PAD (filter));