diff --git a/source/InputStream.cpp b/source/InputStream.cpp index ed088d8..24a115a 100755 --- a/source/InputStream.cpp +++ b/source/InputStream.cpp @@ -47,6 +47,9 @@ InputStream::InputStream() m_iFileFormat = INVALID; + m_cCurrFrame = NULL; + m_pInputBuffer = NULL; + m_cFilename = QString( "" ); m_cStreamInformationString = QString( "" ); } @@ -199,9 +202,12 @@ Void InputStream::close() m_cLibAvContext.closeAvFormat(); #endif - if(m_cCurrFrame) + if( m_cCurrFrame ) delete m_cCurrFrame; + if( m_pInputBuffer ) + free_mem1Dpel( m_pInputBuffer ); + m_iStatus = 0; } diff --git a/source/ModulesHandle.cpp b/source/ModulesHandle.cpp index 45781a8..eb76b9d 100644 --- a/source/ModulesHandle.cpp +++ b/source/ModulesHandle.cpp @@ -29,12 +29,19 @@ namespace plaYUVer { -ModulesHandle::ModulesHandle( QWidget * parent ) +Void ModulesHandle::ModulesList( Bool bCreate ) { // Register Modules REGISTER_MODULE( FilterFrame ); +} + + +ModulesHandle::ModulesHandle( QWidget * parent ) +{ + ModulesList( true ); + // configure class setParent( parent ); m_uiModulesCount = 0; @@ -43,7 +50,6 @@ ModulesHandle::ModulesHandle( QWidget * parent ) ModulesHandle::~ModulesHandle() { - } Void ModulesHandle::appendModule( PlaYUVerModuleIf* pIfModule ) diff --git a/source/ModulesHandle.h b/source/ModulesHandle.h index 9fc5023..cfb703a 100644 --- a/source/ModulesHandle.h +++ b/source/ModulesHandle.h @@ -63,7 +63,7 @@ private: QVector m_arrayModulesActions; Void appendModule( PlaYUVerModuleIf* ); - + Void ModulesList( Bool bCreate ); private Q_SLOTS: void selectModule( int index ); }; 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/PlaYUVerModuleIf.h b/source/PlaYUVerModuleIf.h index 4ed88e6..5806f6c 100644 --- a/source/PlaYUVerModuleIf.h +++ b/source/PlaYUVerModuleIf.h @@ -55,8 +55,11 @@ enum __PlaYUVerModuleRequirements { \ if( USE_##X ) \ { \ - X *pMod = new X(); \ - appendModule( pMod ); \ + if( bCreate ) \ + { \ + X *pMod = new X(); \ + appendModule( pMod ); \ + } \ } \ } 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/modules/FilterFrame.cpp b/source/modules/FilterFrame.cpp index 4bbc853..100b503 100644 --- a/source/modules/FilterFrame.cpp +++ b/source/modules/FilterFrame.cpp @@ -39,14 +39,11 @@ PlaYUVerModuleDefinition FilterFrameDef = { FilterFrame::FilterFrame() { m_cModuleDef = FilterFrameDef; - - m_pcFilteredFrame = NULL; } Void FilterFrame::create( PlaYUVerFrame* InputFrame ) { - if( m_pcFilteredFrame ) - delete m_pcFilteredFrame; + m_pcFilteredFrame = NULL; m_pcFilteredFrame = new PlaYUVerFrame( InputFrame->getWidth(), InputFrame->getHeight(), InputFrame->getPelFormat() ); } diff --git a/source/plaYUVerApp.cpp b/source/plaYUVerApp.cpp index 0835a4e..15c5038 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 {