mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
b37cbd26d5
* Channel adjustment config * Create RgbChannelAdjustment.h * Delete RgbChannelAdjustment.h * Create RgbChannelAdjustment.cpp * Create RgbChannelAdjustment.h * Delete RgbChannelAdjustment.cpp * Create ColorAdjustment.cpp * Delete RgbChannelAdjustment.h * Create ColorAdjustment.h * Update ColorAdjustment.h * Update ColorAdjustment.h * Update ColorAdjustment.h * Update ColorAdjustment.cpp * Update Hyperion.cpp * Update Hyperion.cpp * Update Hyperion.cpp * Update Hyperion.h * Create RgbChannelAdjustment.cpp * Create RgbChannelAdjustment.h * Create ColorAdjustment.h * Create MultiColorAdjustment.h * Update MultiColorAdjustment.h * Create MultiColorAdjustment.cpp * Delete ColorAdjustment.cpp * Delete ColorAdjustment.h * Update RgbChannelAdjustment.cpp * Update Hyperion.cpp * Update Hyperion.h * Update Hyperion.cpp * Bug fixes * Update hyperion.config.json * Add color adjustment to json server and client and adapt hyperion-remote * Change the color modification order * Minor bug fix * Create calibration Images folder * Create calibration Gamma folder * Create calibration RGB folder * Added files via upload * Delete .gitkeep * Delete .gitkeep * Added files via upload * Delete .gitkeep * Update color effect order and don't correct twice * Uploaded gradient images Former-commit-id: 8ab465e59834f12a21709a6f4546bd6808a2a495
125 lines
3.3 KiB
C++
125 lines
3.3 KiB
C++
|
|
// STL includes
|
|
#include <cassert>
|
|
|
|
// Hyperion includes
|
|
#include "MultiColorAdjustment.h"
|
|
|
|
MultiColorAdjustment::MultiColorAdjustment(const unsigned ledCnt) :
|
|
_ledAdjustments(ledCnt, nullptr)
|
|
{
|
|
}
|
|
|
|
MultiColorAdjustment::~MultiColorAdjustment()
|
|
{
|
|
// Clean up all the transforms
|
|
for (ColorAdjustment * adjustment : _adjustment)
|
|
{
|
|
delete adjustment;
|
|
}
|
|
}
|
|
|
|
void MultiColorAdjustment::addAdjustment(ColorAdjustment * adjustment)
|
|
{
|
|
_adjustmentIds.push_back(adjustment->_id);
|
|
_adjustment.push_back(adjustment);
|
|
}
|
|
|
|
void MultiColorAdjustment::setAdjustmentForLed(const std::string& id, const unsigned startLed, const unsigned endLed)
|
|
{
|
|
assert(startLed <= endLed);
|
|
assert(endLed < _ledAdjustments.size());
|
|
|
|
// Get the identified adjustment (don't care if is nullptr)
|
|
ColorAdjustment * adjustment = getAdjustment(id);
|
|
for (unsigned iLed=startLed; iLed<=endLed; ++iLed)
|
|
{
|
|
_ledAdjustments[iLed] = adjustment;
|
|
}
|
|
}
|
|
|
|
bool MultiColorAdjustment::verifyAdjustments() const
|
|
{
|
|
bool allLedsSet = true;
|
|
for (unsigned iLed=0; iLed<_ledAdjustments.size(); ++iLed)
|
|
{
|
|
if (_ledAdjustments[iLed] == nullptr)
|
|
{
|
|
std::cerr << "HYPERION (C.adjustment) ERROR: No adjustment set for " << iLed << std::endl;
|
|
allLedsSet = false;
|
|
}
|
|
}
|
|
return allLedsSet;
|
|
}
|
|
|
|
const std::vector<std::string> & MultiColorAdjustment::getAdjustmentIds()
|
|
{
|
|
return _adjustmentIds;
|
|
}
|
|
|
|
ColorAdjustment* MultiColorAdjustment::getAdjustment(const std::string& id)
|
|
{
|
|
// Iterate through the unique adjustments until we find the one with the given id
|
|
for (ColorAdjustment* adjustment : _adjustment)
|
|
{
|
|
if (adjustment->_id == id)
|
|
{
|
|
return adjustment;
|
|
}
|
|
}
|
|
|
|
// The ColorAdjustment was not found
|
|
return nullptr;
|
|
}
|
|
|
|
std::vector<ColorRgb> MultiColorAdjustment::applyAdjustment(const std::vector<ColorRgb>& rawColors)
|
|
{
|
|
// Create a copy, as we will do the rest of the adjustment in place
|
|
std::vector<ColorRgb> ledColors(rawColors);
|
|
|
|
const size_t itCnt = std::min(_ledAdjustments.size(), rawColors.size());
|
|
for (size_t i=0; i<itCnt; ++i)
|
|
{
|
|
ColorAdjustment* adjustment = _ledAdjustments[i];
|
|
if (adjustment == nullptr)
|
|
{
|
|
// No transform set for this led (do nothing)
|
|
continue;
|
|
}
|
|
ColorRgb& color = ledColors[i];
|
|
|
|
int RR = adjustment->_rgbRedAdjustment.adjustmentR(color.red);
|
|
int RG = adjustment->_rgbRedAdjustment.adjustmentG(color.red);
|
|
int RB = adjustment->_rgbRedAdjustment.adjustmentB(color.red);
|
|
int GR = adjustment->_rgbGreenAdjustment.adjustmentR(color.green);
|
|
int GG = adjustment->_rgbGreenAdjustment.adjustmentG(color.green);
|
|
int GB = adjustment->_rgbGreenAdjustment.adjustmentB(color.green);
|
|
int BR = adjustment->_rgbBlueAdjustment.adjustmentR(color.blue);
|
|
int BG = adjustment->_rgbBlueAdjustment.adjustmentG(color.blue);
|
|
int BB = adjustment->_rgbBlueAdjustment.adjustmentB(color.blue);
|
|
|
|
int ledR = RR + GR + BR;
|
|
int maxR = (int)adjustment->_rgbRedAdjustment.getadjustmentR();
|
|
int ledG = RG + GG + BG;
|
|
int maxG = (int)adjustment->_rgbGreenAdjustment.getadjustmentG();
|
|
int ledB = RB + GB + BB;
|
|
int maxB = (int)adjustment->_rgbBlueAdjustment.getadjustmentB();
|
|
|
|
if (ledR > maxR)
|
|
color.red = (uint8_t)maxR;
|
|
else
|
|
color.red = (uint8_t)ledR;
|
|
|
|
if (ledG > maxG)
|
|
color.green = (uint8_t)maxG;
|
|
else
|
|
color.green = (uint8_t)ledG;
|
|
|
|
if (ledB > maxB)
|
|
color.blue = (uint8_t)maxB;
|
|
else
|
|
color.blue = (uint8_t)ledB;
|
|
}
|
|
return ledColors;
|
|
}
|