Fix frameToBuffer when using interleaved formats

This commit is contained in:
2019-03-08 18:16:38 +00:00
parent 75f16c2b34
commit fda7e0f0c6
3 changed files with 26 additions and 12 deletions
+14 -7
View File
@@ -81,6 +81,11 @@ int CalypFrame::findPixelFormat( const ClpString& name )
return -1; return -1;
} }
int CalypFrame::pelformatColorSpace( const int idx )
{
return g_CalypPixFmtDescriptorsMap.at( idx ).colorSpace;
}
struct CalypFramePrivate struct CalypFramePrivate
{ {
public: public:
@@ -346,6 +351,8 @@ bool CalypFrame::haveSameFmt( const CalypFrame& other, unsigned int match ) cons
bRet &= ( getBitsPel() == other.getBitsPel() ); bRet &= ( getBitsPel() == other.getBitsPel() );
if( match & MATCH_COLOR_SPACE_IGNORE_GRAY ) if( match & MATCH_COLOR_SPACE_IGNORE_GRAY )
bRet &= ( getColorSpace() == CLP_COLOR_GRAY || getColorSpace() == other.getColorSpace() ); bRet &= ( getColorSpace() == CLP_COLOR_GRAY || getColorSpace() == other.getColorSpace() );
if( match & MATCH_BYTES_PER_FRAME )
bRet &= ( getBytesPerFrame() == other.getBytesPerFrame() );
return bRet; return bRet;
} }
@@ -423,7 +430,7 @@ unsigned int CalypFrame::getBitsPel() const
return d->m_uiBitsPel; return d->m_uiBitsPel;
} }
ClpULong CalypFrame::getBytesPerFrame() ClpULong CalypFrame::getBytesPerFrame() const
{ {
return getBytesPerFrame( d->m_uiWidth, d->m_uiHeight, d->m_iPixelFormat, d->m_uiBitsPel ); return getBytesPerFrame( d->m_uiWidth, d->m_uiHeight, d->m_iPixelFormat, d->m_uiBitsPel );
} }
@@ -432,10 +439,10 @@ ClpULong CalypFrame::getBytesPerFrame( unsigned int uiWidth, unsigned int uiHeig
{ {
const CalypPixelFormatDescriptor* pcPelFormat = &( g_CalypPixFmtDescriptorsMap.at( iPixelFormat ) ); const CalypPixelFormatDescriptor* pcPelFormat = &( g_CalypPixFmtDescriptorsMap.at( iPixelFormat ) );
unsigned int bytesPerPixel = ( bitsPixel - 1 ) / 8 + 1; unsigned int bytesPerPixel = ( bitsPixel - 1 ) / 8 + 1;
unsigned long long int numberBytes = uiWidth * uiHeight; ClpULong numberBytes = uiWidth * uiHeight;
if( pcPelFormat->numberChannels > 1 ) if( pcPelFormat->numberChannels > 1 )
{ {
unsigned long long int numberBytesChroma = ClpULong numberBytesChroma =
CHROMASHIFT( uiWidth, pcPelFormat->log2ChromaWidth ) * CHROMASHIFT( uiHeight, pcPelFormat->log2ChromaHeight ); CHROMASHIFT( uiWidth, pcPelFormat->log2ChromaWidth ) * CHROMASHIFT( uiHeight, pcPelFormat->log2ChromaHeight );
numberBytes += ( pcPelFormat->numberChannels - 1 ) * numberBytesChroma; numberBytes += ( pcPelFormat->numberChannels - 1 ) * numberBytesChroma;
} }
@@ -524,11 +531,11 @@ void CalypFrame::setPixel( unsigned int xPos, unsigned int yPos, CalypPixel pixe
void CalypFrame::copyFrom( const CalypFrame& other ) void CalypFrame::copyFrom( const CalypFrame& other )
{ {
if( !haveSameFmt( other, MATCH_ALL ) ) if( !haveSameFmt( other, MATCH_COLOR_SPACE | MATCH_BYTES_PER_FRAME | MATCH_BITS ) )
return; return;
d->m_bHasRGBPel = false; d->m_bHasRGBPel = false;
d->m_bHasHistogram = false; d->m_bHasHistogram = false;
memcpy( &( d->m_pppcInputPel[CLP_LUMA][0][0]), &(other.getPelBufferYUV()[CLP_LUMA][0][0]), getTotalNumberOfPixels() * sizeof( ClpPel ) ); memcpy( &( d->m_pppcInputPel[0][0][0]), &(other.getPelBufferYUV()[0][0][0]), getTotalNumberOfPixels() * sizeof( ClpPel ) );
} }
void CalypFrame::copyFrom( const CalypFrame* other ) void CalypFrame::copyFrom( const CalypFrame* other )
@@ -539,7 +546,7 @@ void CalypFrame::copyFrom( const CalypFrame* other )
void CalypFrame::copyFrom( const CalypFrame& other, unsigned int xPos, unsigned int yPos ) void CalypFrame::copyFrom( const CalypFrame& other, unsigned int xPos, unsigned int yPos )
{ {
if( !haveSameFmt( other, MATCH_COLOR_SPACE | MATCH_PEL_FMT | MATCH_BITS ) ) if( !haveSameFmt( other, MATCH_COLOR_SPACE | MATCH_BYTES_PER_FRAME | MATCH_BITS ) )
return; return;
// TODO: Protect width and height // TODO: Protect width and height
ClpPel*** pInput = other.getPelBufferYUV(); ClpPel*** pInput = other.getPelBufferYUV();
@@ -699,7 +706,7 @@ void CalypFrame::frameToBuffer( ClpByte* output_buffer, int iEndianness )
step = ( d->m_pcPelFormat->comp[ch].step_minus1 ) * bytesPixel; step = ( d->m_pcPelFormat->comp[ch].step_minus1 ) * bytesPixel;
pTmpPel = d->m_pppcInputPel[ch][0]; pTmpPel = d->m_pppcInputPel[ch][0];
pTmpBuff = ppBuff[d->m_pcPelFormat->comp[ch].plane]; pTmpBuff = ppBuff[d->m_pcPelFormat->comp[ch].plane] + ( d->m_pcPelFormat->comp[ch].offset_plus1 - 1 ) * bytesPixel;
for( i = 0; i < CHROMASHIFT( d->m_uiHeight, ratioH ) * CHROMASHIFT( d->m_uiWidth, ratioW ); i++ ) for( i = 0; i < CHROMASHIFT( d->m_uiHeight, ratioH ) * CHROMASHIFT( d->m_uiWidth, ratioW ); i++ )
{ {
+3 -1
View File
@@ -100,6 +100,7 @@ public:
static std::vector<ClpString> supportedPixelFormatListNames( int colorSpace ); static std::vector<ClpString> supportedPixelFormatListNames( int colorSpace );
static int numberOfFormats(); static int numberOfFormats();
static int findPixelFormat( const ClpString& name ); static int findPixelFormat( const ClpString& name );
static int pelformatColorSpace( const int idx );
/** /**
* Creates a new frame using the following configuration * Creates a new frame using the following configuration
@@ -145,6 +146,7 @@ public:
MATCH_PEL_FMT = 4, MATCH_PEL_FMT = 4,
MATCH_BITS = 8, MATCH_BITS = 8,
MATCH_COLOR_SPACE_IGNORE_GRAY = 16, MATCH_COLOR_SPACE_IGNORE_GRAY = 16,
MATCH_BYTES_PER_FRAME = 32,
MATCH_ALL = 0xFFFF, MATCH_ALL = 0xFFFF,
}; };
@@ -236,7 +238,7 @@ public:
* Get number of bytes per frame of an existing frame * Get number of bytes per frame of an existing frame
* @return number of bytes per frame * @return number of bytes per frame
*/ */
ClpULong getBytesPerFrame(); ClpULong getBytesPerFrame() const;
/** /**
* Get number of bytes per frame of a specific pixel format * Get number of bytes per frame of a specific pixel format
+9 -4
View File
@@ -86,18 +86,20 @@ bool StreamHandlerPortableMap::openHandler( ClpString strFilename, bool bInput )
} }
else else
{ {
int colorSpace = CalypFrame::pelformatColorSpace( m_iPixelFormat );
m_iMaxValue = ( 1 << m_uiBitsPerPixel ) - 1; m_iMaxValue = ( 1 << m_uiBitsPerPixel ) - 1;
if( m_uiBitsPerPixel == 1 ) if( m_uiBitsPerPixel == 1 )
{ {
m_iMagicNumber = 4; m_iMagicNumber = 4;
} }
else if( m_iPixelFormat == CLP_GRAY ) else if( colorSpace == CLP_COLOR_GRAY )
{ {
m_iMagicNumber = 5; m_iMagicNumber = 5;
} }
else if( m_iPixelFormat == CLP_RGB24 ) else if( colorSpace == CLP_COLOR_RGB )
{ {
m_iMagicNumber = 6; m_iMagicNumber = 6;
m_iPixelFormat = CalypFrame::findPixelFormat("RGB");
} }
else else
{ {
@@ -105,7 +107,7 @@ bool StreamHandlerPortableMap::openHandler( ClpString strFilename, bool bInput )
return false; return false;
} }
} }
m_iEndianness = 0; m_iEndianness = CLP_BIG_ENDIAN;
m_dFrameRate = 1; m_dFrameRate = 1;
m_uiTotalNumberFrames = 1; m_uiTotalNumberFrames = 1;
return true; return true;
@@ -143,13 +145,16 @@ bool StreamHandlerPortableMap::read( CalypFrame* pcFrame )
bool StreamHandlerPortableMap::write( CalypFrame* pcFrame ) bool StreamHandlerPortableMap::write( CalypFrame* pcFrame )
{ {
CalypFrame pcRGBFrame( pcFrame->getWidth(), pcFrame->getHeight(),
m_iPixelFormat, pcFrame->getBitsPel() );
pcRGBFrame.copyFrom( pcFrame );
fseek( m_pFile, 0, SEEK_SET ); fseek( m_pFile, 0, SEEK_SET );
fprintf( m_pFile, "P%d\n%d %d\n", m_iMagicNumber, m_uiWidth, m_uiHeight ); fprintf( m_pFile, "P%d\n%d %d\n", m_iMagicNumber, m_uiWidth, m_uiHeight );
if( m_iMagicNumber > 4 ) if( m_iMagicNumber > 4 )
{ {
fprintf( m_pFile, "%d\n", m_iMaxValue ); fprintf( m_pFile, "%d\n", m_iMaxValue );
} }
pcFrame->frameToBuffer( m_pStreamBuffer, CLP_BIG_ENDIAN ); pcRGBFrame.frameToBuffer( m_pStreamBuffer, m_iEndianness );
unsigned long long int processed_bytes = fwrite( m_pStreamBuffer, sizeof( ClpByte ), m_uiNBytesPerFrame, m_pFile ); unsigned long long int processed_bytes = fwrite( m_pStreamBuffer, sizeof( ClpByte ), m_uiNBytesPerFrame, m_pFile );
if( processed_bytes != m_uiNBytesPerFrame ) if( processed_bytes != m_uiNBytesPerFrame )
return false; return false;