pixled-lib  1.0
color.h
1 #ifndef PIXLED_PIXEL_H
2 #define PIXLED_PIXEL_H
3 
4 #include <iostream>
5 
6 namespace pixled {
10  class color {
11  private:
12  struct rgb_t {
13  int r;
14  int g;
15  int b;
16  };
17  rgb_t _rgb;
18 
19  struct hsb_t {
20  float h;
21  float s;
22  float b;
23  };
24  hsb_t _hsb;
25 
26  static void rgb_to_hsb(const rgb_t& rgb, hsb_t& hsb);
27  static void hsb_to_rgb(const hsb_t& hsb, rgb_t& rgb);
28 
29  public:
33  uint8_t red() const {return _rgb.r;}
37  uint8_t green() const {return _rgb.g;}
41  uint8_t blue() const {return _rgb.b;}
42 
46  float hue() const {return _hsb.h;}
50  float saturation() const {return _hsb.s;}
54  float brightness() const {return _hsb.b;}
55 
63  color& setRgb(uint8_t r, uint8_t g, uint8_t b);
69  color& setRed(uint8_t r);
75  color& setGreen(uint8_t g);
81  color& setBlue(uint8_t b);
82 
90  color& setHsb(float h, float s, float b);
96  color& setHue(float h);
102  color& setSaturation(float s);
108  color& setBrightness(float b);
109 
118  static color rgb(uint8_t r, uint8_t g, uint8_t b);
127  static color hsb(float h, float s, float b);
128  };
129 
136  bool operator==(const color& c1, const color& c2);
137 }
138 #endif
Definition: chroma.h:25
Definition: chroma.h:46
Definition: color.h:10
color & setHsb(float h, float s, float b)
Definition: color.cpp:143
color & setBlue(uint8_t b)
Definition: color.cpp:137
float brightness() const
Definition: color.h:54
uint8_t blue() const
Definition: color.h:41
uint8_t red() const
Definition: color.h:33
color & setBrightness(float b)
Definition: color.cpp:163
color & setHue(float h)
Definition: color.cpp:151
static color rgb(uint8_t r, uint8_t g, uint8_t b)
Definition: color.cpp:169
static color hsb(float h, float s, float b)
Definition: color.cpp:175
float saturation() const
Definition: color.h:50
color & setSaturation(float s)
Definition: color.cpp:157
color & setRed(uint8_t r)
Definition: color.cpp:125
float hue() const
Definition: color.h:46
color & setGreen(uint8_t g)
Definition: color.cpp:131
color & setRgb(uint8_t r, uint8_t g, uint8_t b)
Definition: color.cpp:117
uint8_t green() const
Definition: color.h:37
Definition: animation.cpp:3
bool operator==(const color &c1, const color &c2)
Definition: color.cpp:181