diff options
author | Sreerenj Balachandran <sreerenj.balachandran@intel.com> | 2012-06-30 00:22:40 +0300 |
---|---|---|
committer | Tim-Philipp Müller <tim@centricular.net> | 2012-07-14 13:37:55 +0100 |
commit | 45ca8876b2f5267f7edb842b6d56d7a6c271ccb3 (patch) | |
tree | 872122042264763655056cf151dad4d60faf3178 /ext/opencv/gstcvsobel.c | |
parent | 8712729a8c3dd3f048473325fe16a65641ca041a (diff) |
opencv: port to 0.11
Basic port to 0.11 API.
https://bugzilla.gnome.org/show_bug.cgi?id=679164
Diffstat (limited to 'ext/opencv/gstcvsobel.c')
-rw-r--r-- | ext/opencv/gstcvsobel.c | 141 |
1 files changed, 81 insertions, 60 deletions
diff --git a/ext/opencv/gstcvsobel.c b/ext/opencv/gstcvsobel.c index 8aaeedd45..aedf9b799 100644 --- a/ext/opencv/gstcvsobel.c +++ b/ext/opencv/gstcvsobel.c @@ -56,20 +56,23 @@ GST_DEBUG_CATEGORY_STATIC (gst_cv_sobel_debug); static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_GRAY8) + GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("GRAY8")) ); + #if G_BYTE_ORDER == G_BIG_ENDIAN -#define BYTE_ORDER_STRING "BIG_ENDIAN" +static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("GRAY16_BE")) + ); #else -#define BYTE_ORDER_STRING "LITTLE_ENDIAN" -#endif - static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_GRAY16 (BYTE_ORDER_STRING)) + GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("GRAY16_LE")) ); +#endif /* Filter signals and args */ enum @@ -89,8 +92,7 @@ enum #define DEFAULT_Y_ORDER 0 #define DEFAULT_APERTURE_SIZE 3 -GST_BOILERPLATE (GstCvSobel, gst_cv_sobel, GstOpencvVideoFilter, - GST_TYPE_OPENCV_VIDEO_FILTER); +G_DEFINE_TYPE (GstCvSobel, gst_cv_sobel, GST_TYPE_OPENCV_VIDEO_FILTER); static void gst_cv_sobel_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); @@ -98,30 +100,11 @@ static void gst_cv_sobel_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); static GstCaps *gst_cv_sobel_transform_caps (GstBaseTransform * trans, - GstPadDirection dir, GstCaps * caps); + GstPadDirection dir, GstCaps * caps, GstCaps * filter); static GstFlowReturn gst_cv_sobel_transform (GstOpencvVideoFilter * filter, GstBuffer * buf, IplImage * img, GstBuffer * outbuf, IplImage * outimg); -/* GObject vmethod implementations */ - -static void -gst_cv_sobel_base_init (gpointer gclass) -{ - GstElementClass *element_class = GST_ELEMENT_CLASS (gclass); - - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&src_factory)); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&sink_factory)); - - gst_element_class_set_details_simple (element_class, - "cvsobel", - "Transform/Effect/Video", - "Applies cvSobel OpenCV function to the image", - "Thiago Santos<thiago.sousa.santos@collabora.co.uk>"); -} - /* initialize the cvsobel's class */ static void gst_cv_sobel_class_init (GstCvSobelClass * klass) @@ -130,12 +113,11 @@ gst_cv_sobel_class_init (GstCvSobelClass * klass) GstBaseTransformClass *gstbasetransform_class; GstOpencvVideoFilterClass *gstopencvbasefilter_class; + GstElementClass *element_class = GST_ELEMENT_CLASS (klass); gobject_class = (GObjectClass *) klass; gstbasetransform_class = (GstBaseTransformClass *) klass; gstopencvbasefilter_class = (GstOpencvVideoFilterClass *) klass; - parent_class = g_type_class_peek_parent (klass); - gobject_class->set_property = gst_cv_sobel_set_property; gobject_class->get_property = gst_cv_sobel_get_property; @@ -155,10 +137,21 @@ gst_cv_sobel_class_init (GstCvSobelClass * klass) g_param_spec_int ("aperture-size", "aperture size", "Size of the extended Sobel Kernel (1, 3, 5 or 7)", 1, 7, DEFAULT_APERTURE_SIZE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&src_factory)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&sink_factory)); + + gst_element_class_set_details_simple (element_class, + "cvsobel", + "Transform/Effect/Video", + "Applies cvSobel OpenCV function to the image", + "Thiago Santos<thiago.sousa.santos@collabora.co.uk>"); } static void -gst_cv_sobel_init (GstCvSobel * filter, GstCvSobelClass * gclass) +gst_cv_sobel_init (GstCvSobel * filter) { filter->x_order = DEFAULT_X_ORDER; filter->y_order = DEFAULT_Y_ORDER; @@ -169,41 +162,69 @@ gst_cv_sobel_init (GstCvSobel * filter, GstCvSobelClass * gclass) static GstCaps * gst_cv_sobel_transform_caps (GstBaseTransform * trans, GstPadDirection dir, - GstCaps * caps) + GstCaps * caps, GstCaps * filter) { - GstCaps *output = NULL; + GstCaps *to, *ret; + GstCaps *templ; GstStructure *structure; + GstPad *other; gint i; - output = gst_caps_copy (caps); - - /* we accept anything from the template caps for either side */ - switch (dir) { - case GST_PAD_SINK: - for (i = 0; i < gst_caps_get_size (output); i++) { - structure = gst_caps_get_structure (output, i); - gst_structure_set (structure, - "depth", G_TYPE_INT, 16, - "bpp", G_TYPE_INT, 16, - "endianness", G_TYPE_INT, G_BYTE_ORDER, NULL); - } - break; - case GST_PAD_SRC: - for (i = 0; i < gst_caps_get_size (output); i++) { - structure = gst_caps_get_structure (output, i); - gst_structure_set (structure, - "depth", G_TYPE_INT, 8, "bpp", G_TYPE_INT, 8, NULL); - gst_structure_remove_field (structure, "endianness"); - } - break; - default: - gst_caps_unref (output); - output = NULL; - g_assert_not_reached (); - break; + to = gst_caps_new_empty (); + + for (i = 0; i < gst_caps_get_size (caps); i++) { + const GValue *v; + GValue list = { 0, }; + GValue val = { 0, }; + + structure = gst_structure_copy (gst_caps_get_structure (caps, i)); + + g_value_init (&list, GST_TYPE_LIST); + + g_value_init (&val, G_TYPE_STRING); + g_value_set_string (&val, "GRAY8"); + gst_value_list_append_value (&list, &val); + g_value_unset (&val); + + g_value_init (&val, G_TYPE_STRING); +#if G_BYTE_ORDER == G_BIG_ENDIAN + g_value_set_string (&val, "GRAY16_BE"); +#else + g_value_set_string (&val, "GRAY16_LE"); +#endif + gst_value_list_append_value (&list, &val); + g_value_unset (&val); + + v = gst_structure_get_value (structure, "format"); + + gst_value_list_merge (&val, v, &list); + gst_structure_set_value (structure, "format", &val); + g_value_unset (&val); + g_value_unset (&list); + + gst_structure_remove_field (structure, "colorimetry"); + gst_structure_remove_field (structure, "chroma-site"); + + gst_caps_append_structure (to, structure); + + } + /* filter against set allowed caps on the pad */ + other = (dir == GST_PAD_SINK) ? trans->srcpad : trans->sinkpad; + templ = gst_pad_get_pad_template_caps (other); + ret = gst_caps_intersect (to, templ); + gst_caps_unref (to); + gst_caps_unref (templ); + + if (ret && filter) { + GstCaps *intersection; + + intersection = + gst_caps_intersect_full (filter, ret, GST_CAPS_INTERSECT_FIRST); + gst_caps_unref (ret); + ret = intersection; } - return output; + return ret; } static void |