From 78eaaa2e8439e75e945b3bdcc1e43074bbb82483 Mon Sep 17 00:00:00 2001 From: redPanther Date: Mon, 4 Jul 2016 00:43:41 +0200 Subject: [PATCH] Filter rework, next step (#82) * 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 * - remove rgbchannelcorrection, this was a dup of rgbchanneladjustment - add cmake policy to hide warning - tune code of rgbchanneltransform --- CMakeLists.txt | 4 + include/hyperion/ColorCorrection.h | 4 +- include/hyperion/Hyperion.h | 2 +- include/utils/RgbChannelAdjustment.h | 6 +- include/utils/RgbChannelCorrection.h | 66 ------------ include/utils/RgbChannelTransform.h | 7 ++ libsrc/hyperion/Hyperion.cpp | 6 +- libsrc/hyperion/MultiColorCorrection.cpp | 6 +- libsrc/jsonserver/JsonClientConnection.cpp | 12 +-- libsrc/utils/CMakeLists.txt | 2 - libsrc/utils/RgbChannelCorrection.cpp | 120 --------------------- libsrc/utils/RgbChannelTransform.cpp | 37 +++---- 12 files changed, 46 insertions(+), 226 deletions(-) delete mode 100644 include/utils/RgbChannelCorrection.h delete mode 100644 libsrc/utils/RgbChannelCorrection.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 9269f48a..f31149ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,10 @@ IF ( POLICY CMP0026 ) CMAKE_POLICY( SET CMP0026 OLD ) ENDIF() +IF ( POLICY CMP0043 ) + CMAKE_POLICY( SET CMP0043 OLD ) +ENDIF() + SET ( HYPERION_VERSION_STABLE OFF ) SET ( HYPERION_VERSION_MAJOR 2 ) SET ( HYPERION_VERSION_MINOR 0 ) diff --git a/include/hyperion/ColorCorrection.h b/include/hyperion/ColorCorrection.h index 51ae0605..55876feb 100644 --- a/include/hyperion/ColorCorrection.h +++ b/include/hyperion/ColorCorrection.h @@ -4,7 +4,7 @@ #include // Utils includes -#include +#include class ColorCorrection { @@ -14,5 +14,5 @@ public: std::string _id; /// The RGB correction - RgbChannelCorrection _rgbCorrection; + RgbChannelAdjustment _rgbCorrection; }; diff --git a/include/hyperion/Hyperion.h b/include/hyperion/Hyperion.h index f6c6e0cb..633be30b 100644 --- a/include/hyperion/Hyperion.h +++ b/include/hyperion/Hyperion.h @@ -235,7 +235,7 @@ public: static HsvTransform * createHsvTransform(const Json::Value & hsvConfig); static HslTransform * createHslTransform(const Json::Value & hslConfig); static RgbChannelTransform * createRgbChannelTransform(const Json::Value& colorConfig); - static RgbChannelCorrection * createRgbChannelCorrection(const Json::Value& colorConfig); + static RgbChannelAdjustment * createRgbChannelCorrection(const Json::Value& colorConfig); static RgbChannelAdjustment * createRgbChannelAdjustment(const Json::Value& colorConfig, const RgbChannel color); static LedDevice * createColorSmoothing(const Json::Value & smoothingConfig, LedDevice * ledDevice); diff --git a/include/utils/RgbChannelAdjustment.h b/include/utils/RgbChannelAdjustment.h index 5b35b651..396c4cd5 100644 --- a/include/utils/RgbChannelAdjustment.h +++ b/include/utils/RgbChannelAdjustment.h @@ -20,15 +20,15 @@ public: /// Destructor ~RgbChannelAdjustment(); - /// @return The current adjustR value - uint8_t getAdjustmentR() const; - /// setAdjustment RGB /// @param adjustR /// @param adjustG /// @param adjustB void setAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB); + /// @return The current adjustR value + uint8_t getAdjustmentR() const; + /// @param threshold New adjustR value void setAdjustmentR(uint8_t adjustR); diff --git a/include/utils/RgbChannelCorrection.h b/include/utils/RgbChannelCorrection.h deleted file mode 100644 index f09b9cef..00000000 --- a/include/utils/RgbChannelCorrection.h +++ /dev/null @@ -1,66 +0,0 @@ -#pragma once - -// STL includes -#include - -/// Correction for a single color byte value -/// All configuration values are unsigned int and assume the color value to be between 0 and 255 -class RgbChannelCorrection -{ -public: - /// Default constructor - RgbChannelCorrection(); - - /// Constructor - /// @param correctionR - /// @param correctionG - /// @param correctionB - - RgbChannelCorrection(int correctionR, int correctionG, int correctionB); - - /// Destructor - ~RgbChannelCorrection(); - - /// @return The current correctionR value - uint8_t getcorrectionR() const; - - /// @param threshold New correctionR value - void setcorrectionR(uint8_t correctionR); - - /// @return The current correctionG value - uint8_t getcorrectionG() const; - - /// @param gamma New correctionG value - void setcorrectionG(uint8_t correctionG); - - /// @return The current correctionB value - uint8_t getcorrectionB() const; - - /// @param blacklevel New correctionB value - void setcorrectionB(uint8_t correctionB); - - /// Transform the given array value - /// @param input The input color bytes - /// @return The corrected byte value - uint8_t correctionR(uint8_t inputR) const; - uint8_t correctionG(uint8_t inputG) const; - uint8_t correctionB(uint8_t inputB) const; - - -private: - /// (re)-initilize the color mapping - void initializeMapping(); - -private: - /// The correction of R channel - int _correctionR; - /// The correction of G channel - int _correctionG; - /// The correction of B channel - int _correctionB; - - /// The mapping from input color to output color - int _mappingR[256]; - int _mappingG[256]; - int _mappingB[256]; -}; diff --git a/include/utils/RgbChannelTransform.h b/include/utils/RgbChannelTransform.h index 7f524d81..fe49f8cc 100644 --- a/include/utils/RgbChannelTransform.h +++ b/include/utils/RgbChannelTransform.h @@ -28,6 +28,13 @@ public: /// Destructor ~RgbChannelTransform(); + /// setAdjustment RGB + /// @param threshold The minimum threshold + /// @param gamma The gamma of the gamma-curve correction + /// @param blacklevel The minimum value for the RGB-Channel + /// @param whitelevel The maximum value for the RGB-Channel + void setTransform(double threshold, double gamma, double blacklevel, double whitelevel); + /// @return The current threshold value double getThreshold() const; diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index 5d0ce425..b5b31c29 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -116,7 +116,7 @@ ColorCorrection * Hyperion::createColorCorrection(const Json::Value & correction { const std::string id = correctionConfig.get("id", "default").asString(); - RgbChannelCorrection * rgbCorrection = createRgbChannelCorrection(correctionConfig["correctionValues"]); + RgbChannelAdjustment * rgbCorrection = createRgbChannelCorrection(correctionConfig["correctionValues"]); ColorCorrection * correction = new ColorCorrection(); correction->_id = id; @@ -404,13 +404,13 @@ RgbChannelTransform* Hyperion::createRgbChannelTransform(const Json::Value& colo return transform; } -RgbChannelCorrection* Hyperion::createRgbChannelCorrection(const Json::Value& colorConfig) +RgbChannelAdjustment* Hyperion::createRgbChannelCorrection(const Json::Value& colorConfig) { const int varR = colorConfig.get("red", 255).asInt(); const int varG = colorConfig.get("green", 255).asInt(); const int varB = colorConfig.get("blue", 255).asInt(); - RgbChannelCorrection* correction = new RgbChannelCorrection(varR, varG, varB); + RgbChannelAdjustment* correction = new RgbChannelAdjustment(varR, varG, varB); return correction; } diff --git a/libsrc/hyperion/MultiColorCorrection.cpp b/libsrc/hyperion/MultiColorCorrection.cpp index 9ec9f10c..23a1ed5b 100644 --- a/libsrc/hyperion/MultiColorCorrection.cpp +++ b/libsrc/hyperion/MultiColorCorrection.cpp @@ -85,8 +85,8 @@ void MultiColorCorrection::applyCorrection(std::vector& ledColors) } 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); + color.red = correction->_rgbCorrection.adjustmentR(color.red); + color.green = correction->_rgbCorrection.adjustmentG(color.green); + color.blue = correction->_rgbCorrection.adjustmentB(color.blue); } } diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index 307a085b..605cb34a 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -411,9 +411,9 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &) temperature["id"] = tempId; Json::Value & tempValues = temperature["correctionValues"]; - tempValues.append(colorTemp->_rgbCorrection.getcorrectionR()); - tempValues.append(colorTemp->_rgbCorrection.getcorrectionG()); - tempValues.append(colorTemp->_rgbCorrection.getcorrectionB()); + tempValues.append(colorTemp->_rgbCorrection.getAdjustmentR()); + tempValues.append(colorTemp->_rgbCorrection.getAdjustmentG()); + tempValues.append(colorTemp->_rgbCorrection.getAdjustmentB()); } @@ -700,9 +700,9 @@ void JsonClientConnection::handleTemperatureCommand(const Json::Value &message) if (temperature.isMember("correctionValues")) { const Json::Value & values = temperature["correctionValues"]; - colorTemperature->_rgbCorrection.setcorrectionR(values[0u].asInt()); - colorTemperature->_rgbCorrection.setcorrectionG(values[1u].asInt()); - colorTemperature->_rgbCorrection.setcorrectionB(values[2u].asInt()); + colorTemperature->_rgbCorrection.setAdjustmentR(values[0u].asInt()); + colorTemperature->_rgbCorrection.setAdjustmentG(values[1u].asInt()); + colorTemperature->_rgbCorrection.setAdjustmentB(values[2u].asInt()); } // commit the changes diff --git a/libsrc/utils/CMakeLists.txt b/libsrc/utils/CMakeLists.txt index 3e4c2074..78127e74 100644 --- a/libsrc/utils/CMakeLists.txt +++ b/libsrc/utils/CMakeLists.txt @@ -36,8 +36,6 @@ add_library(hyperion-utils ${CURRENT_SOURCE_DIR}/HslTransform.cpp ${CURRENT_HEADER_DIR}/RgbChannelTransform.h ${CURRENT_SOURCE_DIR}/RgbChannelTransform.cpp - ${CURRENT_HEADER_DIR}/RgbChannelCorrection.h - ${CURRENT_SOURCE_DIR}/RgbChannelCorrection.cpp ${CURRENT_HEADER_DIR}/RgbChannelAdjustment.h ${CURRENT_SOURCE_DIR}/RgbChannelAdjustment.cpp diff --git a/libsrc/utils/RgbChannelCorrection.cpp b/libsrc/utils/RgbChannelCorrection.cpp deleted file mode 100644 index 7fb16884..00000000 --- a/libsrc/utils/RgbChannelCorrection.cpp +++ /dev/null @@ -1,120 +0,0 @@ -// STL includes -#include - -// Utils includes -#include - -RgbChannelCorrection::RgbChannelCorrection() : - _correctionR(255), - _correctionG(255), - _correctionB(255) -{ - initializeMapping(); -} - -RgbChannelCorrection::RgbChannelCorrection(int correctionR, int correctionG, int correctionB) : - _correctionR(correctionR), - _correctionG(correctionG), - _correctionB(correctionB) -{ - initializeMapping(); -} - -RgbChannelCorrection::~RgbChannelCorrection() -{ -} - -uint8_t RgbChannelCorrection::getcorrectionR() const -{ - return _correctionR; -} - -void RgbChannelCorrection::setcorrectionR(uint8_t correctionR) -{ - _correctionR = correctionR; - initializeMapping(); -} - -uint8_t RgbChannelCorrection::getcorrectionG() const -{ - return _correctionG; -} - -void RgbChannelCorrection::setcorrectionG(uint8_t correctionG) -{ - _correctionG = correctionG; - initializeMapping(); -} - -uint8_t RgbChannelCorrection::getcorrectionB() const -{ - return _correctionB; -} - -void RgbChannelCorrection::setcorrectionB(uint8_t correctionB) -{ - _correctionB = correctionB; - initializeMapping(); -} - -uint8_t RgbChannelCorrection::correctionR(uint8_t inputR) const -{ - return _mappingR[inputR]; -} - -uint8_t RgbChannelCorrection::correctionG(uint8_t inputG) const -{ - return _mappingG[inputG]; -} - -uint8_t RgbChannelCorrection::correctionB(uint8_t inputB) const -{ - return _mappingB[inputB]; -} - -void RgbChannelCorrection::initializeMapping() -{ - // initialize the mapping - for (int i = 0; i < 256; ++i) - { - int outputR = (i * _correctionR) / 255; - if (outputR < -255) - { - outputR = -255; - } - else if (outputR > 255) - { - outputR = 255; - } - _mappingR[i] = outputR; - } - for (int i = 0; i < 256; ++i) - { - int outputG = (i * _correctionG) / 255; - if (outputG < -255) - { - outputG = -255; - } - else if (outputG > 255) - { - outputG = 255; - } - _mappingG[i] = outputG; - } - for (int i = 0; i < 256; ++i) - { - int outputB = (i * _correctionB) / 255; - if (outputB < -255) - { - outputB = -255; - } - else if (outputB > 255) - { - outputB = 255; - } - _mappingB[i] = outputB; - } - - -} - diff --git a/libsrc/utils/RgbChannelTransform.cpp b/libsrc/utils/RgbChannelTransform.cpp index bdd4ec1b..616346db 100644 --- a/libsrc/utils/RgbChannelTransform.cpp +++ b/libsrc/utils/RgbChannelTransform.cpp @@ -4,28 +4,29 @@ // Utils includes #include -RgbChannelTransform::RgbChannelTransform() : - _threshold(0), - _gamma(1.0), - _blacklevel(0.0), - _whitelevel(1.0) +RgbChannelTransform::RgbChannelTransform() { - initializeMapping(); + setTransform(0.0, 1.0, 0.0, 1.0); } -RgbChannelTransform::RgbChannelTransform(double threshold, double gamma, double blacklevel, double whitelevel) : - _threshold(threshold), - _gamma(gamma), - _blacklevel(blacklevel), - _whitelevel(whitelevel) +RgbChannelTransform::RgbChannelTransform(double threshold, double gamma, double blacklevel, double whitelevel) { - initializeMapping(); + setTransform(threshold, gamma, blacklevel, whitelevel); } RgbChannelTransform::~RgbChannelTransform() { } +void RgbChannelTransform::setTransform(double threshold, double gamma, double blacklevel, double whitelevel) +{ + _threshold = threshold; + _gamma = gamma; + _blacklevel = blacklevel; + _whitelevel = whitelevel; + initializeMapping(); +} + double RgbChannelTransform::getThreshold() const { return _threshold; @@ -33,8 +34,7 @@ double RgbChannelTransform::getThreshold() const void RgbChannelTransform::setThreshold(double threshold) { - _threshold = threshold; - initializeMapping(); + setTransform(threshold, _gamma, _blacklevel, _whitelevel); } double RgbChannelTransform::getGamma() const @@ -44,8 +44,7 @@ double RgbChannelTransform::getGamma() const void RgbChannelTransform::setGamma(double gamma) { - _gamma = gamma; - initializeMapping(); + setTransform(_threshold, gamma, _blacklevel, _whitelevel); } double RgbChannelTransform::getBlacklevel() const @@ -55,8 +54,7 @@ double RgbChannelTransform::getBlacklevel() const void RgbChannelTransform::setBlacklevel(double blacklevel) { - _blacklevel = blacklevel; - initializeMapping(); + setTransform(_threshold, _gamma, blacklevel, _whitelevel); } double RgbChannelTransform::getWhitelevel() const @@ -66,8 +64,7 @@ double RgbChannelTransform::getWhitelevel() const void RgbChannelTransform::setWhitelevel(double whitelevel) { - _whitelevel = whitelevel; - initializeMapping(); + setTransform(_threshold, _gamma, _blacklevel, whitelevel); } void RgbChannelTransform::initializeMapping()