From 80747088e3270df8c51dc540e2c25b75d3752721 Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Sat, 10 Oct 2015 13:14:57 +0200 Subject: [PATCH] avoid needless copies during mjpeg decoding --- modules/videoio/src/cap_v4l.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/modules/videoio/src/cap_v4l.cpp b/modules/videoio/src/cap_v4l.cpp index 8160a0c..5ec5278 100644 --- a/modules/videoio/src/cap_v4l.cpp +++ b/modules/videoio/src/cap_v4l.cpp @@ -1612,15 +1612,11 @@ uyvy_to_rgb24 (int width, int height, unsigned char *src, unsigned char *dst) /* convert from mjpeg to rgb24 */ static bool -mjpeg_to_rgb24 (int width, int height, - unsigned char *src, int length, - unsigned char *dst) -{ - cv::Mat temp=cv::imdecode(cv::Mat(std::vector(src, src + length)), 1); - if( !temp.data || temp.cols != width || temp.rows != height ) - return false; - memcpy(dst, temp.data, width*height*3); - return true; +mjpeg_to_rgb24(int width, int height, unsigned char* src, int length, IplImage* dst) { + using namespace cv; + Mat temp = cvarrToMat(dst); + imdecode(Mat(1, length, CV_8U, src), IMREAD_COLOR, &temp); + return temp.data && temp.cols == width && temp.rows == height; } #endif @@ -2068,7 +2064,7 @@ static IplImage* icvRetrieveFrameCAM_V4L( CvCaptureCAM_V4L* capture, int) { (unsigned char*)(capture->buffers[capture->bufferIndex] .start), capture->buffers[capture->bufferIndex].length, - (unsigned char*)capture->frame.imageData)) + &capture->frame)) return 0; break; #endif -- 2.7.4