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
|
|
|
|
2023-04-13 11:21:12 +02:00
|
|
|
#define ROUND_DIVIDE(number, denom) (((number) + (denom) / 2) / (denom))
|
|
|
|
|
2016-10-08 08:14:36 +02:00
|
|
|
namespace RGBW {
|
|
|
|
|
2020-08-08 23:12:43 +02:00
|
|
|
WhiteAlgorithm stringToWhiteAlgorithm(const QString& str)
|
2016-10-08 08:14:36 +02:00
|
|
|
{
|
2020-11-14 17:58:56 +01:00
|
|
|
if (str == "subtract_minimum")
|
|
|
|
{
|
|
|
|
return WhiteAlgorithm::SUBTRACT_MINIMUM;
|
|
|
|
}
|
|
|
|
if (str == "sub_min_warm_adjust")
|
|
|
|
{
|
|
|
|
return WhiteAlgorithm::SUB_MIN_WARM_ADJUST;
|
|
|
|
}
|
|
|
|
if (str == "sub_min_cool_adjust")
|
|
|
|
{
|
|
|
|
return WhiteAlgorithm::SUB_MIN_COOL_ADJUST;
|
|
|
|
}
|
2023-04-13 11:21:12 +02:00
|
|
|
if (str == "cold_white")
|
|
|
|
{
|
|
|
|
return WhiteAlgorithm::COLD_WHITE;
|
|
|
|
}
|
|
|
|
if (str == "neutral_white")
|
|
|
|
{
|
|
|
|
return WhiteAlgorithm::NEUTRAL_WHITE;
|
|
|
|
}
|
|
|
|
if (str == "auto")
|
|
|
|
{
|
|
|
|
return WhiteAlgorithm::AUTO;
|
|
|
|
}
|
|
|
|
if (str == "auto_max")
|
|
|
|
{
|
|
|
|
return WhiteAlgorithm::AUTO_MAX;
|
|
|
|
}
|
|
|
|
if (str == "auto_accurate")
|
|
|
|
{
|
|
|
|
return WhiteAlgorithm::AUTO_ACCURATE;
|
|
|
|
}
|
|
|
|
if (str.isEmpty() || str == "white_off")
|
2020-11-14 17:58:56 +01:00
|
|
|
{
|
|
|
|
return WhiteAlgorithm::WHITE_OFF;
|
|
|
|
}
|
2020-06-28 23:05:32 +02:00
|
|
|
return WhiteAlgorithm::INVALID;
|
2016-10-08 08:14:36 +02:00
|
|
|
}
|
|
|
|
|
2020-08-08 13:22:37 +02:00
|
|
|
void Rgb_to_Rgbw(ColorRgb input, ColorRgbw * output, WhiteAlgorithm algorithm)
|
2016-10-08 08:14:36 +02:00
|
|
|
{
|
|
|
|
switch (algorithm)
|
|
|
|
{
|
2020-06-28 23:05:32 +02:00
|
|
|
case WhiteAlgorithm::SUBTRACT_MINIMUM:
|
2016-10-08 08:14:36 +02:00
|
|
|
{
|
2020-11-14 17:58:56 +01:00
|
|
|
output->white = static_cast<uint8_t>(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;
|
|
|
|
}
|
2020-07-12 20:27:56 +02:00
|
|
|
|
2020-06-28 23:05:32 +02:00
|
|
|
case WhiteAlgorithm::SUB_MIN_WARM_ADJUST:
|
2016-10-08 08:14:36 +02:00
|
|
|
{
|
2018-12-31 06:10:25 +01:00
|
|
|
// http://forum.garagecube.com/viewtopic.php?t=10178
|
2020-06-28 23:05:32 +02:00
|
|
|
// warm white
|
2020-11-14 17:58:56 +01:00
|
|
|
const double F1(0.274);
|
|
|
|
const double F2(0.454);
|
|
|
|
const double F3(2.333);
|
2018-12-31 06:10:25 +01:00
|
|
|
|
2020-11-14 17:58:56 +01:00
|
|
|
output->white = static_cast<uint8_t>(qMin(input.red*F1,qMin(input.green*F2,input.blue*F3)));
|
|
|
|
output->red = input.red - static_cast<uint8_t>(output->white/F1);
|
|
|
|
output->green = input.green - static_cast<uint8_t>(output->white/F2);
|
|
|
|
output->blue = input.blue - static_cast<uint8_t>(output->white/F3);
|
2018-12-31 06:10:25 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-06-28 23:05:32 +02:00
|
|
|
case WhiteAlgorithm::SUB_MIN_COOL_ADJUST:
|
2018-12-31 06:10:25 +01:00
|
|
|
{
|
|
|
|
// http://forum.garagecube.com/viewtopic.php?t=10178
|
2020-06-28 23:05:32 +02:00
|
|
|
// cold white
|
2020-11-14 17:58:56 +01:00
|
|
|
const double F1(0.299);
|
|
|
|
const double F2(0.587);
|
|
|
|
const double F3(0.114);
|
2018-12-31 06:10:25 +01:00
|
|
|
|
2020-11-14 17:58:56 +01:00
|
|
|
output->white = static_cast<uint8_t>(qMin(input.red*F1,qMin(input.green*F2,input.blue*F3)));
|
|
|
|
output->red = input.red - static_cast<uint8_t>(output->white/F1);
|
|
|
|
output->green = input.green - static_cast<uint8_t>(output->white/F2);
|
|
|
|
output->blue = input.blue - static_cast<uint8_t>(output->white/F3);
|
2016-10-08 08:14:36 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-06-28 23:05:32 +02:00
|
|
|
case WhiteAlgorithm::WHITE_OFF:
|
2016-10-08 08:14:36 +02:00
|
|
|
{
|
|
|
|
output->red = input.red;
|
|
|
|
output->green = input.green;
|
|
|
|
output->blue = input.blue;
|
|
|
|
output->white = 0;
|
|
|
|
break;
|
|
|
|
}
|
2023-04-13 11:21:12 +02:00
|
|
|
|
|
|
|
case WhiteAlgorithm::AUTO_MAX:
|
|
|
|
{
|
|
|
|
output->red = input.red;
|
|
|
|
output->green = input.green;
|
|
|
|
output->blue = input.blue;
|
|
|
|
output->white = input.red > input.green ? (input.red > input.blue ? input.red : input.blue) : (input.green > input.blue ? input.green : input.blue);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WhiteAlgorithm::AUTO_ACCURATE:
|
|
|
|
{
|
|
|
|
output->white = input.red < input.green ? (input.red < input.blue ? input.red : input.blue) : (input.green < input.blue ? input.green : input.blue);
|
|
|
|
output->red = input.red - output->white;
|
|
|
|
output->green = input.green - output->white;
|
|
|
|
output->blue = input.blue - output->white;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WhiteAlgorithm::AUTO:
|
|
|
|
{
|
|
|
|
|
|
|
|
output->red = input.red;
|
|
|
|
output->green = input.green;
|
|
|
|
output->blue = input.blue;
|
|
|
|
output->white = input.red < input.green ? (input.red < input.blue ? input.red : input.blue) : (input.green < input.blue ? input.green : input.blue);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WhiteAlgorithm::NEUTRAL_WHITE:
|
|
|
|
case WhiteAlgorithm::COLD_WHITE:
|
|
|
|
{
|
|
|
|
//cold white config
|
|
|
|
uint8_t gain = 0xFF;
|
|
|
|
uint8_t red = 0xA0;
|
|
|
|
uint8_t green = 0xA0;
|
|
|
|
uint8_t blue = 0xA0;
|
|
|
|
|
|
|
|
if (algorithm == WhiteAlgorithm::NEUTRAL_WHITE) {
|
|
|
|
gain = 0xFF;
|
|
|
|
red = 0xB0;
|
|
|
|
green = 0xB0;
|
|
|
|
blue = 0x70;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t _r = qMin((uint32_t)(ROUND_DIVIDE(red * input.red, 0xFF)), (uint32_t)0xFF);
|
|
|
|
uint8_t _g = qMin((uint32_t)(ROUND_DIVIDE(green * input.green, 0xFF)), (uint32_t)0xFF);
|
|
|
|
uint8_t _b = qMin((uint32_t)(ROUND_DIVIDE(blue * input.blue, 0xFF)), (uint32_t)0xFF);
|
|
|
|
|
|
|
|
output->white = qMin(_r, qMin(_g, _b));
|
|
|
|
output->red = input.red - _r;
|
|
|
|
output->green = input.green - _g;
|
|
|
|
output->blue = input.blue - _b;
|
|
|
|
|
|
|
|
uint8_t _w = qMin((uint32_t)(ROUND_DIVIDE(gain * output->white, 0xFF)), (uint32_t)0xFF);
|
|
|
|
output->white = _w;
|
|
|
|
break;
|
|
|
|
}
|
2016-10-08 08:14:36 +02:00
|
|
|
default:
|
|
|
|
break;
|
2016-05-31 22:55:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-08 08:14:36 +02:00
|
|
|
};
|