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
27 * VertigoTV is a loopback alpha blending effector with rotating and scaling.
30 * <title>Example launch line</title>
32 * gst-launch-1.0 -v videotestsrc ! vertigotv ! videoconvert ! autovideosink
33 * ]| This pipeline shows the effect of vertigotv on a test stream.
44 #include "gstvertigo.h"
46 #define gst_vertigotv_parent_class parent_class
47 G_DEFINE_TYPE (GstVertigoTV, gst_vertigotv, GST_TYPE_VIDEO_FILTER);
49 /* Filter signals and args */
57 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
58 #define CAPS_STR GST_VIDEO_CAPS_MAKE ("{ RGBx, BGRx }")
60 #define CAPS_STR GST_VIDEO_CAPS_MAKE ("{ xRGB, xBGR }")
63 static GstStaticPadTemplate gst_vertigotv_src_template =
64 GST_STATIC_PAD_TEMPLATE ("src",
67 GST_STATIC_CAPS (CAPS_STR)
70 static GstStaticPadTemplate gst_vertigotv_sink_template =
71 GST_STATIC_PAD_TEMPLATE ("sink",
74 GST_STATIC_CAPS (CAPS_STR)
78 gst_vertigotv_set_info (GstVideoFilter * vfilter, GstCaps * incaps,
79 GstVideoInfo * in_info, GstCaps * outcaps, GstVideoInfo * out_info)
81 GstVertigoTV *filter = GST_VERTIGOTV (vfilter);
82 gint area, width, height;
84 width = GST_VIDEO_INFO_WIDTH (in_info);
85 height = GST_VIDEO_INFO_HEIGHT (in_info);
87 area = width * height;
89 g_free (filter->buffer);
90 filter->buffer = (guint32 *) g_malloc0 (area * 2 * sizeof (guint32));
92 filter->current_buffer = filter->buffer;
93 filter->alt_buffer = filter->buffer + area;
100 gst_vertigotv_set_parms (GstVertigoTV * filter)
109 dizz = sin (filter->phase) * 10 + sin (filter->phase * 1.9 + 5) * 5;
111 info = &GST_VIDEO_FILTER (filter)->in_info;
113 width = GST_VIDEO_INFO_WIDTH (info);
114 height = GST_VIDEO_INFO_HEIGHT (info);
119 t = (x * x + y * y) * filter->zoomrate;
121 if (width > height) {
125 vx = (x * (x - dizz) + y * y) / t;
129 vx = (x * (x + dizz) + y * y) / t;
136 vx = (x * x + y * (y - dizz)) / t;
140 vx = (x * x + y * (y + dizz)) / t;
144 filter->dx = vx * 65536;
145 filter->dy = vy * 65536;
146 filter->sx = (-vx * x + vy * y + x + cos (filter->phase * 5) * 2) * 65536;
147 filter->sy = (-vx * y - vy * x + y + sin (filter->phase * 6) * 2) * 65536;
149 filter->phase += filter->phase_increment;
150 if (filter->phase > 5700000)
155 gst_vertigotv_transform_frame (GstVideoFilter * vfilter,
156 GstVideoFrame * in_frame, GstVideoFrame * out_frame)
158 GstVertigoTV *filter = GST_VERTIGOTV (vfilter);
159 guint32 *src, *dest, *p;
161 gint x, y, ox, oy, i, width, height, area, sstride, dstride;
162 GstClockTime timestamp, stream_time;
164 timestamp = GST_BUFFER_TIMESTAMP (in_frame->buffer);
166 gst_segment_to_stream_time (&GST_BASE_TRANSFORM (filter)->segment,
167 GST_FORMAT_TIME, timestamp);
169 GST_DEBUG_OBJECT (filter, "sync to %" GST_TIME_FORMAT,
170 GST_TIME_ARGS (timestamp));
172 if (GST_CLOCK_TIME_IS_VALID (stream_time))
173 gst_object_sync_values (GST_OBJECT (filter), stream_time);
175 src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
176 sstride = GST_VIDEO_FRAME_PLANE_STRIDE (in_frame, 0);
177 dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
178 dstride = GST_VIDEO_FRAME_PLANE_STRIDE (out_frame, 0);
180 width = GST_VIDEO_FRAME_WIDTH (in_frame);
181 height = GST_VIDEO_FRAME_HEIGHT (in_frame);
183 area = width * height;
188 gst_vertigotv_set_parms (filter);
189 p = filter->alt_buffer;
191 for (y = 0; y < height; y++) {
195 for (x = 0; x < width; x++) {
196 i = (oy >> 16) * width + (ox >> 16);
202 v = filter->current_buffer[i] & 0xfcfcff;
203 v = (v * 3) + (src[x] & 0xfcfcff);
205 *p++ = dest[x] = (v >> 2);
209 filter->sx -= filter->dy;
210 filter->sy += filter->dx;
216 p = filter->current_buffer;
217 filter->current_buffer = filter->alt_buffer;
218 filter->alt_buffer = p;
224 gst_vertigotv_start (GstBaseTransform * trans)
226 GstVertigoTV *filter = GST_VERTIGOTV (trans);
234 gst_vertigotv_set_property (GObject * object, guint prop_id,
235 const GValue * value, GParamSpec * pspec)
237 GstVertigoTV *filter = GST_VERTIGOTV (object);
239 GST_OBJECT_LOCK (filter);
242 filter->phase_increment = g_value_get_float (value);
244 case PROP_ZOOM_SPEED:
245 filter->zoomrate = g_value_get_float (value);
250 GST_OBJECT_UNLOCK (filter);
254 gst_vertigotv_get_property (GObject * object, guint prop_id, GValue * value,
257 GstVertigoTV *filter = GST_VERTIGOTV (object);
261 g_value_set_float (value, filter->phase_increment);
263 case PROP_ZOOM_SPEED:
264 g_value_set_float (value, filter->zoomrate);
267 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
273 gst_vertigotv_finalize (GObject * object)
275 GstVertigoTV *filter = GST_VERTIGOTV (object);
277 g_free (filter->buffer);
278 filter->buffer = NULL;
280 G_OBJECT_CLASS (parent_class)->finalize (object);
284 gst_vertigotv_class_init (GstVertigoTVClass * klass)
286 GObjectClass *gobject_class = (GObjectClass *) klass;
287 GstElementClass *gstelement_class = (GstElementClass *) klass;
288 GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
289 GstVideoFilterClass *vfilter_class = (GstVideoFilterClass *) klass;
291 gobject_class->set_property = gst_vertigotv_set_property;
292 gobject_class->get_property = gst_vertigotv_get_property;
293 gobject_class->finalize = gst_vertigotv_finalize;
295 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SPEED,
296 g_param_spec_float ("speed", "Speed", "Control the speed of movement",
297 0.01, 100.0, 0.02, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
298 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_ZOOM_SPEED,
299 g_param_spec_float ("zoom-speed", "Zoom Speed",
300 "Control the rate of zooming", 1.01, 1.1, 1.01,
301 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
303 gst_element_class_set_static_metadata (gstelement_class, "VertigoTV effect",
304 "Filter/Effect/Video",
305 "A loopback alpha blending effector with rotating and scaling",
306 "Wim Taymans <wim.taymans@gmail.be>");
308 gst_element_class_add_static_pad_template (gstelement_class,
309 &gst_vertigotv_sink_template);
310 gst_element_class_add_static_pad_template (gstelement_class,
311 &gst_vertigotv_src_template);
313 trans_class->start = GST_DEBUG_FUNCPTR (gst_vertigotv_start);
315 vfilter_class->set_info = GST_DEBUG_FUNCPTR (gst_vertigotv_set_info);
316 vfilter_class->transform_frame =
317 GST_DEBUG_FUNCPTR (gst_vertigotv_transform_frame);
321 gst_vertigotv_init (GstVertigoTV * filter)
323 filter->buffer = NULL;
325 filter->phase_increment = 0.02;
326 filter->zoomrate = 1.01;