From 30421bd808049564f64eeef2579b9f6bea9b4ca7 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Tue, 22 Dec 2015 09:56:17 +0100 Subject: [PATCH 01/54] Create ColorCorrection.h Former-commit-id: f52df680a7f056d37d23e9f7d49fa713d8b48949 --- include/hyperion/ColorCorrection.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 include/hyperion/ColorCorrection.h diff --git a/include/hyperion/ColorCorrection.h b/include/hyperion/ColorCorrection.h new file mode 100644 index 00000000..51ae0605 --- /dev/null +++ b/include/hyperion/ColorCorrection.h @@ -0,0 +1,18 @@ +#pragma once + +// STL includes +#include + +// Utils includes +#include + +class ColorCorrection +{ +public: + + /// Unique identifier for this color correction + std::string _id; + + /// The RGB correction + RgbChannelCorrection _rgbCorrection; +}; From e6fe6e5bc7160352f918b3789a730efe656f97a8 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Tue, 22 Dec 2015 09:57:08 +0100 Subject: [PATCH 02/54] Create HslTransform.h Former-commit-id: 2014641903af65c9ee1ac23cd90dad44d35f6c9f --- include/utils/HslTransform.h | 108 +++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 include/utils/HslTransform.h diff --git a/include/utils/HslTransform.h b/include/utils/HslTransform.h new file mode 100644 index 00000000..01eb4f55 --- /dev/null +++ b/include/utils/HslTransform.h @@ -0,0 +1,108 @@ +#pragma once + +// STL includes +#include + +/// +/// Color transformation to adjust the saturation and value of a RGB color value +/// +class HslTransform +{ +public: + /// + /// Default constructor + /// + HslTransform(); + + /// + /// Constructor + /// + /// @param saturationGain The used saturation gain + /// @param luminanceGain The used luminance gain + /// + HslTransform(double saturationGain, double luminanceGain); + + /// + /// Destructor + /// + ~HslTransform(); + + /// + /// Updates the saturation gain + /// + /// @param saturationGain New saturationGain + /// + void setSaturationGain(double saturationGain); + + /// + /// Returns the saturation gain + /// + /// @return The current Saturation gain + /// + double getSaturationGain() const; + + /// + /// Updates the luminance gain + /// + /// @param luminanceGain New luminance gain + /// + void setLuminanceGain(double luminanceGain); + + /// + /// Returns the luminance gain + /// + /// @return The current luminance gain + /// + double getLuminanceGain() const; + + /// + /// Apply the transform the the given RGB values. + /// + /// @param red The red color component + /// @param green The green color component + /// @param blue The blue color component + /// + /// @note The values are updated in place. + /// + void transform(uint8_t & red, uint8_t & green, uint8_t & blue) const; + + /// + /// Translates an RGB (red, green, blue) color to an HSL (hue, saturation, luminance) color + /// + /// @param[in] red The red RGB-component + /// @param[in] green The green RGB-component + /// @param[in] blue The blue RGB-component + /// @param[out] hue The hue HSL-component + /// @param[out] saturation The saturation HSL-component + /// @param[out] luminance The luminance HSL-component + /// + /// @note Integer version of the conversion are faster, but a little less accurate all values + /// are unsigned 8 bit values and scaled between 0 and 255 except for the hue which is a 16 bit + /// number and scaled between 0 and 360 + /// + static void rgb2hsl(uint8_t red, uint8_t green, uint8_t blue, uint16_t & hue, float & saturation, float & luminance); + + /// + /// Translates an HSL (hue, saturation, luminance) color to an RGB (red, green, blue) color + /// + /// @param[in] hue The hue HSV-component + /// @param[in] saturation The saturation HSV-component + /// @param[in] luminance The luminance HSL-component + /// @param[out] red The red RGB-component + /// @param[out] green The green RGB-component + /// @param[out] blue The blue RGB-component + /// + /// @note Integer version of the conversion are faster, but a little less accurate all values + /// are unsigned 8 bit values and scaled between 0 and 255 except for the hue which is a 16 bit + /// number and scaled between 0 and 360 + /// + static void hsl2rgb(uint16_t hue, float saturation, float luminance, uint8_t & red, uint8_t & green, uint8_t & blue); + +private: + /// The saturation gain + double _saturationGain; + /// The value gain + double _luminanceGain; + /// aux function + float hue2rgb(float p, float q, float t); +}; From 2eabc34f0981f279407ac53b37b5a61080885935 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Tue, 22 Dec 2015 09:58:49 +0100 Subject: [PATCH 03/54] Update HslTransform.h Former-commit-id: 634544dbb41949a55591f5b41ef956588c5c7946 --- include/utils/HslTransform.h | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/include/utils/HslTransform.h b/include/utils/HslTransform.h index 01eb4f55..f2151e65 100644 --- a/include/utils/HslTransform.h +++ b/include/utils/HslTransform.h @@ -4,7 +4,7 @@ #include /// -/// Color transformation to adjust the saturation and value of a RGB color value +/// Color transformation to adjust the saturation and luminance of a RGB color value /// class HslTransform { @@ -76,33 +76,25 @@ public: /// @param[out] saturation The saturation HSL-component /// @param[out] luminance The luminance HSL-component /// - /// @note Integer version of the conversion are faster, but a little less accurate all values - /// are unsigned 8 bit values and scaled between 0 and 255 except for the hue which is a 16 bit - /// number and scaled between 0 and 360 - /// + static void rgb2hsl(uint8_t red, uint8_t green, uint8_t blue, uint16_t & hue, float & saturation, float & luminance); /// /// Translates an HSL (hue, saturation, luminance) color to an RGB (red, green, blue) color /// - /// @param[in] hue The hue HSV-component - /// @param[in] saturation The saturation HSV-component + /// @param[in] hue The hue HSL-component + /// @param[in] saturation The saturation HSL-component /// @param[in] luminance The luminance HSL-component /// @param[out] red The red RGB-component /// @param[out] green The green RGB-component /// @param[out] blue The blue RGB-component /// - /// @note Integer version of the conversion are faster, but a little less accurate all values - /// are unsigned 8 bit values and scaled between 0 and 255 except for the hue which is a 16 bit - /// number and scaled between 0 and 360 - /// + static void hsl2rgb(uint16_t hue, float saturation, float luminance, uint8_t & red, uint8_t & green, uint8_t & blue); private: /// The saturation gain double _saturationGain; - /// The value gain + /// The luminance gain double _luminanceGain; - /// aux function - float hue2rgb(float p, float q, float t); }; From a23aa38f2010a210dcb2689489b471d1c9723410 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Tue, 22 Dec 2015 09:59:17 +0100 Subject: [PATCH 04/54] Create RgbChannelCorrection.h Former-commit-id: 7b0decaf9a9829cbc39a9d14db6bb42fb3d68445 --- include/utils/RgbChannelCorrection.h | 67 ++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 include/utils/RgbChannelCorrection.h diff --git a/include/utils/RgbChannelCorrection.h b/include/utils/RgbChannelCorrection.h new file mode 100644 index 00000000..7e00a633 --- /dev/null +++ b/include/utils/RgbChannelCorrection.h @@ -0,0 +1,67 @@ +#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 transformed 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]; +}; From 7773a82cb40935038eed3396b20cd1e793a49721 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Tue, 22 Dec 2015 09:59:55 +0100 Subject: [PATCH 05/54] Update RgbChannelCorrection.h Former-commit-id: 003e07c72d2244f2ffb6f4c4cb2b3b691ecaaad7 --- include/utils/RgbChannelCorrection.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/utils/RgbChannelCorrection.h b/include/utils/RgbChannelCorrection.h index 7e00a633..f09b9cef 100644 --- a/include/utils/RgbChannelCorrection.h +++ b/include/utils/RgbChannelCorrection.h @@ -41,7 +41,7 @@ public: /// Transform the given array value /// @param input The input color bytes - /// @return The transformed byte value + /// @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; @@ -60,7 +60,6 @@ private: int _correctionB; /// The mapping from input color to output color - int _mappingR[256]; int _mappingG[256]; int _mappingB[256]; From d3afc41040f98ad3b21961e3afeab507cb8dda00 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Tue, 22 Dec 2015 10:01:08 +0100 Subject: [PATCH 06/54] Update CMakeLists.txt Former-commit-id: 470a5b8f4a7c5a44b7aaff7a6c8f834ff55472bf --- libsrc/hyperion/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libsrc/hyperion/CMakeLists.txt b/libsrc/hyperion/CMakeLists.txt index 8f6a227d..f671fea5 100644 --- a/libsrc/hyperion/CMakeLists.txt +++ b/libsrc/hyperion/CMakeLists.txt @@ -18,6 +18,7 @@ SET(Hyperion_HEADERS ${CURRENT_HEADER_DIR}/PriorityMuxer.h ${CURRENT_SOURCE_DIR}/MultiColorTransform.h + ${CURRENT_SOURCE_DIR}/MultiColorCorrection.h ) SET(Hyperion_SOURCES @@ -29,6 +30,7 @@ SET(Hyperion_SOURCES ${CURRENT_SOURCE_DIR}/ImageToLedsMap.cpp ${CURRENT_SOURCE_DIR}/MultiColorTransform.cpp + ${CURRENT_SOURCE_DIR}/MultiColorCorrection.cpp ${CURRENT_SOURCE_DIR}/LinearColorSmoothing.cpp ) From 9acdf946bf5aae27ae995e6039e644fd9c3f053c Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Tue, 22 Dec 2015 10:01:47 +0100 Subject: [PATCH 07/54] Update Hyperion.cpp Former-commit-id: acf5e5c722402f7527ae0b942437d4c01917dccb --- libsrc/hyperion/Hyperion.cpp | 219 ++++++++++++++++++++++++++++++++++- 1 file changed, 217 insertions(+), 2 deletions(-) diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index d6657046..dc6ca3fb 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -15,12 +15,15 @@ // hyperion include #include #include +#include +#include // Leddevice includes #include #include #include "MultiColorTransform.h" +#include "MultiColorCorrection.h" #include "LinearColorSmoothing.h" // effect engine includes @@ -77,6 +80,7 @@ ColorTransform * Hyperion::createColorTransform(const Json::Value & transformCon RgbChannelTransform * blueTransform = createRgbChannelTransform(transformConfig["blue"]); HsvTransform * hsvTransform = createHsvTransform(transformConfig["hsv"]); + HslTransform * hslTransform = createHslTransform(transformConfig["hsl"]); ColorTransform * transform = new ColorTransform(); transform->_id = id; @@ -84,16 +88,35 @@ ColorTransform * Hyperion::createColorTransform(const Json::Value & transformCon transform->_rgbGreenTransform = *greenTransform; transform->_rgbBlueTransform = *blueTransform; transform->_hsvTransform = *hsvTransform; + transform->_hslTransform = *hslTransform; + // Cleanup the allocated individual transforms delete redTransform; delete greenTransform; delete blueTransform; delete hsvTransform; + delete hslTransform; return transform; } +ColorCorrection * Hyperion::createColorCorrection(const Json::Value & correctionConfig) +{ + const std::string id = correctionConfig.get("id", "default").asString(); + + RgbChannelCorrection * rgbCorrection = createRgbChannelCorrection(correctionConfig["correctionValues"]); + + ColorCorrection * correction = new ColorCorrection(); + correction->_id = id; + correction->_rgbCorrection = *rgbCorrection; + + // Cleanup the allocated individual transforms + delete rgbCorrection; + + return correction; +} + MultiColorTransform * Hyperion::createLedColorsTransform(const unsigned ledCnt, const Json::Value & colorConfig) { // Create the result, the transforms are added to this @@ -168,6 +191,154 @@ MultiColorTransform * Hyperion::createLedColorsTransform(const unsigned ledCnt, return transform; } +MultiColorCorrection * Hyperion::createLedColorsCorrection(const unsigned ledCnt, const Json::Value & colorConfig) +{ + // Create the result, the corrections are added to this + MultiColorCorrection * correction = new MultiColorCorrection(ledCnt); + + const Json::Value correctionConfig = colorConfig.get("correction", Json::nullValue); + if (correctionConfig.isNull()) + { + // Old style color correction config (just one for all leds) + ColorCorrection * colorCorrection = createColorCorrection(colorConfig); + correction->addCorrection(colorCorrection); + correction->setCorrectionForLed(colorCorrection->_id, 0, ledCnt-1); + } + else if (!correctionConfig.isArray()) + { + ColorCorrection * colorCorrection = createColorCorrection(colorConfig); + correction->addCorrection(colorCorrection); + correction->setCorrectionForLed(colorCorrection->_id, 0, ledCnt-1); + } + else + { + const QRegExp overallExp("([0-9]+(\\-[0-9]+)?)(,[ ]*([0-9]+(\\-[0-9]+)?))*"); + + for (Json::UInt i = 0; i < correctionConfig.size(); ++i) + { + const Json::Value & config = correctionConfig[i]; + ColorCorrection * colorCorrection = createColorCorrection(config); + correction->addCorrection(colorCorrection); + + const QString ledIndicesStr = QString(config.get("leds", "").asCString()).trimmed(); + if (ledIndicesStr.compare("*") == 0) + { + // Special case for indices '*' => all leds + correction->setCorrectionForLed(colorCorrection->_id, 0, ledCnt-1); + std::cout << "ColorCorrection '" << colorCorrection->_id << "' => [0; "<< ledCnt-1 << "]" << std::endl; + continue; + } + + if (!overallExp.exactMatch(ledIndicesStr)) + { + std::cerr << "Given led indices " << i << " not correct format: " << ledIndicesStr.toStdString() << std::endl; + continue; + } + + std::cout << "ColorCorrection '" << colorCorrection->_id << "' => ["; + + const QStringList ledIndexList = ledIndicesStr.split(","); + for (int i=0; i 0) + { + std::cout << ", "; + } + if (ledIndexList[i].contains("-")) + { + QStringList ledIndices = ledIndexList[i].split("-"); + int startInd = ledIndices[0].toInt(); + int endInd = ledIndices[1].toInt(); + + correction->setCorrectionForLed(colorCorrection->_id, startInd, endInd); + std::cout << startInd << "-" << endInd; + } + else + { + int index = ledIndexList[i].toInt(); + correction->setCorrectionForLed(colorCorrection->_id, index, index); + std::cout << index; + } + } + std::cout << "]" << std::endl; + } + } + return correction; +} + +MultiColorCorrection * Hyperion::createLedColorsTemperature(const unsigned ledCnt, const Json::Value & colorConfig) +{ + // Create the result, the corrections are added to this + MultiColorCorrection * correction = new MultiColorCorrection(ledCnt); + + const Json::Value correctionConfig = colorConfig.get("temperature", Json::nullValue); + if (correctionConfig.isNull()) + { + // Old style color correction config (just one for all leds) + ColorCorrection * colorCorrection = createColorCorrection(colorConfig); + correction->addCorrection(colorCorrection); + correction->setCorrectionForLed(colorCorrection->_id, 0, ledCnt-1); + } + else if (!correctionConfig.isArray()) + { + ColorCorrection * colorCorrection = createColorCorrection(colorConfig); + correction->addCorrection(colorCorrection); + correction->setCorrectionForLed(colorCorrection->_id, 0, ledCnt-1); + } + else + { + const QRegExp overallExp("([0-9]+(\\-[0-9]+)?)(,[ ]*([0-9]+(\\-[0-9]+)?))*"); + + for (Json::UInt i = 0; i < correctionConfig.size(); ++i) + { + const Json::Value & config = correctionConfig[i]; + ColorCorrection * colorCorrection = createColorCorrection(config); + correction->addCorrection(colorCorrection); + + const QString ledIndicesStr = QString(config.get("leds", "").asCString()).trimmed(); + if (ledIndicesStr.compare("*") == 0) + { + // Special case for indices '*' => all leds + correction->setCorrectionForLed(colorCorrection->_id, 0, ledCnt-1); + std::cout << "ColorCorrection '" << colorCorrection->_id << "' => [0; "<< ledCnt-1 << "]" << std::endl; + continue; + } + + if (!overallExp.exactMatch(ledIndicesStr)) + { + std::cerr << "Given led indices " << i << " not correct format: " << ledIndicesStr.toStdString() << std::endl; + continue; + } + + std::cout << "ColorCorrection '" << colorCorrection->_id << "' => ["; + + const QStringList ledIndexList = ledIndicesStr.split(","); + for (int i=0; i 0) + { + std::cout << ", "; + } + if (ledIndexList[i].contains("-")) + { + QStringList ledIndices = ledIndexList[i].split("-"); + int startInd = ledIndices[0].toInt(); + int endInd = ledIndices[1].toInt(); + + correction->setCorrectionForLed(colorCorrection->_id, startInd, endInd); + std::cout << startInd << "-" << endInd; + } + else + { + int index = ledIndexList[i].toInt(); + correction->setCorrectionForLed(colorCorrection->_id, index, index); + std::cout << index; + } + } + std::cout << "]" << std::endl; + } + } + return correction; +} + HsvTransform * Hyperion::createHsvTransform(const Json::Value & hsvConfig) { const double saturationGain = hsvConfig.get("saturationGain", 1.0).asDouble(); @@ -176,6 +347,14 @@ HsvTransform * Hyperion::createHsvTransform(const Json::Value & hsvConfig) return new HsvTransform(saturationGain, valueGain); } +HslTransform * Hyperion::createHslTransform(const Json::Value & hslConfig) +{ + const double saturationGain = hslConfig.get("saturationGain", 1.0).asDouble(); + const double luminanceGain = hslConfig.get("luminanceGain", 1.0).asDouble(); + + return new HslTransform(saturationGain, luminanceGain); +} + RgbChannelTransform* Hyperion::createRgbChannelTransform(const Json::Value& colorConfig) { const double threshold = colorConfig.get("threshold", 0.0).asDouble(); @@ -187,6 +366,16 @@ RgbChannelTransform* Hyperion::createRgbChannelTransform(const Json::Value& colo return transform; } +RgbChannelCorrection* 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); + return correction; +} + LedString Hyperion::createLedString(const Json::Value& ledsConfig, const ColorOrder deviceOrder) { LedString ledString; @@ -270,11 +459,17 @@ LedDevice * Hyperion::createColorSmoothing(const Json::Value & smoothingConfig, Hyperion::Hyperion(const Json::Value &jsonConfig) : _ledString(createLedString(jsonConfig["leds"], createColorOrder(jsonConfig["device"]))), _muxer(_ledString.leds().size()), + _raw2ledCorrection(createLedColorsCorrection(_ledString.leds().size(), jsonConfig["color"])), + _raw2ledTemperature(createLedColorsTemperature(_ledString.leds().size(), jsonConfig["color"])), _raw2ledTransform(createLedColorsTransform(_ledString.leds().size(), jsonConfig["color"])), _device(LedDeviceFactory::construct(jsonConfig["device"])), _effectEngine(nullptr), _timer() { + if (!_raw2ledCorrection->verifyCorrections()) + { + throw std::runtime_error("Color correction incorrectly set"); + } if (!_raw2ledTransform->verifyTransforms()) { throw std::runtime_error("Color transformation incorrectly set"); @@ -314,6 +509,9 @@ Hyperion::~Hyperion() // delete the color transform delete _raw2ledTransform; + + // delete the color correction + delete _raw2ledCorrection; } unsigned Hyperion::getLedCount() const @@ -359,16 +557,31 @@ const std::vector & Hyperion::getTransformIds() const return _raw2ledTransform->getTransformIds(); } +const std::vector & Hyperion::getCorrectionIds() const +{ + return _raw2ledCorrection->getCorrectionIds(); +} + ColorTransform * Hyperion::getTransform(const std::string& id) { return _raw2ledTransform->getTransform(id); } +ColorCorrection * Hyperion::getCorrection(const std::string& id) +{ + return _raw2ledCorrection->getCorrection(id); +} + void Hyperion::transformsUpdated() { update(); } +void Hyperion::correctionsUpdated() +{ + update(); +} + void Hyperion::clear(int priority) { if (_muxer.hasPriority(priority)) @@ -432,8 +645,10 @@ void Hyperion::update() int priority = _muxer.getCurrentPriority(); const PriorityMuxer::InputInfo & priorityInfo = _muxer.getInputInfo(priority); - // Apply the transform to each led and color-channel - std::vector ledColors = _raw2ledTransform->applyTransform(priorityInfo.ledColors); + // Apply the correction and the transform to each led and color-channel + std::vector correctedColors = _raw2ledCorrection->applyCorrection(priorityInfo.ledColors); + std::vector temperatureColors = _raw2ledTemperature->applyCorrection(correctedColors); + std::vector ledColors =_raw2ledTransform->applyTransform(temperatureColors); const std::vector& leds = _ledString.leds(); int i = 0; for (ColorRgb& color : ledColors) From 516df4b83a7595a20195ba74597ed4e0c51e0360 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Tue, 22 Dec 2015 10:06:04 +0100 Subject: [PATCH 08/54] Update Hyperion.cpp Former-commit-id: f5cb215d9d6625102530b7f2b1ccce5145ec0768 --- libsrc/hyperion/Hyperion.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index dc6ca3fb..eef3bd7d 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -470,6 +470,10 @@ Hyperion::Hyperion(const Json::Value &jsonConfig) : { throw std::runtime_error("Color correction incorrectly set"); } + if (!_raw2ledTemperature->verifyCorrections()) + { + throw std::runtime_error("Color temperature incorrectly set"); + } if (!_raw2ledTransform->verifyTransforms()) { throw std::runtime_error("Color transformation incorrectly set"); @@ -512,6 +516,9 @@ Hyperion::~Hyperion() // delete the color correction delete _raw2ledCorrection; + + // delete the color temperature correction + delete _raw2ledTemperature; } unsigned Hyperion::getLedCount() const @@ -562,6 +569,11 @@ const std::vector & Hyperion::getCorrectionIds() const return _raw2ledCorrection->getCorrectionIds(); } +const std::vector & Hyperion::getTemperatureIds() const +{ + return _raw2ledTemperature->getCorrectionIds(); +} + ColorTransform * Hyperion::getTransform(const std::string& id) { return _raw2ledTransform->getTransform(id); @@ -572,6 +584,11 @@ ColorCorrection * Hyperion::getCorrection(const std::string& id) return _raw2ledCorrection->getCorrection(id); } +ColorCorrection * Hyperion::getTemperature(const std::string& id) +{ + return _raw2ledTemperature->getCorrection(id); +} + void Hyperion::transformsUpdated() { update(); From aeed93ac838598a086e15189d62890b210a35bc2 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Tue, 22 Dec 2015 10:08:31 +0100 Subject: [PATCH 09/54] Create MultiColorCorrection.h Former-commit-id: 09d90cb6c5fe0479e659028363391d9e5c846e14 --- libsrc/hyperion/MultiColorCorrection.h | 66 ++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 libsrc/hyperion/MultiColorCorrection.h diff --git a/libsrc/hyperion/MultiColorCorrection.h b/libsrc/hyperion/MultiColorCorrection.h new file mode 100644 index 00000000..5f90fb12 --- /dev/null +++ b/libsrc/hyperion/MultiColorCorrection.h @@ -0,0 +1,66 @@ +#pragma once + +// STL includes +#include + +// Utils includes +#include + +// Hyperion includes +#include + +/// +/// The LedColorTransform is responsible for performing color transformation from 'raw' colors +/// received as input to colors mapped to match the color-properties of the leds. +/// +class MultiColorCorrection +{ +public: + MultiColorCorrection(const unsigned ledCnt); + ~MultiColorCorrection(); + + /** + * Adds a new ColorTransform to this MultiColorTransform + * + * @param transform The new ColorTransform (ownership is transfered) + */ + void addCorrection(ColorCorrection * correction); + + void setCorrectionForLed(const std::string& id, const unsigned startLed, const unsigned endLed); + + bool verifyCorrections() const; + + /// + /// Returns the identifier of all the unique ColorTransform + /// + /// @return The list with unique id's of the ColorTransforms + const std::vector & getCorrectionIds(); + + /// + /// Returns the pointer to the ColorTransform with the given id + /// + /// @param id The identifier of the ColorTransform + /// + /// @return The ColorTransform with the given id (or nullptr if it does not exist) + /// + ColorCorrection* getCorrection(const std::string& id); + + /// + /// Performs the color transoformation from raw-color to led-color + /// + /// @param rawColors The list with raw colors + /// + /// @return The list with led-colors + /// + std::vector applyCorrection(const std::vector& rawColors); + +private: + /// List with transform ids + std::vector _correctionIds; + + /// List with unique ColorTransforms + std::vector _correction; + + /// List with a pointer to the ColorTransform for each individual led + std::vector _ledCorrections; +}; From 27c41acdeebbc9eb7cb4be3b15e4acdba80be887 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Tue, 22 Dec 2015 10:08:55 +0100 Subject: [PATCH 10/54] Create MultiColorCorrection.cpp Former-commit-id: 9a69072ba9306024338cfa03691c6705890bcee3 --- libsrc/hyperion/MultiColorCorrection.cpp | 96 ++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 libsrc/hyperion/MultiColorCorrection.cpp diff --git a/libsrc/hyperion/MultiColorCorrection.cpp b/libsrc/hyperion/MultiColorCorrection.cpp new file mode 100644 index 00000000..c104c31b --- /dev/null +++ b/libsrc/hyperion/MultiColorCorrection.cpp @@ -0,0 +1,96 @@ + +// STL includes +#include + +// Hyperion includes +#include "MultiColorCorrection.h" + +MultiColorCorrection::MultiColorCorrection(const unsigned ledCnt) : + _ledCorrections(ledCnt, nullptr) +{ +} + +MultiColorCorrection::~MultiColorCorrection() +{ + // Clean up all the transforms + for (ColorCorrection * correction : _correction) + { + delete correction; + } +} + +void MultiColorCorrection::addCorrection(ColorCorrection * correction) +{ + _correctionIds.push_back(correction->_id); + _correction.push_back(correction); +} + +void MultiColorCorrection::setCorrectionForLed(const std::string& id, const unsigned startLed, const unsigned endLed) +{ + assert(startLed <= endLed); + assert(endLed < _ledCorrections.size()); + + // Get the identified correction (don't care if is nullptr) + ColorCorrection * correction = getCorrection(id); + for (unsigned iLed=startLed; iLed<=endLed; ++iLed) + { + _ledCorrections[iLed] = correction; + } +} + +bool MultiColorCorrection::verifyCorrections() const +{ + bool allLedsSet = true; + for (unsigned iLed=0; iLed<_ledCorrections.size(); ++iLed) + { + if (_ledCorrections[iLed] == nullptr) + { + std::cerr << "No correction set for " << iLed << std::endl; + allLedsSet = false; + } + } + return allLedsSet; +} + +const std::vector & MultiColorCorrection::getCorrectionIds() +{ + return _correctionIds; +} + +ColorCorrection* MultiColorCorrection::getCorrection(const std::string& id) +{ + // Iterate through the unique transforms until we find the one with the given id + for (ColorCorrection * correction : _correction) + { + if (correction->_id == id) + { + return correction; + } + } + + // The ColorTransform was not found + return nullptr; +} + +std::vector MultiColorCorrection::applyCorrection(const std::vector& rawColors) +{ + // Create a copy, as we will do the rest of the transformation in place + std::vector ledColors(rawColors); + + const size_t itCnt = std::min(_ledCorrections.size(), rawColors.size()); + for (size_t i=0; i_rgbCorrection.correctionR(color.red); + color.green = correction->_rgbCorrection.correctionG(color.green); + color.blue = correction->_rgbCorrection.correctionB(color.blue); + } + return ledColors; +} From 257532df74d0842af8fca3cb2122869e8b7eeb71 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Tue, 22 Dec 2015 10:09:47 +0100 Subject: [PATCH 11/54] Update Hyperion.h Former-commit-id: 932b50f14d2d2365d158f21290ddbf95cf7df0af --- include/hyperion/Hyperion.h | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/include/hyperion/Hyperion.h b/include/hyperion/Hyperion.h index b6ed0946..142e0523 100644 --- a/include/hyperion/Hyperion.h +++ b/include/hyperion/Hyperion.h @@ -13,6 +13,8 @@ // Hyperion includes #include #include +#include +#include // Effect engine includes #include @@ -22,8 +24,12 @@ class LedDevice; class ColorTransform; class EffectEngine; class HsvTransform; +class HslTransform; class RgbChannelTransform; +class RgbChannelCorrection; class MultiColorTransform; +class MultiColorCorrection; +class MultiColorTemperature; /// /// The main class of Hyperion. This gives other 'users' access to the attached LedDevice through @@ -115,15 +121,30 @@ public slots: /// @return The list with transform identifiers /// const std::vector & getTransformIds() const; + + /// + /// Returns the list with unique transform identifiers + /// @return The list with correction identifiers + /// + const std::vector & getCorrectionIds() const; /// /// Returns the ColorTransform with the given identifier /// @return The transform with the given identifier (or nullptr if the identifier does not exist) /// ColorTransform * getTransform(const std::string& id); + + /// + /// Returns the ColorTransform with the given identifier + /// @return The transform with the given identifier (or nullptr if the identifier does not exist) + /// + ColorCorrection * getCorrection(const std::string& id); /// Tell Hyperion that the transforms have changed and the leds need to be updated void transformsUpdated(); + + /// Tell Hyperion that the corrections have changed and the leds need to be updated + void correctionsUpdated(); /// /// Clears the given priority channel. This will switch the led-colors to the colors of the next @@ -163,9 +184,14 @@ public: static LedString createLedString(const Json::Value & ledsConfig, const ColorOrder deviceOrder); static MultiColorTransform * createLedColorsTransform(const unsigned ledCnt, const Json::Value & colorTransformConfig); + static MultiColorCorrection * createLedColorsCorrection(const unsigned ledCnt, const Json::Value & colorCorrectionConfig); + static MultiColorCorrection * createLedColorsTemperature(const unsigned ledCnt, const Json::Value & colorTemperatureConfig); static ColorTransform * createColorTransform(const Json::Value & transformConfig); + static ColorCorrection * createColorCorrection(const Json::Value & correctionConfig); 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 LedDevice * createColorSmoothing(const Json::Value & smoothingConfig, LedDevice * ledDevice); @@ -192,9 +218,15 @@ private: /// The priority muxer PriorityMuxer _muxer; - /// The transformation from raw colors to led colors + /// The transformation from corrected colors to led colors MultiColorTransform * _raw2ledTransform; - + + /// The correction from raw colors to led colors + MultiColorCorrection * _raw2ledCorrection; + + /// The temperature from corrected colors to led colors + MultiColorCorrection * _raw2ledTemperature; + /// The actual LedDevice LedDevice * _device; From 0ba143cd2078fc8cbba460bbe42f8fcfe9cb6edb Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Tue, 22 Dec 2015 10:12:34 +0100 Subject: [PATCH 12/54] Update MultiColorCorrection.h Former-commit-id: 82dee880f9614e813758b2d5c7e08c3a33aa6d4d --- libsrc/hyperion/MultiColorCorrection.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/libsrc/hyperion/MultiColorCorrection.h b/libsrc/hyperion/MultiColorCorrection.h index 5f90fb12..cdefce17 100644 --- a/libsrc/hyperion/MultiColorCorrection.h +++ b/libsrc/hyperion/MultiColorCorrection.h @@ -10,7 +10,7 @@ #include /// -/// The LedColorTransform is responsible for performing color transformation from 'raw' colors +/// The LedColorCorrection is responsible for performing color correction from 'raw' colors /// received as input to colors mapped to match the color-properties of the leds. /// class MultiColorCorrection @@ -20,9 +20,9 @@ public: ~MultiColorCorrection(); /** - * Adds a new ColorTransform to this MultiColorTransform + * Adds a new ColorCorrection to this MultiColorCorrection * - * @param transform The new ColorTransform (ownership is transfered) + * @param Correction The new ColorCorrection (ownership is transfered) */ void addCorrection(ColorCorrection * correction); @@ -31,17 +31,17 @@ public: bool verifyCorrections() const; /// - /// Returns the identifier of all the unique ColorTransform + /// Returns the identifier of all the unique ColorCorrection /// - /// @return The list with unique id's of the ColorTransforms + /// @return The list with unique id's of the ColorCorrections const std::vector & getCorrectionIds(); /// - /// Returns the pointer to the ColorTransform with the given id + /// Returns the pointer to the ColorCorrection with the given id /// - /// @param id The identifier of the ColorTransform + /// @param id The identifier of the ColorCorrection /// - /// @return The ColorTransform with the given id (or nullptr if it does not exist) + /// @return The ColorCorrection with the given id (or nullptr if it does not exist) /// ColorCorrection* getCorrection(const std::string& id); @@ -55,12 +55,12 @@ public: std::vector applyCorrection(const std::vector& rawColors); private: - /// List with transform ids + /// List with Correction ids std::vector _correctionIds; - /// List with unique ColorTransforms + /// List with unique ColorCorrections std::vector _correction; - /// List with a pointer to the ColorTransform for each individual led + /// List with a pointer to the ColorCorrection for each individual led std::vector _ledCorrections; }; From 5215e45f1088c1a9e46609c73a2aea7e428e1973 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Tue, 22 Dec 2015 10:13:01 +0100 Subject: [PATCH 13/54] Update MultiColorCorrection.cpp Former-commit-id: ec17038daea5061bf4910a4884d715e767604155 --- libsrc/hyperion/MultiColorCorrection.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libsrc/hyperion/MultiColorCorrection.cpp b/libsrc/hyperion/MultiColorCorrection.cpp index c104c31b..6388d27e 100644 --- a/libsrc/hyperion/MultiColorCorrection.cpp +++ b/libsrc/hyperion/MultiColorCorrection.cpp @@ -12,7 +12,7 @@ MultiColorCorrection::MultiColorCorrection(const unsigned ledCnt) : MultiColorCorrection::~MultiColorCorrection() { - // Clean up all the transforms + // Clean up all the correctinos for (ColorCorrection * correction : _correction) { delete correction; @@ -59,7 +59,7 @@ const std::vector & MultiColorCorrection::getCorrectionIds() ColorCorrection* MultiColorCorrection::getCorrection(const std::string& id) { - // Iterate through the unique transforms until we find the one with the given id + // Iterate through the unique corrections until we find the one with the given id for (ColorCorrection * correction : _correction) { if (correction->_id == id) @@ -68,13 +68,13 @@ ColorCorrection* MultiColorCorrection::getCorrection(const std::string& id) } } - // The ColorTransform was not found + // The ColorCorrection was not found return nullptr; } std::vector MultiColorCorrection::applyCorrection(const std::vector& rawColors) { - // Create a copy, as we will do the rest of the transformation in place + // Create a copy, as we will do the rest of the correction in place std::vector ledColors(rawColors); const size_t itCnt = std::min(_ledCorrections.size(), rawColors.size()); @@ -83,7 +83,7 @@ std::vector MultiColorCorrection::applyCorrection(const std::vector Date: Wed, 9 Mar 2016 19:36:08 +0100 Subject: [PATCH 14/54] Update Hyperion.h Former-commit-id: 2497c6ea7d153e01e49ed0683e92837106628d44 --- include/hyperion/Hyperion.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/hyperion/Hyperion.h b/include/hyperion/Hyperion.h index 142e0523..516efc2d 100644 --- a/include/hyperion/Hyperion.h +++ b/include/hyperion/Hyperion.h @@ -15,6 +15,7 @@ #include #include #include +#include // Effect engine includes #include From 1fa54a1cee07426b370f7e81eefc772201807a59 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Wed, 9 Mar 2016 19:42:18 +0100 Subject: [PATCH 15/54] Update CMakeLists.txt Former-commit-id: 5182f0e28c8914a970db7c4c0d9fee68d7481e65 --- libsrc/hyperion/CMakeLists.txt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libsrc/hyperion/CMakeLists.txt b/libsrc/hyperion/CMakeLists.txt index f671fea5..68039881 100644 --- a/libsrc/hyperion/CMakeLists.txt +++ b/libsrc/hyperion/CMakeLists.txt @@ -19,6 +19,7 @@ SET(Hyperion_HEADERS ${CURRENT_SOURCE_DIR}/MultiColorTransform.h ${CURRENT_SOURCE_DIR}/MultiColorCorrection.h + ${CURRENT_HEADER_DIR}/MessageForwarder.h ) SET(Hyperion_SOURCES @@ -38,9 +39,13 @@ set(Hyperion_RESOURCES ${CURRENT_SOURCE_DIR}/resource.qrc ) +if(ENABLE_QT5) +QT5_WRAP_CPP(Hyperion_HEADERS_MOC ${Hyperion_QT_HEADERS}) +QT5_ADD_RESOURCES(Hyperion_RESOURCES_RCC ${Hyperion_RESOURCES} OPTIONS "-no-compress") +else(ENABLE_QT5) QT4_WRAP_CPP(Hyperion_HEADERS_MOC ${Hyperion_QT_HEADERS}) - QT4_ADD_RESOURCES(Hyperion_RESOURCES_RCC ${Hyperion_RESOURCES} OPTIONS "-no-compress") +endif(ENABLE_QT5) add_library(hyperion ${Hyperion_HEADERS} @@ -50,6 +55,10 @@ add_library(hyperion ${Hyperion_RESOURCES_RCC} ) +if(ENABLE_QT5) +qt5_use_modules(hyperion Widgets) +endif(ENABLE_QT5) + target_link_libraries(hyperion blackborder hyperion-utils From 88e4737b8b47f31a0bc429796dcb87f40eb3a0e2 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Wed, 9 Mar 2016 19:42:54 +0100 Subject: [PATCH 16/54] Update CMakeLists.txt Former-commit-id: 8afa5615ac8ff62ac6492083f2d2c487cf305dbc --- libsrc/hyperion/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/libsrc/hyperion/CMakeLists.txt b/libsrc/hyperion/CMakeLists.txt index 68039881..a2188127 100644 --- a/libsrc/hyperion/CMakeLists.txt +++ b/libsrc/hyperion/CMakeLists.txt @@ -33,6 +33,7 @@ SET(Hyperion_SOURCES ${CURRENT_SOURCE_DIR}/MultiColorTransform.cpp ${CURRENT_SOURCE_DIR}/MultiColorCorrection.cpp ${CURRENT_SOURCE_DIR}/LinearColorSmoothing.cpp + ${CURRENT_SOURCE_DIR}/MessageForwarder.cpp ) set(Hyperion_RESOURCES From 63e3380ff7574ad7b39401641a50b6736bad3c55 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Wed, 9 Mar 2016 19:45:00 +0100 Subject: [PATCH 17/54] Update Hyperion.cpp Former-commit-id: 24638e6009da0dc3a2168caef53e09664c1db095 --- libsrc/hyperion/Hyperion.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index eef3bd7d..29ee24a3 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -455,6 +455,37 @@ LedDevice * Hyperion::createColorSmoothing(const Json::Value & smoothingConfig, return ledDevice; } +MessageForwarder * Hyperion::createMessageForwarder(const Json::Value & forwarderConfig) +{ + MessageForwarder * forwarder = new MessageForwarder(); + if ( ! forwarderConfig.isNull() ) + { + if ( ! forwarderConfig["json"].isNull() && forwarderConfig["json"].isArray() ) + { + for (const Json::Value& addr : forwarderConfig["json"]) + { + std::cout << "Json forward to " << addr.asString() << std::endl; + forwarder->addJsonSlave(addr.asString()); + } + } + + if ( ! forwarderConfig["proto"].isNull() && forwarderConfig["proto"].isArray() ) + { + for (const Json::Value& addr : forwarderConfig["proto"]) + { + std::cout << "Proto forward to " << addr.asString() << std::endl; + forwarder->addProtoSlave(addr.asString()); + } + } + } + + return forwarder; +} + +MessageForwarder * Hyperion::getForwarder() +{ + return _messageForwarder; +} Hyperion::Hyperion(const Json::Value &jsonConfig) : _ledString(createLedString(jsonConfig["leds"], createColorOrder(jsonConfig["device"]))), @@ -519,6 +550,9 @@ Hyperion::~Hyperion() // delete the color temperature correction delete _raw2ledTemperature; + + // delete the message forwarder + delete _messageForwarder; } unsigned Hyperion::getLedCount() const From bcb080254251193ec877b216e5bd10d5aab94d6b Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Wed, 9 Mar 2016 19:55:55 +0100 Subject: [PATCH 18/54] Update Hyperion.h Former-commit-id: 877c98ea4c6f5503fda14914e315c2b9eb301a44 --- include/hyperion/Hyperion.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/hyperion/Hyperion.h b/include/hyperion/Hyperion.h index 516efc2d..a8691953 100644 --- a/include/hyperion/Hyperion.h +++ b/include/hyperion/Hyperion.h @@ -140,6 +140,12 @@ public slots: /// @return The transform with the given identifier (or nullptr if the identifier does not exist) /// ColorCorrection * getCorrection(const std::string& id); + + /// + /// Returns MessageForwarder Object + /// @return instance of message forwarder object + /// + MessageForwarder * getForwarder(); /// Tell Hyperion that the transforms have changed and the leds need to be updated void transformsUpdated(); @@ -195,6 +201,7 @@ public: static RgbChannelCorrection * createRgbChannelCorrection(const Json::Value& colorConfig); static LedDevice * createColorSmoothing(const Json::Value & smoothingConfig, LedDevice * ledDevice); + static MessageForwarder * createMessageForwarder(const Json::Value & forwarderConfig); signals: /// Signal which is emitted when a priority channel is actively cleared @@ -233,6 +240,9 @@ private: /// Effect engine EffectEngine * _effectEngine; + + //protoo and json Message forwarder + MessageForwarder * _messageForwarder; /// The timer for handling priority channel timeouts QTimer _timer; From 90b9acf68e16f9982b9bef41fb4a14a28e7a8d3b Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Wed, 9 Mar 2016 19:57:03 +0100 Subject: [PATCH 19/54] Update Hyperion.cpp Former-commit-id: 4c3f0a561d7def20dd713add0d437bdf12431e0b --- libsrc/hyperion/Hyperion.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index 29ee24a3..79300f0c 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -495,6 +495,7 @@ Hyperion::Hyperion(const Json::Value &jsonConfig) : _raw2ledTransform(createLedColorsTransform(_ledString.leds().size(), jsonConfig["color"])), _device(LedDeviceFactory::construct(jsonConfig["device"])), _effectEngine(nullptr), + _messageForwarder(createMessageForwarder(jsonConfig["forwarder"])), _timer() { if (!_raw2ledCorrection->verifyCorrections()) @@ -512,8 +513,8 @@ Hyperion::Hyperion(const Json::Value &jsonConfig) : // initialize the image processor factory ImageProcessorFactory::getInstance().init( _ledString, - jsonConfig["blackborderdetector"].get("enable", true).asBool(), - jsonConfig["blackborderdetector"].get("threshold", 0.01).asDouble()); + jsonConfig["blackborderdetector"] + ); // initialize the color smoothing filter _device = createColorSmoothing(jsonConfig["color"]["smoothing"], _device); From 8b2603391545e564b10351f53b6dbea73663978f Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Wed, 9 Mar 2016 19:58:49 +0100 Subject: [PATCH 20/54] Update Hyperion.h Former-commit-id: 9e4ab548db0f2805386d90bfe9cde3aa9426aab5 --- include/hyperion/Hyperion.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/hyperion/Hyperion.h b/include/hyperion/Hyperion.h index a8691953..8ffc7fe5 100644 --- a/include/hyperion/Hyperion.h +++ b/include/hyperion/Hyperion.h @@ -241,7 +241,7 @@ private: /// Effect engine EffectEngine * _effectEngine; - //protoo and json Message forwarder + // proto and json Message forwarder MessageForwarder * _messageForwarder; /// The timer for handling priority channel timeouts From 266f0e6694a27417d6361c7807d1505fff3e5f5d Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Thu, 10 Mar 2016 07:57:47 +0100 Subject: [PATCH 21/54] Update .gitignore Former-commit-id: b33283298729bdca7c78d855964c3126735fd57b --- .gitignore | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitignore b/.gitignore index 7f9c9c20..3c242a4c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ /*.user /build* .DS_Store - -libsrc/hyperion/ImageProcessor.cpp -libsrc/hyperion/CMakeLists.txt From 9f273410a15ab0743d3bd22907964aae72d4c230 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Thu, 10 Mar 2016 07:58:30 +0100 Subject: [PATCH 22/54] Update .gitignore Former-commit-id: 416ddb32c74a723acc019283ab3330f88666a1e9 --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 3c242a4c..91a498c3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /*.user /build* .DS_Store + From 9e13303a4ae7a1ae5bed49143255a14cca40e807 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Thu, 10 Mar 2016 17:27:25 +0100 Subject: [PATCH 23/54] Added files via upload Former-commit-id: 55b74524b06af6f5c443053a56216c0db465fb2f --- libsrc/utils/HslTransform.cpp | 158 ++++++++++++++++++++++++++ libsrc/utils/RgbChannelCorrection.cpp | 120 +++++++++++++++++++ 2 files changed, 278 insertions(+) create mode 100644 libsrc/utils/HslTransform.cpp create mode 100644 libsrc/utils/RgbChannelCorrection.cpp diff --git a/libsrc/utils/HslTransform.cpp b/libsrc/utils/HslTransform.cpp new file mode 100644 index 00000000..09056bb2 --- /dev/null +++ b/libsrc/utils/HslTransform.cpp @@ -0,0 +1,158 @@ +#include +#include +#include + +HslTransform::HslTransform() : + _saturationGain(1.0), + _luminanceGain(1.0) +{ +} + +HslTransform::HslTransform(double saturationGain, double luminanceGain) : + _saturationGain(saturationGain), + _luminanceGain(luminanceGain) +{ +} + +HslTransform::~HslTransform() +{ +} + +void HslTransform::setSaturationGain(double saturationGain) +{ + _saturationGain = saturationGain; +} + +double HslTransform::getSaturationGain() const +{ + return _saturationGain; +} + +void HslTransform::setLuminanceGain(double luminanceGain) +{ + _luminanceGain = luminanceGain; +} + +double HslTransform::getLuminanceGain() const +{ + return _luminanceGain; +} + +void HslTransform::transform(uint8_t & red, uint8_t & green, uint8_t & blue) const +{ + if (_saturationGain != 1.0 || _luminanceGain != 1.0) + { + uint16_t hue; + float saturation, luminance; + rgb2hsl(red, green, blue, hue, saturation, luminance); + + float s = saturation * _saturationGain; + if (s > 1.0f) + saturation = 1.0f; + else + saturation = s; + + float l = luminance * _luminanceGain; + if (l > 1.0f) + luminance = 1.0f; + else + luminance = l; + + hsl2rgb(hue, saturation, luminance, red, green, blue); + } +} + +void HslTransform::rgb2hsl(uint8_t red, uint8_t green, uint8_t blue, uint16_t & hue, float & saturation, float & luminance) +{ + float r = red / 255.0f; + float g = green / 255.0f; + float b = blue / 255.0f; + + float rgbMin = r < g ? (r < b ? r : b) : (g < b ? g : b); + float rgbMax = r > g ? (r > b ? r : b) : (g > b ? g : b); + float diff = rgbMax - rgbMin; + + //luminance + luminance = (rgbMin + rgbMax) / 2.0f; + + if (diff == 0.0f) { + saturation = 0.0f; + hue = 0; + return; + } + + //saturation + if (luminance < 0.5f) + saturation = diff / (rgbMin + rgbMax); + else + saturation = diff / (2.0f - rgbMin - rgbMax); + + if (rgbMax == r) + { + // start from 360 to be sure that we won't assign a negative number to the unsigned hue value + hue = 360 + 60 * (g - b) / (rgbMax - rgbMin); + + if (hue > 359) + hue -= 360; + } + else if (rgbMax == g) + { + hue = 120 + 60 * (b - r) / (rgbMax - rgbMin); + } + else + { + hue = 240 + 60 * (r - g) / (rgbMax - rgbMin); + } + +} + +void HslTransform::hsl2rgb(uint16_t hue, float saturation, float luminance, uint8_t & red, uint8_t & green, uint8_t & blue) +{ + if (saturation == 0.0f){ + red = (uint8_t)(luminance * 255.0f); + green = (uint8_t)(luminance * 255.0f); + blue = (uint8_t)(luminance * 255.0f); + return; + } + + float q; + + if (luminance < 0.5f) + q = luminance * (1.0f + saturation); + else + q = (luminance + saturation) - (luminance * saturation); + + float p = (2.0f * luminance) - q; + float h = hue / 360.0f; + + float t[3]; + + t[0] = h + (1.0f / 3.0f); + t[1] = h; + t[2] = h - (1.0f / 3.0f); + + for (int i = 0; i < 3; i++) { + if (t[i] < 0.0f) + t[i] += 1.0f; + if (t[i] > 1.0f) + t[i] -= 1.0f; + } + + float out[3]; + + for (int i = 0; i < 3; i++) { + if (t[i] * 6.0f < 1.0f) + out[i] = p + (q - p) * 6.0f * t[i]; + else if (t[i] * 2.0f < 1.0f) + out[i] = q; + else if (t[i] * 3.0f < 2.0f) + out[i] = p + (q - p) * ((2.0f / 3.0f) - t[i]) * 6.0f; + else out[i] = p; + } + + //convert back to 0...255 range + red = (uint8_t)(out[0] * 255.0f); + green = (uint8_t)(out[1] * 255.0f); + blue = (uint8_t)(out[2] * 255.0f); + +} diff --git a/libsrc/utils/RgbChannelCorrection.cpp b/libsrc/utils/RgbChannelCorrection.cpp new file mode 100644 index 00000000..2cced20b --- /dev/null +++ b/libsrc/utils/RgbChannelCorrection.cpp @@ -0,0 +1,120 @@ +// STL includes +#include + +// Utils includes +#include + +RgbChannelCorrection::RgbChannelCorrection() : + _correctionR(255), + _correctionB(255), + _correctionG(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; + } + + +} + From b6c08ae34ff6ac3d83ac5fceec2bd14ceb5fc2a7 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Thu, 10 Mar 2016 17:28:34 +0100 Subject: [PATCH 24/54] Update CMakeLists.txt Former-commit-id: 808a5c9a22a57f6d6ee77adb1c1f112b291b7188 --- libsrc/utils/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libsrc/utils/CMakeLists.txt b/libsrc/utils/CMakeLists.txt index 1aad10cb..8de00707 100644 --- a/libsrc/utils/CMakeLists.txt +++ b/libsrc/utils/CMakeLists.txt @@ -23,8 +23,12 @@ add_library(hyperion-utils ${CURRENT_HEADER_DIR}/HsvTransform.h ${CURRENT_SOURCE_DIR}/HsvTransform.cpp + ${CURRENT_HEADER_DIR}/HslTransform.h + ${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}/jsonschema/JsonFactory.h ${CURRENT_HEADER_DIR}/jsonschema/JsonSchemaChecker.h From 3370cc6271a332c92d7feaa8c52159b6372cecf5 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Thu, 10 Mar 2016 17:54:39 +0100 Subject: [PATCH 25/54] Update MultiColorTransform.cpp Former-commit-id: c743c2fec460d645b64c1172212469287af6a8db --- libsrc/hyperion/MultiColorTransform.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libsrc/hyperion/MultiColorTransform.cpp b/libsrc/hyperion/MultiColorTransform.cpp index d15f020e..0b524acf 100644 --- a/libsrc/hyperion/MultiColorTransform.cpp +++ b/libsrc/hyperion/MultiColorTransform.cpp @@ -89,6 +89,7 @@ std::vector MultiColorTransform::applyTransform(const std::vector_hsvTransform.transform(color.red, color.green, color.blue); + transform->_hslTransform.transform(color.red, color.green, color.blue); color.red = transform->_rgbRedTransform.transform(color.red); color.green = transform->_rgbGreenTransform.transform(color.green); color.blue = transform->_rgbBlueTransform.transform(color.blue); From b0d74b2dd8271fcb5a781e9133715aa42f2909e7 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Thu, 10 Mar 2016 17:57:52 +0100 Subject: [PATCH 26/54] Update ColorTransform.h Former-commit-id: 4c944b94cf26720906efa63ea4266064dc092134 --- include/hyperion/ColorTransform.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/hyperion/ColorTransform.h b/include/hyperion/ColorTransform.h index 50cbedba..998d6a60 100644 --- a/include/hyperion/ColorTransform.h +++ b/include/hyperion/ColorTransform.h @@ -6,6 +6,7 @@ // Utils includes #include #include +#include class ColorTransform { @@ -23,4 +24,7 @@ public: /// The HSV Transform for applying Saturation and Value transforms HsvTransform _hsvTransform; + + /// The HSL Transform for applying Saturation and Value transforms + HslTransform _hslTransform; }; From 6e7157c5715b9e6d6155ca6584ba6fc079ddada2 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Thu, 10 Mar 2016 18:08:34 +0100 Subject: [PATCH 27/54] Update Hyperion.h Former-commit-id: c1bd4a7397e8ae2e72b9ef5dcc32ee3b866e2c36 --- include/hyperion/Hyperion.h | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/include/hyperion/Hyperion.h b/include/hyperion/Hyperion.h index 8ffc7fe5..88c480d3 100644 --- a/include/hyperion/Hyperion.h +++ b/include/hyperion/Hyperion.h @@ -124,11 +124,17 @@ public slots: const std::vector & getTransformIds() const; /// - /// Returns the list with unique transform identifiers + /// Returns the list with unique correction identifiers /// @return The list with correction identifiers /// const std::vector & getCorrectionIds() const; - + + /// + /// Returns the list with unique correction identifiers + /// @return The list with correction identifiers + /// + const std::vector & getTemperatureIds() const; + /// /// Returns the ColorTransform with the given identifier /// @return The transform with the given identifier (or nullptr if the identifier does not exist) @@ -136,11 +142,17 @@ public slots: ColorTransform * getTransform(const std::string& id); /// - /// Returns the ColorTransform with the given identifier - /// @return The transform with the given identifier (or nullptr if the identifier does not exist) + /// Returns the ColorCorrection with the given identifier + /// @return The correction with the given identifier (or nullptr if the identifier does not exist) /// ColorCorrection * getCorrection(const std::string& id); + /// + /// Returns the ColorCorrection with the given identifier + /// @return The correction with the given identifier (or nullptr if the identifier does not exist) + /// + ColorCorrection * getTemperature(const std::string& id); + /// /// Returns MessageForwarder Object /// @return instance of message forwarder object @@ -152,6 +164,9 @@ public slots: /// Tell Hyperion that the corrections have changed and the leds need to be updated void correctionsUpdated(); + + /// Tell Hyperion that the corrections have changed and the leds need to be updated + void temperaturesUpdated(); /// /// Clears the given priority channel. This will switch the led-colors to the colors of the next From da7183d28bd4485b26113303097aaac759310bc1 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Thu, 10 Mar 2016 18:13:46 +0100 Subject: [PATCH 28/54] Update Hyperion.cpp Former-commit-id: 5bad6209c49a8fd9eba5582119d9e130b9bea565 --- libsrc/hyperion/Hyperion.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index 79300f0c..b564b3a6 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -634,6 +634,11 @@ void Hyperion::correctionsUpdated() update(); } +void Hyperion::temperaturesUpdated() +{ + update(); +} + void Hyperion::clear(int priority) { if (_muxer.hasPriority(priority)) From 0baebe387342b8a544dd6c7b388a5dda78b25f28 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Fri, 11 Mar 2016 12:20:59 +0100 Subject: [PATCH 29/54] Update hyperion-remote.cpp Former-commit-id: bb2282e48bdd93d4dffcd763ff34e33d3f00670c --- src/hyperion-remote/hyperion-remote.cpp | 84 +++++++++++++++++++++---- 1 file changed, 72 insertions(+), 12 deletions(-) diff --git a/src/hyperion-remote/hyperion-remote.cpp b/src/hyperion-remote/hyperion-remote.cpp index 3636721f..e548fbdc 100644 --- a/src/hyperion-remote/hyperion-remote.cpp +++ b/src/hyperion-remote/hyperion-remote.cpp @@ -53,20 +53,30 @@ int main(int argc, char * argv[]) IntParameter & argDuration = parameters.add ('d', "duration" , "Specify how long the leds should be switched on in millseconds [default: infinity]"); ColorParameter & argColor = parameters.add ('c', "color" , "Set all leds to a constant color (either RRGGBB hex value or a color name. The color may be repeated multiple time like: RRGGBBRRGGBB)"); ImageParameter & argImage = parameters.add ('i', "image" , "Set the leds to the colors according to the given image file"); - StringParameter & argEffect = parameters.add ('e', "effect" , "Enable the effect with the given name"); - StringParameter & argEffectArgs = parameters.add (0x0, "effectArgs", "Arguments to use in combination with the specified effect. Should be a Json object string."); + StringParameter & argEffect = parameters.add ('e', "effect" , "Enable the effect with the given name"); + StringParameter & argEffectArgs = parameters.add (0x0, "effectArgs", "Arguments to use in combination with the specified effect. Should be a Json object string."); SwitchParameter<> & argServerInfo = parameters.add >('l', "list" , "List server info"); SwitchParameter<> & argClear = parameters.add >('x', "clear" , "Clear data for the priority channel provided by the -p option"); SwitchParameter<> & argClearAll = parameters.add >(0x0, "clearall" , "Clear data for all active priority channels"); StringParameter & argId = parameters.add ('q', "qualifier" , "Identifier(qualifier) of the transform to set"); DoubleParameter & argSaturation = parameters.add ('s', "saturation", "Set the HSV saturation gain of the leds"); DoubleParameter & argValue = parameters.add ('v', "value" , "Set the HSV value gain of the leds"); + DoubleParameter & argSaturationL = parameters.add ('u', "saturationL", "Set the HSL saturation gain of the leds"); + DoubleParameter & argLuminance = parameters.add ('m', "luminance" , "Set the HSL luminance gain of the leds"); TransformParameter & argGamma = parameters.add('g', "gamma" , "Set the gamma of the leds (requires 3 space seperated values)"); TransformParameter & argThreshold = parameters.add('t', "threshold" , "Set the threshold of the leds (requires 3 space seperated values between 0.0 and 1.0)"); TransformParameter & argBlacklevel = parameters.add('b', "blacklevel", "Set the blacklevel of the leds (requires 3 space seperated values which are normally between 0.0 and 1.0)"); TransformParameter & argWhitelevel = parameters.add('w', "whitelevel", "Set the whitelevel of the leds (requires 3 space seperated values which are normally between 0.0 and 1.0)"); SwitchParameter<> & argPrint = parameters.add >(0x0, "print" , "Print the json input and output messages on stdout"); SwitchParameter<> & argHelp = parameters.add >('h', "help" , "Show this help message and exit"); + StringParameter & argIdC = parameters.add ('cq', "qualifier" , "Identifier(qualifier) of the correction to set"); + IntParameter & argCorrR = parameters.add ('cr', "correctionR" , "Specify the red channel correction factor"); + IntParameter & argCorrG = parameters.add ('cg', "correctionG" , "Specify the green channel correction factor"); + IntParameter & argCorrB = parameters.add ('cb', "correctionB" , "Specify the blue channel correction factor"); + StringParameter & argIdT = parameters.add ('tq', "qualifier" , "Identifier(qualifier) of the temperature to set"); + IntParameter & argTempR = parameters.add ('tr', "tempR" , "Specify the red channel temperature factor"); + IntParameter & argTempG = parameters.add ('tg', "tempG" , "Specify the red channel temperature factor"); + IntParameter & argTempB = parameters.add ('tb', "tempB" , "Specify the red channel temperature factor"); // set the default values argAddress.setDefault(defaultServerAddress.toStdString()); @@ -85,27 +95,41 @@ int main(int argc, char * argv[]) } // check if at least one of the available color transforms is set - bool colorTransform = argSaturation.isSet() || argValue.isSet() || argThreshold.isSet() || argGamma.isSet() || argBlacklevel.isSet() || argWhitelevel.isSet(); + bool colorTransform = argSaturation.isSet() || argValue.isSet() || argSaturationL.isSet() || argLuminance.isSet() || argThreshold.isSet() || argGamma.isSet() || argBlacklevel.isSet() || argWhitelevel.isSet(); + bool colorCorrection = argCorrR.isSet() || argCorrG.isSet() || argCorrB.isSet(); + bool colorTemp = argTempR.isSet() || argTempG.isSet() || argTempB.isSet(); // check that exactly one command was given - int commandCount = count({argColor.isSet(), argImage.isSet(), argEffect.isSet(), argServerInfo.isSet(), argClear.isSet(), argClearAll.isSet(), colorTransform}); + int commandCount = count({argColor.isSet(), argImage.isSet(), argEffect.isSet(), argServerInfo.isSet(), argClear.isSet(), argClearAll.isSet(), colorTransform, colorCorrection, colorTemp}); if (commandCount != 1) { std::cerr << (commandCount == 0 ? "No command found." : "Multiple commands found.") << " Provide exactly one of the following options:" << std::endl; std::cerr << " " << argColor.usageLine() << std::endl; std::cerr << " " << argImage.usageLine() << std::endl; - std::cerr << " " << argEffect.usageLine() << std::endl; + std::cerr << " " << argEffect.usageLine() << std::endl; std::cerr << " " << argServerInfo.usageLine() << std::endl; std::cerr << " " << argClear.usageLine() << std::endl; std::cerr << " " << argClearAll.usageLine() << std::endl; - std::cerr << "or one or more of the available color transformations:" << std::endl; + std::cerr << "one or more of the available color transformations:" << std::endl; std::cerr << " " << argId.usageLine() << std::endl; std::cerr << " " << argSaturation.usageLine() << std::endl; std::cerr << " " << argValue.usageLine() << std::endl; + std::cerr << " " << argSaturationL.usageLine() << std::endl; + std::cerr << " " << argLuminance.usageLine() << std::endl; std::cerr << " " << argThreshold.usageLine() << std::endl; std::cerr << " " << argGamma.usageLine() << std::endl; std::cerr << " " << argBlacklevel.usageLine() << std::endl; std::cerr << " " << argWhitelevel.usageLine() << std::endl; + std::cerr << "one or more of the available color corrections:" << std::endl; + std::cerr << " " << argIdC.usageLine() << std::endl; + std::cerr << " " << argCorrR.usageLine() << std::endl; + std::cerr << " " << argCorrG.usageLine() << std::endl; + std::cerr << " " << argCorrB.usageLine() << std::endl; + std::cerr << "or one or more of the available color temperature adjustment:" << std::endl; + std::cerr << " " << argIdT.usageLine() << std::endl; + std::cerr << " " << argTempR.usageLine() << std::endl; + std::cerr << " " << argTempG.usageLine() << std::endl; + std::cerr << " " << argTempB.usageLine() << std::endl; return 1; } @@ -121,11 +145,11 @@ int main(int argc, char * argv[]) { connection.setImage(argImage.getValue(), argPriority.getValue(), argDuration.getValue()); } - else if (argEffect.isSet()) - { - connection.setEffect(argEffect.getValue(), argEffectArgs.getValue(), argPriority.getValue(), argDuration.getValue()); - } - else if (argServerInfo.isSet()) + else if (argEffect.isSet()) + { + connection.setEffect(argEffect.getValue(), argEffectArgs.getValue(), argPriority.getValue(), argDuration.getValue()); + } + else if (argServerInfo.isSet()) { QString info = connection.getServerInfo(); std::cout << "Server info:\n" << info.toStdString() << std::endl; @@ -141,12 +165,14 @@ int main(int argc, char * argv[]) else if (colorTransform) { std::string transId; - double saturation, value; + double saturation, value, saturationL, luminance; ColorTransformValues threshold, gamma, blacklevel, whitelevel; if (argId.isSet()) transId = argId.getValue(); if (argSaturation.isSet()) saturation = argSaturation.getValue(); if (argValue.isSet()) value = argValue.getValue(); + if (argSaturationL.isSet()) saturationL = argSaturationL.getValue(); + if (argLuminance.isSet()) luminance = argLuminance.getValue(); if (argThreshold.isSet()) threshold = argThreshold.getValue(); if (argGamma.isSet()) gamma = argGamma.getValue(); if (argBlacklevel.isSet()) blacklevel = argBlacklevel.getValue(); @@ -156,11 +182,45 @@ int main(int argc, char * argv[]) argId.isSet() ? &transId : nullptr, argSaturation.isSet() ? &saturation : nullptr, argValue.isSet() ? &value : nullptr, + argSaturationL.isSet() ? &saturationL : nullptr, + argLuminance.isSet() ? &luminance : nullptr, argThreshold.isSet() ? &threshold : nullptr, argGamma.isSet() ? &gamma : nullptr, argBlacklevel.isSet() ? &blacklevel : nullptr, argWhitelevel.isSet() ? &whitelevel : nullptr); } + else if (colorCorrection) + { + std::string transId; + int red, green, blue; + + if (argIdC.isSet()) transId = argId.getValue(); + if (argCorrR.isSet()) red = argCorrR.getValue(); + if (argCorrG.isSet()) green = argCorrG.getValue(); + if (argCorrB.isSet()) blue = argCorrB.getValue(); + + connection.setCorrection( + argIdC.isSet() ? &transId : nullptr, + argCorrR.isSet() ? &red : nullptr, + argCorrG.isSet() ? &green : nullptr, + argCorrB.isSet() ? &blue : nullptr, + } + else if (colorTemp) + { + std::string transId; + int red, green, blue; + + if (argIdT.isSet()) transId = argId.getValue(); + if (argTempR.isSet()) red = argTempR.getValue(); + if (argTempG.isSet()) green = argTempG.getValue(); + if (argTempB.isSet()) blue = argTempB.getValue(); + + connection.setCorrection( + argIdC.isSet() ? &transId : nullptr, + argTempR.isSet() ? &red : nullptr, + argTempG.isSet() ? &green : nullptr, + argTempB.isSet() ? &blue : nullptr, + } } catch (const std::runtime_error & e) { From 8caf69e5414430f657eb0fd17c264bf18260bf61 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Fri, 11 Mar 2016 12:21:04 +0100 Subject: [PATCH 30/54] Update JsonConnection.h Former-commit-id: fa07c01ab5bb34029d8b13ea93187a54686d784c --- src/hyperion-remote/JsonConnection.h | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/hyperion-remote/JsonConnection.h b/src/hyperion-remote/JsonConnection.h index 472c5565..2f170fef 100644 --- a/src/hyperion-remote/JsonConnection.h +++ b/src/hyperion-remote/JsonConnection.h @@ -89,6 +89,8 @@ public: /// @param transformId The identifier of the transform to set /// @param saturation The HSV saturation gain /// @param value The HSV value gain + /// @param saturationL The HSL saturation gain + /// @param luminance The HSL luminance gain /// @param threshold The threshold /// @param gamma The gamma value /// @param blacklevel The blacklevel @@ -98,10 +100,42 @@ public: std::string * transformId, double * saturation, double * value, + double * saturationL, + double * luminance, ColorTransformValues * threshold, ColorTransformValues * gamma, ColorTransformValues * blacklevel, ColorTransformValues * whitelevel); + + /// + /// Set the color correction of the leds + /// + /// @note Note that providing a NULL will leave the settings on the server unchanged + /// + /// @param correctionId The identifier of the correction to set + /// @param red The red correction value + /// @param green The green correction value + /// @param blue The blue correction value + void setCorrection( + std::string * correctionId, + int * red, + int * green, + int * blue); + + /// + /// Set the color temperature of the leds + /// + /// @note Note that providing a NULL will leave the settings on the server unchanged + /// + /// @param temperatureId The identifier of the correction to set + /// @param red The red temperature value + /// @param green The green temperature value + /// @param blue The blue temperature value + void setCorrection( + std::string * temperaturenId, + int * red, + int * green, + int * blue); private: /// From 39b318e842d7207fd886319afcd0c3604a5c7147 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Fri, 11 Mar 2016 12:28:45 +0100 Subject: [PATCH 31/54] Update JsonConnection.h Former-commit-id: 5191309bb65f446d8d60e21193ece00560d5e67b --- src/hyperion-remote/JsonConnection.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hyperion-remote/JsonConnection.h b/src/hyperion-remote/JsonConnection.h index 2f170fef..85f4ddb0 100644 --- a/src/hyperion-remote/JsonConnection.h +++ b/src/hyperion-remote/JsonConnection.h @@ -131,7 +131,7 @@ public: /// @param red The red temperature value /// @param green The green temperature value /// @param blue The blue temperature value - void setCorrection( + void setTemperature( std::string * temperaturenId, int * red, int * green, From 8fce604ccb1809033fb2786abcdf98f3f7a2380e Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Fri, 11 Mar 2016 12:29:07 +0100 Subject: [PATCH 32/54] Update JsonConnection.h Former-commit-id: 5d44428cd95e2b81b867ace67eb1f77aceb47856 --- src/hyperion-remote/JsonConnection.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hyperion-remote/JsonConnection.h b/src/hyperion-remote/JsonConnection.h index 85f4ddb0..ccda9f1c 100644 --- a/src/hyperion-remote/JsonConnection.h +++ b/src/hyperion-remote/JsonConnection.h @@ -132,7 +132,7 @@ public: /// @param green The green temperature value /// @param blue The blue temperature value void setTemperature( - std::string * temperaturenId, + std::string * temperatureId, int * red, int * green, int * blue); From a5e042225e640c117d32bad34287e292f0e0c854 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Fri, 11 Mar 2016 12:30:32 +0100 Subject: [PATCH 33/54] Update JsonConnection.cpp Former-commit-id: 7b748e605939b65f02cb768a924faa48787618c3 --- src/hyperion-remote/JsonConnection.cpp | 83 +++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/src/hyperion-remote/JsonConnection.cpp b/src/hyperion-remote/JsonConnection.cpp index 652a3dfa..7e296af7 100644 --- a/src/hyperion-remote/JsonConnection.cpp +++ b/src/hyperion-remote/JsonConnection.cpp @@ -192,7 +192,7 @@ void JsonConnection::clearAll() parseReply(reply); } -void JsonConnection::setTransform(std::string * transformId, double * saturation, double * value, ColorTransformValues *threshold, ColorTransformValues *gamma, ColorTransformValues *blacklevel, ColorTransformValues *whitelevel) +void JsonConnection::setTransform(std::string * transformId, double * saturation, double * value, double * saturationL, double * luminance, ColorTransformValues *threshold, ColorTransformValues *gamma, ColorTransformValues *blacklevel, ColorTransformValues *whitelevel) { std::cout << "Set color transforms" << std::endl; @@ -215,7 +215,16 @@ void JsonConnection::setTransform(std::string * transformId, double * saturation { transform["valueGain"] = *value; } + + if (saturation != nullptr) + { + transform["saturationLGain"] = *saturationL; + } + if (value != nullptr) + { + transform["luminanceGain"] = *luminance; + } if (threshold != nullptr) { Json::Value & v = transform["threshold"]; @@ -255,6 +264,78 @@ void JsonConnection::setTransform(std::string * transformId, double * saturation parseReply(reply); } +void JsonConnection::setCorrection(std::string * correctionId, int * red, int * green, int * blue) +{ + std::cout << "Set color corrections" << std::endl; + + // create command + Json::Value command; + command["command"] = "correction"; + Json::Value & correction = command["correction"]; + + if (correctionId != nullptr) + { + correction["id"] = *correctionId; + } + + if (red != nullptr) + { + correction["red"] = *red; + } + + if (green != nullptr) + { + correction["green"] = *green; + } + + if (blue != nullptr) + { + correction["blue"] = *blue; + } + + // send command message + Json::Value reply = sendMessage(command); + + // parse reply message + parseReply(reply); +} + +void JsonConnection::setTemperature(std::string * temperatureId, int * red, int * green, int * blue) +{ + std::cout << "Set color temperature corrections" << std::endl; + + // create command + Json::Value command; + command["command"] = "temperature"; + Json::Value & temperature = command["temperature"]; + + if (correctionId != nullptr) + { + temperature["id"] = *temperatureId; + } + + if (red != nullptr) + { + temperature["red"] = *red; + } + + if (green != nullptr) + { + temperature["green"] = *green; + } + + if (blue != nullptr) + { + temperature["blue"] = *blue; + } + + // send command message + Json::Value reply = sendMessage(command); + + // parse reply message + parseReply(reply); +} + Json::Value JsonConnection::sendMessage(const Json::Value & message) { // serialize message (FastWriter already appends a newline) From c937dfa67410576b6b6686016e1b68833abb3ef2 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Fri, 11 Mar 2016 12:32:48 +0100 Subject: [PATCH 34/54] Update JsonClientConnection.h Former-commit-id: adc564d5259638c3e79ab5a12550a89c0d719186 --- libsrc/jsonserver/JsonClientConnection.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libsrc/jsonserver/JsonClientConnection.h b/libsrc/jsonserver/JsonClientConnection.h index 01db54b1..acf58d7d 100644 --- a/libsrc/jsonserver/JsonClientConnection.h +++ b/libsrc/jsonserver/JsonClientConnection.h @@ -112,6 +112,20 @@ private: /// @param message the incoming message /// void handleTransformCommand(const Json::Value & message); + + /// + /// Handle an incoming JSON Correction message + /// + /// @param message the incoming message + /// + void handleCorrectionCommand(const Json::Value & message); + + /// + /// Handle an incoming JSON Temperature message + /// + /// @param message the incoming message + /// + void handleTemperatureCommand(const Json::Value & message); /// /// Handle an incoming JSON message of unknown type From 28fd10cdcd87cbe16bde1a31104324a47b5af203 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Fri, 11 Mar 2016 12:46:09 +0100 Subject: [PATCH 35/54] Update JsonClientConnection.cpp Former-commit-id: 6216d16565b82427094b030cede48ee589f5c969 --- libsrc/jsonserver/JsonClientConnection.cpp | 76 ++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index e4dbc096..3eea8320 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -486,6 +486,16 @@ void JsonClientConnection::handleTransformCommand(const Json::Value &message) { colorTransform->_hsvTransform.setValueGain(transform["valueGain"].asDouble()); } + + if (transform.isMember("saturationLGain")) + { + colorTransform->_hslTransform.setSaturationGain(transform["saturationLGain"].asDouble()); + } + + if (transform.isMember("luminanceGain")) + { + colorTransform->_hslTransform.setLuminanceGain(transform["luminanceGain"].asDouble()); + } if (transform.isMember("threshold")) { @@ -525,6 +535,72 @@ void JsonClientConnection::handleTransformCommand(const Json::Value &message) sendSuccessReply(); } +void JsonClientConnection::handleCorrectionCommand(const Json::Value &message) +{ + const Json::Value & correction = message["correction"]; + + const std::string correctionId = correction.get("id", _hyperion->getCorrectionIds().front()).asString(); + ColorCorrection * colorCorrection = _hyperion->getCorrection(CorrectionId); + if (colorCorrection == nullptr) + { + //sendErrorReply(std::string("Incorrect transform identifier: ") + transformId); + return; + } + + if (correction.isMember("red")) + { + colorCorrection->_rgbCorrection.setcorrectionR(correction["red"].asInt()); + } + + if (correction.isMember("green")) + { + colorCorrection->_rgbCorrection.setcorrectionG(correction["green"].asInt()); + } + + if (correction.isMember("blue")) + { + colorCorrection->_rgbCorrection.setcorrectionB(correction["blue"].asInt()); + } + + // commit the changes + _hyperion->correctionsUpdated(); + + sendSuccessReply(); +} + +void JsonClientConnection::handleTemperatureCommand(const Json::Value &message) +{ + const Json::Value & temperature = message["temperature"]; + + const std::string tempId = temperature.get("id", _hyperion->getTemperatureIds().front()).asString(); + ColorCorrection * colorTemperature = _hyperion->getTemperature(TemperatureId); + if (colorTemperature == nullptr) + { + //sendErrorReply(std::string("Incorrect transform identifier: ") + transformId); + return; + } + + if (temperature.isMember("red")) + { + colorTemperature->_rgbCorrection.setcorrectionR(temperature["red"].asInt()); + } + + if (temperature.isMember("green")) + { + colorTemperature->_rgbCorrection.setcorrectionG(temperature["green"].asInt()); + } + + if (temperature.isMember("blue")) + { + colorTemperature->_rgbCorrection.setcorrectionB(temperature["blue"].asInt()); + } + + // commit the changes + _hyperion->temperaturesUpdated(); + + sendSuccessReply(); +} + void JsonClientConnection::handleNotImplemented() { sendErrorReply("Command not implemented"); From e4d77660a4526814afae4aa0e4055d9c62c9b83e Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Sun, 13 Mar 2016 11:59:36 +0100 Subject: [PATCH 36/54] Bug fixes Former-commit-id: a6783a75edb83988d1737df3d4a7a14c71ec4223 --- libsrc/jsonserver/JsonClientConnection.cpp | 13 ++++-- libsrc/jsonserver/JsonSchemas.qrc | 2 + .../jsonserver/schema/schema-correction.json | 41 +++++++++++++++++++ .../jsonserver/schema/schema-temperature.json | 41 +++++++++++++++++++ .../jsonserver/schema/schema-transform.json | 10 +++++ libsrc/jsonserver/schema/schema.json | 2 +- src/hyperion-remote/JsonConnection.cpp | 2 +- src/hyperion-remote/hyperion-remote.cpp | 20 ++++----- 8 files changed, 115 insertions(+), 16 deletions(-) create mode 100644 libsrc/jsonserver/schema/schema-correction.json create mode 100644 libsrc/jsonserver/schema/schema-temperature.json diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index 3eea8320..9298a3d2 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include // project includes @@ -247,6 +248,10 @@ void JsonClientConnection::handleMessage(const std::string &messageString) handleClearallCommand(message); else if (command == "transform") handleTransformCommand(message); + else if (command == "correction") + handleCorrectionCommand(message); + else if (command == "temperature") + handleTemperatureCommand(message); else handleNotImplemented(); } @@ -540,10 +545,10 @@ void JsonClientConnection::handleCorrectionCommand(const Json::Value &message) const Json::Value & correction = message["correction"]; const std::string correctionId = correction.get("id", _hyperion->getCorrectionIds().front()).asString(); - ColorCorrection * colorCorrection = _hyperion->getCorrection(CorrectionId); + ColorCorrection * colorCorrection = _hyperion->getCorrection(correctionId); if (colorCorrection == nullptr) { - //sendErrorReply(std::string("Incorrect transform identifier: ") + transformId); + //sendErrorReply(std::string("Incorrect correction identifier: ") + correctionId); return; } @@ -573,10 +578,10 @@ void JsonClientConnection::handleTemperatureCommand(const Json::Value &message) const Json::Value & temperature = message["temperature"]; const std::string tempId = temperature.get("id", _hyperion->getTemperatureIds().front()).asString(); - ColorCorrection * colorTemperature = _hyperion->getTemperature(TemperatureId); + ColorCorrection * colorTemperature = _hyperion->getTemperature(tempId); if (colorTemperature == nullptr) { - //sendErrorReply(std::string("Incorrect transform identifier: ") + transformId); + //sendErrorReply(std::string("Incorrect temperature identifier: ") + tempId); return; } diff --git a/libsrc/jsonserver/JsonSchemas.qrc b/libsrc/jsonserver/JsonSchemas.qrc index 7736e530..193624ba 100644 --- a/libsrc/jsonserver/JsonSchemas.qrc +++ b/libsrc/jsonserver/JsonSchemas.qrc @@ -7,6 +7,8 @@ schema/schema-clear.json schema/schema-clearall.json schema/schema-transform.json + schema/schema-correction.json + schema/schema-temperature.json schema/schema-effect.json diff --git a/libsrc/jsonserver/schema/schema-correction.json b/libsrc/jsonserver/schema/schema-correction.json new file mode 100644 index 00000000..f156d8fd --- /dev/null +++ b/libsrc/jsonserver/schema/schema-correction.json @@ -0,0 +1,41 @@ +{ + "type":"object", + "required":true, + "properties":{ + "command": { + "type" : "string", + "required" : true, + "enum" : ["correction"] + }, + "correction": { + "type": "object", + "required": true, + "properties": { + "id" : { + "type" : "string", + "required" : false + }, + "red" : { + "type" : "number", + "required" : false, + "minimum": 0.0, + "maximum": 255.0 + }, + "green" : { + "type" : "number", + "required" : false, + "minimum": 0.0, + "maximum": 255.0 + }, + "blue" : { + "type" : "number", + "required" : false, + "minimum": 0.0, + "maximum": 255.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false +} diff --git a/libsrc/jsonserver/schema/schema-temperature.json b/libsrc/jsonserver/schema/schema-temperature.json new file mode 100644 index 00000000..1e2b7058 --- /dev/null +++ b/libsrc/jsonserver/schema/schema-temperature.json @@ -0,0 +1,41 @@ +{ + "type":"object", + "required":true, + "properties":{ + "command": { + "type" : "string", + "required" : true, + "enum" : ["temperature"] + }, + "temperature": { + "type": "object", + "required": true, + "properties": { + "id" : { + "type" : "string", + "required" : false + }, + "red" : { + "type" : "number", + "required" : false, + "minimum": 0.0, + "maximum": 255.0 + }, + "green" : { + "type" : "number", + "required" : false, + "minimum": 0.0, + "maximum": 255.0 + }, + "blue" : { + "type" : "number", + "required" : false, + "minimum": 0.0, + "maximum": 255.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false +} diff --git a/libsrc/jsonserver/schema/schema-transform.json b/libsrc/jsonserver/schema/schema-transform.json index 7b939839..8b194eab 100644 --- a/libsrc/jsonserver/schema/schema-transform.json +++ b/libsrc/jsonserver/schema/schema-transform.json @@ -25,6 +25,16 @@ "required" : false, "minimum" : 0.0 }, + "saturationLGain" : { + "type" : "number", + "required" : false, + "minimum" : 0.0 + }, + "luminanceGain" : { + "type" : "number", + "required" : false, + "minimum" : 0.0 + }, "threshold": { "type": "array", "required": false, diff --git a/libsrc/jsonserver/schema/schema.json b/libsrc/jsonserver/schema/schema.json index e931f7b7..061339d1 100644 --- a/libsrc/jsonserver/schema/schema.json +++ b/libsrc/jsonserver/schema/schema.json @@ -5,7 +5,7 @@ "command": { "type" : "string", "required" : true, - "enum" : ["color", "image", "effect", "serverinfo", "clear", "clearall", "transform"] + "enum" : ["color", "image", "effect", "serverinfo", "clear", "clearall", "transform", "correction", "temperature"] } } } diff --git a/src/hyperion-remote/JsonConnection.cpp b/src/hyperion-remote/JsonConnection.cpp index 7e296af7..150fa63a 100644 --- a/src/hyperion-remote/JsonConnection.cpp +++ b/src/hyperion-remote/JsonConnection.cpp @@ -309,7 +309,7 @@ void JsonConnection::setTemperature(std::string * temperatureId, int * red, int command["command"] = "temperature"; Json::Value & temperature = command["temperature"]; - if (correctionId != nullptr) + if (temperatureId != nullptr) { temperature["id"] = *temperatureId; } diff --git a/src/hyperion-remote/hyperion-remote.cpp b/src/hyperion-remote/hyperion-remote.cpp index e548fbdc..9d02011c 100644 --- a/src/hyperion-remote/hyperion-remote.cpp +++ b/src/hyperion-remote/hyperion-remote.cpp @@ -69,14 +69,14 @@ int main(int argc, char * argv[]) TransformParameter & argWhitelevel = parameters.add('w', "whitelevel", "Set the whitelevel of the leds (requires 3 space seperated values which are normally between 0.0 and 1.0)"); SwitchParameter<> & argPrint = parameters.add >(0x0, "print" , "Print the json input and output messages on stdout"); SwitchParameter<> & argHelp = parameters.add >('h', "help" , "Show this help message and exit"); - StringParameter & argIdC = parameters.add ('cq', "qualifier" , "Identifier(qualifier) of the correction to set"); - IntParameter & argCorrR = parameters.add ('cr', "correctionR" , "Specify the red channel correction factor"); - IntParameter & argCorrG = parameters.add ('cg', "correctionG" , "Specify the green channel correction factor"); - IntParameter & argCorrB = parameters.add ('cb', "correctionB" , "Specify the blue channel correction factor"); - StringParameter & argIdT = parameters.add ('tq', "qualifier" , "Identifier(qualifier) of the temperature to set"); - IntParameter & argTempR = parameters.add ('tr', "tempR" , "Specify the red channel temperature factor"); - IntParameter & argTempG = parameters.add ('tg', "tempG" , "Specify the red channel temperature factor"); - IntParameter & argTempB = parameters.add ('tb', "tempB" , "Specify the red channel temperature factor"); + StringParameter & argIdC = parameters.add ('y', "qualifier" , "Identifier(qualifier) of the correction to set"); + IntParameter & argCorrR = parameters.add ('1', "correctionR" , "Specify the red channel correction factor"); + IntParameter & argCorrG = parameters.add ('2', "correctionG" , "Specify the green channel correction factor"); + IntParameter & argCorrB = parameters.add ('3', "correctionB" , "Specify the blue channel correction factor"); + StringParameter & argIdT = parameters.add ('z', "qualifier" , "Identifier(qualifier) of the temperature to set"); + IntParameter & argTempR = parameters.add ('4', "tempR" , "Specify the red channel temperature factor"); + IntParameter & argTempG = parameters.add ('5', "tempG" , "Specify the red channel temperature factor"); + IntParameter & argTempB = parameters.add ('6', "tempB" , "Specify the red channel temperature factor"); // set the default values argAddress.setDefault(defaultServerAddress.toStdString()); @@ -203,7 +203,7 @@ int main(int argc, char * argv[]) argIdC.isSet() ? &transId : nullptr, argCorrR.isSet() ? &red : nullptr, argCorrG.isSet() ? &green : nullptr, - argCorrB.isSet() ? &blue : nullptr, + argCorrB.isSet() ? &blue : nullptr); } else if (colorTemp) { @@ -219,7 +219,7 @@ int main(int argc, char * argv[]) argIdC.isSet() ? &transId : nullptr, argTempR.isSet() ? &red : nullptr, argTempG.isSet() ? &green : nullptr, - argTempB.isSet() ? &blue : nullptr, + argTempB.isSet() ? &blue : nullptr); } } catch (const std::runtime_error & e) From a5a17776d49e0f14604b626c7812b8fc2dfb5326 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Sun, 13 Mar 2016 12:10:54 +0100 Subject: [PATCH 37/54] BugFix Former-commit-id: 8887ee93d5bcaa7ee13f4f5afb601a65d59ee113 --- config/hyperion.config.json | 31 ++++++++++++++ libsrc/hyperion/hyperion.schema.json | 42 +++++++++++++++++++ .../jsonserver/schema/schema-correction.json | 18 ++++---- .../jsonserver/schema/schema-temperature.json | 18 ++++---- src/hyperion-remote/hyperion-remote.cpp | 16 +++---- 5 files changed, 99 insertions(+), 26 deletions(-) diff --git a/config/hyperion.config.json b/config/hyperion.config.json index 8c9d1ecc..fbb61a69 100644 --- a/config/hyperion.config.json +++ b/config/hyperion.config.json @@ -42,6 +42,32 @@ /// - 'updateDelay' The delay of the output to leds (in periods of smoothing) "color" : { + "correction" : + [ + { + "id" : "default", + "leds" : "*", + "correctionValues" : + { + "red" : 255, + "green" : 255, + "blue" : 255 + } + } + ], + "temperature" : + [ + { + "id" : "default", + "leds" : "*", + "correctionValues" : + { + "red" : 255, + "green" : 255, + "blue" : 255 + } + } + ], "transform" : [ { @@ -52,6 +78,11 @@ "saturationGain" : 1.0000, "valueGain" : 1.0000 }, + "hsl" : + { + "saturationGain" : 1.0000, + "luminanceGain" : 1.0000 + },` "red" : { "threshold" : 0.0000, diff --git a/libsrc/hyperion/hyperion.schema.json b/libsrc/hyperion/hyperion.schema.json index e459425b..165bd906 100644 --- a/libsrc/hyperion/hyperion.schema.json +++ b/libsrc/hyperion/hyperion.schema.json @@ -38,6 +38,31 @@ "type":"object", "required":false, "properties": { + "correctionValues" : { + "type" : "object", + "required" : false, + "properties" : { + "red" : { + "type" : "integer", + "required" : false, + "minimum" : 0 + "maximum" : 255 + }, + "green" : { + "type" : "integer", + "required" : false, + "minimum" : 0 + "maximum" : 255 + } + "blue" : { + "type" : "integer", + "required" : false, + "minimum" : 0 + "maximum" : 255 + } + }, + "additionalProperties" : false + }, "hsv" : { "type" : "object", "required" : false, @@ -54,6 +79,23 @@ } }, "additionalProperties" : false + }, + "hsl" : { + "type" : "object", + "required" : false, + "properties" : { + "saturationGain" : { + "type" : "number", + "required" : false, + "minimum" : 0.0 + }, + "luminanceGain" : { + "type" : "number", + "required" : false, + "minimum" : 0.0 + } + }, + "additionalProperties" : false }, "red": { "type":"object", diff --git a/libsrc/jsonserver/schema/schema-correction.json b/libsrc/jsonserver/schema/schema-correction.json index f156d8fd..37bbee6f 100644 --- a/libsrc/jsonserver/schema/schema-correction.json +++ b/libsrc/jsonserver/schema/schema-correction.json @@ -16,22 +16,22 @@ "required" : false }, "red" : { - "type" : "number", + "type" : "integer", "required" : false, - "minimum": 0.0, - "maximum": 255.0 + "minimum": 0, + "maximum": 255 }, "green" : { - "type" : "number", + "type" : "integer", "required" : false, - "minimum": 0.0, - "maximum": 255.0 + "minimum": 0, + "maximum": 255 }, "blue" : { - "type" : "number", + "type" : "integer", "required" : false, - "minimum": 0.0, - "maximum": 255.0 + "minimum": 0, + "maximum": 255 } }, "additionalProperties": false diff --git a/libsrc/jsonserver/schema/schema-temperature.json b/libsrc/jsonserver/schema/schema-temperature.json index 1e2b7058..14ce465b 100644 --- a/libsrc/jsonserver/schema/schema-temperature.json +++ b/libsrc/jsonserver/schema/schema-temperature.json @@ -16,22 +16,22 @@ "required" : false }, "red" : { - "type" : "number", + "type" : "integer", "required" : false, - "minimum": 0.0, - "maximum": 255.0 + "minimum": 0, + "maximum": 255 }, "green" : { - "type" : "number", + "type" : "integer", "required" : false, - "minimum": 0.0, - "maximum": 255.0 + "minimum": 0, + "maximum": 255 }, "blue" : { - "type" : "number", + "type" : "integer", "required" : false, - "minimum": 0.0, - "maximum": 255.0 + "minimum": 0, + "maximum": 255 } }, "additionalProperties": false diff --git a/src/hyperion-remote/hyperion-remote.cpp b/src/hyperion-remote/hyperion-remote.cpp index 9d02011c..ee3530df 100644 --- a/src/hyperion-remote/hyperion-remote.cpp +++ b/src/hyperion-remote/hyperion-remote.cpp @@ -61,7 +61,7 @@ int main(int argc, char * argv[]) StringParameter & argId = parameters.add ('q', "qualifier" , "Identifier(qualifier) of the transform to set"); DoubleParameter & argSaturation = parameters.add ('s', "saturation", "Set the HSV saturation gain of the leds"); DoubleParameter & argValue = parameters.add ('v', "value" , "Set the HSV value gain of the leds"); - DoubleParameter & argSaturationL = parameters.add ('u', "saturationL", "Set the HSL saturation gain of the leds"); + DoubleParameter & argSaturationL = parameters.add ('u', "saturationL", "Set the HSL saturation gain of the leds"); DoubleParameter & argLuminance = parameters.add ('m', "luminance" , "Set the HSL luminance gain of the leds"); TransformParameter & argGamma = parameters.add('g', "gamma" , "Set the gamma of the leds (requires 3 space seperated values)"); TransformParameter & argThreshold = parameters.add('t', "threshold" , "Set the threshold of the leds (requires 3 space seperated values between 0.0 and 1.0)"); @@ -70,13 +70,13 @@ int main(int argc, char * argv[]) SwitchParameter<> & argPrint = parameters.add >(0x0, "print" , "Print the json input and output messages on stdout"); SwitchParameter<> & argHelp = parameters.add >('h', "help" , "Show this help message and exit"); StringParameter & argIdC = parameters.add ('y', "qualifier" , "Identifier(qualifier) of the correction to set"); - IntParameter & argCorrR = parameters.add ('1', "correctionR" , "Specify the red channel correction factor"); - IntParameter & argCorrG = parameters.add ('2', "correctionG" , "Specify the green channel correction factor"); - IntParameter & argCorrB = parameters.add ('3', "correctionB" , "Specify the blue channel correction factor"); + IntParameter & argCorrR = parameters.add ('1', "correctionR" , "Specify the red channel correction"); + IntParameter & argCorrG = parameters.add ('2', "correctionG" , "Specify the green channel correction"); + IntParameter & argCorrB = parameters.add ('3', "correctionB" , "Specify the blue channel correction"); StringParameter & argIdT = parameters.add ('z', "qualifier" , "Identifier(qualifier) of the temperature to set"); - IntParameter & argTempR = parameters.add ('4', "tempR" , "Specify the red channel temperature factor"); - IntParameter & argTempG = parameters.add ('5', "tempG" , "Specify the red channel temperature factor"); - IntParameter & argTempB = parameters.add ('6', "tempB" , "Specify the red channel temperature factor"); + IntParameter & argTempR = parameters.add ('4', "tempR" , "Specify the red channel temperature correction"); + IntParameter & argTempG = parameters.add ('5', "tempG" , "Specify the red channel temperature correction"); + IntParameter & argTempB = parameters.add ('6', "tempB" , "Specify the red channel temperature correction"); // set the default values argAddress.setDefault(defaultServerAddress.toStdString()); @@ -106,7 +106,7 @@ int main(int argc, char * argv[]) std::cerr << (commandCount == 0 ? "No command found." : "Multiple commands found.") << " Provide exactly one of the following options:" << std::endl; std::cerr << " " << argColor.usageLine() << std::endl; std::cerr << " " << argImage.usageLine() << std::endl; - std::cerr << " " << argEffect.usageLine() << std::endl; + std::cerr << " " << argEffect.usageLine() << std::endl; std::cerr << " " << argServerInfo.usageLine() << std::endl; std::cerr << " " << argClear.usageLine() << std::endl; std::cerr << " " << argClearAll.usageLine() << std::endl; From 28f67871dc1fa4cc764ef8442241dbc87c7fae93 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Sun, 13 Mar 2016 13:05:47 +0100 Subject: [PATCH 38/54] More fixes Former-commit-id: 331ba604dba8aa16f9cf42c5827c8542502be545 --- libsrc/hyperion/hyperion.schema.json | 25 ---------------------- libsrc/jsonserver/JsonClientConnection.cpp | 2 ++ src/hyperion-remote/JsonConnection.cpp | 4 ++-- 3 files changed, 4 insertions(+), 27 deletions(-) diff --git a/libsrc/hyperion/hyperion.schema.json b/libsrc/hyperion/hyperion.schema.json index 165bd906..6ace729f 100644 --- a/libsrc/hyperion/hyperion.schema.json +++ b/libsrc/hyperion/hyperion.schema.json @@ -38,31 +38,6 @@ "type":"object", "required":false, "properties": { - "correctionValues" : { - "type" : "object", - "required" : false, - "properties" : { - "red" : { - "type" : "integer", - "required" : false, - "minimum" : 0 - "maximum" : 255 - }, - "green" : { - "type" : "integer", - "required" : false, - "minimum" : 0 - "maximum" : 255 - } - "blue" : { - "type" : "integer", - "required" : false, - "minimum" : 0 - "maximum" : 255 - } - }, - "additionalProperties" : false - }, "hsv" : { "type" : "object", "required" : false, diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index 9298a3d2..5a11dc59 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -409,6 +409,8 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &) transform["saturationGain"] = colorTransform->_hsvTransform.getSaturationGain(); transform["valueGain"] = colorTransform->_hsvTransform.getValueGain(); + transform["saturationLGain"] = colorTransform->_hslTransform.getSaturationGain(); + transform["luminanceGain"] = colorTransform->_hslTransform.getLuminanceGain(); Json::Value & threshold = transform["threshold"]; threshold.append(colorTransform->_rgbRedTransform.getThreshold()); diff --git a/src/hyperion-remote/JsonConnection.cpp b/src/hyperion-remote/JsonConnection.cpp index 150fa63a..009647af 100644 --- a/src/hyperion-remote/JsonConnection.cpp +++ b/src/hyperion-remote/JsonConnection.cpp @@ -216,12 +216,12 @@ void JsonConnection::setTransform(std::string * transformId, double * saturation transform["valueGain"] = *value; } - if (saturation != nullptr) + if (saturationL != nullptr) { transform["saturationLGain"] = *saturationL; } - if (value != nullptr) + if (luminance != nullptr) { transform["luminanceGain"] = *luminance; } From 1f1aee0c37bfa718cfb20f9ea7b6b3f19729f7bb Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Sun, 13 Mar 2016 21:14:22 +0100 Subject: [PATCH 39/54] Final fixex Former-commit-id: 7b2e1a33ab7705dddadfa1ec99d3d7c379ab10dd --- libsrc/hyperion/hyperion.schema.json | 2 +- libsrc/jsonserver/JsonClientConnection.cpp | 6 +++--- src/hyperion-remote/hyperion-remote.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libsrc/hyperion/hyperion.schema.json b/libsrc/hyperion/hyperion.schema.json index 6ace729f..f30e1a27 100644 --- a/libsrc/hyperion/hyperion.schema.json +++ b/libsrc/hyperion/hyperion.schema.json @@ -38,7 +38,7 @@ "type":"object", "required":false, "properties": { - "hsv" : { + "hsv" : { "type" : "object", "required" : false, "properties" : { diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index 5a11dc59..ca0cf46e 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -232,7 +232,7 @@ void JsonClientConnection::handleMessage(const std::string &messageString) sendErrorReply("Error while validating json: " + errors); return; } - + // switch over all possible commands and handle them if (command == "color") handleColorCommand(message); @@ -483,7 +483,7 @@ void JsonClientConnection::handleTransformCommand(const Json::Value &message) //sendErrorReply(std::string("Incorrect transform identifier: ") + transformId); return; } - + if (transform.isMember("saturationGain")) { colorTransform->_hsvTransform.setSaturationGain(transform["saturationGain"].asDouble()); @@ -535,7 +535,7 @@ void JsonClientConnection::handleTransformCommand(const Json::Value &message) colorTransform->_rgbGreenTransform.setWhitelevel(values[1u].asDouble()); colorTransform->_rgbBlueTransform .setWhitelevel(values[2u].asDouble()); } - + // commit the changes _hyperion->transformsUpdated(); diff --git a/src/hyperion-remote/hyperion-remote.cpp b/src/hyperion-remote/hyperion-remote.cpp index ee3530df..b59d87e4 100644 --- a/src/hyperion-remote/hyperion-remote.cpp +++ b/src/hyperion-remote/hyperion-remote.cpp @@ -177,7 +177,7 @@ int main(int argc, char * argv[]) if (argGamma.isSet()) gamma = argGamma.getValue(); if (argBlacklevel.isSet()) blacklevel = argBlacklevel.getValue(); if (argWhitelevel.isSet()) whitelevel = argWhitelevel.getValue(); - + connection.setTransform( argId.isSet() ? &transId : nullptr, argSaturation.isSet() ? &saturation : nullptr, From ef92488c979547dcd19c4e5c2203c416d7348765 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Tue, 15 Mar 2016 11:01:29 +0100 Subject: [PATCH 40/54] Update hyperion.config.json Former-commit-id: 0febd7e5e4651880d9debd6516e47f1700bd351e --- config/hyperion.config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/hyperion.config.json b/config/hyperion.config.json index fbb61a69..355ad7d7 100644 --- a/config/hyperion.config.json +++ b/config/hyperion.config.json @@ -60,7 +60,7 @@ { "id" : "default", "leds" : "*", - "correctionValues" : + "temperatureValues" : { "red" : 255, "green" : 255, From 35b7707b3f862f922a12c91d2799b547b001f92f Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Mon, 21 Mar 2016 16:59:46 +0100 Subject: [PATCH 41/54] Update schema-temperature.json Former-commit-id: 3f5a96e0275e239ba0361905282b59a9bd4412d0 --- .../jsonserver/schema/schema-temperature.json | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/libsrc/jsonserver/schema/schema-temperature.json b/libsrc/jsonserver/schema/schema-temperature.json index 14ce465b..b7be1f4f 100644 --- a/libsrc/jsonserver/schema/schema-temperature.json +++ b/libsrc/jsonserver/schema/schema-temperature.json @@ -15,23 +15,16 @@ "type" : "string", "required" : false }, - "red" : { - "type" : "integer", - "required" : false, - "minimum": 0, - "maximum": 255 - }, - "green" : { - "type" : "integer", - "required" : false, - "minimum": 0, - "maximum": 255 - }, - "blue" : { - "type" : "integer", - "required" : false, - "minimum": 0, - "maximum": 255 + "correctionValues" : { + "type": "array", + "required": false, + "items" : { + "type": "integer", + "minimum": 0, + "maximum": 255 + }, + "minItems": 3, + "maxItems": 3 } }, "additionalProperties": false From ef1f269c51832ab59cd351718d5f8419bba0f751 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Mon, 21 Mar 2016 17:00:01 +0100 Subject: [PATCH 42/54] Update schema-correction.json Former-commit-id: 223e5d183fd2ec83f61421aaa142bc86958fff6a --- .../jsonserver/schema/schema-correction.json | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/libsrc/jsonserver/schema/schema-correction.json b/libsrc/jsonserver/schema/schema-correction.json index 37bbee6f..ad7dbfca 100644 --- a/libsrc/jsonserver/schema/schema-correction.json +++ b/libsrc/jsonserver/schema/schema-correction.json @@ -15,23 +15,16 @@ "type" : "string", "required" : false }, - "red" : { - "type" : "integer", - "required" : false, - "minimum": 0, - "maximum": 255 - }, - "green" : { - "type" : "integer", - "required" : false, - "minimum": 0, - "maximum": 255 - }, - "blue" : { - "type" : "integer", - "required" : false, - "minimum": 0, - "maximum": 255 + "correctionValues" : { + "type": "array", + "required": false, + "items" : { + "type": "integer", + "minimum": 0, + "maximum": 255 + }, + "minItems": 3, + "maxItems": 3 } }, "additionalProperties": false From 642de44c7c37ba1135afa914642f944c54fb50a5 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Mon, 21 Mar 2016 17:04:02 +0100 Subject: [PATCH 43/54] Update JsonClientConnection.cpp Former-commit-id: 53b8cf73df6f3cec49886169b870e5490828716b --- libsrc/jsonserver/JsonClientConnection.cpp | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index ca0cf46e..e6275ae6 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -392,6 +392,47 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &) item["duration_ms"] = Json::Value::UInt(priorityInfo.timeoutTime_ms - now); } } + + // collect correction information + Json::Value & correctionArray = info["correction"]; + for (const std::string& correctionId : _hyperion->getCorrectionIds()) + { + const ColorCorrection * colorCorrection = _hyperion->getCorrection(correctionId); + if (colorCorrection == nullptr) + { + std::cerr << "Incorrect color correction id: " << correctionId << std::endl; + continue; + } + + Json::Value & correction = correctionArray.append(Json::Value()); + correction["id"] = correctionId; + + Json::Value & corrValues = correction["correctionValues"]; + corrValues.append(colorCorrection->_rgbCorrection.getcorrectionR()); + corrValues.append(colorCorrection->_rgbCorrection.getcorrectionG()); + corrValues.append(colorCorrection->_rgbCorrection.getcorrectionB()); + } + + // collect temperature correction information + Json::Value & temperatureArray = info["temperature"]; + for (const std::string& tempId : _hyperion->getTemperatureIds()) + { + const ColorCorrection * colorTemp = _hyperion->getTemperature(tempId); + if (colorTemp == nullptr) + { + std::cerr << "Incorrect color temperature correction id: " << tempId << std::endl; + continue; + } + + Json::Value & temperature = temperatureArray.append(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()); + } + // collect transform information Json::Value & transformArray = info["transform"]; From b46d231f75d3ad41e1cb3185f8405b89f4b02984 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Mon, 21 Mar 2016 17:07:02 +0100 Subject: [PATCH 44/54] Update JsonClientConnection.cpp Former-commit-id: fef896ef86f04901cf2227a0897dd9ea999325b7 --- libsrc/jsonserver/JsonClientConnection.cpp | 36 ++++++---------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index e6275ae6..d146b1c8 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -595,20 +595,12 @@ void JsonClientConnection::handleCorrectionCommand(const Json::Value &message) return; } - if (correction.isMember("red")) + if (correction.isMember("correctionValues")) { - colorCorrection->_rgbCorrection.setcorrectionR(correction["red"].asInt()); - } - - if (correction.isMember("green")) - { - colorCorrection->_rgbCorrection.setcorrectionG(correction["green"].asInt()); - } - - if (correction.isMember("blue")) - { - colorCorrection->_rgbCorrection.setcorrectionB(correction["blue"].asInt()); - } + const Json::Value & values = correction["correctionValues"]; + colorCorrection->_rgbCorrection.setcorrectionR(values[0u].asInt()); + colorCorrection->_rgbCorrection.setcorrectionG(values[1u].asInt()); + colorCorrection->_rgbCorrection.setcorrectionB(values[2u].asInt()); // commit the changes _hyperion->correctionsUpdated(); @@ -628,20 +620,12 @@ void JsonClientConnection::handleTemperatureCommand(const Json::Value &message) return; } - if (temperature.isMember("red")) + if (temperature.isMember("correctionValues")) { - colorTemperature->_rgbCorrection.setcorrectionR(temperature["red"].asInt()); - } - - if (temperature.isMember("green")) - { - colorTemperature->_rgbCorrection.setcorrectionG(temperature["green"].asInt()); - } - - if (temperature.isMember("blue")) - { - colorTemperature->_rgbCorrection.setcorrectionB(temperature["blue"].asInt()); - } + const Json::Value & values = temperature["correctionValues"]; + colorTemperature->_rgbCorrection.setcorrectionR(values[0u].asInt()); + colorTemperature->_rgbCorrection.setcorrectionG(values[1u].asInt()); + colorTemperature->_rgbCorrection.setcorrectionB(values[2u].asInt()); // commit the changes _hyperion->temperaturesUpdated(); From 0bafc4a3cc1989a16d789494cd11e6dd74291caf Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Mon, 21 Mar 2016 17:08:10 +0100 Subject: [PATCH 45/54] Create ColorCorrectionValues.h Former-commit-id: d765e8c7562d6eac5e03e939bd88c858c50597bb --- src/hyperion-remote/ColorCorrectionValues.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/hyperion-remote/ColorCorrectionValues.h diff --git a/src/hyperion-remote/ColorCorrectionValues.h b/src/hyperion-remote/ColorCorrectionValues.h new file mode 100644 index 00000000..0cd0e911 --- /dev/null +++ b/src/hyperion-remote/ColorCorrectionValues.h @@ -0,0 +1,12 @@ +#pragma once + +/// Simple structure to contain the values of a color transformation +struct ColorCorrectionValues +{ + /// The value for the red color-channel + int valueRed; + /// The value for the green color-channel + int valueGreen; + /// The value for the blue color-channel + int valueBlue; +}; From a15a680dc324ab3c914459449f968f56fbd92b03 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Mon, 21 Mar 2016 17:09:10 +0100 Subject: [PATCH 46/54] Update CustomParameter.h Former-commit-id: 99fa0c1a3d6321dc41f4fb1623aee5b364220a67 --- src/hyperion-remote/CustomParameter.h | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/hyperion-remote/CustomParameter.h b/src/hyperion-remote/CustomParameter.h index 4f336dd7..af1836a6 100644 --- a/src/hyperion-remote/CustomParameter.h +++ b/src/hyperion-remote/CustomParameter.h @@ -12,6 +12,7 @@ // hyperion-remote includes #include "ColorTransformValues.h" +#include "ColorCorrectionValues.h" /// Data parameter for a color typedef vlofgren::PODParameter> ColorParameter; @@ -22,6 +23,9 @@ typedef vlofgren::PODParameter ImageParameter; /// Data parameter for color transform values (list of three values) typedef vlofgren::PODParameter TransformParameter; +/// Data parameter for color correction values (list of three values) +typedef vlofgren::PODParameter CorrectionParameter; + namespace vlofgren { /// /// Translates a string (as passed on the commandline) to a vector of colors @@ -128,4 +132,33 @@ namespace vlofgren { return transform; } + + template<> + ColorCorrectionValues CorrectionParameter::validate(const std::string& s) throw (Parameter::ParameterRejected) + { + ColorCorrectionValues correction; + + // s should be split in 3 parts + // seperators are either a ',' or a space + QStringList components = QString(s.c_str()).split(" ", QString::SkipEmptyParts); + + if (components.size() == 3) + { + bool ok1, ok2, ok3; + correction.valueRed = components[0].toInt(&ok1); + correction.valueGreen = components[1].toInt(&ok2); + correction.valueBlue = components[2].toInt(&ok3); + + if (ok1 && ok2 && ok3) + { + return correction; + } + } + + std::stringstream errorMessage; + errorMessage << "Argument " << s << " can not be parsed to 3 integer values"; + throw Parameter::ParameterRejected(errorMessage.str()); + + return correction; + } } From 4836bfc863f70c4dfefde4a89bbd8be307eb552b Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Mon, 21 Mar 2016 17:10:01 +0100 Subject: [PATCH 47/54] Update JsonConnection.h Former-commit-id: 4a0983b135f8386ee4e0db81c044dbaa87e05c03 --- src/hyperion-remote/JsonConnection.h | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/hyperion-remote/JsonConnection.h b/src/hyperion-remote/JsonConnection.h index ccda9f1c..48455110 100644 --- a/src/hyperion-remote/JsonConnection.h +++ b/src/hyperion-remote/JsonConnection.h @@ -14,6 +14,7 @@ // hyperion-remote includes #include "ColorTransformValues.h" +#include "ColorCorrectionValues.h" /// /// Connection class to setup an connection to the hyperion server and execute commands @@ -113,14 +114,10 @@ public: /// @note Note that providing a NULL will leave the settings on the server unchanged /// /// @param correctionId The identifier of the correction to set - /// @param red The red correction value - /// @param green The green correction value - /// @param blue The blue correction value + /// @param correction The correction values void setCorrection( std::string * correctionId, - int * red, - int * green, - int * blue); + ColorCorrectionValues * correction); /// /// Set the color temperature of the leds @@ -128,14 +125,10 @@ public: /// @note Note that providing a NULL will leave the settings on the server unchanged /// /// @param temperatureId The identifier of the correction to set - /// @param red The red temperature value - /// @param green The green temperature value - /// @param blue The blue temperature value + /// @param temperature The temperature correction values void setTemperature( std::string * temperatureId, - int * red, - int * green, - int * blue); + ColorCorrectionValues * temperature); private: /// From 909112fbfb54fa433375932a0eae4a3c58c9561b Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Mon, 21 Mar 2016 17:13:46 +0100 Subject: [PATCH 48/54] Update JsonConnection.cpp Former-commit-id: 712db0e3d8e525353d62bd7dfc6e2dd708b09b85 --- src/hyperion-remote/JsonConnection.cpp | 48 +++++++++----------------- 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/src/hyperion-remote/JsonConnection.cpp b/src/hyperion-remote/JsonConnection.cpp index 009647af..e00488e1 100644 --- a/src/hyperion-remote/JsonConnection.cpp +++ b/src/hyperion-remote/JsonConnection.cpp @@ -264,33 +264,26 @@ void JsonConnection::setTransform(std::string * transformId, double * saturation parseReply(reply); } -void JsonConnection::setCorrection(std::string * correctionId, int * red, int * green, int * blue) +void JsonConnection::setCorrection(std::string * correctionId, ColorCorrectionValues *correction) { std::cout << "Set color corrections" << std::endl; // create command Json::Value command; command["command"] = "correction"; - Json::Value & correction = command["correction"]; - + Json::Value & correct = command["correction"]; + if (correctionId != nullptr) { - correction["id"] = *correctionId; + correct["id"] = *correctionId; } - if (red != nullptr) + if (correction != nullptr) { - correction["red"] = *red; - } - - if (green != nullptr) - { - correction["green"] = *green; - } - - if (blue != nullptr) - { - correction["blue"] = *blue; + Json::Value & v = correction["correctionValues"]; + v.append(correction->valueRed); + v.append(correction->valueGreen); + v.append(correction->valueBlue); } // send command message @@ -300,33 +293,26 @@ void JsonConnection::setCorrection(std::string * correctionId, int * red, int * parseReply(reply); } -void JsonConnection::setTemperature(std::string * temperatureId, int * red, int * green, int * blue) +void JsonConnection::setTemperature(std::string * temperatureId, ColorCorrectionValues *temperature) { std::cout << "Set color temperature corrections" << std::endl; // create command Json::Value command; command["command"] = "temperature"; - Json::Value & temperature = command["temperature"]; + Json::Value & temp = command["temperature"]; if (temperatureId != nullptr) { - temperature["id"] = *temperatureId; + temp["id"] = *temperatureId; } - if (red != nullptr) + if (temperature != nullptr) { - temperature["red"] = *red; - } - - if (green != nullptr) - { - temperature["green"] = *green; - } - - if (blue != nullptr) - { - temperature["blue"] = *blue; + Json::Value & v = temp["correctionValues"]; + v.append(temperature->valueRed); + v.append(temperature->valueGreen); + v.append(temperature->valueBlue); } // send command message From 9987590e5e8652fac46ca33f499b04cfe255d8b1 Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Mon, 21 Mar 2016 17:19:06 +0100 Subject: [PATCH 49/54] Update hyperion-remote.cpp Former-commit-id: 652cde0ee1ef0fed1492c63bf78787467f9dd2b6 --- src/hyperion-remote/hyperion-remote.cpp | 62 +++++++++---------------- 1 file changed, 22 insertions(+), 40 deletions(-) diff --git a/src/hyperion-remote/hyperion-remote.cpp b/src/hyperion-remote/hyperion-remote.cpp index b59d87e4..59fc6997 100644 --- a/src/hyperion-remote/hyperion-remote.cpp +++ b/src/hyperion-remote/hyperion-remote.cpp @@ -70,13 +70,9 @@ int main(int argc, char * argv[]) SwitchParameter<> & argPrint = parameters.add >(0x0, "print" , "Print the json input and output messages on stdout"); SwitchParameter<> & argHelp = parameters.add >('h', "help" , "Show this help message and exit"); StringParameter & argIdC = parameters.add ('y', "qualifier" , "Identifier(qualifier) of the correction to set"); - IntParameter & argCorrR = parameters.add ('1', "correctionR" , "Specify the red channel correction"); - IntParameter & argCorrG = parameters.add ('2', "correctionG" , "Specify the green channel correction"); - IntParameter & argCorrB = parameters.add ('3', "correctionB" , "Specify the blue channel correction"); + CorrectionParameter & argCorrection = parameters.add('Y', "correction" , "Set the correction of the leds (requires 3 space seperated values between 0 and 255)"); StringParameter & argIdT = parameters.add ('z', "qualifier" , "Identifier(qualifier) of the temperature to set"); - IntParameter & argTempR = parameters.add ('4', "tempR" , "Specify the red channel temperature correction"); - IntParameter & argTempG = parameters.add ('5', "tempG" , "Specify the red channel temperature correction"); - IntParameter & argTempB = parameters.add ('6', "tempB" , "Specify the red channel temperature correction"); + CorrectionParameter & argTemperature = parameters.add('Z', "temperature" , "Set the temperature correction of the leds (requires 3 space seperated values between 0 and 255)"); // set the default values argAddress.setDefault(defaultServerAddress.toStdString()); @@ -96,17 +92,15 @@ int main(int argc, char * argv[]) // check if at least one of the available color transforms is set bool colorTransform = argSaturation.isSet() || argValue.isSet() || argSaturationL.isSet() || argLuminance.isSet() || argThreshold.isSet() || argGamma.isSet() || argBlacklevel.isSet() || argWhitelevel.isSet(); - bool colorCorrection = argCorrR.isSet() || argCorrG.isSet() || argCorrB.isSet(); - bool colorTemp = argTempR.isSet() || argTempG.isSet() || argTempB.isSet(); // check that exactly one command was given - int commandCount = count({argColor.isSet(), argImage.isSet(), argEffect.isSet(), argServerInfo.isSet(), argClear.isSet(), argClearAll.isSet(), colorTransform, colorCorrection, colorTemp}); + int commandCount = count({argColor.isSet(), argImage.isSet(), argEffect.isSet(), argServerInfo.isSet(), argClear.isSet(), argClearAll.isSet(), colorTransform, argCorrection.isSet(), argTemperature.isSet()}); if (commandCount != 1) { std::cerr << (commandCount == 0 ? "No command found." : "Multiple commands found.") << " Provide exactly one of the following options:" << std::endl; std::cerr << " " << argColor.usageLine() << std::endl; std::cerr << " " << argImage.usageLine() << std::endl; - std::cerr << " " << argEffect.usageLine() << std::endl; + std::cerr << " " << argEffect.usageLine() << std::endl; std::cerr << " " << argServerInfo.usageLine() << std::endl; std::cerr << " " << argClear.usageLine() << std::endl; std::cerr << " " << argClearAll.usageLine() << std::endl; @@ -122,14 +116,10 @@ int main(int argc, char * argv[]) std::cerr << " " << argWhitelevel.usageLine() << std::endl; std::cerr << "one or more of the available color corrections:" << std::endl; std::cerr << " " << argIdC.usageLine() << std::endl; - std::cerr << " " << argCorrR.usageLine() << std::endl; - std::cerr << " " << argCorrG.usageLine() << std::endl; - std::cerr << " " << argCorrB.usageLine() << std::endl; + std::cerr << " " << argCorrection.usageLine() << std::endl; std::cerr << "or one or more of the available color temperature adjustment:" << std::endl; std::cerr << " " << argIdT.usageLine() << std::endl; - std::cerr << " " << argTempR.usageLine() << std::endl; - std::cerr << " " << argTempG.usageLine() << std::endl; - std::cerr << " " << argTempB.usageLine() << std::endl; + std::cerr << " " << argTemperature.usageLine() << std::endl; return 1; } @@ -183,43 +173,35 @@ int main(int argc, char * argv[]) argSaturation.isSet() ? &saturation : nullptr, argValue.isSet() ? &value : nullptr, argSaturationL.isSet() ? &saturationL : nullptr, - argLuminance.isSet() ? &luminance : nullptr, + argLuminance.isSet() ? &luminance : nullptr, argThreshold.isSet() ? &threshold : nullptr, argGamma.isSet() ? &gamma : nullptr, argBlacklevel.isSet() ? &blacklevel : nullptr, argWhitelevel.isSet() ? &whitelevel : nullptr); } - else if (colorCorrection) + else if (argCorrection.isSet()) { - std::string transId; - int red, green, blue; + std::string corrId; + ColorCorrectionValues correction; + + if (argIdC.isSet()) corrId = argIdC.getValue(); + if (argCorrection.isSet()) correction = argCorrection.getValue(); - if (argIdC.isSet()) transId = argId.getValue(); - if (argCorrR.isSet()) red = argCorrR.getValue(); - if (argCorrG.isSet()) green = argCorrG.getValue(); - if (argCorrB.isSet()) blue = argCorrB.getValue(); - connection.setCorrection( - argIdC.isSet() ? &transId : nullptr, - argCorrR.isSet() ? &red : nullptr, - argCorrG.isSet() ? &green : nullptr, - argCorrB.isSet() ? &blue : nullptr); + argIdC.isSet() ? &corrId : nullptr, + argCorrection.isSet() ? &correction : nullptr); } - else if (colorTemp) + else if (argTemperature.isSet()) { - std::string transId; - int red, green, blue; + std::string tempId; + ColorCorrectionValues temperature; - if (argIdT.isSet()) transId = argId.getValue(); - if (argTempR.isSet()) red = argTempR.getValue(); - if (argTempG.isSet()) green = argTempG.getValue(); - if (argTempB.isSet()) blue = argTempB.getValue(); + if (argIdT.isSet()) tempId = argIdT.getValue(); + if (argTemperature.isSet()) temperature = argTemperature.getValue(); connection.setCorrection( - argIdC.isSet() ? &transId : nullptr, - argTempR.isSet() ? &red : nullptr, - argTempG.isSet() ? &green : nullptr, - argTempB.isSet() ? &blue : nullptr); + argIdT.isSet() ? &tempId : nullptr, + argTemperature.isSet() ? &temperature : nullptr); } } catch (const std::runtime_error & e) From fa3b3388948e9a6d2aa58ac9762bdc953df3220f Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Mon, 21 Mar 2016 17:20:06 +0100 Subject: [PATCH 50/54] Update hyperion-remote.cpp Former-commit-id: 2ef2b5d21eda53e2286af8edf7200eb73f5ae3bf --- src/hyperion-remote/hyperion-remote.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hyperion-remote/hyperion-remote.cpp b/src/hyperion-remote/hyperion-remote.cpp index 59fc6997..3fd9549e 100644 --- a/src/hyperion-remote/hyperion-remote.cpp +++ b/src/hyperion-remote/hyperion-remote.cpp @@ -199,7 +199,7 @@ int main(int argc, char * argv[]) if (argIdT.isSet()) tempId = argIdT.getValue(); if (argTemperature.isSet()) temperature = argTemperature.getValue(); - connection.setCorrection( + connection.setTemperature( argIdT.isSet() ? &tempId : nullptr, argTemperature.isSet() ? &temperature : nullptr); } From 4a6a0ea9bd6db2501d2761747e6111be71ae6a7a Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Mon, 21 Mar 2016 17:21:24 +0100 Subject: [PATCH 51/54] Update hyperion.config.json Former-commit-id: 1b104a073df59cf87d3188ab3c1399943da81ece --- config/hyperion.config.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/hyperion.config.json b/config/hyperion.config.json index 355ad7d7..86597162 100644 --- a/config/hyperion.config.json +++ b/config/hyperion.config.json @@ -13,7 +13,7 @@ "name" : "MyPi", "type" : "ws2801", "output" : "/dev/spidev0.0", - "rate" : 1000000, + "rate" : 250000, "colorOrder" : "rgb" }, @@ -82,7 +82,7 @@ { "saturationGain" : 1.0000, "luminanceGain" : 1.0000 - },` + }, "red" : { "threshold" : 0.0000, From 2d0eeb0a69685b54ddb4a71ae501b4d3a12a422a Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Mon, 21 Mar 2016 17:22:22 +0100 Subject: [PATCH 52/54] Update hyperion.config.json Former-commit-id: ababa8d21284fb7808c571c1db6c400c5bffa4a6 --- config/hyperion.config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/hyperion.config.json b/config/hyperion.config.json index 86597162..0b8c5d8c 100644 --- a/config/hyperion.config.json +++ b/config/hyperion.config.json @@ -13,7 +13,7 @@ "name" : "MyPi", "type" : "ws2801", "output" : "/dev/spidev0.0", - "rate" : 250000, + "rate" : 1000000, "colorOrder" : "rgb" }, From 7da3e83597551c599700c6e0bcb9611e51cff11b Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Mon, 21 Mar 2016 17:39:02 +0100 Subject: [PATCH 53/54] Update JsonConnection.cpp Former-commit-id: c701972ecddcd9655f0aa56b69301ad463f8dcb0 --- src/hyperion-remote/JsonConnection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hyperion-remote/JsonConnection.cpp b/src/hyperion-remote/JsonConnection.cpp index e00488e1..61367104 100644 --- a/src/hyperion-remote/JsonConnection.cpp +++ b/src/hyperion-remote/JsonConnection.cpp @@ -280,7 +280,7 @@ void JsonConnection::setCorrection(std::string * correctionId, ColorCorrectionVa if (correction != nullptr) { - Json::Value & v = correction["correctionValues"]; + Json::Value & v = correct["correctionValues"]; v.append(correction->valueRed); v.append(correction->valueGreen); v.append(correction->valueBlue); From 3c2682b626328c0af3ba74915610bac7cd52c5ec Mon Sep 17 00:00:00 2001 From: AEtHeLsYn Date: Mon, 21 Mar 2016 17:42:13 +0100 Subject: [PATCH 54/54] Update JsonClientConnection.cpp Former-commit-id: 5014c392b3c7629b6f02ead321621f7edc560680 --- libsrc/jsonserver/JsonClientConnection.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index d146b1c8..2d3cfa45 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -601,6 +601,7 @@ void JsonClientConnection::handleCorrectionCommand(const Json::Value &message) colorCorrection->_rgbCorrection.setcorrectionR(values[0u].asInt()); colorCorrection->_rgbCorrection.setcorrectionG(values[1u].asInt()); colorCorrection->_rgbCorrection.setcorrectionB(values[2u].asInt()); + } // commit the changes _hyperion->correctionsUpdated(); @@ -626,6 +627,7 @@ void JsonClientConnection::handleTemperatureCommand(const Json::Value &message) colorTemperature->_rgbCorrection.setcorrectionR(values[0u].asInt()); colorTemperature->_rgbCorrection.setcorrectionG(values[1u].asInt()); colorTemperature->_rgbCorrection.setcorrectionB(values[2u].asInt()); + } // commit the changes _hyperion->temperaturesUpdated();