1 /* $XConsortium: cfbpixmap.c,v 5.14 94/04/17 20:28:56 dpw Exp $ */
2 /***********************************************************
4 Copyright (c) 1987 X Consortium
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 Except as contained in this notice, the name of the X Consortium shall not be
24 used in advertising or otherwise to promote the sale, use or other dealings
25 in this Software without prior written authorization from the X Consortium.
28 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
32 Permission to use, copy, modify, and distribute this software and its
33 documentation for any purpose and without fee is hereby granted,
34 provided that the above copyright notice appear in all copies and that
35 both that copyright notice and this permission notice appear in
36 supporting documentation, and that the name of Digital not be
37 used in advertising or publicity pertaining to distribution of the
38 software without specific, written prior permission.
40 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
41 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
42 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
43 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
44 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
45 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
48 ******************************************************************/
50 written by drewry, september 1986
52 on a monchrome device, a pixmap is a bitmap.
57 #include "scrnintstr.h"
58 #include "pixmapstr.h"
61 #include "cfbmskbits.h"
63 extern unsigned long endtab[];
66 cfbCreatePixmap (pScreen, width, height, depth)
76 paddedWidth = PixmapBytePad(width, depth);
77 datasize = height * paddedWidth;
78 pPixmap = AllocatePixmap(pScreen, datasize);
81 pPixmap->drawable.type = DRAWABLE_PIXMAP;
82 pPixmap->drawable.class = 0;
83 pPixmap->drawable.pScreen = pScreen;
84 pPixmap->drawable.depth = depth;
85 pPixmap->drawable.bitsPerPixel = BitsPerPixel(depth);
86 pPixmap->drawable.id = 0;
87 pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
88 pPixmap->drawable.x = 0;
89 pPixmap->drawable.y = 0;
90 pPixmap->drawable.width = width;
91 pPixmap->drawable.height = height;
92 pPixmap->devKind = paddedWidth;
95 pPixmap->devPrivate.ptr = datasize ?
96 (pointer)((char *)pPixmap + pScreen->totalPixmapSize) : NULL;
98 pPixmap->devPrivate.ptr = (pointer)(pPixmap + 1);
104 cfbDestroyPixmap(pPixmap)
107 if(--pPixmap->refcnt)
115 register PixmapPtr pSrc;
117 register PixmapPtr pDst;
121 size = pSrc->drawable.height * pSrc->devKind;
122 pScreen = pSrc->drawable.pScreen;
123 pDst = (*pScreen->CreatePixmap) (pScreen, pSrc->drawable.width,
124 pSrc->drawable.height, pSrc->drawable.depth);
127 memmove((char *)pDst->devPrivate.ptr, (char *)pSrc->devPrivate.ptr, size);
132 /* replicates a pattern to be a full 32 bits wide.
133 relies on the fact that each scnaline is longword padded.
134 doesn't do anything if pixmap is not a factor of 32 wide.
135 changes width field of pixmap if successful, so that the fast
136 cfbXRotatePixmap code gets used if we rotate the pixmap later.
137 cfbYRotatePixmap code gets used if we rotate the pixmap later.
139 calculate number of times to repeat
140 for each scanline of pattern
141 zero out area to be filled with replicate
142 left shift and or in original as many times as needed
145 cfbPadPixmap(pPixmap)
148 register int width = (pPixmap->drawable.width) * (pPixmap->drawable.bitsPerPixel);
150 register unsigned long mask;
151 register unsigned long *p;
152 register unsigned long bits; /* real pattern bits */
154 int rep; /* repeat count for pattern */
160 if (rep*width != PGSZ)
163 mask = endtab[width];
165 p = (unsigned long *)(pPixmap->devPrivate.ptr);
166 for (h=0; h < pPixmap->drawable.height; h++)
172 #if (BITMAP_BIT_ORDER == MSBFirst)
181 pPixmap->drawable.width = PGSZ/(pPixmap->drawable.bitsPerPixel);
187 * cfb debugging routine -- assumes pixmap is 1 byte deep
189 static cfbdumppixmap(pPix)
197 ErrorF( "pPixmap: 0x%x\n", pPix);
198 ErrorF( "%d wide %d high\n", pPix->drawable.width, pPix->drawable.height);
199 if (pPix->drawable.width > 64)
201 ErrorF( "too wide to see\n");
205 pw = (unsigned int *) pPix->devPrivate.ptr;
209 for ( i=0; i<pPix->drawable.height; ++i )
210 ErrorF( "0x%x\n", pw[i] );
213 for ( i = 0; i < pPix->drawable.height; ++i ) {
215 for(j = 0; j < pPix->drawable.width; j++) {
216 *pdst++ = *psrc++ ? 'X' : ' ' ;
225 /* Rotates pixmap pPix by w pixels to the right on the screen. Assumes that
226 * words are PGSZ bits wide, and that the least significant bit appears on the
230 cfbXRotatePixmap(pPix, rw)
234 register unsigned long *pw, *pwFinal;
235 register unsigned long t;
238 if (pPix == NullPixmap)
241 switch (((DrawablePtr) pPix)->bitsPerPixel) {
245 mfbXRotatePixmap(pPix, rw);
248 ErrorF("cfbXRotatePixmap: unsupported bitsPerPixel %d\n", ((DrawablePtr) pPix)->bitsPerPixel);
251 pw = (unsigned long *)pPix->devPrivate.ptr;
252 modulus (rw, (int) pPix->drawable.width, rot);
253 if(pPix->drawable.width == PPW)
255 pwFinal = pw + pPix->drawable.height;
259 *pw++ = SCRRIGHT(t, rot) |
260 (SCRLEFT(t, (PPW-rot)) & cfbendtab[rot]);
265 ErrorF("cfb internal error: trying to rotate odd-sized pixmap.\n");
267 register unsigned long *pwTmp;
270 tsize = PixmapBytePad(pPix->drawable.width - rot, pPix->drawable.depth);
271 pwTmp = (unsigned long *) ALLOCATE_LOCAL(pPix->drawable.height * tsize);
274 /* divide pw (the pixmap) in two vertically at (w - rot) and swap */
276 size = pPix->devKind >> SIZE0F(PixelGroup);
277 cfbQuickBlt((long *)pw, (long *)pwTmp,
279 (int)pPix->drawable.width - rot, (int)pPix->drawable.height,
281 cfbQuickBlt((long *)pw, (long *)pw,
282 (int)pPix->drawable.width - rot, 0, 0, 0,
283 rot, (int)pPix->drawable.height,
285 cfbQuickBlt((long *)pwTmp, (long *)pw,
287 (int)pPix->drawable.width - rot, (int)pPix->drawable.height,
289 DEALLOCATE_LOCAL(pwTmp);
294 /* Rotates pixmap pPix by h lines. Assumes that h is always less than
295 pPix->drawable.height
299 cfbYRotatePixmap(pPix, rh)
300 register PixmapPtr pPix;
303 int nbyDown; /* bytes to move down to row 0; also offset of
305 int nbyUp; /* bytes to move up to line rh; also
306 offset of first line moved down to 0 */
311 if (pPix == NullPixmap)
313 switch (((DrawablePtr) pPix)->bitsPerPixel) {
317 mfbYRotatePixmap(pPix, rh);
320 ErrorF("cfbYRotatePixmap: unsupported bitsPerPixel %d\n", ((DrawablePtr) pPix)->bitsPerPixel);
324 modulus (rh, (int) pPix->drawable.height, rot);
325 pbase = (char *)pPix->devPrivate.ptr;
327 nbyDown = rot * pPix->devKind;
328 nbyUp = (pPix->devKind * pPix->drawable.height) - nbyDown;
329 if(!(ptmp = (char *)ALLOCATE_LOCAL(nbyUp)))
332 memmove(ptmp, pbase, nbyUp); /* save the low rows */
333 memmove(pbase, pbase+nbyUp, nbyDown); /* slide the top rows down */
334 memmove(pbase+nbyDown, ptmp, nbyUp); /* move lower rows up to row rot */
335 DEALLOCATE_LOCAL(ptmp);
339 cfbCopyRotatePixmap(psrcPix, ppdstPix, xrot, yrot)
340 register PixmapPtr psrcPix, *ppdstPix;
343 register PixmapPtr pdstPix;
345 if ((pdstPix = *ppdstPix) &&
346 (pdstPix->devKind == psrcPix->devKind) &&
347 (pdstPix->drawable.height == psrcPix->drawable.height))
349 memmove((char *)pdstPix->devPrivate.ptr,
350 (char *)psrcPix->devPrivate.ptr,
351 psrcPix->drawable.height * psrcPix->devKind);
352 pdstPix->drawable.width = psrcPix->drawable.width;
353 pdstPix->drawable.depth = psrcPix->drawable.depth;
354 pdstPix->drawable.bitsPerPixel = psrcPix->drawable.bitsPerPixel;
355 pdstPix->drawable.serialNumber = NEXT_SERIAL_NUMBER;
361 (*pdstPix->drawable.pScreen->DestroyPixmap)(pdstPix);
362 *ppdstPix = pdstPix = cfbCopyPixmap(psrcPix);
366 cfbPadPixmap(pdstPix);
368 cfbXRotatePixmap(pdstPix, xrot);
370 cfbYRotatePixmap(pdstPix, yrot);