(file) Return to iplpixmap.c CVS log (file) (dir) Up to [XFree86 CVS] / xc / programs / Xserver / iplan2p4

  1 dawes 3.0 /* $XFree86$ */
  2           /* $XConsortium: iplpixmap.c,v 5.14 94/04/17 20:28:56 dpw Exp $ */
  3           /***********************************************************
  4           
  5           Copyright (c) 1987  X Consortium
  6           
  7           Permission is hereby granted, free of charge, to any person obtaining a copy
  8           of this software and associated documentation files (the "Software"), to deal
  9           in the Software without restriction, including without limitation the rights
 10           to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 11           copies of the Software, and to permit persons to whom the Software is
 12           furnished to do so, subject to the following conditions:
 13           
 14           The above copyright notice and this permission notice shall be included in
 15           all copies or substantial portions of the Software.
 16           
 17           THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 18           IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 19           FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 20           X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 21           AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 22 dawes 3.0 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 23           
 24           Except as contained in this notice, the name of the X Consortium shall not be
 25           used in advertising or otherwise to promote the sale, use or other dealings
 26           in this Software without prior written authorization from the X Consortium.
 27           
 28           
 29           Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
 30           
 31                                   All Rights Reserved
 32           
 33           Permission to use, copy, modify, and distribute this software and its 
 34           documentation for any purpose and without fee is hereby granted, 
 35           provided that the above copyright notice appear in all copies and that
 36           both that copyright notice and this permission notice appear in 
 37           supporting documentation, and that the name of Digital not be
 38           used in advertising or publicity pertaining to distribution of the
 39           software without specific, written prior permission.  
 40           
 41           DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
 42           ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
 43 dawes 3.0 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
 44           ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 45           WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
 46           ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 47           SOFTWARE.
 48           
 49           ******************************************************************/
 50           /* pixmap management
 51              written by drewry, september 1986
 52           
 53              on a monchrome device, a pixmap is a bitmap.
 54           */
 55           
 56           /* Modified nov 94 by Martin Schaller (Martin_Schaller@maus.r.de) for use with
 57           interleaved planes */
 58           
 59           #include "Xmd.h"
 60           #include "servermd.h"
 61           #include "scrnintstr.h"
 62           #include "pixmapstr.h"
 63           #include "mi.h"
 64 dawes 3.0 #include "ipl.h"
 65           #include "iplmskbits.h"
 66           
 67           extern unsigned long endtab[];
 68           
 69           PixmapPtr
 70           iplCreatePixmap (pScreen, width, height, depth)
 71               ScreenPtr	pScreen;
 72               int		width;
 73               int		height;
 74               int		depth;
 75           {
 76               PixmapPtr pPixmap;
 77               int datasize;
 78               int paddedWidth;
 79               int ipad=INTER_PLANES*2 - 1;
 80           
 81               paddedWidth = PixmapBytePad(width, depth);
 82               paddedWidth = (paddedWidth + ipad) & ~ipad;
 83               datasize = height * paddedWidth;
 84               pPixmap = AllocatePixmap(pScreen, datasize);
 85 dawes 3.0     if (!pPixmap)
 86           	return NullPixmap;
 87               pPixmap->drawable.type = DRAWABLE_PIXMAP;
 88               pPixmap->drawable.class = 0;
 89               pPixmap->drawable.pScreen = pScreen;
 90               pPixmap->drawable.depth = depth;
 91               pPixmap->drawable.bitsPerPixel = BitsPerPixel(depth);
 92               pPixmap->drawable.id = 0;
 93               pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
 94               pPixmap->drawable.x = 0;
 95               pPixmap->drawable.y = 0;
 96               pPixmap->drawable.width = width;
 97               pPixmap->drawable.height = height;
 98               pPixmap->devKind = paddedWidth;
 99               pPixmap->refcnt = 1;
100           #ifdef PIXPRIV
101               pPixmap->devPrivate.ptr = datasize ?
102           		(pointer)((char *)pPixmap + pScreen->totalPixmapSize) : NULL;
103           #else
104               pPixmap->devPrivate.ptr = (pointer)((long)(pPixmap + 1));
105           #endif
106 dawes 3.0     return pPixmap;
107           }
108           
109           Bool
110           iplDestroyPixmap(pPixmap)
111               PixmapPtr pPixmap;
112           {
113               if(--pPixmap->refcnt)
114           	return TRUE;
115               xfree(pPixmap);
116               return TRUE;
117           }
118           
119           PixmapPtr
120           iplCopyPixmap(pSrc)
121               register PixmapPtr	pSrc;
122           {
123               register PixmapPtr	pDst;
124               int		size;
125               ScreenPtr pScreen;
126           
127 dawes 3.0     size = pSrc->drawable.height * pSrc->devKind;
128               pScreen = pSrc->drawable.pScreen;
129               pDst = (*pScreen->CreatePixmap) (pScreen, pSrc->drawable.width, 
130           				pSrc->drawable.height, pSrc->drawable.depth);
131               if (!pDst)
132           	return NullPixmap;
133               memmove((char *)pDst->devPrivate.ptr, (char *)pSrc->devPrivate.ptr, size);
134               return pDst;
135           }
136           
137           
138           /* replicates a pattern to be a full 32 bits wide.
139              relies on the fact that each scnaline is longword padded.
140              doesn't do anything if pixmap is not a factor osf 32 wide.
141              changes width field of pixmap if successful, so that the fast
142           	iplXRotatePixmap code gets used if we rotate the pixmap later.
143           	iplYRotatePixmap code gets used if we rotate the pixmap later.
144           
145              calculate number of times to repeat
146              for each scanline of pattern
147                 zero out area to be filled with replicate
148 dawes 3.0       left shift and or in original as many times as needed
149           */
150           
151           void
152           iplPadPixmap(pPixmap)
153               PixmapPtr pPixmap;
154           {
155               register int width = pPixmap->drawable.width;
156               register int h;
157               register unsigned short mask;
158               register unsigned short *p;
159               register unsigned short bits; /* real pattern bits */
160               register int i;
161               int rep;                    /* repeat count for pattern */
162            
163               if (width >= INTER_PGSZ)
164                   return;
165           
166               rep = INTER_PGSZ/width;
167           /*    if (rep*width != INTER_PGSZ)
168                   return; */
169 dawes 3.0  
170               mask = iplendtab[width];
171            
172               p = (unsigned short *)(pPixmap->devPrivate.ptr);
173               for (h=0; h < pPixmap->drawable.height * INTER_PLANES; h++)
174               {
175           	*p &= mask;
176           	bits = *p ;
177                   for(i=1; i<rep; i++)
178                   {
179           #if (BITMAP_BIT_ORDER == MSBFirst) 
180                       bits >>= width;
181           #else
182           	    bits <<= width;
183           #endif
184           	    *p |= bits; 
185                   }
186                   p++;
187               }    
188               pPixmap->drawable.width = rep*width; /* PGSZ/(pPixmap->drawable.bitsPerPixel); */
189           }
190 dawes 3.0 
191           
192           #ifdef notdef
193           /*
194            * ipl debugging routine -- assumes pixmap is 1 byte deep 
195            */
196           static ipldumppixmap(pPix)
197               PixmapPtr	pPix;
198           {
199               unsigned int *pw;
200               char *psrc, *pdst;
201               int	i, j;
202               char	line[66];
203           
204               ErrorF(  "pPixmap: 0x%x\n", pPix);
205               ErrorF(  "%d wide %d high\n", pPix->drawable.width, pPix->drawable.height);
206               if (pPix->drawable.width > 64)
207               {
208           	ErrorF(  "too wide to see\n");
209           	return;
210               }
211 dawes 3.0 
212               pw = (unsigned int *) pPix->devPrivate.ptr;
213               psrc = (char *) pw;
214           
215           /*
216               for ( i=0; i<pPix->drawable.height; ++i )
217           	ErrorF( "0x%x\n", pw[i] );
218           */
219           
220               for ( i = 0; i < pPix->drawable.height; ++i ) {
221           	pdst = line;
222           	for(j = 0; j < pPix->drawable.width; j++) {
223           	    *pdst++ = *psrc++ ? 'X' : ' ' ;
224           	}
225           	*pdst++ = '\n';
226           	*pdst++ = '\0';
227           	ErrorF( "%s", line);
228               }
229           }
230           #endif /* notdef */
231           
232 dawes 3.0 /* Rotates pixmap pPix by w pixels to the right on the screen. Assumes that
233            * words are PGSZ bits wide, and that the least significant bit appears on the
234            * left.
235            */
236           void
237           iplXRotatePixmap(pPix, rw)
238               PixmapPtr	pPix;
239               register int rw;
240           {
241               INTER_DECLAREG(*pw);
242               INTER_DECLAREG(*pwFinal);
243               INTER_DECLAREGP(t);
244               int				rot;
245           
246               if (pPix == NullPixmap)
247                   return;
248           
249               switch (((DrawablePtr) pPix)->bitsPerPixel) {
250           	case INTER_PLANES:
251           	    break;
252           	case 1:
253 dawes 3.0 	    mfbXRotatePixmap(pPix, rw);
254           	    return;
255           	default:
256           	    ErrorF("iplXRotatePixmap: unsupported bitsPerPixel %d\n", ((DrawablePtr) pPix)->bitsPerPixel);
257           	    return;
258               }
259               pw = (unsigned short *)pPix->devPrivate.ptr;
260               modulus (rw, (int) pPix->drawable.width, rot);
261               if(pPix->drawable.width == 16)
262               {
263                   pwFinal = pw + pPix->drawable.height * INTER_PLANES;
264           	while(pw < pwFinal)
265           	{
266           	    INTER_COPY(pw, t);
267           	    INTER_MSKINSM(iplendtab[rot], INTER_PPG-rot, t,
268           			  ~0, rot, t, pw)
269           	    INTER_NEXT_GROUP(pw);
270           	}
271               }
272               else
273               {
274 dawes 3.0         ErrorF("ipl internal error: trying to rotate odd-sized pixmap.\n");
275           #ifdef notdef
276           	register unsigned long *pwTmp;
277           	int size, tsize;
278           
279           	tsize = PixmapBytePad(pPix->drawable.width - rot, pPix->drawable.depth);
280           	pwTmp = (unsigned long *) ALLOCATE_LOCAL(pPix->drawable.height * tsize);
281           	if (!pwTmp)
282           	    return;
283           	/* divide pw (the pixmap) in two vertically at (w - rot) and swap */
284           	tsize >>= 2;
285           	size = pPix->devKind >> SIZE0F(PixelGroup);
286           	iplQuickBlt((long *)pw, (long *)pwTmp,
287           		    0, 0, 0, 0,
288           		    (int)pPix->drawable.width - rot, (int)pPix->drawable.height,
289           		    size, tsize);
290           	iplQuickBlt((long *)pw, (long *)pw,
291           		    (int)pPix->drawable.width - rot, 0, 0, 0,
292           		    rot, (int)pPix->drawable.height,
293           		    size, size);
294           	iplQuickBlt((long *)pwTmp, (long *)pw,
295 dawes 3.0 		    0, 0, rot, 0,
296           		    (int)pPix->drawable.width - rot, (int)pPix->drawable.height,
297           		    tsize, size);
298           	DEALLOCATE_LOCAL(pwTmp);
299           #endif
300               }
301           }
302           
303           /* Rotates pixmap pPix by h lines.  Assumes that h is always less than
304              pPix->drawable.height
305              works on any width.
306            */
307           void
308           iplYRotatePixmap(pPix, rh)
309               register PixmapPtr	pPix;
310               int	rh;
311           {
312               int nbyDown;	/* bytes to move down to row 0; also offset of
313           			   row rh */
314               int nbyUp;		/* bytes to move up to line rh; also
315           			   offset of first line moved down to 0 */
316 dawes 3.0     char *pbase;
317               char *ptmp;
318               int	rot;
319           
320               if (pPix == NullPixmap)
321           	return;
322               switch (((DrawablePtr) pPix)->bitsPerPixel) {
323           	case INTER_PLANES:
324           	    break;
325           	case 1:
326           	    mfbYRotatePixmap(pPix, rh);
327           	    return;
328           	default:
329           	    ErrorF("iplYRotatePixmap: unsupported bitsPerPixel %d\n", ((DrawablePtr) pPix)->bitsPerPixel);
330           	    return;
331               }
332           
333               modulus (rh, (int) pPix->drawable.height, rot);
334               pbase = (char *)pPix->devPrivate.ptr;
335           
336               nbyDown = rot * pPix->devKind;
337 dawes 3.0     nbyUp = (pPix->devKind * pPix->drawable.height) - nbyDown;
338               if(!(ptmp = (char *)ALLOCATE_LOCAL(nbyUp)))
339           	return;
340           
341               memmove(ptmp, pbase, nbyUp);		/* save the low rows */
342               memmove(pbase, pbase+nbyUp, nbyDown);	/* slide the top rows down */
343               memmove(pbase+nbyDown, ptmp, nbyUp);	/* move lower rows up to row rot */
344               DEALLOCATE_LOCAL(ptmp);
345           }
346           
347           void
348           iplCopyRotatePixmap(psrcPix, ppdstPix, xrot, yrot)
349               register PixmapPtr psrcPix, *ppdstPix;
350               int	xrot, yrot;
351           {
352               register PixmapPtr pdstPix;
353           
354               if ((pdstPix = *ppdstPix) &&
355           	(pdstPix->devKind == psrcPix->devKind) &&
356           	(pdstPix->drawable.height == psrcPix->drawable.height))
357               {
358 dawes 3.0 	memmove((char *)pdstPix->devPrivate.ptr,
359           		(char *)psrcPix->devPrivate.ptr,
360           	      psrcPix->drawable.height * psrcPix->devKind);
361           	pdstPix->drawable.width = psrcPix->drawable.width;
362           	pdstPix->drawable.depth = psrcPix->drawable.depth;
363           	pdstPix->drawable.bitsPerPixel = psrcPix->drawable.bitsPerPixel;
364           	pdstPix->drawable.serialNumber = NEXT_SERIAL_NUMBER;
365               }
366               else
367               {
368           	if (pdstPix)
369           	    /* FIX XBUG 6168 */
370           	    (*pdstPix->drawable.pScreen->DestroyPixmap)(pdstPix);
371           	*ppdstPix = pdstPix = iplCopyPixmap(psrcPix);
372           	if (!pdstPix)
373           	    return;
374               }
375               iplPadPixmap(pdstPix);
376               if (xrot)
377           	iplXRotatePixmap(pdstPix, xrot);
378               if (yrot)
379 dawes 3.0 	iplYRotatePixmap(pdstPix, yrot);
380           }

Powered by
ViewCVS 0.9.2