2013-11-20 09:25:49 +01:00
|
|
|
|
|
|
|
// STL includes
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
// Hyperion includes
|
2016-07-01 23:20:41 +02:00
|
|
|
#include <utils/Logger.h>
|
2013-11-20 09:25:49 +01:00
|
|
|
#include "MultiColorTransform.h"
|
|
|
|
|
2013-11-22 11:48:10 +01:00
|
|
|
MultiColorTransform::MultiColorTransform(const unsigned ledCnt) :
|
|
|
|
_ledTransforms(ledCnt, nullptr)
|
2013-11-20 09:25:49 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
MultiColorTransform::~MultiColorTransform()
|
|
|
|
{
|
|
|
|
// Clean up all the transforms
|
|
|
|
for (ColorTransform * transform : _transform)
|
|
|
|
{
|
|
|
|
delete transform;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-22 11:48:10 +01:00
|
|
|
void MultiColorTransform::addTransform(ColorTransform * transform)
|
2013-11-20 09:25:49 +01:00
|
|
|
{
|
2013-11-22 11:48:10 +01:00
|
|
|
_transformIds.push_back(transform->_id);
|
2013-11-20 09:25:49 +01:00
|
|
|
_transform.push_back(transform);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MultiColorTransform::setTransformForLed(const std::string& id, const unsigned startLed, const unsigned endLed)
|
|
|
|
{
|
|
|
|
assert(startLed <= endLed);
|
2013-11-22 11:48:10 +01:00
|
|
|
assert(endLed < _ledTransforms.size());
|
2013-11-20 09:25:49 +01:00
|
|
|
|
|
|
|
// Get the identified transform (don't care if is nullptr)
|
|
|
|
ColorTransform * transform = getTransform(id);
|
|
|
|
for (unsigned iLed=startLed; iLed<=endLed; ++iLed)
|
|
|
|
{
|
|
|
|
_ledTransforms[iLed] = transform;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-22 11:48:10 +01:00
|
|
|
bool MultiColorTransform::verifyTransforms() const
|
2013-11-20 09:25:49 +01:00
|
|
|
{
|
2013-11-22 11:48:10 +01:00
|
|
|
for (unsigned iLed=0; iLed<_ledTransforms.size(); ++iLed)
|
2013-11-20 09:25:49 +01:00
|
|
|
{
|
2013-11-22 11:48:10 +01:00
|
|
|
if (_ledTransforms[iLed] == nullptr)
|
|
|
|
{
|
2016-07-01 23:20:41 +02:00
|
|
|
Warning(Logger::getInstance("ColorTransform"), "No adjustment set for %d", iLed);
|
|
|
|
return false;
|
2013-11-22 11:48:10 +01:00
|
|
|
}
|
2013-11-20 09:25:49 +01:00
|
|
|
}
|
2016-07-01 23:20:41 +02:00
|
|
|
return true;
|
2013-11-22 11:48:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<std::string> & MultiColorTransform::getTransformIds()
|
|
|
|
{
|
|
|
|
return _transformIds;
|
2013-11-20 09:25:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ColorTransform* MultiColorTransform::getTransform(const std::string& id)
|
|
|
|
{
|
|
|
|
// Iterate through the unique transforms until we find the one with the given id
|
|
|
|
for (ColorTransform* transform : _transform)
|
|
|
|
{
|
|
|
|
if (transform->_id == id)
|
|
|
|
{
|
|
|
|
return transform;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The ColorTransform was not found
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-07-01 23:20:41 +02:00
|
|
|
void MultiColorTransform::applyTransform(std::vector<ColorRgb>& ledColors)
|
2013-11-20 09:25:49 +01:00
|
|
|
{
|
2016-07-01 23:20:41 +02:00
|
|
|
const size_t itCnt = std::min(_ledTransforms.size(), ledColors.size());
|
2013-11-20 09:25:49 +01:00
|
|
|
for (size_t i=0; i<itCnt; ++i)
|
|
|
|
{
|
|
|
|
ColorTransform* transform = _ledTransforms[i];
|
|
|
|
if (transform == nullptr)
|
|
|
|
{
|
|
|
|
// No transform set for this led (do nothing)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ColorRgb& color = ledColors[i];
|
|
|
|
|
|
|
|
transform->_hsvTransform.transform(color.red, color.green, color.blue);
|
2016-03-10 17:54:39 +01:00
|
|
|
transform->_hslTransform.transform(color.red, color.green, color.blue);
|
2013-11-20 09:25:49 +01:00
|
|
|
color.red = transform->_rgbRedTransform.transform(color.red);
|
|
|
|
color.green = transform->_rgbGreenTransform.transform(color.green);
|
|
|
|
color.blue = transform->_rgbBlueTransform.transform(color.blue);
|
|
|
|
}
|
|
|
|
}
|