color_utils.hpp
Go to the documentation of this file.
00001 
00022 #include <QColor>
00023 #include <qmath.h>
00024 
00025 namespace color_widgets {
00026 namespace detail {
00027 
00028 
00029 inline qreal color_chromaF(const QColor& c)
00030 {
00031     qreal max = qMax(c.redF(), qMax(c.greenF(), c.blueF()));
00032     qreal min = qMin(c.redF(), qMin(c.greenF(), c.blueF()));
00033     return max - min;
00034 }
00035 
00036 inline qreal color_lumaF(const QColor& c)
00037 {
00038     return 0.30 * c.redF() + 0.59 * c.greenF() + 0.11 * c.blueF();
00039 }
00040 QColor color_from_lch(qreal hue, qreal chroma, qreal luma, qreal alpha = 1 );
00041 
00042 inline QColor rainbow_lch(qreal hue)
00043 {
00044     return color_from_lch(hue,1,1);
00045 }
00046 
00047 inline QColor rainbow_hsv(qreal hue)
00048 {
00049     return QColor::fromHsvF(hue,1,1);
00050 }
00051 
00052 inline qreal color_lightnessF(const QColor& c)
00053 {
00054     return ( qMax(c.redF(),qMax(c.greenF(),c.blueF())) +
00055              qMin(c.redF(),qMin(c.greenF(),c.blueF())) ) / 2;
00056 }
00057 
00058 inline qreal color_HSL_saturationF(const QColor& col)
00059 {
00060     qreal c = color_chromaF(col);
00061     qreal l = color_lightnessF(col);
00062     if ( qFuzzyCompare(l+1,1) || qFuzzyCompare(l+1,2) )
00063         return 0;
00064     return c / (1-qAbs(2*l-1));
00065 }
00066 
00067 QColor color_from_hsl(qreal hue, qreal sat, qreal lig, qreal alpha = 1 );
00068 
00069 } // namespace detail
00070 } // namespace color_widgets


plotjuggler
Author(s): Davide Faconti
autogenerated on Fri Sep 1 2017 02:41:56