2013-08-23 18:24:10 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// STL includes
|
|
|
|
#include <cstdint>
|
|
|
|
|
2013-08-31 14:36:54 +02:00
|
|
|
///
|
2013-09-09 04:54:13 +02:00
|
|
|
/// Color transformation to adjust the saturation and value of a RGB color value
|
2013-08-31 14:36:54 +02:00
|
|
|
///
|
2013-08-23 18:24:10 +02:00
|
|
|
class HsvTransform
|
|
|
|
{
|
|
|
|
public:
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
2013-08-31 14:36:54 +02:00
|
|
|
/// Default constructor
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
2013-08-23 18:24:10 +02:00
|
|
|
HsvTransform();
|
2013-08-31 14:36:54 +02:00
|
|
|
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
|
|
|
/// Constructor
|
|
|
|
///
|
|
|
|
/// @param saturationGain The used saturation gain
|
|
|
|
/// @param valueGain The used value gain
|
|
|
|
///
|
2013-08-23 18:24:10 +02:00
|
|
|
HsvTransform(double saturationGain, double valueGain);
|
2013-08-31 14:36:54 +02:00
|
|
|
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
2013-08-31 14:36:54 +02:00
|
|
|
/// Destructor
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
2013-08-23 18:24:10 +02:00
|
|
|
~HsvTransform();
|
|
|
|
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
|
|
|
/// Updates the saturation gain
|
|
|
|
///
|
2013-08-31 14:36:54 +02:00
|
|
|
/// @param saturationGain New saturationGain
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
2013-08-23 18:24:10 +02:00
|
|
|
void setSaturationGain(double saturationGain);
|
2013-08-31 14:36:54 +02:00
|
|
|
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
|
|
|
/// Returns the saturation gain
|
|
|
|
///
|
2013-08-31 14:36:54 +02:00
|
|
|
/// @return The current Saturation gain
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
2013-08-23 18:24:10 +02:00
|
|
|
double getSaturationGain() const;
|
|
|
|
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
|
|
|
/// Updates the value gain
|
|
|
|
///
|
|
|
|
/// @param valueGain New value gain
|
|
|
|
///
|
2013-08-23 18:24:10 +02:00
|
|
|
void setValueGain(double valueGain);
|
2013-08-31 14:36:54 +02:00
|
|
|
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
|
|
|
/// Returns the value gain
|
|
|
|
///
|
2013-08-31 14:36:54 +02:00
|
|
|
/// @return The current value gain
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
2013-08-23 18:24:10 +02:00
|
|
|
double getValueGain() const;
|
|
|
|
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
|
|
|
/// Apply the transform the the given RGB values.
|
|
|
|
///
|
2013-08-31 14:36:54 +02:00
|
|
|
/// @param red The red color component
|
|
|
|
/// @param green The green color component
|
|
|
|
/// @param blue The blue color component
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
2013-08-31 14:36:54 +02:00
|
|
|
/// @note The values are updated in place.
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
2013-08-23 18:24:10 +02:00
|
|
|
void transform(uint8_t & red, uint8_t & green, uint8_t & blue) const;
|
|
|
|
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
2013-09-09 22:35:28 +02:00
|
|
|
/// Translates an RGB (red, green, blue) color to an HSV (hue, saturation, value) color
|
|
|
|
///
|
|
|
|
/// @param[in] red The red RGB-component
|
|
|
|
/// @param[in] green The green RGB-component
|
|
|
|
/// @param[in] blue The blue RGB-component
|
|
|
|
/// @param[out] hue The hue HSV-component
|
|
|
|
/// @param[out] saturation The saturation HSV-component
|
|
|
|
/// @param[out] value The value HSV-component
|
|
|
|
///
|
|
|
|
/// @note Integer version of the conversion are faster, but a little less accurate all values
|
|
|
|
/// are unsigned 8 bit values and scaled between 0 and 255 except for the hue which is a 16 bit
|
|
|
|
/// number and scaled between 0 and 360
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
2013-08-23 18:24:10 +02:00
|
|
|
static void rgb2hsv(uint8_t red, uint8_t green, uint8_t blue, uint16_t & hue, uint8_t & saturation, uint8_t & value);
|
2013-09-09 22:35:28 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// Translates an HSV (hue, saturation, value) color to an RGB (red, green, blue) color
|
|
|
|
///
|
|
|
|
/// @param[in] hue The hue HSV-component
|
|
|
|
/// @param[in] saturation The saturation HSV-component
|
|
|
|
/// @param[in] value The value HSV-component
|
|
|
|
/// @param[out] red The red RGB-component
|
|
|
|
/// @param[out] green The green RGB-component
|
|
|
|
/// @param[out] blue The blue RGB-component
|
|
|
|
///
|
|
|
|
/// @note Integer version of the conversion are faster, but a little less accurate all values
|
|
|
|
/// are unsigned 8 bit values and scaled between 0 and 255 except for the hue which is a 16 bit
|
|
|
|
/// number and scaled between 0 and 360
|
|
|
|
///
|
2013-08-23 18:24:10 +02:00
|
|
|
static void hsv2rgb(uint16_t hue, uint8_t saturation, uint8_t value, uint8_t & red, uint8_t & green, uint8_t & blue);
|
|
|
|
|
|
|
|
private:
|
2013-09-09 04:54:13 +02:00
|
|
|
/// The saturation gain
|
2013-08-23 18:24:10 +02:00
|
|
|
double _saturationGain;
|
2013-09-09 04:54:13 +02:00
|
|
|
/// The value gain
|
2013-08-23 18:24:10 +02:00
|
|
|
double _valueGain;
|
|
|
|
};
|