2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
23 #define GST_TYPE_EFFECTV \
24 (gst_effectv_get_type())
25 #define GST_EFFECTV(obj) \
26 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_EFFECTV,GstEffecTV))
27 #define GST_EFFECTV_CLASS(klass) \
28 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_ULAW,GstEffecTV))
29 #define GST_IS_EFFECTV(obj) \
30 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_EFFECTV))
31 #define GST_IS_EFFECTV_CLASS(obj) \
32 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_EFFECTV))
34 typedef struct _GstEffecTV GstEffecTV;
35 typedef struct _GstEffecTVClass GstEffecTVClass;
41 GstPad *sinkpad, *srcpad;
44 gint map_width, map_height;
46 gint video_width_margin;
49 struct _GstEffecTVClass
51 GstElementClass parent_class;
54 static GstElementDetails effectv_details = {
57 "Aply edge detect on video",
59 "Wim Taymans <wim.taymans@chello.be>",
64 /* Filter signals and args */
76 GST_PAD_TEMPLATE_FACTORY (effectv_src_factory,
83 "format", GST_PROPS_FOURCC (GST_STR_FOURCC ("RGB ")),
84 "bpp", GST_PROPS_INT (32),
85 "depth", GST_PROPS_INT (32),
86 "endianness", GST_PROPS_INT (G_BYTE_ORDER),
87 "red_mask", GST_PROPS_INT (0xff0000),
88 "green_mask", GST_PROPS_INT (0xff00),
89 "blue_mask", GST_PROPS_INT (0xff),
90 "width", GST_PROPS_INT_RANGE (16, 4096),
91 "height", GST_PROPS_INT_RANGE (16, 4096)
95 GST_PAD_TEMPLATE_FACTORY (effectv_sink_factory,
102 "format", GST_PROPS_FOURCC (GST_STR_FOURCC ("RGB ")),
103 "bpp", GST_PROPS_INT (32),
104 "depth", GST_PROPS_INT (32),
105 "endianness", GST_PROPS_INT (G_BYTE_ORDER),
106 "red_mask", GST_PROPS_INT (0xff0000),
107 "green_mask", GST_PROPS_INT (0xff00),
108 "blue_mask", GST_PROPS_INT (0xff),
109 "width", GST_PROPS_INT_RANGE (16, 4096),
110 "height", GST_PROPS_INT_RANGE (16, 4096)
114 static GType gst_effectv_get_type (void);
116 static void gst_effectv_class_init (GstEffecTVClass * klass);
117 static void gst_effectv_init (GstEffecTV * filter);
119 static void gst_effectv_set_property (GObject * object, guint prop_id,
120 const GValue * value, GParamSpec * pspec);
121 static void gst_effectv_get_property (GObject * object, guint prop_id,
122 GValue * value, GParamSpec * pspec);
124 static void gst_effectv_chain (GstPad * pad, GstBuffer * buf);
126 static GstElementClass *parent_class = NULL;
128 /*static guint gst_filter_signals[LAST_SIGNAL] = { 0 }; */
130 static GType gst_effectv_get_type (void)
132 static GType effectv_type = 0;
135 static const GTypeInfo effectv_info = {
136 sizeof (GstEffecTVClass), NULL,
138 (GClassInitFunc) gst_effectv_class_init,
143 (GInstanceInitFunc) gst_effectv_init,
146 effectv_type = g_type_register_static (GST_TYPE_ELEMENT, "GstEffecTV", &effectv_info, 0);
152 gst_effectv_class_init (GstEffecTVClass * klass)
154 GObjectClass *gobject_class;
155 GstElementClass *gstelement_class;
157 gobject_class = (GObjectClass *) klass;
158 gstelement_class = (GstElementClass *) klass;
160 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
162 gobject_class->set_property = gst_effectv_set_property;
163 gobject_class->get_property = gst_effectv_get_property;
166 static GstPadConnectReturn
167 gst_effectv_sinkconnect (GstPad * pad, GstCaps * caps)
171 filter = GST_EFFECTV (gst_pad_get_parent (pad));
173 if (!GST_CAPS_IS_FIXED (caps))
174 return GST_PAD_CONNECT_DELAYED;
176 gst_caps_get_int (caps, "width", &filter->width);
177 gst_caps_get_int (caps, "height", &filter->height);
179 filter->map_width = filter->width / 4;
180 filter->map_height = filter->height / 4;
181 filter->video_width_margin = filter->width - filter->map_width * 4;
183 g_free (filter->map);
184 filter->map = (guint32 *)g_malloc (filter->map_width * filter->map_height * sizeof(guint32) * 2);
185 bzero(filter->map, filter->map_width * filter->map_height * sizeof(guint32) * 2);
187 if (gst_pad_try_set_caps (filter->srcpad, caps)) {
188 return GST_PAD_CONNECT_OK;
191 return GST_PAD_CONNECT_REFUSED;
195 gst_effectv_init (GstEffecTV * filter)
197 filter->sinkpad = gst_pad_new_from_template (effectv_sink_factory (), "sink");
198 gst_pad_set_chain_function (filter->sinkpad, gst_effectv_chain);
199 gst_pad_set_connect_function (filter->sinkpad, gst_effectv_sinkconnect);
200 gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
202 filter->srcpad = gst_pad_new_from_template (effectv_src_factory (), "src");
203 gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
209 gst_effectv_chain (GstPad * pad, GstBuffer * buf)
216 guint32 v0, v1, v2, v3;
219 filter = GST_EFFECTV (gst_pad_get_parent (pad));
221 src = (guint32 *) GST_BUFFER_DATA (buf);
223 outbuf = gst_buffer_new ();
224 GST_BUFFER_SIZE (outbuf) = (filter->width * filter->height * 4);
225 dest = (guint32 *) GST_BUFFER_DATA (outbuf) = g_malloc (GST_BUFFER_SIZE (outbuf));
226 GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf);
228 src += filter->width * 4 + 4;
229 dest += filter->width * 4 + 4;
231 for (y = 1; y < filter->map_height - 1; y++) {
232 for (x = 1; x < filter->map_width - 1; x++) {
237 /* difference between the current pixel and right neighbor. */
238 r = ((p & 0xff0000) - (q & 0xff0000)) >> 16;
239 g = ((p & 0xff00) - (q & 0xff00)) >> 8;
240 b = (p & 0xff) - (q & 0xff);
244 r = r >> 5; /* To lack the lower bit for saturated addition, */
245 g = g >> 5; /* devide the value with 32, instead of 16. It is */
246 b = b >> 4; /* same as `v2 &= 0xfefeff' */
253 v2 = (r << 17) | (g << 9) | b;
255 /* difference between the current pixel and upper neighbor. */
256 q = *(src - filter->width * 4);
257 r = ((p & 0xff0000) - (q & 0xff0000)) >> 16;
258 g = ((p & 0xff00) - (q & 0xff00)) >> 8;
259 b = (p & 0xff) - (q & 0xff);
272 v3 = (r << 17) | (g << 9) | b;
274 v0 = filter->map[(y - 1) * filter->map_width * 2 + x * 2];
275 v1 = filter->map[y * filter->map_width * 2 + (x - 1) * 2 + 1];
276 filter->map[y * filter->map_width * 2 + x * 2] = v2;
277 filter->map[y * filter->map_width * 2 + x * 2 + 1] = v3;
280 dest[0] = r | (g - (g >> 8));
283 dest[1] = r | (g - (g >> 8));
288 dest[filter->width] = r | (g - (g >> 8));
291 dest[filter->width + 1] = r | (g - (g >> 8));
292 dest[filter->width + 2] = v3;
293 dest[filter->width + 3] = v3;
294 dest[filter->width * 2] = v2;
295 dest[filter->width * 2 + 1] = v2;
296 dest[filter->width * 3] = v2;
297 dest[filter->width * 3 + 1] = v2;
302 src += filter->width * 3 + 8 + filter->video_width_margin;
303 dest += filter->width * 3 + 8 + filter->video_width_margin;
305 gst_buffer_unref (buf);
307 gst_pad_push (filter->srcpad, outbuf);
311 gst_effectv_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec)
315 /* it's not null if we got it, but it might not be ours */
316 g_return_if_fail (GST_IS_EFFECTV (object));
318 filter = GST_EFFECTV (object);
327 gst_effectv_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec)
331 /* it's not null if we got it, but it might not be ours */
332 g_return_if_fail (GST_IS_EFFECTV (object));
334 filter = GST_EFFECTV (object);
338 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
344 plugin_init (GModule * module, GstPlugin * plugin)
346 GstElementFactory *factory;
348 factory = gst_element_factory_new ("edgeTV", GST_TYPE_EFFECTV, &effectv_details);
349 g_return_val_if_fail (factory != NULL, FALSE);
351 gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (effectv_src_factory));
352 gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (effectv_sink_factory));
354 gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
359 GstPluginDesc plugin_desc = {