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., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, 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
40 * WarpTV does realtime goo'ing of the video input.
42 * ## Example launch line
44 * gst-launch-1.0 -v videotestsrc ! warptv ! videoconvert ! autovideosink
45 * ]| This pipeline shows the effect of warptv on a test stream.
53 #include "gsteffectv.h"
58 #include <gst/video/gstvideometa.h>
59 #include <gst/video/gstvideopool.h>
62 #define M_PI 3.14159265358979323846
65 #define gst_warptv_parent_class parent_class
66 G_DEFINE_TYPE (GstWarpTV, gst_warptv, GST_TYPE_VIDEO_FILTER);
67 GST_ELEMENT_REGISTER_DEFINE (warptv, "warptv", GST_RANK_NONE, GST_TYPE_WARPTV);
69 static void initSinTable ();
70 static void initDistTable (GstWarpTV * filter, gint width, gint height);
72 static GstStaticPadTemplate gst_warptv_src_template =
73 GST_STATIC_PAD_TEMPLATE ("src",
76 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ RGBx, xRGB, BGRx, xBGR }"))
79 static GstStaticPadTemplate gst_warptv_sink_template =
80 GST_STATIC_PAD_TEMPLATE ("sink",
83 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ RGBx, xRGB, BGRx, xBGR }"))
87 gst_warptv_set_info (GstVideoFilter * vfilter, GstCaps * incaps,
88 GstVideoInfo * in_info, GstCaps * outcaps, GstVideoInfo * out_info)
90 GstWarpTV *filter = GST_WARPTV (vfilter);
93 width = GST_VIDEO_INFO_WIDTH (in_info);
94 height = GST_VIDEO_INFO_HEIGHT (in_info);
96 g_free (filter->disttable);
97 filter->disttable = g_malloc (width * height * sizeof (guint32));
98 initDistTable (filter, width, height);
103 static gint32 sintable[1024 + 256];
108 gint32 *tptr, *tsinptr;
111 tsinptr = tptr = sintable;
113 for (i = 0; i < 1024; i++)
114 *tptr++ = (int) (sin (i * M_PI / 512) * 32767);
116 for (i = 0; i < 256; i++)
117 *tptr++ = *tsinptr++;
121 initDistTable (GstWarpTV * filter, gint width, gint height)
123 gint32 halfw, halfh, *distptr;
130 distptr = filter->disttable;
132 m = sqrt ((double) (halfw * halfw + halfh * halfh));
134 for (y = -halfh; y < halfh; y++)
135 for (x = -halfw; x < halfw; x++)
137 *distptr++ = ((int) ((sqrtf (x * x + y * y) * 511.9999) / m)) << 1;
139 *distptr++ = ((int) ((sqrt (x * x + y * y) * 511.9999) / m)) << 1;
144 gst_warptv_transform_frame (GstVideoFilter * filter, GstVideoFrame * in_frame,
145 GstVideoFrame * out_frame)
147 GstWarpTV *warptv = GST_WARPTV (filter);
150 gint32 c, i, x, y, dx, dy, maxx, maxy;
151 gint32 *ctptr, *distptr;
154 gint sstride, dstride;
156 src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
157 dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
159 sstride = GST_VIDEO_FRAME_PLANE_STRIDE (in_frame, 0);
160 dstride = GST_VIDEO_FRAME_PLANE_STRIDE (out_frame, 0);
162 width = GST_VIDEO_FRAME_WIDTH (in_frame);
163 height = GST_VIDEO_FRAME_HEIGHT (in_frame);
165 GST_OBJECT_LOCK (warptv);
166 xw = (gint) (sin ((warptv->tval + 100) * M_PI / 128) * 30);
167 yw = (gint) (sin ((warptv->tval) * M_PI / 256) * -35);
168 cw = (gint) (sin ((warptv->tval - 70) * M_PI / 64) * 50);
169 xw += (gint) (sin ((warptv->tval - 10) * M_PI / 512) * 40);
170 yw += (gint) (sin ((warptv->tval + 30) * M_PI / 512) * 40);
172 ctptr = warptv->ctable;
173 distptr = warptv->disttable;
174 ctable = warptv->ctable;
178 for (x = 0; x < 512; x++) {
179 i = (c >> 3) & 0x3FE;
180 *ctptr++ = ((sintable[i] * yw) >> 15);
181 *ctptr++ = ((sintable[i + 256] * xw) >> 15);
187 for (y = 0; y < height - 1; y++) {
188 for (x = 0; x < width; x++) {
190 dx = ctable[i + 1] + x;
203 dest[x] = src[dy * sstride / 4 + dx];
208 warptv->tval = (warptv->tval + 1) & 511;
209 GST_OBJECT_UNLOCK (warptv);
215 gst_warptv_start (GstBaseTransform * trans)
217 GstWarpTV *warptv = GST_WARPTV (trans);
225 gst_warptv_finalize (GObject * object)
227 GstWarpTV *warptv = GST_WARPTV (object);
229 g_free (warptv->disttable);
230 warptv->disttable = NULL;
232 G_OBJECT_CLASS (parent_class)->finalize (object);
236 gst_warptv_class_init (GstWarpTVClass * klass)
238 GObjectClass *gobject_class = (GObjectClass *) klass;
239 GstElementClass *gstelement_class = (GstElementClass *) klass;
240 GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
241 GstVideoFilterClass *vfilter_class = (GstVideoFilterClass *) klass;
243 gobject_class->finalize = gst_warptv_finalize;
245 gst_element_class_set_static_metadata (gstelement_class, "WarpTV effect",
246 "Filter/Effect/Video",
247 "WarpTV does realtime goo'ing of the video input",
248 "Sam Lantinga <slouken@devolution.com>");
250 gst_element_class_add_static_pad_template (gstelement_class,
251 &gst_warptv_sink_template);
252 gst_element_class_add_static_pad_template (gstelement_class,
253 &gst_warptv_src_template);
255 trans_class->start = GST_DEBUG_FUNCPTR (gst_warptv_start);
257 vfilter_class->set_info = GST_DEBUG_FUNCPTR (gst_warptv_set_info);
258 vfilter_class->transform_frame =
259 GST_DEBUG_FUNCPTR (gst_warptv_transform_frame);
265 gst_warptv_init (GstWarpTV * warptv)