qualpal 2.3.0
Loading...
Searching...
No Matches
colors.h
Go to the documentation of this file.
1
12#pragma once
13
14#include <array>
15#include <string>
16
17namespace qualpal {
18
57namespace colors {
58
59// forward declarations
60class HSL;
61class XYZ;
62class Lab;
63class DIN99d;
64class LCHab;
65
83class RGB
84{
85private:
86 double r_value;
87 double g_value;
88 double b_value;
89
90public:
94 RGB();
95
102 RGB(const double r, const double g, const double b);
103
108 RGB(const std::array<double, 3> rgb);
109
120 RGB(const std::string& hex);
121
126 RGB(const HSL& hsl);
127
132 RGB(const XYZ& xyz);
133
138 RGB(const Lab& lab);
139
144 RGB(const LCHab& lch);
145
151 bool operator==(const RGB& other) const
152 {
153 return (r_value == other.r_value) && (g_value == other.g_value) &&
154 (b_value == other.b_value);
155 }
156
162 bool operator!=(const RGB& other) const { return !(*this == other); }
163
173 std::string hex() const;
174
176 double r() const { return r_value; }
178 double g() const { return g_value; }
180 double b() const { return b_value; }
181};
182
194class HSL
195{
196private:
197 double h_value;
198 double s_value;
199 double l_value;
200
201public:
206
213 HSL(const double h, const double s, const double l);
214
219 HSL(const RGB& rgb);
220
225 HSL(const XYZ& xyz);
226
231 HSL(const Lab& lab);
232
237 HSL(const LCHab& lch);
238
244 bool operator==(const HSL& other) const
245 {
246 return (h_value == other.h_value) && (s_value == other.s_value) &&
247 (l_value == other.l_value);
248 }
249
255 bool operator!=(const HSL& other) const { return !(*this == other); }
256
258 double h() const { return h_value; }
260 double s() const { return s_value; }
262 double l() const { return l_value; }
263};
264
271class XYZ
272{
273private:
274 double x_value;
275 double y_value;
276 double z_value;
277
278public:
283
290 XYZ(const double x, const double y, const double z);
291
296 XYZ(const RGB& rgb);
297
303 XYZ(const Lab& lab,
304 const std::array<double, 3>& white_point = { 0.95047, 1, 1.08883 });
305
310 XYZ(const HSL& hsl);
311
317 XYZ(const LCHab& lch,
318 const std::array<double, 3>& white_point = { 0.95047, 1, 1.08883 });
319
325 bool operator==(const XYZ& other) const
326 {
327 return (x_value == other.x_value) && (y_value == other.y_value) &&
328 (z_value == other.z_value);
329 }
330
336 bool operator!=(const XYZ& other) const { return !(*this == other); }
337
339 double x() const { return x_value; }
341 double y() const { return y_value; }
343 double z() const { return z_value; }
344};
345
356{
357private:
358 double l_value;
359 double a_value;
360 double b_value;
361
362public:
367
374 DIN99d(const double l, const double a, const double b);
375
380 DIN99d(const RGB& rgb);
381
386 DIN99d(const HSL& hsl);
387
392 DIN99d(const Lab& lab);
393
399 DIN99d(const XYZ& xyz,
400 const std::array<double, 3>& white_point = { 0.95047, 1, 1.08883 });
401
407 bool operator==(const DIN99d& other) const
408 {
409 return (l_value == other.l_value) && (a_value == other.a_value) &&
410 (b_value == other.b_value);
411 }
412
418 bool operator!=(const DIN99d& other) const { return !(*this == other); }
419
421 double l() const { return l_value; }
423 double a() const { return a_value; }
425 double b() const { return b_value; }
426};
427
438class Lab
439{
440private:
441 double l_value;
442 double a_value;
443 double b_value;
444
445public:
450
457 Lab(const double l, const double a, const double b);
458
463 Lab(const RGB& rgb);
464
469 Lab(const HSL& hsl);
470
476 Lab(const XYZ& xyz,
477 const std::array<double, 3>& white_point = { 0.95047, 1, 1.08883 });
478
483 Lab(const LCHab& lch);
484
490 bool operator==(const Lab& other) const
491 {
492 return (l_value == other.l_value) && (a_value == other.a_value) &&
493 (b_value == other.b_value);
494 }
495
497 double l() const { return l_value; }
499 double a() const { return a_value; }
501 double b() const { return b_value; }
502};
503
514class LCHab
515{
516private:
517 double l_value;
518 double c_value;
519 double h_value;
520
521public:
526
533 LCHab(const double l, const double c, const double h);
534
539 LCHab(const Lab& lab);
540
544 LCHab(const RGB& rgb);
545
550 LCHab(const HSL& hsl);
551
557 LCHab(const XYZ& xyz,
558 const std::array<double, 3>& white_point = { 0.95047, 1, 1.08883 });
559
565 bool operator==(const LCHab& other) const
566 {
567 return (l_value == other.l_value) && (c_value == other.c_value) &&
568 (h_value == other.h_value);
569 }
570
576 bool operator!=(const LCHab& other) const { return !(*this == other); }
577
579 double l() const { return l_value; }
581 double c() const { return c_value; }
583 double h() const { return h_value; }
584};
585
586} // namespace colors
587} // namespace qualpal
DIN99d color space representation.
Definition colors.h:356
DIN99d(const Lab &lab)
Construct DIN99d from Lab color.
DIN99d(const double l, const double a, const double b)
Construct DIN99d from component values.
bool operator!=(const DIN99d &other) const
inequality operator for DIN99d colors
Definition colors.h:418
DIN99d()
Default constructor initializes DIN99d to black (0,0,0)
DIN99d(const RGB &rgb)
Construct DIN99d from RGB color.
double b() const
Get blue-yellow component.
Definition colors.h:425
DIN99d(const HSL &hsl)
Construct DIN99d from HSL color.
double l() const
Get lightness component.
Definition colors.h:421
DIN99d(const XYZ &xyz, const std::array< double, 3 > &white_point={ 0.95047, 1, 1.08883 })
Construct DIN99d from XYZ color.
bool operator==(const DIN99d &other) const
equality operator for DIN99d colors
Definition colors.h:407
double a() const
Get green-red component.
Definition colors.h:423
HSL (Hue, Saturation, Lightness) color representation.
Definition colors.h:195
HSL(const Lab &lab)
Construct HSL from Lab color.
HSL(const double h, const double s, const double l)
Construct HSL from component values.
HSL(const XYZ &xyz)
Construct HSL from XYZ color.
bool operator!=(const HSL &other) const
Inequality operator for HSL colors.
Definition colors.h:255
HSL(const RGB &rgb)
Construct HSL from RGB color.
double l() const
Get lightness [0,1].
Definition colors.h:262
bool operator==(const HSL &other) const
Equality operator for HSL colors.
Definition colors.h:244
HSL()
Default constructor initializes HSL to black (0,0,0)
double s() const
Get saturation [0,1].
Definition colors.h:260
double h() const
Get hue in degrees [0,360)
Definition colors.h:258
HSL(const LCHab &lch)
Construct HSL from LCHab color.
LCHab color space representation (CIE L*C*h)
Definition colors.h:515
LCHab()
Default constructor initializes LCHab to black (0,0,0)
bool operator!=(const LCHab &other) const
inequality operator for LCHab colors
Definition colors.h:576
LCHab(const HSL &hsl)
Construct LCHab from HSL color.
double h() const
Get hue in degrees [0,360)
Definition colors.h:583
LCHab(const XYZ &xyz, const std::array< double, 3 > &white_point={ 0.95047, 1, 1.08883 })
Construct LCHab from XYZ color.
LCHab(const Lab &lab)
Construct LCHab from Lab color.
LCHab(const RGB &rgb)
Construct LCHab from RGB color.
double l() const
Get lightness [0,100].
Definition colors.h:579
double c() const
Get chroma [0,∞)
Definition colors.h:581
LCHab(const double l, const double c, const double h)
Construct LCHab from component values.
bool operator==(const LCHab &other) const
equality operator for LCHab colors
Definition colors.h:565
Lab color space representation (CIE L*a*b*)
Definition colors.h:439
Lab(const HSL &hsl)
Construct Lab from HSL color.
Lab(const RGB &rgb)
Construct Lab from RGB color.
double b() const
Get blue-yellow component.
Definition colors.h:501
bool operator==(const Lab &other) const
Equality operator for Lab colors.
Definition colors.h:490
Lab(const double l, const double a, const double b)
Construct Lab from component values.
double l() const
Get lightness [0,100].
Definition colors.h:497
double a() const
Get green-red component.
Definition colors.h:499
Lab()
Default constructor initializes Lab to black (0,0,0)
Lab(const LCHab &lch)
Construct Lab from LCHab color.
Lab(const XYZ &xyz, const std::array< double, 3 > &white_point={ 0.95047, 1, 1.08883 })
Construct Lab from XYZ color.
RGB color representation with values in [0,1] range.
Definition colors.h:84
RGB()
Default constructor initializes RGB to black (0,0,0)
RGB(const XYZ &xyz)
Construct RGB from XYZ color.
RGB(const std::array< double, 3 > rgb)
Construct RGB from array of normalized values.
RGB(const HSL &hsl)
Construct RGB from HSL color.
std::string hex() const
Convert RGB to hexadecimal string.
RGB(const double r, const double g, const double b)
Construct RGB from normalized values.
double g() const
Get green component [0,1].
Definition colors.h:178
bool operator!=(const RGB &other) const
Inequality operator for RGB colors.
Definition colors.h:162
RGB(const std::string &hex)
Construct RGB from hexadecimal color string.
double b() const
Get blue component [0,1].
Definition colors.h:180
RGB(const LCHab &lch)
Construct RGB from LCHab color.
double r() const
Get red component [0,1].
Definition colors.h:176
RGB(const Lab &lab)
Construct RGB from Lab color.
bool operator==(const RGB &other) const
Equality operator for RGB colors.
Definition colors.h:151
XYZ color representation (CIE 1931 color space)
Definition colors.h:272
bool operator==(const XYZ &other) const
equality operator for XYZ colors
Definition colors.h:325
XYZ(const Lab &lab, const std::array< double, 3 > &white_point={ 0.95047, 1, 1.08883 })
Construct XYZ from Lab color.
XYZ(const HSL &hsl)
Construct XYZ from HSL color.
bool operator!=(const XYZ &other) const
inequality operator for XYZ colors
Definition colors.h:336
XYZ(const double x, const double y, const double z)
Construct XYZ from component values.
double z() const
Get Z component.
Definition colors.h:343
double x() const
Get X component.
Definition colors.h:339
XYZ()
Default constructor initializes XYZ to (0,0,0)
XYZ(const LCHab &lch, const std::array< double, 3 > &white_point={ 0.95047, 1, 1.08883 })
Construct XYZ from LCHab color.
XYZ(const RGB &rgb)
Construct XYZ from RGB color.
double y() const
Get Y component (luminance)
Definition colors.h:341
Qualitative color palette generation library.
Definition analyze.h:19