Add support for little and big endian with an option
This commit is contained in:
1 parent
f596fda8dc
commit
b68bbded34
14 files changed
+104
-35
No files matched your search
@@ -112,7 +112,7 @@ Void LibAvContextHandle::closeAvFormat()
|
||||
m_bHasStream = false;
|
||||
}
|
||||
|
||||
Bool LibAvContextHandle::initAvFormat( const char* filename, UInt& width, UInt& height, Int& pixel_format, UInt& bits_pel, Double& frame_rate,
|
||||
Bool LibAvContextHandle::initAvFormat( const char* filename, UInt& width, UInt& height, Int& pixel_format, UInt& endianness, UInt& bits_pel, Double& frame_rate,
|
||||
UInt64& num_frames )
|
||||
{
|
||||
fmt_ctx = NULL;
|
||||
@@ -177,9 +177,9 @@ Bool LibAvContextHandle::initAvFormat( const char* filename, UInt& width, UInt&
|
||||
getMem1D( &m_pchFrameBuffer, m_uiFrameBufferSize );
|
||||
}
|
||||
|
||||
const char *name = avcodec_get_name( video_dec_ctx->codec_id );
|
||||
const char *name = avcodec_get_name( video_dec_ctx->codec_id );
|
||||
sprintf( m_acCodecName, "%s", name );
|
||||
|
||||
|
||||
Double fr = 30;
|
||||
if( video_stream->avg_frame_rate.den && video_stream->avg_frame_rate.num )
|
||||
fr = av_q2d( video_stream->avg_frame_rate );
|
||||
|
||||
@@ -65,7 +65,7 @@ public:
|
||||
m_bHasStream( false )
|
||||
{
|
||||
}
|
||||
Bool initAvFormat( const char* filename, UInt& width, UInt& height, Int& pixel_format, UInt& bits_pel, Double& frame_rate, UInt64& num_frames );
|
||||
Bool initAvFormat( const char* filename, UInt& width, UInt& height, Int& pixel_format, UInt& bits_pel, UInt& endianness, Double& frame_rate, UInt64& num_frames );
|
||||
Void closeAvFormat();
|
||||
Bool decodeAvFormat();
|
||||
|
||||
|
||||
@@ -119,6 +119,7 @@ enum RGBcomponent
|
||||
COLOR_A,
|
||||
};
|
||||
|
||||
|
||||
inline std::string lowercase( const std::string& in )
|
||||
{
|
||||
std::string out;
|
||||
|
||||
+20
-7
@@ -174,7 +174,7 @@ Void PlaYUVerFrame::init( UInt width, UInt height, Int pel_format, Int bitsPixel
|
||||
m_iNumberChannels = 3;
|
||||
m_uiBitsPel = bitsPixel > 8 ? bitsPixel : 8;
|
||||
m_uiHalfPelValue = 1 << ( m_uiBitsPel - 1 );
|
||||
|
||||
|
||||
if( m_uiWidth == 0 || m_uiHeight == 0 || m_iPixelFormat == -1 || bitsPixel > 16 )
|
||||
{
|
||||
throw "Cannot create a PlYUVerFrame of this type";
|
||||
@@ -385,18 +385,30 @@ Void PlaYUVerFrame::copyFrom( PlaYUVerFrame* input_frame, UInt xPos, UInt yPos )
|
||||
m_bHasHistogram = false;
|
||||
}
|
||||
|
||||
Void PlaYUVerFrame::frameFromBuffer( Byte *Buff, UInt64 uiBuffSize )
|
||||
Void PlaYUVerFrame::frameFromBuffer( Byte *Buff, UInt64 uiBuffSize, Int endianess )
|
||||
{
|
||||
if( uiBuffSize != getBytesPerFrame() )
|
||||
return;
|
||||
|
||||
Byte* ppBuff[MAX_NUMBER_PLANES];
|
||||
Byte* pTmpBuff;
|
||||
Pel* pTmpPel;
|
||||
Pel* pPel;
|
||||
UInt bytesPixel = ( m_uiBitsPel - 1 ) / 8 + 1;
|
||||
UInt shiftInput, shiftOutput;
|
||||
Int ratioH, ratioW, step;
|
||||
UInt i, ch, b;
|
||||
|
||||
if( endianess == 1 )
|
||||
{
|
||||
shiftInput = 8;
|
||||
shiftOutput = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
shiftInput = 0;
|
||||
shiftOutput = 8;
|
||||
}
|
||||
|
||||
ppBuff[0] = Buff;
|
||||
for( i = 1; i < MAX_NUMBER_PLANES; i++ )
|
||||
{
|
||||
@@ -411,18 +423,18 @@ Void PlaYUVerFrame::frameFromBuffer( Byte *Buff, UInt64 uiBuffSize )
|
||||
ratioH = ch > 0 ? m_pcPelFormat->log2ChromaHeight : 0;
|
||||
step = m_pcPelFormat->comp[ch].step_minus1 + 1;
|
||||
|
||||
pTmpPel = m_pppcInputPel[ch][0];
|
||||
pPel = m_pppcInputPel[ch][0];
|
||||
pTmpBuff = ppBuff[m_pcPelFormat->comp[ch].plane] + ( m_pcPelFormat->comp[ch].offset_plus1 - 1 );
|
||||
|
||||
for( i = 0; i < CHROMASHIFT( m_uiHeight, ratioH ) * CHROMASHIFT( m_uiWidth, ratioW ); i++ )
|
||||
{
|
||||
*pTmpPel = *pTmpBuff;
|
||||
*pPel = *pTmpBuff;
|
||||
for( b = 1; b < bytesPixel; b++ )
|
||||
{
|
||||
pTmpBuff++;
|
||||
*pTmpPel |= ( *pTmpBuff << ( 8 * b ) );
|
||||
*pPel = ( *pPel << shiftOutput ) + ( *pTmpBuff << shiftInput );
|
||||
}
|
||||
pTmpPel++;
|
||||
pPel++;
|
||||
pTmpBuff += step;
|
||||
}
|
||||
}
|
||||
@@ -1186,3 +1198,4 @@ Double PlaYUVerFrame::getSSIM( PlaYUVerFrame* Org, Int component )
|
||||
}
|
||||
|
||||
} // NAMESPACE
|
||||
|
||||
+1
-1
@@ -211,7 +211,7 @@ public:
|
||||
Void copyFrom( PlaYUVerFrame* );
|
||||
Void copyFrom( PlaYUVerFrame*, UInt, UInt );
|
||||
|
||||
Void frameFromBuffer( Byte*, UInt64 );
|
||||
Void frameFromBuffer( Byte*, UInt64, Int );
|
||||
Void frameToBuffer( Byte* );
|
||||
|
||||
Void fillRGBBuffer();
|
||||
|
||||
@@ -190,7 +190,7 @@ Void PlaYUVerStream::findHandler()
|
||||
}
|
||||
}
|
||||
|
||||
Bool PlaYUVerStream::open( std::string filename, std::string resolution, std::string input_format_name, UInt bitsPel, UInt frame_rate, Bool bInput )
|
||||
Bool PlaYUVerStream::open( std::string filename, std::string resolution, std::string input_format_name, UInt bitsPel, UInt endianness, UInt frame_rate, Bool bInput )
|
||||
{
|
||||
UInt width;
|
||||
UInt height;
|
||||
@@ -212,10 +212,10 @@ Bool PlaYUVerStream::open( std::string filename, std::string resolution, std::st
|
||||
break;
|
||||
}
|
||||
}
|
||||
return open( filename, width, height, input_format, bitsPel, frame_rate, bInput );
|
||||
return open( filename, width, height, input_format, bitsPel, endianness, frame_rate, bInput );
|
||||
}
|
||||
|
||||
Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int input_format, UInt bitsPel, UInt frame_rate, Bool bInput )
|
||||
Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int input_format, UInt bitsPel, UInt endianness, UInt frame_rate, Bool bInput )
|
||||
{
|
||||
if( m_bInit )
|
||||
{
|
||||
@@ -228,6 +228,7 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in
|
||||
m_uiHeight = height;
|
||||
m_iPixelFormat = input_format;
|
||||
m_uiBitsPerPixel = bitsPel;
|
||||
m_uiEndianness = endianness;
|
||||
m_dFrameRate = frame_rate;
|
||||
|
||||
m_pchFilename = new Char[m_cFilename.size() + 1];
|
||||
@@ -247,7 +248,7 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in
|
||||
#ifdef USE_FFMPEG
|
||||
if( m_iStreamHandler == FFMPEG )
|
||||
{
|
||||
if( !m_cLibAvContext->initAvFormat( m_pchFilename, m_uiWidth, m_uiHeight, m_iPixelFormat, m_uiBitsPerPixel, m_dFrameRate, m_uiTotalFrameNum ) )
|
||||
if( !m_cLibAvContext->initAvFormat( m_pchFilename, m_uiWidth, m_uiHeight, m_iPixelFormat, m_uiBitsPerPixel, m_uiEndianness, m_dFrameRate, m_uiTotalFrameNum ) )
|
||||
{
|
||||
throw "Cannot open file using FFmpeg libs";
|
||||
}
|
||||
@@ -370,7 +371,7 @@ Bool PlaYUVerStream::reload()
|
||||
if( m_iStreamHandler == FFMPEG )
|
||||
{
|
||||
m_cLibAvContext->closeAvFormat();
|
||||
if( !m_cLibAvContext->initAvFormat( m_pchFilename, m_uiWidth, m_uiHeight, m_iPixelFormat, m_uiBitsPerPixel, m_dFrameRate, m_uiTotalFrameNum ) )
|
||||
if( !m_cLibAvContext->initAvFormat( m_pchFilename, m_uiWidth, m_uiHeight, m_iPixelFormat, m_uiBitsPerPixel, m_uiEndianness, m_dFrameRate, m_uiTotalFrameNum ) )
|
||||
{
|
||||
throw "Cannot open file using FFmpeg libs";
|
||||
}
|
||||
@@ -578,7 +579,7 @@ Void PlaYUVerStream::readFrame()
|
||||
throw "[PlaYUVerStream] Error reading frame from libav";
|
||||
return;
|
||||
}
|
||||
m_pcNextFrame->frameFromBuffer( m_cLibAvContext->m_pchFrameBuffer, m_cLibAvContext->m_uiFrameBufferSize );
|
||||
m_pcNextFrame->frameFromBuffer( m_cLibAvContext->m_pchFrameBuffer, m_cLibAvContext->m_uiFrameBufferSize, m_uiEndianness );
|
||||
}
|
||||
#endif
|
||||
if( m_iStreamHandler == YUV_IO )
|
||||
@@ -590,7 +591,7 @@ Void PlaYUVerStream::readFrame()
|
||||
throw "[PlaYUVerStream] Cannot read file";
|
||||
return;
|
||||
}
|
||||
m_pcNextFrame->frameFromBuffer( m_pStreamBuffer, bytes_read );
|
||||
m_pcNextFrame->frameFromBuffer( m_pStreamBuffer, bytes_read, m_uiEndianness );
|
||||
}
|
||||
m_uiCurrFrameFileIdx++;
|
||||
return;
|
||||
|
||||
@@ -95,8 +95,8 @@ public:
|
||||
END_OF_SEQ,
|
||||
};
|
||||
|
||||
Bool open( std::string filename, std::string resolution, std::string input_format, UInt bitsPel, UInt frame_rate, Bool bInput = true );
|
||||
Bool open( std::string filename, UInt width, UInt height, Int input_format, UInt bitsPel, UInt frame_rate, Bool bInput = true );
|
||||
Bool open( std::string filename, std::string resolution, std::string input_format, UInt bitsPel, UInt endianness, UInt frame_rate, Bool bInput = true );
|
||||
Bool open( std::string filename, UInt width, UInt height, Int input_format, UInt bitsPel, UInt endianness, UInt frame_rate, Bool bInput = true );
|
||||
|
||||
Bool reload();
|
||||
|
||||
@@ -194,6 +194,7 @@ private:
|
||||
UInt m_uiHeight;
|
||||
Int m_iPixelFormat;
|
||||
UInt m_uiBitsPerPixel;
|
||||
UInt m_uiEndianness;
|
||||
Double m_dFrameRate;
|
||||
UInt64 m_uiTotalFrameNum;
|
||||
Int64 m_iCurrFrameNum;
|
||||
|
||||
Reference in new issue
Block a user