mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Create MultiColorCorrection.cpp
Former-commit-id: 9a69072ba9306024338cfa03691c6705890bcee3
This commit is contained in:
parent
aeed93ac83
commit
27c41acdee
96
libsrc/hyperion/MultiColorCorrection.cpp
Normal file
96
libsrc/hyperion/MultiColorCorrection.cpp
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
|
||||||
|
// STL includes
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
// Hyperion includes
|
||||||
|
#include "MultiColorCorrection.h"
|
||||||
|
|
||||||
|
MultiColorCorrection::MultiColorCorrection(const unsigned ledCnt) :
|
||||||
|
_ledCorrections(ledCnt, nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
MultiColorCorrection::~MultiColorCorrection()
|
||||||
|
{
|
||||||
|
// Clean up all the transforms
|
||||||
|
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
|
||||||
|
{
|
||||||
|
bool allLedsSet = true;
|
||||||
|
for (unsigned iLed=0; iLed<_ledCorrections.size(); ++iLed)
|
||||||
|
{
|
||||||
|
if (_ledCorrections[iLed] == nullptr)
|
||||||
|
{
|
||||||
|
std::cerr << "No correction set for " << iLed << std::endl;
|
||||||
|
allLedsSet = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return allLedsSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<std::string> & MultiColorCorrection::getCorrectionIds()
|
||||||
|
{
|
||||||
|
return _correctionIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
ColorCorrection* MultiColorCorrection::getCorrection(const std::string& id)
|
||||||
|
{
|
||||||
|
// Iterate through the unique transforms until we find the one with the given id
|
||||||
|
for (ColorCorrection * correction : _correction)
|
||||||
|
{
|
||||||
|
if (correction->_id == id)
|
||||||
|
{
|
||||||
|
return correction;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The ColorTransform was not found
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<ColorRgb> MultiColorCorrection::applyCorrection(const std::vector<ColorRgb>& rawColors)
|
||||||
|
{
|
||||||
|
// Create a copy, as we will do the rest of the transformation in place
|
||||||
|
std::vector<ColorRgb> ledColors(rawColors);
|
||||||
|
|
||||||
|
const size_t itCnt = std::min(_ledCorrections.size(), rawColors.size());
|
||||||
|
for (size_t i=0; i<itCnt; ++i)
|
||||||
|
{
|
||||||
|
ColorCorrection * correction = _ledCorrections[i];
|
||||||
|
if (correction == nullptr)
|
||||||
|
{
|
||||||
|
// No transform set for this led (do nothing)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ColorRgb& color = ledColors[i];
|
||||||
|
|
||||||
|
color.red = correction->_rgbCorrection.correctionR(color.red);
|
||||||
|
color.green = correction->_rgbCorrection.correctionG(color.green);
|
||||||
|
color.blue = correction->_rgbCorrection.correctionB(color.blue);
|
||||||
|
}
|
||||||
|
return ledColors;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user