2016-04-02 00:04:11 +02:00
|
|
|
#include <utils/RgbChannelAdjustment.h>
|
|
|
|
|
2017-01-10 19:58:41 +01:00
|
|
|
RgbChannelAdjustment::RgbChannelAdjustment(QString channelName)
|
|
|
|
: _channelName(channelName)
|
|
|
|
, _log(Logger::getInstance(channelName))
|
2017-04-03 05:19:05 +02:00
|
|
|
, _brightness(0)
|
2016-04-02 00:04:11 +02:00
|
|
|
{
|
2017-04-03 05:19:05 +02:00
|
|
|
resetInitialized();
|
2016-04-02 00:04:11 +02:00
|
|
|
}
|
|
|
|
|
2017-01-10 19:58:41 +01:00
|
|
|
RgbChannelAdjustment::RgbChannelAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB, QString channelName)
|
|
|
|
: _channelName(channelName)
|
|
|
|
, _log(Logger::getInstance(channelName))
|
2016-04-02 00:04:11 +02:00
|
|
|
{
|
2016-07-02 14:00:48 +02:00
|
|
|
setAdjustment(adjustR, adjustG, adjustB);
|
2016-04-02 00:04:11 +02:00
|
|
|
}
|
|
|
|
|
2017-04-03 05:19:05 +02:00
|
|
|
void RgbChannelAdjustment::resetInitialized()
|
|
|
|
{
|
|
|
|
memset(_initialized, false, sizeof(_initialized));
|
|
|
|
}
|
|
|
|
|
2016-07-02 14:00:48 +02:00
|
|
|
void RgbChannelAdjustment::setAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB)
|
2016-04-02 00:04:11 +02:00
|
|
|
{
|
2017-03-31 19:37:27 +02:00
|
|
|
_adjust[RED] = adjustR;
|
2016-07-02 14:00:48 +02:00
|
|
|
_adjust[GREEN] = adjustG;
|
2017-03-31 19:37:27 +02:00
|
|
|
_adjust[BLUE] = adjustB;
|
2017-04-03 05:19:05 +02:00
|
|
|
resetInitialized();
|
2016-04-02 00:04:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-02 14:00:48 +02:00
|
|
|
uint8_t RgbChannelAdjustment::getAdjustmentR() const
|
2016-04-02 00:04:11 +02:00
|
|
|
{
|
2016-07-02 14:00:48 +02:00
|
|
|
return _adjust[RED];
|
2016-04-02 00:04:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-02 14:00:48 +02:00
|
|
|
uint8_t RgbChannelAdjustment::getAdjustmentG() const
|
2016-04-02 00:04:11 +02:00
|
|
|
{
|
2016-07-02 14:00:48 +02:00
|
|
|
return _adjust[GREEN];
|
2016-04-02 00:04:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-02 14:00:48 +02:00
|
|
|
uint8_t RgbChannelAdjustment::getAdjustmentB() const
|
2016-04-02 00:04:11 +02:00
|
|
|
{
|
2016-07-02 14:00:48 +02:00
|
|
|
return _adjust[BLUE];
|
|
|
|
}
|
|
|
|
|
2017-04-03 05:19:05 +02:00
|
|
|
void RgbChannelAdjustment::apply(uint8_t input, uint8_t brightness, uint8_t & red, uint8_t & green, uint8_t & blue)
|
2016-04-02 00:04:11 +02:00
|
|
|
{
|
2017-04-03 05:19:05 +02:00
|
|
|
if (_brightness != brightness)
|
|
|
|
{
|
|
|
|
_brightness = brightness;
|
|
|
|
resetInitialized();
|
|
|
|
}
|
2016-04-02 00:04:11 +02:00
|
|
|
|
2017-04-03 05:19:05 +02:00
|
|
|
if (!_initialized[input])
|
|
|
|
{
|
2020-05-12 19:51:19 +02:00
|
|
|
_mapping[RED ][input] = qMin( ((_brightness * input * _adjust[RED ]) / 65025), (int)UINT8_MAX);
|
|
|
|
_mapping[GREEN][input] = qMin( ((_brightness * input * _adjust[GREEN]) / 65025), (int)UINT8_MAX);
|
|
|
|
_mapping[BLUE ][input] = qMin( ((_brightness * input * _adjust[BLUE ]) / 65025), (int)UINT8_MAX);
|
2017-04-03 05:19:05 +02:00
|
|
|
_initialized[input] = true;
|
|
|
|
}
|
|
|
|
red = _mapping[RED ][input];
|
|
|
|
green = _mapping[GREEN][input];
|
|
|
|
blue = _mapping[BLUE ][input];
|
2016-04-02 00:04:11 +02:00
|
|
|
}
|