From: Ivailo Monev Date: Sat, 1 Aug 2020 18:17:56 +0000 (+0300) Subject: generalize qt_memfill() implementations X-Git-Tag: 4.12.0~3651 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=542bc73fc696fb43384ca8d21996f9174d634d41;p=kde%2FKatie.git generalize qt_memfill() implementations Signed-off-by: Ivailo Monev --- diff --git a/src/gui/painting/qdrawhelper_p.h b/src/gui/painting/qdrawhelper_p.h index 4e15a231c..7d8b4f633 100644 --- a/src/gui/painting/qdrawhelper_p.h +++ b/src/gui/painting/qdrawhelper_p.h @@ -335,38 +335,6 @@ static inline uint PREMUL(uint x) { | (((255*qGreen(p)) / qAlpha(p)) << 8) \ | ((255*qBlue(p)) / qAlpha(p)))) -template -inline DST qt_colorConvert(const SRC color, const DST dummy) -{ - Q_UNUSED(dummy); - return DST(color); -} - -template <> -inline quint32 qt_colorConvert(const quint16 color, const quint32 dummy) -{ - Q_UNUSED(dummy); - const int r = (color & 0xf800); - const int g = (color & 0x07e0); - const int b = (color & 0x001f); - const int tr = (r >> 8) | (r >> 13); - const int tg = (g >> 3) | (g >> 9); - const int tb = (b << 3) | (b >> 2); - - return qRgb(tr, tg, tb); -} - -template <> -inline quint16 qt_colorConvert(const quint32 color, const quint16 dummy) -{ - Q_UNUSED(dummy); - const int r = qRed(color) << 8; - const int g = qGreen(color) << 3; - const int b = qBlue(color) >> 3; - - return (r & 0xf800) | (g & 0x07e0)| (b & 0x001f); -} - class quint32p { public: @@ -1063,36 +1031,52 @@ qrgb444 qrgb444::operator+(qrgb444 v) const return t; } -template -inline void qt_memfill(T *dest, const T value, int count) + +template +inline DST qt_colorConvert(const SRC color, const DST dummy) { - ::memset(dest, value, count); + Q_UNUSED(dummy); + return DST(color); } -template -inline void qt_memfill(DST *dest, const SRC color, int count) +template <> +inline quint32 qt_colorConvert(const quint16 color, const quint32 dummy) { - const DST c = qt_colorConvert(color, 0); - while (count--) - *dest++ = c; + Q_UNUSED(dummy); + const int r = (color & 0xf800); + const int g = (color & 0x07e0); + const int b = (color & 0x001f); + const int tr = (r >> 8) | (r >> 13); + const int tg = (g >> 3) | (g >> 9); + const int tb = (b << 3) | (b >> 2); + + return qRgb(tr, tg, tb); } -template<> inline void qt_memfill(quint32 *dest, const quint32 color, int count) +template <> +inline quint16 qt_colorConvert(const quint32 color, const quint16 dummy) { - while (count--) - *dest++ = color; + Q_UNUSED(dummy); + const int r = qRed(color) << 8; + const int g = qGreen(color) << 3; + const int b = qBlue(color) >> 3; + + return (r & 0xf800) | (g & 0x07e0)| (b & 0x001f); } -template<> inline void qt_memfill(quint16 *dest, const quint16 color, int count) +template +inline void qt_memfill(T *dest, const T color, int count) { while (count--) *dest++ = color; } -template<> inline void qt_memfill(quint8 *dest, const quint8 color, int count) +template +inline void qt_memfill(DST *dest, const SRC color, int count) { + const DST c = qt_colorConvert(color, 0); while (count--) - *dest++ = color; + *dest++ = c; } template