From c8709b33e9192f06c790d7ae24c1f93614213843 Mon Sep 17 00:00:00 2001 From: Dmitry Kazakov Date: Tue, 13 Jan 2015 18:11:14 +0400 Subject: [PATCH] Fix shaky lines on 32-bit systems The value of the mirrored x coordinate is almost exactly integer all the time. On 64-bit systems the CPU converts it into integer correctly, but on 32-bit systems it probably doesn't download it from the FPU register (which are 80-bit and therefore more precise), so the value got truncated to the decremented value. It results in the lines becoming shaky due to random precision errors. Now we explicitly round "almost-integer" part of the sum so no precision fluctuations happen. BUG:341577 --- krita/image/brushengine/kis_paintop.cc | 11 ++--------- krita/plugins/paintops/libpaintop/kis_dab_cache.cpp | 12 ++++++------ 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/krita/image/brushengine/kis_paintop.cc b/krita/image/brushengine/kis_paintop.cc index fbf03dc68a..7c853f173b 100644 --- a/krita/image/brushengine/kis_paintop.cc +++ b/krita/image/brushengine/kis_paintop.cc @@ -104,15 +104,8 @@ void KisPaintOp::setFanCornersInfo(bool fanCornersEnabled, qreal fanCornersStep) void KisPaintOp::splitCoordinate(qreal coordinate, qint32 *whole, qreal *fraction) { - qint32 i = static_cast(coordinate); - - if (coordinate < 0) { - // We always want the fractional part to be positive. - // E.g. -1.25 becomes -2 and +0.75 - i--; - } - - qreal f = coordinate - i; + const qint32 i = std::floor(coordinate); + const qreal f = coordinate - i; *whole = i; *fraction = f; diff --git a/krita/plugins/paintops/libpaintop/kis_dab_cache.cpp b/krita/plugins/paintops/libpaintop/kis_dab_cache.cpp index f2370e723e..628e9a0cda 100644 --- a/krita/plugins/paintops/libpaintop/kis_dab_cache.cpp +++ b/krita/plugins/paintops/libpaintop/kis_dab_cache.cpp @@ -252,8 +252,8 @@ KisFixedPaintDeviceSP KisDabCache::tryFetchFromCache(const SavedDabParameters &p } qreal positiveFraction(qreal x) { - int unused; - qreal fraction; + qint32 unused = 0; + qreal fraction = 0.0; KisPaintOp::splitCoordinate(x, &unused, &fraction); return fraction; @@ -267,8 +267,8 @@ KisDabCache::calculateDabRect(const QPointF &cursorPoint, const KisPaintInformation& info, const MirrorProperties &mirrorProperties) { - int x, y; - qreal subPixelX, subPixelY; + qint32 x = 0, y = 0; + qreal subPixelX = 0.0, subPixelY = 0.0; if (mirrorProperties.coordinateSystemFlipped) { angle = 2 * M_PI - angle; @@ -296,13 +296,13 @@ KisDabCache::calculateDabRect(const QPointF &cursorPoint, if (mirrorProperties.horizontalMirror) { subPixelX = positiveFraction(-(cursorPoint.x() + hotSpot.x())); width = m_d->brush->maskWidth(scaleX, angle, subPixelX, subPixelY, info); - x = cursorPoint.x() + subPixelX + hotSpot.x() - width; + x = qRound(cursorPoint.x() + subPixelX + hotSpot.x()) - width; } if (mirrorProperties.verticalMirror) { subPixelY = positiveFraction(-(cursorPoint.y() + hotSpot.y())); height = m_d->brush->maskHeight(scaleY, angle, subPixelX, subPixelY, info); - y = cursorPoint.y() + subPixelY + hotSpot.y() - height; + y = qRound(cursorPoint.y() + subPixelY + hotSpot.y()) - height; } return DabPosition(QRect(x, y, width, height), -- GitLab