|
|
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: /* $Header: mfbpixmap.c,v 1.45 87/09/07 19:03:20 rws Exp $ */
25:
26: /* pixmap management
27: written by drewry, september 1986
28:
29: on a monchrome device, a pixmap is a bitmap.
30: */
31:
32: #include "Xmd.h"
33: #include "pixmapstr.h"
34: #include "maskbits.h"
35:
36: #include "mfb.h"
37: #include "mi.h"
38:
39: #include "servermd.h"
40:
41: PixmapPtr
42: mfbCreatePixmap (pScreen, width, height, depth)
43: ScreenPtr pScreen;
44: int width;
45: int height;
46: int depth;
47: {
48: register PixmapPtr pPixmap;
49: int size;
50:
51: if (depth != 1)
52: return (PixmapPtr)NULL;
53:
54: pPixmap = (PixmapPtr)Xalloc(sizeof(PixmapRec));
55: pPixmap->drawable.type = DRAWABLE_PIXMAP;
56: pPixmap->drawable.pScreen = pScreen;
57: pPixmap->drawable.depth = 1;
58: pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
59: pPixmap->width = width;
60: pPixmap->height = height;
61: pPixmap->devKind = PixmapBytePad(width, 1);
62: pPixmap->refcnt = 1;
63: size = height * pPixmap->devKind;
64:
65: if ( !(pPixmap->devPrivate = (pointer)Xalloc(size)))
66: {
67: Xfree(pPixmap);
68: return (PixmapPtr)NULL;
69: }
70: else
71: bzero((char *)pPixmap->devPrivate, size);
72: return pPixmap;
73: }
74:
75: Bool
76: mfbDestroyPixmap(pPixmap)
77: PixmapPtr pPixmap;
78: {
79: /* BOGOSITY ALERT */
80: if ((unsigned)pPixmap < 42)
81: return TRUE;
82:
83: if(--pPixmap->refcnt)
84: return TRUE;
85: Xfree(pPixmap->devPrivate);
86: Xfree(pPixmap);
87: return TRUE;
88: }
89:
90:
91: PixmapPtr
92: mfbCopyPixmap(pSrc)
93: register PixmapPtr pSrc;
94: {
95: register PixmapPtr pDst;
96: register int *pDstPriv, *pSrcPriv, *pDstMax;
97: int size;
98:
99: pDst = (PixmapPtr) Xalloc(sizeof(PixmapRec));
100: pDst->drawable.type = pSrc->drawable.type;
101: pDst->drawable.pScreen = pSrc->drawable.pScreen;
102: pDst->width = pSrc->width;
103: pDst->height = pSrc->height;
104: pDst->drawable.depth = pSrc->drawable.depth;
105: pDst->devKind = pSrc->devKind;
106: pDst->refcnt = 1;
107:
108: size = pDst->height * pDst->devKind;
109: pDstPriv = (int *) Xalloc(size);
110: pDst->devPrivate = (pointer) pDstPriv;
111: if (!(pDstPriv))
112: {
113: Xfree(pDst);
114: return NullPixmap;
115: }
116: else
117: bzero((char *) pDstPriv, size);
118: pSrcPriv = (int *)pSrc->devPrivate;
119: pDstMax = pDstPriv + (size >> 2);
120: /* Copy words */
121: while(pDstPriv < pDstMax)
122: {
123: *pDstPriv++ = *pSrcPriv++;
124: }
125:
126: return pDst;
127: }
128:
129:
130: /* replicates a pattern to be a full 32 bits wide.
131: relies on the fact that each scnaline is longword padded.
132: doesn't do anything if pixmap is not a factor of 32 wide.
133: changes width field of pixmap if successful, so that the fast
134: XRotatePixmap code gets used if we rotate the pixmap later.
135:
136: calculate number of times to repeat
137: for each scanline of pattern
138: zero out area to be filled with replicate
139: left shift and or in original as many times as needed
140:
141: returns TRUE iff pixmap was, or could be padded to be, 32 bits wide.
142: */
143: Bool
144: mfbPadPixmap(pPixmap)
145: PixmapPtr pPixmap;
146: {
147: register int width = pPixmap->width;
148: register int h;
149: register int mask;
150: register unsigned int *p;
151: register unsigned int bits; /* real pattern bits */
152: register int i;
153: int rep; /* repeat count for pattern */
154:
155: if (width == 32)
156: return(TRUE);
157: if (width > 32)
158: return(FALSE);
159:
160: rep = 32/width;
161: if (rep*width != 32)
162: return(FALSE);
163:
164: mask = endtab[width];
165:
166: p = (unsigned int *)(pPixmap->devPrivate);
167: for (h=0; h < pPixmap->height; h++)
168: {
169: *p &= mask;
170: bits = *p;
171: for(i=1; i<rep; i++)
172: {
173: bits = SCRRIGHT(bits, width);
174: *p |= bits;
175: }
176: p++;
177: }
178: pPixmap->width = 32;
179: return(TRUE);
180: }
181:
182: /* Rotates pixmap pPix by w pixels to the right on the screen. Assumes that
183: * words are 32 bits wide, and that the least significant bit appears on the
184: * left.
185: */
186: mfbXRotatePixmap(pPix, rw)
187: PixmapPtr pPix;
188: register int rw;
189: {
190: register long *pw, *pwFinal;
191: register unsigned long t;
192:
193: if (pPix == NullPixmap)
194: return;
195:
196: pw = (long *)pPix->devPrivate;
197: rw %= pPix->width;
198: if (rw < 0)
199: rw += pPix->width;
200: if(pPix->width == 32)
201: {
202: pwFinal = pw + pPix->height;
203: while(pw < pwFinal)
204: {
205: t = *pw;
206: *pw++ = SCRRIGHT(t, rw) |
207: (SCRLEFT(t, (32-rw)) & endtab[rw]);
208: }
209: }
210: else
211: {
212: /* We no longer do this. Validate doesn't try to rotate odd-size
213: * tiles or stipples. mfbUnnatural<tile/stipple>FS works directly off
214: * the unrotate tile/stipple in the GC
215: */
216: ErrorF("X internal error: trying to rotate odd-sized pixmap.\n");
217: }
218:
219: }
220: /* Rotates pixmap pPix by h lines. Assumes that h is always less than
221: pPix->height
222: works on any width.
223: */
224: mfbYRotatePixmap(pPix, rh)
225: register PixmapPtr pPix;
226: int rh;
227: {
228: int nbyDown; /* bytes to move down to row 0; also offset of
229: row rh */
230: int nbyUp; /* bytes to move up to line rh; also
231: offset of first line moved down to 0 */
232: char *pbase;
233: char *ptmp;
234:
235: if (pPix == NullPixmap)
236: return;
237: rh %= pPix->height;
238: if (rh < 0)
239: rh += pPix->height;
240:
241: pbase = (char *)pPix->devPrivate;
242:
243: nbyDown = rh * pPix->devKind;
244: nbyUp = (pPix->devKind * pPix->height) - nbyDown;
245: if(!(ptmp = (char *)ALLOCATE_LOCAL(nbyUp)))
246: return;
247:
248: bcopy(pbase, ptmp, nbyUp); /* save the low rows */
249: bcopy(pbase+nbyUp, pbase, nbyDown); /* slide the top rows down */
250: bcopy(ptmp, pbase+nbyDown, nbyUp); /* move lower rows up to row rh */
251: DEALLOCATE_LOCAL(ptmp);
252: }
253:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.