COGS
Computer Graphics Structures library
Color.h
1 #ifndef COGS_COLOR_H
2 #define COGS_COLOR_H
3 #include <vector>
4 #include <functional>
5 
6 #include <glm/common.hpp>
7 
8 #include <COGS/API.h>
9 
10 
11 namespace cogs
12 {
13  struct Color3b;
14  struct Color4b;
15  struct Color3f;
16  struct Color4f;
17  struct Color3hex;
18  struct Color4hex;
19 
21  struct COGS_API Color3b
22  {
23  uint8_t r = 0, g = 0, b = 0;
24  Color3b() = default;
25  Color3b(uint8_t red, uint8_t green, uint8_t blue);
26  Color3b(const Color4b &col);
27  Color3b(const Color3f &col);
28  Color3b(const Color4f &col);
29  Color3b(const Color3hex &col);
30  Color3b(const Color4hex &col);
31  Color3b operator+(const Color3b &col) const;
32  Color3b &operator+=(const Color3b &col);
33  uint8_t *GetPtr();
34  const uint8_t *GetPtr() const;
35  Color3b Mix(const Color3b &col, float weight) const;
36  };
37 
39  struct COGS_API Color4b
40  {
41  uint8_t r = 0, g = 0, b = 0, a = 255;
42  Color4b() = default;
43  Color4b(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha);
44  Color4b(const Color3b &col);
45  Color4b(const Color3f &col);
46  Color4b(const Color4f &col);
47  Color4b(const Color3hex &col);
48  Color4b(const Color4hex &col);
49  Color4b operator+(const Color4b &col) const;
50  Color4b &operator+=(const Color4b &col);
51  uint8_t *GetPtr();
52  const uint8_t *GetPtr() const;
53  Color4b Mix(const Color4b &col, float weight) const;
54  };
55 
57  struct COGS_API Color3f
58  {
59  float r = 0.0f, g = 0.0f, b = 0.0f;
60  Color3f() = default;
61  Color3f(float red, float green, float blue);
62  Color3f(const Color3b &col);
63  Color3f(const Color4b &col);
64  Color3f(const Color4f &col);
65  Color3f(const Color3hex &col);
66  Color3f(const Color4hex &col);
67  float *GetPtr();
68  const float *GetPtr() const;
69  Color3f operator+(const Color3f &col) const;
70  Color3f &operator+=(const Color3f &col);
71  Color3f &operator*=(float multiplier);
72  cogs::Color3f Mix(const Color3f &col, float weight) const;
73  };
74 
76  struct COGS_API Color4f
77  {
78  float r = 0.0f, g = 0.0f, b = 0.0f, a = 1.0f;
79  Color4f() = default;
80  Color4f(float red, float green, float blue, float alpha);
81  Color4f(const Color3b &col);
82  Color4f(const Color4b &col);
83  Color4f(const Color3f &col);
84  Color4f(const Color3f &col, float alpha);
85  Color4f(const Color3hex &col);
86  Color4f(const Color4hex &col);
87  float *GetPtr();
88  const float *GetPtr() const;
89  Color4f operator+(const Color4f &col) const;
90  Color4f &operator+=(const Color4f &col);
91  Color4f &operator*=(float multiplier);
92  Color4f Mix(const Color4f &col, float weight) const;
93  };
94 
96  struct COGS_API Color3hex
97  {
98  Color3hex() = default;
99  Color3hex(const char *hex_color);
100  Color3hex &operator=(const char *hex_color);
101  Color3hex(const Color3hex &col);
102  Color3hex &operator =(const Color3hex &col);
103  explicit Color3hex(const Color3b &col);
104  explicit Color3hex(const Color3f &col);
105  explicit Color3hex(const Color4b &col);
106  explicit Color3hex(const Color4f &col);
107  explicit Color3hex(const Color4hex &col);
108  const char *GetPtr() const;
109 
110  private:
111  char hex[7] = "000000";
112  };
113 
115  struct COGS_API Color4hex
116  {
117  Color4hex() = default;
118  Color4hex(const char *hex_color);
119  Color4hex &operator=(const char *hex_color);
120  Color4hex(const Color4hex &col);
121  Color4hex &operator =(const Color4hex &col);
122  explicit Color4hex(const Color3b &col);
123  explicit Color4hex(const Color3f &col);
124  explicit Color4hex(const Color4b &col);
125  explicit Color4hex(const Color4f &col);
126  explicit Color4hex(const Color3hex &col);
127  const char *GetPtr() const;
128  private:
129  char hex[9] = "000000FF";
130  };
131 
132  COGS_API bool operator ==(const Color3b &a, const Color3b &b);
133  COGS_API bool operator ==(const Color4b &a, const Color4b &b);
134  COGS_API bool operator ==(const Color3f &a, const Color3f &b);
135  COGS_API bool operator ==(const Color4f &a, const Color4f &b);
136  COGS_API bool operator ==(const Color3hex &a, const Color3hex &b);
137  COGS_API bool operator ==(const Color4hex &a, const Color4hex &b);
138 
139  COGS_API bool operator !=(const Color3b &a, const Color3b &b);
140  COGS_API bool operator !=(const Color4b &a, const Color4b &b);
141  COGS_API bool operator !=(const Color3f &a, const Color3f &b);
142  COGS_API bool operator !=(const Color4f &a, const Color4f &b);
143  COGS_API bool operator !=(const Color3hex &a, const Color3hex &b);
144  COGS_API bool operator !=(const Color4hex &a, const Color4hex &b);
145 
146  COGS_API Color3f operator* (const float factor, const Color3f &col);
147  COGS_API Color3f operator* (const Color3f &col, const float factor);
148  COGS_API Color4f operator* (const float factor, const Color4f &col);
149  COGS_API Color4f operator* (const Color4f &col, const float factor);
150 
151  COGS_API Color3f Interpolate(const Color3f &col1, const Color3f &col2, float weight);
152 
154  enum class ColorMap
155  {
157  rainbow = 0,
159  thermal = 1,
161  blue_red = 2,
163  red_green = 3,
165  scattered = 4,
167  grayscale = 5,
169  colorful = 6,
171  colorful_bright = 7
172  };
173 
175  COGS_API std::string ColorMapToString(ColorMap map);
176 
178  COGS_API cogs::Color3f MapValueToColor(float value, ColorMap mapping_func);
179 
181  COGS_API std::vector<cogs::Color3f> MapValuesToColors(const std::vector<float> &values, ColorMap mapping_func);
182 
184  COGS_API std::vector<cogs::Color3f> MapValuesToColors(const std::vector<float> &values, std::function<float(float)> process_func, ColorMap mapping_func);
185 
186 
187 
189  namespace color
190  {
191  const Color3f WHITE = Color3b(255, 255, 255);
192  const Color3f GRAY = Color3b(128, 128, 128);
193  const Color3f BLACK = Color3b(0, 0, 0);
194 
196  const Color3f GRAY90 = Color3b(230, 230, 230);
198  const Color3f GRAY80 = Color3b(204, 204, 204);
200  const Color3f GRAY70 = Color3b(179, 179, 179);
202  const Color3f GRAY60 = Color3b(153, 153, 153);
204  const Color3f GRAY50 = Color3b(128, 128, 128);
206  const Color3f GRAY40 = Color3b(102, 102, 102);
208  const Color3f GRAY30 = Color3b(77, 77, 77);
210  const Color3f GRAY20 = Color3b(51, 51, 51);
212  const Color3f GRAY10 = Color3b(26, 26, 26);
213 
215  const Color3f RED = Color3b(255, 0, 0);
217  const Color3f GREEN = Color3b(0, 255, 0);
219  const Color3f BLUE = Color3b(0, 0, 255);
220 
222  const Color3f CRIMSON = Color3b(214, 44, 54);
223  const Color3f ORANGE = Color3b(242, 172, 41);
224  const Color3f YELLOW = Color3b(252, 223, 78);
226  const Color3f FOREST = Color3b(31, 140, 69);
228  const Color3f LIME = Color3b(83, 252, 20);
230  const Color3f EMERALD = Color3b(80, 220, 100);
232  const Color3f CYAN = Color3b(0, 245, 255);
234  const Color3f SKY = Color3b(5, 157, 255);
236  const Color3f NAVY = Color3b(4, 59, 106);
237  const Color3f PURPLE = Color3b(148, 14, 112);
239  const Color3f MAGENTA = Color3b(211, 19, 90);
240  const Color3f SALMON = Color3b(250, 128, 114);
241  const Color3f PINK = Color3b(242, 131, 166);
242  const Color3f GOLD = Color3b(255, 215, 0);
243  const Color3f CREAM_WHITE = Color3b(255, 252, 209);
244 
246  const Color3f STX_NAVY = Color3b(34, 83, 120);
248  const Color3f STX_GREEN = Color3b(23, 150, 164);
250  const Color3f STX_LIME = Color3b(85, 203, 199);
252  const Color3f STX_VANILLA = Color3b(243, 255, 226);
254  const Color3f STX_ORANGE = Color3b(255, 150, 73);
255  }
256 }
257 
258 #endif /* !COGS_COLOR_H */
Namespace of "Computer Graphic Structures" library, which implement many core classes and structures...
Definition: AabbHierarchy.h:8
Holds three color channels in float format in range 0-1.
Definition: Color.h:57
const Color3f EMERALD
blueish green
Definition: Color.h:230
blue > magenta > red
const Color3f STX_VANILLA
Skeletex bright yellow.
Definition: Color.h:252
const Color3f GREEN
pure green - 0 255 0
Definition: Color.h:217
const Color3f NAVY
dark blue
Definition: Color.h:236
COGS_API std::string ColorMapToString(ColorMap map)
Returns string representation of ColorMap enum value.
const Color3f STX_GREEN
Skeletex darker green.
Definition: Color.h:248
Holds three color channels in uint8 format in range 0-255.
Definition: Color.h:21
const Color3f MAGENTA
pinkish red
Definition: Color.h:239
const Color3f GRAY60
60% lightness
Definition: Color.h:202
const Color3f BLUE
pure blue - 0 0 255
Definition: Color.h:219
const Color3f CYAN
greenish blue
Definition: Color.h:232
const Color3f FOREST
darker green
Definition: Color.h:226
Holds four color channels in float format in range 0-1.
Definition: Color.h:76
const Color3f LIME
bright green
Definition: Color.h:228
ColorMap
Color mapping options.
Definition: Color.h:154
Holds three color channels in hexadecimal string representation.
Definition: Color.h:96
Holds four color channels in hexadecimal string representation.
Definition: Color.h:115
blue > cyan > green > yellow > red > purple
const Color3f GRAY80
80% lightness
Definition: Color.h:198
const Color3f SKY
nicer pure blue
Definition: Color.h:234
const Color3f STX_NAVY
Skeletex dark blue.
Definition: Color.h:246
const Color3f STX_LIME
Skeletex light green.
Definition: Color.h:250
const Color3f GRAY20
20% lightness
Definition: Color.h:210
Holds four color channels in uint8 format in range 0-255.
Definition: Color.h:39
const Color3f CRIMSON
nicer pure red
Definition: Color.h:222
const Color3f GRAY70
70% lightness
Definition: Color.h:200
COGS_API std::vector< cogs::Color3f > MapValuesToColors(const std::vector< float > &values, ColorMap mapping_func)
Converts float values in range <0.0, 1.0> to colors, depending on selected mapping function...
pseudo-random values
const Color3f GRAY50
50% lightness
Definition: Color.h:204
const Color3f GRAY40
40% lightness
Definition: Color.h:206
const Color3f RED
pure red - 255 0 0
Definition: Color.h:215
const Color3f STX_ORANGE
Skeletex orange.
Definition: Color.h:254
const Color3f GRAY30
30% lightness
Definition: Color.h:208
COGS_API cogs::Color3f MapValueToColor(float value, ColorMap mapping_func)
Converts float value in range <0.0, 1.0> to color, depending on selected mapping function.
bluish tones > green > redish tones
const Color3f GRAY10
10% lightness - darkest of grays
Definition: Color.h:212
const Color3f GRAY90
90% lightness -lightest of grays
Definition: Color.h:196
red > yellow > green