mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
refactoring of RgbChannelAdjustment (#79)
* common ledbuffer for color transform hyperion class uses a common buffer for all operations on ledColors got from muxer all color transforms uses new ledBuffer instead of making copies of ledbuffer other fixes: fix compile bug in profiler update doxygen config * migrate logging for color transform classes * prepare new logger in hyperion class * implement hwledcount * Update Hyperion.cpp Fix off color * remove ledscount equivalent from apa102 migrate logging in hyperion.cpp remove unused and duuplicate colorcorrection - but same is available through tempertature * remove colorcorrection completly fix compile * set colororder back to static * in remote: using correction is the same as using temperature - correction is obsolete, command not delete atm for compat reasons * refactoring of RgbChannelAdjustment
This commit is contained in:
parent
36b4d072c5
commit
921f164b26
@ -15,29 +15,34 @@ public:
|
||||
/// @param adjustR
|
||||
/// @param adjustG
|
||||
/// @param adjustB
|
||||
|
||||
RgbChannelAdjustment(int adjustR, int adjustG, int adjustB);
|
||||
RgbChannelAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB);
|
||||
|
||||
/// Destructor
|
||||
~RgbChannelAdjustment();
|
||||
|
||||
/// @return The current adjustR value
|
||||
uint8_t getadjustmentR() const;
|
||||
uint8_t getAdjustmentR() const;
|
||||
|
||||
/// setAdjustment RGB
|
||||
/// @param adjustR
|
||||
/// @param adjustG
|
||||
/// @param adjustB
|
||||
void setAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB);
|
||||
|
||||
/// @param threshold New adjustR value
|
||||
void setadjustmentR(uint8_t adjustR);
|
||||
void setAdjustmentR(uint8_t adjustR);
|
||||
|
||||
/// @return The current adjustG value
|
||||
uint8_t getadjustmentG() const;
|
||||
uint8_t getAdjustmentG() const;
|
||||
|
||||
/// @param gamma New adjustG value
|
||||
void setadjustmentG(uint8_t adjustG);
|
||||
void setAdjustmentG(uint8_t adjustG);
|
||||
|
||||
/// @return The current adjustB value
|
||||
uint8_t getadjustmentB() const;
|
||||
uint8_t getAdjustmentB() const;
|
||||
|
||||
/// @param blacklevel New adjustB value
|
||||
void setadjustmentB(uint8_t adjustB);
|
||||
void setAdjustmentB(uint8_t adjustB);
|
||||
|
||||
/// Transform the given array value
|
||||
/// @param input The input color bytes
|
||||
@ -48,19 +53,15 @@ public:
|
||||
|
||||
|
||||
private:
|
||||
/// color channels
|
||||
enum ColorChannel { RED=0,GREEN=1, BLUE=2 };
|
||||
|
||||
/// (re)-initilize the color mapping
|
||||
void initializeMapping();
|
||||
|
||||
private:
|
||||
/// The adjustment of R channel
|
||||
int _adjustR;
|
||||
/// The adjustment of G channel
|
||||
int _adjustG;
|
||||
/// The adjustment of B channel
|
||||
int _adjustB;
|
||||
|
||||
/// The adjustment of RGB channel
|
||||
uint8_t _adjust[3];
|
||||
|
||||
/// The mapping from input color to output color
|
||||
int _mappingR[256];
|
||||
int _mappingG[256];
|
||||
int _mappingB[256];
|
||||
uint8_t _mapping[3][256];
|
||||
};
|
||||
|
@ -98,11 +98,11 @@ void MultiColorAdjustment::applyAdjustment(std::vector<ColorRgb>& ledColors)
|
||||
int BB = adjustment->_rgbBlueAdjustment.adjustmentB(color.blue);
|
||||
|
||||
int ledR = RR + GR + BR;
|
||||
int maxR = (int)adjustment->_rgbRedAdjustment.getadjustmentR();
|
||||
int maxR = (int)adjustment->_rgbRedAdjustment.getAdjustmentR();
|
||||
int ledG = RG + GG + BG;
|
||||
int maxG = (int)adjustment->_rgbGreenAdjustment.getadjustmentG();
|
||||
int maxG = (int)adjustment->_rgbGreenAdjustment.getAdjustmentG();
|
||||
int ledB = RB + GB + BB;
|
||||
int maxB = (int)adjustment->_rgbBlueAdjustment.getadjustmentB();
|
||||
int maxB = (int)adjustment->_rgbBlueAdjustment.getAdjustmentB();
|
||||
|
||||
if (ledR > maxR)
|
||||
color.red = (uint8_t)maxR;
|
||||
|
@ -470,17 +470,17 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &)
|
||||
adjustment["id"] = adjustmentId;
|
||||
|
||||
Json::Value & redAdjust = adjustment["redAdjust"];
|
||||
redAdjust.append(colorAdjustment->_rgbRedAdjustment.getadjustmentR());
|
||||
redAdjust.append(colorAdjustment->_rgbRedAdjustment.getadjustmentG());
|
||||
redAdjust.append(colorAdjustment->_rgbRedAdjustment.getadjustmentB());
|
||||
redAdjust.append(colorAdjustment->_rgbRedAdjustment.getAdjustmentR());
|
||||
redAdjust.append(colorAdjustment->_rgbRedAdjustment.getAdjustmentG());
|
||||
redAdjust.append(colorAdjustment->_rgbRedAdjustment.getAdjustmentB());
|
||||
Json::Value & greenAdjust = adjustment["greenAdjust"];
|
||||
greenAdjust.append(colorAdjustment->_rgbGreenAdjustment.getadjustmentR());
|
||||
greenAdjust.append(colorAdjustment->_rgbGreenAdjustment.getadjustmentG());
|
||||
greenAdjust.append(colorAdjustment->_rgbGreenAdjustment.getadjustmentB());
|
||||
greenAdjust.append(colorAdjustment->_rgbGreenAdjustment.getAdjustmentR());
|
||||
greenAdjust.append(colorAdjustment->_rgbGreenAdjustment.getAdjustmentG());
|
||||
greenAdjust.append(colorAdjustment->_rgbGreenAdjustment.getAdjustmentB());
|
||||
Json::Value & blueAdjust = adjustment["blueAdjust"];
|
||||
blueAdjust.append(colorAdjustment->_rgbBlueAdjustment.getadjustmentR());
|
||||
blueAdjust.append(colorAdjustment->_rgbBlueAdjustment.getadjustmentG());
|
||||
blueAdjust.append(colorAdjustment->_rgbBlueAdjustment.getadjustmentB());
|
||||
blueAdjust.append(colorAdjustment->_rgbBlueAdjustment.getAdjustmentR());
|
||||
blueAdjust.append(colorAdjustment->_rgbBlueAdjustment.getAdjustmentG());
|
||||
blueAdjust.append(colorAdjustment->_rgbBlueAdjustment.getAdjustmentB());
|
||||
}
|
||||
|
||||
// collect effect info
|
||||
@ -726,25 +726,25 @@ void JsonClientConnection::handleAdjustmentCommand(const Json::Value &message)
|
||||
if (adjustment.isMember("redAdjust"))
|
||||
{
|
||||
const Json::Value & values = adjustment["redAdjust"];
|
||||
colorAdjustment->_rgbRedAdjustment.setadjustmentR(values[0u].asInt());
|
||||
colorAdjustment->_rgbRedAdjustment.setadjustmentG(values[1u].asInt());
|
||||
colorAdjustment->_rgbRedAdjustment.setadjustmentB(values[2u].asInt());
|
||||
colorAdjustment->_rgbRedAdjustment.setAdjustmentR(values[0u].asInt());
|
||||
colorAdjustment->_rgbRedAdjustment.setAdjustmentG(values[1u].asInt());
|
||||
colorAdjustment->_rgbRedAdjustment.setAdjustmentB(values[2u].asInt());
|
||||
}
|
||||
|
||||
if (adjustment.isMember("greenAdjust"))
|
||||
{
|
||||
const Json::Value & values = adjustment["greenAdjust"];
|
||||
colorAdjustment->_rgbGreenAdjustment.setadjustmentR(values[0u].asInt());
|
||||
colorAdjustment->_rgbGreenAdjustment.setadjustmentG(values[1u].asInt());
|
||||
colorAdjustment->_rgbGreenAdjustment.setadjustmentB(values[2u].asInt());
|
||||
colorAdjustment->_rgbGreenAdjustment.setAdjustmentR(values[0u].asInt());
|
||||
colorAdjustment->_rgbGreenAdjustment.setAdjustmentG(values[1u].asInt());
|
||||
colorAdjustment->_rgbGreenAdjustment.setAdjustmentB(values[2u].asInt());
|
||||
}
|
||||
|
||||
if (adjustment.isMember("blueAdjust"))
|
||||
{
|
||||
const Json::Value & values = adjustment["blueAdjust"];
|
||||
colorAdjustment->_rgbBlueAdjustment.setadjustmentR(values[0u].asInt());
|
||||
colorAdjustment->_rgbBlueAdjustment.setadjustmentG(values[1u].asInt());
|
||||
colorAdjustment->_rgbBlueAdjustment.setadjustmentB(values[2u].asInt());
|
||||
colorAdjustment->_rgbBlueAdjustment.setAdjustmentR(values[0u].asInt());
|
||||
colorAdjustment->_rgbBlueAdjustment.setAdjustmentG(values[1u].asInt());
|
||||
colorAdjustment->_rgbBlueAdjustment.setAdjustmentB(values[2u].asInt());
|
||||
}
|
||||
// commit the changes
|
||||
_hyperion->adjustmentsUpdated();
|
||||
|
@ -1,107 +1,84 @@
|
||||
// STL includes
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <algorithm>
|
||||
|
||||
// Utils includes
|
||||
#include <utils/RgbChannelAdjustment.h>
|
||||
|
||||
RgbChannelAdjustment::RgbChannelAdjustment() :
|
||||
_adjustR(255),
|
||||
_adjustG(255),
|
||||
_adjustB(255)
|
||||
RgbChannelAdjustment::RgbChannelAdjustment()
|
||||
{
|
||||
initializeMapping();
|
||||
setAdjustment(UINT8_MAX, UINT8_MAX, UINT8_MAX);
|
||||
}
|
||||
|
||||
RgbChannelAdjustment::RgbChannelAdjustment(int adjustR, int adjustG, int adjustB) :
|
||||
_adjustR(adjustR),
|
||||
_adjustG(adjustG),
|
||||
_adjustB(adjustB)
|
||||
RgbChannelAdjustment::RgbChannelAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB)
|
||||
{
|
||||
initializeMapping();
|
||||
setAdjustment(adjustR, adjustG, adjustB);
|
||||
}
|
||||
|
||||
RgbChannelAdjustment::~RgbChannelAdjustment()
|
||||
{
|
||||
}
|
||||
|
||||
uint8_t RgbChannelAdjustment::getadjustmentR() const
|
||||
void RgbChannelAdjustment::setAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB)
|
||||
{
|
||||
return _adjustR;
|
||||
}
|
||||
|
||||
void RgbChannelAdjustment::setadjustmentR(uint8_t adjustR)
|
||||
{
|
||||
_adjustR = adjustR;
|
||||
_adjust[RED] = adjustR;
|
||||
_adjust[GREEN] = adjustG;
|
||||
_adjust[BLUE] = adjustB;
|
||||
initializeMapping();
|
||||
}
|
||||
|
||||
uint8_t RgbChannelAdjustment::getadjustmentG() const
|
||||
uint8_t RgbChannelAdjustment::getAdjustmentR() const
|
||||
{
|
||||
return _adjustG;
|
||||
return _adjust[RED];
|
||||
}
|
||||
|
||||
void RgbChannelAdjustment::setadjustmentG(uint8_t adjustG)
|
||||
void RgbChannelAdjustment::setAdjustmentR(uint8_t adjustR)
|
||||
{
|
||||
_adjustG = adjustG;
|
||||
initializeMapping();
|
||||
setAdjustment(adjustR, _adjust[GREEN], _adjust[BLUE]);
|
||||
}
|
||||
|
||||
uint8_t RgbChannelAdjustment::getadjustmentB() const
|
||||
uint8_t RgbChannelAdjustment::getAdjustmentG() const
|
||||
{
|
||||
return _adjustB;
|
||||
return _adjust[GREEN];
|
||||
}
|
||||
|
||||
void RgbChannelAdjustment::setadjustmentB(uint8_t adjustB)
|
||||
void RgbChannelAdjustment::setAdjustmentG(uint8_t adjustG)
|
||||
{
|
||||
_adjustB = adjustB;
|
||||
initializeMapping();
|
||||
setAdjustment(_adjust[RED], adjustG, _adjust[BLUE]);
|
||||
}
|
||||
|
||||
uint8_t RgbChannelAdjustment::getAdjustmentB() const
|
||||
{
|
||||
return _adjust[BLUE];
|
||||
}
|
||||
|
||||
void RgbChannelAdjustment::setAdjustmentB(uint8_t adjustB)
|
||||
{
|
||||
setAdjustment(_adjust[RED], _adjust[GREEN], adjustB);
|
||||
}
|
||||
|
||||
uint8_t RgbChannelAdjustment::adjustmentR(uint8_t inputR) const
|
||||
{
|
||||
return _mappingR[inputR];
|
||||
return _mapping[RED][inputR];
|
||||
}
|
||||
|
||||
uint8_t RgbChannelAdjustment::adjustmentG(uint8_t inputG) const
|
||||
{
|
||||
return _mappingG[inputG];
|
||||
return _mapping[GREEN][inputG];
|
||||
}
|
||||
|
||||
uint8_t RgbChannelAdjustment::adjustmentB(uint8_t inputB) const
|
||||
{
|
||||
return _mappingB[inputB];
|
||||
return _mapping[BLUE][inputB];
|
||||
}
|
||||
|
||||
void RgbChannelAdjustment::initializeMapping()
|
||||
{
|
||||
// initialize the mapping
|
||||
for (int i = 0; i < 256; ++i)
|
||||
{
|
||||
int outputR = (i * _adjustR) / 255;
|
||||
if (outputR > 255)
|
||||
// initialize linear mapping
|
||||
for (unsigned channel=0; channel<3; channel++)
|
||||
for (unsigned idx=0; idx<=UINT8_MAX; idx++)
|
||||
{
|
||||
outputR = 255;
|
||||
_mapping[channel][idx] = std::min( ((idx * _adjust[channel]) / UINT8_MAX), (unsigned)UINT8_MAX);
|
||||
}
|
||||
_mappingR[i] = outputR;
|
||||
}
|
||||
for (int i = 0; i < 256; ++i)
|
||||
{
|
||||
int outputG = (i * _adjustG) / 255;
|
||||
if (outputG > 255)
|
||||
{
|
||||
outputG = 255;
|
||||
}
|
||||
_mappingG[i] = outputG;
|
||||
}
|
||||
for (int i = 0; i < 256; ++i)
|
||||
{
|
||||
int outputB = (i * _adjustB) / 255;
|
||||
if (outputB > 255)
|
||||
{
|
||||
outputB = 255;
|
||||
}
|
||||
_mappingB[i] = outputB;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user