2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
5 * Copyright (C) 2001 FUKUCHI Kentarou
7 * Inspired by Adrian Likin's script for the GIMP.
8 * EffecTV is free software. This library is free software;
9 * you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
26 * SECTION:element-shagadelictv
28 * Oh behave, ShagedelicTV makes images shagadelic!
31 * <title>Example launch line</title>
33 * gst-launch -v videotestsrc ! shagadelictv ! videoconvert ! autovideosink
34 * ]| This pipeline shows the effect of shagadelictv on a test stream.
45 #include "gstshagadelic.h"
46 #include "gsteffectv.h"
49 #define M_PI 3.14159265358979323846
52 #define gst_shagadelictv_parent_class parent_class
53 G_DEFINE_TYPE (GstShagadelicTV, gst_shagadelictv, GST_TYPE_VIDEO_FILTER);
55 static void gst_shagadelic_initialize (GstShagadelicTV * filter,
56 GstVideoInfo * in_info);
58 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
59 #define CAPS_STR GST_VIDEO_CAPS_MAKE ("BGRx")
61 #define CAPS_STR GST_VIDEO_CAPS_MAKE ("xRGB")
64 static GstStaticPadTemplate gst_shagadelictv_src_template =
65 GST_STATIC_PAD_TEMPLATE ("src",
68 GST_STATIC_CAPS (CAPS_STR)
71 static GstStaticPadTemplate gst_shagadelictv_sink_template =
72 GST_STATIC_PAD_TEMPLATE ("sink",
75 GST_STATIC_CAPS (CAPS_STR)
79 gst_shagadelictv_set_info (GstVideoFilter * vfilter, GstCaps * incaps,
80 GstVideoInfo * in_info, GstCaps * outcaps, GstVideoInfo * out_info)
82 GstShagadelicTV *filter = GST_SHAGADELICTV (vfilter);
83 gint width, height, area;
85 width = GST_VIDEO_INFO_WIDTH (in_info);
86 height = GST_VIDEO_INFO_HEIGHT (in_info);
88 area = width * height;
90 g_free (filter->ripple);
91 g_free (filter->spiral);
92 filter->ripple = (guint8 *) g_malloc (area * 4);
93 filter->spiral = (guint8 *) g_malloc (area);
95 gst_shagadelic_initialize (filter, in_info);
101 gst_shagadelic_initialize (GstShagadelicTV * filter, GstVideoInfo * info)
111 width = GST_VIDEO_INFO_WIDTH (info);
112 height = GST_VIDEO_INFO_HEIGHT (info);
115 for (y = 0; y < height * 2; y++) {
119 for (x = 0; x < width * 2; x++) {
122 filter->ripple[i++] = ((unsigned int) (sqrtf (xx * xx + yy) * 8)) & 255;
124 filter->ripple[i++] = ((unsigned int) (sqrt (xx * xx + yy) * 8)) & 255;
130 for (y = 0; y < height; y++) {
133 for (x = 0; x < width; x++) {
136 filter->spiral[i++] = ((unsigned int)
138 yy) / ((float) M_PI) * 256 * 9) + (sqrtf (xx * xx +
139 yy * yy) * 5))) & 255;
141 filter->spiral[i++] = ((unsigned int)
142 ((atan2 (xx, yy) / M_PI * 256 * 9) + (sqrt (xx * xx +
143 yy * yy) * 5))) & 255;
145 /* Here is another Swinger!
146 * ((atan2(xx, yy)/M_PI*256) + (sqrt(xx*xx+yy*yy)*10))&255;
150 filter->rx = fastrand () % width;
151 filter->ry = fastrand () % height;
152 filter->bx = fastrand () % width;
153 filter->by = fastrand () % height;
162 gst_shagadelictv_transform_frame (GstVideoFilter * vfilter,
163 GstVideoFrame * in_frame, GstVideoFrame * out_frame)
165 GstShagadelicTV *filter = GST_SHAGADELICTV (vfilter);
172 src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
173 dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
175 width = GST_VIDEO_FRAME_WIDTH (in_frame);
176 height = GST_VIDEO_FRAME_HEIGHT (in_frame);
178 for (y = 0; y < height; y++) {
179 for (x = 0; x < width; x++) {
180 v = *src++ | 0x1010100;
181 v = (v - 0x707060) & 0x1010100;
185 * *dest++ = v & ((r<<16)|(g<<8)|b);
187 r = ((gint8) (filter->ripple[(filter->ry + y) * width * 2 + filter->rx +
188 x] + filter->phase * 2)) >> 7;
189 g = ((gint8) (filter->spiral[y * width + x] + filter->phase * 3)) >> 7;
190 b = ((gint8) (filter->ripple[(filter->by + y) * width * 2 + filter->bx +
191 x] - filter->phase)) >> 7;
192 *dest++ = v & ((r << 16) | (g << 8) | b);
197 if ((filter->rx + filter->rvx) < 0 || (filter->rx + filter->rvx) >= width)
198 filter->rvx = -filter->rvx;
199 if ((filter->ry + filter->rvy) < 0 || (filter->ry + filter->rvy) >= height)
200 filter->rvy = -filter->rvy;
201 if ((filter->bx + filter->bvx) < 0 || (filter->bx + filter->bvx) >= width)
202 filter->bvx = -filter->bvx;
203 if ((filter->by + filter->bvy) < 0 || (filter->by + filter->bvy) >= height)
204 filter->bvy = -filter->bvy;
205 filter->rx += filter->rvx;
206 filter->ry += filter->rvy;
207 filter->bx += filter->bvx;
208 filter->by += filter->bvy;
214 gst_shagadelictv_finalize (GObject * object)
216 GstShagadelicTV *filter = GST_SHAGADELICTV (object);
219 g_free (filter->ripple);
220 filter->ripple = NULL;
223 g_free (filter->spiral);
224 filter->spiral = NULL;
226 G_OBJECT_CLASS (parent_class)->finalize (object);
230 gst_shagadelictv_class_init (GstShagadelicTVClass * klass)
232 GObjectClass *gobject_class = (GObjectClass *) klass;
233 GstElementClass *gstelement_class = (GstElementClass *) klass;
234 GstVideoFilterClass *vfilter_class = (GstVideoFilterClass *) klass;
236 gobject_class->finalize = gst_shagadelictv_finalize;
238 gst_element_class_set_details_simple (gstelement_class, "ShagadelicTV",
239 "Filter/Effect/Video",
240 "Oh behave, ShagedelicTV makes images shagadelic!",
241 "Wim Taymans <wim.taymans@chello.be>");
243 gst_element_class_add_pad_template (gstelement_class,
244 gst_static_pad_template_get (&gst_shagadelictv_sink_template));
245 gst_element_class_add_pad_template (gstelement_class,
246 gst_static_pad_template_get (&gst_shagadelictv_src_template));
248 vfilter_class->set_info = GST_DEBUG_FUNCPTR (gst_shagadelictv_set_info);
249 vfilter_class->transform_frame =
250 GST_DEBUG_FUNCPTR (gst_shagadelictv_transform_frame);
254 gst_shagadelictv_init (GstShagadelicTV * filter)
256 filter->ripple = NULL;
257 filter->spiral = NULL;