From 8f50a6d1b95bda708260435d3c44b1bdebf7499a Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Sun, 23 Mar 2014 18:01:08 +0000 Subject: [PATCH] Use struture Pixel to define pixel values --- source/PlaYUVerFrame.cpp | 69 +++++++++++++++++++++++++++++++++++++++- source/PlaYUVerFrame.h | 2 ++ source/TypeDef.h | 32 ++++++++++++++++--- source/plaYUVerApp.cpp | 8 ++--- 4 files changed, 101 insertions(+), 10 deletions(-) diff --git a/source/PlaYUVerFrame.cpp b/source/PlaYUVerFrame.cpp index 53b0940..79d526d 100755 --- a/source/PlaYUVerFrame.cpp +++ b/source/PlaYUVerFrame.cpp @@ -85,7 +85,9 @@ PlaYUVerFrame::~PlaYUVerFrame() free_mem3Dpel( m_pppcRGBPel ); } -static inline void yuvToRgb( int iY, int iU, int iV, int &iR, int &iG, int &iB ) + +template +Void yuvToRgb( T iY, T iU, T iV, T &iR, T &iG, T &iB ) { iR = iY + 1402 * iV / 1000; iG = iY - ( 101004 * iU + 209599 * iV ) / 293500; @@ -106,6 +108,14 @@ static inline void yuvToRgb( int iY, int iU, int iV, int &iR, int &iG, int &iB ) iB = 255; } +template +Void rgbToyuv( T iR, T iG, T iB, T &iY, T &iU, T &iV ) +{ + iY = 0; + iU = 0; + iV = 0; +} + Void PlaYUVerFrame::YUV420toRGB() { Int iY, iU, iV, iR, iG, iB; @@ -253,6 +263,63 @@ UInt64 PlaYUVerFrame::getBytesPerFrame() return 0; } +Pixel PlaYUVerFrame::ConvertPixel( Pixel sInputPixel, ColorSpace eOutputSpace ) +{ + Pixel sOutputPixel = {COLOR_INVALID,0,0,0}; + + if( sInputPixel.color_space == eOutputSpace ) + return sInputPixel; + + if( eOutputSpace == COLOR_RGB ) + { + yuvToRgb( sInputPixel.Luma, sInputPixel.ChromaU, sInputPixel.ChromaU, + sOutputPixel.ColorR, sOutputPixel.ColorG, sOutputPixel.ColorB ); + } + if( eOutputSpace == COLOR_YUV ) + { + rgbToyuv( sInputPixel.ColorR, sInputPixel.ColorG, sInputPixel.ColorB, + sOutputPixel.Luma, sOutputPixel.ChromaU, sOutputPixel.ChromaU ); + } + return sOutputPixel; +} + + +Pixel PlaYUVerFrame::getPixelValue(const QPoint &pos, ColorSpace space) +{ + Pixel pixel_value; + switch( m_iPixelFormat ) + { + case YUV420: + pixel_value.color_space = COLOR_YUV; + pixel_value.Luma = m_pppcInputPel[LUMA][pos.y()][pos.x()]; + pixel_value.ChromaU = m_pppcInputPel[CHROMA_U][pos.y()>>1][pos.x()>>1]; + pixel_value.ChromaV = m_pppcInputPel[CHROMA_V][pos.y()>>1][pos.x()>>1]; + break; + case YUV422: + pixel_value.color_space = COLOR_YUV; + pixel_value.Luma = m_pppcInputPel[LUMA][pos.y()][pos.x()]; + pixel_value.ChromaU = m_pppcInputPel[CHROMA_U][pos.y()][pos.x()>>1]; + pixel_value.ChromaV = m_pppcInputPel[CHROMA_V][pos.y()][pos.x()>>1]; + break; + case YUV400: + pixel_value.color_space = COLOR_YUV; + pixel_value.Luma = m_pppcInputPel[LUMA][pos.y()][pos.x()]; + pixel_value.ChromaU = 0; + pixel_value.ChromaV = 0; + break; + case RGB: + pixel_value.color_space = COLOR_RGB; + pixel_value.ColorR = m_pppcInputPel[COLOR_R][pos.y()][pos.x()]; + pixel_value.ColorG = m_pppcInputPel[COLOR_G][pos.y()][pos.x()]; + pixel_value.ColorB = m_pppcInputPel[COLOR_B][pos.y()][pos.x()]; + break; + default: + break; + } + ConvertPixel( pixel_value, space ); + return pixel_value; +} + Pel PlaYUVerFrame::getPixelValueFromYUV(const QPoint &pos, YUVcomponent color) { return m_pppcInputPel[color][0][pos.y()*m_uiWidth+pos.x()]; diff --git a/source/PlaYUVerFrame.h b/source/PlaYUVerFrame.h index 437c0d6..edfba71 100755 --- a/source/PlaYUVerFrame.h +++ b/source/PlaYUVerFrame.h @@ -63,6 +63,8 @@ public: } Pel getPixelValueFromYUV(const QPoint &pos, YUVcomponent color); + Pixel ConvertPixel( Pixel sInputPixel, ColorSpace eOutputSpace ); + Pixel getPixelValue(const QPoint &pos, ColorSpace color); QImage getQimage(); diff --git a/source/TypeDef.h b/source/TypeDef.h index 152a043..5c76860 100644 --- a/source/TypeDef.h +++ b/source/TypeDef.h @@ -115,6 +115,14 @@ enum InputStreamColorSpace NO_FMT = -1, YUV420, YUV400, YUV422, RGB, }; +enum ColorSpace +{ + COLOR_INVALID = -1, + COLOR_YUV = 0, + COLOR_RGB, +}; + + enum YUVcomponent { LUMA = 0, @@ -129,10 +137,26 @@ enum RGBcomponent COLOR_B, }; +typedef struct __pixel_definition +{ + ColorSpace color_space; + union + { + Pel Luma; + Pel ColorR; + }; + union + { + Pel ChromaU; + Pel ColorG; + }; + union + { + Pel ChromaV; + Pel ColorB; + }; +}Pixel; - -} - - +} // NAMESPACE #endif // __TYPEDEF_H__ diff --git a/source/plaYUVerApp.cpp b/source/plaYUVerApp.cpp index fa6cf15..f9fe7b9 100644 --- a/source/plaYUVerApp.cpp +++ b/source/plaYUVerApp.cpp @@ -632,7 +632,7 @@ void plaYUVerApp::setActiveSubWindow( QWidget *window ) void plaYUVerApp::updatePixelValueStatusBar(const QPoint & pos, InputStream* stream) { - Pel luma, chromaU = 0, chromaV = 0; + Pixel sPixelValue; Int iWidth, iHeight; Int posX = pos.x(), posY = pos.y(); QString strPixel; @@ -644,10 +644,8 @@ void plaYUVerApp::updatePixelValueStatusBar(const QPoint & pos, InputStream* str if( (posX=0) && (posY=0) ) { - luma = curFrame->getPixelValueFromYUV(pos, LUMA); - //chromaU = curFrame->getPixelValueFromYUV(pos, CHROMA_U); - //chromaV = curFrame->getPixelValueFromYUV(pos, CHROMA_V); - strPixel = QString("Y: %1 U: %2 V: %3").arg(luma).arg(chromaU).arg(chromaV); + sPixelValue = curFrame->getPixelValue(pos,COLOR_YUV); + strPixel = QString("Y: %1 U: %2 V: %3").arg(sPixelValue.Luma).arg(sPixelValue.ChromaU).arg(sPixelValue.ChromaV); } else {