|
|
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: /* pixmap management
25: written by drewry, september 1986
26:
27: on a monchrome device, a pixmap is a bitmap.
28: */
29:
30: #include "Xmd.h"
31: #include "servermd.h"
32: #include "pixmapstr.h"
33: #include "cfbmskbits.h"
34:
35: #include "cfb.h"
36: #include "mi.h"
37:
38: PixmapPtr
39: cfbCreatePixmap (pScreen, width, height, depth, format)
40: ScreenPtr pScreen;
41: int width;
42: int height;
43: int depth;
44: int format;
45: {
46: register PixmapPtr pPixmap;
47: int size;
48:
49: if (depth != 1 && depth != PSZ)
50: return (PixmapPtr)NULL;
51:
52: pPixmap = (PixmapPtr)Xalloc(sizeof(PixmapRec));
53: pPixmap->drawable.type = DRAWABLE_PIXMAP;
54: pPixmap->drawable.pScreen = pScreen;
55: pPixmap->drawable.depth = depth;
56: pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
57: pPixmap->width = width;
58: pPixmap->height = height;
59: pPixmap->devKind = PixmapBytePad(width, depth);
60: pPixmap->refcnt = 1;
61: size = height * pPixmap->devKind;
62:
63: if ( !(pPixmap->devPrivate = (pointer)Xalloc(size)))
64: {
65: Xfree(pPixmap);
66: return (PixmapPtr)NULL;
67: }
68: else
69: bzero((char *)pPixmap->devPrivate, size);
70: return pPixmap;
71: }
72:
73: Bool
74: cfbDestroyPixmap(pPixmap)
75: PixmapPtr pPixmap;
76: {
77: /* BOGOSITY ALERT */
78: if ((unsigned)pPixmap < 42)
79: return TRUE;
80:
81: if(--pPixmap->refcnt)
82: return TRUE;
83: Xfree(pPixmap->devPrivate);
84: Xfree(pPixmap);
85: return TRUE;
86: }
87:
88:
89: PixmapPtr
90: cfbCopyPixmap(pSrc)
91: register PixmapPtr pSrc;
92: {
93: register PixmapPtr pDst;
94: register int *pDstPriv, *pSrcPriv, *pDstMax;
95: int size;
96:
97: pDst = (PixmapPtr) Xalloc(sizeof(PixmapRec));
98: pDst->drawable.type = pSrc->drawable.type;
99: pDst->drawable.pScreen = pSrc->drawable.pScreen;
100: pDst->width = pSrc->width;
101: pDst->height = pSrc->height;
102: pDst->drawable.depth = pSrc->drawable.depth;
103: pDst->devKind = pSrc->devKind;
104: pDst->refcnt = 1;
105:
106: size = pDst->height * pDst->devKind;
107: pDstPriv = (int *) Xalloc(size);
108: pDst->devPrivate = (pointer) pDstPriv;
109: if (!(pDstPriv))
110: {
111: Xfree(pDst);
112: return NullPixmap;
113: }
114: else
115: bzero((char *) pDstPriv, size);
116: pSrcPriv = (int *)pSrc->devPrivate;
117: pDstMax = pDstPriv + (size >> 2);
118: /* Copy words */
119: while(pDstPriv < pDstMax)
120: {
121: *pDstPriv++ = *pSrcPriv++;
122: }
123:
124: return pDst;
125: }
126:
127:
128: /* replicates a pattern to be a full 32 bits wide.
129: relies on the fact that each scnaline is longword padded.
130: doesn't do anything if pixmap is not a factor of 32 wide.
131: changes width field of pixmap if successful, so that the fast
132: cfbXRotatePixmap code gets used if we rotate the pixmap later.
133: cfbXRotatePixmap code gets used if we rotate the pixmap later.
134:
135: calculate number of times to repeat
136: for each scanline of pattern
137: zero out area to be filled with replicate
138: left shift and or in original as many times as needed
139:
140: returns TRUE iff pixmap was, or could be padded to be, 32 bits wide.
141: */
142: Bool
143: cfbPadPixmap(pPixmap)
144: PixmapPtr pPixmap;
145: {
146: /* do nothing for now; eventually pad to a 4-byte boundary. */
147: return( FALSE );
148: }
149:
150:
151: #ifdef notdef
152: /*
153: * cfb debugging routine -- assumes pixmap is 1 byte deep
154: */
155: static cfbdumppixmap(pPix)
156: PixmapPtr pPix;
157: {
158: unsigned int *pw;
159: char *psrc, *pdst;
160: int i, j;
161: char line[66];
162:
163: ErrorF( "pPixmap: 0x%x\n", pPix);
164: ErrorF( "%d wide %d high\n", pPix->width, pPix->height);
165: if (pPix->width > 64)
166: {
167: ErrorF( "too wide to see\n");
168: return;
169: }
170:
171: pw = (unsigned int *) pPix->devPrivate;
172: psrc = (char *) pw;
173:
174: /*
175: for ( i=0; i<pPix->height; ++i )
176: ErrorF( "0x%x\n", pw[i] );
177: */
178:
179: for ( i = 0; i < pPix->height; ++i ) {
180: pdst = line;
181: for(j = 0; j < pPix->width; j++) {
182: *pdst++ = *psrc++ ? 'X' : ' ' ;
183: }
184: *pdst++ = '\n';
185: *pdst++ = '\0';
186: ErrorF( "%s", line);
187: }
188: }
189: #endif notdef
190:
191: /* Rotates pixmap pPix by w pixels to the right on the screen. Assumes that
192: * words are 32 bits wide, and that the least significant bit appears on the
193: * left.
194: */
195: cfbXRotatePixmap(pPix, rw)
196: PixmapPtr pPix;
197: register int rw;
198: {
199: register long *pw, *pwFinal, *pwNew;
200: register unsigned long t;
201: int size;
202:
203: if (pPix == NullPixmap)
204: return;
205:
206: switch (((DrawablePtr) pPix)->depth) {
207: case PSZ:
208: break;
209: case 1:
210: cfbXRotateBitmap(pPix, rw);
211: return;
212: default:
213: ErrorF("cfbXRotatePixmap: unsupported depth %d\n", ((DrawablePtr) pPix)->depth);
214: return;
215: }
216: pw = (long *)pPix->devPrivate;
217: rw %= pPix->width;
218: if (rw < 0)
219: rw += pPix->width;
220: if(pPix->width == PPW)
221: {
222: pwFinal = pw + pPix->height;
223: while(pw < pwFinal)
224: {
225: t = *pw;
226: *pw++ = SCRRIGHT(t, rw) |
227: (SCRLEFT(t, (PPW-rw)) & cfbendtab[rw]);
228: }
229: }
230: else
231: {
232: pwNew = (long *) Xalloc( pPix->height * pPix->devKind);
233:
234: /* o.k., divide pw (the pixmap) in two vertically at (w - rw)
235: * pick up the part on the left and make it the right of the new
236: * pixmap. then pick up the part on the right and make it the left
237: * of the new pixmap.
238: * now hook in the new part and throw away the old. All done.
239: */
240: size = PixmapBytePad(pPix->width, PSZ) >> 2;
241: cfbQuickBlt(pw, pwNew, 0, 0, rw, 0, pPix->width - rw, pPix->height,
242: size, size);
243: cfbQuickBlt(pw, pwNew, pPix->width - rw, 0, 0, 0, rw, pPix->height,
244: size, size);
245: pPix->devPrivate = (pointer) pwNew;
246: Xfree((char *) pw);
247:
248: }
249:
250: }
251: /* Rotates pixmap pPix by h lines. Assumes that h is always less than
252: pPix->height
253: works on any width.
254: */
255: cfbYRotatePixmap(pPix, rh)
256: register PixmapPtr pPix;
257: int rh;
258: {
259: int nbyDown; /* bytes to move down to row 0; also offset of
260: row rh */
261: int nbyUp; /* bytes to move up to line rh; also
262: offset of first line moved down to 0 */
263: char *pbase;
264: char *ptmp;
265:
266: if (pPix == NullPixmap)
267: return;
268: switch (((DrawablePtr) pPix)->depth) {
269: case PSZ:
270: break;
271: case 1:
272: mfbYRotatePixmap(pPix, rh);
273: return;
274: default:
275: ErrorF("cfbYRotatePixmap: unsupported depth %d\n", ((DrawablePtr) pPix)->depth);
276: return;
277: }
278:
279: rh %= pPix->height;
280: if (rh < 0)
281: rh += pPix->height;
282:
283: pbase = (char *)pPix->devPrivate;
284:
285: nbyDown = rh * pPix->devKind;
286: nbyUp = (pPix->devKind * pPix->height) - nbyDown;
287: if(!(ptmp = (char *)ALLOCATE_LOCAL(nbyUp)))
288: return;
289:
290: bcopy(pbase, ptmp, nbyUp); /* save the low rows */
291: bcopy(pbase+nbyUp, pbase, nbyDown); /* slide the top rows down */
292: bcopy(ptmp, pbase+nbyDown, nbyUp); /* move lower rows up to row rh */
293: DEALLOCATE_LOCAL(ptmp);
294: }
295:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.