1 /***********************************************************
3 Copyright (c) 1987 X Consortium
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of the X Consortium shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from the X Consortium.
27 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
31 Permission to use, copy, modify, and distribute this software and its
32 documentation for any purpose and without fee is hereby granted,
33 provided that the above copyright notice appear in all copies and that
34 both that copyright notice and this permission notice appear in
35 supporting documentation, and that the name of Digital not be
36 used in advertising or publicity pertaining to distribution of the
37 software without specific, written prior permission.
39 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
40 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
41 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
47 ******************************************************************/
48 /* $XConsortium: mfbpixmap.c,v 5.13 94/04/17 20:28:28 dpw Exp $ */
51 written by drewry, september 1986
53 on a monchrome device, a pixmap is a bitmap.
57 #include "scrnintstr.h"
58 #include "pixmapstr.h"
67 mfbCreatePixmap (pScreen, width, height, depth)
79 paddedWidth = BitmapBytePad(width);
80 datasize = height * paddedWidth;
81 pPixmap = AllocatePixmap(pScreen, datasize);
84 pPixmap->drawable.type = DRAWABLE_PIXMAP;
85 pPixmap->drawable.class = 0;
86 pPixmap->drawable.pScreen = pScreen;
87 pPixmap->drawable.depth = depth;
88 pPixmap->drawable.bitsPerPixel = depth;
89 pPixmap->drawable.id = 0;
90 pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
91 pPixmap->drawable.x = 0;
92 pPixmap->drawable.y = 0;
93 pPixmap->drawable.width = width;
94 pPixmap->drawable.height = height;
95 pPixmap->devKind = paddedWidth;
98 pPixmap->devPrivate.ptr = datasize ?
99 (pointer)((char *)pPixmap + pScreen->totalPixmapSize) : NULL;
101 pPixmap->devPrivate.ptr = (pointer)(pPixmap + 1);
107 mfbDestroyPixmap(pPixmap)
110 if(--pPixmap->refcnt)
119 register PixmapPtr pSrc;
121 register PixmapPtr pDst;
125 size = pSrc->drawable.height * pSrc->devKind;
126 pScreen = pSrc->drawable.pScreen;
127 pDst = (*pScreen->CreatePixmap) (pScreen, pSrc->drawable.width,
128 pSrc->drawable.height, pSrc->drawable.depth);
131 memmove((char *)pDst->devPrivate.ptr, (char *)pSrc->devPrivate.ptr, size);
136 /* replicates a pattern to be a full 32 bits wide.
137 relies on the fact that each scnaline is longword padded.
138 doesn't do anything if pixmap is not a factor of 32 wide.
139 changes width field of pixmap if successful, so that the fast
140 XRotatePixmap code gets used if we rotate the pixmap later.
142 calculate number of times to repeat
143 for each scanline of pattern
144 zero out area to be filled with replicate
145 left shift and or in original as many times as needed
148 mfbPadPixmap(pPixmap)
151 register int width = pPixmap->drawable.width;
153 register PixelType mask;
154 register PixelType *p;
155 register PixelType bits; /* real pattern bits */
157 int rep; /* repeat count for pattern */
163 if (rep*width != PPW)
166 mask = endtab[width];
168 p = (PixelType *)(pPixmap->devPrivate.ptr);
169 for (h=0; h < pPixmap->drawable.height; h++)
175 bits = SCRRIGHT(bits, width);
180 pPixmap->drawable.width = PPW;
183 /* Rotates pixmap pPix by w pixels to the right on the screen. Assumes that
184 * words are PPW bits wide, and that the least significant bit appears on the
188 mfbXRotatePixmap(pPix, rw)
192 register PixelType *pw, *pwFinal;
193 register PixelType t;
195 if (pPix == NullPixmap)
198 pw = (PixelType *)pPix->devPrivate.ptr;
199 rw %= (int)pPix->drawable.width;
201 rw += (int)pPix->drawable.width;
202 if(pPix->drawable.width == PPW)
204 pwFinal = pw + pPix->drawable.height;
208 *pw++ = SCRRIGHT(t, rw) |
209 (SCRLEFT(t, (PPW-rw)) & endtab[rw]);
214 /* We no longer do this. Validate doesn't try to rotate odd-size
215 * tiles or stipples. mfbUnnatural<tile/stipple>FS works directly off
216 * the unrotate tile/stipple in the GC
218 ErrorF("X internal error: trying to rotate odd-sized pixmap.\n");
223 /* Rotates pixmap pPix by h lines. Assumes that h is always less than
228 mfbYRotatePixmap(pPix, rh)
229 register PixmapPtr pPix;
232 int nbyDown; /* bytes to move down to row 0; also offset of
234 int nbyUp; /* bytes to move up to line rh; also
235 offset of first line moved down to 0 */
240 if (pPix == NullPixmap)
242 height = (int) pPix->drawable.height;
247 pbase = (char *)pPix->devPrivate.ptr;
249 nbyDown = rh * pPix->devKind;
250 nbyUp = (pPix->devKind * height) - nbyDown;
251 if(!(ptmp = (char *)ALLOCATE_LOCAL(nbyUp)))
254 memmove(ptmp, pbase, nbyUp); /* save the low rows */
255 memmove(pbase, pbase+nbyUp, nbyDown); /* slide the top rows down */
256 memmove(pbase+nbyDown, ptmp, nbyUp); /* move lower rows up to row rh */
257 DEALLOCATE_LOCAL(ptmp);
261 mfbCopyRotatePixmap(psrcPix, ppdstPix, xrot, yrot)
262 register PixmapPtr psrcPix, *ppdstPix;
265 register PixmapPtr pdstPix;
267 if ((pdstPix = *ppdstPix) &&
268 (pdstPix->devKind == psrcPix->devKind) &&
269 (pdstPix->drawable.height == psrcPix->drawable.height))
271 memmove((char *)pdstPix->devPrivate.ptr,
272 (char *)psrcPix->devPrivate.ptr,
273 psrcPix->drawable.height * psrcPix->devKind);
274 pdstPix->drawable.width = psrcPix->drawable.width;
275 pdstPix->drawable.serialNumber = NEXT_SERIAL_NUMBER;
281 (*pdstPix->drawable.pScreen->DestroyPixmap)(pdstPix);
282 *ppdstPix = pdstPix = mfbCopyPixmap(psrcPix);
286 mfbPadPixmap(pdstPix);
288 mfbXRotatePixmap(pdstPix, xrot);
290 mfbYRotatePixmap(pdstPix, yrot);