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
40 #include <gstvideofilter.h>
45 #include <gst/video/video.h>
47 #define GST_TYPE_AGINGTV \
48 (gst_agingtv_get_type())
49 #define GST_AGINGTV(obj) \
50 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AGINGTV,GstAgingTV))
51 #define GST_AGINGTV_CLASS(klass) \
52 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AGINGTV,GstAgingTVClass))
53 #define GST_IS_AGINGTV(obj) \
54 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AGINGTV))
55 #define GST_IS_AGINGTV_CLASS(obj) \
56 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AGINGTV))
58 #define SCRATCH_MAX 20
59 typedef struct _scratch
68 static int dx[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
69 static int dy[8] = { 0, -1, -1, -1, 0, 1, 1, 1 };
71 typedef struct _GstAgingTV GstAgingTV;
72 typedef struct _GstAgingTVClass GstAgingTVClass;
76 GstVideofilter videofilter;
81 scratch scratches[SCRATCH_MAX];
89 struct _GstAgingTVClass
91 GstVideofilterClass parent_class;
94 GType gst_agingtv_get_type (void);
96 static GstElementDetails agingtv_details = GST_ELEMENT_DETAILS ("AgingTV",
97 "Filter/Effect/Video",
98 "AgingTV adds age to video input using scratches and dust",
99 "Sam Lantinga <slouken@devolution.com>");
101 static GstStaticPadTemplate gst_agingtv_src_template =
102 GST_STATIC_PAD_TEMPLATE ("src",
105 GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx)
108 static GstStaticPadTemplate gst_agingtv_sink_template =
109 GST_STATIC_PAD_TEMPLATE ("sink",
112 GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx)
115 static GstVideofilterClass *parent_class = NULL;
118 gst_agingtv_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
121 GstAgingTV *filter = GST_AGINGTV (btrans);
122 GstStructure *structure;
123 gboolean ret = FALSE;
125 structure = gst_caps_get_structure (incaps, 0);
127 if (gst_structure_get_int (structure, "width", &filter->width) &&
128 gst_structure_get_int (structure, "height", &filter->height)) {
136 gst_agingtv_get_unit_size (GstBaseTransform * btrans, GstCaps * caps,
140 GstStructure *structure;
141 gboolean ret = FALSE;
144 filter = GST_AGINGTV (btrans);
146 structure = gst_caps_get_structure (caps, 0);
148 if (gst_structure_get_int (structure, "width", &width) &&
149 gst_structure_get_int (structure, "height", &height)) {
150 *size = width * height * 32 / 8;
152 GST_DEBUG_OBJECT (filter, "our frame size is %d bytes (%dx%d)", *size,
162 static unsigned int fastrand_val;
164 return (fastrand_val = fastrand_val * 1103515245 + 12345);
169 coloraging (guint32 * src, guint32 * dest, gint video_area)
174 for (i = video_area; i; i--) {
176 b = (a & 0xfcfcfc) >> 2;
177 *dest++ = a - b + 0x181818 + ((fastrand () >> 8) & 0x101010);
183 scratching (scratch * scratches, gint scratch_lines, guint32 * dest, gint width,
190 for (i = 0; i < scratch_lines; i++) {
191 scratch = &scratches[i];
194 scratch->x = scratch->x + scratch->dx;
196 if (scratch->x < 0 || scratch->x > width * 256) {
200 p = dest + (scratch->x >> 8);
211 y2 = fastrand () % height;
213 for (y = y1; y < y2; y++) {
217 *p = a | (b - (b >> 8));
221 if ((fastrand () & 0xf0000000) == 0) {
222 scratch->life = 2 + (fastrand () >> 27);
223 scratch->x = fastrand () % (width * 256);
224 scratch->dx = ((int) fastrand ()) >> 23;
225 scratch->init = (fastrand () % (height - 1)) + 1;
232 dusts (guint32 * dest, gint width, gint height, gint dust_interval,
240 if (dust_interval == 0) {
241 if ((fastrand () & 0xf0000000) == 0) {
242 dust_interval = fastrand () >> 29;
246 dnum = area_scale * 4 + (fastrand () >> 27);
248 for (i = 0; i < dnum; i++) {
249 x = fastrand () % width;
250 y = fastrand () % height;
251 d = fastrand () >> 29;
252 len = fastrand () % area_scale + 5;
253 for (j = 0; j < len; j++) {
254 dest[y * width + x] = 0x101010;
258 if (y >= height || x >= width)
261 d = (d + fastrand () % 3 - 1) & 7;
268 pits (guint32 * dest, gint width, gint height, gint area_scale,
272 int pnum, size, pnumscale;
275 pnumscale = area_scale * 2;
277 pnum = pnumscale + (fastrand () % pnumscale);
281 pnum = fastrand () % pnumscale;
283 if ((fastrand () & 0xf8000000) == 0) {
284 pits_interval = (fastrand () >> 28) + 20;
287 for (i = 0; i < pnum; i++) {
288 x = fastrand () % (width - 1);
289 y = fastrand () % (height - 1);
291 size = fastrand () >> 28;
293 for (j = 0; j < size; j++) {
294 x = x + fastrand () % 3 - 1;
295 y = y + fastrand () % 3 - 1;
297 if (y >= height || x >= width)
300 dest[y * width + x] = 0xc0c0c0;
306 gst_agingtv_transform (GstBaseTransform * trans, GstBuffer * in,
309 GstAgingTV *agingtv = GST_AGINGTV (trans);
310 gint width = agingtv->width;
311 gint height = agingtv->height;
312 int video_size = width * height;
313 guint32 *src = (guint32 *) GST_BUFFER_DATA (in);
314 guint32 *dest = (guint32 *) GST_BUFFER_DATA (out);
315 gint area_scale = width * height / 64 / 480;
316 GstFlowReturn ret = GST_FLOW_OK;
318 gst_buffer_stamp (out, in);
323 coloraging (src, dest, video_size);
324 scratching (agingtv->scratches, agingtv->scratch_lines, dest, width, height);
325 pits (dest, width, height, area_scale, agingtv->pits_interval);
327 dusts (dest, width, height, agingtv->dust_interval, area_scale);
333 gst_agingtv_base_init (gpointer g_class)
335 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
337 gst_element_class_set_details (element_class, &agingtv_details);
339 gst_element_class_add_pad_template (element_class,
340 gst_static_pad_template_get (&gst_agingtv_sink_template));
341 gst_element_class_add_pad_template (element_class,
342 gst_static_pad_template_get (&gst_agingtv_src_template));
346 gst_agingtv_class_init (gpointer klass, gpointer class_data)
348 GObjectClass *gobject_class;
349 GstElementClass *element_class;
350 GstBaseTransformClass *trans_class;
352 gobject_class = (GObjectClass *) klass;
353 element_class = (GstElementClass *) klass;
354 trans_class = (GstBaseTransformClass *) klass;
356 parent_class = g_type_class_peek_parent (klass);
358 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_agingtv_set_caps);
359 trans_class->get_unit_size = GST_DEBUG_FUNCPTR (gst_agingtv_get_unit_size);
360 trans_class->transform = GST_DEBUG_FUNCPTR (gst_agingtv_transform);
364 gst_agingtv_init (GTypeInstance * instance, gpointer g_class)
369 gst_agingtv_get_type (void)
371 static GType agingtv_type = 0;
374 static const GTypeInfo agingtv_info = {
375 sizeof (GstAgingTVClass),
376 gst_agingtv_base_init,
378 gst_agingtv_class_init,
386 agingtv_type = g_type_register_static (GST_TYPE_VIDEOFILTER,
387 "GstAgingTV", &agingtv_info, 0);