Commit 0c79f4a0 authored by Maksim Shabunin's avatar Maksim Shabunin

MediaSDK: fixed Linux build, improved BGR<->NV12 conversions

parent cc626a3b
...@@ -192,6 +192,12 @@ CV_EXPORTS void cvtTwoPlaneYUVtoBGR(const uchar * src_data, size_t src_step, ...@@ -192,6 +192,12 @@ CV_EXPORTS void cvtTwoPlaneYUVtoBGR(const uchar * src_data, size_t src_step,
int dst_width, int dst_height, int dst_width, int dst_height,
int dcn, bool swapBlue, int uIdx); int dcn, bool swapBlue, int uIdx);
//! Separate Y and UV planes
CV_EXPORTS void cvtTwoPlaneYUVtoBGR(const uchar * y_data, const uchar * uv_data, size_t src_step,
uchar * dst_data, size_t dst_step,
int dst_width, int dst_height,
int dcn, bool swapBlue, int uIdx);
CV_EXPORTS void cvtThreePlaneYUVtoBGR(const uchar * src_data, size_t src_step, CV_EXPORTS void cvtThreePlaneYUVtoBGR(const uchar * src_data, size_t src_step,
uchar * dst_data, size_t dst_step, uchar * dst_data, size_t dst_step,
int dst_width, int dst_height, int dst_width, int dst_height,
...@@ -202,6 +208,12 @@ CV_EXPORTS void cvtBGRtoThreePlaneYUV(const uchar * src_data, size_t src_step, ...@@ -202,6 +208,12 @@ CV_EXPORTS void cvtBGRtoThreePlaneYUV(const uchar * src_data, size_t src_step,
int width, int height, int width, int height,
int scn, bool swapBlue, int uIdx); int scn, bool swapBlue, int uIdx);
//! Separate Y and UV planes
CV_EXPORTS void cvtBGRtoTwoPlaneYUV(const uchar * src_data, size_t src_step,
uchar * y_data, uchar * uv_data, size_t dst_step,
int width, int height,
int scn, bool swapBlue, int uIdx);
CV_EXPORTS void cvtOnePlaneYUVtoBGR(const uchar * src_data, size_t src_step, CV_EXPORTS void cvtOnePlaneYUVtoBGR(const uchar * src_data, size_t src_step,
uchar * dst_data, size_t dst_step, uchar * dst_data, size_t dst_step,
int width, int height, int width, int height,
......
This diff is collapsed.
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
// Linux specific // Linux specific
#ifdef __linux__ #ifdef __linux__
#include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
......
...@@ -288,6 +288,7 @@ protected: ...@@ -288,6 +288,7 @@ protected:
// Linux specific // Linux specific
#ifdef __linux__ #ifdef __linux__
#include <unistd.h>
#include <va/va_drm.h> #include <va/va_drm.h>
class VAHandle : public DeviceHandler { class VAHandle : public DeviceHandler {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "cap_mfx_reader.hpp" #include "cap_mfx_reader.hpp"
#include "opencv2/core/base.hpp" #include "opencv2/core/base.hpp"
#include "cap_mfx_common.hpp" #include "cap_mfx_common.hpp"
#include "opencv2/imgproc/hal/hal.hpp"
using namespace cv; using namespace cv;
using namespace std; using namespace std;
...@@ -243,17 +244,11 @@ bool VideoCapture_IntelMFX::retrieveFrame(int, OutputArray out) ...@@ -243,17 +244,11 @@ bool VideoCapture_IntelMFX::retrieveFrame(int, OutputArray out)
const int cols = info.CropW; const int cols = info.CropW;
const int rows = info.CropH; const int rows = info.CropH;
Mat nv12(rows * 3 / 2, cols, CV_8UC1);
Mat Y(rows, cols, CV_8UC1, data.Y, data.Pitch); out.create(rows, cols, CV_8UC3);
Mat UV(rows / 2, cols, CV_8UC1, data.UV, data.Pitch); Mat res = out.getMat();
Y.copyTo(Mat(nv12, Rect(0, 0, cols, rows))); hal::cvtTwoPlaneYUVtoBGR(data.Y, data.UV, data.Pitch, res.data, res.step, cols, rows, 3, false, 0);
UV.copyTo(Mat(nv12, Rect(0, rows, cols, rows / 2)));
Mat u_and_v[2];
split(UV.reshape(2), u_and_v);
cvtColor(nv12, out, COLOR_YUV2BGR_NV12);
return true; return true;
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "cap_mfx_writer.hpp" #include "cap_mfx_writer.hpp"
#include "opencv2/core/base.hpp" #include "opencv2/core/base.hpp"
#include "cap_mfx_common.hpp" #include "cap_mfx_common.hpp"
#include "opencv2/imgproc/hal/hal.hpp"
using namespace std; using namespace std;
using namespace cv; using namespace cv;
...@@ -166,26 +167,6 @@ void VideoWriter_IntelMFX::write(cv::InputArray input) ...@@ -166,26 +167,6 @@ void VideoWriter_IntelMFX::write(cv::InputArray input)
write_one(input); write_one(input);
} }
inline static void to_nv12(cv::InputArray bgr, cv::Mat & Y, cv::Mat & UV)
{
const int height = bgr.rows();
const int width = bgr.cols();
Mat yuv;
cvtColor(bgr, yuv, CV_BGR2YUV_I420);
CV_Assert(yuv.isContinuous());
Mat Y_(Y, Rect(0, 0, width, height));
yuv.rowRange(0, height).copyTo(Y_);
Mat UV_planar(height, width / 2, CV_8UC1, yuv.ptr(height));
Mat u_and_v[2] = {
UV_planar.rowRange(0, height / 2),
UV_planar.rowRange(height / 2, height),
};
Mat uv;
cv::merge(u_and_v, 2, uv);
Mat UV_(UV, Rect(0, 0, width, height / 2));
uv.reshape(1).copyTo(UV_);
}
bool VideoWriter_IntelMFX::write_one(cv::InputArray bgr) bool VideoWriter_IntelMFX::write_one(cv::InputArray bgr)
{ {
mfxStatus res; mfxStatus res;
...@@ -209,13 +190,11 @@ bool VideoWriter_IntelMFX::write_one(cv::InputArray bgr) ...@@ -209,13 +190,11 @@ bool VideoWriter_IntelMFX::write_one(cv::InputArray bgr)
MSG(cerr << "MFX: Failed to get free surface" << endl); MSG(cerr << "MFX: Failed to get free surface" << endl);
return false; return false;
} }
const int rows = workSurface->Info.Height; Mat src = bgr.getMat();
const int cols = workSurface->Info.Width; hal::cvtBGRtoTwoPlaneYUV(src.data, src.step,
Mat Y(rows, cols, CV_8UC1, workSurface->Data.Y, workSurface->Data.Pitch); workSurface->Data.Y, workSurface->Data.UV, workSurface->Data.Pitch,
Mat UV(rows / 2, cols, CV_8UC1, workSurface->Data.UV, workSurface->Data.Pitch); workSurface->Info.CropW, workSurface->Info.CropH,
to_nv12(bgr, Y, UV); 3, false, 1);
CV_Assert(Y.ptr() == workSurface->Data.Y);
CV_Assert(UV.ptr() == workSurface->Data.UV);
} }
while (true) while (true)
......
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