color_utils.hpp
Go to the documentation of this file.
1 
22 #include <QColor>
23 #include <qmath.h>
24 
25 namespace color_widgets {
26 namespace detail {
27 
28 
29 inline qreal color_chromaF(const QColor& c)
30 {
31  qreal max = qMax(c.redF(), qMax(c.greenF(), c.blueF()));
32  qreal min = qMin(c.redF(), qMin(c.greenF(), c.blueF()));
33  return max - min;
34 }
35 
36 inline qreal color_lumaF(const QColor& c)
37 {
38  return 0.30 * c.redF() + 0.59 * c.greenF() + 0.11 * c.blueF();
39 }
40 QColor color_from_lch(qreal hue, qreal chroma, qreal luma, qreal alpha = 1 );
41 
42 inline QColor rainbow_lch(qreal hue)
43 {
44  return color_from_lch(hue,1,1);
45 }
46 
47 inline QColor rainbow_hsv(qreal hue)
48 {
49  return QColor::fromHsvF(hue,1,1);
50 }
51 
52 inline qreal color_lightnessF(const QColor& c)
53 {
54  return ( qMax(c.redF(),qMax(c.greenF(),c.blueF())) +
55  qMin(c.redF(),qMin(c.greenF(),c.blueF())) ) / 2;
56 }
57 
58 inline qreal color_HSL_saturationF(const QColor& col)
59 {
60  qreal c = color_chromaF(col);
61  qreal l = color_lightnessF(col);
62  if ( qFuzzyCompare(l+1,1) || qFuzzyCompare(l+1,2) )
63  return 0;
64  return c / (1-qAbs(2*l-1));
65 }
66 
67 QColor color_from_hsl(qreal hue, qreal sat, qreal lig, qreal alpha = 1 );
68 
69 } // namespace detail
70 } // namespace color_widgets
QColor rainbow_lch(qreal hue)
Definition: color_utils.hpp:42
QColor rainbow_hsv(qreal hue)
Definition: color_utils.hpp:47
qreal color_lumaF(const QColor &c)
Definition: color_utils.hpp:36
qreal color_chromaF(const QColor &c)
Definition: color_utils.hpp:29
QColor color_from_lch(qreal hue, qreal chroma, qreal luma, qreal alpha=1)
Definition: color_utils.cpp:28
qreal color_HSL_saturationF(const QColor &col)
Definition: color_utils.hpp:58
int min(int a, int b)
QColor color_from_hsl(qreal hue, qreal sat, qreal lig, qreal alpha=1)
Definition: color_utils.cpp:55
qreal color_lightnessF(const QColor &c)
Definition: color_utils.hpp:52


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:17