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
40 #include <gst/video/gstvideofilter.h>
45 #include <gst/video/video.h>
48 #define M_PI 3.14159265358979323846
51 #define GST_TYPE_WARPTV \
52 (gst_warptv_get_type())
53 #define GST_WARPTV(obj) \
54 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_WARPTV,GstWarpTV))
55 #define GST_WARPTV_CLASS(klass) \
56 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_WARPTV,GstWarpTVClass))
57 #define GST_IS_WARPTV(obj) \
58 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_WARPTV))
59 #define GST_IS_WARPTV_CLASS(obj) \
60 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_WARPTV))
62 typedef struct _GstWarpTV GstWarpTV;
63 typedef struct _GstWarpTVClass GstWarpTVClass;
67 GstVideoFilter videofilter;
73 gint32 sintable[1024 + 256];
77 struct _GstWarpTVClass
79 GstVideoFilterClass parent_class;
82 GType gst_warptv_get_type (void);
84 static void initSinTable (GstWarpTV * filter);
85 static void initOffsTable (GstWarpTV * filter);
86 static void initDistTable (GstWarpTV * filter);
88 static GstElementDetails warptv_details = GST_ELEMENT_DETAILS ("WarpTV",
89 "Filter/Effect/Video",
90 "WarpTV does realtime goo'ing of the video input",
91 "Sam Lantinga <slouken@devolution.com>");
93 static GstStaticPadTemplate gst_warptv_src_template =
94 GST_STATIC_PAD_TEMPLATE ("src",
97 GST_STATIC_CAPS (GST_VIDEO_CAPS_RGBx ";" GST_VIDEO_CAPS_xRGB ";"
98 GST_VIDEO_CAPS_BGRx ";" GST_VIDEO_CAPS_xBGR)
101 static GstStaticPadTemplate gst_warptv_sink_template =
102 GST_STATIC_PAD_TEMPLATE ("sink",
105 GST_STATIC_CAPS (GST_VIDEO_CAPS_RGBx ";" GST_VIDEO_CAPS_xRGB ";"
106 GST_VIDEO_CAPS_BGRx ";" GST_VIDEO_CAPS_xBGR)
109 static GstVideoFilterClass *parent_class = NULL;
112 gst_warptv_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
115 GstWarpTV *filter = GST_WARPTV (btrans);
116 GstStructure *structure;
117 gboolean ret = FALSE;
119 structure = gst_caps_get_structure (incaps, 0);
121 if (gst_structure_get_int (structure, "width", &filter->width) &&
122 gst_structure_get_int (structure, "height", &filter->height)) {
123 g_free (filter->disttable);
124 g_free (filter->offstable);
126 filter->offstable = g_malloc (filter->height * sizeof (guint32));
128 g_malloc (filter->width * filter->height * sizeof (guint32));
130 initSinTable (filter);
131 initOffsTable (filter);
132 initDistTable (filter);
140 gst_warptv_get_unit_size (GstBaseTransform * btrans, GstCaps * caps,
144 GstStructure *structure;
145 gboolean ret = FALSE;
148 filter = GST_WARPTV (btrans);
150 structure = gst_caps_get_structure (caps, 0);
152 if (gst_structure_get_int (structure, "width", &width) &&
153 gst_structure_get_int (structure, "height", &height)) {
154 *size = width * height * 32 / 8;
156 GST_DEBUG_OBJECT (filter, "our frame size is %d bytes (%dx%d)", *size,
164 initSinTable (GstWarpTV * filter)
166 gint32 *tptr, *tsinptr;
169 tsinptr = tptr = filter->sintable;
171 for (i = 0; i < 1024; i++)
172 *tptr++ = (int) (sin (i * M_PI / 512) * 32767);
174 for (i = 0; i < 256; i++)
175 *tptr++ = *tsinptr++;
179 initOffsTable (GstWarpTV * filter)
183 for (y = 0; y < filter->height; y++) {
184 filter->offstable[y] = y * filter->width;
189 initDistTable (GstWarpTV * filter)
191 gint32 halfw, halfh, *distptr;
199 halfw = filter->width >> 1;
200 halfh = filter->height >> 1;
202 distptr = filter->disttable;
204 m = sqrt ((double) (halfw * halfw + halfh * halfh));
206 for (y = -halfh; y < halfh; y++)
207 for (x = -halfw; x < halfw; x++)
209 *distptr++ = ((int) ((sqrtf (x * x + y * y) * 511.9999) / m)) << 1;
211 *distptr++ = ((int) ((sqrt (x * x + y * y) * 511.9999) / m)) << 1;
216 gst_warptv_transform (GstBaseTransform * trans, GstBuffer * in, GstBuffer * out)
218 GstWarpTV *warptv = GST_WARPTV (trans);
219 int width = warptv->width;
220 int height = warptv->height;
221 guint32 *src = (guint32 *) GST_BUFFER_DATA (in);
222 guint32 *dest = (guint32 *) GST_BUFFER_DATA (out);
224 gint32 c, i, x, y, dx, dy, maxx, maxy;
225 gint32 skip, *ctptr, *distptr;
226 gint32 *sintable, *ctable;
227 GstFlowReturn ret = GST_FLOW_OK;
229 gst_buffer_stamp (out, in);
231 xw = (gint) (sin ((warptv->tval + 100) * M_PI / 128) * 30);
232 yw = (gint) (sin ((warptv->tval) * M_PI / 256) * -35);
233 cw = (gint) (sin ((warptv->tval - 70) * M_PI / 64) * 50);
234 xw += (gint) (sin ((warptv->tval - 10) * M_PI / 512) * 40);
235 yw += (gint) (sin ((warptv->tval + 30) * M_PI / 512) * 40);
237 ctptr = warptv->ctable;
238 distptr = warptv->disttable;
239 sintable = warptv->sintable;
240 ctable = warptv->ctable;
242 skip = 0; /* video_width*sizeof(RGB32)/4 - video_width;; */
245 for (x = 0; x < 512; x++) {
246 i = (c >> 3) & 0x3FE;
247 *ctptr++ = ((sintable[i] * yw) >> 15);
248 *ctptr++ = ((sintable[i + 256] * xw) >> 15);
254 for (y = 0; y < height - 1; y++) {
255 for (x = 0; x < width; x++) {
257 dx = ctable[i + 1] + x;
269 *dest++ = src[warptv->offstable[dy] + dx];
274 warptv->tval = (warptv->tval + 1) & 511;
280 gst_warptv_base_init (gpointer g_class)
282 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
284 gst_element_class_set_details (element_class, &warptv_details);
286 gst_element_class_add_pad_template (element_class,
287 gst_static_pad_template_get (&gst_warptv_sink_template));
288 gst_element_class_add_pad_template (element_class,
289 gst_static_pad_template_get (&gst_warptv_src_template));
293 gst_warptv_class_init (gpointer klass, gpointer class_data)
295 GObjectClass *gobject_class;
296 GstElementClass *element_class;
297 GstBaseTransformClass *trans_class;
299 gobject_class = (GObjectClass *) klass;
300 element_class = (GstElementClass *) klass;
301 trans_class = (GstBaseTransformClass *) klass;
303 parent_class = g_type_class_peek_parent (klass);
305 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_warptv_set_caps);
306 trans_class->get_unit_size = GST_DEBUG_FUNCPTR (gst_warptv_get_unit_size);
307 trans_class->transform = GST_DEBUG_FUNCPTR (gst_warptv_transform);
311 gst_warptv_init (GTypeInstance * instance, gpointer g_class)
316 gst_warptv_get_type (void)
318 static GType warptv_type = 0;
321 static const GTypeInfo warptv_info = {
322 sizeof (GstWarpTVClass),
323 gst_warptv_base_init,
325 gst_warptv_class_init,
333 warptv_type = g_type_register_static (GST_TYPE_VIDEO_FILTER,
334 "GstWarpTV", &warptv_info, 0);