Fix compilation errors and add new tests
This commit is contained in:
+12
-12
@@ -418,7 +418,7 @@ int CalypFrame::getPelFormat() const
|
||||
return d->m_iPixelFormat;
|
||||
}
|
||||
|
||||
std::string CalypFrame::getPelFmtName()
|
||||
std::string CalypFrame::getPelFmtName() const
|
||||
{
|
||||
return d->m_pcPelFormat->name;
|
||||
}
|
||||
@@ -933,12 +933,12 @@ void CalypFrame::calcHistogram()
|
||||
d->m_bHistogramRunning = false;
|
||||
}
|
||||
|
||||
int CalypFrame::getNumHistogramSegment()
|
||||
int CalypFrame::getNumHistogramSegment() const
|
||||
{
|
||||
return d->m_uiHistoSegments;
|
||||
}
|
||||
|
||||
unsigned int CalypFrame::getMinimumPelValue( unsigned channel )
|
||||
unsigned int CalypFrame::getMinimumPelValue( unsigned channel ) const
|
||||
{
|
||||
if( !d->m_bHasHistogram )
|
||||
return 0;
|
||||
@@ -970,7 +970,7 @@ unsigned int CalypFrame::getMinimumPelValue( unsigned channel )
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int CalypFrame::getMaximumPelValue( unsigned channel )
|
||||
unsigned int CalypFrame::getMaximumPelValue( unsigned channel ) const
|
||||
{
|
||||
if( !d->m_bHasHistogram )
|
||||
return 0;
|
||||
@@ -1002,7 +1002,7 @@ unsigned int CalypFrame::getMaximumPelValue( unsigned channel )
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int CalypFrame::getNEBins( unsigned channel )
|
||||
unsigned int CalypFrame::getNEBins( unsigned channel ) const
|
||||
{
|
||||
if( !d->m_bHasHistogram )
|
||||
return 0;
|
||||
@@ -1035,7 +1035,7 @@ unsigned int CalypFrame::getNEBins( unsigned channel )
|
||||
return nEBins;
|
||||
}
|
||||
|
||||
unsigned int CalypFrame::getMaximum( unsigned channel )
|
||||
unsigned int CalypFrame::getMaximum( unsigned channel ) const
|
||||
{
|
||||
if( !d->m_bHasHistogram )
|
||||
return 0;
|
||||
@@ -1068,7 +1068,7 @@ unsigned int CalypFrame::getMaximum( unsigned channel )
|
||||
return maxValue;
|
||||
}
|
||||
|
||||
unsigned int CalypFrame::getNumPixelsRange( unsigned channel, unsigned int start, unsigned int end )
|
||||
unsigned int CalypFrame::getNumPixelsRange( unsigned channel, unsigned int start, unsigned int end ) const
|
||||
{
|
||||
if( !d->m_bHasHistogram || start < 0 || end > d->m_uiHistoSegments - 1 || start > end )
|
||||
{
|
||||
@@ -1090,7 +1090,7 @@ unsigned int CalypFrame::getNumPixelsRange( unsigned channel, unsigned int start
|
||||
return count;
|
||||
}
|
||||
|
||||
double CalypFrame::getMean( unsigned channel, unsigned int start, unsigned int end )
|
||||
double CalypFrame::getMean( unsigned channel, unsigned int start, unsigned int end ) const
|
||||
{
|
||||
if( !d->m_bHasHistogram || start < 0 || end > d->m_uiHistoSegments - 1 || start > end )
|
||||
{
|
||||
@@ -1120,7 +1120,7 @@ double CalypFrame::getMean( unsigned channel, unsigned int start, unsigned int e
|
||||
return mean;
|
||||
}
|
||||
|
||||
int CalypFrame::getMedian( unsigned channel, unsigned int start, unsigned int end )
|
||||
int CalypFrame::getMedian( unsigned channel, unsigned int start, unsigned int end ) const
|
||||
{
|
||||
if( !d->m_bHasHistogram || start < 0 || end > d->m_uiHistoSegments - 1 || start > end )
|
||||
{
|
||||
@@ -1146,7 +1146,7 @@ int CalypFrame::getMedian( unsigned channel, unsigned int start, unsigned int en
|
||||
return 0;
|
||||
}
|
||||
|
||||
double CalypFrame::getStdDev( unsigned channel, unsigned int start, unsigned int end )
|
||||
double CalypFrame::getStdDev( unsigned channel, unsigned int start, unsigned int end ) const
|
||||
{
|
||||
if( !d->m_bHasHistogram || start < 0 || end > d->m_uiHistoSegments - 1 || start > end )
|
||||
{
|
||||
@@ -1185,7 +1185,7 @@ double CalypFrame::getStdDev( unsigned channel, unsigned int start, unsigned int
|
||||
return sqrt( ( dev - count * mean * mean ) / ( count - 1 ) );
|
||||
}
|
||||
|
||||
double CalypFrame::getHistogramValue( unsigned channel, unsigned int bin )
|
||||
double CalypFrame::getHistogramValue( unsigned channel, unsigned int bin ) const
|
||||
{
|
||||
if( !d->m_bHasHistogram || bin < 0 || bin > d->m_uiHistoSegments - 1 )
|
||||
return 0.0;
|
||||
@@ -1200,7 +1200,7 @@ double CalypFrame::getHistogramValue( unsigned channel, unsigned int bin )
|
||||
return d->m_puiHistogram[indexStart + bin];
|
||||
}
|
||||
|
||||
double CalypFrame::getEntropy( unsigned channel, unsigned int start, unsigned int end )
|
||||
double CalypFrame::getEntropy( unsigned channel, unsigned int start, unsigned int end ) const
|
||||
{
|
||||
if( !d->m_bHasHistogram )
|
||||
return 0;
|
||||
|
||||
+12
-12
@@ -322,7 +322,7 @@ public:
|
||||
* Get pixel format information
|
||||
* @return pixel format name
|
||||
*/
|
||||
std::string getPelFmtName();
|
||||
std::string getPelFmtName() const;
|
||||
|
||||
/**
|
||||
* Get color space information
|
||||
@@ -512,18 +512,18 @@ public:
|
||||
};
|
||||
void calcHistogram();
|
||||
|
||||
unsigned int getMinimumPelValue( unsigned channel );
|
||||
unsigned int getMaximumPelValue( unsigned channel );
|
||||
unsigned int getMinimumPelValue( unsigned channel ) const;
|
||||
unsigned int getMaximumPelValue( unsigned channel ) const;
|
||||
|
||||
unsigned int getMaximum( unsigned channel );
|
||||
unsigned int getNumPixelsRange( unsigned channel, unsigned int start, unsigned int end );
|
||||
double getMean( unsigned channel, unsigned int start, unsigned int end );
|
||||
int getMedian( unsigned channel, unsigned int start, unsigned int end );
|
||||
double getStdDev( unsigned channel, unsigned int start, unsigned int end );
|
||||
double getHistogramValue( unsigned channel, unsigned int bin );
|
||||
unsigned int getNEBins( unsigned channel );
|
||||
int getNumHistogramSegment();
|
||||
double getEntropy( unsigned channel, unsigned int start, unsigned int end );
|
||||
unsigned int getMaximum( unsigned channel ) const;
|
||||
unsigned int getNumPixelsRange( unsigned channel, unsigned int start, unsigned int end ) const;
|
||||
double getMean( unsigned channel, unsigned int start, unsigned int end ) const;
|
||||
int getMedian( unsigned channel, unsigned int start, unsigned int end ) const;
|
||||
double getStdDev( unsigned channel, unsigned int start, unsigned int end ) const;
|
||||
double getHistogramValue( unsigned channel, unsigned int bin ) const;
|
||||
unsigned int getNEBins( unsigned channel ) const;
|
||||
int getNumHistogramSegment() const;
|
||||
double getEntropy( unsigned channel, unsigned int start, unsigned int end ) const;
|
||||
|
||||
/**
|
||||
* interface with OpenCV lib
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "StreamHandlerRaw.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <filesystem>
|
||||
|
||||
#include "CalypFrame.h"
|
||||
|
||||
@@ -61,7 +62,9 @@ bool StreamHandlerRaw::openHandler( std::string strFilename, bool bInput )
|
||||
return false;
|
||||
}
|
||||
calculateFrameNumber();
|
||||
m_strFormatName = "YUV";
|
||||
std::string fileExtension = std::filesystem::path{ strFilename }.extension();
|
||||
fileExtension.erase( fileExtension.begin() );
|
||||
m_strFormatName = clpUppercase( fileExtension );
|
||||
m_strCodecName = "Raw Video";
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <catch2/catch.hpp>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <variant>
|
||||
|
||||
#include "CalypFrame.h"
|
||||
@@ -67,6 +68,163 @@ TEST_CASE( "Can open a YUV 420p file", "CalypStream" )
|
||||
CHECK( frame->getPixel( 336, 278 ) == CalypPixel{ CLP_COLOR_YUV, 99, 111, 142 } );
|
||||
}
|
||||
|
||||
TEST_CASE( "Can open a YUV file", "CalypStream" )
|
||||
{
|
||||
constexpr int kWidth{ 352 };
|
||||
constexpr int kHeight{ 288 };
|
||||
constexpr int kBitsPel{ 8 };
|
||||
constexpr auto KEndianness{ CLP_INVALID_ENDIANESS };
|
||||
|
||||
auto common_checks = []( auto& stream ) {
|
||||
return stream.getWidth() == kWidth &&
|
||||
stream.getHeight() == kHeight &&
|
||||
stream.getBitsPerPixel() == kBitsPel &&
|
||||
stream.getFormatName() == "YUV" &&
|
||||
stream.getCodecName() == "Raw Video" &&
|
||||
stream.getEndianess() == CLP_BIG_ENDIAN;
|
||||
};
|
||||
SECTION( "YUV420p" )
|
||||
{
|
||||
constexpr auto kInputFormat{ CalypPixelFormats::CLP_YUV420P };
|
||||
const auto kFilename = getFileTestFilename( "Foreman.yuv" );
|
||||
REQUIRE( std::filesystem::exists( std::filesystem::path( kFilename ) ) );
|
||||
|
||||
CalypStream test_stream;
|
||||
auto result = test_stream.open( kFilename, kWidth, kHeight, kInputFormat, kBitsPel, KEndianness, kFrameRate, true );
|
||||
REQUIRE( result );
|
||||
CHECK( common_checks( test_stream ) );
|
||||
const auto* frame = test_stream.getCurrFrame();
|
||||
|
||||
CHECK( frame->getColorSpace() == CLP_COLOR_YUV );
|
||||
CHECK( frame->getPelFmtName() == "YUV420p" );
|
||||
CHECK( frame->getPelFormat() == kInputFormat );
|
||||
}
|
||||
SECTION( "YUV422p" )
|
||||
{
|
||||
constexpr auto kInputFormat{ CalypPixelFormats::CLP_YUV422P };
|
||||
const auto kFilename = getFileTestFilename( "Foreman_352x288_yuv422p.yuv" );
|
||||
REQUIRE( std::filesystem::exists( std::filesystem::path( kFilename ) ) );
|
||||
|
||||
CalypStream test_stream;
|
||||
auto result = test_stream.open( kFilename, kWidth, kHeight, kInputFormat, kBitsPel, KEndianness, kFrameRate, true );
|
||||
REQUIRE( result );
|
||||
CHECK( common_checks( test_stream ) );
|
||||
const auto* frame = test_stream.getCurrFrame();
|
||||
|
||||
CHECK( frame->getColorSpace() == CLP_COLOR_YUV );
|
||||
CHECK( frame->getPelFmtName() == "YUV422p" );
|
||||
CHECK( frame->getPelFormat() == kInputFormat );
|
||||
}
|
||||
SECTION( "YUV444p" )
|
||||
{
|
||||
constexpr auto kInputFormat{ CalypPixelFormats::CLP_YUV444P };
|
||||
const auto kFilename = getFileTestFilename( "Foreman_352x288_yuv444p.yuv" );
|
||||
REQUIRE( std::filesystem::exists( std::filesystem::path( kFilename ) ) );
|
||||
|
||||
CalypStream test_stream;
|
||||
auto result = test_stream.open( kFilename, kWidth, kHeight, kInputFormat, kBitsPel, KEndianness, kFrameRate, true );
|
||||
REQUIRE( result );
|
||||
CHECK( common_checks( test_stream ) );
|
||||
const auto* frame = test_stream.getCurrFrame();
|
||||
|
||||
CHECK( frame->getColorSpace() == CLP_COLOR_YUV );
|
||||
CHECK( frame->getPelFmtName() == "YUV444p" );
|
||||
CHECK( frame->getPelFormat() == kInputFormat );
|
||||
}
|
||||
SECTION( "YUYV422" )
|
||||
{
|
||||
constexpr auto kInputFormat{ CalypPixelFormats::CLP_YUYV422 };
|
||||
const auto kFilename = getFileTestFilename( "Foreman_352x288_yuyv422.yuv" );
|
||||
REQUIRE( std::filesystem::exists( std::filesystem::path( kFilename ) ) );
|
||||
|
||||
CalypStream test_stream;
|
||||
auto result = test_stream.open( kFilename, kWidth, kHeight, kInputFormat, kBitsPel, KEndianness, kFrameRate, true );
|
||||
REQUIRE( result );
|
||||
CHECK( common_checks( test_stream ) );
|
||||
const auto* frame = test_stream.getCurrFrame();
|
||||
|
||||
CHECK( frame->getColorSpace() == CLP_COLOR_YUV );
|
||||
CHECK( frame->getPelFmtName() == "YUYV422" );
|
||||
CHECK( frame->getPelFormat() == kInputFormat );
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE( "Can open a RGB file", "CalypStream" )
|
||||
{
|
||||
constexpr int kWidth{ 352 };
|
||||
constexpr int kHeight{ 288 };
|
||||
constexpr int kBitsPel{ 8 };
|
||||
constexpr auto KEndianness{ CLP_INVALID_ENDIANESS };
|
||||
|
||||
auto common_checks = []( auto& stream ) {
|
||||
return stream.getWidth() == kWidth &&
|
||||
stream.getHeight() == kHeight &&
|
||||
stream.getBitsPerPixel() == kBitsPel &&
|
||||
stream.getFormatName() == "YUV" &&
|
||||
stream.getCodecName() == "Raw Video" &&
|
||||
stream.getEndianess() == CLP_BIG_ENDIAN;
|
||||
};
|
||||
SECTION( "RGB24" )
|
||||
{
|
||||
constexpr auto kInputFormat{ CalypPixelFormats::CLP_RGB24 };
|
||||
const auto kFilename = getFileTestFilename( "Foreman_352x288_rgb24.yuv" );
|
||||
REQUIRE( std::filesystem::exists( std::filesystem::path( kFilename ) ) );
|
||||
CalypStream test_stream;
|
||||
auto result = test_stream.open( kFilename, kWidth, kHeight, kInputFormat, kBitsPel, KEndianness, kFrameRate, true );
|
||||
REQUIRE( result );
|
||||
CHECK( common_checks( test_stream ) );
|
||||
const auto* frame = test_stream.getCurrFrame();
|
||||
CHECK( frame->getColorSpace() == CLP_COLOR_RGB );
|
||||
CHECK( frame->getPelFmtName() == "RGB" );
|
||||
CHECK( frame->getPelFormat() == kInputFormat );
|
||||
|
||||
std::cout << test_stream.getFormatName();
|
||||
}
|
||||
|
||||
SECTION( "BGR24" )
|
||||
{
|
||||
constexpr auto kInputFormat{ CalypPixelFormats::CLP_BGR24 };
|
||||
const auto kFilename = getFileTestFilename( "Foreman_352x288_bgr24.yuv" );
|
||||
REQUIRE( std::filesystem::exists( std::filesystem::path( kFilename ) ) );
|
||||
CalypStream test_stream;
|
||||
auto result = test_stream.open( kFilename, kWidth, kHeight, kInputFormat, kBitsPel, KEndianness, kFrameRate, true );
|
||||
REQUIRE( result );
|
||||
CHECK( common_checks( test_stream ) );
|
||||
const auto* frame = test_stream.getCurrFrame();
|
||||
CHECK( frame->getColorSpace() == CLP_COLOR_RGB );
|
||||
CHECK( frame->getPelFmtName() == "BGR" );
|
||||
CHECK( frame->getPelFormat() == kInputFormat );
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE( "Can open a GRAY file", "CalypStream" )
|
||||
{
|
||||
constexpr int kWidth{ 352 };
|
||||
constexpr int kHeight{ 288 };
|
||||
constexpr int kBitsPel{ 8 };
|
||||
constexpr auto KEndianness{ CLP_INVALID_ENDIANESS };
|
||||
|
||||
auto common_checks = []( auto& stream ) {
|
||||
return stream.getWidth() == kWidth &&
|
||||
stream.getHeight() == kHeight &&
|
||||
stream.getBitsPerPixel() == kBitsPel &&
|
||||
stream.getFormatName() == "YUV" &&
|
||||
stream.getCodecName() == "Raw Video" &&
|
||||
stream.getEndianess() == CLP_BIG_ENDIAN;
|
||||
};
|
||||
constexpr auto kInputFormat{ CalypPixelFormats::CLP_GRAY };
|
||||
const auto kFilename = getFileTestFilename( "Foreman_352x288_gray.yuv" );
|
||||
REQUIRE( std::filesystem::exists( std::filesystem::path( kFilename ) ) );
|
||||
CalypStream test_stream;
|
||||
auto result = test_stream.open( kFilename, kWidth, kHeight, kInputFormat, kBitsPel, KEndianness, kFrameRate, true );
|
||||
REQUIRE( result );
|
||||
CHECK( common_checks( test_stream ) );
|
||||
const auto* frame = test_stream.getCurrFrame();
|
||||
CHECK( frame->getColorSpace() == CLP_COLOR_GRAY );
|
||||
CHECK( frame->getPelFmtName() == "GRAY" );
|
||||
CHECK( frame->getPelFormat() == kInputFormat );
|
||||
}
|
||||
|
||||
TEST_CASE( "Can open .batatas file as RAW video", "CalypStream" )
|
||||
{
|
||||
constexpr int kWidth{ 352 };
|
||||
@@ -109,7 +267,7 @@ TEST_CASE( "Can open .batatas file as RAW video", "CalypStream" )
|
||||
CHECK( test_stream.getWidth() == kWidth );
|
||||
CHECK( test_stream.getHeight() == kHeight );
|
||||
CHECK( test_stream.getBitsPerPixel() == kBitsPel );
|
||||
CHECK( test_stream.getFormatName() == "YUV" );
|
||||
CHECK( test_stream.getFormatName() == "BATATAS" );
|
||||
CHECK( test_stream.getCodecName() == "Raw Video" );
|
||||
CHECK( test_stream.getEndianess() == CLP_BIG_ENDIAN );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user