Improved qt_gradient_clamp for reflect spreads.
authorSamuel Rødal <samuel.rodal@nokia.com>
Sat, 18 Sep 2010 09:04:29 +0000 (11:04 +0200)
committerOlivier Goffart <olivier.goffart@nokia.com>
Tue, 10 May 2011 10:54:45 +0000 (12:54 +0200)
Using GRADIENT_STOPTABLE_SIZE * 2 as the modulo gives more correct
behaviour, and also improves performance slightly.

Reviewed-by: Benjamin Poulain
(cherry picked from commit 44dd7ef86a3970694a4f8fd9516575c0533a336e)

src/gui/painting/qdrawhelper_p.h

index 2cfcffb..6377fe1 100644 (file)
@@ -349,13 +349,11 @@ static inline uint qt_gradient_clamp(const QGradientData *data, int ipos)
         if (data->spread == QGradient::RepeatSpread) {
             ipos = ipos % GRADIENT_STOPTABLE_SIZE;
             ipos = ipos < 0 ? GRADIENT_STOPTABLE_SIZE + ipos : ipos;
-
         } else if (data->spread == QGradient::ReflectSpread) {
-            const int limit = GRADIENT_STOPTABLE_SIZE * 2 - 1;
+            const int limit = GRADIENT_STOPTABLE_SIZE * 2;
             ipos = ipos % limit;
             ipos = ipos < 0 ? limit + ipos : ipos;
-            ipos = ipos >= GRADIENT_STOPTABLE_SIZE ? limit - ipos : ipos;
-
+            ipos = ipos >= GRADIENT_STOPTABLE_SIZE ? limit - 1 - ipos : ipos;
         } else {
             if (ipos < 0)
                 ipos = 0;
@@ -364,7 +362,6 @@ static inline uint qt_gradient_clamp(const QGradientData *data, int ipos)
         }
     }
 
-
     Q_ASSERT(ipos >= 0);
     Q_ASSERT(ipos < GRADIENT_STOPTABLE_SIZE);