Rasterizer: compute intersection factors only when needed
Fixes oss-fuzz issue 29285 Change-Id: I8f7e0bc898b119d153a36cef5a74371249ed7686 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> Reviewed-by: Robert Loehning <robert.loehning@qt.io> (cherry picked from commit e1ed570f9d0ec3998f130e2c3870ef49e7994dbf) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
a48f500c34
commit
c1cd5dcabe
@ -657,6 +657,7 @@ static QScFixed intersectPixelFP(int x, QScFixed top, QScFixed bottom, QScFixed
|
|||||||
QScFixed rightX = IntToQScFixed(x) + QScFixedFactor;
|
QScFixed rightX = IntToQScFixed(x) + QScFixedFactor;
|
||||||
|
|
||||||
QScFixed leftIntersectY, rightIntersectY;
|
QScFixed leftIntersectY, rightIntersectY;
|
||||||
|
auto computeIntersectY = [&]() {
|
||||||
if (slope > 0) {
|
if (slope > 0) {
|
||||||
leftIntersectY = top + QScFixedMultiply(leftX - leftIntersectX, invSlope);
|
leftIntersectY = top + QScFixedMultiply(leftX - leftIntersectX, invSlope);
|
||||||
rightIntersectY = leftIntersectY + invSlope;
|
rightIntersectY = leftIntersectY + invSlope;
|
||||||
@ -664,12 +665,14 @@ static QScFixed intersectPixelFP(int x, QScFixed top, QScFixed bottom, QScFixed
|
|||||||
leftIntersectY = top + QScFixedMultiply(leftX - rightIntersectX, invSlope);
|
leftIntersectY = top + QScFixedMultiply(leftX - rightIntersectX, invSlope);
|
||||||
rightIntersectY = leftIntersectY + invSlope;
|
rightIntersectY = leftIntersectY + invSlope;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (leftIntersectX >= leftX && rightIntersectX <= rightX) {
|
if (leftIntersectX >= leftX && rightIntersectX <= rightX) {
|
||||||
return QScFixedMultiply(bottom - top, leftIntersectX - leftX + ((rightIntersectX - leftIntersectX) >> 1));
|
return QScFixedMultiply(bottom - top, leftIntersectX - leftX + ((rightIntersectX - leftIntersectX) >> 1));
|
||||||
} else if (leftIntersectX >= rightX) {
|
} else if (leftIntersectX >= rightX) {
|
||||||
return bottom - top;
|
return bottom - top;
|
||||||
} else if (leftIntersectX >= leftX) {
|
} else if (leftIntersectX >= leftX) {
|
||||||
|
computeIntersectY();
|
||||||
if (slope > 0) {
|
if (slope > 0) {
|
||||||
return (bottom - top) - QScFixedFastMultiply((rightX - leftIntersectX) >> 1, rightIntersectY - top);
|
return (bottom - top) - QScFixedFastMultiply((rightX - leftIntersectX) >> 1, rightIntersectY - top);
|
||||||
} else {
|
} else {
|
||||||
@ -678,12 +681,14 @@ static QScFixed intersectPixelFP(int x, QScFixed top, QScFixed bottom, QScFixed
|
|||||||
} else if (rightIntersectX <= leftX) {
|
} else if (rightIntersectX <= leftX) {
|
||||||
return 0;
|
return 0;
|
||||||
} else if (rightIntersectX <= rightX) {
|
} else if (rightIntersectX <= rightX) {
|
||||||
|
computeIntersectY();
|
||||||
if (slope > 0) {
|
if (slope > 0) {
|
||||||
return QScFixedFastMultiply((rightIntersectX - leftX) >> 1, bottom - leftIntersectY);
|
return QScFixedFastMultiply((rightIntersectX - leftX) >> 1, bottom - leftIntersectY);
|
||||||
} else {
|
} else {
|
||||||
return QScFixedFastMultiply((rightIntersectX - leftX) >> 1, leftIntersectY - top);
|
return QScFixedFastMultiply((rightIntersectX - leftX) >> 1, leftIntersectY - top);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
computeIntersectY();
|
||||||
if (slope > 0) {
|
if (slope > 0) {
|
||||||
return (bottom - rightIntersectY) + ((rightIntersectY - leftIntersectY) >> 1);
|
return (bottom - rightIntersectY) + ((rightIntersectY - leftIntersectY) >> 1);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user