2013-08-21 16:25:27 +02:00
|
|
|
#include "BlackBorderDetector.h"
|
|
|
|
|
|
|
|
BlackBorderDetector::BlackBorderDetector()
|
|
|
|
{
|
2013-08-21 16:52:03 +02:00
|
|
|
// empty
|
2013-08-21 16:25:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BlackBorder BlackBorderDetector::process(const RgbImage& image)
|
|
|
|
{
|
|
|
|
int firstNonBlackPixelTop = -1;
|
|
|
|
int firstNonBlackPixelLeft = -1;
|
|
|
|
|
2013-08-21 16:52:03 +02:00
|
|
|
// Find the non-black pixel at the top-half border
|
|
|
|
for (unsigned x=0; x<image.width()/2; ++x)
|
2013-08-21 16:25:27 +02:00
|
|
|
{
|
|
|
|
const RgbColor& color = image(x, 0);
|
|
|
|
if (!isBlack(color))
|
|
|
|
{
|
|
|
|
firstNonBlackPixelTop = x;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-08-21 16:52:03 +02:00
|
|
|
// Find the non-black pixel at the left-half border
|
|
|
|
for (unsigned y=0; y<image.height()/2; ++y)
|
2013-08-21 16:25:27 +02:00
|
|
|
{
|
|
|
|
const RgbColor& color = image(0, y);
|
|
|
|
if (!isBlack(color))
|
|
|
|
{
|
|
|
|
firstNonBlackPixelLeft = y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-21 16:52:03 +02:00
|
|
|
// Construct 'unknown' result
|
2013-08-21 16:25:27 +02:00
|
|
|
BlackBorder detectedBorder;
|
|
|
|
detectedBorder.type = BlackBorder::unknown;
|
|
|
|
|
|
|
|
if (firstNonBlackPixelTop == 0 /*&& firstNonBlackPixelLeft == 0*/)
|
|
|
|
{
|
|
|
|
// No black border
|
|
|
|
// C-?-?-? ...
|
|
|
|
// ? +----
|
|
|
|
// ? |
|
|
|
|
// ? |
|
|
|
|
// :
|
|
|
|
|
|
|
|
detectedBorder.type = BlackBorder::none;
|
|
|
|
detectedBorder.size = -1;
|
|
|
|
}
|
|
|
|
else if (firstNonBlackPixelTop < 0)
|
|
|
|
{
|
2013-08-21 16:52:03 +02:00
|
|
|
if (firstNonBlackPixelLeft < 0)
|
2013-08-21 16:25:27 +02:00
|
|
|
{
|
|
|
|
// We don't know
|
2013-08-21 16:52:03 +02:00
|
|
|
// B-B-B-B ...
|
|
|
|
// B +---- ...
|
2013-08-21 16:25:27 +02:00
|
|
|
// B |
|
|
|
|
// B |
|
|
|
|
// :
|
|
|
|
|
|
|
|
detectedBorder.type = BlackBorder::unknown;
|
|
|
|
detectedBorder.size = -1;
|
|
|
|
}
|
2013-08-21 16:52:03 +02:00
|
|
|
else //(firstNonBlackPixelLeft > 0)
|
2013-08-21 16:25:27 +02:00
|
|
|
{
|
|
|
|
// Border at top of screen
|
2013-08-21 16:52:03 +02:00
|
|
|
// B-B-B-B ...
|
|
|
|
// B +---- ...
|
2013-08-21 16:25:27 +02:00
|
|
|
// C |
|
|
|
|
// ? |
|
|
|
|
// :
|
|
|
|
|
|
|
|
detectedBorder.type = BlackBorder::horizontal;
|
|
|
|
detectedBorder.size = firstNonBlackPixelLeft;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // (firstNonBlackPixelTop > 0)
|
|
|
|
{
|
2013-08-21 16:52:03 +02:00
|
|
|
if (firstNonBlackPixelLeft < 0)
|
2013-08-21 16:25:27 +02:00
|
|
|
{
|
|
|
|
// Border at left of screen
|
|
|
|
// B-B-C-? ...
|
2013-08-21 16:52:03 +02:00
|
|
|
// B +---- ...
|
2013-08-21 16:25:27 +02:00
|
|
|
// B |
|
|
|
|
// B |
|
|
|
|
// :
|
|
|
|
|
|
|
|
detectedBorder.type = BlackBorder::vertical;
|
|
|
|
detectedBorder.size = firstNonBlackPixelTop;
|
|
|
|
}
|
2013-08-21 16:52:03 +02:00
|
|
|
else //(firstNonBlackPixelLeft > 0)
|
2013-08-21 16:25:27 +02:00
|
|
|
{
|
|
|
|
// No black border
|
|
|
|
// B-B-C-? ...
|
|
|
|
// B +----
|
|
|
|
// C |
|
|
|
|
// ? |
|
|
|
|
// :
|
|
|
|
|
|
|
|
detectedBorder.type = BlackBorder::none;
|
|
|
|
detectedBorder.size = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return detectedBorder;
|
|
|
|
}
|