⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qrasterizer.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                }                if (rightWidth) {                    coverage[n] = rightWidth;                    x[n] = iRight;                    len[n] = 1;                    ++n;                }            }            for (int y = iTop; y <= iBottom; ++y) {                Q16Dot16 rowHeight = FloatToQ16Dot16(qMin(qreal(y + 1), pb.y()) - qMax(qreal(y), pa.y()));                for (int i = 0; i < n; ++i)                    buffer.addSpan(x[i], len[i], y, Q16Dot16ToInt(255 * Q16Dot16Multiply(rowHeight, coverage[i])));            }        } else { // aliased            int iTop = int(pa.y() + 0.5f);            int iBottom = int(pb.y() - 0.5f);            int iLeft = int(left + 0.5f);            int iRight = int(right - 0.5f);            buffer.setBoundingRect(iLeft, iTop, iRight, iBottom);            int iWidth = iRight - iLeft + 1;            for (int y = iTop; y <= iBottom; ++y)                buffer.addSpan(iLeft, iWidth, y, 255);        }    } else {        if (pa.y() > pb.y())            qSwap(pa, pb);        QPointF delta = pb - pa;        delta *= 0.5f * width;        QPointF perp(delta.y(), -delta.x());        if (squareCap) {            pa -= delta;            pb += delta;        }        QPointF top;        QPointF left;        QPointF right;        QPointF bottom;        if (pa.x() < pb.x()) {            top = pa + perp;            left = pa - perp;            right = pb + perp;            bottom = pb - perp;        } else {            top = pa - perp;            left = pb - perp;            right = pa + perp;            bottom = pb + perp;        }        qreal topBound = qBound(qreal(d->deviceRect.top()), top.y(), qreal(d->deviceRect.bottom()));        qreal bottomBound = qBound(qreal(d->deviceRect.top()), bottom.y(), qreal(d->deviceRect.bottom()));        if (qFuzzyCompare(topBound, bottomBound))            return;        qreal leftSlope = (left.x() - top.x()) / (left.y() - top.y());        qreal rightSlope = -1.0f / leftSlope;        Q16Dot16 leftSlopeFP = FloatToQ16Dot16(leftSlope);        Q16Dot16 rightSlopeFP = FloatToQ16Dot16(rightSlope);        if (d->antialiased) {            int iTop = int(topBound);            int iLeft = int(left.y());            int iRight = int(right.y());            int iBottom = int(bottomBound);            buffer.setBoundingRect(int(left.x()), iTop, int(right.x()), iBottom);            Q16Dot16 leftIntersectAf = FloatToQ16Dot16(top.x() + (iTop - top.y()) * leftSlope);            Q16Dot16 rightIntersectAf = FloatToQ16Dot16(top.x() + (iTop - top.y()) * rightSlope);            Q16Dot16 leftIntersectBf = 0;            Q16Dot16 rightIntersectBf = 0;            if (iLeft < iTop)                leftIntersectBf = FloatToQ16Dot16(left.x() + (iTop - left.y()) * rightSlope);            if (iRight < iTop)                rightIntersectBf = FloatToQ16Dot16(right.x() + (iTop - right.y()) * leftSlope);            Q16Dot16 rowTop, rowBottomLeft, rowBottomRight, rowTopLeft, rowTopRight, rowBottom;            Q16Dot16 topLeftIntersectAf, topLeftIntersectBf, topRightIntersectAf, topRightIntersectBf;            Q16Dot16 bottomLeftIntersectAf, bottomLeftIntersectBf, bottomRightIntersectAf, bottomRightIntersectBf;            int leftMin, leftMax, rightMin, rightMax;            for (int y = iTop; y <= iBottom; ++y) {                rowTop = FloatToQ16Dot16(qMax(qreal(y), top.y()));                rowBottomLeft = FloatToQ16Dot16(qMin(qreal(y + 1), left.y()));                rowBottomRight = FloatToQ16Dot16(qMin(qreal(y + 1), right.y()));                rowTopLeft = FloatToQ16Dot16(qMax(qreal(y), left.y()));                rowTopRight = FloatToQ16Dot16(qMax(qreal(y), right.y()));                rowBottom = FloatToQ16Dot16(qMin(qreal(y + 1), bottom.y()));                Q16Dot16 yFP = IntToQ16Dot16(y);                if (y == iTop) {                    topLeftIntersectAf = leftIntersectAf + Q16Dot16Multiply(leftSlopeFP, rowTop - yFP);                    topRightIntersectAf = rightIntersectAf + Q16Dot16Multiply(rightSlopeFP, rowTop - yFP);                } else {                    topLeftIntersectAf = leftIntersectAf;                    topRightIntersectAf = rightIntersectAf;                }                if (y == iLeft) {                    leftIntersectBf = FloatToQ16Dot16(left.x() + (y - left.y()) * rightSlope);                    topLeftIntersectBf = leftIntersectBf + Q16Dot16Multiply(rightSlopeFP, rowTopLeft - yFP);                    bottomLeftIntersectAf = leftIntersectAf + Q16Dot16Multiply(leftSlopeFP, rowBottomLeft - yFP);                } else {                    topLeftIntersectBf = leftIntersectBf;                    bottomLeftIntersectAf = leftIntersectAf + leftSlopeFP;                }                if (y == iRight) {                    rightIntersectBf = FloatToQ16Dot16(right.x() + (y - right.y()) * leftSlope);                    topRightIntersectBf = rightIntersectBf + Q16Dot16Multiply(leftSlopeFP, rowTopRight - yFP);                    bottomRightIntersectAf = rightIntersectAf + Q16Dot16Multiply(rightSlopeFP, rowBottomRight - yFP);                } else {                    topRightIntersectBf = rightIntersectBf;                    bottomRightIntersectAf = rightIntersectAf + rightSlopeFP;                }                if (y == iBottom) {                    bottomLeftIntersectBf = leftIntersectBf + Q16Dot16Multiply(rightSlopeFP, rowBottom - yFP);                    bottomRightIntersectBf = rightIntersectBf + Q16Dot16Multiply(leftSlopeFP, rowBottom - yFP);                } else {                    bottomLeftIntersectBf = leftIntersectBf + rightSlopeFP;                    bottomRightIntersectBf = rightIntersectBf + leftSlopeFP;                }                if (y < iLeft) {                    leftMin = Q16Dot16ToInt(bottomLeftIntersectAf);                    leftMax = Q16Dot16ToInt(topLeftIntersectAf);                } else if (y == iLeft) {                    leftMin = Q16Dot16ToInt(qMax(bottomLeftIntersectAf, topLeftIntersectBf));                    leftMax = Q16Dot16ToInt(qMax(topLeftIntersectAf, bottomLeftIntersectBf));                } else {                    leftMin = Q16Dot16ToInt(topLeftIntersectBf);                    leftMax = Q16Dot16ToInt(bottomLeftIntersectBf);                }                leftMin = qBound(d->deviceRect.left(), leftMin, d->deviceRect.right());                leftMax = qBound(d->deviceRect.left(), leftMax, d->deviceRect.right());                if (y < iRight) {                    rightMin = Q16Dot16ToInt(topRightIntersectAf);                    rightMax = Q16Dot16ToInt(bottomRightIntersectAf);                } else if (y == iRight) {                    rightMin = Q16Dot16ToInt(qMin(topRightIntersectAf, bottomRightIntersectBf));                    rightMax = Q16Dot16ToInt(qMin(bottomRightIntersectAf, topRightIntersectBf));                } else {                    rightMin = Q16Dot16ToInt(bottomRightIntersectBf);                    rightMax = Q16Dot16ToInt(topRightIntersectBf);                }                rightMin = qBound(d->deviceRect.left(), rightMin, d->deviceRect.right());                rightMax = qBound(d->deviceRect.left(), rightMax, d->deviceRect.right());                Q16Dot16 rowHeight = rowBottom - rowTop;                int x = leftMin;                while (x <= leftMax) {                    Q16Dot16 excluded = 0;                    if (y <= iLeft)                        excluded += intersectPixelFP(x, rowTop, rowBottomLeft,                                                     bottomLeftIntersectAf, topLeftIntersectAf,                                                     leftSlopeFP, -rightSlopeFP);                    if (y >= iLeft)                        excluded += intersectPixelFP(x, rowTopLeft, rowBottom,                                                     topLeftIntersectBf, bottomLeftIntersectBf,                                                     rightSlopeFP, -leftSlopeFP);                    if (x >= rightMin) {                        if (y <= iRight)                            excluded += (rowBottomRight - rowTop) - intersectPixelFP(x, rowTop, rowBottomRight,                                                                                     topRightIntersectAf, bottomRightIntersectAf,                                                                                     rightSlopeFP, -leftSlopeFP);                        if (y >= iRight)                            excluded += (rowBottom - rowTopRight) - intersectPixelFP(x, rowTopRight, rowBottom,                                                                                     bottomRightIntersectBf, topRightIntersectBf,                                                                                     leftSlopeFP, -rightSlopeFP);                    }                    Q16Dot16 coverage = rowHeight - excluded;                    buffer.addSpan(x, 1, y, Q16Dot16ToInt(255 * coverage));                    ++x;                }                if (x < rightMin) {                    buffer.addSpan(x, rightMin - x, y, Q16Dot16ToInt(255 * rowHeight));                    x = rightMin;                }                while (x <= rightMax) {                    Q16Dot16 excluded = 0;                    if (y <= iRight)                        excluded += (rowBottomRight - rowTop) - intersectPixelFP(x, rowTop, rowBottomRight,                                                                                 topRightIntersectAf, bottomRightIntersectAf,                                                                                 rightSlopeFP, -leftSlopeFP);                    if (y >= iRight)                        excluded += (rowBottom - rowTopRight) - intersectPixelFP(x, rowTopRight, rowBottom,                                                                                 bottomRightIntersectBf, topRightIntersectBf,                                                                                 leftSlopeFP, -rightSlopeFP);                    Q16Dot16 coverage = rowHeight - excluded;                    buffer.addSpan(x, 1, y, Q16Dot16ToInt(255 * coverage));                    ++x;                }                leftIntersectAf += leftSlopeFP;                leftIntersectBf += rightSlopeFP;                rightIntersectAf += rightSlopeFP;                rightIntersectBf += leftSlopeFP;            }        } else { // aliased            int iTop = int(top.y() + 0.5f);            int iLeft = int(left.y() - 0.5f);            int iRight = int(right.y() - 0.5f);            int iBottom = int(bottom.y() - 0.5f);            buffer.setBoundingRect((int)left.x(), iTop, (int)right.x(), iBottom);            Q16Dot16 leftIntersectAf = FloatToQ16Dot16(top.x() + 0.5f + (iTop + 0.5f - top.y()) * leftSlope);            Q16Dot16 leftIntersectBf = FloatToQ16Dot16(left.x() + 0.5f + (iLeft + 1.5f - left.y()) * rightSlope);            Q16Dot16 rightIntersectAf = FloatToQ16Dot16(top.x() - 0.5f + (iTop + 0.5f - top.y()) * rightSlope);            Q16Dot16 rightIntersectBf = FloatToQ16Dot16(right.x() - 0.5f + (iRight + 1.5f - right.y()) * leftSlope);            Q16Dot16 iMiddle = qMin(iLeft, iRight);            int y;            for (y = iTop; y <= iMiddle; ++y) {                if (y >= d->deviceRect.top() && y <= d->deviceRect.bottom()) {                    int x1 = Q16Dot16ToInt(leftIntersectAf);                    int x2 = Q16Dot16ToInt(rightIntersectAf);                    if (x2 >= d->deviceRect.left() && x1 <= d->deviceRect.right()) {                        x1 = qMax(x1, d->deviceRect.left());                        x2 = qMin(x2, d->deviceRect.right());                        buffer.addSpan(x1, x2 - x1 + 1, y, 255);                    }                }                leftIntersectAf += leftSlopeFP;                rightIntersectAf += rightSlopeFP;            }            for (; y <= iRight; ++y) {                if (y >= d->deviceRect.top() && y <= d->deviceRect.bottom()) {                    int x1 = Q16Dot16ToInt(leftIntersectBf);                    int x2 = Q16Dot16ToInt(rightIntersectAf);                    if (x2 >= d->deviceRect.left() && x1 <= d->deviceRect.right()) {                        x1 = qMax(x1, d->deviceRect.left());                        x2 = qMin(x2, d->deviceRect.right());                        buffer.addSpan(x1, x2 - x1 + 1, y, 255);                    }                }                leftIntersectBf += rightSlopeFP;                rightIntersectAf += rightSlopeFP;            }            for (; y <= iLeft; ++y) {                if (y >= d->deviceRect.top() && y <= d->deviceRect.bottom()) {                    int x1 = Q16Dot16ToInt(leftIntersectAf);                    int x2 = Q16Dot16ToInt(rightIntersectBf);                    if (x2 >= d->deviceRect.left() && x1 <= d->deviceRect.right()) {                        x1 = qMax(x1, d->deviceRect.left());                        x2 = qMin(x2, d->deviceRect.right());                        buffer.addSpan(x1, x2 - x1 + 1, y, 255);                    }                }                leftIntersectAf += leftSlopeFP;                rightIntersectBf += leftSlopeFP;            }            for (; y <= iBottom; ++y) {                if (y >= d->deviceRect.top() && y <= d->deviceRect.bottom()) {                    int x1 = Q16Dot16ToInt(leftIntersectBf);                    int x2 = Q16Dot16ToInt(rightIntersectBf);                    if (x2 >= d->deviceRect.left() && x1 <= d->deviceRect.right()) {                        x1 = qMax(x1, d->deviceRect.left());                        x2 = qMin(x2, d->deviceRect.right());                        buffer.addSpan(x1, x2 - x1 + 1, y, 255);                    }                }                leftIntersectBf += rightSlopeFP;                rightIntersectBf += leftSlopeFP;            }        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -