]> git.sesse.net Git - rdpsrv/blob - Xserver/programs/Xserver/cfb/cfb8cppl.c
Import X server from vnc-3.3.7.
[rdpsrv] / Xserver / programs / Xserver / cfb / cfb8cppl.c
1 /*
2  * $XConsortium: cfb8cppl.c,v 1.15 94/04/17 20:28:41 dpw Exp $
3  *
4 Copyright (c) 1990  X Consortium
5
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:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
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.
22
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.
26  *
27  * Author:  Keith Packard, MIT X Consortium
28  */
29
30 #if PSZ == 8
31 #include "X.h"
32 #include "Xmd.h"
33 #include "gcstruct.h"
34 #include "window.h"
35 #include "pixmapstr.h"
36 #include "scrnintstr.h"
37 #include "windowstr.h"
38 #include "cfb.h"
39 #undef   PSZ /* for maskbits.h */
40 #include "maskbits.h"
41 #include "mergerop.h"
42
43 #if BITMAP_BIT_ORDER == MSBFirst
44 #define LeftMost    (MFB_PPW-1)
45 #define StepBit(bit, inc)  ((bit) -= (inc))
46 #else
47 #define LeftMost    0
48 #define StepBit(bit, inc)  ((bit) += (inc))
49 #endif
50
51 #define GetBits(psrc, nBits, curBit, bitPos, bits) {\
52     bits = 0; \
53     while (nBits--) \
54     { \
55         bits |= (PixelType)(((*psrc++ >> bitPos) & 1)) << curBit; \
56         StepBit (curBit, 1); \
57     } \
58 }
59
60 void
61 cfbCopyImagePlane (pSrcDrawable, pDstDrawable, rop, prgnDst, pptSrc, planemask)
62     DrawablePtr pSrcDrawable;
63     DrawablePtr pDstDrawable;
64     int rop;
65     RegionPtr prgnDst;
66     DDXPointPtr pptSrc;
67     unsigned long planemask;
68 {
69     cfbCopyPlane8to1 (pSrcDrawable, pDstDrawable, rop, prgnDst, pptSrc,
70                       (unsigned long) ~0L, planemask);
71 }
72
73 void
74 cfbCopyPlane8to1 (pSrcDrawable, pDstDrawable, rop, prgnDst, pptSrc, planemask, bitPlane)
75     DrawablePtr pSrcDrawable;
76     DrawablePtr pDstDrawable;
77     int rop;
78     RegionPtr prgnDst;
79     DDXPointPtr pptSrc;
80     unsigned long planemask;
81     unsigned long   bitPlane;
82 {
83     int                     srcx, srcy, dstx, dsty, width, height;
84     unsigned char           *psrcBase;
85     PixelType               *pdstBase;
86     int                     widthSrc, widthDst;
87     unsigned char           *psrcLine;
88     PixelType               *pdstLine;
89     register unsigned char  *psrc;
90     register int            i;
91     register int            curBit;
92     register int            bitPos;
93     register unsigned long  bits;
94     register PixelType      *pdst;
95     PixelType               startmask, endmask;
96     int                     niStart, niEnd;
97     int                     bitStart, bitEnd;
98     int                     nl, nlMiddle;
99     int                     nbox;
100     BoxPtr                  pbox;
101     MROP_DECLARE()
102
103     if (!(planemask & 1))
104         return;
105
106     if (rop != GXcopy)
107         MROP_INITIALIZE (rop, planemask);
108
109     cfbGetByteWidthAndPointer (pSrcDrawable, widthSrc, psrcBase)
110
111     mfbGetPixelWidthAndPointer (pDstDrawable, widthDst, pdstBase)
112
113     bitPos = ffs (bitPlane) - 1;
114
115     nbox = REGION_NUM_RECTS(prgnDst);
116     pbox = REGION_RECTS(prgnDst);
117     while (nbox--)
118     {
119         dstx = pbox->x1;
120         dsty = pbox->y1;
121         srcx = pptSrc->x;
122         srcy = pptSrc->y;
123         width = pbox->x2 - pbox->x1;
124         height = pbox->y2 - pbox->y1;
125         pbox++;
126         pptSrc++;
127         psrcLine = psrcBase + srcy * widthSrc + srcx;
128         pdstLine = mfbScanline(pdstBase, dstx, dsty, widthDst);
129         dstx &= MFB_PIM;
130         if (dstx + width <= MFB_PPW)
131         {
132             maskpartialbits(dstx, width, startmask);
133             nlMiddle = 0;
134             endmask = 0;
135         }
136         else
137         {
138             maskbits (dstx, width, startmask, endmask, nlMiddle);
139         }
140         if (startmask)
141         {
142             niStart = min(MFB_PPW - dstx, width);
143             bitStart = LeftMost;
144             StepBit (bitStart, dstx);
145         }
146         if (endmask)
147         {
148             niEnd = (dstx + width) & MFB_PIM;
149             bitEnd = LeftMost;
150         }
151         if (rop == GXcopy)
152         {
153             while (height--)
154             {
155                 psrc = psrcLine;
156                 pdst = pdstLine;
157                 psrcLine += widthSrc;
158                 mfbScanlineInc(pdstLine, widthDst);
159                 if (startmask)
160                 {
161                     i = niStart;
162                     curBit = bitStart;
163                     GetBits (psrc, i, curBit, bitPos, bits);
164                     *pdst = *pdst & ~startmask | bits;
165                     pdst++;
166                 }
167                 nl = nlMiddle;
168                 while (nl--)
169                 {
170                     i = MFB_PPW;
171                     curBit = LeftMost;
172                     GetBits (psrc, i, curBit, bitPos, bits);
173                     *pdst++ = bits;
174                 }
175                 if (endmask)
176                 {
177                     i = niEnd;
178                     curBit = bitEnd;
179                     GetBits (psrc, i, curBit, bitPos, bits);
180                     *pdst = *pdst & ~endmask | bits;
181                 }
182             }
183         }
184         else
185         {
186             while (height--)
187             {
188                 psrc = psrcLine;
189                 pdst = pdstLine;
190                 psrcLine += widthSrc;
191                 mfbScanlineInc(pdstLine, widthDst);
192                 if (startmask)
193                 {
194                     i = niStart;
195                     curBit = bitStart;
196                     GetBits (psrc, i, curBit, bitPos, bits);
197                     *pdst = MROP_MASK(bits, *pdst, startmask);
198                     pdst++;
199                 }
200                 nl = nlMiddle;
201                 while (nl--)
202                 {
203                     i = MFB_PPW;
204                     curBit = LeftMost;
205                     GetBits (psrc, i, curBit, bitPos, bits);
206                     *pdst = MROP_SOLID(bits, *pdst);
207                     pdst++;
208                 }
209                 if (endmask)
210                 {
211                     i = niEnd;
212                     curBit = bitEnd;
213                     GetBits (psrc, i, curBit, bitPos, bits);
214                     *pdst = MROP_MASK (bits, *pdst, endmask);
215                 }
216             }
217         }
218     }
219 }
220
221 #endif