3
* Copyright (C) 2010 Thiago Santos <thiago.sousa.santos@collabora.co.uk>
5
* Permission is hereby granted, free of charge, to any person obtaining a
6
* copy of this software and associated documentation files (the "Software"),
7
* to deal in the Software without restriction, including without limitation
8
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
* and/or sell copies of the Software, and to permit persons to whom the
10
* Software is furnished to do so, subject to the following conditions:
12
* The above copyright notice and this permission notice shall be included in
13
* all copies or substantial portions of the Software.
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
* DEALINGS IN THE SOFTWARE.
23
* Alternatively, the contents of this file may be used under the
24
* GNU Lesser General Public License Version 2.1 (the "LGPL"), in
25
* which case the following provisions apply instead of the ones
28
* This library is free software; you can redistribute it and/or
29
* modify it under the terms of the GNU Library General Public
30
* License as published by the Free Software Foundation; either
31
* version 2 of the License, or (at your option) any later version.
33
* This library is distributed in the hope that it will be useful,
34
* but WITHOUT ANY WARRANTY; without even the implied warranty of
35
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
36
* Library General Public License for more details.
38
* You should have received a copy of the GNU Library General Public
39
* License along with this library; if not, write to the
40
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
41
* Boston, MA 02111-1307, USA.
50
#include "gstcvsmooth.h"
52
GST_DEBUG_CATEGORY_STATIC (gst_cv_smooth_debug);
53
#define GST_CAT_DEFAULT gst_cv_smooth_debug
55
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
58
GST_STATIC_CAPS ("video/x-raw-rgb, depth=(int)24, bpp=(int)24")
61
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
64
GST_STATIC_CAPS ("video/x-raw-rgb, depth=(int)24, bpp=(int)24")
67
/* Filter signals and args */
83
#define GST_TYPE_CV_SMOOTH_TYPE (gst_cv_smooth_type_get_type ())
85
gst_cv_smooth_type_get_type (void)
87
static GType cv_smooth_type_type = 0;
89
static const GEnumValue smooth_types[] = {
90
{CV_BLUR_NO_SCALE, "CV Blur No Scale", "blur-no-scale"},
91
{CV_BLUR, "CV Blur", "blur"},
92
{CV_GAUSSIAN, "CV Gaussian", "gaussian"},
93
{CV_MEDIAN, "CV Median", "median"},
94
{CV_BILATERAL, "CV Bilateral", "bilateral"},
98
if (!cv_smooth_type_type) {
100
g_enum_register_static ("GstCvSmoothTypeType", smooth_types);
102
return cv_smooth_type_type;
105
#define DEFAULT_CV_SMOOTH_TYPE CV_GAUSSIAN
106
#define DEFAULT_PARAM1 3
107
#define DEFAULT_PARAM2 0.0
108
#define DEFAULT_PARAM3 0.0
109
#define DEFAULT_PARAM4 0.0
111
GST_BOILERPLATE (GstCvSmooth, gst_cv_smooth, GstOpencvBaseTransform,
112
GST_TYPE_OPENCV_BASE_TRANSFORM);
114
static void gst_cv_smooth_set_property (GObject * object, guint prop_id,
115
const GValue * value, GParamSpec * pspec);
116
static void gst_cv_smooth_get_property (GObject * object, guint prop_id,
117
GValue * value, GParamSpec * pspec);
119
static GstFlowReturn gst_cv_smooth_transform_ip (GstOpencvBaseTransform * filter,
120
GstBuffer * buf, IplImage * img);
121
static GstFlowReturn gst_cv_smooth_transform (GstOpencvBaseTransform * filter,
122
GstBuffer * buf, IplImage * img, GstBuffer * outbuf, IplImage * outimg);
126
gst_cv_smooth_finalize (GObject * obj)
128
G_OBJECT_CLASS (parent_class)->finalize (obj);
132
/* GObject vmethod implementations */
135
gst_cv_smooth_base_init (gpointer gclass)
137
GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
139
gst_element_class_add_pad_template (element_class,
140
gst_static_pad_template_get (&src_factory));
141
gst_element_class_add_pad_template (element_class,
142
gst_static_pad_template_get (&sink_factory));
144
gst_element_class_set_details_simple (element_class,
146
"Transform/Effect/Video",
147
"Applies cvSmooth OpenCV function to the image",
148
"Thiago Santos<thiago.sousa.santos@collabora.co.uk>");
151
/* initialize the cvsmooth's class */
153
gst_cv_smooth_class_init (GstCvSmoothClass * klass)
155
GObjectClass *gobject_class;
156
GstOpencvBaseTransformClass *gstopencvbasefilter_class;
157
GstElementClass *gstelement_class;
159
gobject_class = (GObjectClass *) klass;
160
gstelement_class = (GstElementClass *) klass;
161
gstopencvbasefilter_class = (GstOpencvBaseTransformClass *) klass;
163
parent_class = g_type_class_peek_parent (klass);
165
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_cv_smooth_finalize);
166
gobject_class->set_property = gst_cv_smooth_set_property;
167
gobject_class->get_property = gst_cv_smooth_get_property;
169
gstopencvbasefilter_class->cv_trans_ip_func = gst_cv_smooth_transform_ip;
170
gstopencvbasefilter_class->cv_trans_func = gst_cv_smooth_transform;
172
g_object_class_install_property (gobject_class, PROP_SMOOTH_TYPE,
173
g_param_spec_enum ("type",
176
GST_TYPE_CV_SMOOTH_TYPE,
177
DEFAULT_CV_SMOOTH_TYPE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)
179
g_object_class_install_property (gobject_class, PROP_PARAM1,
180
g_param_spec_int ("param1", "param1",
181
"Param1 (Check cvSmooth OpenCV docs)", 1, G_MAXINT, DEFAULT_PARAM1,
182
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
183
g_object_class_install_property (gobject_class, PROP_PARAM2,
184
g_param_spec_int ("param2", "param2",
185
"Param2 (Check cvSmooth OpenCV docs)", 0, G_MAXINT, DEFAULT_PARAM2,
186
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
187
g_object_class_install_property (gobject_class, PROP_PARAM3,
188
g_param_spec_double ("param3", "param3",
189
"Param3 (Check cvSmooth OpenCV docs)", 0, G_MAXDOUBLE, DEFAULT_PARAM3,
190
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
191
g_object_class_install_property (gobject_class, PROP_PARAM4,
192
g_param_spec_double ("param4", "param4",
193
"Param4 (Check cvSmooth OpenCV docs)", 0, G_MAXDOUBLE, DEFAULT_PARAM4,
194
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
197
/* initialize the new element
198
* instantiate pads and add them to element
199
* set pad calback functions
200
* initialize instance structure
203
gst_cv_smooth_init (GstCvSmooth * filter, GstCvSmoothClass * gclass)
205
filter->type = DEFAULT_CV_SMOOTH_TYPE;
206
filter->param1 = DEFAULT_PARAM1;
207
filter->param2 = DEFAULT_PARAM2;
208
filter->param3 = DEFAULT_PARAM3;
209
filter->param4 = DEFAULT_PARAM4;
211
gst_base_transform_set_in_place (GST_BASE_TRANSFORM (filter), FALSE);
215
gst_cv_smooth_change_type (GstCvSmooth * filter, gint value)
217
GST_DEBUG_OBJECT (filter, "Changing type from %d to %d", filter->type, value);
218
if (filter->type == value)
221
filter->type = value;
225
gst_base_transform_set_in_place (GST_BASE_TRANSFORM (filter), TRUE);
228
gst_base_transform_set_in_place (GST_BASE_TRANSFORM (filter), FALSE);
234
gst_cv_smooth_set_property (GObject * object, guint prop_id,
235
const GValue * value, GParamSpec * pspec)
237
GstCvSmooth *filter = GST_CV_SMOOTH (object);
240
case PROP_SMOOTH_TYPE:
241
gst_cv_smooth_change_type (filter, g_value_get_enum (value));
244
gint prop = g_value_get_int (value);
247
filter->param1 = prop;
249
GST_WARNING_OBJECT (filter, "Ignoring value for param1, not odd"
255
gint prop = g_value_get_int (value);
257
if (prop % 2 == 1 || prop == 0) {
258
filter->param1 = prop;
260
GST_WARNING_OBJECT (filter, "Ignoring value for param2, not odd"
261
" nor zero (%d)", prop);
266
filter->param3 = g_value_get_double (value);
269
filter->param4 = g_value_get_double (value);
272
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
278
gst_cv_smooth_get_property (GObject * object, guint prop_id,
279
GValue * value, GParamSpec * pspec)
281
GstCvSmooth *filter = GST_CV_SMOOTH (object);
284
case PROP_SMOOTH_TYPE:
285
g_value_set_enum (value, filter->type);
288
g_value_set_int (value, filter->param1);
291
g_value_set_int (value, filter->param2);
294
g_value_set_double (value, filter->param3);
297
g_value_set_double (value, filter->param4);
300
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
306
gst_cv_smooth_transform (GstOpencvBaseTransform * base, GstBuffer * buf,
307
IplImage * img, GstBuffer * outbuf, IplImage * outimg)
309
GstCvSmooth *filter = GST_CV_SMOOTH (base);
311
cvSmooth (img, outimg, filter->type, filter->param1, filter->param2,
312
filter->param3, filter->param4);
318
gst_cv_smooth_transform_ip (GstOpencvBaseTransform * base, GstBuffer * buf,
321
GstCvSmooth *filter = GST_CV_SMOOTH (base);
323
cvSmooth (img, img, filter->type, filter->param1, filter->param2,
324
filter->param3, filter->param4);
330
gst_cv_smooth_plugin_init (GstPlugin * plugin)
332
GST_DEBUG_CATEGORY_INIT (gst_cv_smooth_debug, "cvsmooth", 0, "cvsmooth");
334
return gst_element_register (plugin, "cvsmooth", GST_RANK_NONE,