Changeset 846 for trunk/src/gui/painting/qrasterizer.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/gui/painting/qrasterizer.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 66 66 #define COORD_OFFSET 32 // 26.6, 32 is half a pixel 67 67 68 static 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 68 74 class QSpanBuffer { 69 75 public: … … 199 205 200 206 QScanConverter::QScanConverter() 201 : m_alloc(0) 207 : m_lines(0) 208 , m_alloc(0) 202 209 , m_size(0) 203 210 , m_intersections(0) 211 , m_active(0) 204 212 { 205 213 } … … 311 319 void qScanConvert(QScanConverter &d, T allVertical) 312 320 { 321 if (!d.m_lines.size()) { 322 d.m_active.reset(); 323 return; 324 } 313 325 qSort(d.m_lines.data(), d.m_lines.data() + d.m_lines.size(), QT_PREPEND_NAMESPACE(topOrder)); 314 326 int line = 0; … … 688 700 } 689 701 690 static inline bool q 16Dot16Compare(qreal p1, qreal p2)691 { 692 return FloatToQ16Dot16(p2 - p1) == 0;702 static inline bool q26Dot6Compare(qreal p1, qreal p2) 703 { 704 return int((p2 - p1) * 64.) == 0; 693 705 } 694 706 … … 703 715 } 704 716 717 static 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 705 723 void QRasterizer::rasterizeLine(const QPointF &a, const QPointF &b, qreal width, bool squareCap) 706 724 { … … 713 731 QPointF pb = b; 714 732 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; 718 740 const QRectF clip(d->clipRect.topLeft() - offs, d->clipRect.bottomRight() + QPoint(1, 1) + offs); 719 741 720 if (!clip.contains( a) || !clip.contains(b)) {742 if (!clip.contains(pa) || !clip.contains(pb)) { 721 743 qreal t1 = 0; 722 744 qreal t2 = 1; 723 745 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() }; 726 748 727 749 const qreal low[2] = { clip.left(), clip.top() }; … … 746 768 return; 747 769 } 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; 750 776 } 751 777 … … 758 784 759 785 { 760 const qreal gridResolution = 64;761 const qreal reciprocal = 1 / gridResolution;762 763 // snap to grid to prevent large slopes764 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 769 786 // old delta 770 787 const QPointF d0 = a - b; … … 784 801 QSpanBuffer buffer(d->blend, d->data, d->clipRect); 785 802 786 if (q 16Dot16Compare(pa.y(), pb.y())) {803 if (q26Dot6Compare(pa.y(), pb.y())) { 787 804 const qreal x = (pa.x() + pb.x()) * 0.5f; 788 805 const qreal dx = qAbs(pb.x() - pa.x()) * 0.5f; … … 794 811 pb = QPointF(x, y + dy); 795 812 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())) { 805 817 if (pa.y() > pb.y()) 806 818 qSwap(pa, pb); … … 809 821 const qreal halfWidth = 0.5f * width * dy; 810 822 811 if (squareCap) {812 pa.ry() -= halfWidth;813 pb.ry() += halfWidth;814 }815 816 823 qreal left = pa.x() - halfWidth; 817 824 qreal right = pa.x() + halfWidth; … … 823 830 pb.ry() = qBound(qreal(d->clipRect.top()), pb.y(), qreal(d->clipRect.bottom() + 1)); 824 831 825 if (q 16Dot16Compare(left, right) || q16Dot16Compare(pa.y(), pb.y()))832 if (q26Dot6Compare(left, right) || q26Dot6Compare(pa.y(), pb.y())) 826 833 return; 827 834 … … 894 901 const QPointF perp(delta.y(), -delta.x()); 895 902 896 if (squareCap) {897 pa -= delta;898 pb += delta;899 }900 901 903 QPointF top; 902 904 QPointF left; … … 916 918 } 917 919 920 top = snapTo26Dot6Grid(top); 921 bottom = snapTo26Dot6Grid(bottom); 922 left = snapTo26Dot6Grid(left); 923 right = snapTo26Dot6Grid(right); 924 918 925 const qreal topBound = qBound(qreal(d->clipRect.top()), top.y(), qreal(d->clipRect.bottom())); 919 926 const qreal bottomBound = qBound(qreal(d->clipRect.top()), bottom.y(), qreal(d->clipRect.bottom())); 920 927 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); 926 950 927 951 if (d->antialiased) { … … 931 955 const Q16Dot16 iBottomFP = IntToQ16Dot16(int(bottomBound)); 932 956 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); 935 959 Q16Dot16 leftIntersectBf = 0; 936 960 Q16Dot16 rightIntersectBf = 0; 937 961 938 962 if (iLeftFP < iTopFP) 939 leftIntersectBf = FloatToQ16Dot16(left.x() + (int(topBound) - left.y()) * rightSlope);963 leftIntersectBf = FloatToQ16Dot16(left.x() + (int(topBound) - left.y()) * bottomLeftSlope); 940 964 941 965 if (iRightFP < iTopFP) 942 rightIntersectBf = FloatToQ16Dot16(right.x() + (int(topBound) - right.y()) * leftSlope);966 rightIntersectBf = FloatToQ16Dot16(right.x() + (int(topBound) - right.y()) * bottomRightSlope); 943 967 944 968 Q16Dot16 rowTop, rowBottomLeft, rowBottomRight, rowTopLeft, rowTopRight, rowBottom; … … 955 979 rowTop = qMax(iTopFP, yTopFP); 956 980 topLeftIntersectAf = leftIntersectAf + 957 Q16Dot16Multiply( leftSlopeFP, rowTop - iTopFP);981 Q16Dot16Multiply(topLeftSlopeFP, rowTop - iTopFP); 958 982 topRightIntersectAf = rightIntersectAf + 959 Q16Dot16Multiply( rightSlopeFP, rowTop - iTopFP);983 Q16Dot16Multiply(topRightSlopeFP, rowTop - iTopFP); 960 984 961 985 Q16Dot16 yFP = iTopFP; … … 969 993 if (yFP == iLeftFP) { 970 994 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); 974 998 } else { 975 999 topLeftIntersectBf = leftIntersectBf; 976 bottomLeftIntersectAf = leftIntersectAf + leftSlopeFP;1000 bottomLeftIntersectAf = leftIntersectAf + topLeftSlopeFP; 977 1001 } 978 1002 979 1003 if (yFP == iRightFP) { 980 1004 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); 984 1008 } else { 985 1009 topRightIntersectBf = rightIntersectBf; 986 bottomRightIntersectAf = rightIntersectAf + rightSlopeFP;1010 bottomRightIntersectAf = rightIntersectAf + topRightSlopeFP; 987 1011 } 988 1012 989 1013 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); 992 1016 } else { 993 bottomLeftIntersectBf = leftIntersectBf + rightSlopeFP;994 bottomRightIntersectBf = rightIntersectBf + leftSlopeFP;1017 bottomLeftIntersectBf = leftIntersectBf + bottomLeftSlopeFP; 1018 bottomRightIntersectBf = rightIntersectBf + bottomRightSlopeFP; 995 1019 } 996 1020 … … 1037 1061 excluded += intersectPixelFP(x, rowTop, rowBottomLeft, 1038 1062 bottomLeftIntersectAf, topLeftIntersectAf, 1039 leftSlopeFP, -rightSlopeFP);1063 topLeftSlopeFP, invTopLeftSlopeFP); 1040 1064 if (yFP >= iLeftFP) 1041 1065 excluded += intersectPixelFP(x, rowTopLeft, rowBottom, 1042 1066 topLeftIntersectBf, bottomLeftIntersectBf, 1043 rightSlopeFP, -leftSlopeFP);1067 bottomLeftSlopeFP, invBottomLeftSlopeFP); 1044 1068 1045 1069 if (x >= rightMin) { … … 1047 1071 excluded += (rowBottomRight - rowTop) - intersectPixelFP(x, rowTop, rowBottomRight, 1048 1072 topRightIntersectAf, bottomRightIntersectAf, 1049 rightSlopeFP, -leftSlopeFP);1073 topRightSlopeFP, invTopRightSlopeFP); 1050 1074 if (yFP >= iRightFP) 1051 1075 excluded += (rowBottom - rowTopRight) - intersectPixelFP(x, rowTopRight, rowBottom, 1052 1076 bottomRightIntersectBf, topRightIntersectBf, 1053 leftSlopeFP, -rightSlopeFP);1077 bottomRightSlopeFP, invBottomRightSlopeFP); 1054 1078 } 1055 1079 … … 1069 1093 excluded += (rowBottomRight - rowTop) - intersectPixelFP(x, rowTop, rowBottomRight, 1070 1094 topRightIntersectAf, bottomRightIntersectAf, 1071 rightSlopeFP, -leftSlopeFP);1095 topRightSlopeFP, invTopRightSlopeFP); 1072 1096 if (yFP >= iRightFP) 1073 1097 excluded += (rowBottom - rowTopRight) - intersectPixelFP(x, rowTopRight, rowBottom, 1074 1098 bottomRightIntersectBf, topRightIntersectBf, 1075 leftSlopeFP, -rightSlopeFP);1099 bottomRightSlopeFP, invBottomRightSlopeFP); 1076 1100 1077 1101 Q16Dot16 coverage = rowHeight - excluded; … … 1081 1105 } 1082 1106 1083 leftIntersectAf += leftSlopeFP;1084 leftIntersectBf += rightSlopeFP;1085 rightIntersectAf += rightSlopeFP;1086 rightIntersectBf += leftSlopeFP;1107 leftIntersectAf += topLeftSlopeFP; 1108 leftIntersectBf += bottomLeftSlopeFP; 1109 rightIntersectAf += topRightSlopeFP; 1110 rightIntersectBf += bottomRightSlopeFP; 1087 1111 topLeftIntersectAf = leftIntersectAf; 1088 1112 topRightIntersectAf = rightIntersectAf; … … 1098 1122 int iMiddle = qMin(iLeft, iRight); 1099 1123 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); 1104 1128 1105 1129 int ny; … … 1123 1147 } 1124 1148 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); 1129 1153 #undef DO_SEGMENT 1130 1154 } … … 1176 1200 1177 1201 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;1184 1202 } 1185 1203
Note:
See TracChangeset
for help on using the changeset viewer.