[comp.sys.sun] Addendum to "faster replrop" message

jef@helios.ee.lbl.gov (Jef Poskanzer) (01/05/89)

I did some more timings, and came up with the appended version.  It is a
few percent faster than the one in my original message.  If you Jfeel like
it, replace that one with this one when you post the message.

Jef

jef_pr_replrop(dpr, dx, dy, dw, dh, op, spr, sx, sy)
Pixrect *dpr, *spr;
int dx, dy, dw, dh, op, sx, sy;
{
	register int w, h, status;

	if ( spr == (Pixrect *) 0 ) {
		/* Special case the NULL pixrect. */
		w = dw;
		h = dh;
	} else {
		w = spr->pr_size.x;
		/* Avoid tiny horizontal blits. */
		while ( w < 256 ) w *= 2;
		if ( w > dw ) w = dw;

		h = spr->pr_size.y;
		/* But no edge effects vertically, so no problem. */
		if ( h > dh ) h = dh;
	}

	if (status = pr_replrop(dpr, dx, dy, w, h, op, spr, sx, sy))
		return status;

	op &= ~ PIX_DONTCLIP;

	while ( w < dw || h < dh ) {
		if ( w < dw )
			if (status = pr_rop(dpr, dx + w, dy, w, h, op, dpr, dx, dy))
				return status;
		if ( h < dh )
			if (status = pr_rop(dpr, dx, dy + h, w, h, op, dpr, dx, dy))
				return status;
		if ( w < dw && h < dh )
			if (status = pr_rop(dpr, dx + w, dy + h, w, h, op, dpr, dx, dy))
				return status;
		w *= 2;
		h *= 2;
	}
	return 0;
}