summaryrefslogtreecommitdiffstats
path: root/src/gui/opengl/qopenglgradientcache.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/opengl/qopenglgradientcache.cpp')
-rw-r--r--src/gui/opengl/qopenglgradientcache.cpp67
1 files changed, 34 insertions, 33 deletions
diff --git a/src/gui/opengl/qopenglgradientcache.cpp b/src/gui/opengl/qopenglgradientcache.cpp
index 13bad9aabb..58dcbed50a 100644
--- a/src/gui/opengl/qopenglgradientcache.cpp
+++ b/src/gui/opengl/qopenglgradientcache.cpp
@@ -1,31 +1,37 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtGui module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -102,7 +108,7 @@ GLuint QOpenGL2GradientCache::getBuffer(const QGradient &gradient, qreal opacity
{
quint64 hash_val = 0;
- QGradientStops stops = gradient.stops();
+ const QGradientStops stops = gradient.stops();
for (int i = 0; i < stops.size() && i <= 2; i++)
hash_val += stops[i].second.rgba();
@@ -164,16 +170,12 @@ GLuint QOpenGL2GradientCache::addCacheElement(quint64 hash_val, const QGradient
void QOpenGL2GradientCache::generateGradientColorTable(const QGradient& gradient, QRgba64 *colorTable, int size, qreal opacity) const
{
int pos = 0;
- QGradientStops s = gradient.stops();
- QVector<QRgba64> colors(s.size());
-
- for (int i = 0; i < s.size(); ++i)
- colors[i] = s[i].second.rgba64();
+ const QGradientStops s = gradient.stops();
bool colorInterpolation = (gradient.interpolationMode() == QGradient::ColorInterpolation);
uint alpha = qRound(opacity * 256);
- QRgba64 current_color = combineAlpha256(colors[0], alpha);
+ QRgba64 current_color = combineAlpha256(s[0].second.rgba64(), alpha);
qreal incr = 1.0 / qreal(size);
qreal fpos = 1.5 * incr;
colorTable[pos++] = qPremultiply(current_color);
@@ -187,9 +189,10 @@ void QOpenGL2GradientCache::generateGradientColorTable(const QGradient& gradient
if (colorInterpolation)
current_color = qPremultiply(current_color);
- for (int i = 0; i < s.size() - 1; ++i) {
+ const int sLast = s.size() - 1;
+ for (int i = 0; i < sLast; ++i) {
qreal delta = 1/(s[i+1].first - s[i].first);
- QRgba64 next_color = combineAlpha256(colors[i+1], alpha);
+ QRgba64 next_color = combineAlpha256(s[i + 1].second.rgba64(), alpha);
if (colorInterpolation)
next_color = qPremultiply(next_color);
@@ -208,7 +211,7 @@ void QOpenGL2GradientCache::generateGradientColorTable(const QGradient& gradient
Q_ASSERT(s.size() > 0);
- QRgba64 last_color = qPremultiply(combineAlpha256(colors[s.size() - 1], alpha));
+ QRgba64 last_color = qPremultiply(combineAlpha256(s[sLast].second.rgba64(), alpha));
for (;pos < size; ++pos)
colorTable[pos] = last_color;
@@ -219,16 +222,13 @@ void QOpenGL2GradientCache::generateGradientColorTable(const QGradient& gradient
void QOpenGL2GradientCache::generateGradientColorTable(const QGradient& gradient, uint *colorTable, int size, qreal opacity) const
{
int pos = 0;
- QGradientStops s = gradient.stops();
- QVector<uint> colors(s.size());
-
- for (int i = 0; i < s.size(); ++i)
- colors[i] = s[i].second.rgba(); // Qt LIES! It returns ARGB (on little-endian AND on big-endian)
+ const QGradientStops s = gradient.stops();
bool colorInterpolation = (gradient.interpolationMode() == QGradient::ColorInterpolation);
uint alpha = qRound(opacity * 256);
- uint current_color = ARGB_COMBINE_ALPHA(colors[0], alpha);
+ // Qt LIES! It returns ARGB (on little-endian AND on big-endian)
+ uint current_color = ARGB_COMBINE_ALPHA(s[0].second.rgba(), alpha);
qreal incr = 1.0 / qreal(size);
qreal fpos = 1.5 * incr;
colorTable[pos++] = ARGB2RGBA(qPremultiply(current_color));
@@ -242,9 +242,10 @@ void QOpenGL2GradientCache::generateGradientColorTable(const QGradient& gradient
if (colorInterpolation)
current_color = qPremultiply(current_color);
- for (int i = 0; i < s.size() - 1; ++i) {
+ const int sLast = s.size() - 1;
+ for (int i = 0; i < sLast; ++i) {
qreal delta = 1/(s[i+1].first - s[i].first);
- uint next_color = ARGB_COMBINE_ALPHA(colors[i+1], alpha);
+ uint next_color = ARGB_COMBINE_ALPHA(s[i + 1].second.rgba(), alpha);
if (colorInterpolation)
next_color = qPremultiply(next_color);
@@ -263,7 +264,7 @@ void QOpenGL2GradientCache::generateGradientColorTable(const QGradient& gradient
Q_ASSERT(s.size() > 0);
- uint last_color = ARGB2RGBA(qPremultiply(ARGB_COMBINE_ALPHA(colors[s.size() - 1], alpha)));
+ uint last_color = ARGB2RGBA(qPremultiply(ARGB_COMBINE_ALPHA(s[sLast].second.rgba(), alpha)));
for (;pos < size; ++pos)
colorTable[pos] = last_color;