Add support for portable maps from 1 to 6

This commit is contained in:
jfmcarreira committed 2016-04-02 04:04:19 +01:00
1 parent e9feb12367
commit 51834ae5a7
10 files changed
+120 -126

No files matched your search

+2
View File
@@ -12,6 +12,8 @@ set(PlaYUVer_Lib_SRCS
# PlaYUVerFrameStats.cpp
# Stream
PlaYUVerStream.cpp
StreamHandlerRaw.cpp
StreamHandlerPortableMap.cpp
# Command Parser
PlaYUVerCmdParser.cpp
PlaYUVerProgramOptions.cpp
+4 -19
View File
@@ -30,7 +30,7 @@
#include "PlaYUVerStream.h"
#include "PlaYUVerStreamHandlerIf.h"
#include "StreamHandlerRaw.h"
#include "StreamHandlerPortable.h"
#include "StreamHandlerPortableMap.h"
#ifdef USE_FFMPEG
#include "StreamHandlerLibav.h"
@@ -47,6 +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" );
#ifdef USE_FFMPEG
APPEND_PLAYUVER_SUPPORTED_FMT( StreamHandlerLibav, Read );
#endif
@@ -199,24 +202,6 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in
m_iEndianness = endianness;
m_dFrameRate = frame_rate;
// #ifdef USE_OPENCV
// if( m_iStreamHandler == OPENCV_HANDLER )
// {
// m_pcCurrFrame = LibOpenCVHandler::loadFrame( m_cFilename );
// if( m_pcCurrFrame )
// {
// m_uiWidth = m_pcCurrFrame->getWidth();
// m_uiHeight = m_pcCurrFrame->getHeight();
// m_iPixelFormat = m_pcCurrFrame->getPelFormat();
// }
// m_pcNextFrame = NULL;
// m_uiFrameBufferSize = 0;
// m_uiFrameBufferIndex = 0;
// m_uiTotalFrameNum = 1;
// }
// #endif
m_pfctCreateHandler = PlaYUVerStream::findStreamHandler( filename, m_bIsInput );
if( !m_pfctCreateHandler )
{
+5 -8
View File
@@ -26,7 +26,7 @@
#define __PLAYUVERSTREAMHANDLERIF_H__
#include "PlaYUVerDefs.h"
#include "LibMemory.h"
#include "PlaYUVerFrame.h"
namespace plaYUVer
{
@@ -51,17 +51,14 @@ public:
virtual ~PlaYUVerStreamHandlerIf()
{
}
virtual Bool openHandler( std::string strFilename, Bool bInput ) = 0;
virtual UInt64 calculateFrameNumber() = 0;
virtual Void closeHandler() = 0;
virtual Bool configureBuffer( PlaYUVerFrame* pcFrame ) = 0;
virtual UInt64 calculateFrameNumber() = 0;
virtual Bool seek( UInt64 iFrameNum ) = 0;
virtual Bool read( PlaYUVerFrame* pcFrame ) = 0;
virtual Bool write( PlaYUVerFrame* pcFrame ) = 0;
virtual Bool seek( UInt64 iFrameNum ) = 0;
virtual Bool configureBuffer( PlaYUVerFrame* pcFrame )
{
return getMem1D<Byte>( &m_pStreamBuffer, pcFrame->getBytesPerFrame() );
}
virtual Void getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rBitsPerPel, Int& rEndianness, Double& rFrameRate )
{
+10 -3
View File
@@ -203,9 +203,6 @@ Bool StreamHandlerLibav::openHandler( std::string strFilename, Bool bInput )
m_uiBitsPerPixel = 16;
m_iEndianness = 0;
pix_fmt = AV_PIX_FMT_GRAY8;
case AV_PIX_FMT_PAL8:
pix_fmt = AV_PIX_FMT_GRAY8;
break;
}
m_uiWidth = m_cCodecCtx->width;
@@ -269,8 +266,18 @@ Void StreamHandlerLibav::closeHandler()
av_free( m_cFrame );
}
m_bHasStream = false;
if( m_pStreamBuffer )
freeMem1D( m_pStreamBuffer );
}
Bool StreamHandlerLibav::configureBuffer( PlaYUVerFrame* pcFrame )
{
return getMem1D<Byte>( &m_pStreamBuffer, pcFrame->getBytesPerFrame() );
}
Void StreamHandlerLibav::getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rBitsPerPel, Int& rEndianness, Double& rFrameRate )
{
rWidth = m_uiWidth;
+1
View File
@@ -72,6 +72,7 @@ public:
Bool openHandler( std::string strFilename, Bool bInput );
Void closeHandler();
Bool configureBuffer( PlaYUVerFrame* pcFrame );
UInt64 calculateFrameNumber();
Bool seek( UInt64 iFrameNum );
Bool read( PlaYUVerFrame* pcFrame );
+7
View File
@@ -60,6 +60,12 @@ Void StreamHandlerOpenCV::closeHandler()
}
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;
@@ -70,6 +76,7 @@ Void StreamHandlerOpenCV::getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFor
rFrameRate = 1;
}
UInt64 StreamHandlerOpenCV::calculateFrameNumber()
{
return 1;
+1
View File
@@ -57,6 +57,7 @@ public:
Bool openHandler( std::string strFilename, Bool bInput );
Void closeHandler();
Bool configureBuffer( PlaYUVerFrame* pcFrame );
UInt64 calculateFrameNumber();
Bool seek( UInt64 iFrameNum );
Bool read( PlaYUVerFrame* pcFrame );
+70 -35
View File
@@ -32,47 +32,81 @@
namespace plaYUVer
{
std::vector<PlaYUVerSupportedFormat> StreamHandlerPortableMap::supportedReadFormats()
{
INI_REGIST_PLAYUVER_SUPPORTED_FMT;
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerPortableMap::Create, "Portable Grayscale Map ", "pgm" );
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerPortableMap::Create, "Portable Pix Map ", "ppm" );
END_REGIST_PLAYUVER_SUPPORTED_FMT;
}
std::vector<PlaYUVerSupportedFormat> StreamHandlerPortableMap::supportedWriteFormats()
{
INI_REGIST_PLAYUVER_SUPPORTED_FMT;
// APPEND_PLAYUVER_SUPPORTED_FMT( StreamHandlerPortableMap, Read );
END_REGIST_PLAYUVER_SUPPORTED_FMT;
}
Bool StreamHandlerPortableMap::openHandler( std::string strFilename, Bool bInput )
{
m_cFilename = strFilename;
m_bIsInput = bInput;
m_pFile = NULL;
m_pFile = fopen( strFilename.c_str(), bInput ? "rb" : "wb" );
if( m_pFile == NULL )
{
return false;
}
m_strFormatName = "PGM";
m_strCodecName = "Raw Video";
if( m_bIsInput )
{
char line[101];
do
{
fgets( line, 100, m_pFile );
}
while( 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 );
if( m_iMagicNumber == 1 || m_iMagicNumber == 4 )
{
m_uiBitsPerPixel = 1;
m_iMaxValue = 1;
m_iPixelFormat = PlaYUVerFrame::GRAY;
}
else
{
do
{
fgets( line, 100, m_pFile );
}
while( 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;
}
}
return true;
}
Void StreamHandlerPortableMap::closeHandler()
{
if( m_pFile )
fclose( m_pFile );
}
Bool StreamHandlerPortableMap::configureBuffer( PlaYUVerFrame* pcFrame )
{
return true;
if( m_pStreamBuffer )
freeMem1D( m_pStreamBuffer );
}
Void StreamHandlerPortableMap::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;
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() );
}
UInt64 StreamHandlerPortableMap::calculateFrameNumber()
{
return 1;
@@ -85,19 +119,20 @@ Bool StreamHandlerPortableMap::seek( UInt64 iFrameNum )
Bool StreamHandlerPortableMap::read( PlaYUVerFrame* pcFrame )
{
return false;
UInt64 processed_bytes = fread( m_pStreamBuffer, sizeof( Byte ), m_uiNBytesPerFrame, m_pFile );
if( processed_bytes != m_uiNBytesPerFrame )
return false;
pcFrame->frameFromBuffer( m_pStreamBuffer );
return true;
}
Bool StreamHandlerPortableMap::write( PlaYUVerFrame* pcFrame )
{
Bool bRet = false;
cv::Mat* pcCvFrame = pcFrame->getCvMat();
if( pcCvFrame )
{
bRet = cv::imwrite( m_cFilename.c_str(), *pcCvFrame );
delete pcCvFrame;
}
return bRet;
pcFrame->frameToBuffer( m_pStreamBuffer );
UInt64 processed_bytes = fwrite( m_pStreamBuffer, sizeof( Byte ), m_uiNBytesPerFrame, m_pFile );
if( processed_bytes != m_uiNBytesPerFrame )
return false;
return true;
}
} // NAMESPACE
+7 -5
View File
@@ -44,10 +44,6 @@ class StreamHandlerPortableMap: public PlaYUVerStreamHandlerIf
REGISTER_STREAM_HANDLER( StreamHandlerPortableMap )
public:
static std::vector<PlaYUVerSupportedFormat> supportedReadFormats();
static std::vector<PlaYUVerSupportedFormat> supportedWriteFormats();
StreamHandlerPortableMap() {}
~StreamHandlerPortableMap() {}
@@ -62,7 +58,13 @@ public:
Void getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rBitsPerPel, Int& rEndianness, Double& rFrameRate );
private:
std::string m_cFilename;
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
+13 -56
View File
@@ -18,12 +18,12 @@
*/
/**
* \file PlaYUVerRawHandler.h
* \file StreamHandlerRaw.h
* \brief Abstract class for stream handling
*/
#ifndef __PLAYUVERRAWHANDLER_H__
#define __PLAYUVERRAWHANDLER_H__
#ifndef __STREAMHANDLERRAW_H__
#define __STREAMHANDLERRAW_H__
#include "PlaYUVerDefs.h"
#include "PlaYUVerStreamHandlerIf.h"
@@ -47,62 +47,19 @@ public:
PlaYUVerRawHandler() {}
~PlaYUVerRawHandler() {}
Bool openHandler( std::string strFilename, Bool bInput )
{
m_bIsInput = bInput;
m_pFile = NULL;
m_pFile = fopen( strFilename.c_str(), bInput ? "rb" : "wb" );
if( m_pFile == NULL )
{
return false;
}
m_strFormatName = "YUV";
m_strCodecName = "Raw Video";
return true;
}
Void closeHandler()
{
if( m_pFile )
fclose( m_pFile );
}
UInt64 calculateFrameNumber()
{
if( !m_pFile || m_uiNBytesPerFrame == 0 )
return 0;
fseek( m_pFile, 0, SEEK_END );
UInt64 fileSize = ftell( m_pFile );
fseek( m_pFile, 0, SEEK_SET );
return ( fileSize / m_uiNBytesPerFrame );
}
Bool seek( UInt64 iFrameNum )
{
if( m_bIsInput && m_pFile )
{
fseek( m_pFile, iFrameNum >= 0 ? iFrameNum * m_uiNBytesPerFrame : 0, SEEK_SET );
return true;
}
return false;
}
Bool read( PlaYUVerFrame* pcFrame )
{
UInt64 processed_bytes = fread( m_pStreamBuffer, sizeof( Byte ), m_uiNBytesPerFrame, m_pFile );
if( processed_bytes != m_uiNBytesPerFrame )
return false;
pcFrame->frameFromBuffer( m_pStreamBuffer );
return true;
}
Bool write( PlaYUVerFrame* pcFrame )
{
pcFrame->frameToBuffer( m_pStreamBuffer );
UInt64 processed_bytes = fwrite( m_pStreamBuffer, sizeof( Byte ), m_uiNBytesPerFrame, m_pFile );
if( processed_bytes != m_uiNBytesPerFrame )
return false;
return true;
}
Bool openHandler( std::string strFilename, Bool bInput );
Void closeHandler();
Bool configureBuffer( PlaYUVerFrame* pcFrame );
UInt64 calculateFrameNumber();
Bool seek( UInt64 iFrameNum );
Bool read( PlaYUVerFrame* pcFrame );
Bool write( PlaYUVerFrame* pcFrame );
};
} // NAMESPACE
#endif // __PLAYUVERRAWHANDLER_H__
#endif // __STREAMHANDLERRAW_H__