2013-11-20 09:25:49 +01:00
|
|
|
|
|
|
|
// STL includes
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
// Hyperion includes
|
|
|
|
#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
|
|
|
bool allLedsSet = true;
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
std::cerr << "No transform set for " << iLed << std::endl;
|
|
|
|
allLedsSet = false;
|
|
|
|
}
|
2013-11-20 09:25:49 +01:00
|
|
|
}
|
2013-11-22 11:48:10 +01:00
|
|
|
return allLedsSet;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<ColorRgb> MultiColorTransform::applyTransform(const std::vector<ColorRgb>& rawColors)
|
|
|
|
{
|
|
|
|
// Create a copy, as we will do the rest of the transformation in place
|
|
|
|
std::vector<ColorRgb> ledColors(rawColors);
|
|
|
|
|
2013-11-22 11:48:10 +01:00
|
|
|
const size_t itCnt = std::min(_ledTransforms.size(), rawColors.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);
|
|
|
|
color.red = transform->_rgbRedTransform.transform(color.red);
|
|
|
|
color.green = transform->_rgbGreenTransform.transform(color.green);
|
|
|
|
color.blue = transform->_rgbBlueTransform.transform(color.blue);
|
|
|
|
}
|
|
|
|
return ledColors;
|
|
|
|
}
|