2017-08-04 12:01:45 +02:00
|
|
|
#include <QtCore/qmath.h>
|
2017-01-06 14:25:55 +01:00
|
|
|
#include <utils/RgbTransform.h>
|
|
|
|
|
|
|
|
RgbTransform::RgbTransform()
|
|
|
|
{
|
2017-04-03 05:19:05 +02:00
|
|
|
init(1.0, 1.0, 1.0, 0.0, false, 100, 100);
|
2017-01-06 14:25:55 +01:00
|
|
|
}
|
|
|
|
|
2017-04-03 05:19:05 +02:00
|
|
|
RgbTransform::RgbTransform(double gammaR, double gammaG, double gammaB, double backlightThreshold, bool backlightColored, uint8_t brightness, uint8_t brightnessCompensation)
|
2017-01-06 14:25:55 +01:00
|
|
|
{
|
2017-04-03 05:19:05 +02:00
|
|
|
init(gammaR, gammaG, gammaB, backlightThreshold, backlightColored, brightness, brightnessCompensation);
|
2017-01-06 14:25:55 +01:00
|
|
|
}
|
|
|
|
|
2017-04-03 05:19:05 +02:00
|
|
|
void RgbTransform::init(double gammaR, double gammaG, double gammaB, double backlightThreshold, bool backlightColored, uint8_t brightness, uint8_t brightnessCompensation)
|
2017-01-06 14:25:55 +01:00
|
|
|
{
|
2017-02-11 22:52:47 +01:00
|
|
|
_backLightEnabled = true;
|
2017-01-06 14:25:55 +01:00
|
|
|
setGamma(gammaR,gammaG,gammaB);
|
2017-02-11 22:52:47 +01:00
|
|
|
setBacklightThreshold(backlightThreshold);
|
|
|
|
setBacklightColored(backlightColored);
|
2017-04-03 05:19:05 +02:00
|
|
|
setBrightness(brightness);
|
|
|
|
setBrightnessCompensation(brightnessCompensation);
|
2017-01-06 14:25:55 +01:00
|
|
|
initializeMapping();
|
|
|
|
}
|
|
|
|
|
|
|
|
RgbTransform::~RgbTransform()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
double RgbTransform::getGammaR() const
|
|
|
|
{
|
|
|
|
return _gammaR;
|
|
|
|
}
|
|
|
|
|
|
|
|
double RgbTransform::getGammaG() const
|
|
|
|
{
|
|
|
|
return _gammaG;
|
|
|
|
}
|
|
|
|
|
|
|
|
double RgbTransform::getGammaB() const
|
|
|
|
{
|
|
|
|
return _gammaB;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RgbTransform::setGamma(double gammaR, double gammaG, double gammaB)
|
|
|
|
{
|
|
|
|
_gammaR = gammaR;
|
|
|
|
_gammaG = (gammaG < 0.0) ? _gammaR : gammaG;
|
|
|
|
_gammaB = (gammaB < 0.0) ? _gammaR : gammaB;
|
|
|
|
initializeMapping();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RgbTransform::initializeMapping()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 256; ++i)
|
|
|
|
{
|
2017-08-04 12:01:45 +02:00
|
|
|
_mappingR[i] = qMin(qMax((int)(qPow(i / 255.0, _gammaR) * 255), 0), 255);
|
|
|
|
_mappingG[i] = qMin(qMax((int)(qPow(i / 255.0, _gammaG) * 255), 0), 255);
|
|
|
|
_mappingB[i] = qMin(qMax((int)(qPow(i / 255.0, _gammaB) * 255), 0), 255);
|
2017-01-06 14:25:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-03 05:19:05 +02:00
|
|
|
int RgbTransform::getBacklightThreshold() const
|
2017-01-06 14:25:55 +01:00
|
|
|
{
|
2017-02-11 22:52:47 +01:00
|
|
|
return _backlightThreshold;
|
2017-01-06 14:25:55 +01:00
|
|
|
}
|
|
|
|
|
2017-04-03 05:19:05 +02:00
|
|
|
void RgbTransform::setBacklightThreshold(int backlightThreshold)
|
2017-01-06 14:25:55 +01:00
|
|
|
{
|
2017-02-11 22:52:47 +01:00
|
|
|
_backlightThreshold = backlightThreshold;
|
2017-08-04 12:01:45 +02:00
|
|
|
_sumBrightnessLow = 765.0 * ((qPow(2.0,(_backlightThreshold/100)*2)-1) / 3.0);
|
2017-02-11 22:52:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RgbTransform::getBacklightColored() const
|
|
|
|
{
|
|
|
|
return _backlightColored;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RgbTransform::setBacklightColored(bool backlightColored)
|
|
|
|
{
|
|
|
|
_backlightColored = backlightColored;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RgbTransform::getBackLightEnabled() const
|
|
|
|
{
|
|
|
|
return _backLightEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RgbTransform::setBackLightEnabled(bool enable)
|
|
|
|
{
|
|
|
|
_backLightEnabled = enable;
|
2017-01-06 14:25:55 +01:00
|
|
|
}
|
|
|
|
|
2017-04-03 05:19:05 +02:00
|
|
|
uint8_t RgbTransform::getBrightness() const
|
2017-01-06 14:25:55 +01:00
|
|
|
{
|
2017-04-03 05:19:05 +02:00
|
|
|
return _brightness;
|
2017-01-06 14:25:55 +01:00
|
|
|
}
|
|
|
|
|
2017-04-03 05:19:05 +02:00
|
|
|
void RgbTransform::setBrightness(uint8_t brightness)
|
2017-01-06 14:25:55 +01:00
|
|
|
{
|
2017-04-03 05:19:05 +02:00
|
|
|
_brightness = brightness;
|
|
|
|
updateBrightnessComponents();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RgbTransform::setBrightnessCompensation(uint8_t brightnessCompensation)
|
|
|
|
{
|
|
|
|
_brightnessCompensation = brightnessCompensation;
|
|
|
|
updateBrightnessComponents();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t RgbTransform::getBrightnessCompensation() const
|
|
|
|
{
|
|
|
|
return _brightnessCompensation;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RgbTransform::updateBrightnessComponents()
|
|
|
|
{
|
|
|
|
double Fw = _brightnessCompensation*2.0/100.0+1.0;
|
|
|
|
double Fcmy = _brightnessCompensation/100.0+1.0;
|
|
|
|
|
|
|
|
double B_in= 0;
|
|
|
|
_brightness_rgb = 0;
|
|
|
|
_brightness_cmy = 0;
|
|
|
|
_brightness_w = 0;
|
|
|
|
|
|
|
|
if (_brightness > 0)
|
|
|
|
{
|
|
|
|
B_in = (_brightness<50)? -0.09*_brightness+7.5 : -0.04*_brightness+5.0;
|
|
|
|
|
2017-08-04 12:01:45 +02:00
|
|
|
_brightness_rgb = std::ceil(qMin(255.0,255.0/B_in));
|
|
|
|
_brightness_cmy = std::ceil(qMin(255.0,255.0/(B_in*Fcmy)));
|
|
|
|
_brightness_w = std::ceil(qMin(255.0,255.0/(B_in*Fw)));
|
2017-04-03 05:19:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RgbTransform::getBrightnessComponents(uint8_t & rgb, uint8_t & cmy, uint8_t & w )
|
|
|
|
{
|
|
|
|
rgb = _brightness_rgb;
|
|
|
|
cmy = _brightness_cmy;
|
|
|
|
w = _brightness_w;
|
2017-01-06 14:25:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RgbTransform::transform(uint8_t & red, uint8_t & green, uint8_t & blue)
|
|
|
|
{
|
|
|
|
// apply gamma
|
|
|
|
red = _mappingR[red];
|
2018-12-27 23:11:32 +01:00
|
|
|
green = _mappingR[green];
|
|
|
|
blue = _mappingR[blue];
|
2017-01-06 14:25:55 +01:00
|
|
|
|
|
|
|
// apply brightnesss
|
|
|
|
int rgbSum = red+green+blue;
|
|
|
|
|
2017-04-03 05:19:05 +02:00
|
|
|
if ( _backLightEnabled && _sumBrightnessLow>0 && rgbSum < _sumBrightnessLow)
|
2017-01-06 14:25:55 +01:00
|
|
|
{
|
2017-02-11 22:52:47 +01:00
|
|
|
if (_backlightColored)
|
|
|
|
{
|
|
|
|
if (rgbSum == 0)
|
|
|
|
{
|
|
|
|
if (red ==0) red = 1;
|
|
|
|
if (green==0) green = 1;
|
|
|
|
if (blue ==0) blue = 1;
|
|
|
|
rgbSum = red+green+blue;
|
|
|
|
}
|
2017-08-04 12:01:45 +02:00
|
|
|
double cL =qMin((int)(_sumBrightnessLow /rgbSum), 255);
|
2017-02-11 22:52:47 +01:00
|
|
|
|
|
|
|
red *= cL;
|
|
|
|
green *= cL;
|
|
|
|
blue *= cL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-04 12:01:45 +02:00
|
|
|
red = qMin((int)(_sumBrightnessLow/3.0), 255);
|
2017-02-11 22:52:47 +01:00
|
|
|
green = red;
|
|
|
|
blue = red;
|
|
|
|
}
|
2017-01-06 14:25:55 +01:00
|
|
|
}
|
|
|
|
}
|
2017-04-03 05:19:05 +02:00
|
|
|
|