1 /* $XConsortium: cfbgetsp.c,v 5.14 94/04/17 20:28:50 dpw Exp $ */
2 /* $XFree86: xc/programs/Xserver/cfb/cfbgetsp.c,v 3.0.4.1 1997/07/13 14:44:57 dawes Exp $ */
3 /***********************************************************
5 Copyright (c) 1987 X Consortium
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:
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
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 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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.
29 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
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.
41 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
42 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
43 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
49 ******************************************************************/
58 #include "windowstr.h"
59 #include "pixmapstr.h"
60 #include "scrnintstr.h"
63 #include "cfbmskbits.h"
65 /* GetSpans -- for each span, gets bits from drawable starting at ppt[i]
66 * and continuing for pwidth[i] bits
67 * Each scanline returned will be server scanline padded, i.e., it will come
68 * out to an integral number of words.
71 cfbGetSpans(pDrawable, wMax, ppt, pwidth, nspans, pchardstStart)
72 DrawablePtr pDrawable; /* drawable from which to get bits */
73 int wMax; /* largest value of all *pwidths */
74 register DDXPointPtr ppt; /* points to start copying from */
75 int *pwidth; /* list of number of bits to copy */
76 int nspans; /* number of scanlines to copy */
77 char *pchardstStart; /* where to put the bits */
79 PixelGroup *pdstStart = (PixelGroup *)pchardstStart;
80 register PixelGroup *pdst; /* where to put the bits */
81 register PixelGroup *psrc; /* where to get the bits */
82 register PixelGroup tmpSrc; /* scratch buffer for bits */
83 PixelGroup *psrcBase; /* start of src bitmap */
84 int widthSrc; /* width of pixmap in bytes */
85 register DDXPointPtr pptLast; /* one past last point to get */
86 int xEnd; /* last pixel to copy from */
89 PixelGroup startmask, endmask;
90 int nlMiddle, nl, srcBit;
94 register char *psrcb, *pdstb;
95 register int xIndex = 0;
98 switch (pDrawable->bitsPerPixel) {
100 mfbGetSpans(pDrawable, wMax, ppt, pwidth, nspans, pchardstStart);
105 FatalError("cfbGetSpans: invalid depth\n");
109 cfbGetLongWidthAndPointer (pDrawable, widthSrc, psrcBase)
113 if ((nspans == 1) && (*pwidth == 1))
115 tmpSrc = *((PixelType *)(psrcBase + (ppt->y * widthSrc))
117 #if BITMAP_BIT_ORDER == MSBFirst
118 tmpSrc <<= (sizeof (unsigned long) - sizeof (PixelType)) * 8;
123 # endif /* PSZ != 24 */
126 pptLast = ppt + nspans;
130 xEnd = min(ppt->x + *pwidth, widthSrc * sizeof(long) / 3);
132 psrc = psrcBase + ppt->y * widthSrc;
134 psrcb = (char *)psrc + (ppt->x * 3);
136 pdstb = (char *)pdst;
137 pdstNext = pdst + ((w * 3 + 3) >> 2);
139 xEnd = min(ppt->x + *pwidth, widthSrc << PWSH);
141 psrc = psrcBase + ppt->y * widthSrc + (ppt->x >> PWSH);
142 srcBit = ppt->x & PIM;
143 pdstNext = pdst + ((w + PPW - 1) >> PWSH);
148 FatalError("cfb24GetSpans: Internal error (w < 0)\n");
151 psrc = (PixelGroup *)((unsigned long)psrcb & ~0x03);
152 getbits24(psrc, tmpSrc, srcBit);
153 pdst = (PixelGroup *)((unsigned long)pdstb & ~0x03);
154 putbits24(tmpSrc, nstart, PPW, pdst, ~((unsigned long)0), xIndex);
161 #else /* PSZ == 24 */
162 if (srcBit + w <= PPW)
164 getbits(psrc, srcBit, w, tmpSrc);
165 putbits(tmpSrc, 0, w, pdst, ~((unsigned long)0));
170 maskbits(ppt->x, w, startmask, endmask, nlMiddle);
174 nstart = PPW - srcBit;
175 getbits(psrc, srcBit, nstart, tmpSrc);
176 putbits(tmpSrc, 0, nstart, pdst, ~((unsigned long)0));
177 if(srcBit + nstart >= PPW)
184 putbits(tmpSrc, nstart, PPW, pdst, ~((unsigned long)0));
191 getbits(psrc, 0, nend, tmpSrc);
192 putbits(tmpSrc, nstart, nend, pdst, ~((unsigned long)0));
196 #endif /* PSZ == 24 */