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
45 #include <gst/video/video.h>
48 #define M_PI 3.14159265358979323846
51 GST_BOILERPLATE (GstWarpTV, gst_warptv, GstVideoFilter, GST_TYPE_VIDEO_FILTER);
53 static void initSinTable (GstWarpTV * filter);
54 static void initOffsTable (GstWarpTV * filter);
55 static void initDistTable (GstWarpTV * filter);
57 static GstStaticPadTemplate gst_warptv_src_template =
58 GST_STATIC_PAD_TEMPLATE ("src",
61 GST_STATIC_CAPS (GST_VIDEO_CAPS_RGBx ";" GST_VIDEO_CAPS_xRGB ";"
62 GST_VIDEO_CAPS_BGRx ";" GST_VIDEO_CAPS_xBGR)
65 static GstStaticPadTemplate gst_warptv_sink_template =
66 GST_STATIC_PAD_TEMPLATE ("sink",
69 GST_STATIC_CAPS (GST_VIDEO_CAPS_RGBx ";" GST_VIDEO_CAPS_xRGB ";"
70 GST_VIDEO_CAPS_BGRx ";" GST_VIDEO_CAPS_xBGR)
74 gst_warptv_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
77 GstWarpTV *filter = GST_WARPTV (btrans);
78 GstStructure *structure;
81 structure = gst_caps_get_structure (incaps, 0);
83 if (gst_structure_get_int (structure, "width", &filter->width) &&
84 gst_structure_get_int (structure, "height", &filter->height)) {
85 g_free (filter->disttable);
86 g_free (filter->offstable);
88 filter->offstable = g_malloc (filter->height * sizeof (guint32));
90 g_malloc (filter->width * filter->height * sizeof (guint32));
92 initSinTable (filter);
93 initOffsTable (filter);
94 initDistTable (filter);
102 initSinTable (GstWarpTV * filter)
104 gint32 *tptr, *tsinptr;
107 tsinptr = tptr = filter->sintable;
109 for (i = 0; i < 1024; i++)
110 *tptr++ = (int) (sin (i * M_PI / 512) * 32767);
112 for (i = 0; i < 256; i++)
113 *tptr++ = *tsinptr++;
117 initOffsTable (GstWarpTV * filter)
121 for (y = 0; y < filter->height; y++) {
122 filter->offstable[y] = y * filter->width;
127 initDistTable (GstWarpTV * filter)
129 gint32 halfw, halfh, *distptr;
137 halfw = filter->width >> 1;
138 halfh = filter->height >> 1;
140 distptr = filter->disttable;
142 m = sqrt ((double) (halfw * halfw + halfh * halfh));
144 for (y = -halfh; y < halfh; y++)
145 for (x = -halfw; x < halfw; x++)
147 *distptr++ = ((int) ((sqrtf (x * x + y * y) * 511.9999) / m)) << 1;
149 *distptr++ = ((int) ((sqrt (x * x + y * y) * 511.9999) / m)) << 1;
154 gst_warptv_transform (GstBaseTransform * trans, GstBuffer * in, GstBuffer * out)
156 GstWarpTV *warptv = GST_WARPTV (trans);
157 int width = warptv->width;
158 int height = warptv->height;
159 guint32 *src = (guint32 *) GST_BUFFER_DATA (in);
160 guint32 *dest = (guint32 *) GST_BUFFER_DATA (out);
162 gint32 c, i, x, y, dx, dy, maxx, maxy;
163 gint32 skip, *ctptr, *distptr;
164 gint32 *sintable, *ctable;
165 GstFlowReturn ret = GST_FLOW_OK;
167 xw = (gint) (sin ((warptv->tval + 100) * M_PI / 128) * 30);
168 yw = (gint) (sin ((warptv->tval) * M_PI / 256) * -35);
169 cw = (gint) (sin ((warptv->tval - 70) * M_PI / 64) * 50);
170 xw += (gint) (sin ((warptv->tval - 10) * M_PI / 512) * 40);
171 yw += (gint) (sin ((warptv->tval + 30) * M_PI / 512) * 40);
173 ctptr = warptv->ctable;
174 distptr = warptv->disttable;
175 sintable = warptv->sintable;
176 ctable = warptv->ctable;
178 skip = 0; /* video_width*sizeof(RGB32)/4 - video_width;; */
181 for (x = 0; x < 512; x++) {
182 i = (c >> 3) & 0x3FE;
183 *ctptr++ = ((sintable[i] * yw) >> 15);
184 *ctptr++ = ((sintable[i + 256] * xw) >> 15);
190 for (y = 0; y < height - 1; y++) {
191 for (x = 0; x < width; x++) {
193 dx = ctable[i + 1] + x;
205 *dest++ = src[warptv->offstable[dy] + dx];
210 warptv->tval = (warptv->tval + 1) & 511;
216 gst_warptv_start (GstBaseTransform * trans)
218 GstWarpTV *warptv = GST_WARPTV (trans);
226 gst_warptv_finalize (GObject * object)
228 GstWarpTV *warptv = GST_WARPTV (object);
230 g_free (warptv->offstable);
231 warptv->offstable = NULL;
232 g_free (warptv->disttable);
233 warptv->disttable = NULL;
237 gst_warptv_base_init (gpointer g_class)
239 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
241 gst_element_class_set_details_simple (element_class, "WarpTV effect",
242 "Filter/Effect/Video",
243 "WarpTV does realtime goo'ing of the video input",
244 "Sam Lantinga <slouken@devolution.com>");
246 gst_element_class_add_pad_template (element_class,
247 gst_static_pad_template_get (&gst_warptv_sink_template));
248 gst_element_class_add_pad_template (element_class,
249 gst_static_pad_template_get (&gst_warptv_src_template));
253 gst_warptv_class_init (GstWarpTVClass * klass)
255 GObjectClass *gobject_class = (GObjectClass *) klass;
256 GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
258 gobject_class->finalize = gst_warptv_finalize;
260 trans_class->start = GST_DEBUG_FUNCPTR (gst_warptv_start);
261 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_warptv_set_caps);
262 trans_class->transform = GST_DEBUG_FUNCPTR (gst_warptv_transform);
266 gst_warptv_init (GstWarpTV * warptv, GstWarpTVClass * klass)