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 ! ffmpegcolorspace ! autovideosink
37 * ]| This pipeline shows the effect of edgetv on a test stream.
49 #include <gst/video/video.h>
51 GST_BOILERPLATE (GstEdgeTV, gst_edgetv, GstVideoFilter, GST_TYPE_VIDEO_FILTER);
53 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
54 #define CAPS_STR GST_VIDEO_CAPS_BGRx ";" GST_VIDEO_CAPS_RGBx
56 #define CAPS_STR GST_VIDEO_CAPS_xBGR ";" GST_VIDEO_CAPS_xRGB
59 static GstStaticPadTemplate gst_edgetv_src_template =
60 GST_STATIC_PAD_TEMPLATE ("src",
63 GST_STATIC_CAPS (CAPS_STR)
66 static GstStaticPadTemplate gst_edgetv_sink_template =
67 GST_STATIC_PAD_TEMPLATE ("sink",
70 GST_STATIC_CAPS (CAPS_STR)
74 gst_edgetv_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
77 GstEdgeTV *edgetv = GST_EDGETV (btrans);
78 GstStructure *structure;
81 structure = gst_caps_get_structure (incaps, 0);
83 if (gst_structure_get_int (structure, "width", &edgetv->width) &&
84 gst_structure_get_int (structure, "height", &edgetv->height)) {
87 edgetv->map_width = edgetv->width / 4;
88 edgetv->map_height = edgetv->height / 4;
89 edgetv->video_width_margin = edgetv->width % 4;
91 map_size = edgetv->map_width * edgetv->map_height * sizeof (guint32) * 2;
94 edgetv->map = (guint32 *) g_malloc0 (map_size);
102 gst_edgetv_transform (GstBaseTransform * trans, GstBuffer * in, GstBuffer * out)
104 GstEdgeTV *filter = GST_EDGETV (trans);
108 guint32 v0, v1, v2, v3;
109 GstFlowReturn ret = GST_FLOW_OK;
111 src = (guint32 *) GST_BUFFER_DATA (in);
112 dest = (guint32 *) GST_BUFFER_DATA (out);
114 src += filter->width * 4 + 4;
115 dest += filter->width * 4 + 4;
117 for (y = 1; y < filter->map_height - 1; y++) {
118 for (x = 1; x < filter->map_width - 1; x++) {
122 /* difference between the current pixel and right neighbor. */
123 r = ((p & 0xff0000) - (q & 0xff0000)) >> 16;
124 g = ((p & 0xff00) - (q & 0xff00)) >> 8;
125 b = (p & 0xff) - (q & 0xff);
129 r = r >> 5; /* To lack the lower bit for saturated addition, */
130 g = g >> 5; /* devide the value with 32, instead of 16. It is */
131 b = b >> 4; /* same as `v2 &= 0xfefeff' */
138 v2 = (r << 17) | (g << 9) | b;
140 /* difference between the current pixel and upper neighbor. */
141 q = *(src - filter->width * 4);
142 r = ((p & 0xff0000) - (q & 0xff0000)) >> 16;
143 g = ((p & 0xff00) - (q & 0xff00)) >> 8;
144 b = (p & 0xff) - (q & 0xff);
157 v3 = (r << 17) | (g << 9) | b;
159 v0 = filter->map[(y - 1) * filter->map_width * 2 + x * 2];
160 v1 = filter->map[y * filter->map_width * 2 + (x - 1) * 2 + 1];
161 filter->map[y * filter->map_width * 2 + x * 2] = v2;
162 filter->map[y * filter->map_width * 2 + x * 2 + 1] = v3;
165 dest[0] = r | (g - (g >> 8));
168 dest[1] = r | (g - (g >> 8));
173 dest[filter->width] = r | (g - (g >> 8));
176 dest[filter->width + 1] = r | (g - (g >> 8));
177 dest[filter->width + 2] = v3;
178 dest[filter->width + 3] = v3;
179 dest[filter->width * 2] = v2;
180 dest[filter->width * 2 + 1] = v2;
181 dest[filter->width * 3] = v2;
182 dest[filter->width * 3 + 1] = v2;
187 src += filter->width * 3 + 8 + filter->video_width_margin;
188 dest += filter->width * 3 + 8 + filter->video_width_margin;
195 gst_edgetv_start (GstBaseTransform * trans)
197 GstEdgeTV *edgetv = GST_EDGETV (trans);
200 memset (edgetv->map, 0,
201 edgetv->map_width * edgetv->map_height * sizeof (guint32) * 2);
206 gst_edgetv_finalize (GObject * object)
208 GstEdgeTV *edgetv = GST_EDGETV (object);
210 g_free (edgetv->map);
213 G_OBJECT_CLASS (parent_class)->finalize (object);
217 gst_edgetv_base_init (gpointer g_class)
219 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
221 gst_element_class_set_details_simple (element_class, "EdgeTV effect",
222 "Filter/Effect/Video",
223 "Apply edge detect on video", "Wim Taymans <wim.taymans@chello.be>");
225 gst_element_class_add_pad_template (element_class,
226 gst_static_pad_template_get (&gst_edgetv_sink_template));
227 gst_element_class_add_pad_template (element_class,
228 gst_static_pad_template_get (&gst_edgetv_src_template));
232 gst_edgetv_class_init (GstEdgeTVClass * klass)
234 GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
235 GObjectClass *gobject_class = (GObjectClass *) klass;
237 gobject_class->finalize = gst_edgetv_finalize;
239 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_edgetv_set_caps);
240 trans_class->transform = GST_DEBUG_FUNCPTR (gst_edgetv_transform);
241 trans_class->start = GST_DEBUG_FUNCPTR (gst_edgetv_start);
245 gst_edgetv_init (GstEdgeTV * edgetv, GstEdgeTVClass * klass)