clean color adjustment (#428)

This commit is contained in:
redPanther 2017-03-31 19:37:27 +02:00 committed by GitHub
parent 7f8ad86bdd
commit 852f7b86bb
4 changed files with 27 additions and 101 deletions

View File

@ -21,6 +21,10 @@ public:
/// Destructor /// Destructor
~RgbChannelAdjustment(); ~RgbChannelAdjustment();
/// Transform the given array value
/// @param input The input color bytes
void apply(uint8_t input, uint8_t & red, uint8_t & green, uint8_t & blue);
/// setAdjustment RGB /// setAdjustment RGB
/// @param adjustR /// @param adjustR
@ -31,29 +35,12 @@ public:
/// @return The current adjustR value /// @return The current adjustR value
uint8_t getAdjustmentR() const; uint8_t getAdjustmentR() const;
/// @param threshold New adjustR value
void setAdjustmentR(uint8_t adjustR);
/// @return The current adjustG value /// @return The current adjustG value
uint8_t getAdjustmentG() const; uint8_t getAdjustmentG() const;
/// @param gamma New adjustG value
void setAdjustmentG(uint8_t adjustG);
/// @return The current adjustB value /// @return The current adjustB value
uint8_t getAdjustmentB() const; uint8_t getAdjustmentB() const;
/// @param blacklevel New adjustB value
void setAdjustmentB(uint8_t adjustB);
/// Transform the given array value
/// @param input The input color bytes
/// @return The corrected byte value
uint8_t getAdjustmentR(uint8_t inputR) const;
uint8_t getAdjustmentG(uint8_t inputG) const;
uint8_t getAdjustmentB(uint8_t inputB) const;
private: private:
/// color channels /// color channels
enum ColorChannel { RED=0,GREEN=1, BLUE=2 }; enum ColorChannel { RED=0,GREEN=1, BLUE=2 };

View File

@ -123,37 +123,15 @@ void MultiColorAdjustment::applyAdjustment(std::vector<ColorRgb>& ledColors)
uint8_t yellow = rg *(255-oblue)/65025; uint8_t yellow = rg *(255-oblue)/65025;
uint8_t white = rg *(oblue) /65025; uint8_t white = rg *(oblue) /65025;
uint8_t OR = adjustment->_rgbBlackAdjustment.getAdjustmentR(black); uint8_t OR, OG, OB, RR, RG, RB, GR, GG, GB, BR, BG, BB, CR, CG, CB, MR, MG, MB, YR, YG, YB, WR, WG, WB;
uint8_t OG = adjustment->_rgbBlackAdjustment.getAdjustmentG(black); adjustment->_rgbBlackAdjustment.apply(black, OR, OG, OB);
uint8_t OB = adjustment->_rgbBlackAdjustment.getAdjustmentB(black); adjustment->_rgbRedAdjustment.apply(red, RR, RG, RB);
adjustment->_rgbGreenAdjustment.apply(green, GR, GG, GB);
uint8_t RR = adjustment->_rgbRedAdjustment.getAdjustmentR(red); adjustment->_rgbBlueAdjustment.apply(blue, BR, BG, BB);
uint8_t RG = adjustment->_rgbRedAdjustment.getAdjustmentG(red); adjustment->_rgbCyanAdjustment.apply(cyan, CR, CG, CB);
uint8_t RB = adjustment->_rgbRedAdjustment.getAdjustmentB(red); adjustment->_rgbMagentaAdjustment.apply(magenta, MR, MG, MB);
adjustment->_rgbYellowAdjustment.apply(yellow, YR, YG, YB);
uint8_t GR = adjustment->_rgbGreenAdjustment.getAdjustmentR(green); adjustment->_rgbWhiteAdjustment.apply(white, WR, WG, WB);
uint8_t GG = adjustment->_rgbGreenAdjustment.getAdjustmentG(green);
uint8_t GB = adjustment->_rgbGreenAdjustment.getAdjustmentB(green);
uint8_t BR = adjustment->_rgbBlueAdjustment.getAdjustmentR(blue);
uint8_t BG = adjustment->_rgbBlueAdjustment.getAdjustmentG(blue);
uint8_t BB = adjustment->_rgbBlueAdjustment.getAdjustmentB(blue);
uint8_t CR = adjustment->_rgbCyanAdjustment.getAdjustmentR(cyan);
uint8_t CG = adjustment->_rgbCyanAdjustment.getAdjustmentG(cyan);
uint8_t CB = adjustment->_rgbCyanAdjustment.getAdjustmentB(cyan);
uint8_t MR = adjustment->_rgbMagentaAdjustment.getAdjustmentR(magenta);
uint8_t MG = adjustment->_rgbMagentaAdjustment.getAdjustmentG(magenta);
uint8_t MB = adjustment->_rgbMagentaAdjustment.getAdjustmentB(magenta);
uint8_t YR = adjustment->_rgbYellowAdjustment.getAdjustmentR(yellow);
uint8_t YG = adjustment->_rgbYellowAdjustment.getAdjustmentG(yellow);
uint8_t YB = adjustment->_rgbYellowAdjustment.getAdjustmentB(yellow);
uint8_t WR = adjustment->_rgbWhiteAdjustment.getAdjustmentR(white);
uint8_t WG = adjustment->_rgbWhiteAdjustment.getAdjustmentG(white);
uint8_t WB = adjustment->_rgbWhiteAdjustment.getAdjustmentB(white);
color.red = OR + RR + GR + BR + CR + MR + YR + WR; color.red = OR + RR + GR + BR + CR + MR + YR + WR;
color.green = OG + RG + GG + BG + CG + MG + YG + WG; color.green = OG + RG + GG + BG + CG + MG + YG + WG;

View File

@ -893,60 +893,44 @@ void JsonClientConnection::handleAdjustmentCommand(const QJsonObject& message, c
if (adjustment.contains("red")) if (adjustment.contains("red"))
{ {
const QJsonArray & values = adjustment["red"].toArray(); const QJsonArray & values = adjustment["red"].toArray();
colorAdjustment->_rgbRedAdjustment.setAdjustmentR(values[0u].toInt()); colorAdjustment->_rgbRedAdjustment.setAdjustment(values[0u].toInt(), values[1u].toInt(), values[2u].toInt());
colorAdjustment->_rgbRedAdjustment.setAdjustmentG(values[1u].toInt());
colorAdjustment->_rgbRedAdjustment.setAdjustmentB(values[2u].toInt());
} }
if (adjustment.contains("green")) if (adjustment.contains("green"))
{ {
const QJsonArray & values = adjustment["green"].toArray(); const QJsonArray & values = adjustment["green"].toArray();
colorAdjustment->_rgbGreenAdjustment.setAdjustmentR(values[0u].toInt()); colorAdjustment->_rgbGreenAdjustment.setAdjustment(values[0u].toInt(), values[1u].toInt(), values[2u].toInt());
colorAdjustment->_rgbGreenAdjustment.setAdjustmentG(values[1u].toInt());
colorAdjustment->_rgbGreenAdjustment.setAdjustmentB(values[2u].toInt());
} }
if (adjustment.contains("blue")) if (adjustment.contains("blue"))
{ {
const QJsonArray & values = adjustment["blue"].toArray(); const QJsonArray & values = adjustment["blue"].toArray();
colorAdjustment->_rgbBlueAdjustment.setAdjustmentR(values[0u].toInt()); colorAdjustment->_rgbBlueAdjustment.setAdjustment(values[0u].toInt(), values[1u].toInt(), values[2u].toInt());
colorAdjustment->_rgbBlueAdjustment.setAdjustmentG(values[1u].toInt());
colorAdjustment->_rgbBlueAdjustment.setAdjustmentB(values[2u].toInt());
} }
if (adjustment.contains("cyan")) if (adjustment.contains("cyan"))
{ {
const QJsonArray & values = adjustment["cyan"].toArray(); const QJsonArray & values = adjustment["cyan"].toArray();
colorAdjustment->_rgbCyanAdjustment.setAdjustmentR(values[0u].toInt()); colorAdjustment->_rgbCyanAdjustment.setAdjustment(values[0u].toInt(), values[1u].toInt(), values[2u].toInt());
colorAdjustment->_rgbCyanAdjustment.setAdjustmentG(values[1u].toInt());
colorAdjustment->_rgbCyanAdjustment.setAdjustmentB(values[2u].toInt());
} }
if (adjustment.contains("magenta")) if (adjustment.contains("magenta"))
{ {
const QJsonArray & values = adjustment["magenta"].toArray(); const QJsonArray & values = adjustment["magenta"].toArray();
colorAdjustment->_rgbMagentaAdjustment.setAdjustmentR(values[0u].toInt()); colorAdjustment->_rgbMagentaAdjustment.setAdjustment(values[0u].toInt(), values[1u].toInt(), values[2u].toInt());
colorAdjustment->_rgbMagentaAdjustment.setAdjustmentG(values[1u].toInt());
colorAdjustment->_rgbMagentaAdjustment.setAdjustmentB(values[2u].toInt());
} }
if (adjustment.contains("yellow")) if (adjustment.contains("yellow"))
{ {
const QJsonArray & values = adjustment["yellow"].toArray(); const QJsonArray & values = adjustment["yellow"].toArray();
colorAdjustment->_rgbYellowAdjustment.setAdjustmentR(values[0u].toInt()); colorAdjustment->_rgbYellowAdjustment.setAdjustment(values[0u].toInt(), values[1u].toInt(), values[2u].toInt());
colorAdjustment->_rgbYellowAdjustment.setAdjustmentG(values[1u].toInt());
colorAdjustment->_rgbYellowAdjustment.setAdjustmentB(values[2u].toInt());
} }
if (adjustment.contains("black")) if (adjustment.contains("black"))
{ {
const QJsonArray & values = adjustment["black"].toArray(); const QJsonArray & values = adjustment["black"].toArray();
colorAdjustment->_rgbBlackAdjustment.setAdjustmentR(values[0u].toInt()); colorAdjustment->_rgbBlackAdjustment.setAdjustment(values[0u].toInt(), values[1u].toInt(), values[2u].toInt());
colorAdjustment->_rgbBlackAdjustment.setAdjustmentG(values[1u].toInt());
colorAdjustment->_rgbBlackAdjustment.setAdjustmentB(values[2u].toInt());
} }
if (adjustment.contains("white")) if (adjustment.contains("white"))
{ {
const QJsonArray & values = adjustment["white"].toArray(); const QJsonArray & values = adjustment["white"].toArray();
colorAdjustment->_rgbWhiteAdjustment.setAdjustmentR(values[0u].toInt()); colorAdjustment->_rgbWhiteAdjustment.setAdjustment(values[0u].toInt(), values[1u].toInt(), values[2u].toInt());
colorAdjustment->_rgbWhiteAdjustment.setAdjustmentG(values[1u].toInt());
colorAdjustment->_rgbWhiteAdjustment.setAdjustmentB(values[2u].toInt());
} }
if (adjustment.contains("gammaRed")) if (adjustment.contains("gammaRed"))

View File

@ -26,9 +26,9 @@ RgbChannelAdjustment::~RgbChannelAdjustment()
void RgbChannelAdjustment::setAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB) void RgbChannelAdjustment::setAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB)
{ {
_adjust[RED] = adjustR; _adjust[RED] = adjustR;
_adjust[GREEN] = adjustG; _adjust[GREEN] = adjustG;
_adjust[BLUE] = adjustB; _adjust[BLUE] = adjustB;
initializeMapping(); initializeMapping();
} }
@ -37,44 +37,21 @@ uint8_t RgbChannelAdjustment::getAdjustmentR() const
return _adjust[RED]; return _adjust[RED];
} }
void RgbChannelAdjustment::setAdjustmentR(uint8_t adjustR)
{
setAdjustment(adjustR, _adjust[GREEN], _adjust[BLUE]);
}
uint8_t RgbChannelAdjustment::getAdjustmentG() const uint8_t RgbChannelAdjustment::getAdjustmentG() const
{ {
return _adjust[GREEN]; return _adjust[GREEN];
} }
void RgbChannelAdjustment::setAdjustmentG(uint8_t adjustG)
{
setAdjustment(_adjust[RED], adjustG, _adjust[BLUE]);
}
uint8_t RgbChannelAdjustment::getAdjustmentB() const uint8_t RgbChannelAdjustment::getAdjustmentB() const
{ {
return _adjust[BLUE]; return _adjust[BLUE];
} }
void RgbChannelAdjustment::setAdjustmentB(uint8_t adjustB) void RgbChannelAdjustment::apply(uint8_t input, uint8_t & red, uint8_t & green, uint8_t & blue)
{ {
setAdjustment(_adjust[RED], _adjust[GREEN], adjustB); red = _mapping[RED][input];
} green = _mapping[GREEN][input];
blue = _mapping[BLUE][input];
uint8_t RgbChannelAdjustment::getAdjustmentR(uint8_t inputR) const
{
return _mapping[RED][inputR];
}
uint8_t RgbChannelAdjustment::getAdjustmentG(uint8_t inputG) const
{
return _mapping[GREEN][inputG];
}
uint8_t RgbChannelAdjustment::getAdjustmentB(uint8_t inputB) const
{
return _mapping[BLUE][inputB];
} }
void RgbChannelAdjustment::initializeMapping() void RgbChannelAdjustment::initializeMapping()