109 lines
2.3 KiB
C++
109 lines
2.3 KiB
C++
#ifndef COLOR_H
|
|
#define COLOR_H
|
|
|
|
#include <string>
|
|
|
|
|
|
namespace Color {
|
|
|
|
class Color
|
|
{
|
|
public:
|
|
Color() = default;
|
|
|
|
public:
|
|
static Color FromHSL(int hue, int saturation, int luminance);
|
|
static Color FromHSLString(const std::string& hslString);
|
|
static Color FromRGB(int red, int green, int blue);
|
|
static Color FromRGBString(const std::string& rgbString);
|
|
|
|
public:
|
|
int Hue() const;
|
|
void Hue(int hue);
|
|
void Hue(double hue);
|
|
int Saturation() const;
|
|
void Saturation(int saturation);
|
|
void Saturation(double saturation);
|
|
int Luminance() const;
|
|
void Luminance(int luminance);
|
|
void Luminance(double luminance);
|
|
std::string HSLString() const;
|
|
|
|
int Red() const;
|
|
void Red(int red);
|
|
void Red(double red);
|
|
int Green() const;
|
|
void Green(int green);
|
|
void Green(double green);
|
|
int Blue() const;
|
|
void Blue(int blue);
|
|
void Blue(double blue);
|
|
std::string RGBString() const;
|
|
|
|
private:
|
|
struct HSL
|
|
{
|
|
double hue;
|
|
double saturation;
|
|
double luminance;
|
|
};
|
|
|
|
struct RGB
|
|
{
|
|
double red;
|
|
double green;
|
|
double blue;
|
|
};
|
|
|
|
class Conversion
|
|
{
|
|
public:
|
|
Conversion() = delete;
|
|
~Conversion() = delete;
|
|
|
|
public:
|
|
static double Hue(int hue);
|
|
static int Hue(double hue);
|
|
static int Hue(const std::string& hue);
|
|
static double Saturation(int saturation);
|
|
static int Saturation(double saturation);
|
|
static int Saturation(const std::string& saturation);
|
|
static double Luminance(int luminance);
|
|
static int Luminance(double luminance);
|
|
static int Luminance(const std::string& luminance);
|
|
|
|
static double Red(int red);
|
|
static int Red(double red);
|
|
static int Red(const std::string& red);
|
|
static double Green(int green);
|
|
static int Green(double green);
|
|
static int Green(const std::string& green);
|
|
static double Blue(int blue);
|
|
static int Blue(double blue);
|
|
static int Blue(const std::string& blue);
|
|
|
|
private:
|
|
static const int m_hueFactor = 255;
|
|
static const int m_saturationFactor = 255;
|
|
static const int m_luminanceFactor = 255;
|
|
static const int m_redFactor = 255;
|
|
static const int m_greenFactor = 255;
|
|
static const int m_blueFactor = 255;
|
|
};
|
|
|
|
private:
|
|
Color(const Color::HSL& hsl);
|
|
Color(const Color::RGB& rgb);
|
|
|
|
private:
|
|
static Color::HSL rgbToHSL(const Color::RGB& rgb);
|
|
static Color::RGB hslToRGB(const Color::HSL& hsl);
|
|
|
|
private:
|
|
HSL m_hsl;
|
|
};
|
|
|
|
} // namespace Color
|
|
|
|
#endif // COLOR_H
|