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 <gst/video/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(klass) \
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 const GstElementDetails agingtv_details =
97 GST_ELEMENT_DETAILS ("AgingTV effect",
98 "Filter/Effect/Video",
99 "AgingTV adds age to video input using scratches and dust",
100 "Sam Lantinga <slouken@devolution.com>");
102 static GstStaticPadTemplate gst_agingtv_src_template =
103 GST_STATIC_PAD_TEMPLATE ("src",
106 GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx)
109 static GstStaticPadTemplate gst_agingtv_sink_template =
110 GST_STATIC_PAD_TEMPLATE ("sink",
113 GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx)
116 static GstVideoFilterClass *parent_class = NULL;
119 gst_agingtv_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
122 GstAgingTV *filter = GST_AGINGTV (btrans);
123 GstStructure *structure;
124 gboolean ret = FALSE;
126 structure = gst_caps_get_structure (incaps, 0);
128 if (gst_structure_get_int (structure, "width", &filter->width) &&
129 gst_structure_get_int (structure, "height", &filter->height)) {
137 gst_agingtv_get_unit_size (GstBaseTransform * btrans, GstCaps * caps,
141 GstStructure *structure;
142 gboolean ret = FALSE;
145 filter = GST_AGINGTV (btrans);
147 structure = gst_caps_get_structure (caps, 0);
149 if (gst_structure_get_int (structure, "width", &width) &&
150 gst_structure_get_int (structure, "height", &height)) {
151 *size = width * height * 32 / 8;
153 GST_DEBUG_OBJECT (filter, "our frame size is %d bytes (%dx%d)", *size,
163 static unsigned int fastrand_val;
165 return (fastrand_val = fastrand_val * 1103515245 + 12345);
170 coloraging (guint32 * src, guint32 * dest, gint video_area)
175 for (i = video_area; i; i--) {
177 b = (a & 0xfcfcfc) >> 2;
178 *dest++ = a - b + 0x181818 + ((fastrand () >> 8) & 0x101010);
184 scratching (scratch * scratches, gint scratch_lines, guint32 * dest, gint width,
191 for (i = 0; i < scratch_lines; i++) {
192 scratch = &scratches[i];
195 scratch->x = scratch->x + scratch->dx;
197 if (scratch->x < 0 || scratch->x > width * 256) {
201 p = dest + (scratch->x >> 8);
212 y2 = fastrand () % height;
214 for (y = y1; y < y2; y++) {
218 *p = a | (b - (b >> 8));
222 if ((fastrand () & 0xf0000000) == 0) {
223 scratch->life = 2 + (fastrand () >> 27);
224 scratch->x = fastrand () % (width * 256);
225 scratch->dx = ((int) fastrand ()) >> 23;
226 scratch->init = (fastrand () % (height - 1)) + 1;
233 dusts (guint32 * dest, gint width, gint height, gint dust_interval,
241 if (dust_interval == 0) {
242 if ((fastrand () & 0xf0000000) == 0) {
243 dust_interval = fastrand () >> 29;
247 dnum = area_scale * 4 + (fastrand () >> 27);
249 for (i = 0; i < dnum; i++) {
250 x = fastrand () % width;
251 y = fastrand () % height;
252 d = fastrand () >> 29;
253 len = fastrand () % area_scale + 5;
254 for (j = 0; j < len; j++) {
255 dest[y * width + x] = 0x101010;
259 if (y >= height || x >= width)
262 d = (d + fastrand () % 3 - 1) & 7;
269 pits (guint32 * dest, gint width, gint height, gint area_scale,
273 int pnum, size, pnumscale;
276 pnumscale = area_scale * 2;
278 pnum = pnumscale + (fastrand () % pnumscale);
282 pnum = fastrand () % pnumscale;
284 if ((fastrand () & 0xf8000000) == 0) {
285 pits_interval = (fastrand () >> 28) + 20;
288 for (i = 0; i < pnum; i++) {
289 x = fastrand () % (width - 1);
290 y = fastrand () % (height - 1);
292 size = fastrand () >> 28;
294 for (j = 0; j < size; j++) {
295 x = x + fastrand () % 3 - 1;
296 y = y + fastrand () % 3 - 1;
298 if (y >= height || x >= width)
301 dest[y * width + x] = 0xc0c0c0;
307 gst_agingtv_transform (GstBaseTransform * trans, GstBuffer * in,
310 GstAgingTV *agingtv = GST_AGINGTV (trans);
311 gint width = agingtv->width;
312 gint height = agingtv->height;
313 int video_size = width * height;
314 guint32 *src = (guint32 *) GST_BUFFER_DATA (in);
315 guint32 *dest = (guint32 *) GST_BUFFER_DATA (out);
316 gint area_scale = width * height / 64 / 480;
317 GstFlowReturn ret = GST_FLOW_OK;
319 gst_buffer_copy_metadata (out, in, GST_BUFFER_COPY_TIMESTAMPS);
324 coloraging (src, dest, video_size);
325 scratching (agingtv->scratches, agingtv->scratch_lines, dest, width, height);
326 pits (dest, width, height, area_scale, agingtv->pits_interval);
328 dusts (dest, width, height, agingtv->dust_interval, area_scale);
334 gst_agingtv_base_init (gpointer g_class)
336 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
338 gst_element_class_set_details (element_class, &agingtv_details);
340 gst_element_class_add_pad_template (element_class,
341 gst_static_pad_template_get (&gst_agingtv_sink_template));
342 gst_element_class_add_pad_template (element_class,
343 gst_static_pad_template_get (&gst_agingtv_src_template));
347 gst_agingtv_class_init (gpointer klass, gpointer class_data)
349 GstBaseTransformClass *trans_class;
351 trans_class = (GstBaseTransformClass *) klass;
353 parent_class = g_type_class_peek_parent (klass);
355 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_agingtv_set_caps);
356 trans_class->get_unit_size = GST_DEBUG_FUNCPTR (gst_agingtv_get_unit_size);
357 trans_class->transform = GST_DEBUG_FUNCPTR (gst_agingtv_transform);
361 gst_agingtv_init (GTypeInstance * instance, gpointer g_class)
366 gst_agingtv_get_type (void)
368 static GType agingtv_type = 0;
371 static const GTypeInfo agingtv_info = {
372 sizeof (GstAgingTVClass),
373 gst_agingtv_base_init,
375 gst_agingtv_class_init,
383 agingtv_type = g_type_register_static (GST_TYPE_VIDEO_FILTER,
384 "GstAgingTV", &agingtv_info, 0);