2013-08-23 18:24:10 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// STL includes
|
|
|
|
#include <cstdint>
|
|
|
|
|
2013-08-31 14:36:54 +02:00
|
|
|
///
|
2017-01-06 14:25:55 +01:00
|
|
|
/// Color transformation to adjust the saturation and luminance of a RGB color value
|
2013-08-31 14:36:54 +02:00
|
|
|
///
|
2017-01-06 14:25:55 +01:00
|
|
|
class ColorSys
|
2013-08-23 18:24:10 +02:00
|
|
|
{
|
|
|
|
public:
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
2017-01-06 14:25:55 +01:00
|
|
|
/// Translates an RGB (red, green, blue) color to an HSL (hue, saturation, luminance) color
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
2017-01-06 14:25:55 +01:00
|
|
|
/// @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 HSL-component
|
|
|
|
/// @param[out] saturation The saturation HSL-component
|
|
|
|
/// @param[out] luminance The luminance HSL-component
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
2013-08-31 14:36:54 +02:00
|
|
|
|
2017-01-06 14:25:55 +01:00
|
|
|
static void rgb2hsl(uint8_t red, uint8_t green, uint8_t blue, uint16_t & hue, float & saturation, float & luminance);
|
2013-08-23 18:24:10 +02:00
|
|
|
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
2017-01-06 14:25:55 +01:00
|
|
|
/// Translates an HSL (hue, saturation, luminance) color to an RGB (red, green, blue) color
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
2017-01-06 14:25:55 +01:00
|
|
|
/// @param[in] hue The hue HSL-component
|
|
|
|
/// @param[in] saturation The saturation HSL-component
|
|
|
|
/// @param[in] luminance The luminance HSL-component
|
|
|
|
/// @param[out] red The red RGB-component
|
|
|
|
/// @param[out] green The green RGB-component
|
|
|
|
/// @param[out] blue The blue RGB-component
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
2013-08-23 18:24:10 +02:00
|
|
|
|
2017-01-06 14:25:55 +01:00
|
|
|
static void hsl2rgb(uint16_t hue, float saturation, float luminance, uint8_t & red, uint8_t & green, uint8_t & blue);
|
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);
|
2020-08-08 13:22:37 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// Translates a YUV (luminance, chrominance, chrominance) color to an RGB (red, green, blue) color
|
|
|
|
///
|
|
|
|
/// @param[in] y The luminance YUV-component
|
|
|
|
/// @param[in] u The chrominance YUV-component
|
|
|
|
/// @param[in] v The chrominance YUV-component
|
|
|
|
/// @param[out] red The red RGB-component
|
|
|
|
/// @param[out] green The green RGB-component
|
|
|
|
/// @param[out] blue The blue RGB-component
|
|
|
|
static void yuv2rgb(uint8_t y, uint8_t u, uint8_t v, uint8_t & r, uint8_t & g, uint8_t & b);
|
2013-08-23 18:24:10 +02:00
|
|
|
};
|