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., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
25 * SECTION:element-vertigotv
28 * VertigoTV is a loopback alpha blending effector with rotating and scaling.
30 * ## Example launch line
32 * gst-launch-1.0 -v videotestsrc ! vertigotv ! videoconvert ! autovideosink
33 * ]| This pipeline shows the effect of vertigotv on a test stream.
44 #include "gsteffectv.h"
45 #include "gstvertigo.h"
47 #define gst_vertigotv_parent_class parent_class
48 G_DEFINE_TYPE (GstVertigoTV, gst_vertigotv, GST_TYPE_VIDEO_FILTER);
49 GST_ELEMENT_REGISTER_DEFINE (vertigotv, "vertigotv", GST_RANK_NONE,
52 /* Filter signals and args */
60 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
61 #define CAPS_STR GST_VIDEO_CAPS_MAKE ("{ RGBx, BGRx }")
63 #define CAPS_STR GST_VIDEO_CAPS_MAKE ("{ xRGB, 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_info (GstVideoFilter * vfilter, GstCaps * incaps,
82 GstVideoInfo * in_info, GstCaps * outcaps, GstVideoInfo * out_info)
84 GstVertigoTV *filter = GST_VERTIGOTV (vfilter);
85 gint area, width, height;
87 width = GST_VIDEO_INFO_WIDTH (in_info);
88 height = GST_VIDEO_INFO_HEIGHT (in_info);
90 area = width * height;
92 g_free (filter->buffer);
93 filter->buffer = (guint32 *) g_malloc0 (area * 2 * sizeof (guint32));
95 filter->current_buffer = filter->buffer;
96 filter->alt_buffer = filter->buffer + area;
103 gst_vertigotv_set_parms (GstVertigoTV * filter)
112 dizz = sin (filter->phase) * 10 + sin (filter->phase * 1.9 + 5) * 5;
114 info = &GST_VIDEO_FILTER (filter)->in_info;
116 width = GST_VIDEO_INFO_WIDTH (info);
117 height = GST_VIDEO_INFO_HEIGHT (info);
122 t = (x * x + y * y) * filter->zoomrate;
124 if (width > 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_frame (GstVideoFilter * vfilter,
159 GstVideoFrame * in_frame, GstVideoFrame * out_frame)
161 GstVertigoTV *filter = GST_VERTIGOTV (vfilter);
162 guint32 *src, *dest, *p;
164 gint x, y, ox, oy, i, width, height, area, sstride, dstride;
165 GstClockTime timestamp, stream_time;
167 timestamp = GST_BUFFER_TIMESTAMP (in_frame->buffer);
169 gst_segment_to_stream_time (&GST_BASE_TRANSFORM (filter)->segment,
170 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 (GST_OBJECT (filter), stream_time);
178 src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
179 sstride = GST_VIDEO_FRAME_PLANE_STRIDE (in_frame, 0);
180 dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
181 dstride = GST_VIDEO_FRAME_PLANE_STRIDE (out_frame, 0);
183 width = GST_VIDEO_FRAME_WIDTH (in_frame);
184 height = GST_VIDEO_FRAME_HEIGHT (in_frame);
186 area = width * height;
191 gst_vertigotv_set_parms (filter);
192 p = filter->alt_buffer;
194 for (y = 0; y < height; y++) {
198 for (x = 0; x < width; x++) {
199 i = (oy >> 16) * width + (ox >> 16);
205 v = filter->current_buffer[i] & 0xfcfcff;
206 v = (v * 3) + (src[x] & 0xfcfcff);
208 *p++ = dest[x] = (v >> 2);
212 filter->sx -= filter->dy;
213 filter->sy += filter->dx;
219 p = filter->current_buffer;
220 filter->current_buffer = filter->alt_buffer;
221 filter->alt_buffer = p;
227 gst_vertigotv_start (GstBaseTransform * trans)
229 GstVertigoTV *filter = GST_VERTIGOTV (trans);
237 gst_vertigotv_set_property (GObject * object, guint prop_id,
238 const GValue * value, GParamSpec * pspec)
240 GstVertigoTV *filter = GST_VERTIGOTV (object);
242 GST_OBJECT_LOCK (filter);
245 filter->phase_increment = g_value_get_float (value);
247 case PROP_ZOOM_SPEED:
248 filter->zoomrate = g_value_get_float (value);
253 GST_OBJECT_UNLOCK (filter);
257 gst_vertigotv_get_property (GObject * object, guint prop_id, GValue * value,
260 GstVertigoTV *filter = GST_VERTIGOTV (object);
264 g_value_set_float (value, filter->phase_increment);
266 case PROP_ZOOM_SPEED:
267 g_value_set_float (value, filter->zoomrate);
270 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
276 gst_vertigotv_finalize (GObject * object)
278 GstVertigoTV *filter = GST_VERTIGOTV (object);
280 g_free (filter->buffer);
281 filter->buffer = NULL;
283 G_OBJECT_CLASS (parent_class)->finalize (object);
287 gst_vertigotv_class_init (GstVertigoTVClass * klass)
289 GObjectClass *gobject_class = (GObjectClass *) klass;
290 GstElementClass *gstelement_class = (GstElementClass *) klass;
291 GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
292 GstVideoFilterClass *vfilter_class = (GstVideoFilterClass *) klass;
294 gobject_class->set_property = gst_vertigotv_set_property;
295 gobject_class->get_property = gst_vertigotv_get_property;
296 gobject_class->finalize = gst_vertigotv_finalize;
298 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SPEED,
299 g_param_spec_float ("speed", "Speed", "Control the speed of movement",
300 0.01, 100.0, 0.02, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
301 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_ZOOM_SPEED,
302 g_param_spec_float ("zoom-speed", "Zoom Speed",
303 "Control the rate of zooming", 1.01, 1.1, 1.01,
304 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
306 gst_element_class_set_static_metadata (gstelement_class, "VertigoTV effect",
307 "Filter/Effect/Video",
308 "A loopback alpha blending effector with rotating and scaling",
309 "Wim Taymans <wim.taymans@gmail.be>");
311 gst_element_class_add_static_pad_template (gstelement_class,
312 &gst_vertigotv_sink_template);
313 gst_element_class_add_static_pad_template (gstelement_class,
314 &gst_vertigotv_src_template);
316 trans_class->start = GST_DEBUG_FUNCPTR (gst_vertigotv_start);
318 vfilter_class->set_info = GST_DEBUG_FUNCPTR (gst_vertigotv_set_info);
319 vfilter_class->transform_frame =
320 GST_DEBUG_FUNCPTR (gst_vertigotv_transform_frame);
324 gst_vertigotv_init (GstVertigoTV * filter)
326 filter->buffer = NULL;
328 filter->phase_increment = 0.02;
329 filter->zoomrate = 1.01;