2016-05-31 22:55:56 +02:00
|
|
|
#include <utils/ColorRgb.h>
|
|
|
|
#include <utils/ColorRgbw.h>
|
2016-10-08 08:14:36 +02:00
|
|
|
#include <utils/RgbToRgbw.h>
|
2016-06-28 21:53:34 +02:00
|
|
|
#include <utils/Logger.h>
|
2016-05-31 22:55:56 +02:00
|
|
|
|
2016-10-08 08:14:36 +02:00
|
|
|
namespace RGBW {
|
|
|
|
|
2017-03-04 22:17:42 +01:00
|
|
|
WhiteAlgorithm stringToWhiteAlgorithm(QString str)
|
2016-10-08 08:14:36 +02:00
|
|
|
{
|
|
|
|
if (str == "subtract_minimum") return SUBTRACT_MINIMUM;
|
|
|
|
if (str == "sub_min_warm_adjust") return SUB_MIN_WARM_ADJUST;
|
2018-12-31 06:10:25 +01:00
|
|
|
if (str == "sub_min_cool_adjust") return SUB_MIN_COOL_ADJUST;
|
2017-03-04 22:17:42 +01:00
|
|
|
if (str.isEmpty() || str == "white_off") return WHITE_OFF;
|
2016-10-08 08:14:36 +02:00
|
|
|
return INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Rgb_to_Rgbw(ColorRgb input, ColorRgbw * output, const WhiteAlgorithm algorithm)
|
|
|
|
{
|
|
|
|
switch (algorithm)
|
|
|
|
{
|
|
|
|
case SUBTRACT_MINIMUM:
|
|
|
|
{
|
2017-08-04 12:01:45 +02:00
|
|
|
output->white = qMin(qMin(input.red, input.green), input.blue);
|
2016-10-08 08:14:36 +02:00
|
|
|
output->red = input.red - output->white;
|
|
|
|
output->green = input.green - output->white;
|
|
|
|
output->blue = input.blue - output->white;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SUB_MIN_WARM_ADJUST:
|
|
|
|
{
|
2018-12-31 06:10:25 +01:00
|
|
|
// 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;
|
2016-10-08 08:14:36 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WHITE_OFF:
|
|
|
|
{
|
|
|
|
output->red = input.red;
|
|
|
|
output->green = input.green;
|
|
|
|
output->blue = input.blue;
|
|
|
|
output->white = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
2016-05-31 22:55:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-08 08:14:36 +02:00
|
|
|
};
|