hyperion.ng/libsrc/hyperion/BlackBorderProcessor.cpp
T. van der Zwan dd16af0df5 Changed RgbImage to template based Image (with template for pixel type)
Former-commit-id: ef02f164eaf3c2f9dd552c1c17b525cf6eed499c
2013-11-11 09:00:37 +00:00

84 lines
1.8 KiB
C++

// Local-Hyperion includes
#include <hyperion/BlackBorderProcessor.h>
using namespace hyperion;
BlackBorderProcessor::BlackBorderProcessor(
const unsigned unknownFrameCnt,
const unsigned borderFrameCnt,
const unsigned blurRemoveCnt) :
_unknownSwitchCnt(unknownFrameCnt),
_borderSwitchCnt(borderFrameCnt),
_blurRemoveCnt(blurRemoveCnt),
_detector(),
_currentBorder({true, -1, -1}),
_previousDetectedBorder({true, -1, -1}),
_consistentCnt(0)
{
// empty
}
BlackBorder BlackBorderProcessor::getCurrentBorder() const
{
return _currentBorder;
}
bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder)
{
// set the consistency counter
if (newDetectedBorder == _previousDetectedBorder)
{
++_consistentCnt;
}
else
{
_previousDetectedBorder = newDetectedBorder;
_consistentCnt = 0;
}
// check if there is a change
if (_currentBorder == newDetectedBorder)
{
// No change required
return false;
}
bool borderChanged = false;
if (newDetectedBorder.unknown)
{
// apply the unknown border if we consistently can't determine a border
if (_consistentCnt == _unknownSwitchCnt)
{
_currentBorder = newDetectedBorder;
borderChanged = true;
}
}
else
{
// apply the detected border if it has been detected consistently
if (_currentBorder.unknown || _consistentCnt == _borderSwitchCnt)
{
_currentBorder = newDetectedBorder;
borderChanged = true;
}
else
{
// apply smaller borders immediately
if (newDetectedBorder.verticalSize < _currentBorder.verticalSize)
{
_currentBorder.verticalSize = newDetectedBorder.verticalSize;
borderChanged = true;
}
if (newDetectedBorder.horizontalSize < _currentBorder.horizontalSize)
{
_currentBorder.horizontalSize = newDetectedBorder.horizontalSize;
borderChanged = true;
}
}
}
return borderChanged;
}