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/quickshapes | |
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/quickshapes')
-rw-r--r-- | src/quickshapes/qquickshapegenericrenderer.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/quickshapes/qquickshapegenericrenderer.cpp b/src/quickshapes/qquickshapegenericrenderer.cpp index f5fcd72152..864d0f06d9 100644 --- a/src/quickshapes/qquickshapegenericrenderer.cpp +++ b/src/quickshapes/qquickshapegenericrenderer.cpp @@ -63,11 +63,13 @@ struct ColoredVertex // must match QSGGeometry::ColoredPoint2D static inline QQuickShapeGenericRenderer::Color4ub colorToColor4ub(const QColor &c) { + float r, g, b, a; + c.getRgbF(&r, &g, &b, &a); QQuickShapeGenericRenderer::Color4ub color = { - uchar(qRound(c.redF() * c.alphaF() * 255)), - uchar(qRound(c.greenF() * c.alphaF() * 255)), - uchar(qRound(c.blueF() * c.alphaF() * 255)), - uchar(qRound(c.alphaF() * 255)) + uchar(qRound(r * a * 255)), + uchar(qRound(g * a * 255)), + uchar(qRound(b * a * 255)), + uchar(qRound(a * 255)) }; return color; } |