Color.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #ifndef COLOR_H
  2. #define COLOR_H
  3. #include <string>
  4. namespace Color {
  5. class Color
  6. {
  7. public:
  8. Color() = default;
  9. public:
  10. static Color FromHSL(int hue, int saturation, int luminance);
  11. static Color FromHSLString(const std::string& hslString);
  12. static Color FromRGB(int red, int green, int blue);
  13. static Color FromRGBString(const std::string& rgbString);
  14. public:
  15. int Hue() const;
  16. void Hue(int hue);
  17. void Hue(double hue);
  18. int Saturation() const;
  19. void Saturation(int saturation);
  20. void Saturation(double saturation);
  21. int Luminance() const;
  22. void Luminance(int luminance);
  23. void Luminance(double luminance);
  24. std::string HSLString() const;
  25. int Red() const;
  26. void Red(int red);
  27. void Red(double red);
  28. int Green() const;
  29. void Green(int green);
  30. void Green(double green);
  31. int Blue() const;
  32. void Blue(int blue);
  33. void Blue(double blue);
  34. std::string RGBString() const;
  35. private:
  36. struct HSL
  37. {
  38. double hue;
  39. double saturation;
  40. double luminance;
  41. };
  42. struct RGB
  43. {
  44. double red;
  45. double green;
  46. double blue;
  47. };
  48. class Conversion
  49. {
  50. public:
  51. Conversion() = delete;
  52. ~Conversion() = delete;
  53. public:
  54. static double Hue(int hue);
  55. static int Hue(double hue);
  56. static int Hue(const std::string& hue);
  57. static double Saturation(int saturation);
  58. static int Saturation(double saturation);
  59. static int Saturation(const std::string& saturation);
  60. static double Luminance(int luminance);
  61. static int Luminance(double luminance);
  62. static int Luminance(const std::string& luminance);
  63. static double Red(int red);
  64. static int Red(double red);
  65. static int Red(const std::string& red);
  66. static double Green(int green);
  67. static int Green(double green);
  68. static int Green(const std::string& green);
  69. static double Blue(int blue);
  70. static int Blue(double blue);
  71. static int Blue(const std::string& blue);
  72. private:
  73. static const int m_hueFactor = 255;
  74. static const int m_saturationFactor = 255;
  75. static const int m_luminanceFactor = 255;
  76. static const int m_redFactor = 255;
  77. static const int m_greenFactor = 255;
  78. static const int m_blueFactor = 255;
  79. };
  80. private:
  81. Color(const Color::HSL& hsl);
  82. Color(const Color::RGB& rgb);
  83. private:
  84. static Color::HSL rgbToHSL(const Color::RGB& rgb);
  85. static Color::RGB hslToRGB(const Color::HSL& hsl);
  86. private:
  87. HSL m_hsl;
  88. };
  89. } // namespace Color
  90. #endif // COLOR_H