mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
a3e59f0243
Former-commit-id: ed6dd4e6872ea69d682096a82e108a3f7e7ca4ae
142 lines
2.8 KiB
C++
142 lines
2.8 KiB
C++
|
|
// STL includes
|
|
#include <random>
|
|
|
|
// Hyperion includes
|
|
#include "hyperion/BlackBorderDetector.h"
|
|
|
|
using namespace hyperion;
|
|
|
|
RgbColor randomColor()
|
|
{
|
|
const uint8_t randomRedValue = uint8_t(rand() % (std::numeric_limits<uint8_t>::max() + 1));
|
|
const uint8_t randomGreenValue = uint8_t(rand() % (std::numeric_limits<uint8_t>::max() + 1));
|
|
const uint8_t randomBlueValue = uint8_t(rand() % (std::numeric_limits<uint8_t>::max() + 1));
|
|
|
|
return {randomRedValue, randomGreenValue, randomBlueValue};
|
|
}
|
|
|
|
RgbImage createImage(unsigned width, unsigned height, unsigned topBorder, unsigned leftBorder)
|
|
{
|
|
RgbImage image(width, height);
|
|
for (unsigned x=0; x<image.width(); ++x)
|
|
{
|
|
for (unsigned y=0; y<image.height(); ++y)
|
|
{
|
|
if (y < topBorder || x < leftBorder)
|
|
{
|
|
image(x,y) = RgbColor::BLACK;
|
|
}
|
|
else
|
|
{
|
|
image(x,y) = randomColor();
|
|
}
|
|
}
|
|
}
|
|
return image;
|
|
}
|
|
|
|
int TC_NO_BORDER()
|
|
{
|
|
int result = 0;
|
|
|
|
BlackBorderDetector detector;
|
|
|
|
{
|
|
RgbImage image = createImage(64, 64, 0, 0);
|
|
BlackBorder border = detector.process(image);
|
|
if (border.unknown != false && border.horizontalSize != 0 && border.verticalSize != 0)
|
|
{
|
|
std::cerr << "Failed to correctly detect no border" << std::endl;
|
|
result = -1;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
int TC_TOP_BORDER()
|
|
{
|
|
int result = 0;
|
|
|
|
BlackBorderDetector detector;
|
|
|
|
{
|
|
RgbImage image = createImage(64, 64, 12, 0);
|
|
BlackBorder border = detector.process(image);
|
|
if (border.unknown != false && border.horizontalSize != 12 && border.verticalSize != 0)
|
|
{
|
|
std::cerr << "Failed to correctly detect horizontal border with correct size" << std::endl;
|
|
result = -1;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
int TC_LEFT_BORDER()
|
|
{
|
|
int result = 0;
|
|
|
|
BlackBorderDetector detector;
|
|
|
|
{
|
|
RgbImage image = createImage(64, 64, 0, 12);
|
|
BlackBorder border = detector.process(image);
|
|
if (border.unknown != false && border.horizontalSize != 0 && border.verticalSize != 12)
|
|
{
|
|
std::cerr << "Failed to detected vertical border with correct size" << std::endl;
|
|
result = -1;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
int TC_DUAL_BORDER()
|
|
{
|
|
int result = 0;
|
|
|
|
BlackBorderDetector detector;
|
|
|
|
{
|
|
RgbImage image = createImage(64, 64, 12, 12);
|
|
BlackBorder border = detector.process(image);
|
|
if (border.unknown != false && border.horizontalSize != 12 && border.verticalSize != 12)
|
|
{
|
|
std::cerr << "Failed to detected two-sided border" << std::endl;
|
|
result = -1;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
int TC_UNKNOWN_BORDER()
|
|
{
|
|
int result = 0;
|
|
|
|
BlackBorderDetector detector;
|
|
|
|
{
|
|
RgbImage image = createImage(64, 64, 30, 30);
|
|
BlackBorder border = detector.process(image);
|
|
if (border.unknown != true)
|
|
{
|
|
std::cerr << "Failed to detected unknown border" << std::endl;
|
|
result = -1;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
int main()
|
|
{
|
|
TC_NO_BORDER();
|
|
TC_TOP_BORDER();
|
|
TC_LEFT_BORDER();
|
|
TC_DUAL_BORDER();
|
|
TC_UNKNOWN_BORDER();
|
|
|
|
return 0;
|
|
}
|