qualpal 4.0.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
30enum class WhitePoint
31{
32 D65,
33 D50,
34 D55,
35 A,
36 E
37};
38
44std::array<double, 3>
46
85namespace colors {
86
87// forward declarations
88class HSL;
89class XYZ;
90class Lab;
91class DIN99d;
92class LCHab;
93
119class RGB
120{
121private:
122 double r_value;
123 double g_value;
124 double b_value;
125
126public:
131
138 RGB(const double r, const double g, const double b);
139
144 RGB(const std::array<double, 3> rgb);
145
156 RGB(const std::string& hex);
157
163 RGB(const char* hex)
164 : RGB(std::string(hex)) {};
165
170 RGB(const HSL& hsl);
171
176 RGB(const XYZ& xyz);
177
182 RGB(const Lab& lab);
183
188 RGB(const LCHab& lch);
189
195 bool operator==(const RGB& other) const
196 {
197 return (r_value == other.r_value) && (g_value == other.g_value) &&
198 (b_value == other.b_value);
199 }
200
206 bool operator!=(const RGB& other) const { return !(*this == other); }
207
217 std::string hex() const;
218
220 double r() const { return r_value; }
222 double g() const { return g_value; }
224 double b() const { return b_value; }
225};
226
245class HSL
246{
247private:
248 double h_value;
249 double s_value;
250 double l_value;
251
252public:
257
264 HSL(const double h, const double s, const double l);
265
270 HSL(const RGB& rgb);
271
276 HSL(const XYZ& xyz);
277
282 HSL(const Lab& lab);
283
288 HSL(const LCHab& lch);
289
295 bool operator==(const HSL& other) const
296 {
297 return (h_value == other.h_value) && (s_value == other.s_value) &&
298 (l_value == other.l_value);
299 }
300
306 bool operator!=(const HSL& other) const { return !(*this == other); }
307
309 double h() const { return h_value; }
311 double s() const { return s_value; }
313 double l() const { return l_value; }
314};
315
339class XYZ
340{
341private:
342 double x_value;
343 double y_value;
344 double z_value;
345
346public:
351
358 XYZ(const double x, const double y, const double z);
359
364 XYZ(const RGB& rgb);
365
371 XYZ(const Lab& lab,
372 const std::array<double, 3>& white_point = { 0.95047, 1, 1.08883 });
373
378 XYZ(const HSL& hsl);
379
385 XYZ(const LCHab& lch,
386 const std::array<double, 3>& white_point = { 0.95047, 1, 1.08883 });
387
393 bool operator==(const XYZ& other) const
394 {
395 return (x_value == other.x_value) && (y_value == other.y_value) &&
396 (z_value == other.z_value);
397 }
398
404 bool operator!=(const XYZ& other) const { return !(*this == other); }
405
407 double x() const { return x_value; }
409 double y() const { return y_value; }
411 double z() const { return z_value; }
412};
413
433{
434private:
435 double l_value;
436 double a_value;
437 double b_value;
438
439public:
444
451 DIN99d(const double l, const double a, const double b);
452
457 DIN99d(const RGB& rgb);
458
463 DIN99d(const HSL& hsl);
464
469 DIN99d(const Lab& lab);
470
476 DIN99d(const XYZ& xyz,
477 const std::array<double, 3>& white_point = { 0.95047, 1, 1.08883 });
478
484 bool operator==(const DIN99d& other) const
485 {
486 return (l_value == other.l_value) && (a_value == other.a_value) &&
487 (b_value == other.b_value);
488 }
489
495 bool operator!=(const DIN99d& other) const { return !(*this == other); }
496
498 double l() const { return l_value; }
500 double a() const { return a_value; }
502 double b() const { return b_value; }
503};
504
520class Lab
521{
522private:
523 double l_value;
524 double a_value;
525 double b_value;
526
527public:
532
539 Lab(const double l, const double a, const double b);
540
545 Lab(const RGB& rgb);
546
551 Lab(const HSL& hsl);
552
558 Lab(const XYZ& xyz,
559 const std::array<double, 3>& white_point = { 0.95047, 1, 1.08883 });
560
565 Lab(const LCHab& lch);
566
572 bool operator==(const Lab& other) const
573 {
574 return (l_value == other.l_value) && (a_value == other.a_value) &&
575 (b_value == other.b_value);
576 }
577
579 double l() const { return l_value; }
581 double a() const { return a_value; }
583 double b() const { return b_value; }
584};
585
602class LCHab
603{
604private:
605 double l_value;
606 double c_value;
607 double h_value;
608
609public:
614
621 LCHab(const double l, const double c, const double h);
622
627 LCHab(const Lab& lab);
628
632 LCHab(const RGB& rgb);
633
638 LCHab(const HSL& hsl);
639
645 LCHab(const XYZ& xyz,
646 const std::array<double, 3>& white_point = { 0.95047, 1, 1.08883 });
647
653 bool operator==(const LCHab& other) const
654 {
655 return (l_value == other.l_value) && (c_value == other.c_value) &&
656 (h_value == other.h_value);
657 }
658
664 bool operator!=(const LCHab& other) const { return !(*this == other); }
665
667 double l() const { return l_value; }
669 double c() const { return c_value; }
671 double h() const { return h_value; }
672};
673
674} // namespace colors
675} // namespace qualpal
DIN99d color space representation.
Definition colors.h:433
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:495
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:502
DIN99d(const HSL &hsl)
Construct DIN99d from HSL color.
double l() const
Get lightness component.
Definition colors.h:498
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:484
double a() const
Get green-red component.
Definition colors.h:500
HSL (Hue, Saturation, Lightness) color representation.
Definition colors.h:246
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:306
HSL(const RGB &rgb)
Construct HSL from RGB color.
double l() const
Get lightness [0,1].
Definition colors.h:313
bool operator==(const HSL &other) const
Equality operator for HSL colors.
Definition colors.h:295
HSL()
Default constructor initializes HSL to black (0,0,0)
double s() const
Get saturation [0,1].
Definition colors.h:311
double h() const
Get hue in degrees [0,360)
Definition colors.h:309
HSL(const LCHab &lch)
Construct HSL from LCHab color.
LCHab color space representation (CIE L*C*h)
Definition colors.h:603
LCHab()
Default constructor initializes LCHab to black (0,0,0)
bool operator!=(const LCHab &other) const
inequality operator for LCHab colors
Definition colors.h:664
LCHab(const HSL &hsl)
Construct LCHab from HSL color.
double h() const
Get hue in degrees [0,360)
Definition colors.h:671
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:667
double c() const
Get chroma [0,∞)
Definition colors.h:669
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:653
Lab color space representation (CIE L*a*b*).
Definition colors.h:521
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:583
bool operator==(const Lab &other) const
Equality operator for Lab colors.
Definition colors.h:572
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:579
double a() const
Get green-red component.
Definition colors.h:581
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:120
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:222
bool operator!=(const RGB &other) const
Inequality operator for RGB colors.
Definition colors.h:206
RGB(const std::string &hex)
Construct RGB from hexadecimal color string.
double b() const
Get blue component [0,1].
Definition colors.h:224
RGB(const LCHab &lch)
Construct RGB from LCHab color.
double r() const
Get red component [0,1].
Definition colors.h:220
RGB(const Lab &lab)
Construct RGB from Lab color.
RGB(const char *hex)
Construct RGB from hexadecimal color string literal.
Definition colors.h:163
bool operator==(const RGB &other) const
Equality operator for RGB colors.
Definition colors.h:195
XYZ color representation (CIE 1931 color space).
Definition colors.h:340
bool operator==(const XYZ &other) const
equality operator for XYZ colors
Definition colors.h:393
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:404
XYZ(const double x, const double y, const double z)
Construct XYZ from component values.
double z() const
Get Z component.
Definition colors.h:411
double x() const
Get X component.
Definition colors.h:407
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:409
Qualitative color palette generation library.
Definition analyze.h:21
WhitePoint
Standard CIE illuminants for color space conversions.
Definition colors.h:31
@ E
Equal energy {1.0, 1.0, 1.0}.
@ D65
Daylight 6500K {0.95047, 1.0, 1.08883}.
@ D55
Daylight 5500K {0.95682, 1.0, 0.92149}.
@ D50
Daylight 5000K {0.96422, 1.0, 0.82521}.
@ A
Incandescent {1.09850, 1.0, 0.35585}.
std::array< double, 3 > whitePointToXYZ(WhitePoint wp)
Convert WhitePoint enum to XYZ tristimulus values.