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;
72 GstVideofilter videofilter;
77 scratch scratches[SCRATCH_MAX];
85 struct _GstAgingTVClass {
86 GstVideofilterClass parent_class;
89 /* GstAgingTV signals and args */
100 static void gst_agingtv_base_init (gpointer g_class);
101 static void gst_agingtv_class_init (gpointer g_class, gpointer class_data);
102 static void gst_agingtv_init (GTypeInstance *instance, gpointer g_class);
103 static void gst_agingtv_setup (GstVideofilter *videofilter);
105 static void gst_agingtv_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
106 static void gst_agingtv_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
107 static void gst_agingtv_rgb32 (GstVideofilter *videofilter, void *d, void *s);
110 gst_agingtv_get_type (void)
112 static GType agingtv_type = 0;
115 static const GTypeInfo agingtv_info = {
116 sizeof(GstAgingTVClass),
117 gst_agingtv_base_init,
119 gst_agingtv_class_init,
126 agingtv_type = g_type_register_static(GST_TYPE_VIDEOFILTER,
127 "GstAgingTV", &agingtv_info, 0);
132 static GstVideofilterFormat gst_agingtv_formats[] = {
133 { "RGB ", 32, gst_agingtv_rgb32, 24, G_BIG_ENDIAN, 0x0000ff00, 0x00ff0000, 0xff000000 }
137 gst_agingtv_base_init (gpointer g_class)
139 static GstElementDetails agingtv_details = GST_ELEMENT_DETAILS (
141 "Filter/Effect/Video",
142 "AgingTV adds age to video input using scratches and dust",
143 "Sam Lantinga <slouken@devolution.com>"
145 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
146 GstVideofilterClass *videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
149 gst_element_class_set_details (element_class, &agingtv_details);
151 for(i=0;i<G_N_ELEMENTS(gst_agingtv_formats);i++){
152 gst_videofilter_class_add_format(videofilter_class,
153 gst_agingtv_formats + i);
156 gst_videofilter_class_add_pad_templates (GST_VIDEOFILTER_CLASS (g_class));
160 gst_agingtv_class_init (gpointer g_class, gpointer class_data)
162 GObjectClass *gobject_class;
163 GstVideofilterClass *videofilter_class;
165 gobject_class = G_OBJECT_CLASS (g_class);
166 videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
169 g_object_class_install_property(gobject_class, ARG_METHOD,
170 g_param_spec_enum("method","method","method",
171 GST_TYPE_AGINGTV_METHOD, GST_AGINGTV_METHOD_1,
175 gobject_class->set_property = gst_agingtv_set_property;
176 gobject_class->get_property = gst_agingtv_get_property;
178 videofilter_class->setup = gst_agingtv_setup;
182 gst_agingtv_init (GTypeInstance *instance, gpointer g_class)
184 GstAgingTV *agingtv = GST_AGINGTV (instance);
185 GstVideofilter *videofilter;
187 GST_DEBUG("gst_agingtv_init");
189 videofilter = GST_VIDEOFILTER(agingtv);
194 static void gst_agingtv_setup(GstVideofilter *videofilter)
197 int width = gst_videofilter_get_input_width(videofilter);
198 int height = gst_videofilter_get_input_height(videofilter);
200 g_return_if_fail(GST_IS_AGINGTV(videofilter));
201 agingtv = GST_AGINGTV(videofilter);
203 /* if any setup needs to be done, do it here */
205 agingtv->width = width;
206 agingtv->height = height;
212 static unsigned int fastrand_val;
214 return (fastrand_val = fastrand_val * 1103515245 + 12345);
219 coloraging (guint32 *src, guint32 *dest, gint video_area)
224 for (i = video_area; i; i--) {
226 b = (a & 0xfcfcfc) >> 2;
227 *dest++ = a - b + 0x181818 + ((fastrand () >> 8) & 0x101010);
233 scratching (scratch *scratches, gint scratch_lines, guint32 *dest, gint width, gint height)
239 for (i = 0; i < scratch_lines; i++) {
240 scratch = &scratches[i];
243 scratch->x = scratch->x + scratch->dx;
245 if (scratch->x < 0 || scratch->x > width * 256) {
249 p = dest + (scratch->x >> 8);
260 y2 = fastrand () % height;
262 for (y = y1; y < y2; y++) {
266 *p = a | (b - (b >> 8));
270 if ((fastrand () & 0xf0000000) == 0) {
271 scratch->life = 2 + (fastrand () >> 27);
272 scratch->x = fastrand () % (width * 256);
273 scratch->dx = ((int) fastrand ()) >> 23;
274 scratch->init = (fastrand () % (height - 1)) + 1;
281 dusts (guint32 *dest, gint width, gint height, gint dust_interval, gint area_scale)
288 if (dust_interval == 0) {
289 if ((fastrand () & 0xf0000000) == 0) {
290 dust_interval = fastrand () >> 29;
294 dnum = area_scale * 4 + (fastrand() >> 27);
296 for (i = 0; i < dnum; i++) {
297 x = fastrand () % width;
298 y = fastrand () % height;
299 d = fastrand () >> 29;
300 len = fastrand () % area_scale + 5;
301 for (j = 0; j < len; j++) {
302 dest[y * width + x] = 0x101010;
306 if (y >= height || x >= width) break;
308 d = (d + fastrand () % 3 - 1) & 7;
315 pits (guint32 *dest, gint width, gint height, gint area_scale, gint pits_interval)
318 int pnum, size, pnumscale;
321 pnumscale = area_scale * 2;
323 pnum = pnumscale + (fastrand () % pnumscale);
327 pnum = fastrand () % pnumscale;
329 if ((fastrand () & 0xf8000000) == 0) {
330 pits_interval = (fastrand () >> 28) + 20;
333 for (i = 0; i < pnum; i++) {
334 x = fastrand () % (width - 1);
335 y = fastrand () % (height - 1);
337 size = fastrand () >> 28;
339 for (j = 0; j < size; j++) {
340 x = x + fastrand () % 3 - 1;
341 y = y + fastrand () % 3 - 1;
343 if (y >= height || x >= width) break;
345 dest[y * width + x] = 0xc0c0c0;
351 gst_agingtv_rgb32 (GstVideofilter *videofilter, void *d, void *s)
354 int width = gst_videofilter_get_input_width(videofilter);
355 int height = gst_videofilter_get_input_height(videofilter);
356 int video_size = width * height;
359 gint area_scale = width * height / 64 / 480;
360 if (area_scale <= 0) area_scale = 1;
362 g_return_if_fail(GST_IS_AGINGTV(videofilter));
363 agingtv = GST_AGINGTV(videofilter);
365 coloraging (src, dest, video_size);
366 scratching (agingtv->scratches, agingtv->scratch_lines, dest, width, height);
367 pits (dest, width, height, area_scale, agingtv->pits_interval);
369 dusts (dest, width, height, agingtv->dust_interval, area_scale);
374 gst_agingtv_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
378 /* it's not null if we got it, but it might not be ours */
379 g_return_if_fail(GST_IS_AGINGTV(object));
380 src = GST_AGINGTV(object);
382 GST_DEBUG("gst_agingtv_set_property");
386 src->method = g_value_get_enum (value);
395 gst_agingtv_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
399 /* it's not null if we got it, but it might not be ours */
400 g_return_if_fail(GST_IS_AGINGTV(object));
401 src = GST_AGINGTV(object);
406 g_value_set_enum (value, src->method);
410 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);