|
|
1.1 root 1: /*
2: Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
3: and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
4:
5: All Rights Reserved
6:
7: Permission to use, copy, modify, and distribute this software and its
8: documentation for any purpose and without fee is hereby granted,
9: provided that the above copyright notice appear in all copies and that
10: both that copyright notice and this permission notice appear in
11: supporting documentation, and that the names of Digital or MIT not be
12: used in advertising or publicity pertaining to distribution of the
13: software without specific, written prior permission.
14:
15: DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
16: ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
17: DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
18: ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
19: WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
20: ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
21: SOFTWARE.
22:
23: */
24:
25: #include "cfbmskbits.h"
26:
27: /* cfbQuickBlt -- a quick and dirty bitblit routine
28: * copies from psrcBase(xSrc, ySrc) to pdstBase(xDst, yDst) an array of bits
29: * w wide by h high. It is assumed that psrcBase and pdstBase point at
30: * things reasonable to bitblt between. It is assumed that all clipping has
31: * been done. It is also assumed that the rectangle fits on the destination
32: * (that is, that (pdstBase + (yDst * h) + w) is a bit in the destination).
33: * This routine does no error-checking of any type, CAVEAT HACKER
34: */
35: cfbQuickBlt(psrcBase, pdstBase, xSrc, ySrc, xDst, yDst, w, h, wSrc, wDst)
36: int *psrcBase, *pdstBase, /* first bits in pixmaps */
37: xSrc, ySrc, /* origin of source */
38: xDst, yDst, /* origin for destination */
39: w, /* width to blt */
40: h, /* height to blt */
41: wSrc, wDst; /* width of pixmaps */
42: {
43:
44: int *psrcLine, *pdstLine;
45: int xdir, ydir;
46: int nl, startmask, endmask, nlMiddle, *psrc, *pdst, tmpSrc;
47:
48: if(psrcBase + wSrc * h < pdstBase ||
49: pdstBase + wDst * h < psrcBase)
50: {
51: /* the areas don't overlap right and down is fine */
52: xdir = ydir = 1;
53: }
54: else if(ySrc < yDst) /* move right and up */
55: {
56: xdir = 1;
57: ydir = -1;
58: }
59: else if(ySrc > yDst) /* move right and down */
60: {
61: xdir = 1;
62: ydir = 1;
63: }
64: else if(xSrc < xDst) /* move left and down */
65: {
66: xdir = -1;
67: ydir = 1;
68: }
69: else /* if xSrc <= xDst */ /* move right and down */
70: {
71: xdir = 1;
72: ydir = 1;
73: }
74:
75: if (ydir == -1) /* start at last scanline of rectangle */
76: {
77: psrcLine = psrcBase + (((ySrc + h) -1) * wSrc);
78: pdstLine = pdstBase + (((yDst + h) -1) * wDst);
79: wSrc = -wSrc;
80: wDst = -wDst;
81: }
82: else /* start at first scanline */
83: {
84: psrcLine = psrcBase + (ySrc * wSrc);
85: pdstLine = pdstBase + (yDst * wDst);
86: }
87:
88: /* x direction doesn't matter for < 1 longword */
89: if (w <= PPW)
90: {
91: int srcBit, dstBit; /* bit offset of src and dst */
92:
93: pdstLine += (xDst >> PWSH);
94: psrcLine += (xSrc >> PWSH);
95: psrc = psrcLine;
96: pdst = pdstLine;
97:
98: srcBit = xSrc & PIM;
99: dstBit = xDst & PIM;
100:
101: while(h--)
102: {
103: getbits(psrc, srcBit, w, tmpSrc);
104: /*XXX*/ putbits(tmpSrc, dstBit, w, pdst, -1);
105: psrc += wSrc;
106: pdst += wDst;
107: }
108: }
109: else
110: {
111: register int xoffSrc; /* offset (>= 0, < 32) from which to
112: fetch whole longwords fetched
113: in src */
114: int nstart; /* number of ragged bits
115: at start of dst */
116: int nend; /* number of ragged bits at end
117: of dst */
118: int srcStartOver; /* pulling nstart bits from src
119: overflows into the next word? */
120:
121: maskbits(xDst, w, startmask, endmask, nlMiddle);
122: if (startmask)
123: nstart = PPW - (xDst & PIM);
124: else
125: nstart = 0;
126: if (endmask)
127: nend = (xDst + w) & PIM;
128: else
129: nend = 0;
130:
131: xoffSrc = ((xSrc & PIM) + nstart) & PIM;
132: srcStartOver = ((xSrc & PIM) + nstart) > PLST;
133:
134: if (xdir == 1) /* move left to right */
135: {
136: pdstLine += (xDst >> PWSH);
137: psrcLine += (xSrc >> PWSH);
138:
139: while (h--)
140: {
141: psrc = psrcLine;
142: pdst = pdstLine;
143:
144: if (startmask)
145: {
146: getbits(psrc, (xSrc & PIM), nstart, tmpSrc);
147: /*XXX*/ putbits(tmpSrc, (xDst & PIM), nstart, pdst, -1);
148: pdst++;
149: if (srcStartOver)
150: psrc++;
151: }
152:
153: nl = nlMiddle;
154: while (nl--)
155: {
156: getbits(psrc, xoffSrc, PPW, tmpSrc);
157: *pdst++ = tmpSrc;
158: psrc++;
159: }
160:
161: if (endmask)
162: {
163: getbits(psrc, xoffSrc, nend, tmpSrc);
164: /*XXX*/ putbits(tmpSrc, 0, nend, pdst, -1);
165: }
166:
167: psrcLine += wSrc;
168: pdstLine += wDst;
169: }
170: }
171: else /* move right to left */
172: {
173: pdstLine += ((xDst + w) >> PWSH);
174: psrcLine += (xSrc + w >> PWSH);
175: /* if fetch of last partial bits from source crosses
176: a longword boundary, start at the previous longword
177: */
178: if (xoffSrc + nend >= PPW)
179: --psrcLine;
180:
181: while (h--)
182: {
183: psrc = psrcLine;
184: pdst = pdstLine;
185:
186: if (endmask)
187: {
188: getbits(psrc, xoffSrc, nend, tmpSrc)
189: /*XXX*/ putbits(tmpSrc, 0, nend, pdst, -1)
190: }
191:
192: nl = nlMiddle;
193: while (nl--)
194: {
195: --psrc;
196: getbits(psrc, xoffSrc, PPW, tmpSrc)
197: *--pdst = tmpSrc;
198: }
199:
200: if (startmask)
201: {
202: if (srcStartOver)
203: --psrc;
204: --pdst;
205: getbits(psrc, (xSrc & PIM), nstart, tmpSrc)
206: /*XXX*/ putbits(tmpSrc, (xDst & PIM), nstart, pdst, -1)
207: }
208:
209: pdstLine += wDst;
210: psrcLine += wSrc;
211: }
212: } /* move right to left */
213: }
214: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.