From 852f7b86bbc17c6dff61e41c7f944d6879253fb7 Mon Sep 17 00:00:00 2001 From: redPanther Date: Fri, 31 Mar 2017 19:37:27 +0200 Subject: [PATCH] clean color adjustment (#428) --- include/utils/RgbChannelAdjustment.h | 21 +++--------- libsrc/hyperion/MultiColorAdjustment.cpp | 40 +++++----------------- libsrc/jsonserver/JsonClientConnection.cpp | 32 +++++------------ libsrc/utils/RgbChannelAdjustment.cpp | 35 ++++--------------- 4 files changed, 27 insertions(+), 101 deletions(-) diff --git a/include/utils/RgbChannelAdjustment.h b/include/utils/RgbChannelAdjustment.h index fae861b6..88bb9aea 100644 --- a/include/utils/RgbChannelAdjustment.h +++ b/include/utils/RgbChannelAdjustment.h @@ -21,6 +21,10 @@ public: /// Destructor ~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 /// @param adjustR @@ -31,29 +35,12 @@ public: /// @return The current adjustR value uint8_t getAdjustmentR() const; - /// @param threshold New adjustR value - void setAdjustmentR(uint8_t adjustR); - /// @return The current adjustG value uint8_t getAdjustmentG() const; - /// @param gamma New adjustG value - void setAdjustmentG(uint8_t adjustG); - /// @return The current adjustB value 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: /// color channels enum ColorChannel { RED=0,GREEN=1, BLUE=2 }; diff --git a/libsrc/hyperion/MultiColorAdjustment.cpp b/libsrc/hyperion/MultiColorAdjustment.cpp index 8af98804..6bab6382 100644 --- a/libsrc/hyperion/MultiColorAdjustment.cpp +++ b/libsrc/hyperion/MultiColorAdjustment.cpp @@ -123,37 +123,15 @@ void MultiColorAdjustment::applyAdjustment(std::vector& ledColors) uint8_t yellow = rg *(255-oblue)/65025; uint8_t white = rg *(oblue) /65025; - uint8_t OR = adjustment->_rgbBlackAdjustment.getAdjustmentR(black); - uint8_t OG = adjustment->_rgbBlackAdjustment.getAdjustmentG(black); - uint8_t OB = adjustment->_rgbBlackAdjustment.getAdjustmentB(black); - - uint8_t RR = adjustment->_rgbRedAdjustment.getAdjustmentR(red); - uint8_t RG = adjustment->_rgbRedAdjustment.getAdjustmentG(red); - uint8_t RB = adjustment->_rgbRedAdjustment.getAdjustmentB(red); - - uint8_t GR = adjustment->_rgbGreenAdjustment.getAdjustmentR(green); - 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); + 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; + adjustment->_rgbBlackAdjustment.apply(black, OR, OG, OB); + adjustment->_rgbRedAdjustment.apply(red, RR, RG, RB); + adjustment->_rgbGreenAdjustment.apply(green, GR, GG, GB); + adjustment->_rgbBlueAdjustment.apply(blue, BR, BG, BB); + adjustment->_rgbCyanAdjustment.apply(cyan, CR, CG, CB); + adjustment->_rgbMagentaAdjustment.apply(magenta, MR, MG, MB); + adjustment->_rgbYellowAdjustment.apply(yellow, YR, YG, YB); + adjustment->_rgbWhiteAdjustment.apply(white, WR, WG, WB); color.red = OR + RR + GR + BR + CR + MR + YR + WR; color.green = OG + RG + GG + BG + CG + MG + YG + WG; diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index 08992d7a..ba246547 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -893,60 +893,44 @@ void JsonClientConnection::handleAdjustmentCommand(const QJsonObject& message, c if (adjustment.contains("red")) { const QJsonArray & values = adjustment["red"].toArray(); - colorAdjustment->_rgbRedAdjustment.setAdjustmentR(values[0u].toInt()); - colorAdjustment->_rgbRedAdjustment.setAdjustmentG(values[1u].toInt()); - colorAdjustment->_rgbRedAdjustment.setAdjustmentB(values[2u].toInt()); + colorAdjustment->_rgbRedAdjustment.setAdjustment(values[0u].toInt(), values[1u].toInt(), values[2u].toInt()); } if (adjustment.contains("green")) { const QJsonArray & values = adjustment["green"].toArray(); - colorAdjustment->_rgbGreenAdjustment.setAdjustmentR(values[0u].toInt()); - colorAdjustment->_rgbGreenAdjustment.setAdjustmentG(values[1u].toInt()); - colorAdjustment->_rgbGreenAdjustment.setAdjustmentB(values[2u].toInt()); + colorAdjustment->_rgbGreenAdjustment.setAdjustment(values[0u].toInt(), values[1u].toInt(), values[2u].toInt()); } if (adjustment.contains("blue")) { const QJsonArray & values = adjustment["blue"].toArray(); - colorAdjustment->_rgbBlueAdjustment.setAdjustmentR(values[0u].toInt()); - colorAdjustment->_rgbBlueAdjustment.setAdjustmentG(values[1u].toInt()); - colorAdjustment->_rgbBlueAdjustment.setAdjustmentB(values[2u].toInt()); + colorAdjustment->_rgbBlueAdjustment.setAdjustment(values[0u].toInt(), values[1u].toInt(), values[2u].toInt()); } if (adjustment.contains("cyan")) { const QJsonArray & values = adjustment["cyan"].toArray(); - colorAdjustment->_rgbCyanAdjustment.setAdjustmentR(values[0u].toInt()); - colorAdjustment->_rgbCyanAdjustment.setAdjustmentG(values[1u].toInt()); - colorAdjustment->_rgbCyanAdjustment.setAdjustmentB(values[2u].toInt()); + colorAdjustment->_rgbCyanAdjustment.setAdjustment(values[0u].toInt(), values[1u].toInt(), values[2u].toInt()); } if (adjustment.contains("magenta")) { const QJsonArray & values = adjustment["magenta"].toArray(); - colorAdjustment->_rgbMagentaAdjustment.setAdjustmentR(values[0u].toInt()); - colorAdjustment->_rgbMagentaAdjustment.setAdjustmentG(values[1u].toInt()); - colorAdjustment->_rgbMagentaAdjustment.setAdjustmentB(values[2u].toInt()); + colorAdjustment->_rgbMagentaAdjustment.setAdjustment(values[0u].toInt(), values[1u].toInt(), values[2u].toInt()); } if (adjustment.contains("yellow")) { const QJsonArray & values = adjustment["yellow"].toArray(); - colorAdjustment->_rgbYellowAdjustment.setAdjustmentR(values[0u].toInt()); - colorAdjustment->_rgbYellowAdjustment.setAdjustmentG(values[1u].toInt()); - colorAdjustment->_rgbYellowAdjustment.setAdjustmentB(values[2u].toInt()); + colorAdjustment->_rgbYellowAdjustment.setAdjustment(values[0u].toInt(), values[1u].toInt(), values[2u].toInt()); } if (adjustment.contains("black")) { const QJsonArray & values = adjustment["black"].toArray(); - colorAdjustment->_rgbBlackAdjustment.setAdjustmentR(values[0u].toInt()); - colorAdjustment->_rgbBlackAdjustment.setAdjustmentG(values[1u].toInt()); - colorAdjustment->_rgbBlackAdjustment.setAdjustmentB(values[2u].toInt()); + colorAdjustment->_rgbBlackAdjustment.setAdjustment(values[0u].toInt(), values[1u].toInt(), values[2u].toInt()); } if (adjustment.contains("white")) { const QJsonArray & values = adjustment["white"].toArray(); - colorAdjustment->_rgbWhiteAdjustment.setAdjustmentR(values[0u].toInt()); - colorAdjustment->_rgbWhiteAdjustment.setAdjustmentG(values[1u].toInt()); - colorAdjustment->_rgbWhiteAdjustment.setAdjustmentB(values[2u].toInt()); + colorAdjustment->_rgbWhiteAdjustment.setAdjustment(values[0u].toInt(), values[1u].toInt(), values[2u].toInt()); } if (adjustment.contains("gammaRed")) diff --git a/libsrc/utils/RgbChannelAdjustment.cpp b/libsrc/utils/RgbChannelAdjustment.cpp index 53c2b350..f5c76c2d 100644 --- a/libsrc/utils/RgbChannelAdjustment.cpp +++ b/libsrc/utils/RgbChannelAdjustment.cpp @@ -26,9 +26,9 @@ RgbChannelAdjustment::~RgbChannelAdjustment() void RgbChannelAdjustment::setAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB) { - _adjust[RED] = adjustR; + _adjust[RED] = adjustR; _adjust[GREEN] = adjustG; - _adjust[BLUE] = adjustB; + _adjust[BLUE] = adjustB; initializeMapping(); } @@ -37,44 +37,21 @@ uint8_t RgbChannelAdjustment::getAdjustmentR() const return _adjust[RED]; } -void RgbChannelAdjustment::setAdjustmentR(uint8_t adjustR) -{ - setAdjustment(adjustR, _adjust[GREEN], _adjust[BLUE]); -} - uint8_t RgbChannelAdjustment::getAdjustmentG() const { return _adjust[GREEN]; } -void RgbChannelAdjustment::setAdjustmentG(uint8_t adjustG) -{ - setAdjustment(_adjust[RED], adjustG, _adjust[BLUE]); -} - uint8_t RgbChannelAdjustment::getAdjustmentB() const { 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); -} - -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]; + red = _mapping[RED][input]; + green = _mapping[GREEN][input]; + blue = _mapping[BLUE][input]; } void RgbChannelAdjustment::initializeMapping()