2016-04-02 00:04:11 +02:00
|
|
|
// STL includes
|
|
|
|
#include <cmath>
|
2016-07-02 14:00:48 +02:00
|
|
|
#include <cstdint>
|
|
|
|
#include <algorithm>
|
2016-04-02 00:04:11 +02:00
|
|
|
|
|
|
|
// Utils includes
|
|
|
|
#include <utils/RgbChannelAdjustment.h>
|
|
|
|
|
2016-07-02 14:00:48 +02:00
|
|
|
RgbChannelAdjustment::RgbChannelAdjustment()
|
2016-04-02 00:04:11 +02:00
|
|
|
{
|
2016-07-02 14:00:48 +02:00
|
|
|
setAdjustment(UINT8_MAX, UINT8_MAX, UINT8_MAX);
|
2016-04-02 00:04:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-02 14:00:48 +02:00
|
|
|
RgbChannelAdjustment::RgbChannelAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB)
|
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
|
|
|
}
|
|
|
|
|
|
|
|
RgbChannelAdjustment::~RgbChannelAdjustment()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2016-07-02 14:00:48 +02:00
|
|
|
_adjust[RED] = adjustR;
|
|
|
|
_adjust[GREEN] = adjustG;
|
|
|
|
_adjust[BLUE] = adjustB;
|
|
|
|
initializeMapping();
|
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
|
|
|
void RgbChannelAdjustment::setAdjustmentR(uint8_t adjustR)
|
2016-04-02 00:04:11 +02:00
|
|
|
{
|
2016-07-02 14:00:48 +02:00
|
|
|
setAdjustment(adjustR, _adjust[GREEN], _adjust[BLUE]);
|
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
|
|
|
void RgbChannelAdjustment::setAdjustmentG(uint8_t adjustG)
|
2016-04-02 00:04:11 +02:00
|
|
|
{
|
2016-07-02 14:00:48 +02:00
|
|
|
setAdjustment(_adjust[RED], adjustG, _adjust[BLUE]);
|
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];
|
|
|
|
}
|
|
|
|
|
|
|
|
void RgbChannelAdjustment::setAdjustmentB(uint8_t adjustB)
|
|
|
|
{
|
|
|
|
setAdjustment(_adjust[RED], _adjust[GREEN], adjustB);
|
2016-04-02 00:04:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t RgbChannelAdjustment::adjustmentR(uint8_t inputR) const
|
|
|
|
{
|
2016-07-02 14:00:48 +02:00
|
|
|
return _mapping[RED][inputR];
|
2016-04-02 00:04:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t RgbChannelAdjustment::adjustmentG(uint8_t inputG) const
|
|
|
|
{
|
2016-07-02 14:00:48 +02:00
|
|
|
return _mapping[GREEN][inputG];
|
2016-04-02 00:04:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t RgbChannelAdjustment::adjustmentB(uint8_t inputB) const
|
|
|
|
{
|
2016-07-02 14:00:48 +02:00
|
|
|
return _mapping[BLUE][inputB];
|
2016-04-02 00:04:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void RgbChannelAdjustment::initializeMapping()
|
|
|
|
{
|
2016-07-02 14:00:48 +02:00
|
|
|
// initialize linear mapping
|
|
|
|
for (unsigned channel=0; channel<3; channel++)
|
|
|
|
for (unsigned idx=0; idx<=UINT8_MAX; idx++)
|
2016-04-02 00:04:11 +02:00
|
|
|
{
|
2016-07-02 14:00:48 +02:00
|
|
|
_mapping[channel][idx] = std::min( ((idx * _adjust[channel]) / UINT8_MAX), (unsigned)UINT8_MAX);
|
2016-04-02 00:04:11 +02:00
|
|
|
}
|
|
|
|
}
|