Improve code

This commit is contained in:
jfmcarreira committed 2014-03-31 16:09:07 +01:00
1 parent 3a02de7641
commit c07bce8d41
3 files changed
+55 -21

No files matched your search

+21 -12
View File
@@ -58,6 +58,7 @@ InputStream::InputStream()
m_pcNextFrame = NULL;
m_ppcFrameBuffer = NULL;
m_uiFrameBufferSize = 2;
m_uiAveragePlayInterval = 0;
}
InputStream::~InputStream()
@@ -193,8 +194,10 @@ Bool InputStream::open( QString filename, UInt width, UInt height, Int input_for
if( m_uiTotalFrameNum > 1 )
readNextFrame();
m_bInit = true;
m_cTimer.start();
m_uiAveragePlayInterval = 0;
m_bInit = true;
return m_bInit;
}
@@ -220,6 +223,8 @@ Void InputStream::close()
if( m_pInputBuffer )
freeMem1D<Pel>( m_pInputBuffer );
qDebug() << "Frame read time: " << QString::number( 1000 / (m_uiAveragePlayInterval+1) ) << " fps";
m_bInit = false;
}
@@ -285,7 +290,7 @@ Bool InputStream::guessFormat( QString filename, UInt& rWidth, UInt& rHeight, In
Void InputStream::readNextFrame()
{
UInt64 bytes_read = 0;
m_cTimer.restart();
if( m_iStatus == 0 )
{
return;
@@ -303,20 +308,24 @@ Void InputStream::readNextFrame()
{
m_cLibAvContext.decodeAvFormat();
m_pcNextFrame->FrameFromBuffer( m_cLibAvContext.video_dst_data[0], m_iPixelFormat );
return;
}
else
#endif
UInt64 frame_bytes_input = m_pcNextFrame->getBytesPerFrame();
bytes_read = fread( m_pInputBuffer, sizeof(Pel), frame_bytes_input, m_pFile );
if( bytes_read != frame_bytes_input )
{
m_iErrorStatus = READING;
qDebug( ) << " Reading error !!!"
<< endl;
return;
UInt64 frame_bytes_input = m_pcNextFrame->getBytesPerFrame();
bytes_read = fread( m_pInputBuffer, sizeof(Pel), frame_bytes_input, m_pFile );
if( bytes_read != frame_bytes_input )
{
m_iErrorStatus = READING;
qDebug( ) << " Reading error !!!"
<< endl;
return;
}
m_pcNextFrame->FrameFromBuffer( m_pInputBuffer, m_iPixelFormat );
}
m_pcNextFrame->FrameFromBuffer( m_pInputBuffer, m_iPixelFormat );
Int time = m_cTimer.elapsed();
m_uiAveragePlayInterval = ( m_uiAveragePlayInterval + time) / 2;
m_pcNextFrame->FrametoRGB8();
return;
}
+3
View File
@@ -71,6 +71,9 @@ private:
QString m_cFormatName;
QString m_cStreamInformationString;
QTime m_cTimer;
UInt m_uiAveragePlayInterval;
FILE* m_pFile; /**< The input file pointer >*/
Int m_iFileFormat;
Int m_iPixelFormat;
+31 -9
View File
@@ -121,6 +121,28 @@ Void yuvToRgb( T iY, T iU, T iV, T &iR, T &iG, T &iB )
iB = 255;
}
static inline Void yuvToRgb( Int iY, Int iU, Int iV, Int &iR, Int &iG, Int &iB )
{
iR = iY + 1402 * iV / 1000;
iG = iY - ( 101004 * iU + 209599 * iV ) / 293500;
iB = iY + 1772 * iU / 1000;
if( iR < 0 )
iR = 0;
if( iG < 0 )
iG = 0;
if( iB < 0 )
iB = 0;
if( iR > 255 )
iR = 255;
if( iG > 255 )
iG = 255;
if( iB > 255 )
iB = 255;
}
template<typename T>
Void rgbToyuv( T iR, T iG, T iB, T &iY, T &iU, T &iV )
{
@@ -191,9 +213,9 @@ Void PlaYUVerFrame::FrametoRGB8()
for( UInt y = 0; y < m_uiHeight; y++ )
for( UInt x = 0; x < m_uiWidth; x++ )
{
*pcRGBPelInterlaced++ = m_pppcRGBPel[COLOR_R][y][x];
*pcRGBPelInterlaced++ = m_pppcRGBPel[COLOR_G][y][x];
*pcRGBPelInterlaced++ = m_pppcRGBPel[COLOR_B][y][x];
*pcRGBPelInterlaced++ = *pRGBPelR++;
*pcRGBPelInterlaced++ = *pRGBPelG++;
*pcRGBPelInterlaced++ = *pRGBPelB++;
}
break;
case YUV422p:
@@ -218,9 +240,9 @@ Void PlaYUVerFrame::FrametoRGB8()
for( UInt y = 0; y < m_uiHeight; y++ )
for( UInt x = 0; x < m_uiWidth; x++ )
{
*pcRGBPelInterlaced++ = m_pppcRGBPel[COLOR_R][y][x];
*pcRGBPelInterlaced++ = m_pppcRGBPel[COLOR_G][y][x];
*pcRGBPelInterlaced++ = m_pppcRGBPel[COLOR_B][y][x];
*pcRGBPelInterlaced++ = *pRGBPelR++;
*pcRGBPelInterlaced++ = *pRGBPelG++;
*pcRGBPelInterlaced++ = *pRGBPelB++;
}
break;
case YUV444p:
@@ -261,9 +283,9 @@ Void PlaYUVerFrame::FrametoRGB8()
for( UInt y = 0; y < m_uiHeight; y++ )
for( UInt x = 0; x < m_uiWidth; x++ )
{
*pcRGBPelInterlaced++ = m_pppcInputPel[COLOR_R][y][x];
*pcRGBPelInterlaced++ = m_pppcInputPel[COLOR_G][y][x];
*pcRGBPelInterlaced++ = m_pppcInputPel[COLOR_B][y][x];
*pcRGBPelInterlaced++ = *pRGBPelR++;
*pcRGBPelInterlaced++ = *pRGBPelG++;
*pcRGBPelInterlaced++ = *pRGBPelB++;
}
break;
default: