From 5a9d9a8ae0f8c33b82b9b8f4499e3947b0f10295 Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Mon, 26 Apr 2010 17:34:12 -0300 Subject: [PATCH] faceblur: facedetect: templatematch: textwrite: Set buffer to writable These elements operates in place, set buffer to writable before operating. --- ext/opencv/faceblur/gstfaceblur.c | 7 ++++--- ext/opencv/facedetect/gstfacedetect.c | 7 ++++--- ext/opencv/templatematch/gsttemplatematch.c | 12 ++++++------ ext/opencv/textwrite/gsttextwrite.c | 4 +--- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/ext/opencv/faceblur/gstfaceblur.c b/ext/opencv/faceblur/gstfaceblur.c index a33a708..bceb068 100644 --- a/ext/opencv/faceblur/gstfaceblur.c +++ b/ext/opencv/faceblur/gstfaceblur.c @@ -272,6 +272,9 @@ gst_faceblur_chain (GstPad * pad, GstBuffer * buf) cvHaarDetectObjects (filter->cvGray, filter->cvCascade, filter->cvStorage, 1.1, 2, 0, cvSize (30, 30)); + if (faces && faces->total > 0) { + buf = gst_buffer_make_writable (buf); + } for (i = 0; i < (faces ? faces->total : 0); i++) { CvRect *r = (CvRect *) cvGetSeqElem (faces, i); cvSetImageROI (filter->cvImage, *r); @@ -279,11 +282,9 @@ gst_faceblur_chain (GstPad * pad, GstBuffer * buf) cvSmooth (filter->cvImage, filter->cvImage, CV_GAUSSIAN, 11, 11, 0, 0); cvResetImageROI (filter->cvImage); } - } - gst_buffer_set_data (buf, (guint8 *) filter->cvImage->imageData, - filter->cvImage->imageSize); + /* these filters operate in place, so we push the same buffer */ return gst_pad_push (filter->srcpad, buf); } diff --git a/ext/opencv/facedetect/gstfacedetect.c b/ext/opencv/facedetect/gstfacedetect.c index 6494e43..660add6 100644 --- a/ext/opencv/facedetect/gstfacedetect.c +++ b/ext/opencv/facedetect/gstfacedetect.c @@ -284,6 +284,10 @@ gst_facedetect_chain (GstPad * pad, GstBuffer * buf) cvHaarDetectObjects (filter->cvGray, filter->cvCascade, filter->cvStorage, 1.1, 2, 0, cvSize (30, 30)); + if (filter->display && faces && faces->total > 0) { + buf = gst_buffer_make_writable (buf); + } + for (i = 0; i < (faces ? faces->total : 0); i++) { CvRect *r = (CvRect *) cvGetSeqElem (faces, i); @@ -310,9 +314,6 @@ gst_facedetect_chain (GstPad * pad, GstBuffer * buf) } - gst_buffer_set_data (buf, (guint8 *) filter->cvImage->imageData, - filter->cvImage->imageSize); - return gst_pad_push (filter->srcpad, buf); } diff --git a/ext/opencv/templatematch/gsttemplatematch.c b/ext/opencv/templatematch/gsttemplatematch.c index 6dad35b..3821020 100644 --- a/ext/opencv/templatematch/gsttemplatematch.c +++ b/ext/opencv/templatematch/gsttemplatematch.c @@ -310,13 +310,14 @@ gst_templatematch_chain (GstPad * pad, GstBuffer * buf) double best_res; filter = GST_TEMPLATEMATCH (GST_OBJECT_PARENT (pad)); - buf = gst_buffer_make_writable (buf); + + /* FIXME Why template == NULL returns OK? + * shouldn't it be a passthrough instead? */ if ((!filter) || (!buf) || filter->template == NULL) { return GST_FLOW_OK; } filter->cvImage->imageData = (char *) GST_BUFFER_DATA (buf); - if (!filter->cvDistImage) { filter->cvDistImage = cvCreateImage (cvSize (filter->cvImage->width - @@ -344,6 +345,9 @@ gst_templatematch_chain (GstPad * pad, GstBuffer * buf) if (filter->display) { CvPoint corner = best_pos; + + buf = gst_buffer_make_writable (buf); + corner.x += filter->cvTemplateImage->width; corner.y += filter->cvTemplateImage->height; cvRectangle (filter->cvImage, best_pos, corner, CV_RGB (255, 32, 32), 3, @@ -352,10 +356,6 @@ gst_templatematch_chain (GstPad * pad, GstBuffer * buf) } - - gst_buffer_set_data (buf, (guint8 *) filter->cvImage->imageData, - filter->cvImage->imageSize); - return gst_pad_push (filter->srcpad, buf); } diff --git a/ext/opencv/textwrite/gsttextwrite.c b/ext/opencv/textwrite/gsttextwrite.c index 7e56846..287de3f 100644 --- a/ext/opencv/textwrite/gsttextwrite.c +++ b/ext/opencv/textwrite/gsttextwrite.c @@ -384,11 +384,9 @@ gst_textwrite_chain (GstPad * pad, GstBuffer * buf) cvInitFont(&(filter->font),CV_FONT_VECTOR0, filter->width,filter->height,0,filter->thickness,0); + buf = gst_buffer_make_writable (buf); cvPutText (filter->cvImage,filter->textbuf,cvPoint(filter->xpos,filter->ypos), &(filter->font), cvScalar(filter->colorR,filter->colorG,filter->colorB,0)); - gst_buffer_set_data (buf, (guint8 *) filter->cvImage->imageData, - filter->cvImage->imageSize); - return gst_pad_push (filter->srcpad, buf); } -- 2.7.4