Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
5.6.0
-
None
Description
We do a very naive rounding of QRectF to QRect, rounding the dimensions and top-left coordinates separately. This can cause the rounded result to be more than 1 pixel off. For instance rounding (0.5,0.5, 2.5, 2.5) can be rounded to (1,1, 3,3) which would make the right bottom pixels off by 1.5. This can among other things cause our clips to migrate outside source boundaries causing bugs like https://bugreports.qt.io/browse/QTBUG-56252 for instance.
One standard way of fixing is to instead round top-left and bottom-right coordinates, to keep the boundaries within 1 pixel of the source, but it may cause the dimensions to be off by more than a pixel.
QRect(qround(x), qround(y), qround(x+w) - qround(x), qround(y+h) - qround(y))
Another solution is to round the dimensions first than then do a symmetric expansions before rounding coordinates.
wr = round(w), hr = round(h)
return QRect(round(x+(w - wr)/2), round(y+(h - wh)/2), wr, hr)
Attachments
For Gerrit Dashboard: QTBUG-56420 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
198112,3 | Improve rounding of QRect::toRect | dev | qt/qtbase | Status: MERGED | +2 | 0 |