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>
45 #define GST_TYPE_AGINGTV \
46 (gst_agingtv_get_type())
47 #define GST_AGINGTV(obj) \
48 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AGINGTV,GstAgingTV))
49 #define GST_AGINGTV_CLASS(klass) \
50 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AGINGTV,GstAgingTVClass))
51 #define GST_IS_AGINGTV(obj) \
52 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AGINGTV))
53 #define GST_IS_AGINGTV_CLASS(obj) \
54 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AGINGTV))
56 #define SCRATCH_MAX 20
57 typedef struct _scratch
65 static int dx[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
66 static int dy[8] = { 0, -1, -1, -1, 0, 1, 1, 1 };
68 typedef struct _GstAgingTV GstAgingTV;
69 typedef struct _GstAgingTVClass GstAgingTVClass;
73 GstVideofilter videofilter;
78 scratch scratches[SCRATCH_MAX];
86 struct _GstAgingTVClass
88 GstVideofilterClass parent_class;
91 /* GstAgingTV signals and args */
104 static void gst_agingtv_base_init (gpointer g_class);
105 static void gst_agingtv_class_init (gpointer g_class, gpointer class_data);
106 static void gst_agingtv_init (GTypeInstance * instance, gpointer g_class);
107 static void gst_agingtv_setup (GstVideofilter * videofilter);
109 static void gst_agingtv_set_property (GObject * object, guint prop_id,
110 const GValue * value, GParamSpec * pspec);
111 static void gst_agingtv_get_property (GObject * object, guint prop_id,
112 GValue * value, GParamSpec * pspec);
113 static void gst_agingtv_rgb32 (GstVideofilter * videofilter, void *d, void *s);
116 gst_agingtv_get_type (void)
118 static GType agingtv_type = 0;
121 static const GTypeInfo agingtv_info = {
122 sizeof (GstAgingTVClass),
123 gst_agingtv_base_init,
125 gst_agingtv_class_init,
132 agingtv_type = g_type_register_static (GST_TYPE_VIDEOFILTER,
133 "GstAgingTV", &agingtv_info, 0);
138 static GstVideofilterFormat gst_agingtv_formats[] = {
139 {"RGB ", 32, gst_agingtv_rgb32, 24, G_BIG_ENDIAN, 0x0000ff00, 0x00ff0000,
144 gst_agingtv_base_init (gpointer g_class)
146 static GstElementDetails agingtv_details = GST_ELEMENT_DETAILS ("AgingTV",
147 "Filter/Effect/Video",
148 "AgingTV adds age to video input using scratches and dust",
149 "Sam Lantinga <slouken@devolution.com>");
150 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
151 GstVideofilterClass *videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
154 gst_element_class_set_details (element_class, &agingtv_details);
156 for (i = 0; i < G_N_ELEMENTS (gst_agingtv_formats); i++) {
157 gst_videofilter_class_add_format (videofilter_class,
158 gst_agingtv_formats + i);
161 gst_videofilter_class_add_pad_templates (GST_VIDEOFILTER_CLASS (g_class));
165 gst_agingtv_class_init (gpointer g_class, gpointer class_data)
167 GObjectClass *gobject_class;
168 GstVideofilterClass *videofilter_class;
170 gobject_class = G_OBJECT_CLASS (g_class);
171 videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
174 g_object_class_install_property (gobject_class, ARG_METHOD,
175 g_param_spec_enum ("method", "method", "method",
176 GST_TYPE_AGINGTV_METHOD, GST_AGINGTV_METHOD_1, G_PARAM_READWRITE));
179 gobject_class->set_property = gst_agingtv_set_property;
180 gobject_class->get_property = gst_agingtv_get_property;
182 videofilter_class->setup = gst_agingtv_setup;
186 gst_agingtv_init (GTypeInstance * instance, gpointer g_class)
188 GstAgingTV *agingtv = GST_AGINGTV (instance);
189 GstVideofilter *videofilter;
191 GST_DEBUG ("gst_agingtv_init");
193 videofilter = GST_VIDEOFILTER (agingtv);
199 gst_agingtv_setup (GstVideofilter * videofilter)
202 int width = gst_videofilter_get_input_width (videofilter);
203 int height = gst_videofilter_get_input_height (videofilter);
205 g_return_if_fail (GST_IS_AGINGTV (videofilter));
206 agingtv = GST_AGINGTV (videofilter);
208 /* if any setup needs to be done, do it here */
210 agingtv->width = width;
211 agingtv->height = height;
217 static unsigned int fastrand_val;
219 return (fastrand_val = fastrand_val * 1103515245 + 12345);
224 coloraging (guint32 * src, guint32 * dest, gint video_area)
229 for (i = video_area; i; i--) {
231 b = (a & 0xfcfcfc) >> 2;
232 *dest++ = a - b + 0x181818 + ((fastrand () >> 8) & 0x101010);
238 scratching (scratch * scratches, gint scratch_lines, guint32 * dest, gint width,
245 for (i = 0; i < scratch_lines; i++) {
246 scratch = &scratches[i];
249 scratch->x = scratch->x + scratch->dx;
251 if (scratch->x < 0 || scratch->x > width * 256) {
255 p = dest + (scratch->x >> 8);
266 y2 = fastrand () % height;
268 for (y = y1; y < y2; y++) {
272 *p = a | (b - (b >> 8));
276 if ((fastrand () & 0xf0000000) == 0) {
277 scratch->life = 2 + (fastrand () >> 27);
278 scratch->x = fastrand () % (width * 256);
279 scratch->dx = ((int) fastrand ()) >> 23;
280 scratch->init = (fastrand () % (height - 1)) + 1;
287 dusts (guint32 * dest, gint width, gint height, gint dust_interval,
295 if (dust_interval == 0) {
296 if ((fastrand () & 0xf0000000) == 0) {
297 dust_interval = fastrand () >> 29;
301 dnum = area_scale * 4 + (fastrand () >> 27);
303 for (i = 0; i < dnum; i++) {
304 x = fastrand () % width;
305 y = fastrand () % height;
306 d = fastrand () >> 29;
307 len = fastrand () % area_scale + 5;
308 for (j = 0; j < len; j++) {
309 dest[y * width + x] = 0x101010;
313 if (y >= height || x >= width)
316 d = (d + fastrand () % 3 - 1) & 7;
323 pits (guint32 * dest, gint width, gint height, gint area_scale,
327 int pnum, size, pnumscale;
330 pnumscale = area_scale * 2;
332 pnum = pnumscale + (fastrand () % pnumscale);
336 pnum = fastrand () % pnumscale;
338 if ((fastrand () & 0xf8000000) == 0) {
339 pits_interval = (fastrand () >> 28) + 20;
342 for (i = 0; i < pnum; i++) {
343 x = fastrand () % (width - 1);
344 y = fastrand () % (height - 1);
346 size = fastrand () >> 28;
348 for (j = 0; j < size; j++) {
349 x = x + fastrand () % 3 - 1;
350 y = y + fastrand () % 3 - 1;
352 if (y >= height || x >= width)
355 dest[y * width + x] = 0xc0c0c0;
361 gst_agingtv_rgb32 (GstVideofilter * videofilter, void *d, void *s)
364 int width = gst_videofilter_get_input_width (videofilter);
365 int height = gst_videofilter_get_input_height (videofilter);
366 int video_size = width * height;
369 gint area_scale = width * height / 64 / 480;
374 g_return_if_fail (GST_IS_AGINGTV (videofilter));
375 agingtv = GST_AGINGTV (videofilter);
377 coloraging (src, dest, video_size);
378 scratching (agingtv->scratches, agingtv->scratch_lines, dest, width, height);
379 pits (dest, width, height, area_scale, agingtv->pits_interval);
381 dusts (dest, width, height, agingtv->dust_interval, area_scale);
386 gst_agingtv_set_property (GObject * object, guint prop_id, const GValue * value,
391 /* it's not null if we got it, but it might not be ours */
392 g_return_if_fail (GST_IS_AGINGTV (object));
393 src = GST_AGINGTV (object);
395 GST_DEBUG ("gst_agingtv_set_property");
399 src->method = g_value_get_enum (value);
408 gst_agingtv_get_property (GObject * object, guint prop_id, GValue * value,
413 /* it's not null if we got it, but it might not be ours */
414 g_return_if_fail (GST_IS_AGINGTV (object));
415 src = GST_AGINGTV (object);
420 g_value_set_enum (value, src->method);
424 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);