qualpal 3.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
91class RGB
92{
93private:
94 double r_value;
95 double g_value;
96 double b_value;
97
98public:
103
110 RGB(const double r, const double g, const double b);
111
116 RGB(const std::array<double, 3> rgb);
117
128 RGB(const std::string& hex);
129
135 RGB(const char* hex)
136 : RGB(std::string(hex)) {};
137
142 RGB(const HSL& hsl);
143
148 RGB(const XYZ& xyz);
149
154 RGB(const Lab& lab);
155
160 RGB(const LCHab& lch);
161
167 bool operator==(const RGB& other) const
168 {
169 return (r_value == other.r_value) && (g_value == other.g_value) &&
170 (b_value == other.b_value);
171 }
172
178 bool operator!=(const RGB& other) const { return !(*this == other); }
179
189 std::string hex() const;
190
192 double r() const { return r_value; }
194 double g() const { return g_value; }
196 double b() const { return b_value; }
197};
198
217class HSL
218{
219private:
220 double h_value;
221 double s_value;
222 double l_value;
223
224public:
229
236 HSL(const double h, const double s, const double l);
237
242 HSL(const RGB& rgb);
243
248 HSL(const XYZ& xyz);
249
254 HSL(const Lab& lab);
255
260 HSL(const LCHab& lch);
261
267 bool operator==(const HSL& other) const
268 {
269 return (h_value == other.h_value) && (s_value == other.s_value) &&
270 (l_value == other.l_value);
271 }
272
278 bool operator!=(const HSL& other) const { return !(*this == other); }
279
281 double h() const { return h_value; }
283 double s() const { return s_value; }
285 double l() const { return l_value; }
286};
287
311class XYZ
312{
313private:
314 double x_value;
315 double y_value;
316 double z_value;
317
318public:
323
330 XYZ(const double x, const double y, const double z);
331
336 XYZ(const RGB& rgb);
337
343 XYZ(const Lab& lab,
344 const std::array<double, 3>& white_point = { 0.95047, 1, 1.08883 });
345
350 XYZ(const HSL& hsl);
351
357 XYZ(const LCHab& lch,
358 const std::array<double, 3>& white_point = { 0.95047, 1, 1.08883 });
359
365 bool operator==(const XYZ& other) const
366 {
367 return (x_value == other.x_value) && (y_value == other.y_value) &&
368 (z_value == other.z_value);
369 }
370
376 bool operator!=(const XYZ& other) const { return !(*this == other); }
377
379 double x() const { return x_value; }
381 double y() const { return y_value; }
383 double z() const { return z_value; }
384};
385
405{
406private:
407 double l_value;
408 double a_value;
409 double b_value;
410
411public:
416
423 DIN99d(const double l, const double a, const double b);
424
429 DIN99d(const RGB& rgb);
430
435 DIN99d(const HSL& hsl);
436
441 DIN99d(const Lab& lab);
442
448 DIN99d(const XYZ& xyz,
449 const std::array<double, 3>& white_point = { 0.95047, 1, 1.08883 });
450
456 bool operator==(const DIN99d& other) const
457 {
458 return (l_value == other.l_value) && (a_value == other.a_value) &&
459 (b_value == other.b_value);
460 }
461
467 bool operator!=(const DIN99d& other) const { return !(*this == other); }
468
470 double l() const { return l_value; }
472 double a() const { return a_value; }
474 double b() const { return b_value; }
475};
476
492class Lab
493{
494private:
495 double l_value;
496 double a_value;
497 double b_value;
498
499public:
504
511 Lab(const double l, const double a, const double b);
512
517 Lab(const RGB& rgb);
518
523 Lab(const HSL& hsl);
524
530 Lab(const XYZ& xyz,
531 const std::array<double, 3>& white_point = { 0.95047, 1, 1.08883 });
532
537 Lab(const LCHab& lch);
538
544 bool operator==(const Lab& other) const
545 {
546 return (l_value == other.l_value) && (a_value == other.a_value) &&
547 (b_value == other.b_value);
548 }
549
551 double l() const { return l_value; }
553 double a() const { return a_value; }
555 double b() const { return b_value; }
556};
557
574class LCHab
575{
576private:
577 double l_value;
578 double c_value;
579 double h_value;
580
581public:
586
593 LCHab(const double l, const double c, const double h);
594
599 LCHab(const Lab& lab);
600
604 LCHab(const RGB& rgb);
605
610 LCHab(const HSL& hsl);
611
617 LCHab(const XYZ& xyz,
618 const std::array<double, 3>& white_point = { 0.95047, 1, 1.08883 });
619
625 bool operator==(const LCHab& other) const
626 {
627 return (l_value == other.l_value) && (c_value == other.c_value) &&
628 (h_value == other.h_value);
629 }
630
636 bool operator!=(const LCHab& other) const { return !(*this == other); }
637
639 double l() const { return l_value; }
641 double c() const { return c_value; }
643 double h() const { return h_value; }
644};
645
646} // namespace colors
647} // namespace qualpal
DIN99d color space representation.
Definition colors.h:405
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:467
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:474
DIN99d(const HSL &hsl)
Construct DIN99d from HSL color.
double l() const
Get lightness component.
Definition colors.h:470
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:456
double a() const
Get green-red component.
Definition colors.h:472
HSL (Hue, Saturation, Lightness) color representation.
Definition colors.h:218
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:278
HSL(const RGB &rgb)
Construct HSL from RGB color.
double l() const
Get lightness [0,1].
Definition colors.h:285
bool operator==(const HSL &other) const
Equality operator for HSL colors.
Definition colors.h:267
HSL()
Default constructor initializes HSL to black (0,0,0)
double s() const
Get saturation [0,1].
Definition colors.h:283
double h() const
Get hue in degrees [0,360)
Definition colors.h:281
HSL(const LCHab &lch)
Construct HSL from LCHab color.
LCHab color space representation (CIE L*C*h)
Definition colors.h:575
LCHab()
Default constructor initializes LCHab to black (0,0,0)
bool operator!=(const LCHab &other) const
inequality operator for LCHab colors
Definition colors.h:636
LCHab(const HSL &hsl)
Construct LCHab from HSL color.
double h() const
Get hue in degrees [0,360)
Definition colors.h:643
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:639
double c() const
Get chroma [0,∞)
Definition colors.h:641
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:625
Lab color space representation (CIE L*a*b*).
Definition colors.h:493
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:555
bool operator==(const Lab &other) const
Equality operator for Lab colors.
Definition colors.h:544
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:551
double a() const
Get green-red component.
Definition colors.h:553
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:92
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:194
bool operator!=(const RGB &other) const
Inequality operator for RGB colors.
Definition colors.h:178
RGB(const std::string &hex)
Construct RGB from hexadecimal color string.
double b() const
Get blue component [0,1].
Definition colors.h:196
RGB(const LCHab &lch)
Construct RGB from LCHab color.
double r() const
Get red component [0,1].
Definition colors.h:192
RGB(const Lab &lab)
Construct RGB from Lab color.
RGB(const char *hex)
Construct RGB from hexadecimal color string literal.
Definition colors.h:135
bool operator==(const RGB &other) const
Equality operator for RGB colors.
Definition colors.h:167
XYZ color representation (CIE 1931 color space).
Definition colors.h:312
bool operator==(const XYZ &other) const
equality operator for XYZ colors
Definition colors.h:365
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:376
XYZ(const double x, const double y, const double z)
Construct XYZ from component values.
double z() const
Get Z component.
Definition colors.h:383
double x() const
Get X component.
Definition colors.h:379
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:381
Qualitative color palette generation library.
Definition analyze.h:21