diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2014-09-01 11:28:50 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2014-09-02 19:07:44 +0200 |
commit | d8712ad04402903118739c31569a3cae6df3884e (patch) | |
tree | dbda090ea93aec2eb49b9fefa8a258752724a6cf /src/gui/painting | |
parent | 1629deec839552fb78689c8edd93a3ffab61efde (diff) |
qPremultiply(QRgb): let the compiler see all versions
Use a template helper function and template specialization
to select which of the two versions (64bit / 32bit) to
use. This makes the compiler see both versions on all
platforms, enabling better syntax checking should either
of the two change. It also will fail to compile on platforms
where the word size is neither 4 nor eight bytes now...
And, of course, it's always satisfying to remove a use of
the preprocessor.
Change-Id: I4870411f99eb3b1a2c0c170fa53fa3c9b026da15
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
Diffstat (limited to 'src/gui/painting')
-rw-r--r-- | src/gui/painting/qrgb.h | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/gui/painting/qrgb.h b/src/gui/painting/qrgb.h index d8e19302d1..646aded954 100644 --- a/src/gui/painting/qrgb.h +++ b/src/gui/painting/qrgb.h @@ -80,9 +80,11 @@ inline Q_DECL_CONSTEXPR int qGray(QRgb rgb) // convert RGB to gra inline Q_DECL_CONSTEXPR bool qIsGray(QRgb rgb) { return qRed(rgb) == qGreen(rgb) && qRed(rgb) == qBlue(rgb); } +template <int ProcessorWordSize> +inline QRgb qPremultiply_impl(QRgb x); -#if Q_PROCESSOR_WORDSIZE == 8 // 64-bit version -inline QRgb qPremultiply(QRgb x) +template <> // 64-bit version +inline QRgb qPremultiply_impl<8>(QRgb x) { const uint a = qAlpha(x); quint64 t = (((quint64(x)) | ((quint64(x)) << 24)) & 0x00ff00ff00ff00ff) * a; @@ -90,8 +92,9 @@ inline QRgb qPremultiply(QRgb x) t &= 0x000000ff00ff00ff; return (uint(t)) | (uint(t >> 24)) | (a << 24); } -#else // 32-bit version -inline QRgb qPremultiply(QRgb x) + +template <> // 32-bit version +inline QRgb qPremultiply_impl<4>(QRgb x) { const uint a = qAlpha(x); uint t = (x & 0xff00ff) * a; @@ -104,7 +107,8 @@ inline QRgb qPremultiply(QRgb x) x |= t | (a << 24); return x; } -#endif + +inline QRgb qPremultiply(QRgb x) { return qPremultiply_impl<Q_PROCESSOR_WORDSIZE>(x); } Q_GUI_EXPORT extern const uint qt_inv_premul_factor[]; |