2014-07-11 20:35:48 +04:00
|
|
|
#include "svkernelv2.h"
|
|
|
|
|
|
|
|
SvKernelV2::SvKernelV2()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SvKernelV2::~SvKernelV2()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-07-22 20:37:29 +04:00
|
|
|
int SvKernelV2::rgbDiff(QRgb left, QRgb right)
|
2014-07-11 20:35:48 +04:00
|
|
|
{
|
2014-07-22 20:37:29 +04:00
|
|
|
QColor cLeft(left);
|
|
|
|
QColor cRight(right);
|
2014-07-11 20:35:48 +04:00
|
|
|
|
2014-07-22 20:37:29 +04:00
|
|
|
int leftDiff = max(qBlue(left), qRed(left), qGreen(left)) -
|
|
|
|
min(qBlue(left), qRed(left), qGreen(left));
|
2014-07-18 20:48:42 +04:00
|
|
|
|
2014-07-22 20:37:29 +04:00
|
|
|
int rightDiff = max(qBlue(right), qRed(right), qGreen(right)) -
|
|
|
|
min(qBlue(right), qRed(right), qGreen(right));
|
2014-07-18 20:48:42 +04:00
|
|
|
|
2014-07-22 20:37:29 +04:00
|
|
|
int minDiff= leftDiff < rightDiff ? rightDiff : leftDiff;
|
2014-07-18 20:48:42 +04:00
|
|
|
|
2014-07-22 20:37:29 +04:00
|
|
|
int diff = cLeft.value() - cRight.value();
|
2014-07-23 15:44:35 +04:00
|
|
|
int hsvDiff = minDiff > 70 ? abs(cLeft.hsvHue() - cRight.hsvHue()) : 0;
|
2014-07-22 20:37:29 +04:00
|
|
|
if (hsvDiff > 180) {
|
|
|
|
hsvDiff = 360 - hsvDiff;
|
|
|
|
}
|
2014-07-18 20:48:42 +04:00
|
|
|
|
2014-07-23 15:44:35 +04:00
|
|
|
int dsign = sign(diff);
|
|
|
|
dsign = dsign == 0 ? 1 : dsign;
|
|
|
|
|
|
|
|
return /*dsign * ((rightDiff - leftDiff)>>2) + */diff /*+ (hsvDiff > 5 ? dsign * 10 : 0)*/;
|
2014-07-22 20:37:29 +04:00
|
|
|
}
|
2014-07-18 20:48:42 +04:00
|
|
|
|
2014-07-22 20:37:29 +04:00
|
|
|
void SvKernelV2::exec(int line)
|
|
|
|
{
|
2014-07-23 15:44:35 +04:00
|
|
|
QRgb vtop, top, right, bottom, vbottom, _xy, xy;
|
2014-07-18 20:48:42 +04:00
|
|
|
|
2014-07-23 15:44:35 +04:00
|
|
|
int __dX, _dX, dX, dX_,
|
|
|
|
__dY, _dY, dY, dY_;
|
2014-07-18 20:48:42 +04:00
|
|
|
|
2014-07-22 20:37:29 +04:00
|
|
|
int value;
|
2014-07-18 20:48:42 +04:00
|
|
|
|
2014-07-22 20:37:29 +04:00
|
|
|
for (int x = 0; x < m_result->getWidth(); x++) {
|
|
|
|
value = 0;
|
2014-07-18 20:48:42 +04:00
|
|
|
|
2014-07-23 15:44:35 +04:00
|
|
|
vtop = m_left->getPixelRGB(x - 1, line - 3);
|
|
|
|
top = m_left->getPixelRGB(x - 1, line - 2);
|
|
|
|
right = m_left->getPixelRGB(x, line - 1);
|
|
|
|
bottom = m_left->getPixelRGB(x - 1, line);
|
|
|
|
vbottom = m_left->getPixelRGB(x - 1, line + 1);
|
|
|
|
xy = m_left->getPixelRGB(x - 1, line - 1);
|
2014-07-18 20:48:42 +04:00
|
|
|
|
2014-07-22 20:37:29 +04:00
|
|
|
dX_ = rgbDiff(_xy, right);
|
|
|
|
dY_ = rgbDiff(vtop, top);
|
|
|
|
dY = rgbDiff(top, _xy);
|
|
|
|
_dY = rgbDiff(_xy, bottom);
|
2014-07-23 15:44:35 +04:00
|
|
|
__dY = rgbDiff(bottom, vbottom);
|
|
|
|
|
|
|
|
if ( dX >= _dX && dX > dX_ ||
|
|
|
|
dX <= _dX && dX < dX_) {
|
|
|
|
if (dX == _dX) {
|
|
|
|
if (dX > dX_ && _dX > __dX ||
|
|
|
|
dX < dX_ && _dX < __dX) {
|
|
|
|
value += abs(dX);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
value += abs(dX);
|
|
|
|
}
|
2014-07-22 20:37:29 +04:00
|
|
|
}
|
2014-07-18 20:48:42 +04:00
|
|
|
|
2014-07-23 15:44:35 +04:00
|
|
|
if ( dY >= _dY && dY > dY_ ||
|
|
|
|
dY <= _dY && dY < dY_) {
|
|
|
|
|
|
|
|
if (dY == _dY) {
|
|
|
|
if (dY > dY_ && _dY > __dY ||
|
|
|
|
dY < dY_ && _dY < __dY) {
|
2014-07-18 20:48:42 +04:00
|
|
|
|
2014-07-23 15:44:35 +04:00
|
|
|
value += abs(dY);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
value += abs(dY);
|
|
|
|
}
|
2014-07-18 20:48:42 +04:00
|
|
|
}
|
|
|
|
|
2014-07-22 20:37:29 +04:00
|
|
|
if (value > 0) {
|
|
|
|
m_result->putGrayPixel(x - 1, line - 1, value);
|
2014-07-18 20:48:42 +04:00
|
|
|
}
|
|
|
|
|
2014-07-23 15:44:35 +04:00
|
|
|
__dX = _dX;
|
2014-07-22 20:37:29 +04:00
|
|
|
_dX = dX;
|
|
|
|
dX = dX_;
|
|
|
|
_xy = right;
|
|
|
|
}
|
2014-07-11 20:35:48 +04:00
|
|
|
}
|
2014-07-22 20:37:29 +04:00
|
|
|
|