2016-04-02 00:04:11 +02:00
|
|
|
#include <utils/RgbChannelAdjustment.h>
|
|
|
|
|
2024-12-28 20:45:10 +01:00
|
|
|
|
|
|
|
RgbChannelAdjustment::RgbChannelAdjustment(const QString& channelName)
|
2024-01-13 17:04:45 +01:00
|
|
|
: RgbChannelAdjustment(0, 0, 0, channelName)
|
2016-04-02 00:04:11 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-12-28 20:45:10 +01:00
|
|
|
RgbChannelAdjustment::RgbChannelAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB, const QString& channelName )
|
|
|
|
: RgbChannelAdjustment({adjustR, adjustG, adjustB}, channelName)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
RgbChannelAdjustment::RgbChannelAdjustment(const ColorRgb& adjust, const QString& channelName )
|
2017-01-10 19:58:41 +01:00
|
|
|
: _channelName(channelName)
|
2024-01-13 17:04:45 +01:00
|
|
|
, _log(Logger::getInstance("CHANNEL_" + channelName.toUpper()))
|
2024-12-28 20:45:10 +01:00
|
|
|
, _mapping{ {0}, {0}, {0} }
|
2024-01-13 17:04:45 +01:00
|
|
|
, _brightness(0)
|
2016-04-02 00:04:11 +02:00
|
|
|
{
|
2024-12-28 20:45:10 +01:00
|
|
|
setAdjustment(adjust);
|
2016-04-02 00:04:11 +02:00
|
|
|
}
|
|
|
|
|
2017-04-03 05:19:05 +02:00
|
|
|
void RgbChannelAdjustment::resetInitialized()
|
|
|
|
{
|
2024-12-28 20:45:10 +01:00
|
|
|
memset(_initialized, 0, sizeof(_initialized));
|
2017-04-03 05:19:05 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2024-12-28 20:45:10 +01:00
|
|
|
setAdjustment( {adjustR, adjustG, adjustB} );
|
|
|
|
}
|
|
|
|
|
|
|
|
void RgbChannelAdjustment::setAdjustment(const ColorRgb& adjust)
|
|
|
|
{
|
|
|
|
_adjust = adjust;
|
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
|
|
|
{
|
2024-12-28 20:45:10 +01: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
|
|
|
{
|
2024-12-28 20:45:10 +01: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
|
|
|
{
|
2024-12-28 20:45:10 +01:00
|
|
|
return _adjust.blue;
|
2016-07-02 14:00:48 +02:00
|
|
|
}
|
|
|
|
|
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])
|
|
|
|
{
|
2024-12-28 20:45:10 +01:00
|
|
|
const double adjustedInput = _brightness * input / DOUBLE_UINT8_MAX_SQUARED;
|
|
|
|
_mapping.red[input] = static_cast<quint8>(qBound(0, static_cast<int>(_adjust.red * adjustedInput), static_cast<int>(UINT8_MAX)));
|
|
|
|
_mapping.green[input] = static_cast<quint8>(qBound(0 ,static_cast<int>(_adjust.green * adjustedInput), static_cast<int>(UINT8_MAX)));
|
|
|
|
_mapping.blue[input] = static_cast<quint8>(qBound(0, static_cast<int>(_adjust.blue * adjustedInput), static_cast<int>(UINT8_MAX)));
|
2017-04-03 05:19:05 +02:00
|
|
|
_initialized[input] = true;
|
|
|
|
}
|
2024-12-28 20:45:10 +01:00
|
|
|
red = _mapping.red[input];
|
|
|
|
green = _mapping.green[input];
|
|
|
|
blue = _mapping.blue[input];
|
2016-04-02 00:04:11 +02:00
|
|
|
}
|