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
66 static int dx[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
67 static int dy[8] = { 0, -1, -1, -1, 0, 1, 1, 1 };
69 typedef struct _GstAgingTV GstAgingTV;
70 typedef struct _GstAgingTVClass GstAgingTVClass;
74 GstVideofilter videofilter;
79 scratch scratches[SCRATCH_MAX];
87 struct _GstAgingTVClass
89 GstVideofilterClass parent_class;
92 /* GstAgingTV signals and args */
105 static void gst_agingtv_base_init (gpointer g_class);
106 static void gst_agingtv_class_init (gpointer g_class, gpointer class_data);
107 static void gst_agingtv_init (GTypeInstance * instance, gpointer g_class);
108 static void gst_agingtv_setup (GstVideofilter * videofilter);
110 static void gst_agingtv_set_property (GObject * object, guint prop_id,
111 const GValue * value, GParamSpec * pspec);
112 static void gst_agingtv_get_property (GObject * object, guint prop_id,
113 GValue * value, GParamSpec * pspec);
114 static void gst_agingtv_rgb32 (GstVideofilter * videofilter, void *d, void *s);
117 gst_agingtv_get_type (void)
119 static GType agingtv_type = 0;
122 static const GTypeInfo agingtv_info = {
123 sizeof (GstAgingTVClass),
124 gst_agingtv_base_init,
126 gst_agingtv_class_init,
134 agingtv_type = g_type_register_static (GST_TYPE_VIDEOFILTER,
135 "GstAgingTV", &agingtv_info, 0);
140 static GstVideofilterFormat gst_agingtv_formats[] = {
141 {"RGB ", 32, gst_agingtv_rgb32, 24, G_BIG_ENDIAN, 0x0000ff00, 0x00ff0000,
146 gst_agingtv_base_init (gpointer g_class)
148 static GstElementDetails agingtv_details = GST_ELEMENT_DETAILS ("AgingTV",
149 "Filter/Effect/Video",
150 "AgingTV adds age to video input using scratches and dust",
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, &agingtv_details);
158 for (i = 0; i < G_N_ELEMENTS (gst_agingtv_formats); i++) {
159 gst_videofilter_class_add_format (videofilter_class,
160 gst_agingtv_formats + i);
163 gst_videofilter_class_add_pad_templates (GST_VIDEOFILTER_CLASS (g_class));
167 gst_agingtv_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);
175 gobject_class->set_property = gst_agingtv_set_property;
176 gobject_class->get_property = gst_agingtv_get_property;
179 g_object_class_install_property (gobject_class, ARG_METHOD,
180 g_param_spec_enum ("method", "method", "method",
181 GST_TYPE_AGINGTV_METHOD, GST_AGINGTV_METHOD_1, G_PARAM_READWRITE));
184 videofilter_class->setup = gst_agingtv_setup;
188 gst_agingtv_init (GTypeInstance * instance, gpointer g_class)
190 GstAgingTV *agingtv = GST_AGINGTV (instance);
191 GstVideofilter *videofilter;
193 GST_DEBUG ("gst_agingtv_init");
195 videofilter = GST_VIDEOFILTER (agingtv);
201 gst_agingtv_setup (GstVideofilter * videofilter)
204 int width = gst_videofilter_get_input_width (videofilter);
205 int height = gst_videofilter_get_input_height (videofilter);
207 g_return_if_fail (GST_IS_AGINGTV (videofilter));
208 agingtv = GST_AGINGTV (videofilter);
210 /* if any setup needs to be done, do it here */
212 agingtv->width = width;
213 agingtv->height = height;
219 static unsigned int fastrand_val;
221 return (fastrand_val = fastrand_val * 1103515245 + 12345);
226 coloraging (guint32 * src, guint32 * dest, gint video_area)
231 for (i = video_area; i; i--) {
233 b = (a & 0xfcfcfc) >> 2;
234 *dest++ = a - b + 0x181818 + ((fastrand () >> 8) & 0x101010);
240 scratching (scratch * scratches, gint scratch_lines, guint32 * dest, gint width,
247 for (i = 0; i < scratch_lines; i++) {
248 scratch = &scratches[i];
251 scratch->x = scratch->x + scratch->dx;
253 if (scratch->x < 0 || scratch->x > width * 256) {
257 p = dest + (scratch->x >> 8);
268 y2 = fastrand () % height;
270 for (y = y1; y < y2; y++) {
274 *p = a | (b - (b >> 8));
278 if ((fastrand () & 0xf0000000) == 0) {
279 scratch->life = 2 + (fastrand () >> 27);
280 scratch->x = fastrand () % (width * 256);
281 scratch->dx = ((int) fastrand ()) >> 23;
282 scratch->init = (fastrand () % (height - 1)) + 1;
289 dusts (guint32 * dest, gint width, gint height, gint dust_interval,
297 if (dust_interval == 0) {
298 if ((fastrand () & 0xf0000000) == 0) {
299 dust_interval = fastrand () >> 29;
303 dnum = area_scale * 4 + (fastrand () >> 27);
305 for (i = 0; i < dnum; i++) {
306 x = fastrand () % width;
307 y = fastrand () % height;
308 d = fastrand () >> 29;
309 len = fastrand () % area_scale + 5;
310 for (j = 0; j < len; j++) {
311 dest[y * width + x] = 0x101010;
315 if (y >= height || x >= width)
318 d = (d + fastrand () % 3 - 1) & 7;
325 pits (guint32 * dest, gint width, gint height, gint area_scale,
329 int pnum, size, pnumscale;
332 pnumscale = area_scale * 2;
334 pnum = pnumscale + (fastrand () % pnumscale);
338 pnum = fastrand () % pnumscale;
340 if ((fastrand () & 0xf8000000) == 0) {
341 pits_interval = (fastrand () >> 28) + 20;
344 for (i = 0; i < pnum; i++) {
345 x = fastrand () % (width - 1);
346 y = fastrand () % (height - 1);
348 size = fastrand () >> 28;
350 for (j = 0; j < size; j++) {
351 x = x + fastrand () % 3 - 1;
352 y = y + fastrand () % 3 - 1;
354 if (y >= height || x >= width)
357 dest[y * width + x] = 0xc0c0c0;
363 gst_agingtv_rgb32 (GstVideofilter * videofilter, void *d, void *s)
366 int width = gst_videofilter_get_input_width (videofilter);
367 int height = gst_videofilter_get_input_height (videofilter);
368 int video_size = width * height;
371 gint area_scale = width * height / 64 / 480;
376 g_return_if_fail (GST_IS_AGINGTV (videofilter));
377 agingtv = GST_AGINGTV (videofilter);
379 coloraging (src, dest, video_size);
380 scratching (agingtv->scratches, agingtv->scratch_lines, dest, width, height);
381 pits (dest, width, height, area_scale, agingtv->pits_interval);
383 dusts (dest, width, height, agingtv->dust_interval, area_scale);
388 gst_agingtv_set_property (GObject * object, guint prop_id, const GValue * value,
393 g_return_if_fail (GST_IS_AGINGTV (object));
394 src = GST_AGINGTV (object);
396 GST_DEBUG ("gst_agingtv_set_property");
400 src->method = g_value_get_enum (value);
409 gst_agingtv_get_property (GObject * object, guint prop_id, GValue * value,
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);