2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) <2003> David Schleef <ds@schleef.org>
5 * EffecTV - Realtime Digital Video Effector
6 * Copyright (C) 2001 FUKUCHI Kentarou
8 * This library is free software; 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 * This file was (probably) generated from gstvideotemplate.c,
26 * gstvideotemplate.c,v 1.11 2004/01/07 08:56:45 ds Exp
29 /* From main.c of warp-1.1:
31 * Simple DirectMedia Layer demo
32 * Realtime picture 'gooing'
33 * by sam lantinga slouken@devolution.com
37 * SECTION:element-warptv
39 * WarpTV does realtime goo'ing of the video input.
42 * <title>Example launch line</title>
44 * gst-launch -v videotestsrc ! warptv ! videoconvert ! autovideosink
45 * ]| This pipeline shows the effect of warptv on a test stream.
57 #include <gst/video/gstvideometa.h>
58 #include <gst/video/gstvideopool.h>
61 #define M_PI 3.14159265358979323846
64 #define gst_warptv_parent_class parent_class
65 G_DEFINE_TYPE (GstWarpTV, gst_warptv, GST_TYPE_VIDEO_FILTER);
67 static void initSinTable ();
68 static void initDistTable (GstWarpTV * filter, gint width, gint height);
70 static GstStaticPadTemplate gst_warptv_src_template =
71 GST_STATIC_PAD_TEMPLATE ("src",
74 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ RGBx, xRGB, BGRx, xBGR }"))
77 static GstStaticPadTemplate gst_warptv_sink_template =
78 GST_STATIC_PAD_TEMPLATE ("sink",
81 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ RGBx, xRGB, BGRx, xBGR }"))
85 gst_warptv_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
88 GstWarpTV *filter = GST_WARPTV (btrans);
92 if (!gst_video_info_from_caps (&info, incaps))
97 width = GST_VIDEO_INFO_WIDTH (&info);
98 height = GST_VIDEO_INFO_HEIGHT (&info);
100 g_free (filter->disttable);
101 filter->disttable = g_malloc (width * height * sizeof (guint32));
102 initDistTable (filter, width, height);
109 GST_DEBUG_OBJECT (filter, "invalid caps received");
114 static gint32 sintable[1024 + 256];
119 gint32 *tptr, *tsinptr;
122 tsinptr = tptr = sintable;
124 for (i = 0; i < 1024; i++)
125 *tptr++ = (int) (sin (i * M_PI / 512) * 32767);
127 for (i = 0; i < 256; i++)
128 *tptr++ = *tsinptr++;
132 initDistTable (GstWarpTV * filter, gint width, gint height)
134 gint32 halfw, halfh, *distptr;
141 distptr = filter->disttable;
143 m = sqrt ((double) (halfw * halfw + halfh * halfh));
145 for (y = -halfh; y < halfh; y++)
146 for (x = -halfw; x < halfw; x++)
148 *distptr++ = ((int) ((sqrtf (x * x + y * y) * 511.9999) / m)) << 1;
150 *distptr++ = ((int) ((sqrt (x * x + y * y) * 511.9999) / m)) << 1;
155 gst_warptv_transform (GstBaseTransform * trans, GstBuffer * in, GstBuffer * out)
157 GstWarpTV *warptv = GST_WARPTV (trans);
160 gint32 c, i, x, y, dx, dy, maxx, maxy;
161 gint32 *ctptr, *distptr;
164 gint sstride, dstride;
165 GstVideoFrame in_frame, out_frame;
167 gst_video_frame_map (&in_frame, &warptv->info, in, GST_MAP_READ);
168 gst_video_frame_map (&out_frame, &warptv->info, out, GST_MAP_WRITE);
170 src = GST_VIDEO_FRAME_PLANE_DATA (&in_frame, 0);
171 dest = GST_VIDEO_FRAME_PLANE_DATA (&out_frame, 0);
173 sstride = GST_VIDEO_FRAME_PLANE_STRIDE (&in_frame, 0) / 4;
174 dstride = GST_VIDEO_FRAME_PLANE_STRIDE (&out_frame, 0) / 4;
176 width = GST_VIDEO_FRAME_WIDTH (&in_frame);
177 height = GST_VIDEO_FRAME_HEIGHT (&in_frame);
179 GST_OBJECT_LOCK (warptv);
180 xw = (gint) (sin ((warptv->tval + 100) * M_PI / 128) * 30);
181 yw = (gint) (sin ((warptv->tval) * M_PI / 256) * -35);
182 cw = (gint) (sin ((warptv->tval - 70) * M_PI / 64) * 50);
183 xw += (gint) (sin ((warptv->tval - 10) * M_PI / 512) * 40);
184 yw += (gint) (sin ((warptv->tval + 30) * M_PI / 512) * 40);
186 ctptr = warptv->ctable;
187 distptr = warptv->disttable;
188 ctable = warptv->ctable;
192 for (x = 0; x < 512; x++) {
193 i = (c >> 3) & 0x3FE;
194 *ctptr++ = ((sintable[i] * yw) >> 15);
195 *ctptr++ = ((sintable[i + 256] * xw) >> 15);
201 for (y = 0; y < height - 1; y++) {
202 for (x = 0; x < width; x++) {
204 dx = ctable[i + 1] + x;
217 dest[x] = src[dy * sstride + dx];
222 warptv->tval = (warptv->tval + 1) & 511;
223 GST_OBJECT_UNLOCK (warptv);
225 gst_video_frame_unmap (&in_frame);
226 gst_video_frame_unmap (&out_frame);
232 gst_warptv_start (GstBaseTransform * trans)
234 GstWarpTV *warptv = GST_WARPTV (trans);
242 gst_wraptv_decide_allocation (GstBaseTransform * trans, GstQuery * query)
244 GstBufferPool *pool = NULL;
245 guint size, min, max, prefix, alignment;
247 gst_query_parse_allocation_params (query, &size, &min, &max, &prefix,
251 GstStructure *config;
253 config = gst_buffer_pool_get_config (pool);
254 gst_buffer_pool_config_add_option (config,
255 GST_BUFFER_POOL_OPTION_VIDEO_META);
256 gst_buffer_pool_set_config (pool, config);
262 gst_warptv_finalize (GObject * object)
264 GstWarpTV *warptv = GST_WARPTV (object);
266 g_free (warptv->disttable);
267 warptv->disttable = NULL;
269 G_OBJECT_CLASS (parent_class)->finalize (object);
273 gst_warptv_class_init (GstWarpTVClass * klass)
275 GObjectClass *gobject_class = (GObjectClass *) klass;
276 GstElementClass *gstelement_class = (GstElementClass *) klass;
277 GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
279 gobject_class->finalize = gst_warptv_finalize;
281 gst_element_class_set_details_simple (gstelement_class, "WarpTV effect",
282 "Filter/Effect/Video",
283 "WarpTV does realtime goo'ing of the video input",
284 "Sam Lantinga <slouken@devolution.com>");
286 gst_element_class_add_pad_template (gstelement_class,
287 gst_static_pad_template_get (&gst_warptv_sink_template));
288 gst_element_class_add_pad_template (gstelement_class,
289 gst_static_pad_template_get (&gst_warptv_src_template));
291 trans_class->start = GST_DEBUG_FUNCPTR (gst_warptv_start);
292 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_warptv_set_caps);
293 trans_class->decide_allocation =
294 GST_DEBUG_FUNCPTR (gst_wraptv_decide_allocation);
295 trans_class->transform = GST_DEBUG_FUNCPTR (gst_warptv_transform);
301 gst_warptv_init (GstWarpTV * warptv)