Use struture Pixel to define pixel values

This commit is contained in:
jfmcarreira committed 2014-03-23 18:01:08 +00:00
1 parent a98aa68221
commit 8f50a6d1b9
4 files changed
+101 -10

No files matched your search

+68 -1
View File
@@ -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<typename T>
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<typename T>
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()];
+2
View File
@@ -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();
+28 -4
View File
@@ -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__
+3 -5
View File
@@ -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<iWidth) && (posX>=0) && (posY<iHeight) && (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
{