2015-12-22 10:08:55 +01:00
|
|
|
|
|
|
|
// STL includes
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
// Hyperion includes
|
2016-07-01 23:20:41 +02:00
|
|
|
#include <utils/Logger.h>
|
2015-12-22 10:08:55 +01:00
|
|
|
#include "MultiColorCorrection.h"
|
|
|
|
|
|
|
|
MultiColorCorrection::MultiColorCorrection(const unsigned ledCnt) :
|
|
|
|
_ledCorrections(ledCnt, nullptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
MultiColorCorrection::~MultiColorCorrection()
|
|
|
|
{
|
2015-12-22 10:13:01 +01:00
|
|
|
// Clean up all the correctinos
|
2015-12-22 10:08:55 +01:00
|
|
|
for (ColorCorrection * correction : _correction)
|
|
|
|
{
|
|
|
|
delete correction;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MultiColorCorrection::addCorrection(ColorCorrection * correction)
|
|
|
|
{
|
|
|
|
_correctionIds.push_back(correction->_id);
|
|
|
|
_correction.push_back(correction);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MultiColorCorrection::setCorrectionForLed(const std::string& id, const unsigned startLed, const unsigned endLed)
|
|
|
|
{
|
|
|
|
assert(startLed <= endLed);
|
|
|
|
assert(endLed < _ledCorrections.size());
|
|
|
|
|
|
|
|
// Get the identified correction (don't care if is nullptr)
|
|
|
|
ColorCorrection * correction = getCorrection(id);
|
|
|
|
for (unsigned iLed=startLed; iLed<=endLed; ++iLed)
|
|
|
|
{
|
|
|
|
_ledCorrections[iLed] = correction;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MultiColorCorrection::verifyCorrections() const
|
|
|
|
{
|
|
|
|
for (unsigned iLed=0; iLed<_ledCorrections.size(); ++iLed)
|
|
|
|
{
|
|
|
|
if (_ledCorrections[iLed] == nullptr)
|
|
|
|
{
|
2016-07-01 23:20:41 +02:00
|
|
|
Warning(Logger::getInstance("ColorCorrect"), "No adjustment set for %d", iLed);
|
|
|
|
return false;
|
2015-12-22 10:08:55 +01:00
|
|
|
}
|
|
|
|
}
|
2016-07-01 23:20:41 +02:00
|
|
|
return true;
|
2015-12-22 10:08:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<std::string> & MultiColorCorrection::getCorrectionIds()
|
|
|
|
{
|
|
|
|
return _correctionIds;
|
|
|
|
}
|
|
|
|
|
|
|
|
ColorCorrection* MultiColorCorrection::getCorrection(const std::string& id)
|
|
|
|
{
|
2015-12-22 10:13:01 +01:00
|
|
|
// Iterate through the unique corrections until we find the one with the given id
|
2015-12-22 10:08:55 +01:00
|
|
|
for (ColorCorrection * correction : _correction)
|
|
|
|
{
|
|
|
|
if (correction->_id == id)
|
|
|
|
{
|
|
|
|
return correction;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-22 10:13:01 +01:00
|
|
|
// The ColorCorrection was not found
|
2015-12-22 10:08:55 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-07-01 23:20:41 +02:00
|
|
|
void MultiColorCorrection::applyCorrection(std::vector<ColorRgb>& ledColors)
|
2015-12-22 10:08:55 +01:00
|
|
|
{
|
2016-07-01 23:20:41 +02:00
|
|
|
const size_t itCnt = std::min(_ledCorrections.size(), ledColors.size());
|
2015-12-22 10:08:55 +01:00
|
|
|
for (size_t i=0; i<itCnt; ++i)
|
|
|
|
{
|
|
|
|
ColorCorrection * correction = _ledCorrections[i];
|
|
|
|
if (correction == nullptr)
|
|
|
|
{
|
2015-12-22 10:13:01 +01:00
|
|
|
// No correction set for this led (do nothing)
|
2015-12-22 10:08:55 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ColorRgb& color = ledColors[i];
|
|
|
|
|
2016-07-04 00:43:41 +02:00
|
|
|
color.red = correction->_rgbCorrection.adjustmentR(color.red);
|
|
|
|
color.green = correction->_rgbCorrection.adjustmentG(color.green);
|
|
|
|
color.blue = correction->_rgbCorrection.adjustmentB(color.blue);
|
2015-12-22 10:08:55 +01:00
|
|
|
}
|
|
|
|
}
|