]> git.sesse.net Git - rdpsrv/blob - Xserver/programs/Xserver/cfb/cfbgetsp.c
Import X server from vnc-3.3.7.
[rdpsrv] / Xserver / programs / Xserver / cfb / cfbgetsp.c
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 /***********************************************************
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 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 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
51 #include "X.h"
52 #include "Xmd.h"
53 #include "servermd.h"
54
55 #include "misc.h"
56 #include "region.h"
57 #include "gc.h"
58 #include "windowstr.h"
59 #include "pixmapstr.h"
60 #include "scrnintstr.h"
61
62 #include "cfb.h"
63 #include "cfbmskbits.h"
64
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.
69  */
70 void
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 */
78 {
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 */
87     register int        nstart; 
88     int                 nend; 
89     PixelGroup          startmask, endmask;
90     int                 nlMiddle, nl, srcBit;
91     int                 w;
92     PixelGroup          *pdstNext;
93 #if PSZ == 24
94     register char *psrcb, *pdstb;
95     register int xIndex = 0;
96 #endif
97
98     switch (pDrawable->bitsPerPixel) {
99         case 1:
100             mfbGetSpans(pDrawable, wMax, ppt, pwidth, nspans, pchardstStart);
101             return;
102         case PSZ:
103             break;
104         default:
105             FatalError("cfbGetSpans: invalid depth\n");
106     }
107
108     
109     cfbGetLongWidthAndPointer (pDrawable, widthSrc, psrcBase)
110
111 #ifdef PIXEL_ADDR
112 # if PSZ != 24
113     if ((nspans == 1) && (*pwidth == 1))
114     {
115         tmpSrc = *((PixelType *)(psrcBase + (ppt->y * widthSrc))
116                    + ppt->x);
117 #if BITMAP_BIT_ORDER == MSBFirst
118         tmpSrc <<= (sizeof (unsigned long) - sizeof (PixelType)) * 8;
119 #endif
120         *pdstStart = tmpSrc;
121         return;
122     }
123 # endif /* PSZ != 24 */
124 #endif
125     pdst = pdstStart;
126     pptLast = ppt + nspans;
127     while(ppt < pptLast)
128     {
129 #if PSZ == 24
130         xEnd = min(ppt->x + *pwidth, widthSrc * sizeof(long) / 3);
131         w = xEnd - ppt->x;
132         psrc = psrcBase + ppt->y * widthSrc;
133         srcBit = ppt->x;
134         psrcb = (char *)psrc + (ppt->x * 3);
135         xIndex = 0;
136         pdstb = (char *)pdst;
137         pdstNext = pdst + ((w * 3 + 3) >> 2);
138 #else
139         xEnd = min(ppt->x + *pwidth, widthSrc << PWSH);
140         w = xEnd - ppt->x;
141         psrc = psrcBase + ppt->y * widthSrc + (ppt->x >> PWSH); 
142         srcBit = ppt->x & PIM;
143         pdstNext = pdst + ((w + PPW - 1) >> PWSH);
144 #endif
145
146 #if PSZ == 24
147         if (w < 0)
148           FatalError("cfb24GetSpans: Internal error (w < 0)\n");
149         nl = w;
150         while (nl--){ 
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);
155           srcBit++;
156           psrcb += 3;
157           xIndex++;
158           pdstb += 3;
159         } 
160         pdst = pdstNext;
161 #else /* PSZ == 24 */
162         if (srcBit + w <= PPW) 
163         { 
164             getbits(psrc, srcBit, w, tmpSrc);
165             putbits(tmpSrc, 0, w, pdst, ~((unsigned long)0)); 
166             pdst++;
167         } 
168         else 
169         { 
170             maskbits(ppt->x, w, startmask, endmask, nlMiddle);
171             nstart = 0; 
172             if (startmask) 
173             { 
174                 nstart = PPW - srcBit; 
175                 getbits(psrc, srcBit, nstart, tmpSrc);
176                 putbits(tmpSrc, 0, nstart, pdst, ~((unsigned long)0));
177                 if(srcBit + nstart >= PPW)
178                     psrc++;
179             } 
180             nl = nlMiddle; 
181             while (nl--) 
182             { 
183                 tmpSrc = *psrc;
184                 putbits(tmpSrc, nstart, PPW, pdst, ~((unsigned long)0));
185                 psrc++;
186                 pdst++;
187             } 
188             if (endmask) 
189             { 
190                 nend = xEnd & PIM; 
191                 getbits(psrc, 0, nend, tmpSrc);
192                 putbits(tmpSrc, nstart, nend, pdst, ~((unsigned long)0));
193             } 
194             pdst = pdstNext;
195         } 
196 #endif /* PSZ == 24 */
197         ppt++;
198         pwidth++;
199     }
200 }