Plasma Engine  2.0
Loading...
Searching...
No Matches
Color.h
1#pragma once
2
3#include <Foundation/Math/Math.h>
4#include <Foundation/Math/Vec4.h>
5
43class PL_FOUNDATION_DLL plColor
44{
45public:
46 PL_DECLARE_POD_TYPE();
47
48 // *** Predefined Colors ***
49public:
50 static const plColor AliceBlue;
51 static const plColor AntiqueWhite;
52 static const plColor Aqua;
53 static const plColor Aquamarine;
54 static const plColor Azure;
55 static const plColor Beige;
56 static const plColor Bisque;
57 static const plColor Black;
58 static const plColor BlanchedAlmond;
59 static const plColor Blue;
60 static const plColor BlueViolet;
61 static const plColor Brown;
62 static const plColor BurlyWood;
63 static const plColor CadetBlue;
64 static const plColor Chartreuse;
65 static const plColor Chocolate;
66 static const plColor Coral;
67 static const plColor CornflowerBlue;
68 static const plColor Cornsilk;
69 static const plColor Crimson;
70 static const plColor Cyan;
71 static const plColor DarkBlue;
72 static const plColor DarkCyan;
73 static const plColor DarkGoldenRod;
74 static const plColor DarkGray;
75 static const plColor DarkGrey;
76 static const plColor DarkGreen;
77 static const plColor DarkKhaki;
78 static const plColor DarkMagenta;
79 static const plColor DarkOliveGreen;
80 static const plColor DarkOrange;
81 static const plColor DarkOrchid;
82 static const plColor DarkRed;
83 static const plColor DarkSalmon;
84 static const plColor DarkSeaGreen;
85 static const plColor DarkSlateBlue;
86 static const plColor DarkSlateGray;
87 static const plColor DarkSlateGrey;
88 static const plColor DarkTurquoise;
89 static const plColor DarkViolet;
90 static const plColor DeepPink;
91 static const plColor DeepSkyBlue;
92 static const plColor DimGray;
93 static const plColor DimGrey;
94 static const plColor DodgerBlue;
95 static const plColor FireBrick;
96 static const plColor FloralWhite;
97 static const plColor ForestGreen;
98 static const plColor Fuchsia;
99 static const plColor Gainsboro;
100 static const plColor GhostWhite;
101 static const plColor Gold;
102 static const plColor GoldenRod;
103 static const plColor Gray;
104 static const plColor Grey;
105 static const plColor Green;
106 static const plColor GreenYellow;
107 static const plColor HoneyDew;
108 static const plColor HotPink;
109 static const plColor IndianRed;
110 static const plColor Indigo;
111 static const plColor Ivory;
112 static const plColor Khaki;
113 static const plColor Lavender;
114 static const plColor LavenderBlush;
115 static const plColor LawnGreen;
116 static const plColor LemonChiffon;
117 static const plColor LightBlue;
118 static const plColor LightCoral;
119 static const plColor LightCyan;
121 static const plColor LightGray;
122 static const plColor LightGrey;
123 static const plColor LightGreen;
124 static const plColor LightPink;
125 static const plColor LightSalmon;
126 static const plColor LightSeaGreen;
127 static const plColor LightSkyBlue;
128 static const plColor LightSlateGray;
129 static const plColor LightSlateGrey;
130 static const plColor LightSteelBlue;
131 static const plColor LightYellow;
132 static const plColor Lime;
133 static const plColor LimeGreen;
134 static const plColor Linen;
135 static const plColor Magenta;
136 static const plColor Maroon;
138 static const plColor MediumBlue;
139 static const plColor MediumOrchid;
140 static const plColor MediumPurple;
141 static const plColor MediumSeaGreen;
146 static const plColor MidnightBlue;
147 static const plColor MintCream;
148 static const plColor MistyRose;
149 static const plColor Moccasin;
150 static const plColor NavajoWhite;
151 static const plColor Navy;
152 static const plColor OldLace;
153 static const plColor Olive;
154 static const plColor OliveDrab;
155 static const plColor Orange;
156 static const plColor OrangeRed;
157 static const plColor Orchid;
158 static const plColor PaleGoldenRod;
159 static const plColor PaleGreen;
160 static const plColor PaleTurquoise;
161 static const plColor PaleVioletRed;
162 static const plColor PapayaWhip;
163 static const plColor PeachPuff;
164 static const plColor Peru;
165 static const plColor Pink;
166 static const plColor Plum;
167 static const plColor PowderBlue;
168 static const plColor Purple;
169 static const plColor RebeccaPurple;
170 static const plColor Red;
171 static const plColor RosyBrown;
172 static const plColor RoyalBlue;
173 static const plColor SaddleBrown;
174 static const plColor Salmon;
175 static const plColor SandyBrown;
176 static const plColor SeaGreen;
177 static const plColor SeaShell;
178 static const plColor Sienna;
179 static const plColor Silver;
180 static const plColor SkyBlue;
181 static const plColor SlateBlue;
182 static const plColor SlateGray;
183 static const plColor SlateGrey;
184 static const plColor Snow;
185 static const plColor SpringGreen;
186 static const plColor SteelBlue;
187 static const plColor Tan;
188 static const plColor Teal;
189 static const plColor Thistle;
190 static const plColor Tomato;
191 static const plColor Turquoise;
192 static const plColor Violet;
193 static const plColor Wheat;
194 static const plColor White;
195 static const plColor WhiteSmoke;
196 static const plColor Yellow;
197 static const plColor YellowGreen;
198
199 // *** Data ***
200public:
201 float r;
202 float g;
203 float b;
204 float a;
205
206 // *** Static Functions ***
207public:
209 [[nodiscard]] static plColor MakeNaN();
210
212 [[nodiscard]] static plColor MakeZero();
213
215 [[nodiscard]] static plColor MakeRGBA(float fLinearRed, float fLinearGreen, float fLinearBlue, float fLinearAlpha = 1.0f);
216
217 // *** Constructors ***
218public:
220 plColor(); // [tested]
221
226 constexpr plColor(float fLinearRed, float fLinearGreen, float fLinearBlue, float fLinearAlpha = 1.0f); // [tested]
227
231 plColor(const plColorLinearUB& cc); // [tested]
232
236 plColor(const plColorGammaUB& cc); // [tested]
237
238#if PL_ENABLED(PL_MATH_CHECK_FOR_NAN)
239 void AssertNotNaN() const
240 {
241 PL_ASSERT_ALWAYS(!IsNaN(), "This object contains NaN values. This can happen when you forgot to initialize it before using it. Please check that "
242 "all code-paths properly initialize this object.");
243 }
244#endif
245
247 void SetRGB(float fLinearRed, float fLinearGreen, float fLinearBlue); // [tested]
248
250 void SetRGBA(float fLinearRed, float fLinearGreen, float fLinearBlue, float fLinearAlpha = 1.0f); // [tested]
251
252 // *** Conversion Operators/Functions ***
253public:
258 static plColor MakeFromKelvin(plUInt32 uiKelvin);
259
263 [[nodiscard]] static plColor MakeHSV(float fHue, float fSat, float fVal); // [tested]
264
268 void GetHSV(float& out_fHue, float& out_fSat, float& out_fValue) const; // [tested]
269
271 const float* GetData() const { return &r; }
272
274 float* GetData() { return &r; }
275
277 const plVec4 GetAsVec4() const;
278
280 static float GammaToLinear(float fGamma); // [tested]
282 static float LinearToGamma(float fGamma); // [tested]
283
285 static plVec3 GammaToLinear(const plVec3& vGamma); // [tested]
287 static plVec3 LinearToGamma(const plVec3& vGamma); // [tested]
288
289 // *** Color specific functions ***
290public:
292 bool IsNormalized() const; // [tested]
293
295 float CalcAverageRGB() const;
296
298 float GetSaturation() const; // [tested]
299
301 float GetLuminance() const;
302
307 plColor GetInvertedColor() const; // [tested]
308
310 plColor GetComplementaryColor() const; // [tested]
311
313 void ScaleRGB(float fFactor);
314
316 void ScaleRGBA(float fFactor);
317
319 float ComputeHdrMultiplier() const;
320
323 float ComputeHdrExposureValue() const;
324
326 void ApplyHdrExposureValue(float fEv);
327
329 void NormalizeToLdrRange();
330
332 plColor GetDarker(float fFactor = 2.0f) const;
333
334 // *** Numeric properties ***
335public:
337 bool IsNaN() const; // [tested]
338
340 bool IsValid() const; // [tested]
341
342 // *** Operators ***
343public:
345 void operator=(const plColorLinearUB& cc); // [tested]
346
348 void operator=(const plColorGammaUB& cc); // [tested]
349
351 void operator+=(const plColor& rhs); // [tested]
352
354 void operator-=(const plColor& rhs); // [tested]
355
357 void operator*=(const plColor& rhs); // [tested]
358
360 void operator*=(float f); // [tested]
361
363 void operator/=(float f); // [tested]
364
369 void operator*=(const plMat4& rhs); // [tested]
370
372 bool IsIdenticalRGB(const plColor& rhs) const; // [tested]
373
375 bool IsIdenticalRGBA(const plColor& rhs) const; // [tested]
376
378 bool IsEqualRGB(const plColor& rhs, float fEpsilon) const; // [tested]
379
381 bool IsEqualRGBA(const plColor& rhs, float fEpsilon) const; // [tested]
382
384 plColor WithAlpha(float fAlpha) const;
385
387 [[nodiscard]] plUInt32 ToRGBA8() const;
388
390 [[nodiscard]] plUInt32 ToABGR8() const;
391};
392
393// *** Operators ***
394
396const plColor operator+(const plColor& c1, const plColor& c2); // [tested]
397
399const plColor operator-(const plColor& c1, const plColor& c2); // [tested]
400
402const plColor operator*(const plColor& c1, const plColor& c2); // [tested]
403
405const plColor operator*(float f, const plColor& c); // [tested]
406
408const plColor operator*(const plColor& c, float f); // [tested]
409
411const plColor operator/(const plColor& c, float f); // [tested]
412
417const plColor operator*(const plMat4& lhs, const plColor& rhs); // [tested]
418
420bool operator==(const plColor& c1, const plColor& c2); // [tested]
421
423bool operator!=(const plColor& c1, const plColor& c2); // [tested]
424
426bool operator<(const plColor& c1, const plColor& c2); // [tested]
427
428static_assert(sizeof(plColor) == 16);
429
430#include <Foundation/Math/Implementation/Color_inl.h>
A 8bit per channel unsigned normalized (values interpreted as 0-1) color storage format that represen...
Definition Color8UNorm.h:99
plColor represents an RGBA color in linear color space. Values are stored as float,...
Definition Color.h:44
static const plColor Orchid
#DA70D6
Definition Color.h:157
static const plColor LightSeaGreen
#20B2AA
Definition Color.h:126
static const plColor SlateGray
#708090
Definition Color.h:182
static const plColor MediumOrchid
#BA55D3
Definition Color.h:139
static const plColor CadetBlue
#5F9EA0
Definition Color.h:63
static const plColor White
#FFFFFF
Definition Color.h:194
static const plColor DarkOrchid
#9932CC
Definition Color.h:81
static const plColor RebeccaPurple
#663399
Definition Color.h:169
static const plColor PaleTurquoise
#AFEEEE
Definition Color.h:160
static const plColor SlateGrey
#708090
Definition Color.h:183
static const plColor DarkKhaki
#BDB76B
Definition Color.h:77
const float * GetData() const
Conversion to const float*.
Definition Color.h:271
static const plColor Grey
#808080
Definition Color.h:104
static const plColor DarkSlateGrey
#2F4F4F
Definition Color.h:87
static const plColor CornflowerBlue
#6495ED The original!
Definition Color.h:67
static const plColor Gainsboro
#DCDCDC
Definition Color.h:99
static const plColor DarkGreen
#006400
Definition Color.h:76
static const plColor DarkMagenta
#8B008B
Definition Color.h:78
static const plColor Beige
#F5F5DC
Definition Color.h:55
static const plColor RoyalBlue
#4169E1
Definition Color.h:172
static const plColor IndianRed
#CD5C5C
Definition Color.h:109
static const plColor AliceBlue
#F0F8FF
Definition Color.h:50
static const plColor Blue
#0000FF
Definition Color.h:59
static const plColor SeaShell
#FFF5EE
Definition Color.h:177
static const plColor GoldenRod
#DAA520
Definition Color.h:102
static const plColor DarkGray
#A9A9A9
Definition Color.h:74
static const plColor MediumSeaGreen
#3CB371
Definition Color.h:141
static const plColor MistyRose
#FFE4E1
Definition Color.h:148
static const plColor LightSteelBlue
#B0C4DE
Definition Color.h:130
static const plColor Salmon
#FA8072
Definition Color.h:174
static const plColor SeaGreen
#2E8B57
Definition Color.h:176
static const plColor Cyan
#00FFFF
Definition Color.h:70
static const plColor MediumAquaMarine
#66CDAA
Definition Color.h:137
static const plColor LightGreen
#90EE90
Definition Color.h:123
static const plColor LightSalmon
#FFA07A
Definition Color.h:125
static const plColor SpringGreen
#00FF7F
Definition Color.h:185
static const plColor Coral
#FF7F50
Definition Color.h:66
static const plColor DarkSlateGray
#2F4F4F
Definition Color.h:86
static const plColor MediumBlue
#0000CD
Definition Color.h:138
static const plColor Black
#000000
Definition Color.h:57
static const plColor Peru
#CD853F
Definition Color.h:164
static const plColor Navy
#000080
Definition Color.h:151
static const plColor BlueViolet
#8A2BE2
Definition Color.h:60
static const plColor ForestGreen
#228B22
Definition Color.h:97
static const plColor BurlyWood
#DEB887
Definition Color.h:62
static const plColor PapayaWhip
#FFEFD5
Definition Color.h:162
static const plColor DeepSkyBlue
#00BFFF
Definition Color.h:91
static const plColor SlateBlue
#6A5ACD
Definition Color.h:181
static const plColor LightGrey
#D3D3D3
Definition Color.h:122
static const plColor PowderBlue
#B0E0E6
Definition Color.h:167
static const plColor LightSkyBlue
#87CEFA
Definition Color.h:127
static const plColor DarkGrey
#A9A9A9
Definition Color.h:75
static const plColor Snow
#FFFAFA
Definition Color.h:184
static const plColor Wheat
#F5DEB3
Definition Color.h:193
static const plColor GhostWhite
#F8F8FF
Definition Color.h:100
static const plColor Lavender
#E6E6FA
Definition Color.h:113
static const plColor Maroon
#800000
Definition Color.h:136
static const plColor Moccasin
#FFE4B5
Definition Color.h:149
static const plColor LightGray
#D3D3D3
Definition Color.h:121
static const plColor PaleGreen
#98FB98
Definition Color.h:159
static const plColor DimGray
#696969
Definition Color.h:92
static const plColor Brown
#A52A2A
Definition Color.h:61
static const plColor DarkTurquoise
#00CED1
Definition Color.h:88
static const plColor FloralWhite
#FFFAF0
Definition Color.h:96
static const plColor Chartreuse
#7FFF00
Definition Color.h:64
static const plColor Aqua
#00FFFF
Definition Color.h:52
static const plColor MediumSpringGreen
#00FA9A
Definition Color.h:143
static const plColor PaleGoldenRod
#EEE8AA
Definition Color.h:158
static const plColor MediumTurquoise
#48D1CC
Definition Color.h:144
static const plColor Tan
#D2B48C
Definition Color.h:187
static const plColor DarkGoldenRod
#B8860B
Definition Color.h:73
static const plColor DarkSeaGreen
#8FBC8F
Definition Color.h:84
static const plColor DimGrey
#696969
Definition Color.h:93
float * GetData()
Conversion to float*.
Definition Color.h:274
static const plColor FireBrick
#B22222
Definition Color.h:95
static const plColor WhiteSmoke
#F5F5F5
Definition Color.h:195
static const plColor LightSlateGray
#778899
Definition Color.h:128
static const plColor LightBlue
#ADD8E6
Definition Color.h:117
static const plColor LightSlateGrey
#778899
Definition Color.h:129
static const plColor GreenYellow
#ADFF2F
Definition Color.h:106
static const plColor AntiqueWhite
#FAEBD7
Definition Color.h:51
static const plColor Azure
#F0FFFF
Definition Color.h:54
static const plColor LightPink
#FFB6C1
Definition Color.h:124
static const plColor Gold
#FFD700
Definition Color.h:101
static const plColor Violet
#EE82EE
Definition Color.h:192
static const plColor Gray
#808080
Definition Color.h:103
static const plColor Linen
#FAF0E6
Definition Color.h:134
static const plColor Bisque
#FFE4C4
Definition Color.h:56
static const plColor Purple
#800080
Definition Color.h:168
static const plColor DarkRed
#8B0000
Definition Color.h:82
static const plColor DarkSlateBlue
#483D8B
Definition Color.h:85
static const plColor MidnightBlue
#191970
Definition Color.h:146
static const plColor Magenta
#FF00FF
Definition Color.h:135
static const plColor Thistle
#D8BFD8
Definition Color.h:189
static const plColor Teal
#008080
Definition Color.h:188
static const plColor PaleVioletRed
#DB7093
Definition Color.h:161
static const plColor LightCyan
#E0FFFF
Definition Color.h:119
static const plColor LemonChiffon
#FFFACD
Definition Color.h:116
static const plColor LightYellow
#FFFFE0
Definition Color.h:131
static const plColor SkyBlue
#87CEEB
Definition Color.h:180
static const plColor HoneyDew
#F0FFF0
Definition Color.h:107
static const plColor Red
#FF0000
Definition Color.h:170
static const plColor MintCream
#F5FFFA
Definition Color.h:147
static const plColor Green
#008000
Definition Color.h:105
static const plColor DarkOrange
#FF8C00
Definition Color.h:80
static const plColor Cornsilk
#FFF8DC
Definition Color.h:68
static const plColor MediumVioletRed
#C71585
Definition Color.h:145
static const plColor DarkOliveGreen
#556B2F
Definition Color.h:79
static const plColor LimeGreen
#32CD32
Definition Color.h:133
static const plColor DodgerBlue
#1E90FF
Definition Color.h:94
static const plColor Khaki
#F0E68C
Definition Color.h:112
static const plColor Olive
#808000
Definition Color.h:153
static const plColor Indigo
#4B0082
Definition Color.h:110
static const plColor LightCoral
#F08080
Definition Color.h:118
static const plColor YellowGreen
#9ACD32
Definition Color.h:197
static const plColor Turquoise
#40E0D0
Definition Color.h:191
static const plColor SteelBlue
#4682B4
Definition Color.h:186
static const plColor NavajoWhite
#FFDEAD
Definition Color.h:150
static const plColor OliveDrab
#6B8E23
Definition Color.h:154
static const plColor DarkViolet
#9400D3
Definition Color.h:89
static const plColor LavenderBlush
#FFF0F5
Definition Color.h:114
static const plColor Chocolate
#D2691E
Definition Color.h:65
static const plColor OldLace
#FDF5E6
Definition Color.h:152
static const plColor PeachPuff
#FFDAB9
Definition Color.h:163
static const plColor MediumPurple
#9370DB
Definition Color.h:140
static const plColor Silver
#C0C0C0
Definition Color.h:179
static const plColor Pink
#FFC0CB
Definition Color.h:165
static const plColor DeepPink
#FF1493
Definition Color.h:90
static const plColor DarkSalmon
#E9967A
Definition Color.h:83
static const plColor Sienna
#A0522D
Definition Color.h:178
static const plColor SandyBrown
#F4A460
Definition Color.h:175
static const plColor MediumSlateBlue
#7B68EE
Definition Color.h:142
static const plColor Lime
#00FF00
Definition Color.h:132
static const plColor Yellow
#FFFF00
Definition Color.h:196
static const plColor Crimson
#DC143C
Definition Color.h:69
static const plColor HotPink
#FF69B4
Definition Color.h:108
static const plColor Fuchsia
#FF00FF
Definition Color.h:98
static const plColor OrangeRed
#FF4500
Definition Color.h:156
static const plColor Tomato
#FF6347
Definition Color.h:190
static const plColor BlanchedAlmond
#FFEBCD
Definition Color.h:58
static const plColor RosyBrown
#BC8F8F
Definition Color.h:171
static const plColor DarkCyan
#008B8B
Definition Color.h:72
static const plColor LawnGreen
#7CFC00
Definition Color.h:115
static const plColor Orange
#FFA500
Definition Color.h:155
static const plColor DarkBlue
#00008B
Definition Color.h:71
static const plColor LightGoldenRodYellow
#FAFAD2
Definition Color.h:120
static const plColor SaddleBrown
#8B4513
Definition Color.h:173
static const plColor Aquamarine
#7FFFD4
Definition Color.h:53
static const plColor Ivory
#FFFFF0
Definition Color.h:111
static const plColor Plum
#DDA0DD
Definition Color.h:166
A 8bit per channel unsigned normalized (values interpreted as 0-1) color storage format that represen...
Definition Color8UNorm.h:61