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
color_widgets::detail::rainbow_hsv
QColor rainbow_hsv(qreal hue)
Definition: color_utils.hpp:47
color_widgets::detail::color_from_hsl
QColor color_from_hsl(qreal hue, qreal sat, qreal lig, qreal alpha=1)
Definition: color_utils.cpp:55
color_widgets::detail::rainbow_lch
QColor rainbow_lch(qreal hue)
Definition: color_utils.hpp:42
detail
Definition: args.h:19
color_widgets::detail::color_lumaF
qreal color_lumaF(const QColor &c)
Definition: color_utils.hpp:36
color_widgets::detail::color_chromaF
qreal color_chromaF(const QColor &c)
Definition: color_utils.hpp:29
color_widgets
Definition: color_dialog.hpp:33
color_widgets::detail::color_HSL_saturationF
qreal color_HSL_saturationF(const QColor &col)
Definition: color_utils.hpp:58
color_widgets::detail::color_lightnessF
qreal color_lightnessF(const QColor &c)
Definition: color_utils.hpp:52
color_widgets::detail::color_from_lch
QColor color_from_lch(qreal hue, qreal chroma, qreal luma, qreal alpha=1)
Definition: color_utils.cpp:28


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:43