2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) <2009> Sebastian Dröge <sebastian.droege@collabora.co.uk>
6 * Copyright (C) 2001-2002 FUKUCHI Kentarou
8 * EdgeTV - detects edge and display it in good old computer way
10 * EffecTV is free software. This library is free software;
11 * you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
21 * You should have received a copy of the GNU Library General Public
22 * License along with this library; if not, write to the
23 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 * Boston, MA 02111-1307, USA.
28 * SECTION:element-edgetv
30 * EdgeTV detects edges and display it in good old low resolution
34 * <title>Example launch line</title>
36 * gst-launch -v videotestsrc ! edgetv ! videoconvert ! autovideosink
37 * ]| This pipeline shows the effect of edgetv on a test stream.
49 #define gst_edgetv_parent_class parent_class
50 G_DEFINE_TYPE (GstEdgeTV, gst_edgetv, GST_TYPE_VIDEO_FILTER);
52 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
53 #define CAPS_STR GST_VIDEO_CAPS_MAKE ("{ BGRx, RGBx }")
55 #define CAPS_STR GST_VIDEO_CAPS_MAKE ("{ xBGR, xRGB }")
58 static GstStaticPadTemplate gst_edgetv_src_template =
59 GST_STATIC_PAD_TEMPLATE ("src",
62 GST_STATIC_CAPS (CAPS_STR)
65 static GstStaticPadTemplate gst_edgetv_sink_template =
66 GST_STATIC_PAD_TEMPLATE ("sink",
69 GST_STATIC_CAPS (CAPS_STR)
73 gst_edgetv_set_info (GstVideoFilter * filter, GstCaps * incaps,
74 GstVideoInfo * in_info, GstCaps * outcaps, GstVideoInfo * out_info)
76 GstEdgeTV *edgetv = GST_EDGETV (filter);
80 width = GST_VIDEO_INFO_WIDTH (in_info);
81 height = GST_VIDEO_INFO_HEIGHT (in_info);
83 edgetv->map_width = width / 4;
84 edgetv->map_height = height / 4;
85 edgetv->video_width_margin = width % 4;
87 map_size = edgetv->map_width * edgetv->map_height * sizeof (guint32) * 2;
90 edgetv->map = (guint32 *) g_malloc0 (map_size);
96 gst_edgetv_transform_frame (GstVideoFilter * vfilter, GstVideoFrame * in_frame,
97 GstVideoFrame * out_frame)
99 GstEdgeTV *filter = GST_EDGETV (vfilter);
103 guint32 v0, v1, v2, v3;
104 gint width, map_height, map_width;
105 gint video_width_margin;
107 GstFlowReturn ret = GST_FLOW_OK;
110 map_height = filter->map_height;
111 map_width = filter->map_width;
112 video_width_margin = filter->video_width_margin;
114 src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
115 dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
117 width = GST_VIDEO_FRAME_WIDTH (in_frame);
119 src += width * 4 + 4;
120 dest += width * 4 + 4;
122 for (y = 1; y < map_height - 1; y++) {
123 for (x = 1; x < map_width - 1; x++) {
127 /* difference between the current pixel and left neighbor. */
128 r = ((p & 0xff0000) - (q & 0xff0000)) >> 16;
129 g = ((p & 0xff00) - (q & 0xff00)) >> 8;
130 b = (p & 0xff) - (q & 0xff);
134 r = r >> 5; /* To lack the lower bit for saturated addition, */
135 g = g >> 5; /* devide the value with 32, instead of 16. It is */
136 b = b >> 4; /* same as `v2 &= 0xfefeff' */
143 v2 = (r << 17) | (g << 9) | b;
145 /* difference between the current pixel and upper neighbor. */
146 q = *(src - width * 4);
147 r = ((p & 0xff0000) - (q & 0xff0000)) >> 16;
148 g = ((p & 0xff00) - (q & 0xff00)) >> 8;
149 b = (p & 0xff) - (q & 0xff);
162 v3 = (r << 17) | (g << 9) | b;
164 v0 = map[(y - 1) * map_width * 2 + x * 2];
165 v1 = map[y * map_width * 2 + (x - 1) * 2 + 1];
166 map[y * map_width * 2 + x * 2] = v2;
167 map[y * map_width * 2 + x * 2 + 1] = v3;
170 dest[0] = r | (g - (g >> 8));
173 dest[1] = r | (g - (g >> 8));
178 dest[width] = r | (g - (g >> 8));
181 dest[width + 1] = r | (g - (g >> 8));
182 dest[width + 2] = v3;
183 dest[width + 3] = v3;
184 dest[width * 2] = v2;
185 dest[width * 2 + 1] = v2;
186 dest[width * 2 + 2] = 0;
187 dest[width * 2 + 3] = 0;
188 dest[width * 3] = v2;
189 dest[width * 3 + 1] = v2;
190 dest[width * 3 + 2] = 0;
191 dest[width * 3 + 3] = 0;
196 src += width * 3 + 8 + video_width_margin;
197 dest += width * 3 + 8 + video_width_margin;
204 gst_edgetv_start (GstBaseTransform * trans)
206 GstEdgeTV *edgetv = GST_EDGETV (trans);
209 memset (edgetv->map, 0,
210 edgetv->map_width * edgetv->map_height * sizeof (guint32) * 2);
215 gst_edgetv_finalize (GObject * object)
217 GstEdgeTV *edgetv = GST_EDGETV (object);
219 g_free (edgetv->map);
222 G_OBJECT_CLASS (parent_class)->finalize (object);
226 gst_edgetv_class_init (GstEdgeTVClass * klass)
228 GObjectClass *gobject_class = (GObjectClass *) klass;
229 GstElementClass *gstelement_class = (GstElementClass *) klass;
230 GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
231 GstVideoFilterClass *vfilter_class = (GstVideoFilterClass *) klass;
233 gobject_class->finalize = gst_edgetv_finalize;
235 gst_element_class_set_details_simple (gstelement_class, "EdgeTV effect",
236 "Filter/Effect/Video",
237 "Apply edge detect on video", "Wim Taymans <wim.taymans@chello.be>");
239 gst_element_class_add_pad_template (gstelement_class,
240 gst_static_pad_template_get (&gst_edgetv_sink_template));
241 gst_element_class_add_pad_template (gstelement_class,
242 gst_static_pad_template_get (&gst_edgetv_src_template));
244 trans_class->start = GST_DEBUG_FUNCPTR (gst_edgetv_start);
246 vfilter_class->set_info = GST_DEBUG_FUNCPTR (gst_edgetv_set_info);
247 vfilter_class->transform_frame =
248 GST_DEBUG_FUNCPTR (gst_edgetv_transform_frame);
252 gst_edgetv_init (GstEdgeTV * edgetv)