Make QRgb-related functions constexpr

Change-Id: I44b2b60e89a3312889101d7e5c305f4f7c18f7ae
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
Giuseppe D'Angelo 2013-05-15 11:07:40 +02:00 committed by The Qt Project
parent e63b831bbd
commit f66af39933

View File

@ -52,31 +52,31 @@ typedef unsigned int QRgb; // RGB triplet
// non-namespaced Qt global variable
const Q_DECL_UNUSED QRgb RGB_MASK = 0x00ffffff; // masks RGB values
inline int qRed(QRgb rgb) // get red part of RGB
inline Q_DECL_CONSTEXPR int qRed(QRgb rgb) // get red part of RGB
{ return ((rgb >> 16) & 0xff); }
inline int qGreen(QRgb rgb) // get green part of RGB
inline Q_DECL_CONSTEXPR int qGreen(QRgb rgb) // get green part of RGB
{ return ((rgb >> 8) & 0xff); }
inline int qBlue(QRgb rgb) // get blue part of RGB
inline Q_DECL_CONSTEXPR int qBlue(QRgb rgb) // get blue part of RGB
{ return (rgb & 0xff); }
inline int qAlpha(QRgb rgb) // get alpha part of RGBA
inline Q_DECL_CONSTEXPR int qAlpha(QRgb rgb) // get alpha part of RGBA
{ return rgb >> 24; }
inline QRgb qRgb(int r, int g, int b)// set RGB value
inline Q_DECL_CONSTEXPR QRgb qRgb(int r, int g, int b)// set RGB value
{ return (0xffu << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); }
inline QRgb qRgba(int r, int g, int b, int a)// set RGBA value
inline Q_DECL_CONSTEXPR QRgb qRgba(int r, int g, int b, int a)// set RGBA value
{ return ((a & 0xff) << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); }
inline int qGray(int r, int g, int b)// convert R,G,B to gray 0..255
inline Q_DECL_CONSTEXPR int qGray(int r, int g, int b)// convert R,G,B to gray 0..255
{ return (r*11+g*16+b*5)/32; }
inline int qGray(QRgb rgb) // convert RGB to gray 0..255
inline Q_DECL_CONSTEXPR int qGray(QRgb rgb) // convert RGB to gray 0..255
{ return qGray(qRed(rgb), qGreen(rgb), qBlue(rgb)); }
inline bool qIsGray(QRgb rgb)
inline Q_DECL_CONSTEXPR bool qIsGray(QRgb rgb)
{ return qRed(rgb) == qGreen(rgb) && qRed(rgb) == qBlue(rgb); }
QT_END_NAMESPACE