First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xwin / winpushpxl.c
blob72ef2d559553af5b91b651bd0acadc49c223ca31
1 /***********************************************************
3 Copyright 1987, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
26 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
28 All Rights Reserved
30 Permission to use, copy, modify, and distribute this software and its
31 documentation for any purpose and without fee is hereby granted,
32 provided that the above copyright notice appear in all copies and that
33 both that copyright notice and this permission notice appear in
34 supporting documentation, and that the name of Digital not be
35 used in advertising or publicity pertaining to distribution of the
36 software without specific, written prior permission.
38 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
44 SOFTWARE.
46 ******************************************************************/
47 #ifdef HAVE_XWIN_CONFIG_H
48 #include <xwin-config.h>
49 #endif
50 #include <X11/X.h>
51 #include "gcstruct.h"
52 #include "scrnintstr.h"
53 #include "pixmapstr.h"
54 #include "miscstruct.h"
55 #include "../mfb/maskbits.h"
56 #include "mi.h"
58 #define NPT 128
60 /* winPushPixels -- squeegees the fill style of pGC through pBitMap
61 * into pDrawable. pBitMap is a stencil (dx by dy of it is used, it may
62 * be bigger) which is placed on the drawable at xOrg, yOrg. Where a 1 bit
63 * is set in the bitmap, the fill style is put onto the drawable using
64 * the GC's logical function. The drawable is not changed where the bitmap
65 * has a zero bit or outside the area covered by the stencil.
67 WARNING:
68 this code works if the 1-bit deep pixmap format returned by GetSpans
69 is the same as the format defined by the mfb code (i.e. 32-bit padding
70 per scanline, scanline unit = 32 bits; later, this might mean
71 bitsizeof(int) padding and sacnline unit == bitsizeof(int).)
76 * in order to have both (MSB_FIRST and LSB_FIRST) versions of this
77 * in the server, we need to rename one of them
79 void
80 winPushPixels (GCPtr pGC, PixmapPtr pBitMap, DrawablePtr pDrawable,
81 int dx, int dy, int xOrg, int yOrg)
83 int h, dxDivPPW, ibEnd;
84 MiBits *pwLineStart;
85 register MiBits *pw, *pwEnd;
86 register MiBits msk;
87 register int ib, w;
88 register int ipt; /* index into above arrays */
89 Bool fInBox;
90 DDXPointRec pt[NPT], ptThisLine;
91 int width[NPT];
92 PixelType startmask;
95 startmask = (MiBits)(-1) ^
96 LONG2CHARSDIFFORDER((MiBits)(-1) >> 1);
98 pwLineStart = (MiBits *)xalloc(BitmapBytePad(dx));
99 if (!pwLineStart)
100 return;
101 ipt = 0;
102 dxDivPPW = dx/PPW;
104 for(h = 0, ptThisLine.x = 0, ptThisLine.y = 0;
105 h < dy;
106 h++, ptThisLine.y++)
109 (*pBitMap->drawable.pScreen->GetSpans)((DrawablePtr)pBitMap, dx,
110 &ptThisLine, &dx, 1, (char *)pwLineStart);
112 pw = pwLineStart;
113 /* Process all words which are fully in the pixmap */
115 fInBox = FALSE;
116 pwEnd = pwLineStart + dxDivPPW;
117 while(pw < pwEnd)
119 w = *pw;
120 #ifdef XFree86Server
121 msk = startmask;
122 #else
123 msk = (MiBits)(-1) ^ SCRRIGHT((MiBits)(-1), 1);
124 #endif
125 for(ib = 0; ib < PPW; ib++)
127 if(w & msk)
129 if(!fInBox)
131 pt[ipt].x = ((pw - pwLineStart) << PWSH) + ib + xOrg;
132 pt[ipt].y = h + yOrg;
133 /* start new box */
134 fInBox = TRUE;
137 else
139 if(fInBox)
141 width[ipt] = ((pw - pwLineStart) << PWSH) +
142 ib + xOrg - pt[ipt].x;
143 if (++ipt >= NPT)
145 (*pGC->ops->FillSpans)(pDrawable, pGC,
146 NPT, pt, width, TRUE);
147 ipt = 0;
149 /* end box */
150 fInBox = FALSE;
153 #ifdef XFree86Server
154 /* This is not quite right, but it'll do for now */
155 msk = LONG2CHARSDIFFORDER(LONG2CHARSDIFFORDER(msk) >> 1);
156 #else
157 msk = SCRRIGHT(msk, 1);
158 #endif
160 pw++;
162 ibEnd = dx & PIM;
163 if(ibEnd)
165 /* Process final partial word on line */
166 w = *pw;
167 #ifdef XFree86Server
168 msk = startmask;
169 #else
170 msk = (MiBits)(-1) ^ SCRRIGHT((MiBits)(-1), 1);
171 #endif
172 for(ib = 0; ib < ibEnd; ib++)
174 if(w & msk)
176 if(!fInBox)
178 /* start new box */
179 pt[ipt].x = ((pw - pwLineStart) << PWSH) + ib + xOrg;
180 pt[ipt].y = h + yOrg;
181 fInBox = TRUE;
184 else
186 if(fInBox)
188 /* end box */
189 width[ipt] = ((pw - pwLineStart) << PWSH) +
190 ib + xOrg - pt[ipt].x;
191 if (++ipt >= NPT)
193 (*pGC->ops->FillSpans)(pDrawable,
194 pGC, NPT, pt, width, TRUE);
195 ipt = 0;
197 fInBox = FALSE;
200 #ifdef XFree86Server
201 /* This is not quite right, but it'll do for now */
202 msk = LONG2CHARSDIFFORDER(LONG2CHARSDIFFORDER(msk) >> 1);
203 #else
204 msk = SCRRIGHT(msk, 1);
205 #endif
208 /* If scanline ended with last bit set, end the box */
209 if(fInBox)
211 width[ipt] = dx + xOrg - pt[ipt].x;
212 if (++ipt >= NPT)
214 (*pGC->ops->FillSpans)(pDrawable, pGC, NPT, pt, width, TRUE);
215 ipt = 0;
219 xfree(pwLineStart);
220 /* Flush any remaining spans */
221 if (ipt)
223 (*pGC->ops->FillSpans)(pDrawable, pGC, ipt, pt, width, TRUE);