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 ! ffmpegcolorspace ! autovideosink
45 * ]| This pipeline shows the effect of warptv on a test stream.
58 #include <gst/video/video.h>
61 #define M_PI 3.14159265358979323846
64 GST_BOILERPLATE (GstWarpTV, gst_warptv, GstVideoFilter, GST_TYPE_VIDEO_FILTER);
66 static void initSinTable ();
67 static void initOffsTable (GstWarpTV * filter);
68 static void initDistTable (GstWarpTV * filter);
70 static GstStaticPadTemplate gst_warptv_src_template =
71 GST_STATIC_PAD_TEMPLATE ("src",
74 GST_STATIC_CAPS (GST_VIDEO_CAPS_RGBx ";" GST_VIDEO_CAPS_xRGB ";"
75 GST_VIDEO_CAPS_BGRx ";" GST_VIDEO_CAPS_xBGR)
78 static GstStaticPadTemplate gst_warptv_sink_template =
79 GST_STATIC_PAD_TEMPLATE ("sink",
82 GST_STATIC_CAPS (GST_VIDEO_CAPS_RGBx ";" GST_VIDEO_CAPS_xRGB ";"
83 GST_VIDEO_CAPS_BGRx ";" GST_VIDEO_CAPS_xBGR)
87 gst_warptv_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
90 GstWarpTV *filter = GST_WARPTV (btrans);
91 GstStructure *structure;
94 structure = gst_caps_get_structure (incaps, 0);
96 if (gst_structure_get_int (structure, "width", &filter->width) &&
97 gst_structure_get_int (structure, "height", &filter->height)) {
98 g_free (filter->disttable);
99 g_free (filter->offstable);
101 filter->offstable = g_malloc (filter->height * sizeof (guint32));
103 g_malloc (filter->width * filter->height * sizeof (guint32));
105 initOffsTable (filter);
106 initDistTable (filter);
113 static gint32 sintable[1024 + 256];
118 gint32 *tptr, *tsinptr;
121 tsinptr = tptr = sintable;
123 for (i = 0; i < 1024; i++)
124 *tptr++ = (int) (sin (i * M_PI / 512) * 32767);
126 for (i = 0; i < 256; i++)
127 *tptr++ = *tsinptr++;
131 initOffsTable (GstWarpTV * filter)
135 for (y = 0; y < filter->height; y++) {
136 filter->offstable[y] = y * filter->width;
141 initDistTable (GstWarpTV * filter)
143 gint32 halfw, halfh, *distptr;
151 halfw = filter->width >> 1;
152 halfh = filter->height >> 1;
154 distptr = filter->disttable;
156 m = sqrt ((double) (halfw * halfw + halfh * halfh));
158 for (y = -halfh; y < halfh; y++)
159 for (x = -halfw; x < halfw; x++)
161 *distptr++ = ((int) ((sqrtf (x * x + y * y) * 511.9999) / m)) << 1;
163 *distptr++ = ((int) ((sqrt (x * x + y * y) * 511.9999) / m)) << 1;
168 gst_warptv_transform (GstBaseTransform * trans, GstBuffer * in, GstBuffer * out)
170 GstWarpTV *warptv = GST_WARPTV (trans);
171 int width = warptv->width;
172 int height = warptv->height;
173 guint32 *src = (guint32 *) GST_BUFFER_DATA (in);
174 guint32 *dest = (guint32 *) GST_BUFFER_DATA (out);
176 gint32 c, i, x, y, dx, dy, maxx, maxy;
177 gint32 skip, *ctptr, *distptr;
179 GstFlowReturn ret = GST_FLOW_OK;
181 xw = (gint) (sin ((warptv->tval + 100) * M_PI / 128) * 30);
182 yw = (gint) (sin ((warptv->tval) * M_PI / 256) * -35);
183 cw = (gint) (sin ((warptv->tval - 70) * M_PI / 64) * 50);
184 xw += (gint) (sin ((warptv->tval - 10) * M_PI / 512) * 40);
185 yw += (gint) (sin ((warptv->tval + 30) * M_PI / 512) * 40);
187 ctptr = warptv->ctable;
188 distptr = warptv->disttable;
189 ctable = warptv->ctable;
191 skip = 0; /* video_width*sizeof(RGB32)/4 - video_width;; */
194 for (x = 0; x < 512; x++) {
195 i = (c >> 3) & 0x3FE;
196 *ctptr++ = ((sintable[i] * yw) >> 15);
197 *ctptr++ = ((sintable[i + 256] * xw) >> 15);
203 for (y = 0; y < height - 1; y++) {
204 for (x = 0; x < width; x++) {
206 dx = ctable[i + 1] + x;
218 *dest++ = src[warptv->offstable[dy] + dx];
223 warptv->tval = (warptv->tval + 1) & 511;
229 gst_warptv_start (GstBaseTransform * trans)
231 GstWarpTV *warptv = GST_WARPTV (trans);
239 gst_warptv_finalize (GObject * object)
241 GstWarpTV *warptv = GST_WARPTV (object);
243 g_free (warptv->offstable);
244 warptv->offstable = NULL;
245 g_free (warptv->disttable);
246 warptv->disttable = NULL;
248 G_OBJECT_CLASS (parent_class)->finalize (object);
252 gst_warptv_base_init (gpointer g_class)
254 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
256 gst_element_class_set_details_simple (element_class, "WarpTV effect",
257 "Filter/Effect/Video",
258 "WarpTV does realtime goo'ing of the video input",
259 "Sam Lantinga <slouken@devolution.com>");
261 gst_element_class_add_pad_template (element_class,
262 gst_static_pad_template_get (&gst_warptv_sink_template));
263 gst_element_class_add_pad_template (element_class,
264 gst_static_pad_template_get (&gst_warptv_src_template));
268 gst_warptv_class_init (GstWarpTVClass * klass)
270 GObjectClass *gobject_class = (GObjectClass *) klass;
271 GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
273 gobject_class->finalize = gst_warptv_finalize;
275 trans_class->start = GST_DEBUG_FUNCPTR (gst_warptv_start);
276 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_warptv_set_caps);
277 trans_class->transform = GST_DEBUG_FUNCPTR (gst_warptv_transform);
283 gst_warptv_init (GstWarpTV * warptv, GstWarpTVClass * klass)
285 gst_pad_use_fixed_caps (GST_BASE_TRANSFORM_SRC_PAD (warptv));
286 gst_pad_use_fixed_caps (GST_BASE_TRANSFORM_SINK_PAD (warptv));