Example #1
0
static void
_fbSegment(DrawablePtr drawable, GCPtr gc, const BoxRec *b, void *_data)
{
	struct fbSegment *data = _data;
	const unsigned int bias = miGetZeroLineBias(drawable->pScreen);
	int adx, ady;               /* abs values of dx and dy */
	int sdx, sdy;               /* sign of dx and dy */
	int e, e1, e2, e3;          /* bresenham error and increments */
	int len, axis, octant;
	int dashoff, doff;
	unsigned int oc1, oc2;

	DBG(("%s box=(%d, %d),(%d, %d)\n",
	     __FUNCTION__, b->x1, b->y1, b->x2, b->y2));

	CalcLineDeltas(data->x1, data->y1, data->x2, data->y2,
		       adx, ady, sdx, sdy, 1, 1, octant);

	if (adx > ady) {
		axis = X_AXIS;
		e1 = ady << 1;
		e2 = e1 - (adx << 1);
		e = e1 - adx;
		len = adx;
	} else {
		axis = Y_AXIS;
		e1 = adx << 1;
		e2 = e1 - (ady << 1);
		e = e1 - ady;
		SetYMajorOctant(octant);
		len = ady;
	}

	FIXUP_ERROR(e, octant, bias);

	/*
	 * Adjust error terms to compare against zero
	 */
	e3 = e2 - e1;
	e = e - e1;

	if (data->drawLast)
		len++;
	dashoff = *data->dashOffset;
	*data->dashOffset = dashoff + len;

	oc1 = 0;
	oc2 = 0;
	OUTCODES(oc1, data->x1, data->y1, b);
	OUTCODES(oc2, data->x2, data->y2, b);
	if ((oc1 | oc2) == 0) {
		data->bres(drawable, gc, dashoff,
			   sdx, sdy, axis, data->x1, data->y1, e, e1, e3, len);
	} else if (oc1 & oc2) {
	} else {
		int new_x1 = data->x1, new_y1 = data->y1;
		int new_x2 = data->x2, new_y2 = data->y2;
		int clip1 = 0, clip2 = 0;
		int clipdx, clipdy;
		int err;

		if (miZeroClipLine(b->x1, b->y1, b->x2-1, b->y2-1,
				   &new_x1, &new_y1, &new_x2, &new_y2,
				   adx, ady, &clip1, &clip2,
				   octant, bias, oc1, oc2) == -1)
			return;

		if (axis == X_AXIS)
			len = abs(new_x2 - new_x1);
		else
			len = abs(new_y2 - new_y1);
		if (clip2 != 0 || data->drawLast)
			len++;
		if (len) {
			/* unwind bresenham error term to first point */
			doff = dashoff;
			err = e;
			if (clip1) {
				clipdx = abs(new_x1 - data->x1);
				clipdy = abs(new_y1 - data->y1);
				if (axis == X_AXIS) {
					doff += clipdx;
					err += e3 * clipdy + e1 * clipdx;
				} else {
					doff += clipdy;
					err += e3 * clipdx + e1 * clipdy;
				}
			}
			data->bres(drawable, gc, doff,
				   sdx, sdy, axis, new_x1, new_y1,
				   err, e1, e3, len);
		}
	}
}
Example #2
0
void
fbSegment(DrawablePtr pDrawable,
          GCPtr pGC,
          int x1, int y1, int x2, int y2, Bool drawLast, int *dashOffset)
{
    FbBres *bres;
    RegionPtr pClip = fbGetCompositeClip(pGC);
    BoxPtr pBox;
    int nBox;
    int adx;                    /* abs values of dx and dy */
    int ady;
    int signdx;                 /* sign of dx and dy */
    int signdy;
    int e, e1, e2, e3;          /* bresenham error and increments */
    int len;                    /* length of segment */
    int axis;                   /* major axis */
    int octant;
    int dashoff;
    int doff;
    unsigned int bias = miGetZeroLineBias(pDrawable->pScreen);
    unsigned int oc1;           /* outcode of point 1 */
    unsigned int oc2;           /* outcode of point 2 */

    nBox = RegionNumRects(pClip);
    pBox = RegionRects(pClip);

    bres = fbSelectBres(pDrawable, pGC);

    CalcLineDeltas(x1, y1, x2, y2, adx, ady, signdx, signdy, 1, 1, octant);

    if (adx > ady) {
        axis = X_AXIS;
        e1 = ady << 1;
        e2 = e1 - (adx << 1);
        e = e1 - adx;
        len = adx;
    }
    else {
        axis = Y_AXIS;
        e1 = adx << 1;
        e2 = e1 - (ady << 1);
        e = e1 - ady;
        SetYMajorOctant(octant);
        len = ady;
    }

    FIXUP_ERROR(e, octant, bias);

    /*
     * Adjust error terms to compare against zero
     */
    e3 = e2 - e1;
    e = e - e1;

    /* we have bresenham parameters and two points.
       all we have to do now is clip and draw.
     */

    if (drawLast)
        len++;
    dashoff = *dashOffset;
    *dashOffset = dashoff + len;
    while (nBox--) {
        oc1 = 0;
        oc2 = 0;
        OUTCODES(oc1, x1, y1, pBox);
        OUTCODES(oc2, x2, y2, pBox);
        if ((oc1 | oc2) == 0) {
            (*bres) (pDrawable, pGC, dashoff,
                     signdx, signdy, axis, x1, y1, e, e1, e3, len);
            break;
        }
        else if (oc1 & oc2) {
            pBox++;
        }
        else {
            int new_x1 = x1, new_y1 = y1, new_x2 = x2, new_y2 = y2;
            int clip1 = 0, clip2 = 0;
            int clipdx, clipdy;
            int err;

            if (miZeroClipLine(pBox->x1, pBox->y1, pBox->x2 - 1,
                               pBox->y2 - 1,
                               &new_x1, &new_y1, &new_x2, &new_y2,
                               adx, ady, &clip1, &clip2,
                               octant, bias, oc1, oc2) == -1) {
                pBox++;
                continue;
            }

            if (axis == X_AXIS)
                len = abs(new_x2 - new_x1);
            else
                len = abs(new_y2 - new_y1);
            if (clip2 != 0 || drawLast)
                len++;
            if (len) {
                /* unwind bresenham error term to first point */
                doff = dashoff;
                err = e;
                if (clip1) {
                    clipdx = abs(new_x1 - x1);
                    clipdy = abs(new_y1 - y1);
                    if (axis == X_AXIS) {
                        doff += clipdx;
                        err += e3 * clipdy + e1 * clipdx;
                    }
                    else {
                        doff += clipdy;
                        err += e3 * clipdx + e1 * clipdy;
                    }
                }
                (*bres) (pDrawable, pGC, doff,
                         signdx, signdy, axis, new_x1, new_y1,
                         err, e1, e3, len);
            }
            pBox++;
        }
    }                           /* while (nBox--) */
}