Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/painting/qrasterizer.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    6666#define COORD_OFFSET 32 // 26.6, 32 is half a pixel
    6767
     68static inline QT_FT_Vector PointToVector(const QPointF &p)
     69{
     70    QT_FT_Vector result = { QT_FT_Pos(p.x() * 64), QT_FT_Pos(p.y() * 64) };
     71    return result;
     72}
     73
    6874class QSpanBuffer {
    6975public:
     
    199205
    200206QScanConverter::QScanConverter()
    201    : m_alloc(0)
     207   : m_lines(0)
     208   , m_alloc(0)
    202209   , m_size(0)
    203210   , m_intersections(0)
     211   , m_active(0)
    204212{
    205213}
     
    311319void qScanConvert(QScanConverter &d, T allVertical)
    312320{
     321    if (!d.m_lines.size()) {
     322        d.m_active.reset();
     323        return;
     324    }
    313325    qSort(d.m_lines.data(), d.m_lines.data() + d.m_lines.size(), QT_PREPEND_NAMESPACE(topOrder));
    314326    int line = 0;
     
    688700}
    689701
    690 static inline bool q16Dot16Compare(qreal p1, qreal p2)
    691 {
    692     return FloatToQ16Dot16(p2 - p1) == 0;
     702static inline bool q26Dot6Compare(qreal p1, qreal p2)
     703{
     704    return int((p2  - p1) * 64.) == 0;
    693705}
    694706
     
    703715}
    704716
     717static inline QPointF snapTo26Dot6Grid(const QPointF &p)
     718{
     719    return QPointF(qFloorF(p.x() * 64) * (1 / qreal(64)),
     720                   qFloorF(p.y() * 64) * (1 / qreal(64)));
     721}
     722
    705723void QRasterizer::rasterizeLine(const QPointF &a, const QPointF &b, qreal width, bool squareCap)
    706724{
     
    713731    QPointF pb = b;
    714732
    715     QPointF offs = QPointF(qAbs(b.y() - a.y()), qAbs(b.x() - a.x())) * width * 0.5;   
    716     if (squareCap)
    717         offs += QPointF(offs.y(), offs.x());
     733    if (squareCap) {
     734        QPointF delta = pb - pa;
     735        pa -= (0.5f * width) * delta;
     736        pb += (0.5f * width) * delta;
     737    }
     738
     739    QPointF offs = QPointF(qAbs(b.y() - a.y()), qAbs(b.x() - a.x())) * width * 0.5;
    718740    const QRectF clip(d->clipRect.topLeft() - offs, d->clipRect.bottomRight() + QPoint(1, 1) + offs);
    719741
    720     if (!clip.contains(a) || !clip.contains(b)) {
     742    if (!clip.contains(pa) || !clip.contains(pb)) {
    721743        qreal t1 = 0;
    722744        qreal t2 = 1;
    723745
    724         const qreal o[2] = { a.x(), a.y() };
    725         const qreal d[2] = { b.x() - a.x(), b.y() - a.y() };
     746        const qreal o[2] = { pa.x(), pa.y() };
     747        const qreal d[2] = { pb.x() - pa.x(), pb.y() - pa.y() };
    726748
    727749        const qreal low[2] = { clip.left(), clip.top() };
     
    746768                return;
    747769        }
    748         pa = a + (b - a) * t1;
    749         pb = a + (b - a) * t2;
     770
     771        QPointF npa = pa + (pb - pa) * t1;
     772        QPointF npb = pa + (pb - pa) * t2;
     773
     774        pa = npa;
     775        pb = npb;
    750776    }
    751777
     
    758784
    759785    {
    760         const qreal gridResolution = 64;
    761         const qreal reciprocal = 1 / gridResolution;
    762 
    763         // snap to grid to prevent large slopes
    764         pa.rx() = qFloorF(pa.rx() * gridResolution) * reciprocal;
    765         pa.ry() = qFloorF(pa.ry() * gridResolution) * reciprocal;
    766         pb.rx() = qFloorF(pb.rx() * gridResolution) * reciprocal;
    767         pb.ry() = qFloorF(pb.ry() * gridResolution) * reciprocal;
    768 
    769786        // old delta
    770787        const QPointF d0 = a - b;
     
    784801    QSpanBuffer buffer(d->blend, d->data, d->clipRect);
    785802
    786     if (q16Dot16Compare(pa.y(), pb.y())) {
     803    if (q26Dot6Compare(pa.y(), pb.y())) {
    787804        const qreal x = (pa.x() + pb.x()) * 0.5f;
    788805        const qreal dx = qAbs(pb.x() - pa.x()) * 0.5f;
     
    794811        pb = QPointF(x, y + dy);
    795812
    796         if (squareCap)
    797             width = 1 / width + 1.0f;
    798         else
    799             width = 1 / width;
    800 
    801         squareCap = false;
    802     }
    803 
    804     if (q16Dot16Compare(pa.x(), pb.x())) {
     813        width = 1 / width;
     814    }
     815
     816    if (q26Dot6Compare(pa.x(), pb.x())) {
    805817        if (pa.y() > pb.y())
    806818            qSwap(pa, pb);
     
    809821        const qreal halfWidth = 0.5f * width * dy;
    810822
    811         if (squareCap) {
    812             pa.ry() -= halfWidth;
    813             pb.ry() += halfWidth;
    814         }
    815 
    816823        qreal left = pa.x() - halfWidth;
    817824        qreal right = pa.x() + halfWidth;
     
    823830        pb.ry() = qBound(qreal(d->clipRect.top()), pb.y(), qreal(d->clipRect.bottom() + 1));
    824831
    825         if (q16Dot16Compare(left, right) || q16Dot16Compare(pa.y(), pb.y()))
     832        if (q26Dot6Compare(left, right) || q26Dot6Compare(pa.y(), pb.y()))
    826833            return;
    827834
     
    894901        const QPointF perp(delta.y(), -delta.x());
    895902
    896         if (squareCap) {
    897             pa -= delta;
    898             pb += delta;
    899         }
    900 
    901903        QPointF top;
    902904        QPointF left;
     
    916918        }
    917919
     920        top = snapTo26Dot6Grid(top);
     921        bottom = snapTo26Dot6Grid(bottom);
     922        left = snapTo26Dot6Grid(left);
     923        right = snapTo26Dot6Grid(right);
     924
    918925        const qreal topBound = qBound(qreal(d->clipRect.top()), top.y(), qreal(d->clipRect.bottom()));
    919926        const qreal bottomBound = qBound(qreal(d->clipRect.top()), bottom.y(), qreal(d->clipRect.bottom()));
    920927
    921         const qreal leftSlope = (left.x() - top.x()) / (left.y() - top.y());
    922         const qreal rightSlope = -1.0f / leftSlope;
    923 
    924         const Q16Dot16 leftSlopeFP = FloatToQ16Dot16(leftSlope);
    925         const Q16Dot16 rightSlopeFP = FloatToQ16Dot16(rightSlope);
     928        const QPointF topLeftEdge = left - top;
     929        const QPointF topRightEdge = right - top;
     930        const QPointF bottomLeftEdge = bottom - left;
     931        const QPointF bottomRightEdge = bottom - right;
     932
     933        const qreal topLeftSlope = topLeftEdge.x() / topLeftEdge.y();
     934        const qreal bottomLeftSlope = bottomLeftEdge.x() / bottomLeftEdge.y();
     935
     936        const qreal topRightSlope = topRightEdge.x() / topRightEdge.y();
     937        const qreal bottomRightSlope = bottomRightEdge.x() / bottomRightEdge.y();
     938
     939        const Q16Dot16 topLeftSlopeFP = FloatToQ16Dot16(topLeftSlope);
     940        const Q16Dot16 topRightSlopeFP = FloatToQ16Dot16(topRightSlope);
     941
     942        const Q16Dot16 bottomLeftSlopeFP = FloatToQ16Dot16(bottomLeftSlope);
     943        const Q16Dot16 bottomRightSlopeFP = FloatToQ16Dot16(bottomRightSlope);
     944
     945        const Q16Dot16 invTopLeftSlopeFP = FloatToQ16Dot16(1 / topLeftSlope);
     946        const Q16Dot16 invTopRightSlopeFP = FloatToQ16Dot16(1 / topRightSlope);
     947
     948        const Q16Dot16 invBottomLeftSlopeFP = FloatToQ16Dot16(1 / bottomLeftSlope);
     949        const Q16Dot16 invBottomRightSlopeFP = FloatToQ16Dot16(1 / bottomRightSlope);
    926950
    927951        if (d->antialiased) {
     
    931955            const Q16Dot16 iBottomFP = IntToQ16Dot16(int(bottomBound));
    932956
    933             Q16Dot16 leftIntersectAf = FloatToQ16Dot16(top.x() + (int(topBound) - top.y()) * leftSlope);
    934             Q16Dot16 rightIntersectAf = FloatToQ16Dot16(top.x() + (int(topBound) - top.y()) * rightSlope);
     957            Q16Dot16 leftIntersectAf = FloatToQ16Dot16(top.x() + (int(topBound) - top.y()) * topLeftSlope);
     958            Q16Dot16 rightIntersectAf = FloatToQ16Dot16(top.x() + (int(topBound) - top.y()) * topRightSlope);
    935959            Q16Dot16 leftIntersectBf = 0;
    936960            Q16Dot16 rightIntersectBf = 0;
    937961
    938962            if (iLeftFP < iTopFP)
    939                 leftIntersectBf = FloatToQ16Dot16(left.x() + (int(topBound) - left.y()) * rightSlope);
     963                leftIntersectBf = FloatToQ16Dot16(left.x() + (int(topBound) - left.y()) * bottomLeftSlope);
    940964
    941965            if (iRightFP < iTopFP)
    942                 rightIntersectBf = FloatToQ16Dot16(right.x() + (int(topBound) - right.y()) * leftSlope);
     966                rightIntersectBf = FloatToQ16Dot16(right.x() + (int(topBound) - right.y()) * bottomRightSlope);
    943967
    944968            Q16Dot16 rowTop, rowBottomLeft, rowBottomRight, rowTopLeft, rowTopRight, rowBottom;
     
    955979            rowTop = qMax(iTopFP, yTopFP);
    956980            topLeftIntersectAf = leftIntersectAf +
    957                                  Q16Dot16Multiply(leftSlopeFP, rowTop - iTopFP);
     981                                 Q16Dot16Multiply(topLeftSlopeFP, rowTop - iTopFP);
    958982            topRightIntersectAf = rightIntersectAf +
    959                                   Q16Dot16Multiply(rightSlopeFP, rowTop - iTopFP);
     983                                  Q16Dot16Multiply(topRightSlopeFP, rowTop - iTopFP);
    960984
    961985            Q16Dot16 yFP = iTopFP;
     
    969993                if (yFP == iLeftFP) {
    970994                    const int y = Q16Dot16ToInt(yFP);
    971                     leftIntersectBf = FloatToQ16Dot16(left.x() + (y - left.y()) * rightSlope);
    972                     topLeftIntersectBf = leftIntersectBf + Q16Dot16Multiply(rightSlopeFP, rowTopLeft - yFP);
    973                     bottomLeftIntersectAf = leftIntersectAf + Q16Dot16Multiply(leftSlopeFP, rowBottomLeft - yFP);
     995                    leftIntersectBf = FloatToQ16Dot16(left.x() + (y - left.y()) * bottomLeftSlope);
     996                    topLeftIntersectBf = leftIntersectBf + Q16Dot16Multiply(bottomLeftSlopeFP, rowTopLeft - yFP);
     997                    bottomLeftIntersectAf = leftIntersectAf + Q16Dot16Multiply(topLeftSlopeFP, rowBottomLeft - yFP);
    974998                } else {
    975999                    topLeftIntersectBf = leftIntersectBf;
    976                     bottomLeftIntersectAf = leftIntersectAf + leftSlopeFP;
     1000                    bottomLeftIntersectAf = leftIntersectAf + topLeftSlopeFP;
    9771001                }
    9781002
    9791003                if (yFP == iRightFP) {
    9801004                    const int y = Q16Dot16ToInt(yFP);
    981                     rightIntersectBf = FloatToQ16Dot16(right.x() + (y - right.y()) * leftSlope);
    982                     topRightIntersectBf = rightIntersectBf + Q16Dot16Multiply(leftSlopeFP, rowTopRight - yFP);
    983                     bottomRightIntersectAf = rightIntersectAf + Q16Dot16Multiply(rightSlopeFP, rowBottomRight - yFP);
     1005                    rightIntersectBf = FloatToQ16Dot16(right.x() + (y - right.y()) * bottomRightSlope);
     1006                    topRightIntersectBf = rightIntersectBf + Q16Dot16Multiply(bottomRightSlopeFP, rowTopRight - yFP);
     1007                    bottomRightIntersectAf = rightIntersectAf + Q16Dot16Multiply(topRightSlopeFP, rowBottomRight - yFP);
    9841008                } else {
    9851009                    topRightIntersectBf = rightIntersectBf;
    986                     bottomRightIntersectAf = rightIntersectAf + rightSlopeFP;
     1010                    bottomRightIntersectAf = rightIntersectAf + topRightSlopeFP;
    9871011                }
    9881012
    9891013                if (yFP == iBottomFP) {
    990                     bottomLeftIntersectBf = leftIntersectBf + Q16Dot16Multiply(rightSlopeFP, rowBottom - yFP);
    991                     bottomRightIntersectBf = rightIntersectBf + Q16Dot16Multiply(leftSlopeFP, rowBottom - yFP);
     1014                    bottomLeftIntersectBf = leftIntersectBf + Q16Dot16Multiply(bottomLeftSlopeFP, rowBottom - yFP);
     1015                    bottomRightIntersectBf = rightIntersectBf + Q16Dot16Multiply(bottomRightSlopeFP, rowBottom - yFP);
    9921016                } else {
    993                     bottomLeftIntersectBf = leftIntersectBf + rightSlopeFP;
    994                     bottomRightIntersectBf = rightIntersectBf + leftSlopeFP;
     1017                    bottomLeftIntersectBf = leftIntersectBf + bottomLeftSlopeFP;
     1018                    bottomRightIntersectBf = rightIntersectBf + bottomRightSlopeFP;
    9951019                }
    9961020
     
    10371061                        excluded += intersectPixelFP(x, rowTop, rowBottomLeft,
    10381062                                                     bottomLeftIntersectAf, topLeftIntersectAf,
    1039                                                      leftSlopeFP, -rightSlopeFP);
     1063                                                     topLeftSlopeFP, invTopLeftSlopeFP);
    10401064                    if (yFP >= iLeftFP)
    10411065                        excluded += intersectPixelFP(x, rowTopLeft, rowBottom,
    10421066                                                     topLeftIntersectBf, bottomLeftIntersectBf,
    1043                                                      rightSlopeFP, -leftSlopeFP);
     1067                                                     bottomLeftSlopeFP, invBottomLeftSlopeFP);
    10441068
    10451069                    if (x >= rightMin) {
     
    10471071                            excluded += (rowBottomRight - rowTop) - intersectPixelFP(x, rowTop, rowBottomRight,
    10481072                                                                                     topRightIntersectAf, bottomRightIntersectAf,
    1049                                                                                      rightSlopeFP, -leftSlopeFP);
     1073                                                                                     topRightSlopeFP, invTopRightSlopeFP);
    10501074                        if (yFP >= iRightFP)
    10511075                            excluded += (rowBottom - rowTopRight) - intersectPixelFP(x, rowTopRight, rowBottom,
    10521076                                                                                     bottomRightIntersectBf, topRightIntersectBf,
    1053                                                                                      leftSlopeFP, -rightSlopeFP);
     1077                                                                                     bottomRightSlopeFP, invBottomRightSlopeFP);
    10541078                    }
    10551079
     
    10691093                        excluded += (rowBottomRight - rowTop) - intersectPixelFP(x, rowTop, rowBottomRight,
    10701094                                                                                 topRightIntersectAf, bottomRightIntersectAf,
    1071                                                                                  rightSlopeFP, -leftSlopeFP);
     1095                                                                                 topRightSlopeFP, invTopRightSlopeFP);
    10721096                    if (yFP >= iRightFP)
    10731097                        excluded += (rowBottom - rowTopRight) - intersectPixelFP(x, rowTopRight, rowBottom,
    10741098                                                                                 bottomRightIntersectBf, topRightIntersectBf,
    1075                                                                                  leftSlopeFP, -rightSlopeFP);
     1099                                                                                 bottomRightSlopeFP, invBottomRightSlopeFP);
    10761100
    10771101                    Q16Dot16 coverage = rowHeight - excluded;
     
    10811105                }
    10821106
    1083                 leftIntersectAf += leftSlopeFP;
    1084                 leftIntersectBf += rightSlopeFP;
    1085                 rightIntersectAf += rightSlopeFP;
    1086                 rightIntersectBf += leftSlopeFP;
     1107                leftIntersectAf += topLeftSlopeFP;
     1108                leftIntersectBf += bottomLeftSlopeFP;
     1109                rightIntersectAf += topRightSlopeFP;
     1110                rightIntersectBf += bottomRightSlopeFP;
    10871111                topLeftIntersectAf = leftIntersectAf;
    10881112                topRightIntersectAf = rightIntersectAf;
     
    10981122            int iMiddle = qMin(iLeft, iRight);
    10991123
    1100             Q16Dot16 leftIntersectAf = FloatToQ16Dot16(top.x() + 0.5f + (iTop + 0.5f - top.y()) * leftSlope);
    1101             Q16Dot16 leftIntersectBf = FloatToQ16Dot16(left.x() + 0.5f + (iLeft + 1.5f - left.y()) * rightSlope);
    1102             Q16Dot16 rightIntersectAf = FloatToQ16Dot16(top.x() - 0.5f + (iTop + 0.5f - top.y()) * rightSlope);
    1103             Q16Dot16 rightIntersectBf = FloatToQ16Dot16(right.x() - 0.5f + (iRight + 1.5f - right.y()) * leftSlope);
     1124            Q16Dot16 leftIntersectAf = FloatToQ16Dot16(top.x() + 0.5f + (iTop + 0.5f - top.y()) * topLeftSlope);
     1125            Q16Dot16 leftIntersectBf = FloatToQ16Dot16(left.x() + 0.5f + (iLeft + 1.5f - left.y()) * bottomLeftSlope);
     1126            Q16Dot16 rightIntersectAf = FloatToQ16Dot16(top.x() - 0.5f + (iTop + 0.5f - top.y()) * topRightSlope);
     1127            Q16Dot16 rightIntersectBf = FloatToQ16Dot16(right.x() - 0.5f + (iRight + 1.5f - right.y()) * bottomRightSlope);
    11041128
    11051129            int ny;
     
    11231147             }
    11241148
    1125             DO_SEGMENT(iMiddle, leftIntersectAf, rightIntersectAf, leftSlopeFP, rightSlopeFP)
    1126             DO_SEGMENT(iRight, leftIntersectBf, rightIntersectAf, rightSlopeFP, rightSlopeFP)
    1127             DO_SEGMENT(iLeft, leftIntersectAf, rightIntersectBf, leftSlopeFP, leftSlopeFP)
    1128             DO_SEGMENT(iBottom, leftIntersectBf, rightIntersectBf, rightSlopeFP, leftSlopeFP)
     1149            DO_SEGMENT(iMiddle, leftIntersectAf, rightIntersectAf, topLeftSlopeFP, topRightSlopeFP)
     1150            DO_SEGMENT(iRight, leftIntersectBf, rightIntersectAf, bottomLeftSlopeFP, topRightSlopeFP)
     1151            DO_SEGMENT(iLeft, leftIntersectAf, rightIntersectBf, topLeftSlopeFP, bottomRightSlopeFP);
     1152            DO_SEGMENT(iBottom, leftIntersectBf, rightIntersectBf, bottomLeftSlopeFP, bottomRightSlopeFP);
    11291153#undef DO_SEGMENT
    11301154        }
     
    11761200
    11771201    d->scanConverter.end();
    1178 }
    1179 
    1180 static inline QT_FT_Vector PointToVector(const QPointF &p)
    1181 {
    1182     QT_FT_Vector result = { QT_FT_Pos(p.x() * 64), QT_FT_Pos(p.y() * 64) };
    1183     return result;
    11841202}
    11851203
Note: See TracChangeset for help on using the changeset viewer.