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-1.0 -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_info (GstVideoFilter * vfilter, GstCaps * incaps,
86 GstVideoInfo * in_info, GstCaps * outcaps, GstVideoInfo * out_info)
88 GstWarpTV *filter = GST_WARPTV (vfilter);
91 width = GST_VIDEO_INFO_WIDTH (in_info);
92 height = GST_VIDEO_INFO_HEIGHT (in_info);
94 g_free (filter->disttable);
95 filter->disttable = g_malloc (width * height * sizeof (guint32));
96 initDistTable (filter, width, height);
101 static gint32 sintable[1024 + 256];
106 gint32 *tptr, *tsinptr;
109 tsinptr = tptr = sintable;
111 for (i = 0; i < 1024; i++)
112 *tptr++ = (int) (sin (i * M_PI / 512) * 32767);
114 for (i = 0; i < 256; i++)
115 *tptr++ = *tsinptr++;
119 initDistTable (GstWarpTV * filter, gint width, gint height)
121 gint32 halfw, halfh, *distptr;
128 distptr = filter->disttable;
130 m = sqrt ((double) (halfw * halfw + halfh * halfh));
132 for (y = -halfh; y < halfh; y++)
133 for (x = -halfw; x < halfw; x++)
135 *distptr++ = ((int) ((sqrtf (x * x + y * y) * 511.9999) / m)) << 1;
137 *distptr++ = ((int) ((sqrt (x * x + y * y) * 511.9999) / m)) << 1;
142 gst_warptv_transform_frame (GstVideoFilter * filter, GstVideoFrame * in_frame,
143 GstVideoFrame * out_frame)
145 GstWarpTV *warptv = GST_WARPTV (filter);
148 gint32 c, i, x, y, dx, dy, maxx, maxy;
149 gint32 *ctptr, *distptr;
152 gint sstride, dstride;
154 src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
155 dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
157 sstride = GST_VIDEO_FRAME_PLANE_STRIDE (in_frame, 0);
158 dstride = GST_VIDEO_FRAME_PLANE_STRIDE (out_frame, 0);
160 width = GST_VIDEO_FRAME_WIDTH (in_frame);
161 height = GST_VIDEO_FRAME_HEIGHT (in_frame);
163 GST_OBJECT_LOCK (warptv);
164 xw = (gint) (sin ((warptv->tval + 100) * M_PI / 128) * 30);
165 yw = (gint) (sin ((warptv->tval) * M_PI / 256) * -35);
166 cw = (gint) (sin ((warptv->tval - 70) * M_PI / 64) * 50);
167 xw += (gint) (sin ((warptv->tval - 10) * M_PI / 512) * 40);
168 yw += (gint) (sin ((warptv->tval + 30) * M_PI / 512) * 40);
170 ctptr = warptv->ctable;
171 distptr = warptv->disttable;
172 ctable = warptv->ctable;
176 for (x = 0; x < 512; x++) {
177 i = (c >> 3) & 0x3FE;
178 *ctptr++ = ((sintable[i] * yw) >> 15);
179 *ctptr++ = ((sintable[i + 256] * xw) >> 15);
185 for (y = 0; y < height - 1; y++) {
186 for (x = 0; x < width; x++) {
188 dx = ctable[i + 1] + x;
201 dest[x] = src[dy * sstride / 4 + dx];
206 warptv->tval = (warptv->tval + 1) & 511;
207 GST_OBJECT_UNLOCK (warptv);
213 gst_warptv_start (GstBaseTransform * trans)
215 GstWarpTV *warptv = GST_WARPTV (trans);
223 gst_warptv_finalize (GObject * object)
225 GstWarpTV *warptv = GST_WARPTV (object);
227 g_free (warptv->disttable);
228 warptv->disttable = NULL;
230 G_OBJECT_CLASS (parent_class)->finalize (object);
234 gst_warptv_class_init (GstWarpTVClass * klass)
236 GObjectClass *gobject_class = (GObjectClass *) klass;
237 GstElementClass *gstelement_class = (GstElementClass *) klass;
238 GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
239 GstVideoFilterClass *vfilter_class = (GstVideoFilterClass *) klass;
241 gobject_class->finalize = gst_warptv_finalize;
243 gst_element_class_set_static_metadata (gstelement_class, "WarpTV effect",
244 "Filter/Effect/Video",
245 "WarpTV does realtime goo'ing of the video input",
246 "Sam Lantinga <slouken@devolution.com>");
248 gst_element_class_add_pad_template (gstelement_class,
249 gst_static_pad_template_get (&gst_warptv_sink_template));
250 gst_element_class_add_pad_template (gstelement_class,
251 gst_static_pad_template_get (&gst_warptv_src_template));
253 trans_class->start = GST_DEBUG_FUNCPTR (gst_warptv_start);
255 vfilter_class->set_info = GST_DEBUG_FUNCPTR (gst_warptv_set_info);
256 vfilter_class->transform_frame =
257 GST_DEBUG_FUNCPTR (gst_warptv_transform_frame);
263 gst_warptv_init (GstWarpTV * warptv)