Refactor pixel formats enum

This commit is contained in:
2021-10-27 23:07:46 +01:00
parent 90a5c32bb6
commit bb2a1ac228
35 changed files with 289 additions and 277 deletions
+9 -9
View File
@@ -166,7 +166,7 @@ bool VideoStreamSubWindow::loadFile( QString cFilename, bool bForceDialog )
ConfigureFormatDialog formatDialog( this );
unsigned int Width = 0, Height = 0, BitsPel = 8, FrameRate = 30;
int Endianness = CLP_LITTLE_ENDIAN;
int InputFormat = CLP_YUV420P;
auto InputFormat = ClpPixelFormats::CLP_YUV420P;
QSettings appSettings;
if( m_pCurrStream )
@@ -220,7 +220,7 @@ bool VideoStreamSubWindow::loadFile( QString cFilename, bool bForceDialog )
m_sStreamInfo.m_cFilename = cFilename;
m_sStreamInfo.m_uiWidth = Width;
m_sStreamInfo.m_uiHeight = Height;
m_sStreamInfo.m_iPelFormat = InputFormat;
m_sStreamInfo.m_iPelFormat = static_cast<std::int64_t>( InputFormat );
m_sStreamInfo.m_uiBitsPelPixel = BitsPel;
m_sStreamInfo.m_iEndianness = Endianness;
m_sStreamInfo.m_uiFrameRate = FrameRate;
@@ -259,7 +259,7 @@ bool VideoStreamSubWindow::loadFile( CalypFileInfo streamInfo )
m_pCurrStream = m_pcResourceManager->getResourceAsset( m_uiResourceId );
if( !m_pCurrStream->open( streamInfo.m_cFilename.toStdString(), streamInfo.m_uiWidth, streamInfo.m_uiHeight,
streamInfo.m_iPelFormat, streamInfo.m_uiBitsPelPixel, streamInfo.m_iEndianness,
static_cast<ClpPixelFormats>( streamInfo.m_iPelFormat ), streamInfo.m_uiBitsPelPixel, streamInfo.m_iEndianness,
streamInfo.m_uiFrameRate, streamInfo.m_bForceRaw, CalypStream::Type::Input ) )
{
return false;
@@ -281,7 +281,7 @@ bool VideoStreamSubWindow::loadFile( CalypFileInfo streamInfo )
return true;
}
bool VideoStreamSubWindow::guessFormat( const QString& filename, unsigned int& rWidth, unsigned int& rHeight, int& rInputFormat, unsigned int& rBitsPerPixel,
bool VideoStreamSubWindow::guessFormat( const QString& filename, unsigned int& rWidth, unsigned int& rHeight, ClpPixelFormats& rInputFormat, unsigned int& rBitsPerPixel,
int& rEndianness, unsigned int& rFrameRate )
{
std::vector<CalypStandardResolution> stdResList = CalypStream::stdResolutionSizes();
@@ -299,12 +299,12 @@ bool VideoStreamSubWindow::guessFormat( const QString& filename, unsigned int& r
{
bGuessed = false;
// Guess pixel format
auto formats_list = CalypFrame::supportedPixelFormatListNames();
for( std::size_t i = 0; i < formats_list.size(); i++ )
const auto& formats_list = CalypFrame::supportedPixelFormatListNames();
for( const auto& [key, name] : formats_list )
{
if( FilenameShort.contains( formats_list[i].c_str(), Qt::CaseInsensitive ) )
if( FilenameShort.contains( QString::fromStdString( std::string( name ) ), Qt::CaseInsensitive ) )
{
rInputFormat = i;
rInputFormat = key;
break;
}
}
@@ -427,7 +427,7 @@ bool VideoStreamSubWindow::guessFormat( const QString& filename, unsigned int& r
rEndianness = CLP_LITTLE_ENDIAN;
}
if( rWidth > 0 && rHeight > 0 && rInputFormat >= 0 )
if( rWidth > 0 && rHeight > 0 && rInputFormat != ClpPixelFormats::CLP_INVALID_FMT )
bGuessed = true && !bGuessedByFilesize;
}
return !bGuessed;
+1 -1
View File
@@ -107,7 +107,7 @@ public:
private:
bool goToNextFrame( bool bThreaded );
static bool guessFormat( const QString& filename, unsigned int& rWidth, unsigned int& rHeight, int& rInputFormat, unsigned int& rBitsPerPixel,
static bool guessFormat( const QString& filename, unsigned int& rWidth, unsigned int& rHeight, ClpPixelFormats& rInputFormat, unsigned int& rBitsPerPixel,
int& rEndianness, unsigned int& rFrameRate );
private: // NO_LINT
+28 -31
View File
@@ -382,8 +382,28 @@ ConfigureFormatDialog::ConfigureFormatDialog( QWidget* parent )
setFixedSize( MainLayout->sizeHint() );
}
auto findPelFormatColorSpace( ClpPixelFormats rInputFormat ) -> std::pair<int, std::int64_t>
{
if( rInputFormat != ClpPixelFormats::CLP_INVALID_FMT )
{
auto pelFmtName = CalypFrame::pixelFormatName( rInputFormat );
for( unsigned int j = 0; j < CalypFrame::supportedColorSpacesListNames().size(); j++ )
{
const auto& formats_list = CalypFrame::supportedPixelFormatListNames( j );
for( const auto& [key, name] : formats_list )
{
if( pelFmtName == name )
{
return std::make_pair( j, static_cast<int>( key ) );
}
}
}
}
return std::make_pair( 0, 0 );
}
int ConfigureFormatDialog::runConfigureFormatDialog( const QString& Filename, unsigned int& rWidth, unsigned int& rHeight,
int& rInputFormat, unsigned int& rBits, int& rEndianess, unsigned int& rFrameRate )
ClpPixelFormats& rInputFormat, unsigned int& rBits, int& rEndianess, unsigned int& rFrameRate )
{
// Set default values
// setWindowTitle( "Configure resolution for " + Filename );
@@ -391,24 +411,8 @@ int ConfigureFormatDialog::runConfigureFormatDialog( const QString& Filename, un
m_spinBoxWidth->setValue( rWidth );
m_spinBoxheight->setValue( rHeight );
int colorSpace = 0;
int sampling = 0;
if( rInputFormat >= 0 )
{
std::string pelFmtName = CalypFrame::supportedPixelFormatListNames()[rInputFormat];
for( unsigned int j = 0; j < CalypFrame::supportedColorSpacesListNames().size(); j++ )
{
for( unsigned int i = 0; i < CalypFrame::supportedPixelFormatListNames( j ).size(); i++ )
{
if( pelFmtName == CalypFrame::supportedPixelFormatListNames( j )[i] )
{
colorSpace = j;
sampling = i;
break;
}
}
}
}
auto [colorSpace, sampling] = findPelFormatColorSpace( rInputFormat );
m_comboBoxColorSpace->setCurrentIndex( colorSpace );
m_comboBoxPixelFormat->setCurrentIndex( sampling );
m_spinBoxBits->setValue( rBits );
@@ -441,16 +445,8 @@ int ConfigureFormatDialog::runConfigureFormatDialog( const QString& Filename, un
rWidth = m_spinBoxWidth->value();
rHeight = m_spinBoxheight->value();
colorSpace = m_comboBoxColorSpace->currentIndex();
sampling = m_comboBoxPixelFormat->currentIndex();
std::string pelFmtName = CalypFrame::supportedPixelFormatListNames( colorSpace )[sampling];
for( unsigned int i = 0; i < CalypFrame::supportedPixelFormatListNames().size(); i++ )
{
if( pelFmtName == CalypFrame::supportedPixelFormatListNames()[i] )
{
rInputFormat = i;
break;
}
}
sampling = m_comboBoxPixelFormat->currentData().toInt();
rInputFormat = static_cast<ClpPixelFormats>( sampling );
rBits = m_spinBoxBits->value();
rEndianess = m_comboBoxEndianness->currentIndex();
rFrameRate = m_spinBoxFrameRate->value();
@@ -512,9 +508,10 @@ void ConfigureFormatDialog::slotColorSpaceChange( int idx )
return;
m_comboBoxPixelFormat->clear();
for( unsigned int i = 0; i < CalypFrame::supportedPixelFormatListNames( idx ).size(); i++ )
const auto& formats_list = CalypFrame::supportedPixelFormatListNames( idx );
for( const auto& [key, name] : formats_list )
{
m_comboBoxPixelFormat->insertItem( i, CalypFrame::supportedPixelFormatListNames( idx )[i].c_str() );
m_comboBoxPixelFormat->addItem( QString::fromStdString( std::string( name ) ), static_cast<int>( key ) );
}
m_comboBoxPixelFormat->setCurrentIndex( 0 );
}
+1 -1
View File
@@ -51,7 +51,7 @@ class ConfigureFormatDialog : public QDialog
public:
ConfigureFormatDialog( QWidget* parent = 0 );
int runConfigureFormatDialog( const QString& Filename, unsigned int& rWidth, unsigned int& rHeight, int& rInputFormat, unsigned int& rBits,
int runConfigureFormatDialog( const QString& Filename, unsigned int& rWidth, unsigned int& rHeight, ClpPixelFormats& rInputFormat, unsigned int& rBits,
int& rEndianess, unsigned int& rFrameRate );
void readSettings();
@@ -56,7 +56,7 @@ bool AbsoluteFrameDifferenceExample::create( std::vector<CalypFrame*> apcFrameLi
return false;
m_pcFrameDifference =
new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), CLP_GRAY );
new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), ClpPixelFormats::CLP_GRAY );
return true;
}
+1 -1
View File
@@ -47,7 +47,7 @@ FrameBinarizationAPIv1::FrameBinarizationAPIv1()
void FrameBinarizationAPIv1::create( CalypFrame* frame )
{
m_pcBinFrame = NULL;
m_pcBinFrame = new CalypFrame( frame->getWidth(), frame->getHeight(), CLP_GRAY, 8 );
m_pcBinFrame = new CalypFrame( frame->getWidth(), frame->getHeight(), ClpPixelFormats::CLP_GRAY, 8 );
}
CalypFrame* FrameBinarizationAPIv1::process( CalypFrame* frame )
+76 -67
View File
@@ -64,47 +64,68 @@ std::vector<std::string> CalypFrame::supportedColorSpacesListNames()
};
}
std::vector<std::string> CalypFrame::supportedPixelFormatListNames()
constexpr auto CalypFrame::numberOfFormats() -> std::size_t
{
std::vector<std::string> formatsList;
for( int i = 0; i < numberOfFormats(); i++ )
{
formatsList.push_back( g_CalypPixFmtDescriptorsMap.at( i ).name );
}
return formatsList;
return kNumberOfPixelFormats;
}
std::vector<std::string> CalypFrame::supportedPixelFormatListNames( int colorSpace )
auto CalypFrame::findPixelFormat( const std::string& name ) -> std::optional<ClpPixelFormats>
{
std::vector<std::string> formatsList;
for( int i = 0; i < numberOfFormats(); i++ )
for( const auto& [key, fmt] : g_CalypPixFmtDescriptorsMap )
{
if( g_CalypPixFmtDescriptorsMap.at( i ).colorSpace == colorSpace )
formatsList.push_back( g_CalypPixFmtDescriptorsMap.at( i ).name );
if( fmt.name.size() == name.size() &&
std::equal( fmt.name.begin(), fmt.name.end(), name.begin(),
[]( auto a, auto b ) { return std::tolower( a ) == std::tolower( b ); } ) )
return key;
}
return formatsList;
return {};
}
int CalypFrame::numberOfFormats()
auto CalypFrame::findPixelFormat( const std::string_view name ) -> std::optional<ClpPixelFormats>
{
return static_cast<int>( g_CalypPixFmtDescriptorsMap.size() );
for( const auto& [key, fmt] : g_CalypPixFmtDescriptorsMap )
{
if( fmt.name.size() == name.size() &&
std::equal( fmt.name.begin(), fmt.name.end(), name.begin(),
[]( auto a, auto b ) { return std::tolower( a ) == std::tolower( b ); } ) )
return key;
}
return {};
}
int CalypFrame::findPixelFormat( const std::string& name )
{
for( int i = 0; i < numberOfFormats(); i++ )
{
if( g_CalypPixFmtDescriptorsMap.at( i ).name == name )
return i;
}
return -1;
}
int CalypFrame::pelformatColorSpace( const int idx )
auto CalypFrame::pelformatColorSpace( ClpPixelFormats idx ) -> int
{
return g_CalypPixFmtDescriptorsMap.at( idx ).colorSpace;
}
auto CalypFrame::supportedPixelFormatListNames() -> std::map<ClpPixelFormats, std::string_view>
{
std::map<ClpPixelFormats, std::string_view> formatsList;
for( const auto& [key, fmt] : g_CalypPixFmtDescriptorsMap )
{
formatsList[key] = fmt.name;
}
return formatsList;
}
auto CalypFrame::supportedPixelFormatListNames( int colorSpace ) -> std::map<ClpPixelFormats, std::string_view>
{
std::map<ClpPixelFormats, std::string_view> formatsList;
for( const auto& [key, fmt] : g_CalypPixFmtDescriptorsMap )
{
if( fmt.colorSpace == colorSpace )
{
formatsList[key] = fmt.name;
}
}
return formatsList;
}
auto CalypFrame::pixelFormatName( ClpPixelFormats idx ) -> const std::string_view
{
return g_CalypPixFmtDescriptorsMap.at( idx ).name;
}
class CalypFrame::CalypFramePrivate
{
public:
@@ -112,11 +133,10 @@ public:
//! Struct with the pixel format description.
const CalypPixelFormatDescriptor* m_pcPelFormat{ nullptr };
std::string m_cPelFmtName;
unsigned int m_uiWidth{ 0 }; //!< Width of the frame
unsigned int m_uiHeight{ 0 }; //!< Height of the frame
int m_iPixelFormat{ 0 }; //!< Pixel format number (it follows the list of supported pixel formats)
ClpPixelFormats m_iPixelFormat{ ClpPixelFormats::CLP_INVALID_FMT }; //!< Pixel format number (it follows the list of supported pixel formats)
unsigned int m_uiBitsPel{ 0 }; //!< Bits per pixel/channel
unsigned int m_uiHalfPelValue{ 0 }; //!< Bits per pixel/channel
bool m_bHasNegativeValues{ false }; //!< Half of the scale correspond to negative values
@@ -142,26 +162,26 @@ public:
CalypFramePrivate& operator=( const CalypFramePrivate& ) = delete;
CalypFramePrivate& operator=( CalypFramePrivate&& ) = delete;
void init( unsigned int width, unsigned int height, int pel_format, unsigned bitsPixel )
void init( unsigned int width, unsigned int height, ClpPixelFormats pelFormat, unsigned bitsPixel )
{
init( width, height, pel_format, bitsPixel, false );
init( width, height, pelFormat, bitsPixel, false );
}
void init( unsigned int width, unsigned int height, int pel_format, unsigned bitsPixel, bool has_negative_values )
void init( unsigned int width, unsigned int height, ClpPixelFormats pelFormat, unsigned bitsPixel, bool has_negative_values )
{
m_uiWidth = width;
m_uiHeight = height;
m_iPixelFormat = pel_format;
m_iPixelFormat = pelFormat;
m_uiBitsPel = bitsPixel < kMinBitsPerPixel ? kMinBitsPerPixel : bitsPixel;
m_uiHalfPelValue = 1 << ( m_uiBitsPel - 1 );
m_bHasNegativeValues = has_negative_values;
if( m_uiWidth == 0 || m_uiHeight == 0 || m_iPixelFormat == -1 || bitsPixel > kMaxBitsPerPixel )
if( m_uiWidth == 0 || m_uiHeight == 0 || m_iPixelFormat == ClpPixelFormats::CLP_INVALID_FMT || bitsPixel > kMaxBitsPerPixel )
{
throw CalypFailure( "CalypFrame", "Cannot create a CalypFrame of this type" );
}
m_pcPelFormat = &( g_CalypPixFmtDescriptorsMap.at( pel_format ) );
m_pcPelFormat = &( g_CalypPixFmtDescriptorsMap.at( pelFormat ) );
int iNumberChannels = m_pcPelFormat->numberChannels;
std::size_t mem_size = 0;
@@ -210,8 +230,6 @@ public:
m_puiHistogram.resize( m_uiHistoSegments * m_uiHistoChannels );
m_cPelFmtName = CalypFrame::supportedPixelFormatListNames()[m_iPixelFormat].c_str();
m_bInit = true;
}
@@ -266,13 +284,13 @@ public:
/*!
* \brief Constructors
*/
CalypFrame::CalypFrame( unsigned int width, unsigned int height, int pelFormat, unsigned bitsPixel )
CalypFrame::CalypFrame( unsigned int width, unsigned int height, ClpPixelFormats pelFormat, unsigned bitsPixel )
: d{ std::make_unique<CalypFramePrivate>() }
{
d->init( width, height, pelFormat, bitsPixel );
}
CalypFrame::CalypFrame( unsigned int width, unsigned int height, int pelFormat, unsigned bitsPixel, bool has_negative_values )
CalypFrame::CalypFrame( unsigned int width, unsigned int height, ClpPixelFormats pelFormat, unsigned bitsPixel, bool has_negative_values )
: d{ std::make_unique<CalypFramePrivate>() }
{
d->init( width, height, pelFormat, bitsPixel, has_negative_values );
@@ -302,16 +320,6 @@ CalypFrame::CalypFrame( const CalypFrame& other )
copyFrom( &other );
}
// CalypFrame::CalypFrame( const CalypFrame* other )
// : d{ std::make_unique<CalypFramePrivate>() }
// {
// if( other )
// {
// d->init( other->getWidth(), other->getHeight(), other->getPelFormat(), other->getBitsPel(), other->getHasNegativeValues() );
// copyFrom( other );
// }
// }
CalypFrame& CalypFrame::operator=( const CalypFrame& other )
{
// Self-assignment detection
@@ -409,14 +417,14 @@ bool CalypFrame::haveSameFmt( const CalypFrame* other, unsigned int match ) cons
return bRet;
}
int CalypFrame::getPelFormat() const
auto CalypFrame::getPelFormat() const -> ClpPixelFormats
{
return d->m_iPixelFormat;
}
std::string CalypFrame::getPelFmtName() const
auto CalypFrame::getPelFmtName() const -> std::string
{
return d->m_pcPelFormat->name;
return std::string( d->m_pcPelFormat->name );
}
int CalypFrame::getColorSpace() const
@@ -483,16 +491,16 @@ std::uint64_t CalypFrame::getBytesPerFrame() const
return getBytesPerFrame( d->m_uiWidth, d->m_uiHeight, d->m_iPixelFormat, d->m_uiBitsPel );
}
std::uint64_t CalypFrame::getBytesPerFrame( unsigned int uiWidth, unsigned int uiHeight, int iPixelFormat, unsigned int bitsPixel )
std::uint64_t CalypFrame::getBytesPerFrame( unsigned int uiWidth, unsigned int uiHeight, ClpPixelFormats pelFormat, unsigned int bitsPixel )
{
const CalypPixelFormatDescriptor* pcPelFormat = &( g_CalypPixFmtDescriptorsMap.at( iPixelFormat ) );
const auto& pcPelFormat = g_CalypPixFmtDescriptorsMap.at( pelFormat );
unsigned int bytesPerPixel = ( bitsPixel - 1 ) / 8 + 1;
std::uint64_t numberBytes = uiWidth * uiHeight;
if( pcPelFormat->numberChannels > 1 )
if( pcPelFormat.numberChannels > 1 )
{
std::uint64_t numberBytesChroma =
CHROMASHIFT( uiWidth, pcPelFormat->log2ChromaWidth ) * CHROMASHIFT( uiHeight, pcPelFormat->log2ChromaHeight );
numberBytes += ( pcPelFormat->numberChannels - 1 ) * numberBytesChroma;
CHROMASHIFT( uiWidth, pcPelFormat.log2ChromaWidth ) * CHROMASHIFT( uiHeight, pcPelFormat.log2ChromaHeight );
numberBytes += ( pcPelFormat.numberChannels - 1 ) * numberBytesChroma;
}
return numberBytes * bytesPerPixel;
}
@@ -660,7 +668,7 @@ void CalypFrame::frameFromBuffer( const std::vector<ClpByte>& Buff, int iEndiann
void CalypFrame::frameFromBuffer( const std::vector<ClpByte>& Buff, int iEndianness )
{
const ClpByte* ppBuff[MAX_NUMBER_PLANES];
const ClpByte* ppBuff[CalypPixel::getMaxNumberOfComponents()];
unsigned int bytesPixel = ( d->m_uiBitsPel - 1 ) / 8 + 1;
int startByte = 0;
int endByte = bytesPixel;
@@ -675,7 +683,7 @@ void CalypFrame::frameFromBuffer( const std::vector<ClpByte>& Buff, int iEndiann
}
ppBuff[0] = Buff.data();
for( unsigned i = 1; i < MAX_NUMBER_PLANES; i++ )
for( unsigned i = 1; i < CalypPixel::getMaxNumberOfComponents(); i++ )
{
int ratioW = i > 1 ? d->m_pcPelFormat->log2ChromaWidth : 0;
int ratioH = i > 1 ? d->m_pcPelFormat->log2ChromaHeight : 0;
@@ -714,11 +722,11 @@ void CalypFrame::frameFromBuffer( const std::vector<ClpByte>& Buff, int iEndiann
void CalypFrame::frameToBuffer( std::vector<ClpByte>& output_buffer, int iEndianness ) const
{
unsigned int bytesPixel = ( d->m_uiBitsPel - 1 ) / 8 + 1;
ClpByte* ppBuff[MAX_NUMBER_PLANES];
ClpByte* ppBuff[CalypPixel::getMaxNumberOfComponents()];
ClpByte* pTmpBuff;
ClpPel* pTmpPel;
int ratioH, ratioW, step;
unsigned int i, ch;
unsigned int ch;
int startByte = 0;
int endByte = bytesPixel;
int incByte = 1;
@@ -732,7 +740,7 @@ void CalypFrame::frameToBuffer( std::vector<ClpByte>& output_buffer, int iEndian
}
ppBuff[0] = output_buffer.data();
for( int i = 1; i < MAX_NUMBER_PLANES; i++ )
for( std::size_t i = 1; i < CalypPixel::getMaxNumberOfComponents(); i++ )
{
ratioW = i > 1 ? d->m_pcPelFormat->log2ChromaWidth : 0;
ratioH = i > 1 ? d->m_pcPelFormat->log2ChromaHeight : 0;
@@ -748,7 +756,7 @@ void CalypFrame::frameToBuffer( std::vector<ClpByte>& output_buffer, int iEndian
pTmpPel = d->m_pppcInputPel[ch][0];
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( std::size_t i = 0; i < CHROMASHIFT( d->m_uiHeight, ratioH ) * CHROMASHIFT( d->m_uiWidth, ratioW ); i++ )
{
for( b = startByte; b != endByte; b += incByte )
{
@@ -843,7 +851,7 @@ void CalypFrame::fillRGBBuffer() const
}
else if( d->m_pcPelFormat->colorSpace == CLP_COLOR_YUV )
{
if( d->m_iPixelFormat == CLP_YUV420P )
if( d->m_iPixelFormat == ClpPixelFormats::CLP_YUV420P )
{
fillRGBBufferYUV420p( d->m_pppcInputPel, pARGB, d->m_uiWidth, d->m_uiHeight, shiftBits );
return;
@@ -1238,7 +1246,7 @@ bool CalypFrame::toMat( cv::Mat& cvMat, bool convertToGray, bool scale, unsigned
return bRet;
}
unsigned int cvPrecision = getBitsPel() > 8 ? CV_16U : CV_8U;
unsigned numBytes = getBitsPel() > 8 ? 2 : 1;
unsigned numBytes = getBitsPel() > sizeof( char ) ? 2 : 1;
unsigned numChannels = getNumberChannels();
unsigned scaleFactor = 1 << ( numBytes * 8 - getBitsPel() );
if( !scale )
@@ -1315,17 +1323,18 @@ bool CalypFrame::fromMat( cv::Mat& cvMat, int channel )
if( !d->m_bInit )
{
uchar depth = cvMat.type() & CV_MAT_DEPTH_MASK;
if( d->m_iPixelFormat == CLP_INVALID_FMT )
if( d->m_iPixelFormat == ClpPixelFormats::CLP_INVALID_FMT )
{
switch( cvMat.channels() )
{
case 1:
d->m_iPixelFormat = findPixelFormat( "GRAY" );
d->m_iPixelFormat = ClpPixelFormats::CLP_GRAY;
break;
case 3:
d->m_iPixelFormat = findPixelFormat( "BGR24" );
d->m_iPixelFormat = ClpPixelFormats::CLP_BGR24;
break;
default:
assert( false );
return false;
}
}
+22 -18
View File
@@ -27,7 +27,9 @@
#define __CALYPFRAME_H__
#include <cstdint>
#include <map>
#include <memory>
#include <optional>
#include <span>
#include <string>
#include <vector>
@@ -56,11 +58,11 @@ enum CalypColorSpace
};
/**
* \enum CalypPixelFormats
* \enum ClpPixelFormats
* \brief List of supported pixel formats
* \ingroup CalypLibGrp
*/
enum CalypPixelFormats
enum class ClpPixelFormats : int
{
CLP_INVALID_FMT = -1, //!< Invalid
CLP_YUV420P = 0, //!< YUV 420 progressive
@@ -73,7 +75,7 @@ enum CalypPixelFormats
CLP_BGR24, //!< BGR 32 bpp
CLP_RGBA32, //!< RGBA 32 bpp
CLP_BGRA32, //!< BGRA 32 bpp
CLP_MAX_FMT = 255, //!< Account for future formats
CLP_MAX_FMT = 254, //!< Account for future formats
};
enum CLP_YUV_Components
@@ -113,7 +115,7 @@ private:
std::array<ClpPel, kMaxNumberOfComponents> m_pelComp{ 0, 0, 0, 0 };
public:
static std::size_t getMaxNumberOfComponents() { return kMaxNumberOfComponents; }
static constexpr std::size_t getMaxNumberOfComponents() { return kMaxNumberOfComponents; }
CalypPixel() = default;
CalypPixel( const int CalypColorSpace, const ClpPel c0 = 0 );
@@ -130,16 +132,16 @@ public:
auto components() const -> const std::array<ClpPel, kMaxNumberOfComponents>& { return m_pelComp; };
auto components() -> std::array<ClpPel, kMaxNumberOfComponents>& { return m_pelComp; };
ClpPel operator[]( const int& channel ) const { return m_pelComp[channel]; }
ClpPel& operator[]( const int& channel ) { return m_pelComp[channel]; }
ClpPel operator[]( const std::size_t channel ) const { return m_pelComp[channel]; }
ClpPel& operator[]( const std::size_t channel ) { return m_pelComp[channel]; }
CalypPixel& operator+=( const CalypPixel& );
CalypPixel& operator-=( const CalypPixel& );
CalypPixel& operator*=( const double& );
CalypPixel& operator*=( const double );
CalypPixel operator+( const CalypPixel& ) const;
CalypPixel operator-( const CalypPixel& ) const;
CalypPixel operator*( const double& ) const;
CalypPixel operator*( const double ) const;
auto operator==( const CalypPixel& other ) const -> bool;
@@ -218,11 +220,13 @@ public:
* of CalypFrame
* @return vector of strings with pixel formats names
*/
static std::vector<std::string> supportedPixelFormatListNames();
static std::vector<std::string> supportedPixelFormatListNames( int colorSpace );
static int numberOfFormats();
static int findPixelFormat( const std::string& name );
static int pelformatColorSpace( const int idx );
static constexpr auto numberOfFormats() -> std::size_t;
static auto findPixelFormat( const std::string& name ) -> std::optional<ClpPixelFormats>;
static auto findPixelFormat( const std::string_view name ) -> std::optional<ClpPixelFormats>;
static auto pelformatColorSpace( ClpPixelFormats idx ) -> int;
static auto supportedPixelFormatListNames() -> std::map<ClpPixelFormats, std::string_view>;
static auto supportedPixelFormatListNames( int colorSpace ) -> std::map<ClpPixelFormats, std::string_view>;
static auto pixelFormatName( ClpPixelFormats idx ) -> const std::string_view;
/**
* Creates a new frame using the following configuration
@@ -233,7 +237,7 @@ public:
*
* @note this function might misbehave if the pixel format enum is not correct
*/
CalypFrame( unsigned int width, unsigned int height, int pelFormat, unsigned bitsPixel = 8 );
CalypFrame( unsigned int width, unsigned int height, ClpPixelFormats pelFormat, unsigned bitsPixel = 8 );
/**
* Creates a new frame using the following configuration
@@ -244,7 +248,7 @@ public:
*
* @note this function might misbehave if the pixel format enum is not correct
*/
CalypFrame( unsigned int width, unsigned int height, int pelFormat, unsigned bitsPixel, bool has_negative_values );
CalypFrame( unsigned int width, unsigned int height, ClpPixelFormats pelFormat, unsigned bitsPixel, bool has_negative_values );
/**
* Move contructor
@@ -316,13 +320,13 @@ public:
* Get pixel format information
* @return pixel format index
*/
int getPelFormat() const;
ClpPixelFormats getPelFormat() const;
/**
* Get pixel format information
* @return pixel format name
*/
std::string getPelFmtName() const;
auto getPelFmtName() const -> std::string;
/**
* Get color space information
@@ -403,7 +407,7 @@ public:
* Get number of bytes per frame of a specific pixel format
* @return number of bytes per frame
*/
static std::uint64_t getBytesPerFrame( unsigned int uiWidth, unsigned int uiHeight, int iPixelFormat, unsigned int bitsPixel );
static std::uint64_t getBytesPerFrame( unsigned int uiWidth, unsigned int uiHeight, ClpPixelFormats pelFormat, unsigned int bitsPixel );
/**
* Reset frame pixels to zero
+4 -1
View File
@@ -22,11 +22,14 @@
* \brief Calyp modules interface for OpenCV
*/
#include "CalypFrame.h"
#include "CalypModuleIf.h"
// OpenCV
#include <opencv2/opencv.hpp>
#include "PixelFormats.h"
bool CalypOpenCVModuleIf::create( std::vector<CalypFrame*> apcFrameList )
{
_BASIC_MODULE_API_2_CHECK_
@@ -39,7 +42,7 @@ bool CalypOpenCVModuleIf::create( std::vector<CalypFrame*> apcFrameList )
Mat* outputMat = create_using_opencv( acMatList );
if( outputMat )
{
unsigned pelFormat = m_bConvertToGray ? CalypFrame::findPixelFormat( "GRAY" ) : apcFrameList[0]->getPelFormat();
auto pelFormat = m_bConvertToGray ? ClpPixelFormats::CLP_GRAY : apcFrameList[0]->getPelFormat();
m_pcOutputFrame = std::make_unique<CalypFrame>( outputMat->cols, outputMat->rows, pelFormat, apcFrameList[0]->getBitsPel() );
bRet = true;
}
+3 -2
View File
@@ -688,9 +688,10 @@ bool CalypOptions::checkListingOpts()
if( hasOpt( "pel_fmts" ) )
{
std::cout << "Calyp supported pixel formats:" << std::endl;
for( unsigned int i = 0; i < CalypFrame::supportedPixelFormatListNames().size(); i++ )
const auto& fmt_list = CalypFrame::supportedPixelFormatListNames();
for( const auto& [key, name] : fmt_list )
{
std::cout << " " << CalypFrame::supportedPixelFormatListNames()[i] << std::endl;
std::cout << " " << name << std::endl;
}
bRet |= true;
}
+2 -2
View File
@@ -95,7 +95,7 @@ CalypPixel& CalypPixel::operator-=( const CalypPixel& in )
return *this;
}
CalypPixel& CalypPixel::operator*=( const double& op )
CalypPixel& CalypPixel::operator*=( const double op )
{
std::transform( m_pelComp.begin(),
m_pelComp.end(),
@@ -130,7 +130,7 @@ CalypPixel CalypPixel::operator-( const CalypPixel& in ) const
return result;
}
CalypPixel CalypPixel::operator*( const double& op ) const
CalypPixel CalypPixel::operator*( const double op ) const
{
CalypPixel result{ m_colorSpace };
auto& comp = result.components();
+15 -17
View File
@@ -30,6 +30,7 @@
#include <iostream>
#include <memory>
#include <mutex>
#include <string>
#include "CalypFrame.h"
#include "CalypStreamHandlerIf.h"
@@ -112,7 +113,7 @@ struct CalypStreamFrameBuffer : std::enable_shared_from_this<CalypStreamFrameBuf
std::vector<std::unique_ptr<CalypFrame>> framePool;
std::size_t bufferIdx{ 0 };
CalypStreamFrameBuffer( std::size_t size, unsigned int width, unsigned int height, int pelFormat, unsigned int bitsPixel, bool hasNegative )
CalypStreamFrameBuffer( std::size_t size, unsigned int width, unsigned int height, ClpPixelFormats pelFormat, unsigned int bitsPixel, bool hasNegative )
{
framePool.reserve( size );
for( std::size_t i = 0; i < size; i++ )
@@ -199,7 +200,7 @@ public:
close();
}
bool open( std::string filename, unsigned int width, unsigned int height, int input_format, unsigned int bitsPel, int endianness, bool hasNegative,
bool open( std::string filename, unsigned int width, unsigned int height, ClpPixelFormats input_format, unsigned int bitsPel, int endianness, bool hasNegative,
unsigned int frame_rate, bool forceRaw, CalypStream::Type type )
{
if( isInit )
@@ -246,7 +247,7 @@ public:
return isInit;
}
if( handler->m_uiWidth <= 0 || handler->m_uiHeight <= 0 || handler->m_iPixelFormat < 0 )
if( handler->m_uiWidth <= 0 || handler->m_uiHeight <= 0 || handler->m_iPixelFormat == ClpPixelFormats::CLP_INVALID_FMT )
{
close();
throw CalypFailure( "CalypStream", "Incorrect configuration: width, height or pixel format" );
@@ -400,7 +401,6 @@ bool CalypStream::open( std::string filename, std::string resolution, std::strin
{
unsigned int width = 0;
unsigned int height = 0;
int input_format = -1;
if( resolution.size() > 0 )
{
@@ -410,30 +410,28 @@ bool CalypStream::open( std::string filename, std::string resolution, std::strin
return false;
}
}
for( unsigned int i = 0; i < CalypFrame::supportedPixelFormatListNames().size(); i++ )
const auto input_format = CalypFrame::findPixelFormat( input_format_name );
if( !input_format.has_value() )
{
if( clpLowercase( CalypFrame::supportedPixelFormatListNames()[i] ) == clpLowercase( input_format_name ) )
{
input_format = i;
break;
return false;
}
}
return d->open( std::move( filename ), width, height, input_format, bitsPel, endianness, hasNegative, frame_rate, false, type );
return d->open( std::move( filename ), width, height, *input_format, bitsPel, endianness, hasNegative, frame_rate, false, type );
}
bool CalypStream::open( std::string filename, unsigned int width, unsigned int height, int input_format, unsigned int bitsPel, int endianness,
bool CalypStream::open( std::string filename, unsigned int width, unsigned int height, ClpPixelFormats input_format, unsigned int bitsPel, int endianness,
unsigned int frame_rate, CalypStream::Type type )
{
return d->open( std::move( filename ), width, height, input_format, bitsPel, endianness, false, frame_rate, false, type );
}
bool CalypStream::open( std::string filename, unsigned int width, unsigned int height, int input_format, unsigned int bitsPel, int endianness, bool hasNegative,
bool CalypStream::open( std::string filename, unsigned int width, unsigned int height, ClpPixelFormats input_format, unsigned int bitsPel, int endianness, bool hasNegative,
unsigned int frame_rate, CalypStream::Type type )
{
return d->open( std::move( filename ), width, height, input_format, bitsPel, endianness, hasNegative, frame_rate, false, type );
}
bool CalypStream::open( std::string filename, unsigned int width, unsigned int height, int input_format, unsigned int bitsPel, int endianness,
bool CalypStream::open( std::string filename, unsigned int width, unsigned int height, ClpPixelFormats input_format, unsigned int bitsPel, int endianness,
unsigned int frame_rate, bool forceRaw, CalypStream::Type type )
{
return d->open( std::move( filename ), width, height, input_format, bitsPel, endianness, false, frame_rate, forceRaw, type );
@@ -460,7 +458,7 @@ bool CalypStream::reload()
d->handler->calculateFrameNumber();
d->handler->configureBuffer( *refFrame );
if( d->handler->m_uiWidth <= 0 || d->handler->m_uiHeight <= 0 || d->handler->m_iPixelFormat < 0 ||
if( d->handler->m_uiWidth <= 0 || d->handler->m_uiHeight <= 0 || d->handler->m_iPixelFormat == ClpPixelFormats::CLP_INVALID_FMT ||
d->handler->m_uiBitsPerPixel == 0 || d->handler->m_uiTotalNumberFrames == 0 )
{
return false;
@@ -515,7 +513,7 @@ long CalypStream::getCurrFrameNum() const
return d->iCurrFrameNum;
}
void CalypStream::getFormat( unsigned int& rWidth, unsigned int& rHeight, int& rInputFormat, unsigned int& rBitsPerPel, int& rEndianness,
void CalypStream::getFormat( unsigned int& rWidth, unsigned int& rHeight, ClpPixelFormats& rInputFormat, unsigned int& rBitsPerPel, int& rEndianness,
unsigned int& rFrameRate ) const
{
if( d->isInit )
@@ -531,7 +529,7 @@ void CalypStream::getFormat( unsigned int& rWidth, unsigned int& rHeight, int& r
{
rWidth = 0;
rHeight = 0;
rInputFormat = CLP_YUV420P;
rInputFormat = ClpPixelFormats::CLP_YUV420P;
rBitsPerPel = kDefaultBitsPerPixel;
rEndianness = 0;
rFrameRate = kDefaultFrameRate;
+5 -11
View File
@@ -96,18 +96,12 @@ public:
bool hasNegative,
unsigned int frame_rate,
Type type );
bool open( std::string filename, unsigned int width, unsigned int height, ClpPixelFormats input_format, unsigned int bitsPel, int endianness,
unsigned int frame_rate, CalypStream::Type type );
bool open( std::string filename,
unsigned int width,
unsigned int height,
int input_format,
unsigned int bitsPel,
int endianness,
unsigned int frame_rate,
Type type );
bool open( std::string filename,
unsigned int width,
unsigned int height,
int input_format,
ClpPixelFormats input_format,
unsigned int bitsPel,
int endianness,
bool hasNegative,
@@ -116,7 +110,7 @@ public:
bool open( std::string filename,
unsigned int width,
unsigned int height,
int input_format,
ClpPixelFormats input_format,
unsigned int bitsPel,
int endianness,
unsigned int frame_rate,
@@ -135,7 +129,7 @@ public:
int getEndianess() const;
long getCurrFrameNum() const;
double getFrameRate() const;
void getFormat( unsigned int& rWidth, unsigned int& rHeight, int& rInputFormat, unsigned int& rBitsPerPel, int& rEndianness,
void getFormat( unsigned int& rWidth, unsigned int& rHeight, ClpPixelFormats& rInputFormat, unsigned int& rBitsPerPel, int& rEndianness,
unsigned int& rFrameRate ) const;
auto hasNextFrame() -> bool;
+1 -1
View File
@@ -105,7 +105,7 @@ protected:
bool m_bNative{ true };
unsigned int m_uiWidth{ 0 };
unsigned int m_uiHeight{ 0 };
int m_iPixelFormat{ -1 };
ClpPixelFormats m_iPixelFormat{ ClpPixelFormats::CLP_INVALID_FMT };
unsigned int m_uiBitsPerPixel{ 8 };
int m_iEndianness{ CLP_INVALID_ENDIANESS };
double m_dFrameRate{ 30 };
+21 -21
View File
@@ -43,11 +43,11 @@
#define ADD_FFMPEG_PEL_FMT( fmt ) 0
#endif
const std::map<int, CalypPixelFormatDescriptor> g_CalypPixFmtDescriptorsMap = {
const std::map<ClpPixelFormats, CalypPixelFormatDescriptor> g_CalypPixFmtDescriptorsMap = {
{
CLP_YUV420P,
ClpPixelFormats::CLP_YUV420P,
{
"YUV420p",
"YUV420p"sv,
CLP_COLOR_YUV,
3,
3,
@@ -62,9 +62,9 @@ const std::map<int, CalypPixelFormatDescriptor> g_CalypPixFmtDescriptorsMap = {
},
},
{
CLP_YUV422P,
ClpPixelFormats::CLP_YUV422P,
{
"YUV422p",
"YUV422p"sv,
CLP_COLOR_YUV,
3,
3,
@@ -79,9 +79,9 @@ const std::map<int, CalypPixelFormatDescriptor> g_CalypPixFmtDescriptorsMap = {
},
},
{
CLP_YUV444P,
ClpPixelFormats::CLP_YUV444P,
{
"YUV444p",
"YUV444p"sv,
CLP_COLOR_YUV,
3,
3,
@@ -96,9 +96,9 @@ const std::map<int, CalypPixelFormatDescriptor> g_CalypPixFmtDescriptorsMap = {
},
},
{
CLP_YUYV422,
ClpPixelFormats::CLP_YUYV422,
{
"YUYV422",
"YUYV422"sv,
CLP_COLOR_YUV,
3,
1,
@@ -113,9 +113,9 @@ const std::map<int, CalypPixelFormatDescriptor> g_CalypPixFmtDescriptorsMap = {
},
},
{
CLP_GRAY,
ClpPixelFormats::CLP_GRAY,
{
"GRAY",
"GRAY"sv,
CLP_COLOR_GRAY,
1,
1,
@@ -126,9 +126,9 @@ const std::map<int, CalypPixelFormatDescriptor> g_CalypPixFmtDescriptorsMap = {
},
},
{
CLP_RGB24P,
ClpPixelFormats::CLP_RGB24P,
{
"RGBp",
"RGBp"sv,
CLP_COLOR_RGB,
3,
3,
@@ -143,9 +143,9 @@ const std::map<int, CalypPixelFormatDescriptor> g_CalypPixFmtDescriptorsMap = {
},
},
{
CLP_RGB24,
ClpPixelFormats::CLP_RGB24,
{
"RGB",
"RGB"sv,
CLP_COLOR_RGB,
3,
1,
@@ -160,9 +160,9 @@ const std::map<int, CalypPixelFormatDescriptor> g_CalypPixFmtDescriptorsMap = {
},
},
{
CLP_BGR24,
ClpPixelFormats::CLP_BGR24,
{
"BGR",
"BGR"sv,
CLP_COLOR_RGB,
3,
1,
@@ -177,9 +177,9 @@ const std::map<int, CalypPixelFormatDescriptor> g_CalypPixFmtDescriptorsMap = {
},
},
{
CLP_RGBA32,
ClpPixelFormats::CLP_RGBA32,
{
"RGBA",
"RGBA"sv,
CLP_COLOR_RGBA,
4,
1,
@@ -195,9 +195,9 @@ const std::map<int, CalypPixelFormatDescriptor> g_CalypPixFmtDescriptorsMap = {
},
},
{
CLP_BGRA32,
ClpPixelFormats::CLP_BGRA32,
{
"BGRA",
"BGRA"sv,
CLP_COLOR_RGBA,
4,
1,
+19 -12
View File
@@ -29,11 +29,21 @@
#include "CalypFrame.h"
#define CHROMA_RESAMPLING( X ) ( ( ( X + 1 ) >> 1 ) << 1 )
using namespace std::string_view_literals;
#define CHROMARATIO( SIZE, RATIO ) ( RATIO > 1 ? ( ( SIZE + 1 ) / RATIO ) : SIZE )
template <typename T>
inline constexpr T CHROMA_RESAMPLING( T in )
{
return ( ( ( in + 1 ) >> 1 ) << 1 );
}
typedef struct CalypComponentDescriptor
template <typename T, typename R>
inline constexpr T CHROMARATIO( T size, R ratio )
{
return ( ratio > 1 ? ( ( size + 1 ) / ratio ) : size );
}
struct CalypComponentDescriptor
{
/**
* Which of the 4 planes contains the component.
@@ -51,8 +61,7 @@ typedef struct CalypComponentDescriptor
* Elements are bits for bitstream formats, bytes otherwise.
*/
unsigned short offset_plus1;
} CalypComponentDescriptor;
};
/**
* Descriptor that unambiguously describes how the bits of a pixel are
@@ -63,9 +72,9 @@ typedef struct CalypComponentDescriptor
* and all the YUV variants) AVPixFmtDescriptor just stores how values
* are stored not what these values represent.
*/
typedef struct CalypPixelFormatDescriptor
struct CalypPixelFormatDescriptor
{
const char* name;
std::string_view name;
int colorSpace;
@@ -102,11 +111,9 @@ typedef struct CalypPixelFormatDescriptor
* otherwise 0 is luma, 1 is chroma-U and 2 is chroma-V.
*/
CalypComponentDescriptor comp[4];
};
} CalypPixelFormatDescriptor;
#define MAX_NUMBER_PLANES 3
extern const std::map<int, CalypPixelFormatDescriptor> g_CalypPixFmtDescriptorsMap;
static constexpr std::size_t kNumberOfPixelFormats{ 10 };
extern const std::map<ClpPixelFormats, CalypPixelFormatDescriptor> g_CalypPixFmtDescriptorsMap;
#endif // __PIXELFORMATS_H__
+15 -19
View File
@@ -197,20 +197,16 @@ bool StreamHandlerLibav::openHandler( std::string strFilename, bool bInput )
auxPixFmt = AV_PIX_FMT_GRAY8;
}
m_iPixelFormat = CLP_INVALID_FMT;
for( int i = 0; i < CalypFrame::numberOfFormats(); i++ )
{
if( g_CalypPixFmtDescriptorsMap.at( i ).ffmpegPelFormat == auxPixFmt )
{
m_iPixelFormat = i;
break;
}
}
if( m_iPixelFormat == CLP_INVALID_FMT )
{
m_iPixelFormat = ClpPixelFormats::CLP_INVALID_FMT;
m_bNative = false;
//throw CalypFailure( "StreamHandlerLibav", "Cannot open file using FFmpeg libs - unsupported pixel format" );
//return false;
auto found_fmt = std::find_if( g_CalypPixFmtDescriptorsMap.begin(), g_CalypPixFmtDescriptorsMap.end(),
[auxPixFmt]( const auto& fmt ) {
return fmt.second.ffmpegPelFormat == auxPixFmt;
} );
if( found_fmt != g_CalypPixFmtDescriptorsMap.end() )
{
m_bNative = true;
m_iPixelFormat = found_fmt->first;
}
double fr = 30;
@@ -249,27 +245,27 @@ bool StreamHandlerLibav::openHandler( std::string strFilename, bool bInput )
if( !m_bNative )
{
int newPelFmt = -1;
ClpPixelFormats newPelFmt{ ClpPixelFormats::CLP_INVALID_FMT };
const AVPixFmtDescriptor* ffPelDesc = av_pix_fmt_desc_get( AVPixelFormat( m_ffPixFmt ) );
if( ffPelDesc->flags & AV_PIX_FMT_FLAG_PAL )
{
newPelFmt = CLP_RGB24;
newPelFmt = ClpPixelFormats::CLP_RGB24;
}
else if( ffPelDesc->flags & AV_PIX_FMT_FLAG_ALPHA )
{
newPelFmt = CLP_RGBA32;
newPelFmt = ClpPixelFormats::CLP_RGBA32;
}
else if( ffPelDesc->flags & AV_PIX_FMT_FLAG_RGB )
{
newPelFmt = CLP_RGB24;
newPelFmt = ClpPixelFormats::CLP_RGB24;
}
else if( ffPelDesc->nb_components == 1 )
{
newPelFmt = CLP_GRAY;
newPelFmt = ClpPixelFormats::CLP_GRAY;
}
else
{
newPelFmt = CLP_YUV444P;
newPelFmt = ClpPixelFormats::CLP_YUV444P;
}
m_iPixelFormat = newPelFmt;
+3 -1
View File
@@ -28,6 +28,8 @@
#include <opencv2/opencv.hpp>
#include "CalypFrame.h"
#include "PixelFormats.h"
#if CV_MAJOR_VERSION >= 3
#include <opencv2/videoio.hpp>
#endif
@@ -103,7 +105,7 @@ bool StreamHandlerOpenCV::openHandler( std::string strFilename, bool bInput )
m_dFrameRate = 1;
}
m_uiBitsPerPixel = 8;
m_iPixelFormat = CalypFrame::findPixelFormat( "BGR" );
m_iPixelFormat = ClpPixelFormats::CLP_BGR24;
m_uiTotalNumberFrames = 1;
if( m_pcVideoCapture )
+5 -4
View File
@@ -28,6 +28,7 @@
#include <cstdio>
#include "CalypFrame.h"
#include "PixelFormats.h"
std::vector<CalypStreamFormat> StreamHandlerPortableMap::supportedReadFormats()
{
@@ -79,7 +80,7 @@ bool StreamHandlerPortableMap::openHandler( std::string strFilename, bool bInput
}
}
m_uiBitsPerPixel = log( m_iMaxValue + 1 ) / log( 2 );
m_iPixelFormat = m_iMagicNumber == 1 || m_iMagicNumber == 2 || m_iMagicNumber == 5 ? CLP_GRAY : CLP_RGB24;
m_iPixelFormat = m_iMagicNumber == 1 || m_iMagicNumber == 2 || m_iMagicNumber == 5 ? ClpPixelFormats::CLP_GRAY : ClpPixelFormats::CLP_RGB24;
}
else
{
@@ -88,17 +89,17 @@ bool StreamHandlerPortableMap::openHandler( std::string strFilename, bool bInput
if( m_uiBitsPerPixel == 1 )
{
m_iMagicNumber = 1;
m_iPixelFormat = CalypFrame::findPixelFormat( "GRAY" );
m_iPixelFormat = ClpPixelFormats::CLP_GRAY;
}
else if( colorSpace == CLP_COLOR_GRAY )
{
m_iMagicNumber = 5;
m_iPixelFormat = CalypFrame::findPixelFormat( "GRAY" );
m_iPixelFormat = ClpPixelFormats::CLP_GRAY;
}
else if( colorSpace == CLP_COLOR_RGB )
{
m_iMagicNumber = 6;
m_iPixelFormat = CalypFrame::findPixelFormat( "RGB" );
m_iPixelFormat = ClpPixelFormats::CLP_RGB24;
}
else
{
+6 -6
View File
@@ -29,32 +29,32 @@
TEST_CASE( "create a 256x128 frame with 8 bits in YUV420 format", "CalypFrame" )
{
// Constructor: CalypFrame( unsigned int width, unsigned int height, int pelFormat, unsigned bitsPixel = 8 );
CalypFrame testFrame( 256, 128, CLP_YUV420P, 8 );
CalypFrame testFrame( 256, 128, ClpPixelFormats::CLP_YUV420P, 8 );
CHECK( testFrame.getWidth() == 256 );
CHECK( testFrame.getHeight() == 128 );
CHECK( testFrame.getPelFormat() == CLP_YUV420P );
CHECK( testFrame.getPelFormat() == ClpPixelFormats::CLP_YUV420P );
CHECK( testFrame.getBitsPel() == 8 );
}
TEST_CASE( "create a 256x128 frame with 10 bits in YUV420 format", "CalypFrame" )
{
// Constructor: CalypFrame( unsigned int width, unsigned int height, int pelFormat, unsigned bitsPixel = 8 );
CalypFrame testFrame( 256, 128, CLP_YUV420P, 10 );
CalypFrame testFrame( 256, 128, ClpPixelFormats::CLP_YUV420P, 10 );
CHECK( testFrame.getWidth() == 256 );
CHECK( testFrame.getHeight() == 128 );
CHECK( testFrame.getPelFormat() == CLP_YUV420P );
CHECK( testFrame.getPelFormat() == ClpPixelFormats::CLP_YUV420P );
CHECK( testFrame.getBitsPel() == 10 );
}
TEST_CASE( "create a 256x128 frame with 16 bits in YUV420 format", "CalypFrame" )
{
// Constructor: CalypFrame( unsigned int width, unsigned int height, int pelFormat, unsigned bitsPixel = 8 );
CalypFrame testFrame( 256, 128, CLP_YUV420P, 16 );
CalypFrame testFrame( 256, 128, ClpPixelFormats::CLP_YUV420P, 16 );
CHECK( testFrame.getWidth() == 256 );
CHECK( testFrame.getHeight() == 128 );
CHECK( testFrame.getPelFormat() == CLP_YUV420P );
CHECK( testFrame.getPelFormat() == ClpPixelFormats::CLP_YUV420P );
CHECK( testFrame.getBitsPel() == 16 );
}
+9 -9
View File
@@ -42,7 +42,7 @@ TEST_CASE( "Can open a YUV 420p file", "CalypStream" )
{
constexpr int kWidth{ 352 };
constexpr int kHeight{ 288 };
constexpr auto kInputFormat{ CalypPixelFormats::CLP_YUV420P };
constexpr auto kInputFormat{ ClpPixelFormats::CLP_YUV420P };
constexpr int kBitsPel{ 8 };
constexpr auto KEndianness{ CLP_INVALID_ENDIANESS };
@@ -85,7 +85,7 @@ TEST_CASE( "Can open a YUV file", "CalypStream" )
};
SECTION( "YUV420p" )
{
constexpr auto kInputFormat{ CalypPixelFormats::CLP_YUV420P };
constexpr auto kInputFormat{ ClpPixelFormats::CLP_YUV420P };
const auto kFilename = getFileTestFilename( "Foreman.yuv" );
REQUIRE( std::filesystem::exists( std::filesystem::path( kFilename ) ) );
@@ -101,7 +101,7 @@ TEST_CASE( "Can open a YUV file", "CalypStream" )
}
SECTION( "YUV422p" )
{
constexpr auto kInputFormat{ CalypPixelFormats::CLP_YUV422P };
constexpr auto kInputFormat{ ClpPixelFormats::CLP_YUV422P };
const auto kFilename = getFileTestFilename( "Foreman_352x288_yuv422p.yuv" );
REQUIRE( std::filesystem::exists( std::filesystem::path( kFilename ) ) );
@@ -117,7 +117,7 @@ TEST_CASE( "Can open a YUV file", "CalypStream" )
}
SECTION( "YUV444p" )
{
constexpr auto kInputFormat{ CalypPixelFormats::CLP_YUV444P };
constexpr auto kInputFormat{ ClpPixelFormats::CLP_YUV444P };
const auto kFilename = getFileTestFilename( "Foreman_352x288_yuv444p.yuv" );
REQUIRE( std::filesystem::exists( std::filesystem::path( kFilename ) ) );
@@ -133,7 +133,7 @@ TEST_CASE( "Can open a YUV file", "CalypStream" )
}
SECTION( "YUYV422" )
{
constexpr auto kInputFormat{ CalypPixelFormats::CLP_YUYV422 };
constexpr auto kInputFormat{ ClpPixelFormats::CLP_YUYV422 };
const auto kFilename = getFileTestFilename( "Foreman_352x288_yuyv422.yuv" );
REQUIRE( std::filesystem::exists( std::filesystem::path( kFilename ) ) );
@@ -166,7 +166,7 @@ TEST_CASE( "Can open a RGB file", "CalypStream" )
};
SECTION( "RGB24" )
{
constexpr auto kInputFormat{ CalypPixelFormats::CLP_RGB24 };
constexpr auto kInputFormat{ ClpPixelFormats::CLP_RGB24 };
const auto kFilename = getFileTestFilename( "Foreman_352x288_rgb24.yuv" );
REQUIRE( std::filesystem::exists( std::filesystem::path( kFilename ) ) );
CalypStream test_stream;
@@ -183,7 +183,7 @@ TEST_CASE( "Can open a RGB file", "CalypStream" )
SECTION( "BGR24" )
{
constexpr auto kInputFormat{ CalypPixelFormats::CLP_BGR24 };
constexpr auto kInputFormat{ ClpPixelFormats::CLP_BGR24 };
const auto kFilename = getFileTestFilename( "Foreman_352x288_bgr24.yuv" );
REQUIRE( std::filesystem::exists( std::filesystem::path( kFilename ) ) );
CalypStream test_stream;
@@ -212,7 +212,7 @@ TEST_CASE( "Can open a GRAY file", "CalypStream" )
stream.getCodecName() == "Raw Video" &&
stream.getEndianess() == CLP_BIG_ENDIAN;
};
constexpr auto kInputFormat{ CalypPixelFormats::CLP_GRAY };
constexpr auto kInputFormat{ ClpPixelFormats::CLP_GRAY };
const auto kFilename = getFileTestFilename( "Foreman_352x288_gray.yuv" );
REQUIRE( std::filesystem::exists( std::filesystem::path( kFilename ) ) );
CalypStream test_stream;
@@ -229,7 +229,7 @@ TEST_CASE( "Can open .batatas file as RAW video", "CalypStream" )
{
constexpr int kWidth{ 352 };
constexpr int kHeight{ 288 };
constexpr auto kInputFormat{ CalypPixelFormats::CLP_YUV420P };
constexpr auto kInputFormat{ ClpPixelFormats::CLP_YUV420P };
constexpr int kBitsPel{ 8 };
constexpr auto KEndianness{ CLP_INVALID_ENDIANESS };
+2 -2
View File
@@ -35,12 +35,12 @@ protected:
static void SetUpTestCase()
{
pcStreamPast = std::make_unique<CalypStream>();
pcStreamPast->open( std::string( CALYP_TEST_DATA_DIR ) + std::string( "/BasketballDrill_F10_832x480_yuv420p.yuv" ), 832, 480, 0, 8,
pcStreamPast->open( std::string( CALYP_TEST_DATA_DIR ) + std::string( "/BasketballDrill_F10_832x480_yuv420p.yuv" ), 832, 480, ClpPixelFormats::CLP_YUV420P, 8,
CLP_BIG_ENDIAN, 1, CalypStream::Type::Input );
pcFramePast = pcStreamPast->getCurrFrame();
pcStreamFuture = std::make_unique<CalypStream>();
pcStreamFuture->open( std::string( CALYP_TEST_DATA_DIR ) + std::string( "/BasketballDrill_F15_832x480_yuv420p.yuv" ), 832, 480, 0, 8,
pcStreamFuture->open( std::string( CALYP_TEST_DATA_DIR ) + std::string( "/BasketballDrill_F15_832x480_yuv420p.yuv" ), 832, 480, ClpPixelFormats::CLP_YUV420P, 8,
CLP_BIG_ENDIAN, 1, CalypStream::Type::Input );
pcFrameFuture = pcStreamFuture->getCurrFrame();
}
+1 -1
View File
@@ -52,7 +52,7 @@ bool AbsoluteFrameDifference::create( std::vector<CalypFrame*> apcFrameList )
if( !apcFrameList[i]->haveSameFmt( apcFrameList[0], CalypFrame::MATCH_COLOR_SPACE_IGNORE_GRAY | CalypFrame::MATCH_COLOR_SPACE | CalypFrame::MATCH_RESOLUTION | CalypFrame::MATCH_BITS ) )
return false;
m_pcFrameDifference = std::make_unique<CalypFrame>( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), CLP_GRAY, apcFrameList[0]->getBitsPel() );
m_pcFrameDifference = std::make_unique<CalypFrame>( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), ClpPixelFormats::CLP_GRAY, apcFrameList[0]->getBitsPel() );
return true;
}
+3 -1
View File
@@ -25,6 +25,8 @@
#include "DisparityStereoBM.h"
#include "lib/CalypFrame.h"
DisparityStereoBM::DisparityStereoBM()
{
/* Module Definition */
@@ -49,7 +51,7 @@ bool DisparityStereoBM::create( std::vector<CalypFrame*> apcFrameList )
{
_BASIC_MODULE_API_2_CHECK_
m_pcDisparityFrame =
new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), CLP_GRAY );
new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), ClpPixelFormats::CLP_GRAY );
if( ( m_uiBlockSize % 2 ) == 0 )
{
m_uiBlockSize++;
+1 -1
View File
@@ -51,7 +51,7 @@ bool DisparityStereoSGBM::create( std::vector<CalypFrame*> apcFrameList )
{
_BASIC_MODULE_API_2_CHECK_
m_pcDisparityFrame =
new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), CLP_GRAY );
new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), ClpPixelFormats::CLP_GRAY );
if( ( m_uiBlockSize % 2 ) == 0 )
{
m_uiBlockSize++;
+1 -1
View File
@@ -41,7 +41,7 @@ FilterComponentModule::FilterComponentModule()
bool FilterComponentModule::createFilter( unsigned int uiWidth, unsigned int uiHeight, unsigned int bitsPixel )
{
m_pcFilteredFrame = NULL;
m_pcFilteredFrame = new CalypFrame( uiWidth, uiHeight, CLP_GRAY, bitsPixel );
m_pcFilteredFrame = new CalypFrame( uiWidth, uiHeight, ClpPixelFormats::CLP_GRAY, bitsPixel );
return true;
}
+1 -1
View File
@@ -45,7 +45,7 @@ FrameBinarization::FrameBinarization()
void FrameBinarization::create( CalypFrame* frame )
{
m_pcBinFrame = NULL;
m_pcBinFrame = new CalypFrame( frame->getWidth(), frame->getHeight(), CLP_GRAY, 8 );
m_pcBinFrame = new CalypFrame( frame->getWidth(), frame->getHeight(), ClpPixelFormats::CLP_GRAY, 8 );
}
CalypFrame* FrameBinarization::process( CalypFrame* frame )
+5 -5
View File
@@ -61,22 +61,22 @@ bool FrameMask::create( std::vector<CalypFrame*> apcFrameList )
m_iWeight = m_iWeight > 100 || m_iWeight < 0 ? 5 : m_iWeight;
m_iWeight = m_iWeight > 10 ? m_iWeight / 10 : m_iWeight;
int iPelFmt = 0;
auto iPelFmt = ClpPixelFormats::CLP_INVALID_FMT;
int iColorSpace = apcFrameList[0]->getColorSpace();
if( iColorSpace == CLP_COLOR_GRAY )
{
iColorSpace = apcFrameList[1]->getPelFormat();
iColorSpace = apcFrameList[1]->getColorSpace();
}
switch( iColorSpace )
{
case CLP_COLOR_GRAY:
iPelFmt = CLP_GRAY;
iPelFmt = ClpPixelFormats::CLP_GRAY;
break;
case CLP_COLOR_YUV:
iPelFmt = CLP_YUV444P;
iPelFmt = ClpPixelFormats::CLP_YUV444P;
break;
case CLP_COLOR_RGB:
iPelFmt = CLP_RGB24;
iPelFmt = ClpPixelFormats::CLP_RGB24;
break;
}
+1 -1
View File
@@ -61,7 +61,7 @@ bool HEVCIntraPrediction::create( std::vector<CalypFrame*> apcFrameList )
{
_BASIC_MODULE_API_2_CHECK_
m_pcPredBlock = NULL;
m_pcPredBlock = new CalypFrame( m_iBlockSize * 2 + 1, m_iBlockSize * 2 + 1, CLP_GRAY, apcFrameList[0]->getBitsPel() );
m_pcPredBlock = new CalypFrame( m_iBlockSize * 2 + 1, m_iBlockSize * 2 + 1, ClpPixelFormats::CLP_GRAY, apcFrameList[0]->getBitsPel() );
m_referenceMem.resize( m_iBlockSize * 4 );
+1 -1
View File
@@ -53,7 +53,7 @@ bool InterFrameVariance::create( std::vector<CalypFrame*> apcFrameList )
return false;
m_pcFrameVariance =
new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), CLP_GRAY, 8 );
new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), ClpPixelFormats::CLP_GRAY, 8 );
m_pVariance = CalypPlane<double>{ apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight() };
+1 -1
View File
@@ -69,7 +69,7 @@ bool MeasureOpticalFlowDualTVL1::create( std::vector<CalypFrame*> apcFrameList )
#else
m_cTvl1 = cv::createOptFlow_DualTVL1();
#endif
m_pcOutputFrame = new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), CLP_GRAY );
m_pcOutputFrame = new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), ClpPixelFormats::CLP_GRAY );
return true;
}
+1 -1
View File
@@ -62,7 +62,7 @@ bool OpticalFlowModule::commonCreate( std::vector<CalypFrame*> apcFrameList )
return false;
m_iStep = 16;
m_pcOutputFrame = new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), CLP_GRAY );
m_pcOutputFrame = new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), ClpPixelFormats::CLP_GRAY );
return true;
}
+1 -3
View File
@@ -29,8 +29,6 @@
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/photo.hpp>
//using cv::InputArray;
//using cv::OutputArray;
using cv::Rect;
using cv::Scalar;
using cv::Size;
@@ -202,7 +200,7 @@ bool ThreeSixtyDownsampling::createDownsamplingMask( CalypFrame* pcInputFrame )
return false;
// m_pcDownsampled = new CalypFrame( m_iWidth, m_uiHeight, pcInputFrame->getPelFormat(), pcInputFrame->getBitsPel() );
m_pcDownsampled = new CalypFrame( m_iWidth, m_iHeight, CalypFrame::findPixelFormat( "GRAY" ), pcInputFrame->getBitsPel() );
m_pcDownsampled = new CalypFrame( m_iWidth, m_iHeight, ClpPixelFormats::CLP_GRAY, pcInputFrame->getBitsPel() );
m_isOdd = !( m_iHeight % 2 );
for( unsigned ch = 0; ch < m_pcDownsampled->getNumberChannels(); ch++ )
+1 -1
View File
@@ -39,7 +39,7 @@ protected:
std::string moduleName = CALYP_TEST_MODULE_NAME;
pcStream = std::make_unique<CalypStream>();
pcStream->open( std::string( CALYP_TEST_DATA_DIR ) + std::string( "/BasketballDrill_F10_832x480_yuv420p.yuv" ), 832, 480, 0, 8,
pcStream->open( std::string( CALYP_TEST_DATA_DIR ) + std::string( "/BasketballDrill_F10_832x480_yuv420p.yuv" ), 832, 480, ClpPixelFormats::CLP_YUV420P, 8,
CLP_BIG_ENDIAN, 1, CalypStream::Type::Input );
}
@@ -52,7 +52,7 @@ protected:
std::string moduleName = CALYP_TEST_MODULE_NAME;
pcStream = std::make_unique<CalypStream>();
pcStream->open( std::string( CALYP_TEST_DATA_DIR ) + std::string( "/BasketballDrill_F10_832x480_yuv420p.yuv" ), 832, 480, 0, 8,
pcStream->open( std::string( CALYP_TEST_DATA_DIR ) + std::string( "/BasketballDrill_F10_832x480_yuv420p.yuv" ), 832, 480, ClpPixelFormats::CLP_YUV420P, 8,
CLP_BIG_ENDIAN, 1, CalypStream::Type::Input );
CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap();