From d6c17ecabb52c42b4f68d43128b1a343c2e7711b Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Fri, 7 Nov 2014 02:44:08 +0000 Subject: [PATCH] Changes in the PlaYUVerFrame to CvMat conversion --- source/lib/PlaYUVerFrame.cpp | 15 ++++++++------- source/lib/PlaYUVerFrame.h | 16 ++++++++++++++++ source/lib/PlaYUVerFramePixelFormats.cpp | 6 ------ 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/source/lib/PlaYUVerFrame.cpp b/source/lib/PlaYUVerFrame.cpp index 1ddcb69..d88e765 100644 --- a/source/lib/PlaYUVerFrame.cpp +++ b/source/lib/PlaYUVerFrame.cpp @@ -398,7 +398,7 @@ cv::Mat PlaYUVerFrame::getCvMat() case YUV444p: case YUV422p: case YUYV422: - cvType = CV_8UC3; + cvType = CV_8UC4; break; case GRAY: cvType = CV_8UC1; @@ -413,7 +413,7 @@ cv::Mat PlaYUVerFrame::getCvMat() if( m_iPixelFormat != GRAY ) { fillRGBBuffer(); - memcpy( opencvFrame.data, m_pcRGB32, m_uiWidth * m_uiHeight * 3 * sizeof(Pel) ); + memcpy( opencvFrame.data, m_pcRGB32, m_uiWidth * m_uiHeight * 4 * sizeof(UChar) ); } else { @@ -431,7 +431,7 @@ Void PlaYUVerFrame::copyFrom( cv::Mat* opencvFrame ) case 1: m_iPixelFormat = GRAY; break; - case 3: + case 4: m_iPixelFormat = RGB8; break; default: @@ -452,12 +452,13 @@ Void PlaYUVerFrame::copyFrom( cv::Mat* opencvFrame ) Pel* pInputPelU = m_pppcInputPel[CHROMA_U][0]; Pel* pInputPelV = m_pppcInputPel[CHROMA_V][0]; Pel* pcRGBPelInterlaced = m_pcRGB32; - memcpy( pcRGBPelInterlaced, opencvFrame->data, m_uiWidth * m_uiHeight * 3 * sizeof(Pel) ); + memcpy( pcRGBPelInterlaced, opencvFrame->data, m_uiWidth * m_uiHeight * 4 * sizeof(Pel) ); + UInt* buff = (UInt*)pcRGBPelInterlaced; for( UInt i = 0; i < m_uiHeight * m_uiWidth; i++ ) { - *pInputPelY++ = *pcRGBPelInterlaced++; - *pInputPelU++ = *pcRGBPelInterlaced++; - *pInputPelV++ = *pcRGBPelInterlaced++; + *pInputPelY++ = qRed( *buff ); + *pInputPelU++ = qGreen( *buff ); + *pInputPelV++ = qBlue( *buff++ ); } m_bHasRGBPel = true; } diff --git a/source/lib/PlaYUVerFrame.h b/source/lib/PlaYUVerFrame.h index 17f6384..1820d1f 100644 --- a/source/lib/PlaYUVerFrame.h +++ b/source/lib/PlaYUVerFrame.h @@ -91,6 +91,22 @@ Void rgbToYuv( T iR, T iG, T iB, T &iY, T &iU, T &iV ) iV = ( 1000 * ( iR - iY ) + 179456 ) / 1402; } +inline Q_DECL_CONSTEXPR Int qRed(UInt rgb) // get red part of RGB +{ return ((rgb >> 16) & 0xff); } + +inline Q_DECL_CONSTEXPR Int qGreen(UInt rgb) // get green part of RGB +{ return ((rgb >> 8) & 0xff); } + +inline Q_DECL_CONSTEXPR Int qBlue(UInt rgb) // get blue part of RGB +{ return (rgb & 0xff); } + +inline Q_DECL_CONSTEXPR Int qAlpha(UInt rgb) // get alpha part of RGBA +{ return rgb >> 24; } + +inline Q_DECL_CONSTEXPR UInt qRgb(Int r, Int g, Int b) // set RGB value +{ return (0xffu << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); } + + class PlaYUVerFrame { public: diff --git a/source/lib/PlaYUVerFramePixelFormats.cpp b/source/lib/PlaYUVerFramePixelFormats.cpp index 1244ed4..bb69063 100644 --- a/source/lib/PlaYUVerFramePixelFormats.cpp +++ b/source/lib/PlaYUVerFramePixelFormats.cpp @@ -39,12 +39,6 @@ namespace plaYUVer #define ADD_FFMPEG_PEL_FMT( fmt ) 0 #endif -static inline UInt qRgb( Int r, Int g, Int b ) // set RGB value -{ - return ( 0xffu << 24 ) | ( ( r & 0xff ) << 16 ) | ( ( g & 0xff ) << 8 ) | ( b & 0xff ); -} - - /** * YUV Formats * Progressive and interlaces