diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2022-06-25 11:59:20 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2022-06-28 17:16:47 +0200 |
commit | aefb5c5a56dd6882179130b98fc44ac0fb366b03 (patch) | |
tree | 57bfb915d2930a5fad5489ec3f267357d2c04a12 | |
parent | Ensure consistent cursor width under fractional scaling (diff) | |
download | qtbase-aefb5c5a56dd6882179130b98fc44ac0fb366b03.tar.xz qtbase-aefb5c5a56dd6882179130b98fc44ac0fb366b03.zip |
Avoid overflowing coverage in rasterizer
A single examined pixel might have sampled corners outside the logical
constraints, that needs to be ignore.
Pick-to: 6.4 6.3 6.2
Fixes: QTBUG-92485
Change-Id: I105fd42d3388a48f3bb03c00d640832e8e99477c
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
-rw-r--r-- | src/gui/painting/qrasterizer.cpp | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/src/gui/painting/qrasterizer.cpp b/src/gui/painting/qrasterizer.cpp index 8a3e46e58b..cd9d3ba4d0 100644 --- a/src/gui/painting/qrasterizer.cpp +++ b/src/gui/painting/qrasterizer.cpp @@ -1064,28 +1064,26 @@ void QRasterizer::rasterizeLine(const QPointF &a, const QPointF &b, qreal width, while (x <= leftMax) { QScFixed excluded = 0; - if (yFP <= iLeftFP) + if (yFP <= iLeftFP && rowBottomLeft > rowTop) excluded += intersectPixelFP(x, rowTop, rowBottomLeft, bottomLeftIntersectAf, topLeftIntersectAf, topLeftSlopeFP, invTopLeftSlopeFP); - if (yFP >= iLeftFP) + if (yFP >= iLeftFP && rowBottom > rowTopLeft) excluded += intersectPixelFP(x, rowTopLeft, rowBottom, topLeftIntersectBf, bottomLeftIntersectBf, bottomLeftSlopeFP, invBottomLeftSlopeFP); - if (x >= rightMin) { - if (yFP <= iRightFP) + if (yFP <= iRightFP && rowBottomRight > rowTop) excluded += (rowBottomRight - rowTop) - intersectPixelFP(x, rowTop, rowBottomRight, topRightIntersectAf, bottomRightIntersectAf, topRightSlopeFP, invTopRightSlopeFP); - if (yFP >= iRightFP) + if (yFP >= iRightFP && rowBottom > rowTopRight) excluded += (rowBottom - rowTopRight) - intersectPixelFP(x, rowTopRight, rowBottom, bottomRightIntersectBf, topRightIntersectBf, bottomRightSlopeFP, invBottomRightSlopeFP); } - if (excluded > QScFixedFactor) - excluded = excluded % QScFixedFactor; + Q_ASSERT(excluded >= 0 && excluded <= rowHeight); QScFixed coverage = rowHeight - excluded; buffer.addSpan(x, 1, QScFixedToInt(yFP), QScFixedToInt(255 * coverage)); @@ -1098,17 +1096,16 @@ void QRasterizer::rasterizeLine(const QPointF &a, const QPointF &b, qreal width, } while (x <= rightMax) { QScFixed excluded = 0; - if (yFP <= iRightFP) + if (yFP <= iRightFP && rowBottomRight > rowTop) excluded += (rowBottomRight - rowTop) - intersectPixelFP(x, rowTop, rowBottomRight, topRightIntersectAf, bottomRightIntersectAf, topRightSlopeFP, invTopRightSlopeFP); - if (yFP >= iRightFP) + if (yFP >= iRightFP && rowBottom > rowTopRight) excluded += (rowBottom - rowTopRight) - intersectPixelFP(x, rowTopRight, rowBottom, bottomRightIntersectBf, topRightIntersectBf, bottomRightSlopeFP, invBottomRightSlopeFP); - if (excluded > QScFixedFactor) - excluded = excluded % QScFixedFactor; + Q_ASSERT(excluded >= 0 && excluded <= rowHeight); QScFixed coverage = rowHeight - excluded; buffer.addSpan(x, 1, QScFixedToInt(yFP), QScFixedToInt(255 * coverage)); |