diff options
author | JiDe Zhang <zhangjide@uniontech.com> | 2021-10-28 11:45:52 +0800 |
---|---|---|
committer | JiDe Zhang <zhangjide@uniontech.com> | 2021-10-29 18:59:48 +0800 |
commit | 85b5413dc43e20951a3f27b2940961b1c998df95 (patch) | |
tree | b131e0f53937f0db19f1d4a06e86d7810d5ade5c /src/plugins | |
parent | 004e90b15569ab204e8302df853ef66eba918131 (diff) |
Avoid unnecessary color format conversion
If a color is not the rgb format, when QColor::red() QColor::blue()
QColor::green() is used continuously to obtain the values of different
channels, three times color conversions will occur. Therefore, use
QColor::toRgb() before that to ensure that only one conversion is
performed at most. Not only rgb, the conversion of other formats is the
same.
Change-Id: Ia969e1ca6f1524ad5d7e8dec915bcbc407875c66
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/scenegraph/openvg/qsgopenvghelpers.cpp | 10 | ||||
-rw-r--r-- | src/plugins/scenegraph/openvg/qsgopenvginternalrectanglenode.cpp | 18 |
2 files changed, 16 insertions, 12 deletions
diff --git a/src/plugins/scenegraph/openvg/qsgopenvghelpers.cpp b/src/plugins/scenegraph/openvg/qsgopenvghelpers.cpp index ab5cfb48b8..a9e27b9bbf 100644 --- a/src/plugins/scenegraph/openvg/qsgopenvghelpers.cpp +++ b/src/plugins/scenegraph/openvg/qsgopenvghelpers.cpp @@ -334,10 +334,12 @@ void qDrawSubImage(VGImage image, const QRectF &sourceRect, const QPointF &destO const QVector<VGfloat> qColorToVGColor(const QColor &color, float opacity) { QVector<VGfloat> vgColor(4); - vgColor[0] = color.redF(); - vgColor[1] = color.greenF(); - vgColor[2] = color.blueF(); - vgColor[3] = color.alphaF() * opacity; + float r, g, b, a; + color.getRgbF(&r, &g, &b, &a); + vgColor[0] = r; + vgColor[1] = g; + vgColor[2] = b; + vgColor[3] = a * opacity; return vgColor; } diff --git a/src/plugins/scenegraph/openvg/qsgopenvginternalrectanglenode.cpp b/src/plugins/scenegraph/openvg/qsgopenvginternalrectanglenode.cpp index 2c71c1610a..9cb81d05e4 100644 --- a/src/plugins/scenegraph/openvg/qsgopenvginternalrectanglenode.cpp +++ b/src/plugins/scenegraph/openvg/qsgopenvginternalrectanglenode.cpp @@ -87,17 +87,19 @@ static QGradientStop interpolateStop(const QGradientStop &firstStop, const QGrad double distance = secondStop.first - firstStop.first; double distanceDelta = newPos - firstStop.first; double modifierValue = distanceDelta / distance; - int redDelta = (secondStop.second.red() - firstStop.second.red()) * modifierValue; - int greenDelta = (secondStop.second.green() - firstStop.second.green()) * modifierValue; - int blueDelta = (secondStop.second.blue() - firstStop.second.blue()) * modifierValue; - int alphaDelta = (secondStop.second.alpha() - firstStop.second.alpha()) * modifierValue; + const auto firstStopRgbColor = firstStop.second.toRgb(); + const auto secondStopRgbColor = secondStop.second.toRgb(); + int redDelta = (secondStopRgbColor.red() - firstStopRgbColor.red()) * modifierValue; + int greenDelta = (secondStopRgbColor.green() - firstStopRgbColor.green()) * modifierValue; + int blueDelta = (secondStopRgbColor.blue() - firstStopRgbColor.blue()) * modifierValue; + int alphaDelta = (secondStopRgbColor.alpha() - firstStopRgbColor.alpha()) * modifierValue; QGradientStop newStop; newStop.first = newPos; - newStop.second = QColor(firstStop.second.red() + redDelta, - firstStop.second.green() + greenDelta, - firstStop.second.blue() + blueDelta, - firstStop.second.alpha() + alphaDelta); + newStop.second = QColor(firstStopRgbColor.red() + redDelta, + firstStopRgbColor.green() + greenDelta, + firstStopRgbColor.blue() + blueDelta, + firstStopRgbColor.alpha() + alphaDelta); return newStop; } |