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
41 #include <gstvideofilter.h>
44 #include "gsteffectv.h"
47 #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;
83 /* GstWarpTV signals and args */
96 static void gst_warptv_base_init (gpointer g_class);
97 static void gst_warptv_class_init (gpointer g_class, gpointer class_data);
98 static void gst_warptv_init (GTypeInstance * instance, gpointer g_class);
100 static void gst_warptv_set_property (GObject * object, guint prop_id,
101 const GValue * value, GParamSpec * pspec);
102 static void gst_warptv_get_property (GObject * object, guint prop_id,
103 GValue * value, GParamSpec * pspec);
105 static void gst_warptv_setup (GstVideofilter * videofilter);
106 static void initSinTable (GstWarpTV * filter);
107 static void initOffsTable (GstWarpTV * filter);
108 static void initDistTable (GstWarpTV * filter);
109 static void gst_warptv_rgb32 (GstVideofilter * videofilter, void *d, void *s);
112 gst_warptv_get_type (void)
114 static GType warptv_type = 0;
117 static const GTypeInfo warptv_info = {
118 sizeof (GstWarpTVClass),
119 gst_warptv_base_init,
121 gst_warptv_class_init,
128 warptv_type = g_type_register_static (GST_TYPE_VIDEOFILTER,
129 "GstWarpTV", &warptv_info, 0);
134 static GstVideofilterFormat gst_warptv_formats[] = {
135 {"RGB ", 32, gst_warptv_rgb32, 24, G_BIG_ENDIAN, 0x00ff0000, 0x0000ff00,
137 {"RGB ", 32, gst_warptv_rgb32, 24, G_BIG_ENDIAN, 0xff000000, 0x00ff0000,
139 {"RGB ", 32, gst_warptv_rgb32, 24, G_BIG_ENDIAN, 0x000000ff, 0x0000ff00,
141 {"RGB ", 32, gst_warptv_rgb32, 24, G_BIG_ENDIAN, 0x0000ff00, 0x00ff0000,
146 gst_warptv_base_init (gpointer g_class)
148 static GstElementDetails warptv_details = GST_ELEMENT_DETAILS ("WarpTV",
149 "Filter/Effect/Video",
150 "WarpTV does realtime goo'ing of the video input",
151 "Sam Lantinga <slouken@devolution.com>");
152 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
153 GstVideofilterClass *videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
156 gst_element_class_set_details (element_class, &warptv_details);
158 for (i = 0; i < G_N_ELEMENTS (gst_warptv_formats); i++) {
159 gst_videofilter_class_add_format (videofilter_class,
160 gst_warptv_formats + i);
163 gst_videofilter_class_add_pad_templates (GST_VIDEOFILTER_CLASS (g_class));
167 gst_warptv_class_init (gpointer g_class, gpointer class_data)
169 GObjectClass *gobject_class;
170 GstVideofilterClass *videofilter_class;
172 gobject_class = G_OBJECT_CLASS (g_class);
173 videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
176 g_object_class_install_property (gobject_class, ARG_METHOD,
177 g_param_spec_enum ("method", "method", "method",
178 GST_TYPE_WARPTV_METHOD, GST_WARPTV_METHOD_1, G_PARAM_READWRITE));
181 gobject_class->set_property = gst_warptv_set_property;
182 gobject_class->get_property = gst_warptv_get_property;
184 videofilter_class->setup = gst_warptv_setup;
188 gst_warptv_init (GTypeInstance * instance, gpointer g_class)
190 GstWarpTV *warptv = GST_WARPTV (instance);
191 GstVideofilter *videofilter;
193 GST_DEBUG ("gst_warptv_init");
195 videofilter = GST_VIDEOFILTER (warptv);
201 gst_warptv_set_property (GObject * object, guint prop_id, const GValue * value,
206 /* it's not null if we got it, but it might not be ours */
207 g_return_if_fail (GST_IS_WARPTV (object));
208 src = GST_WARPTV (object);
210 GST_DEBUG ("gst_warptv_set_property");
214 src->method = g_value_get_enum (value);
223 gst_warptv_get_property (GObject * object, guint prop_id, GValue * value,
228 /* it's not null if we got it, but it might not be ours */
229 g_return_if_fail (GST_IS_WARPTV (object));
230 src = GST_WARPTV (object);
235 g_value_set_enum (value, src->method);
239 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
246 gst_warptv_setup (GstVideofilter * videofilter)
249 int width = gst_videofilter_get_input_width (videofilter);
250 int height = gst_videofilter_get_input_height (videofilter);
252 g_return_if_fail (GST_IS_WARPTV (videofilter));
253 warptv = GST_WARPTV (videofilter);
255 /* if any setup needs to be done, do it here */
257 warptv->width = width;
258 warptv->height = height;
260 /* FIXME this should be reset in PAUSE->READY, not here */
264 g_free (warptv->disttable);
265 g_free (warptv->offstable);
267 warptv->offstable = (guint32 *) g_malloc (height * sizeof (guint32));
268 warptv->disttable = g_malloc (width * height * sizeof (guint32));
270 initSinTable (warptv);
271 initOffsTable (warptv);
272 initDistTable (warptv);
276 initSinTable (GstWarpTV * filter)
278 gint32 *tptr, *tsinptr;
281 tsinptr = tptr = filter->sintable;
283 for (i = 0; i < 1024; i++)
284 *tptr++ = (int) (sin (i * M_PI / 512) * 32767);
286 for (i = 0; i < 256; i++)
287 *tptr++ = *tsinptr++;
291 initOffsTable (GstWarpTV * filter)
295 for (y = 0; y < filter->height; y++) {
296 filter->offstable[y] = y * filter->width;
301 initDistTable (GstWarpTV * filter)
303 gint32 halfw, halfh, *distptr;
311 halfw = filter->width >> 1;
312 halfh = filter->height >> 1;
314 distptr = filter->disttable;
316 m = sqrt ((double) (halfw * halfw + halfh * halfh));
318 for (y = -halfh; y < halfh; y++)
319 for (x = -halfw; x < halfw; x++)
321 *distptr++ = ((int) ((sqrtf (x * x + y * y) * 511.9999) / m)) << 1;
323 *distptr++ = ((int) ((sqrt (x * x + y * y) * 511.9999) / m)) << 1;
328 gst_warptv_rgb32 (GstVideofilter * videofilter, void *d, void *s)
331 int width = gst_videofilter_get_input_width (videofilter);
332 int height = gst_videofilter_get_input_height (videofilter);
336 gint32 c, i, x, y, dx, dy, maxx, maxy;
337 gint32 skip, *ctptr, *distptr;
338 gint32 *sintable, *ctable;
340 g_return_if_fail (GST_IS_WARPTV (videofilter));
341 warptv = GST_WARPTV (videofilter);
343 xw = (gint) (sin ((warptv->tval + 100) * M_PI / 128) * 30);
344 yw = (gint) (sin ((warptv->tval) * M_PI / 256) * -35);
345 cw = (gint) (sin ((warptv->tval - 70) * M_PI / 64) * 50);
346 xw += (gint) (sin ((warptv->tval - 10) * M_PI / 512) * 40);
347 yw += (gint) (sin ((warptv->tval + 30) * M_PI / 512) * 40);
349 ctptr = warptv->ctable;
350 distptr = warptv->disttable;
351 sintable = warptv->sintable;
352 ctable = warptv->ctable;
354 skip = 0; /* video_width*sizeof(RGB32)/4 - video_width;; */
357 for (x = 0; x < 512; x++) {
358 i = (c >> 3) & 0x3FE;
359 *ctptr++ = ((sintable[i] * yw) >> 15);
360 *ctptr++ = ((sintable[i + 256] * xw) >> 15);
366 for (y = 0; y < height - 1; y++) {
367 for (x = 0; x < width; x++) {
369 dx = ctable[i + 1] + x;
381 *dest++ = src[warptv->offstable[dy] + dx];
386 warptv->tval = (warptv->tval + 1) & 511;