From bceb255b7a160fab2ebda6b094ea922e95db8ca4 Mon Sep 17 00:00:00 2001 From: penfold42 Date: Mon, 31 Dec 2018 16:10:25 +1100 Subject: [PATCH] Implemented warm white (and added cool white) RGBW white algorithms --- include/utils/RgbToRgbw.h | 8 +++++++- libsrc/utils/RgbToRgbw.cpp | 27 ++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/include/utils/RgbToRgbw.h b/include/utils/RgbToRgbw.h index f1450427..87b76667 100644 --- a/include/utils/RgbToRgbw.h +++ b/include/utils/RgbToRgbw.h @@ -6,7 +6,13 @@ namespace RGBW { - enum WhiteAlgorithm { INVALID, SUBTRACT_MINIMUM, SUB_MIN_WARM_ADJUST, WHITE_OFF }; + enum WhiteAlgorithm { + INVALID, + SUBTRACT_MINIMUM, + SUB_MIN_WARM_ADJUST, + SUB_MIN_COOL_ADJUST, + WHITE_OFF + }; WhiteAlgorithm stringToWhiteAlgorithm(QString str); void Rgb_to_Rgbw(ColorRgb input, ColorRgbw * output, const WhiteAlgorithm algorithm); diff --git a/libsrc/utils/RgbToRgbw.cpp b/libsrc/utils/RgbToRgbw.cpp index 7e5005c1..bb6aaa40 100755 --- a/libsrc/utils/RgbToRgbw.cpp +++ b/libsrc/utils/RgbToRgbw.cpp @@ -9,6 +9,7 @@ WhiteAlgorithm stringToWhiteAlgorithm(QString str) { if (str == "subtract_minimum") return SUBTRACT_MINIMUM; if (str == "sub_min_warm_adjust") return SUB_MIN_WARM_ADJUST; + if (str == "sub_min_cool_adjust") return SUB_MIN_COOL_ADJUST; if (str.isEmpty() || str == "white_off") return WHITE_OFF; return INVALID; } @@ -28,7 +29,31 @@ void Rgb_to_Rgbw(ColorRgb input, ColorRgbw * output, const WhiteAlgorithm algori case SUB_MIN_WARM_ADJUST: { - Error(Logger::getInstance("RGBtoRGBW"), "white algorithm 'sub_min_warm_adjust' is not implemented yet." ); + // http://forum.garagecube.com/viewtopic.php?t=10178 + // warm white + float F1 = 0.274; + float F2 = 0.454; + float F3 = 2.333; + + output->white = qMin(input.red*F1,qMin(input.green*F2,input.blue*F3)); + output->red = input.red - output->white/F1; + output->green = input.green - output->white/F2; + output->blue = input.blue - output->white/F3; + break; + } + + case SUB_MIN_COOL_ADJUST: + { + // http://forum.garagecube.com/viewtopic.php?t=10178 + // cold white + float F1 = 0.299; + float F2 = 0.587; + float F3 = 0.114; + + output->white = qMin(input.red*F1,qMin(input.green*F2,input.blue*F3)); + output->red = input.red - output->white/F1; + output->green = input.green - output->white/F2; + output->blue = input.blue - output->white/F3; break; }