Change some variable to PlaYUVerStreamHandlerIf and make it friend of PlaYUVerStream
This commit is contained in:
1 parent
51834ae5a7
commit
55ae2a0e7f
9 files changed
+126
-163
No files matched your search
+70
-54
@@ -47,9 +47,9 @@ std::vector<PlaYUVerSupportedFormat> PlaYUVerStream::supportedReadFormats()
|
||||
INI_REGIST_PLAYUVER_SUPPORTED_FMT;
|
||||
REGIST_PLAYUVER_SUPPORTED_FMT( &PlaYUVerRawHandler::Create, "Raw Video", "yuv" );
|
||||
REGIST_PLAYUVER_SUPPORTED_FMT( &PlaYUVerRawHandler::Create, "Raw Video", "gray" );
|
||||
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerPortableMap::Create, "Portable BitMap ", "pbm" );
|
||||
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerPortableMap::Create, "Portable GrayMap ", "pgm" );
|
||||
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerPortableMap::Create, "Portable PixMap ", "ppm" );
|
||||
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerPortableMap::Create, "Portable BitMap ", "pbm" );
|
||||
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerPortableMap::Create, "Portable GrayMap ", "pgm" );
|
||||
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerPortableMap::Create, "Portable PixMap ", "ppm" );
|
||||
#ifdef USE_FFMPEG
|
||||
APPEND_PLAYUVER_SUPPORTED_FMT( StreamHandlerLibav, Read );
|
||||
#endif
|
||||
@@ -127,17 +127,11 @@ PlaYUVerStream::PlaYUVerStream()
|
||||
{
|
||||
m_bInit = false;
|
||||
m_pfctCreateHandler = NULL;
|
||||
m_pcStreamHandler = NULL;
|
||||
m_pcHandler = NULL;
|
||||
m_bIsInput = true;
|
||||
m_bLoadAll = false;
|
||||
m_uiWidth = 0;
|
||||
m_uiHeight = 0;
|
||||
m_uiTotalFrameNum = 0;
|
||||
m_iCurrFrameNum = -1;
|
||||
m_iPixelFormat = -1;
|
||||
m_uiBitsPerPixel = 8;
|
||||
m_iEndianness = -1;
|
||||
m_dFrameRate = 30;
|
||||
m_cFilename = "";
|
||||
m_pcCurrFrame = NULL;
|
||||
m_pcNextFrame = NULL;
|
||||
@@ -154,11 +148,11 @@ PlaYUVerStream::~PlaYUVerStream()
|
||||
|
||||
std::string PlaYUVerStream::getFormatName()
|
||||
{
|
||||
return !m_pcStreamHandler ? "" : m_pcStreamHandler->getFormatName();
|
||||
return !m_pcHandler ? "" : m_pcHandler->getFormatName();
|
||||
}
|
||||
std::string PlaYUVerStream::getCodecName()
|
||||
{
|
||||
return !m_pcStreamHandler ? "" : m_pcStreamHandler->getCodecName();
|
||||
return !m_pcHandler ? "" : m_pcHandler->getCodecName();
|
||||
}
|
||||
|
||||
Bool PlaYUVerStream::open( std::string filename, std::string resolution, std::string input_format_name, UInt bitsPel, Int endianness, UInt frame_rate, Bool bInput )
|
||||
@@ -194,13 +188,6 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in
|
||||
}
|
||||
m_bInit = false;
|
||||
m_bIsInput = bInput;
|
||||
m_cFilename = filename;
|
||||
m_uiWidth = width;
|
||||
m_uiHeight = height;
|
||||
m_iPixelFormat = input_format;
|
||||
m_uiBitsPerPixel = bitsPel;
|
||||
m_iEndianness = endianness;
|
||||
m_dFrameRate = frame_rate;
|
||||
|
||||
m_pfctCreateHandler = PlaYUVerStream::findStreamHandler( filename, m_bIsInput );
|
||||
if( !m_pfctCreateHandler )
|
||||
@@ -209,23 +196,34 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in
|
||||
throw "[PlaYUVerStream] Invalid handler";
|
||||
}
|
||||
|
||||
m_pcStreamHandler = m_pfctCreateHandler();
|
||||
m_pcHandler = m_pfctCreateHandler();
|
||||
|
||||
if( !m_pcStreamHandler )
|
||||
if( !m_pcHandler )
|
||||
{
|
||||
close();
|
||||
throw "[PlaYUVerStream] Invalid handler";
|
||||
}
|
||||
|
||||
if( !m_pcStreamHandler->openHandler( m_cFilename, m_bIsInput ) )
|
||||
m_cFilename = filename;
|
||||
|
||||
m_pcHandler->m_cFilename = filename;
|
||||
m_pcHandler->m_uiWidth = width;
|
||||
m_pcHandler->m_uiHeight = height;
|
||||
m_pcHandler->m_iPixelFormat = input_format;
|
||||
m_pcHandler->m_uiBitsPerPixel = bitsPel;
|
||||
m_pcHandler->m_iEndianness = endianness;
|
||||
m_pcHandler->m_dFrameRate = frame_rate;
|
||||
|
||||
|
||||
if( !m_pcHandler->openHandler( m_cFilename, m_bIsInput ) )
|
||||
{
|
||||
close();
|
||||
throw "[PlaYUVerStream] Cannot open file";
|
||||
return m_bInit;
|
||||
}
|
||||
m_pcStreamHandler->getFormat( m_uiWidth, m_uiHeight, m_iPixelFormat, m_uiBitsPerPixel, m_iEndianness, m_dFrameRate );
|
||||
|
||||
if( m_uiWidth <= 0 || m_uiHeight <= 0 || m_iPixelFormat < 0 )
|
||||
|
||||
if( m_pcHandler->m_uiWidth <= 0 || m_pcHandler->m_uiHeight <= 0 || m_pcHandler->m_iPixelFormat < 0 )
|
||||
{
|
||||
close();
|
||||
throw "[PlaYUVerStream] Incorrect configuration";
|
||||
@@ -239,7 +237,7 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in
|
||||
{
|
||||
try
|
||||
{
|
||||
m_ppcFrameBuffer[i] = new PlaYUVerFrame( m_uiWidth, m_uiHeight, m_iPixelFormat, m_uiBitsPerPixel, m_iEndianness );
|
||||
m_ppcFrameBuffer[i] = new PlaYUVerFrame( m_pcHandler->m_uiWidth, m_pcHandler->m_uiHeight, m_pcHandler->m_iPixelFormat, m_pcHandler->m_uiBitsPerPixel, m_pcHandler->m_iEndianness );
|
||||
}
|
||||
catch( const char *msg )
|
||||
{
|
||||
@@ -251,11 +249,11 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in
|
||||
m_uiFrameBufferIndex = 0;
|
||||
m_pcCurrFrame = m_ppcFrameBuffer[m_uiFrameBufferIndex];
|
||||
|
||||
m_pcStreamHandler->setBytesPerFrame( m_pcCurrFrame->getBytesPerFrame() );
|
||||
m_pcHandler->setBytesPerFrame( m_pcCurrFrame->getBytesPerFrame() );
|
||||
|
||||
if( m_bIsInput )
|
||||
{
|
||||
m_uiTotalFrameNum = m_pcStreamHandler->calculateFrameNumber();
|
||||
m_uiTotalFrameNum = m_pcHandler->calculateFrameNumber();
|
||||
}
|
||||
|
||||
if( m_bIsInput && m_uiTotalFrameNum <= 0 )
|
||||
@@ -265,21 +263,13 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in
|
||||
return m_bInit;
|
||||
}
|
||||
|
||||
if( !m_pcStreamHandler->configureBuffer( m_pcCurrFrame ) )
|
||||
if( !m_pcHandler->configureBuffer( m_pcCurrFrame ) )
|
||||
{
|
||||
close();
|
||||
throw "[PlaYUVerStream] Cannot allocated memory";
|
||||
return m_bInit;
|
||||
}
|
||||
|
||||
if( m_pcCurrFrame )
|
||||
{
|
||||
m_uiWidth = m_pcCurrFrame->getWidth();
|
||||
m_uiHeight = m_pcCurrFrame->getHeight();
|
||||
m_iPixelFormat = m_pcCurrFrame->getPelFormat();
|
||||
m_uiBitsPerPixel = m_pcCurrFrame->getBitsPel();
|
||||
}
|
||||
|
||||
m_iCurrFrameNum = -1;
|
||||
m_bInit = true;
|
||||
|
||||
@@ -291,17 +281,16 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in
|
||||
|
||||
Bool PlaYUVerStream::reload()
|
||||
{
|
||||
m_pcStreamHandler->setBytesPerFrame( m_pcCurrFrame->getBytesPerFrame() );
|
||||
|
||||
m_pcStreamHandler->closeHandler();
|
||||
if( !m_pcStreamHandler->openHandler( m_cFilename, m_bIsInput ) )
|
||||
m_pcHandler->closeHandler();
|
||||
if( !m_pcHandler->openHandler( m_cFilename, m_bIsInput ) )
|
||||
{
|
||||
throw "[PlaYUVerStream] Cannot open file using FFmpeg libs";
|
||||
}
|
||||
m_uiTotalFrameNum = m_pcStreamHandler->calculateFrameNumber();
|
||||
m_pcHandler->setBytesPerFrame( m_pcCurrFrame->getBytesPerFrame() );
|
||||
m_uiTotalFrameNum = m_pcHandler->calculateFrameNumber();
|
||||
|
||||
|
||||
if( m_uiWidth <= 0 || m_uiHeight <= 0 || m_iPixelFormat < 0 || m_uiTotalFrameNum < 1 )
|
||||
if( m_pcHandler->m_uiWidth <= 0 || m_pcHandler->m_uiHeight <= 0
|
||||
|| m_pcHandler->m_iPixelFormat < 0 || m_pcHandler->m_uiBitsPerPixel == 0 || m_uiTotalFrameNum < 1 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -320,7 +309,7 @@ Void PlaYUVerStream::close()
|
||||
if( !m_bInit )
|
||||
return;
|
||||
|
||||
m_pcStreamHandler->closeHandler();
|
||||
m_pcHandler->closeHandler();
|
||||
|
||||
|
||||
|
||||
@@ -340,16 +329,43 @@ Void PlaYUVerStream::close()
|
||||
m_bInit = false;
|
||||
}
|
||||
|
||||
std::string PlaYUVerStream::getFileName()
|
||||
{
|
||||
return m_cFilename;
|
||||
}
|
||||
|
||||
UInt PlaYUVerStream::getFrameNum()
|
||||
{
|
||||
return m_uiTotalFrameNum;
|
||||
}
|
||||
UInt PlaYUVerStream::getWidth() const
|
||||
{
|
||||
return m_pcHandler->m_uiWidth;
|
||||
}
|
||||
UInt PlaYUVerStream::getHeight() const
|
||||
{
|
||||
return m_pcHandler->m_uiHeight;
|
||||
}
|
||||
Double PlaYUVerStream::getFrameRate()
|
||||
{
|
||||
return m_pcHandler->m_dFrameRate;
|
||||
}
|
||||
|
||||
Int PlaYUVerStream::getCurrFrameNum()
|
||||
{
|
||||
return m_iCurrFrameNum;
|
||||
}
|
||||
|
||||
Void PlaYUVerStream::getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rBitsPerPel, Int& rEndianness, UInt& rFrameRate )
|
||||
{
|
||||
if( m_bInit )
|
||||
{
|
||||
rWidth = m_uiWidth;
|
||||
rHeight = m_uiHeight;
|
||||
rInputFormat = m_iPixelFormat;
|
||||
rBitsPerPel = m_uiBitsPerPixel;
|
||||
rEndianness = m_iEndianness;
|
||||
rFrameRate = m_dFrameRate;
|
||||
rWidth = m_pcHandler->m_uiWidth;
|
||||
rHeight = m_pcHandler->m_uiHeight;
|
||||
rInputFormat = m_pcHandler->m_iPixelFormat;
|
||||
rBitsPerPel = m_pcHandler->m_uiBitsPerPixel;
|
||||
rEndianness = m_pcHandler->m_iEndianness;
|
||||
rFrameRate = m_pcHandler->m_dFrameRate;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -382,7 +398,7 @@ Void PlaYUVerStream::loadAll()
|
||||
getMem1D<PlaYUVerFrame*>( &m_ppcFrameBuffer, m_uiFrameBufferSize );
|
||||
for( UInt i = 0; i < m_uiFrameBufferSize; i++ )
|
||||
{
|
||||
m_ppcFrameBuffer[i] = new PlaYUVerFrame( m_uiWidth, m_uiHeight, m_iPixelFormat, m_uiBitsPerPixel );
|
||||
m_ppcFrameBuffer[i] = new PlaYUVerFrame( m_pcHandler->m_uiWidth, m_pcHandler->m_uiHeight, m_pcHandler->m_iPixelFormat, m_pcHandler->m_uiBitsPerPixel );
|
||||
if( !m_ppcFrameBuffer[i] )
|
||||
{
|
||||
close();
|
||||
@@ -446,7 +462,7 @@ Void PlaYUVerStream::readFrame()
|
||||
return;
|
||||
}
|
||||
|
||||
if( !m_pcStreamHandler->read( m_pcNextFrame ) )
|
||||
if( !m_pcHandler->read( m_pcNextFrame ) )
|
||||
{
|
||||
throw "[PlaYUVerStream] Cannot read file";
|
||||
return;
|
||||
@@ -463,7 +479,7 @@ Void PlaYUVerStream::writeFrame()
|
||||
|
||||
Void PlaYUVerStream::writeFrame( PlaYUVerFrame *pcFrame )
|
||||
{
|
||||
if( !m_pcStreamHandler->write( pcFrame ) )
|
||||
if( !m_pcHandler->write( pcFrame ) )
|
||||
{
|
||||
throw "[PlaYUVerStream] Cannot write into the file";
|
||||
}
|
||||
@@ -568,7 +584,7 @@ Bool PlaYUVerStream::seekInput( UInt64 new_frame_num )
|
||||
return true;
|
||||
}
|
||||
|
||||
if( !m_pcStreamHandler->seek( new_frame_num ) )
|
||||
if( !m_pcHandler->seek( new_frame_num ) )
|
||||
{
|
||||
throw "[PlaYUVerStream] Cannot write into the file";
|
||||
}
|
||||
|
||||
+7
-33
@@ -107,11 +107,15 @@ public:
|
||||
|
||||
Bool open( std::string filename, std::string resolution, std::string input_format, UInt bitsPel, Int endianness, UInt frame_rate, Bool bInput = true );
|
||||
Bool open( std::string filename, UInt width, UInt height, Int input_format, UInt bitsPel, Int endianness, UInt frame_rate, Bool bInput = true );
|
||||
|
||||
Bool reload();
|
||||
|
||||
Void close();
|
||||
|
||||
std::string getFileName();
|
||||
UInt getFrameNum();
|
||||
UInt getWidth() const;
|
||||
UInt getHeight() const;
|
||||
Int getCurrFrameNum();
|
||||
Double getFrameRate();
|
||||
Void getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rBitsPerPel, Int& rEndianness, UInt& rFrameRate );
|
||||
|
||||
Void loadAll();
|
||||
@@ -137,47 +141,17 @@ public:
|
||||
return m_bInit;
|
||||
}
|
||||
|
||||
std::string getFileName()
|
||||
{
|
||||
return m_cFilename;
|
||||
}
|
||||
|
||||
UInt getFrameNum()
|
||||
{
|
||||
return m_uiTotalFrameNum;
|
||||
}
|
||||
UInt getWidth() const
|
||||
{
|
||||
return m_uiWidth;
|
||||
}
|
||||
UInt getHeight() const
|
||||
{
|
||||
return m_uiHeight;
|
||||
}
|
||||
Int getCurrFrameNum()
|
||||
{
|
||||
return m_iCurrFrameNum;
|
||||
}
|
||||
Double getFrameRate()
|
||||
{
|
||||
return m_dFrameRate;
|
||||
}
|
||||
Void getDuration( Int* duration_array );
|
||||
|
||||
private:
|
||||
|
||||
Bool m_bInit;
|
||||
CreateStreamHandlerFn m_pfctCreateHandler;
|
||||
PlaYUVerStreamHandlerIf* m_pcStreamHandler;
|
||||
PlaYUVerStreamHandlerIf* m_pcHandler;
|
||||
|
||||
Bool m_bIsInput;
|
||||
std::string m_cFilename;
|
||||
UInt m_uiWidth;
|
||||
UInt m_uiHeight;
|
||||
Int m_iPixelFormat;
|
||||
UInt m_uiBitsPerPixel;
|
||||
Int m_iEndianness;
|
||||
Double m_dFrameRate;
|
||||
UInt64 m_uiTotalFrameNum;
|
||||
Int64 m_iCurrFrameNum;
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#define __PLAYUVERSTREAMHANDLERIF_H__
|
||||
|
||||
#include "PlaYUVerDefs.h"
|
||||
#include "PlaYUVerStream.h"
|
||||
#include "PlaYUVerFrame.h"
|
||||
|
||||
namespace plaYUVer
|
||||
@@ -43,10 +44,17 @@ namespace plaYUVer
|
||||
*/
|
||||
class PlaYUVerStreamHandlerIf
|
||||
{
|
||||
friend class PlaYUVerStream;
|
||||
public:
|
||||
PlaYUVerStreamHandlerIf()
|
||||
{
|
||||
m_bIsInput = true;
|
||||
m_uiWidth = 0;
|
||||
m_uiHeight = 0;
|
||||
m_iPixelFormat = -1;
|
||||
m_uiBitsPerPixel = 8;
|
||||
m_iEndianness = -1;
|
||||
m_dFrameRate = 30;
|
||||
}
|
||||
virtual ~PlaYUVerStreamHandlerIf()
|
||||
{
|
||||
@@ -60,10 +68,6 @@ public:
|
||||
virtual Bool read( PlaYUVerFrame* pcFrame ) = 0;
|
||||
virtual Bool write( PlaYUVerFrame* pcFrame ) = 0;
|
||||
|
||||
virtual Void getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rBitsPerPel, Int& rEndianness, Double& rFrameRate )
|
||||
{
|
||||
return;
|
||||
}
|
||||
Void setBytesPerFrame( UInt64 uiNBytes )
|
||||
{
|
||||
m_uiNBytesPerFrame = uiNBytes;
|
||||
@@ -79,6 +83,14 @@ public:
|
||||
|
||||
protected:
|
||||
Bool m_bIsInput;
|
||||
std::string m_cFilename;
|
||||
UInt m_uiWidth;
|
||||
UInt m_uiHeight;
|
||||
Int m_iPixelFormat;
|
||||
UInt m_uiBitsPerPixel;
|
||||
Int m_iEndianness;
|
||||
Double m_dFrameRate;
|
||||
|
||||
Byte* m_pStreamBuffer;
|
||||
UInt64 m_uiNBytesPerFrame;
|
||||
std::string m_strFormatName;
|
||||
|
||||
@@ -278,17 +278,6 @@ Bool StreamHandlerLibav::configureBuffer( PlaYUVerFrame* pcFrame )
|
||||
}
|
||||
|
||||
|
||||
Void StreamHandlerLibav::getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rBitsPerPel, Int& rEndianness, Double& rFrameRate )
|
||||
{
|
||||
rWidth = m_uiWidth;
|
||||
rHeight = m_uiHeight;
|
||||
rInputFormat = m_iPixelFormat;
|
||||
rBitsPerPel = m_uiBitsPerPixel;
|
||||
rEndianness = m_iEndianness;
|
||||
rFrameRate = m_dFrameRate;
|
||||
}
|
||||
|
||||
|
||||
UInt64 StreamHandlerLibav::calculateFrameNumber()
|
||||
{
|
||||
UInt64 num_frames;
|
||||
|
||||
@@ -78,8 +78,6 @@ public:
|
||||
Bool read( PlaYUVerFrame* pcFrame );
|
||||
Bool write( PlaYUVerFrame* pcFrame );
|
||||
|
||||
Void getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rBitsPerPel, Int& rEndianness, Double& rFrameRate );
|
||||
|
||||
UInt getStreamDuration()
|
||||
{
|
||||
return m_uiSecs;
|
||||
@@ -90,13 +88,6 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
UInt m_uiWidth;
|
||||
UInt m_uiHeight;
|
||||
Int m_iPixelFormat;
|
||||
UInt m_uiBitsPerPixel;
|
||||
Int m_iEndianness;
|
||||
Double m_dFrameRate;
|
||||
|
||||
AVFormatContext* m_cFmtCtx;
|
||||
AVCodecContext* m_cCodecCtx;
|
||||
AVStream* m_cStream;
|
||||
@@ -106,8 +97,6 @@ private:
|
||||
|
||||
Bool m_bHasStream;
|
||||
|
||||
Char m_acFormatName[20];
|
||||
Char m_acCodecName[20];
|
||||
UInt64 m_uiSecs;
|
||||
UInt64 m_uiMicroSec;
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ std::vector<PlaYUVerSupportedFormat> StreamHandlerOpenCV::supportedWriteFormats(
|
||||
Bool StreamHandlerOpenCV::openHandler( std::string strFilename, Bool bInput )
|
||||
{
|
||||
m_cFilename = strFilename;
|
||||
m_dFrameRate = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -65,18 +66,6 @@ Bool StreamHandlerOpenCV::configureBuffer( PlaYUVerFrame* pcFrame )
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Void StreamHandlerOpenCV::getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rBitsPerPel, Int& rEndianness, Double& rFrameRate )
|
||||
{
|
||||
// rWidth = m_uiWidth;
|
||||
// rHeight = m_uiHeight;
|
||||
// rInputFormat = m_iPixelFormat;
|
||||
// rBitsPerPel = m_uiBitsPerPixel;
|
||||
// rEndianness = m_iEndianness;
|
||||
rFrameRate = 1;
|
||||
}
|
||||
|
||||
|
||||
UInt64 StreamHandlerOpenCV::calculateFrameNumber()
|
||||
{
|
||||
return 1;
|
||||
|
||||
@@ -63,10 +63,6 @@ public:
|
||||
Bool read( PlaYUVerFrame* pcFrame );
|
||||
Bool write( PlaYUVerFrame* pcFrame );
|
||||
|
||||
Void getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rBitsPerPel, Int& rEndianness, Double& rFrameRate );
|
||||
|
||||
private:
|
||||
std::string m_cFilename;
|
||||
};
|
||||
|
||||
} // NAMESPACE
|
||||
|
||||
@@ -46,19 +46,10 @@ Bool StreamHandlerPortableMap::openHandler( std::string strFilename, Bool bInput
|
||||
if( m_bIsInput )
|
||||
{
|
||||
char line[101];
|
||||
do
|
||||
{
|
||||
fgets( line, 100, m_pFile );
|
||||
}
|
||||
while( line[0] == '#' );
|
||||
while( fgets( line, 100, m_pFile ) && line[0] == '#' );
|
||||
sscanf( line,"P%d", &m_iMagicNumber );
|
||||
|
||||
do
|
||||
{
|
||||
fgets( line, 100, m_pFile );
|
||||
}
|
||||
while( line[0] == '#' );
|
||||
sscanf( line,"%d %d", &m_iWidth, &m_iHeight );
|
||||
while( fgets( line, 100, m_pFile ) && line[0] == '#' );
|
||||
sscanf( line,"%u %u", &m_uiWidth, &m_uiHeight );
|
||||
|
||||
if( m_iMagicNumber == 1 || m_iMagicNumber == 4 )
|
||||
{
|
||||
@@ -68,17 +59,34 @@ Bool StreamHandlerPortableMap::openHandler( std::string strFilename, Bool bInput
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
fgets( line, 100, m_pFile );
|
||||
}
|
||||
while( line[0] == '#' );
|
||||
while( fgets( line, 100, m_pFile ) && line[0] == '#' );
|
||||
sscanf( line,"%d", &m_iMaxValue );
|
||||
|
||||
m_uiBitsPerPixel = log( m_iMaxValue + 1 )/log( 2 );
|
||||
m_iPixelFormat = m_iMagicNumber == 2 || m_iMagicNumber == 5 ? PlaYUVerFrame::GRAY : PlaYUVerFrame::RGB24;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_iMaxValue = ( 1 << m_uiBitsPerPixel ) - 1;
|
||||
if( m_uiBitsPerPixel == 1 )
|
||||
{
|
||||
m_iMagicNumber = 4;
|
||||
}
|
||||
else if( m_iPixelFormat == PlaYUVerFrame::GRAY )
|
||||
{
|
||||
m_iMagicNumber = 5;
|
||||
}
|
||||
else if( m_iPixelFormat == PlaYUVerFrame::RGB24 )
|
||||
{
|
||||
m_iMagicNumber = 6;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
m_iEndianness = 0;
|
||||
m_dFrameRate = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -91,16 +99,6 @@ Void StreamHandlerPortableMap::closeHandler()
|
||||
freeMem1D( m_pStreamBuffer );
|
||||
}
|
||||
|
||||
Void StreamHandlerPortableMap::getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rBitsPerPel, Int& rEndianness, Double& rFrameRate )
|
||||
{
|
||||
rWidth = m_iWidth;
|
||||
rHeight = m_iHeight;
|
||||
rInputFormat = m_iPixelFormat;
|
||||
rBitsPerPel = m_uiBitsPerPixel;
|
||||
rEndianness = 0;
|
||||
rFrameRate = 1;
|
||||
}
|
||||
|
||||
Bool StreamHandlerPortableMap::configureBuffer( PlaYUVerFrame* pcFrame )
|
||||
{
|
||||
return getMem1D<Byte>( &m_pStreamBuffer, pcFrame->getBytesPerFrame() );
|
||||
@@ -128,6 +126,12 @@ Bool StreamHandlerPortableMap::read( PlaYUVerFrame* pcFrame )
|
||||
|
||||
Bool StreamHandlerPortableMap::write( PlaYUVerFrame* pcFrame )
|
||||
{
|
||||
fseek( m_pFile, 0, SEEK_SET );
|
||||
fprintf( m_pFile, "P%d\n%d %d\n", m_iMagicNumber, m_uiWidth, m_uiHeight );
|
||||
if( m_iMagicNumber > 4 )
|
||||
{
|
||||
fprintf( m_pFile, "%d\n", m_iMaxValue );
|
||||
}
|
||||
pcFrame->frameToBuffer( m_pStreamBuffer );
|
||||
UInt64 processed_bytes = fwrite( m_pStreamBuffer, sizeof( Byte ), m_uiNBytesPerFrame, m_pFile );
|
||||
if( processed_bytes != m_uiNBytesPerFrame )
|
||||
|
||||
@@ -55,16 +55,10 @@ public:
|
||||
Bool read( PlaYUVerFrame* pcFrame );
|
||||
Bool write( PlaYUVerFrame* pcFrame );
|
||||
|
||||
Void getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rBitsPerPel, Int& rEndianness, Double& rFrameRate );
|
||||
|
||||
private:
|
||||
FILE* m_pFile; /**< The input file pointer >*/
|
||||
Int m_iMagicNumber;
|
||||
Int m_iMaxValue;
|
||||
Int m_iWidth;
|
||||
Int m_iHeight;
|
||||
Int m_iPixelFormat;
|
||||
UInt m_uiBitsPerPixel;
|
||||
};
|
||||
|
||||
} // NAMESPACE
|
||||
|
||||
Reference in new issue
Block a user