First import
[xorg_rtime.git] / xorg-server-1.4 / mi / mipushpxl.c
blob3695f30da8a1e701fd4a854ec51f2658efc0169a
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_DIX_CONFIG_H
48 #include <dix-config.h>
49 #endif
51 #include <X11/X.h>
52 #include "gcstruct.h"
53 #include "scrnintstr.h"
54 #include "pixmapstr.h"
55 #include "regionstr.h"
56 #include "../mfb/maskbits.h"
57 #include "mi.h"
59 #define NPT 128
61 /* miPushPixels -- squeegees the fill style of pGC through pBitMap
62 * into pDrawable. pBitMap is a stencil (dx by dy of it is used, it may
63 * be bigger) which is placed on the drawable at xOrg, yOrg. Where a 1 bit
64 * is set in the bitmap, the fill style is put onto the drawable using
65 * the GC's logical function. The drawable is not changed where the bitmap
66 * has a zero bit or outside the area covered by the stencil.
68 WARNING:
69 this code works if the 1-bit deep pixmap format returned by GetSpans
70 is the same as the format defined by the mfb code (i.e. 32-bit padding
71 per scanline, scanline unit = 32 bits; later, this might mean
72 bitsizeof(int) padding and sacnline unit == bitsizeof(int).)
77 * in order to have both (MSB_FIRST and LSB_FIRST) versions of this
78 * in the server, we need to rename one of them
80 _X_EXPORT void
81 miPushPixels(pGC, pBitMap, pDrawable, dx, dy, xOrg, yOrg)
82 GCPtr pGC;
83 PixmapPtr pBitMap;
84 DrawablePtr pDrawable;
85 int dx, dy, xOrg, yOrg;
87 int h, dxDivPPW, ibEnd;
88 MiBits *pwLineStart;
89 MiBits *pw, *pwEnd;
90 MiBits msk;
91 int ib, w;
92 int ipt; /* index into above arrays */
93 Bool fInBox;
94 DDXPointRec pt[NPT], ptThisLine;
95 int width[NPT];
96 #if 1
97 PixelType startmask;
98 if (screenInfo.bitmapBitOrder == IMAGE_BYTE_ORDER)
99 if (screenInfo.bitmapBitOrder == LSBFirst)
100 startmask = (MiBits)(-1) ^
101 LONG2CHARSSAMEORDER((MiBits)(-1) << 1);
102 else
103 startmask = (MiBits)(-1) ^
104 LONG2CHARSSAMEORDER((MiBits)(-1) >> 1);
105 else
106 if (screenInfo.bitmapBitOrder == LSBFirst)
107 startmask = (MiBits)(-1) ^
108 LONG2CHARSDIFFORDER((MiBits)(-1) << 1);
109 else
110 startmask = (MiBits)(-1) ^
111 LONG2CHARSDIFFORDER((MiBits)(-1) >> 1);
112 #endif
114 pwLineStart = (MiBits *)xalloc(BitmapBytePad(dx));
115 if (!pwLineStart)
116 return;
117 ipt = 0;
118 dxDivPPW = dx/PPW;
120 for(h = 0, ptThisLine.x = 0, ptThisLine.y = 0;
121 h < dy;
122 h++, ptThisLine.y++)
125 (*pBitMap->drawable.pScreen->GetSpans)((DrawablePtr)pBitMap, dx,
126 &ptThisLine, &dx, 1, (char *)pwLineStart);
128 pw = pwLineStart;
129 /* Process all words which are fully in the pixmap */
131 fInBox = FALSE;
132 pwEnd = pwLineStart + dxDivPPW;
133 while(pw < pwEnd)
135 w = *pw;
136 #if 1
137 msk = startmask;
138 #else
139 msk = (MiBits)(-1) ^ SCRRIGHT((MiBits)(-1), 1);
140 #endif
141 for(ib = 0; ib < PPW; ib++)
143 if(w & msk)
145 if(!fInBox)
147 pt[ipt].x = ((pw - pwLineStart) << PWSH) + ib + xOrg;
148 pt[ipt].y = h + yOrg;
149 /* start new box */
150 fInBox = TRUE;
153 else
155 if(fInBox)
157 width[ipt] = ((pw - pwLineStart) << PWSH) +
158 ib + xOrg - pt[ipt].x;
159 if (++ipt >= NPT)
161 (*pGC->ops->FillSpans)(pDrawable, pGC,
162 NPT, pt, width, TRUE);
163 ipt = 0;
165 /* end box */
166 fInBox = FALSE;
169 #if 1
170 /* This is not quite right, but it'll do for now */
171 if (screenInfo.bitmapBitOrder == IMAGE_BYTE_ORDER)
172 if (screenInfo.bitmapBitOrder == LSBFirst)
173 msk = LONG2CHARSSAMEORDER(LONG2CHARSSAMEORDER(msk) << 1);
174 else
175 msk = LONG2CHARSSAMEORDER(LONG2CHARSSAMEORDER(msk) >> 1);
176 else
177 if (screenInfo.bitmapBitOrder == LSBFirst)
178 msk = LONG2CHARSDIFFORDER(LONG2CHARSDIFFORDER(msk) << 1);
179 else
180 msk = LONG2CHARSDIFFORDER(LONG2CHARSDIFFORDER(msk) >> 1);
181 #else
182 msk = SCRRIGHT(msk, 1);
183 #endif
185 pw++;
187 ibEnd = dx & PIM;
188 if(ibEnd)
190 /* Process final partial word on line */
191 w = *pw;
192 #if 1
193 msk = startmask;
194 #else
195 msk = (MiBits)(-1) ^ SCRRIGHT((MiBits)(-1), 1);
196 #endif
197 for(ib = 0; ib < ibEnd; ib++)
199 if(w & msk)
201 if(!fInBox)
203 /* start new box */
204 pt[ipt].x = ((pw - pwLineStart) << PWSH) + ib + xOrg;
205 pt[ipt].y = h + yOrg;
206 fInBox = TRUE;
209 else
211 if(fInBox)
213 /* end box */
214 width[ipt] = ((pw - pwLineStart) << PWSH) +
215 ib + xOrg - pt[ipt].x;
216 if (++ipt >= NPT)
218 (*pGC->ops->FillSpans)(pDrawable,
219 pGC, NPT, pt, width, TRUE);
220 ipt = 0;
222 fInBox = FALSE;
225 #if 1
226 /* This is not quite right, but it'll do for now */
227 if (screenInfo.bitmapBitOrder == IMAGE_BYTE_ORDER)
228 if (screenInfo.bitmapBitOrder == LSBFirst)
229 msk = LONG2CHARSSAMEORDER(LONG2CHARSSAMEORDER(msk) << 1);
230 else
231 msk = LONG2CHARSSAMEORDER(LONG2CHARSSAMEORDER(msk) >> 1);
232 else
233 if (screenInfo.bitmapBitOrder == LSBFirst)
234 msk = LONG2CHARSDIFFORDER(LONG2CHARSDIFFORDER(msk) << 1);
235 else
236 msk = LONG2CHARSDIFFORDER(LONG2CHARSDIFFORDER(msk) >> 1);
237 #else
238 msk = SCRRIGHT(msk, 1);
239 #endif
242 /* If scanline ended with last bit set, end the box */
243 if(fInBox)
245 width[ipt] = dx + xOrg - pt[ipt].x;
246 if (++ipt >= NPT)
248 (*pGC->ops->FillSpans)(pDrawable, pGC, NPT, pt, width, TRUE);
249 ipt = 0;
253 xfree(pwLineStart);
254 /* Flush any remaining spans */
255 if (ipt)
257 (*pGC->ops->FillSpans)(pDrawable, pGC, ipt, pt, width, TRUE);