OSDN Git Service

generalize qt_memfill<T>() implementations
authorIvailo Monev <xakepa10@gmail.com>
Sat, 1 Aug 2020 18:17:56 +0000 (21:17 +0300)
committerIvailo Monev <xakepa10@gmail.com>
Sat, 1 Aug 2020 18:24:50 +0000 (21:24 +0300)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
src/gui/painting/qdrawhelper_p.h

index 4e15a23..7d8b4f6 100644 (file)
@@ -335,38 +335,6 @@ static inline uint PREMUL(uint x) {
      | (((255*qGreen(p)) / qAlpha(p))  << 8)            \
      | ((255*qBlue(p)) / qAlpha(p))))
 
-template <class DST, class SRC>
-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 <class T>
-inline void qt_memfill(T *dest, const T value, int count)
+
+template <class DST, class SRC>
+inline DST qt_colorConvert(const SRC color, const DST dummy)
 {
-    ::memset(dest, value, count);
+    Q_UNUSED(dummy);
+    return DST(color);
 }
 
-template <class DST, class SRC>
-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<DST, SRC>(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 <class T>
+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 <class DST, class SRC>
+inline void qt_memfill(DST *dest, const SRC color, int count)
 {
+    const DST c = qt_colorConvert<DST, SRC>(color, 0);
     while (count--)
-        *dest++ = color;
+        *dest++ = c;
 }
 
 template <class T>