|
|
1.1 root 1: #ifndef lint
2: static char *rcsid_tile_c = "$Header: tile.c,v 10.1 86/11/19 10:44:34 jg Exp $";
3: #endif lint
4: /* Copyright 1985 Massachusetts Institute of Technology */
5:
6: /* tile.c - Perform a raster operation involving a pattern
7: *
8: * TileFill Patterns a portion of the screen
9: * DrawFilled Draw a filled generalized line/polygon/combination
10: * AlignTile Aligns tile to a given coordinates
11: *
12: * Changes and modifications by:
13: *
14: * Scott Bates
15: * Brown University
16: * IRIS, Box 1946
17: * Providence, RI 02912
18: *
19: *
20: * Copyright (c) 1986 Brown University
21: *
22: * Permission to use, copy, modify and distribute this software and its
23: * documentation for any purpose and without fee is hereby granted, provided
24: * that the above copyright notice appear in all copies, and that both
25: * that copyright notice and this permission notice appear in supporting
26: * documentation, and that the name of Brown University not be used in
27: * advertising or publicity pertaining to distribution of the software
28: * without specific, written prior permission. Brown University makes no
29: * representations about the suitability of this software for any purpose.
30: * It is provided "as-is" without express or implied warranty.
31: */
32:
33: #include "private.h"
34: #include "bitblt.h"
35:
36: /*
37: * Tile area of screen using a mask
38: */
39:
40: /*ARGSUSED*/
41: TileFill (tile, xoff, yoff, xymask, dstx, dsty, width, height,
42: clips, clipcount, func, zmask)
43: register PIXMAP *tile;
44: register BITMAP *xymask;
45: register width, height;
46: int xoff, yoff, dstx, dsty, zmask;
47: register func;
48: CLIP *clips;
49: {
50: u_short *clipmask = NILMASK;
51: register BITMAP *bm = (BITMAP *) tile->data;
52: register u_short *tilepattern;
53: u_short newtilepattern[TILE_SIZE];
54:
55: #ifdef TRACE_X
56: fprintf(stderr, "In TileFill\n");
57: fflush(stderr);
58: #endif TRACE_X
59:
60: /*
61: * There better be at least one plane
62: */
63:
64: if ((zmask & 1) == 0)
65: return;
66:
67: /*
68: * If pixmap needs to be inverted before being displayed
69: * remap funtion to reflect this change.
70: */
71:
72: func = SSMap[func | (tile->kind & InvertFlag)];
73:
74: /*
75: * Get tile. If pixmap has no associated bitmap then pixmap
76: * struct contains pointer to constant tile. Otherwise, it
77: * contains pointer to bitmap which points to the tile.
78: */
79:
80: if (PTYPE(tile) == ConstantPixmap) {
81: tilepattern = (u_short *) tile->data;
82: } else {
83: tilepattern = (u_short *) bm->data;
84:
85: /*
86: * Align tile to offset supplied
87: */
88:
89: if ((xoff | yoff) & 0x0F) {
90: AlignTile(tilepattern, newtilepattern, xoff, yoff);
91: tilepattern = newtilepattern;
92: }
93: }
94:
95: /*
96: * Clip xymask and destnation rectangle to minimum size
97: */
98:
99: if(xymask) {
100: width = MIN (xymask->width, width);
101: height = MIN (xymask->height, height);
102: clipmask = (u_short *) xymask->data;
103: }
104:
105: /*
106: * Fill in destination rectangle
107: */
108:
109: FillInRect(dstx, dsty, width, height, &DstRect);
110:
111: /*
112: * Tile area of screen using a mask
113: */
114:
115: CopyBits (tilepattern, NIL, NIL, NILRECT,
116: (u_short *) pbm.data, pbm.width, pbm.height, &DstRect,
117: clipmask, width, height, MAKE_TILE_RULE(func),
118: clipcount, clips);
119: }
120:
121: /*
122: * Draw a filled generalized line/polygon/combination
123: */
124:
125: /*ARGSUSED*/
126: DrawFilled (verts, vertcount, xbase, ybase, srcpix, tile, xoff, yoff,
127: clips, clipcount, func, zmask)
128: Vertex *verts;
129: register PIXMAP *tile;
130: int vertcount, xbase, ybase, srcpix, xoff, yoff, clipcount, zmask;
131: int func;
132: CLIP *clips;
133: {
134: BITMAP *xymask;
135: Vertex *newverts;
136: int newvertcount;
137:
138: #ifdef TRACE_X
139: fprintf(stderr, "In DrawFilled\n");
140: fflush(stderr);
141: #endif TRACE_X
142:
143: /*
144: * Limit draw operation to one plane
145: */
146:
147: if ((zmask & 1) == 0 || vertcount < 2)
148: return;
149:
150: /*
151: * Convert path list to absolute line segments
152: */
153:
154: if(PathListConverter(verts, vertcount, xbase, ybase, &newverts,
155: &newvertcount, FILL_PATH_LIST) == NULL) {
156: DeviceError("DrawCurve failure in PathListConverter()\n");
157: return;
158: }
159:
160: /*
161: * Make mask for polygon fill
162: */
163:
164: if((xymask = MakeMask(newverts, newvertcount)) == NULL) {
165: DeviceError("DrawFilled failure in MakeMask()\n");
166: return;
167: }
168:
169: /*
170: * Fill the polygon
171: */
172:
173: if(tile) {
174: /*
175: * Tile fill the polygon using the mask
176: */
177:
178: TileFill(tile, xoff, yoff, xymask, 0, 0, xymask->width,
179: xymask->height, clips, clipcount, func, zmask);
180: } else {
181: /*
182: * Pix fill the polygon using the mask
183: */
184:
185: PixFill(srcpix, xymask, 0, 0, xymask->width, xymask->height,
186: clips, clipcount, func, zmask);
187: }
188:
189: /*
190: * Free mask BITMAP and space used by converted vertex list
191: */
192:
193: FreeBitmap(xymask);
194: free((caddr_t)newverts);
195: }
196:
197: /*
198: * Align tile to offset provided.
199: * Note: tile is in IBM bit order not VAX
200: */
201:
202: static
203: AlignTile(src, dst, xoff, yoff)
204: register u_short *src, *dst;
205: register int xoff, yoff;
206: {
207: register int i;
208: register int shift;
209: u_short mask;
210:
211: #ifdef TRACE_X
212: fprintf(stderr, "In Align_Tile\n");
213: fflush(stderr);
214: #endif TRACE_X
215:
216: xoff &= 0x0F;
217: yoff = (TILE_HEIGHT - (yoff & 0x0F)) & 0x0F;
218: shift = (TILE_WIDTH - xoff) & 0x0F;
219: mask = (1 << xoff) - 1;
220:
221: for (i = 0; i < TILE_HEIGHT; i++) {
222: dst[i] = (src[yoff] >> xoff) | ((src[yoff] & mask) << shift);
223: yoff++;
224: yoff &= 0x0F;
225: }
226: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.