Smoothing Fix (#727)

Increase color change for small RGB differences.
This commit is contained in:
Robin Kobus 2017-10-08 18:28:15 +02:00 committed by brindosch
parent 47d087a46f
commit 1c212321a4
2 changed files with 12 additions and 3 deletions

View File

@ -77,6 +77,7 @@ void LinearColorSmoothing::updateLeds()
if (deltaTime < 0)
{
memcpy(_previousValues.data(), _targetValues.data(), _targetValues.size() * sizeof(ColorRgb));
_previousTime = now;
queueColors(_previousValues);
@ -87,14 +88,20 @@ void LinearColorSmoothing::updateLeds()
_writeToLedsEnable = true;
float k = 1.0f - 1.0f * deltaTime / (_targetTime - _previousTime);
int reddif = 0, greendif = 0, bluedif = 0;
for (size_t i = 0; i < _previousValues.size(); ++i)
{
ColorRgb & prev = _previousValues[i];
ColorRgb & target = _targetValues[i];
prev.red += k * (target.red - prev.red);
prev.green += k * (target.green - prev.green);
prev.blue += k * (target.blue - prev.blue);
reddif = target.red - prev.red;
greendif = target.green - prev.green;
bluedif = target.blue - prev.blue;
prev.red += (reddif < 0 ? -1:1) * ceil(k * abs(reddif));
prev.green += (greendif < 0 ? -1:1) * ceil(k * abs(greendif));
prev.blue += (bluedif < 0 ? -1:1) * ceil(k * abs(bluedif));
}
_previousTime = now;

View File

@ -3,6 +3,8 @@
// STL includes
#include <string>
#include <vector>
#include <stdlib.h>
#include <math.h>
// Qt includes
#include <QTimer>