summaryrefslogtreecommitdiff
path: root/dviware/beebe/src/fillrect.h
blob: 89a768bf697d3e51cbc357f74cca98bc61aa02bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* -*-C-*- fillrect.h */
/*-->fillrect*/
/**********************************************************************/
/****************************** fillrect ******************************/
/**********************************************************************/

void
fillrect(x,y,width,height)
COORDINATE x,y,width,height;		/* lower left corner, size */

/***********************************************************************
With the page origin (0,0) at the lower-left corner of the bitmap,  draw
a filled rectangle at (x,y).
***********************************************************************/

{
    register UNSIGN32 *p;
    register COORDINATE i,j,xloffset,xroffset,xlpart,xrpart;

    if ( ((x+width) <= 0) || (XSIZE <= x) || ((y+height) <= 0) ||
	(YSIZE <= y) )
	return;		/* Trivial reject -- rectangle outside page */
    else
    {
	xlpart = x/HOST_WORD_SIZE;
	xrpart = (x + width)/HOST_WORD_SIZE;
	xloffset = x % HOST_WORD_SIZE;
	xroffset = (x + width) % HOST_WORD_SIZE;
	for (j = 0; j < height; ++j)	    /* loop over raster lines */
	{
	    if (IN(0,y+j,YBIT-1))
	    {
		p = BITMAP(y+j,xlpart);
		if (IN(0,xlpart,XBIT-1))
		    if (xlpart < xrpart) /* set bits in left partial word */
			*p |= rightones[xloffset];
		    else    /* set bits in middle of left partial word */
			*p |= (rightones[xloffset] & ~rightones[xroffset]);

		++p;
		for (i = xlpart+1; i < xrpart; (++p,++i))
		    if (IN(0,i,XBIT-1))
			*p = (UNSIGN32)ONES;  /* set complete words */

		/* finally, set bits in right partial word */
		if ((xlpart < xrpart) && IN(0,xrpart,XBIT-1))
		    *BITMAP(y+j,xrpart) |= ~rightones[xroffset];
	    }
	}
    }
}