From 171f075959a65f3a20df92ef2702bc60f9b0276f Mon Sep 17 00:00:00 2001 From: redpanther Date: Fri, 31 Mar 2017 16:14:59 +0200 Subject: [PATCH 1/8] clean color adjustment --- include/utils/RgbChannelAdjustment.h | 21 +++--------- libsrc/hyperion/MultiColorAdjustment.cpp | 40 +++++----------------- libsrc/jsonserver/JsonClientConnection.cpp | 32 +++++------------ libsrc/utils/RgbChannelAdjustment.cpp | 35 ++++--------------- 4 files changed, 27 insertions(+), 101 deletions(-) diff --git a/include/utils/RgbChannelAdjustment.h b/include/utils/RgbChannelAdjustment.h index fae861b6b..88bb9aeab 100644 --- a/include/utils/RgbChannelAdjustment.h +++ b/include/utils/RgbChannelAdjustment.h @@ -21,6 +21,10 @@ class RgbChannelAdjustment /// Destructor ~RgbChannelAdjustment(); + + /// Transform the given array value + /// @param input The input color bytes + void apply(uint8_t input, uint8_t & red, uint8_t & green, uint8_t & blue); /// setAdjustment RGB /// @param adjustR @@ -31,29 +35,12 @@ class RgbChannelAdjustment /// @return The current adjustR value uint8_t getAdjustmentR() const; - /// @param threshold New adjustR value - void setAdjustmentR(uint8_t adjustR); - /// @return The current adjustG value uint8_t getAdjustmentG() const; - /// @param gamma New adjustG value - void setAdjustmentG(uint8_t adjustG); - /// @return The current adjustB value uint8_t getAdjustmentB() const; - /// @param blacklevel New adjustB value - void setAdjustmentB(uint8_t adjustB); - - /// Transform the given array value - /// @param input The input color bytes - /// @return The corrected byte value - uint8_t getAdjustmentR(uint8_t inputR) const; - uint8_t getAdjustmentG(uint8_t inputG) const; - uint8_t getAdjustmentB(uint8_t inputB) const; - - private: /// color channels enum ColorChannel { RED=0,GREEN=1, BLUE=2 }; diff --git a/libsrc/hyperion/MultiColorAdjustment.cpp b/libsrc/hyperion/MultiColorAdjustment.cpp index 8af98804c..6bab6382c 100644 --- a/libsrc/hyperion/MultiColorAdjustment.cpp +++ b/libsrc/hyperion/MultiColorAdjustment.cpp @@ -123,37 +123,15 @@ void MultiColorAdjustment::applyAdjustment(std::vector& ledColors) uint8_t yellow = rg *(255-oblue)/65025; uint8_t white = rg *(oblue) /65025; - uint8_t OR = adjustment->_rgbBlackAdjustment.getAdjustmentR(black); - uint8_t OG = adjustment->_rgbBlackAdjustment.getAdjustmentG(black); - uint8_t OB = adjustment->_rgbBlackAdjustment.getAdjustmentB(black); - - uint8_t RR = adjustment->_rgbRedAdjustment.getAdjustmentR(red); - uint8_t RG = adjustment->_rgbRedAdjustment.getAdjustmentG(red); - uint8_t RB = adjustment->_rgbRedAdjustment.getAdjustmentB(red); - - uint8_t GR = adjustment->_rgbGreenAdjustment.getAdjustmentR(green); - uint8_t GG = adjustment->_rgbGreenAdjustment.getAdjustmentG(green); - uint8_t GB = adjustment->_rgbGreenAdjustment.getAdjustmentB(green); - - uint8_t BR = adjustment->_rgbBlueAdjustment.getAdjustmentR(blue); - uint8_t BG = adjustment->_rgbBlueAdjustment.getAdjustmentG(blue); - uint8_t BB = adjustment->_rgbBlueAdjustment.getAdjustmentB(blue); - - uint8_t CR = adjustment->_rgbCyanAdjustment.getAdjustmentR(cyan); - uint8_t CG = adjustment->_rgbCyanAdjustment.getAdjustmentG(cyan); - uint8_t CB = adjustment->_rgbCyanAdjustment.getAdjustmentB(cyan); - - uint8_t MR = adjustment->_rgbMagentaAdjustment.getAdjustmentR(magenta); - uint8_t MG = adjustment->_rgbMagentaAdjustment.getAdjustmentG(magenta); - uint8_t MB = adjustment->_rgbMagentaAdjustment.getAdjustmentB(magenta); - - uint8_t YR = adjustment->_rgbYellowAdjustment.getAdjustmentR(yellow); - uint8_t YG = adjustment->_rgbYellowAdjustment.getAdjustmentG(yellow); - uint8_t YB = adjustment->_rgbYellowAdjustment.getAdjustmentB(yellow); - - uint8_t WR = adjustment->_rgbWhiteAdjustment.getAdjustmentR(white); - uint8_t WG = adjustment->_rgbWhiteAdjustment.getAdjustmentG(white); - uint8_t WB = adjustment->_rgbWhiteAdjustment.getAdjustmentB(white); + uint8_t OR, OG, OB, RR, RG, RB, GR, GG, GB, BR, BG, BB, CR, CG, CB, MR, MG, MB, YR, YG, YB, WR, WG, WB; + adjustment->_rgbBlackAdjustment.apply(black, OR, OG, OB); + adjustment->_rgbRedAdjustment.apply(red, RR, RG, RB); + adjustment->_rgbGreenAdjustment.apply(green, GR, GG, GB); + adjustment->_rgbBlueAdjustment.apply(blue, BR, BG, BB); + adjustment->_rgbCyanAdjustment.apply(cyan, CR, CG, CB); + adjustment->_rgbMagentaAdjustment.apply(magenta, MR, MG, MB); + adjustment->_rgbYellowAdjustment.apply(yellow, YR, YG, YB); + adjustment->_rgbWhiteAdjustment.apply(white, WR, WG, WB); color.red = OR + RR + GR + BR + CR + MR + YR + WR; color.green = OG + RG + GG + BG + CG + MG + YG + WG; diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index 08992d7a8..ba2465476 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -893,60 +893,44 @@ void JsonClientConnection::handleAdjustmentCommand(const QJsonObject& message, c if (adjustment.contains("red")) { const QJsonArray & values = adjustment["red"].toArray(); - colorAdjustment->_rgbRedAdjustment.setAdjustmentR(values[0u].toInt()); - colorAdjustment->_rgbRedAdjustment.setAdjustmentG(values[1u].toInt()); - colorAdjustment->_rgbRedAdjustment.setAdjustmentB(values[2u].toInt()); + colorAdjustment->_rgbRedAdjustment.setAdjustment(values[0u].toInt(), values[1u].toInt(), values[2u].toInt()); } if (adjustment.contains("green")) { const QJsonArray & values = adjustment["green"].toArray(); - colorAdjustment->_rgbGreenAdjustment.setAdjustmentR(values[0u].toInt()); - colorAdjustment->_rgbGreenAdjustment.setAdjustmentG(values[1u].toInt()); - colorAdjustment->_rgbGreenAdjustment.setAdjustmentB(values[2u].toInt()); + colorAdjustment->_rgbGreenAdjustment.setAdjustment(values[0u].toInt(), values[1u].toInt(), values[2u].toInt()); } if (adjustment.contains("blue")) { const QJsonArray & values = adjustment["blue"].toArray(); - colorAdjustment->_rgbBlueAdjustment.setAdjustmentR(values[0u].toInt()); - colorAdjustment->_rgbBlueAdjustment.setAdjustmentG(values[1u].toInt()); - colorAdjustment->_rgbBlueAdjustment.setAdjustmentB(values[2u].toInt()); + colorAdjustment->_rgbBlueAdjustment.setAdjustment(values[0u].toInt(), values[1u].toInt(), values[2u].toInt()); } if (adjustment.contains("cyan")) { const QJsonArray & values = adjustment["cyan"].toArray(); - colorAdjustment->_rgbCyanAdjustment.setAdjustmentR(values[0u].toInt()); - colorAdjustment->_rgbCyanAdjustment.setAdjustmentG(values[1u].toInt()); - colorAdjustment->_rgbCyanAdjustment.setAdjustmentB(values[2u].toInt()); + colorAdjustment->_rgbCyanAdjustment.setAdjustment(values[0u].toInt(), values[1u].toInt(), values[2u].toInt()); } if (adjustment.contains("magenta")) { const QJsonArray & values = adjustment["magenta"].toArray(); - colorAdjustment->_rgbMagentaAdjustment.setAdjustmentR(values[0u].toInt()); - colorAdjustment->_rgbMagentaAdjustment.setAdjustmentG(values[1u].toInt()); - colorAdjustment->_rgbMagentaAdjustment.setAdjustmentB(values[2u].toInt()); + colorAdjustment->_rgbMagentaAdjustment.setAdjustment(values[0u].toInt(), values[1u].toInt(), values[2u].toInt()); } if (adjustment.contains("yellow")) { const QJsonArray & values = adjustment["yellow"].toArray(); - colorAdjustment->_rgbYellowAdjustment.setAdjustmentR(values[0u].toInt()); - colorAdjustment->_rgbYellowAdjustment.setAdjustmentG(values[1u].toInt()); - colorAdjustment->_rgbYellowAdjustment.setAdjustmentB(values[2u].toInt()); + colorAdjustment->_rgbYellowAdjustment.setAdjustment(values[0u].toInt(), values[1u].toInt(), values[2u].toInt()); } if (adjustment.contains("black")) { const QJsonArray & values = adjustment["black"].toArray(); - colorAdjustment->_rgbBlackAdjustment.setAdjustmentR(values[0u].toInt()); - colorAdjustment->_rgbBlackAdjustment.setAdjustmentG(values[1u].toInt()); - colorAdjustment->_rgbBlackAdjustment.setAdjustmentB(values[2u].toInt()); + colorAdjustment->_rgbBlackAdjustment.setAdjustment(values[0u].toInt(), values[1u].toInt(), values[2u].toInt()); } if (adjustment.contains("white")) { const QJsonArray & values = adjustment["white"].toArray(); - colorAdjustment->_rgbWhiteAdjustment.setAdjustmentR(values[0u].toInt()); - colorAdjustment->_rgbWhiteAdjustment.setAdjustmentG(values[1u].toInt()); - colorAdjustment->_rgbWhiteAdjustment.setAdjustmentB(values[2u].toInt()); + colorAdjustment->_rgbWhiteAdjustment.setAdjustment(values[0u].toInt(), values[1u].toInt(), values[2u].toInt()); } if (adjustment.contains("gammaRed")) diff --git a/libsrc/utils/RgbChannelAdjustment.cpp b/libsrc/utils/RgbChannelAdjustment.cpp index 53c2b350e..f5c76c2d3 100644 --- a/libsrc/utils/RgbChannelAdjustment.cpp +++ b/libsrc/utils/RgbChannelAdjustment.cpp @@ -26,9 +26,9 @@ RgbChannelAdjustment::~RgbChannelAdjustment() void RgbChannelAdjustment::setAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB) { - _adjust[RED] = adjustR; + _adjust[RED] = adjustR; _adjust[GREEN] = adjustG; - _adjust[BLUE] = adjustB; + _adjust[BLUE] = adjustB; initializeMapping(); } @@ -37,44 +37,21 @@ uint8_t RgbChannelAdjustment::getAdjustmentR() const return _adjust[RED]; } -void RgbChannelAdjustment::setAdjustmentR(uint8_t adjustR) -{ - setAdjustment(adjustR, _adjust[GREEN], _adjust[BLUE]); -} - uint8_t RgbChannelAdjustment::getAdjustmentG() const { return _adjust[GREEN]; } -void RgbChannelAdjustment::setAdjustmentG(uint8_t adjustG) -{ - setAdjustment(_adjust[RED], adjustG, _adjust[BLUE]); -} - uint8_t RgbChannelAdjustment::getAdjustmentB() const { return _adjust[BLUE]; } -void RgbChannelAdjustment::setAdjustmentB(uint8_t adjustB) -{ - setAdjustment(_adjust[RED], _adjust[GREEN], adjustB); -} - -uint8_t RgbChannelAdjustment::getAdjustmentR(uint8_t inputR) const -{ - return _mapping[RED][inputR]; -} - -uint8_t RgbChannelAdjustment::getAdjustmentG(uint8_t inputG) const -{ - return _mapping[GREEN][inputG]; -} - -uint8_t RgbChannelAdjustment::getAdjustmentB(uint8_t inputB) const +void RgbChannelAdjustment::apply(uint8_t input, uint8_t & red, uint8_t & green, uint8_t & blue) { - return _mapping[BLUE][inputB]; + red = _mapping[RED][input]; + green = _mapping[GREEN][input]; + blue = _mapping[BLUE][input]; } void RgbChannelAdjustment::initializeMapping() From 64d95689641f398cf4ec6b99a0b8342deff5b6ad Mon Sep 17 00:00:00 2001 From: redpanther Date: Fri, 31 Mar 2017 19:52:11 +0200 Subject: [PATCH 2/8] now a prio duration of "0" means infinity --- libsrc/hyperion/PriorityMuxer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/hyperion/PriorityMuxer.cpp b/libsrc/hyperion/PriorityMuxer.cpp index 611d0650d..540afabb1 100644 --- a/libsrc/hyperion/PriorityMuxer.cpp +++ b/libsrc/hyperion/PriorityMuxer.cpp @@ -91,7 +91,7 @@ void PriorityMuxer::setCurrentTime(const int64_t& now) for (auto infoIt = _activeInputs.begin(); infoIt != _activeInputs.end();) { - if (infoIt->timeoutTime_ms != -1 && infoIt->timeoutTime_ms <= now) + if (infoIt->timeoutTime_ms > 0 && infoIt->timeoutTime_ms <= now) { infoIt = _activeInputs.erase(infoIt); } From cb8eb2bb2c00b5c0cf82c8a0420c3472135dce0d Mon Sep 17 00:00:00 2001 From: redpanther Date: Fri, 31 Mar 2017 20:41:37 +0200 Subject: [PATCH 3/8] implement dynamic 'just in time' initialization --- include/utils/RgbChannelAdjustment.h | 9 +++++--- libsrc/utils/RgbChannelAdjustment.cpp | 31 ++++++++++++++++----------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/include/utils/RgbChannelAdjustment.h b/include/utils/RgbChannelAdjustment.h index 88bb9aeab..6b5c00b9e 100644 --- a/include/utils/RgbChannelAdjustment.h +++ b/include/utils/RgbChannelAdjustment.h @@ -45,9 +45,9 @@ class RgbChannelAdjustment /// color channels enum ColorChannel { RED=0,GREEN=1, BLUE=2 }; - /// (re)-initilize the color mapping - void initializeMapping(); - + /// reset init of color mapping + void resetInitialized(); + /// The adjustment of RGB channel uint8_t _adjust[3]; @@ -59,4 +59,7 @@ class RgbChannelAdjustment /// Logger instance Logger * _log; + + bool _initialized[256]; + }; diff --git a/libsrc/utils/RgbChannelAdjustment.cpp b/libsrc/utils/RgbChannelAdjustment.cpp index f5c76c2d3..426b21a1c 100644 --- a/libsrc/utils/RgbChannelAdjustment.cpp +++ b/libsrc/utils/RgbChannelAdjustment.cpp @@ -10,7 +10,7 @@ RgbChannelAdjustment::RgbChannelAdjustment(QString channelName) : _channelName(channelName) , _log(Logger::getInstance(channelName)) { - //setAdjustment(UINT8_MAX, UINT8_MAX, UINT8_MAX); + resetInitialized(); } RgbChannelAdjustment::RgbChannelAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB, QString channelName) @@ -24,12 +24,21 @@ RgbChannelAdjustment::~RgbChannelAdjustment() { } +void RgbChannelAdjustment::resetInitialized() +{ + Debug(_log, "initialize mapping with %d,%d,%d", _adjust[RED], _adjust[GREEN], _adjust[BLUE]); + for(int idx=0;idx<256;idx++) + { + _initialized[idx] = false; + } +} + void RgbChannelAdjustment::setAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB) { _adjust[RED] = adjustR; _adjust[GREEN] = adjustG; _adjust[BLUE] = adjustB; - initializeMapping(); + resetInitialized(); } uint8_t RgbChannelAdjustment::getAdjustmentR() const @@ -49,18 +58,14 @@ uint8_t RgbChannelAdjustment::getAdjustmentB() const void RgbChannelAdjustment::apply(uint8_t input, uint8_t & red, uint8_t & green, uint8_t & blue) { + if (!_initialized[input]) + { + _mapping[0][input] = std::min( (((unsigned)input * _adjust[0]) / UINT8_MAX), (unsigned)UINT8_MAX); + _mapping[1][input] = std::min( (((unsigned)input * _adjust[1]) / UINT8_MAX), (unsigned)UINT8_MAX); + _mapping[2][input] = std::min( (((unsigned)input * _adjust[2]) / UINT8_MAX), (unsigned)UINT8_MAX); + _initialized[input] = true; + } red = _mapping[RED][input]; green = _mapping[GREEN][input]; blue = _mapping[BLUE][input]; } - -void RgbChannelAdjustment::initializeMapping() -{ - Debug(_log, "initialize mapping with %d,%d,%d", _adjust[RED], _adjust[GREEN], _adjust[BLUE]); - // initialize linear mapping - for (unsigned channel=0; channel<3; channel++) - for (unsigned idx=0; idx<=UINT8_MAX; idx++) - { - _mapping[channel][idx] = std::min( ((idx * _adjust[channel]) / UINT8_MAX), (unsigned)UINT8_MAX); - } -} From bc5d7fb3c5a2b74437cf83838a2b6c057cb6f459 Mon Sep 17 00:00:00 2001 From: redpanther Date: Sun, 2 Apr 2017 06:43:48 +0200 Subject: [PATCH 4/8] implement new brightness handling --- assets/webconfig/i18n/de.json | 6 +- assets/webconfig/i18n/en.json | 2 + assets/webconfig/js/content_remote.js | 4 +- assets/webconfig/js/ui_utils.js | 6 +- config/hyperion.config.json.commented | 3 +- config/hyperion.config.json.default | 3 +- include/utils/RgbChannelAdjustment.h | 5 +- include/utils/RgbTransform.h | 21 ++++-- libsrc/hyperion/Hyperion.cpp | 5 +- libsrc/hyperion/MultiColorAdjustment.cpp | 22 +++--- libsrc/hyperion/PriorityMuxer.cpp | 2 +- .../hyperion/schemas/hyperion.schema-2.json | 27 ++++--- libsrc/jsonserver/JsonClientConnection.cpp | 9 ++- .../jsonserver/schema/schema-adjustment.json | 12 +++- libsrc/utils/RgbChannelAdjustment.cpp | 24 ++++--- libsrc/utils/RgbTransform.cpp | 70 ++++++++++++++----- src/hyperion-remote/JsonConnection.cpp | 7 +- src/hyperion-remote/JsonConnection.h | 3 +- src/hyperion-remote/hyperion-remote.cpp | 11 +-- 19 files changed, 167 insertions(+), 75 deletions(-) diff --git a/assets/webconfig/i18n/de.json b/assets/webconfig/i18n/de.json index a87e3c75b..52b8dc6b1 100644 --- a/assets/webconfig/i18n/de.json +++ b/assets/webconfig/i18n/de.json @@ -439,8 +439,10 @@ "edt_conf_color_backlightThreshold_expl" : "Eine Beleuchtung die dauerhaft aktiv ist. (Automatisch deaktiviert bei Effekten, Farben oder im Zustand \"Aus\")", "edt_conf_color_backlightColored_title" : "Farbige Hintergrund - beleuchtung", "edt_conf_color_backlightColored_expl" : "Die Hintergrundbeleuchtung kann mit oder ohne Farbanteile genutzt werden.", - "edt_conf_color_brightness_title" : "Maximale Helligkeit", - "edt_conf_color_brightness_expl" : "Zwischen 0.0 und 0.5 ist die Helligkeit linearisiert. Von 0.5 bis 1.0 wird cyan, magenta und gelb bis zu 2x heller und weiß bis zu 3x.", + "edt_conf_color_brightness_title" : "Helligkeit", + "edt_conf_color_brightness_expl" : "die desamt Helligkeit", + "edt_conf_color_brightnessComp_title" : "Helligkeits Kompensation", + "edt_conf_color_brightnessComp_expl" : "Kompensiert unterschiede in der Helligkeit zwischen RGB, CMY und weiß. 100 ist volle Kompensation, 0 keine Kompensation", "edt_conf_smooth_heading_title" : "Glättung", "edt_conf_smooth_type_title" : "Art", "edt_conf_smooth_type_expl" : "Algorithmus der Glättung.", diff --git a/assets/webconfig/i18n/en.json b/assets/webconfig/i18n/en.json index 7bbf01737..41d869b99 100644 --- a/assets/webconfig/i18n/en.json +++ b/assets/webconfig/i18n/en.json @@ -442,6 +442,8 @@ "edt_conf_color_backlightColored_expl" : "Add some color to your backlight.", "edt_conf_color_brightness_title" : "maximal brightness", "edt_conf_color_brightness_expl" : "From 0.0 to 0.5 the brightness is linearised, from 0.5 to 1.0 cyan, magenta, yellow is up to 2x brighter and white 3x.", + "edt_conf_color_brightnessComp_title" : "Brightness Compensation", + "edt_conf_color_brightnessComp_expl" : "compensates bightness differences between RGB, CMY and white. 100 means full compensation, 0 no compensation", "edt_conf_smooth_heading_title" : "Smoothing", "edt_conf_smooth_type_title" : "Type", "edt_conf_smooth_type_expl" : "Type of smoothing.", diff --git a/assets/webconfig/js/content_remote.js b/assets/webconfig/js/content_remote.js index 258068683..f8a9eea41 100644 --- a/assets/webconfig/js/content_remote.js +++ b/assets/webconfig/js/content_remote.js @@ -53,8 +53,10 @@ $(document).ready(function() { } else { - if(sColor[key].key == "brightness" || sColor[key].key == "backlightThreshold") + if(sColor[key].key == "backlightThreshold") property = ''; + else if(sColor[key].key == "brightness" || sColor[key].key == "brightnessCompensation") + property = ''; else property = ''; diff --git a/assets/webconfig/js/ui_utils.js b/assets/webconfig/js/ui_utils.js index 9893e391e..9ca37938e 100644 --- a/assets/webconfig/js/ui_utils.js +++ b/assets/webconfig/js/ui_utils.js @@ -235,14 +235,14 @@ function valValue(id,value,min,max) { if(typeof max === 'undefined' || max == "") max = 999999; - - if(value > max) + + if(Number(value) > Number(max)) { $('#'+id).val(max); showInfoDialog("warning","",$.i18n('edt_msg_error_maximum_incl',max)); return max; } - else if(value < min) + else if(Number(value) < Number(min)) { $('#'+id).val(min); showInfoDialog("warning","",$.i18n('edt_msg_error_minimum_incl',min)); diff --git a/config/hyperion.config.json.commented b/config/hyperion.config.json.commented index 0902c5d21..407b55200 100644 --- a/config/hyperion.config.json.commented +++ b/config/hyperion.config.json.commented @@ -74,7 +74,8 @@ "gammaBlue" : 1.5, "backlightThreshold" : 0.0, "backlightColored" : false, - "brightness" : 0.5 + "brightness" : 100, + "brightnessCompensation" : 80 } ] }, diff --git a/config/hyperion.config.json.default b/config/hyperion.config.json.default index 0533f799c..9d781b242 100644 --- a/config/hyperion.config.json.default +++ b/config/hyperion.config.json.default @@ -40,7 +40,8 @@ "gammaBlue" : 1.5, "backlightThreshold" : 0.0, "backlightColored" : false, - "brightness" : 0.75 + "brightness" : 100, + "brightnessCompensation" : 80 } ] }, diff --git a/include/utils/RgbChannelAdjustment.h b/include/utils/RgbChannelAdjustment.h index 6b5c00b9e..80dfbe15b 100644 --- a/include/utils/RgbChannelAdjustment.h +++ b/include/utils/RgbChannelAdjustment.h @@ -24,7 +24,7 @@ class RgbChannelAdjustment /// Transform the given array value /// @param input The input color bytes - void apply(uint8_t input, uint8_t & red, uint8_t & green, uint8_t & blue); + void apply(uint8_t input, uint8_t brightness, uint8_t & red, uint8_t & green, uint8_t & blue); /// setAdjustment RGB /// @param adjustR @@ -61,5 +61,6 @@ class RgbChannelAdjustment Logger * _log; bool _initialized[256]; - + + uint8_t _brightness; }; diff --git a/include/utils/RgbTransform.h b/include/utils/RgbTransform.h index 32523362e..ea52496ec 100644 --- a/include/utils/RgbTransform.h +++ b/include/utils/RgbTransform.h @@ -24,7 +24,7 @@ class RgbTransform /// @param backlightColored use color in backlight /// @param brightnessHigh The used higher brightness /// - RgbTransform(double gammaR, double gammaG, double gammaB, double backlightThreshold, bool backlightColored, double brightnessHigh); + RgbTransform(double gammaR, double gammaG, double gammaB, double backlightThreshold, bool backlightColored, uint8_t brightness, uint8_t brightnessCompensation); /// /// Destructor @@ -65,10 +65,14 @@ class RgbTransform /// @return The current brightness - double getBrightness() const; + uint8_t getBrightness() const; /// @param brightness New brightness - void setBrightness(double brightness); + void setBrightness(uint8_t brightness); + + void getBrightnessComponents(uint8_t & rgb, uint8_t & cmy, uint8_t & w ); + uint8_t getBrightnessCompensation() const; + void setBrightnessCompensation(uint8_t brightnessCompensation); /// /// Apply the transform the the given RGB values. @@ -92,16 +96,18 @@ class RgbTransform /// @param backlightColored en/disable color in backlight /// @param brightnessHigh The used higher brightness /// - void init(double gammaR, double gammaG, double gammaB, double backlightThreshold, bool backlightColored, double brightnessHigh); + void init(double gammaR, double gammaG, double gammaB, double backlightThreshold, bool backlightColored, uint8_t brightness, uint8_t brightnessCompensation); /// (re)-initilize the color mapping void initializeMapping(); /// The saturation gain + void updateBrightnessComponents(); + double _backlightThreshold; bool _backlightColored; - double _brightnessHigh; + uint8_t _brightness; + uint8_t _brightnessCompensation; double _sumBrightnessLow; - double _sumBrightnessHigh; double _gammaR; double _gammaG; @@ -112,5 +118,8 @@ class RgbTransform uint8_t _mappingG[256]; uint8_t _mappingB[256]; + uint8_t _brightness_rgb; + uint8_t _brightness_cmy; + uint8_t _brightness_w; bool _backLightEnabled; }; diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index fc9c2f6e0..000ae736b 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -162,12 +162,13 @@ RgbTransform* Hyperion::createRgbTransform(const QJsonObject& colorConfig) { const double backlightThreshold = colorConfig["backlightThreshold"].toDouble(0.0); const bool backlightColored = colorConfig["backlightColored"].toBool(false); - const double brightness = colorConfig["brightness"].toDouble(0.5); + const double brightness = colorConfig["brightness"].toInt(100); + const double brightnessComp= colorConfig["brightnessCompensation"].toInt(100); const double gammaR = colorConfig["gammaRed"].toDouble(1.0); const double gammaG = colorConfig["gammaGreen"].toDouble(1.0); const double gammaB = colorConfig["gammaBlue"].toDouble(1.0); - RgbTransform* transform = new RgbTransform(gammaR, gammaG, gammaB, backlightThreshold, backlightColored, brightness); + RgbTransform* transform = new RgbTransform(gammaR, gammaG, gammaB, backlightThreshold, backlightColored, brightness, brightnessComp); return transform; } diff --git a/libsrc/hyperion/MultiColorAdjustment.cpp b/libsrc/hyperion/MultiColorAdjustment.cpp index 6bab6382c..302fb52b9 100644 --- a/libsrc/hyperion/MultiColorAdjustment.cpp +++ b/libsrc/hyperion/MultiColorAdjustment.cpp @@ -106,8 +106,10 @@ void MultiColorAdjustment::applyAdjustment(std::vector& ledColors) uint8_t ored = color.red; uint8_t ogreen = color.green; uint8_t oblue = color.blue; + uint8_t B_RGB, B_CMY, B_W; adjustment->_rgbTransform.transform(ored,ogreen,oblue); + adjustment->_rgbTransform.getBrightnessComponents(B_RGB, B_CMY, B_W); uint32_t nrng = (uint32_t) (255-ored)*(255-ogreen); uint32_t rng = (uint32_t) (ored) *(255-ogreen); @@ -123,15 +125,17 @@ void MultiColorAdjustment::applyAdjustment(std::vector& ledColors) uint8_t yellow = rg *(255-oblue)/65025; uint8_t white = rg *(oblue) /65025; - uint8_t OR, OG, OB, RR, RG, RB, GR, GG, GB, BR, BG, BB, CR, CG, CB, MR, MG, MB, YR, YG, YB, WR, WG, WB; - adjustment->_rgbBlackAdjustment.apply(black, OR, OG, OB); - adjustment->_rgbRedAdjustment.apply(red, RR, RG, RB); - adjustment->_rgbGreenAdjustment.apply(green, GR, GG, GB); - adjustment->_rgbBlueAdjustment.apply(blue, BR, BG, BB); - adjustment->_rgbCyanAdjustment.apply(cyan, CR, CG, CB); - adjustment->_rgbMagentaAdjustment.apply(magenta, MR, MG, MB); - adjustment->_rgbYellowAdjustment.apply(yellow, YR, YG, YB); - adjustment->_rgbWhiteAdjustment.apply(white, WR, WG, WB); + uint8_t OR, OG, OB, RR, RG, RB, GR, GG, GB, BR, BG, BB; + uint8_t CR, CG, CB, MR, MG, MB, YR, YG, YB, WR, WG, WB; + + adjustment->_rgbBlackAdjustment.apply (black , 255 , OR, OG, OB); + adjustment->_rgbRedAdjustment.apply (red , B_RGB, RR, RG, RB); + adjustment->_rgbGreenAdjustment.apply (green , B_RGB, GR, GG, GB); + adjustment->_rgbBlueAdjustment.apply (blue , B_RGB, BR, BG, BB); + adjustment->_rgbCyanAdjustment.apply (cyan , B_CMY, CR, CG, CB); + adjustment->_rgbMagentaAdjustment.apply(magenta, B_CMY, MR, MG, MB); + adjustment->_rgbYellowAdjustment.apply (yellow , B_CMY, YR, YG, YB); + adjustment->_rgbWhiteAdjustment.apply (white , B_W , WR, WG, WB); color.red = OR + RR + GR + BR + CR + MR + YR + WR; color.green = OG + RG + GG + BG + CG + MG + YG + WG; diff --git a/libsrc/hyperion/PriorityMuxer.cpp b/libsrc/hyperion/PriorityMuxer.cpp index 540afabb1..a71df0182 100644 --- a/libsrc/hyperion/PriorityMuxer.cpp +++ b/libsrc/hyperion/PriorityMuxer.cpp @@ -12,7 +12,7 @@ PriorityMuxer::PriorityMuxer(int ledCount) , _lowestPriorityInfo() { _lowestPriorityInfo.priority = LOWEST_PRIORITY; - _lowestPriorityInfo.timeoutTime_ms = -1; + _lowestPriorityInfo.timeoutTime_ms = 0; _lowestPriorityInfo.ledColors = std::vector(ledCount, {0, 0, 0}); _lowestPriorityInfo.componentId = hyperion::COMP_COLOR; _lowestPriorityInfo.origin = "System"; diff --git a/libsrc/hyperion/schemas/hyperion.schema-2.json b/libsrc/hyperion/schemas/hyperion.schema-2.json index 3224c2053..41315e95f 100644 --- a/libsrc/hyperion/schemas/hyperion.schema-2.json +++ b/libsrc/hyperion/schemas/hyperion.schema-2.json @@ -294,15 +294,26 @@ }, "brightness" : { - "type" : "number", + "type" : "integer", "title" : "edt_conf_color_brightness_title", "required" : true, - "minimum" : 0.0, - "maximum": 1.0, - "default" : 1.0, - "step" : 0.05, + "minimum" : 0, + "maximum": 100, + "default" : 100, + "append" : "edt_append_percent", "propertyOrder" : 13 }, + "brightnessCompensation" : + { + "type" : "integer", + "title" : "edt_conf_color_brightnessComp_title", + "required" : true, + "minimum" : 0, + "maximum": 100, + "default" : 90, + "append" : "edt_append_percent", + "propertyOrder" : 14 + }, "gammaRed" : { "type" : "number", @@ -312,7 +323,7 @@ "maximum": 100.0, "default" : 1.5, "step" : 0.1, - "propertyOrder" : 14 + "propertyOrder" : 15 }, "gammaGreen" : { @@ -323,7 +334,7 @@ "maximum": 100.0, "default" : 1.5, "step" : 0.1, - "propertyOrder" : 15 + "propertyOrder" : 16 }, "gammaBlue" : { @@ -334,7 +345,7 @@ "maximum": 100.0, "default" : 1.5, "step" : 0.1, - "propertyOrder" : 16 + "propertyOrder" : 17 } }, "additionalProperties" : false diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index ba2465476..8c60c0fba 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -757,10 +757,11 @@ void JsonClientConnection::handleServerInfoCommand(const QJsonObject&, const QSt yellowAdjust.append(colorAdjustment->_rgbYellowAdjustment.getAdjustmentG()); yellowAdjust.append(colorAdjustment->_rgbYellowAdjustment.getAdjustmentB()); adjustment.insert("yellow", yellowAdjust); - + adjustment["backlightThreshold"] = colorAdjustment->_rgbTransform.getBacklightThreshold(); adjustment["backlightColored"] = colorAdjustment->_rgbTransform.getBacklightColored(); adjustment["brightness"] = colorAdjustment->_rgbTransform.getBrightness(); + adjustment["brightnessCompensation"] = colorAdjustment->_rgbTransform.getBrightnessCompensation(); adjustment["gammaRed"] = colorAdjustment->_rgbTransform.getGammaR(); adjustment["gammaGreen"] = colorAdjustment->_rgbTransform.getGammaG(); adjustment["gammaBlue"] = colorAdjustment->_rgbTransform.getGammaB(); @@ -956,7 +957,11 @@ void JsonClientConnection::handleAdjustmentCommand(const QJsonObject& message, c } if (adjustment.contains("brightness")) { - colorAdjustment->_rgbTransform.setBrightness(adjustment["brightness"].toDouble()); + colorAdjustment->_rgbTransform.setBrightness(adjustment["brightness"].toInt()); + } + if (adjustment.contains("brightnessCompensation")) + { + colorAdjustment->_rgbTransform.setBrightnessCompensation(adjustment["brightnessCompensation"].toInt()); } // commit the changes diff --git a/libsrc/jsonserver/schema/schema-adjustment.json b/libsrc/jsonserver/schema/schema-adjustment.json index fd7fc1630..2cb805316 100644 --- a/libsrc/jsonserver/schema/schema-adjustment.json +++ b/libsrc/jsonserver/schema/schema-adjustment.json @@ -135,10 +135,16 @@ "required" : false }, "brightness" : { - "type" : "number", + "type" : "integer", "required" : false, - "minimum" : 0.0, - "maximum" : 1.0 + "minimum" : 0, + "maximum" : 100 + }, + "brightnessCompensation" : { + "type" : "integer", + "required" : false, + "minimum" : 0, + "maximum" : 100 } }, "additionalProperties": false diff --git a/libsrc/utils/RgbChannelAdjustment.cpp b/libsrc/utils/RgbChannelAdjustment.cpp index 426b21a1c..2a317a8b9 100644 --- a/libsrc/utils/RgbChannelAdjustment.cpp +++ b/libsrc/utils/RgbChannelAdjustment.cpp @@ -9,6 +9,7 @@ RgbChannelAdjustment::RgbChannelAdjustment(QString channelName) : _channelName(channelName) , _log(Logger::getInstance(channelName)) + , _brightness(0) { resetInitialized(); } @@ -27,10 +28,7 @@ RgbChannelAdjustment::~RgbChannelAdjustment() void RgbChannelAdjustment::resetInitialized() { Debug(_log, "initialize mapping with %d,%d,%d", _adjust[RED], _adjust[GREEN], _adjust[BLUE]); - for(int idx=0;idx<256;idx++) - { - _initialized[idx] = false; - } + memset(_initialized, false, sizeof(_initialized)); } void RgbChannelAdjustment::setAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB) @@ -56,16 +54,22 @@ uint8_t RgbChannelAdjustment::getAdjustmentB() const return _adjust[BLUE]; } -void RgbChannelAdjustment::apply(uint8_t input, uint8_t & red, uint8_t & green, uint8_t & blue) +void RgbChannelAdjustment::apply(uint8_t input, uint8_t brightness, uint8_t & red, uint8_t & green, uint8_t & blue) { + if (_brightness != brightness) + { + _brightness = brightness; + resetInitialized(); + } + if (!_initialized[input]) { - _mapping[0][input] = std::min( (((unsigned)input * _adjust[0]) / UINT8_MAX), (unsigned)UINT8_MAX); - _mapping[1][input] = std::min( (((unsigned)input * _adjust[1]) / UINT8_MAX), (unsigned)UINT8_MAX); - _mapping[2][input] = std::min( (((unsigned)input * _adjust[2]) / UINT8_MAX), (unsigned)UINT8_MAX); + _mapping[RED ][input] = std::min( ((_brightness * input * _adjust[RED ]) / 65025), UINT8_MAX); + _mapping[GREEN][input] = std::min( ((_brightness * input * _adjust[GREEN]) / 65025), UINT8_MAX); + _mapping[BLUE ][input] = std::min( ((_brightness * input * _adjust[BLUE ]) / 65025), UINT8_MAX); _initialized[input] = true; } - red = _mapping[RED][input]; + red = _mapping[RED ][input]; green = _mapping[GREEN][input]; - blue = _mapping[BLUE][input]; + blue = _mapping[BLUE ][input]; } diff --git a/libsrc/utils/RgbTransform.cpp b/libsrc/utils/RgbTransform.cpp index 256cabb54..190e80608 100644 --- a/libsrc/utils/RgbTransform.cpp +++ b/libsrc/utils/RgbTransform.cpp @@ -5,21 +5,22 @@ RgbTransform::RgbTransform() { - init(1.0, 1.0, 1.0, 0.0, false, 1.0); + init(1.0, 1.0, 1.0, 0.0, false, 100, 100); } -RgbTransform::RgbTransform(double gammaR, double gammaG, double gammaB, double backlightThreshold, bool backlightColored, double brightnessHigh) +RgbTransform::RgbTransform(double gammaR, double gammaG, double gammaB, double backlightThreshold, bool backlightColored, uint8_t brightness, uint8_t brightnessCompensation) { - init(gammaR, gammaG, gammaB, backlightThreshold, backlightColored, brightnessHigh); + init(gammaR, gammaG, gammaB, backlightThreshold, backlightColored, brightness, brightnessCompensation); } -void RgbTransform::init(double gammaR, double gammaG, double gammaB, double backlightThreshold, bool backlightColored, double brightnessHigh) +void RgbTransform::init(double gammaR, double gammaG, double gammaB, double backlightThreshold, bool backlightColored, uint8_t brightness, uint8_t brightnessCompensation) { _backLightEnabled = true; setGamma(gammaR,gammaG,gammaB); setBacklightThreshold(backlightThreshold); setBacklightColored(backlightColored); - setBrightness(brightnessHigh); + setBrightness(brightness); + setBrightnessCompensation(brightnessCompensation); initializeMapping(); } @@ -92,15 +93,54 @@ void RgbTransform::setBackLightEnabled(bool enable) _backLightEnabled = enable; } -double RgbTransform::getBrightness() const +uint8_t RgbTransform::getBrightness() const { - return _brightnessHigh; + return _brightness; } -void RgbTransform::setBrightness(double brightness) +void RgbTransform::setBrightness(uint8_t brightness) { - _brightnessHigh = brightness; - _sumBrightnessHigh = 765.0 * ((std::pow(2.0,brightness*2)-1) / 3.0); + _brightness = brightness; + updateBrightnessComponents(); +} + +void RgbTransform::setBrightnessCompensation(uint8_t brightnessCompensation) +{ + _brightnessCompensation = brightnessCompensation; + updateBrightnessComponents(); +} + +uint8_t RgbTransform::getBrightnessCompensation() const +{ + return _brightnessCompensation; +} + +void RgbTransform::updateBrightnessComponents() +{ + double Fw = _brightnessCompensation*2.0/100.0+1.0; + double Fcmy = _brightnessCompensation/100.0+1.0; + + double B_in= 0; + _brightness_rgb = 0; + _brightness_cmy = 0; + _brightness_w = 0; + + if (_brightness > 0) + { + B_in = -0.093*_brightness+std::sqrt(_brightness); + if (_brightness< 57) B_in += std::sqrt(57)-std::sqrt(_brightness); + + _brightness_rgb = std::ceil(std::min(255.0,255.0/B_in)); + _brightness_cmy = std::ceil(std::min(255.0,255.0/(B_in*Fcmy))); + _brightness_w = std::ceil(std::min(255.0,255.0/(B_in*Fw))); + } +} + +void RgbTransform::getBrightnessComponents(uint8_t & rgb, uint8_t & cmy, uint8_t & w ) +{ + rgb = _brightness_rgb; + cmy = _brightness_cmy; + w = _brightness_w; } void RgbTransform::transform(uint8_t & red, uint8_t & green, uint8_t & blue) @@ -114,14 +154,7 @@ void RgbTransform::transform(uint8_t & red, uint8_t & green, uint8_t & blue) // apply brightnesss int rgbSum = red+green+blue; - if (_sumBrightnessHigh > 0 && rgbSum > _sumBrightnessHigh) - { - double cH = _sumBrightnessHigh / rgbSum; - red *= cH; - green *= cH; - blue *= cH; - } - else if ( _backLightEnabled && _sumBrightnessLow>0 && rgbSum < _sumBrightnessLow) + if ( _backLightEnabled && _sumBrightnessLow>0 && rgbSum < _sumBrightnessLow) { if (_backlightColored) { @@ -147,3 +180,4 @@ void RgbTransform::transform(uint8_t & red, uint8_t & green, uint8_t & blue) } //std::cout << _sumBrightnessLow << " " << (int)red << " " << (int)green << " " << (int)blue << std::endl; } + diff --git a/src/hyperion-remote/JsonConnection.cpp b/src/hyperion-remote/JsonConnection.cpp index bfb42f7be..8953ea422 100644 --- a/src/hyperion-remote/JsonConnection.cpp +++ b/src/hyperion-remote/JsonConnection.cpp @@ -447,7 +447,8 @@ void JsonConnection::setAdjustment( double *gammaB, double *backlightThreshold, int *backlightColored, - double *brightness) + int *brightness, + int *brightnessC) { qDebug() << "Set color adjustments"; @@ -538,6 +539,10 @@ void JsonConnection::setAdjustment( { adjust["brightness"] = *brightness; } + if (brightnessC != nullptr) + { + adjust["brightnessCompensation"] = *brightnessC; + } if (gammaR != nullptr) { adjust["gammaRed"] = *gammaR; diff --git a/src/hyperion-remote/JsonConnection.h b/src/hyperion-remote/JsonConnection.h index 5e1df5b6b..219ed0021 100644 --- a/src/hyperion-remote/JsonConnection.h +++ b/src/hyperion-remote/JsonConnection.h @@ -156,7 +156,8 @@ class JsonConnection double *gammaB, double *backlightThreshold, int *backlightColored, - double *brightness); + int *brightness, + int *brightnessC); /// /// sets the image to leds mapping type diff --git a/src/hyperion-remote/hyperion-remote.cpp b/src/hyperion-remote/hyperion-remote.cpp index 470d108ae..081a7a85a 100644 --- a/src/hyperion-remote/hyperion-remote.cpp +++ b/src/hyperion-remote/hyperion-remote.cpp @@ -75,8 +75,9 @@ int main(int argc, char * argv[]) BooleanOption & argClearAll = parser.add(0x0, "clearall" , "Clear data for all active priority channels"); Option & argEnableComponent = parser.add