Commit 02b20f61 authored by Nicolas Dufresne's avatar Nicolas Dufresne

cvsobel: Avoid extra copy of the output image

Simply produce the result into the output image provided by the base
class. This avoid useless copy. This also removes unchecked buffer map
and ensure that GstVideoMeta is respected (for stride mostly).

https://bugzilla.gnome.org/show_bug.cgi?id=775377
parent 7a284f1a
......@@ -116,7 +116,6 @@ gst_cv_sobel_finalize (GObject * obj)
GstCvSobel *filter = GST_CV_SOBEL (obj);
if (filter->cvSobel != NULL) {
cvReleaseImage (&filter->cvCSobel);
cvReleaseImage (&filter->cvGray);
cvReleaseImage (&filter->cvSobel);
}
......@@ -192,12 +191,10 @@ gst_cv_sobel_set_caps (GstOpencvVideoFilter * transform,
GstCvSobel *filter = GST_CV_SOBEL (transform);
if (filter->cvSobel != NULL) {
cvReleaseImage (&filter->cvCSobel);
cvReleaseImage (&filter->cvGray);
cvReleaseImage (&filter->cvSobel);
}
filter->cvCSobel = cvCreateImage (cvSize (in_width, in_height), IPL_DEPTH_8U, in_channels);
filter->cvGray = cvCreateImage (cvSize (in_width, in_height), IPL_DEPTH_8U, 1);
filter->cvSobel = cvCreateImage (cvSize (out_width, out_height), IPL_DEPTH_8U, 1);
......@@ -265,23 +262,18 @@ gst_cv_sobel_transform (GstOpencvVideoFilter * base, GstBuffer * buf,
IplImage * img, GstBuffer * outbuf, IplImage * outimg)
{
GstCvSobel *filter = GST_CV_SOBEL (base);
GstMapInfo out_info;
cvCvtColor (img, filter->cvGray, CV_RGB2GRAY);
cvSobel (filter->cvGray, filter->cvSobel, filter->x_order, filter->y_order,
filter->aperture_size);
cvZero (filter->cvCSobel);
cvZero (outimg);
if (filter->mask) {
cvCopy (img, filter->cvCSobel, filter->cvSobel);
cvCopy (img, outimg, filter->cvSobel);
} else {
cvCvtColor (filter->cvSobel, filter->cvCSobel, CV_GRAY2RGB);
cvCvtColor (filter->cvSobel, outimg, CV_GRAY2RGB);
}
gst_buffer_map (outbuf, &out_info, GST_MAP_WRITE);
memcpy (out_info.data, filter->cvCSobel->imageData,
gst_buffer_get_size (outbuf));
return GST_FLOW_OK;
}
......
......@@ -72,7 +72,6 @@ struct _GstCvSobel
gint aperture_size;
gboolean mask;
IplImage *cvCSobel;
IplImage *cvGray;
IplImage *cvSobel;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment