mipushpxl.c revision 706f2543
1706f2543Smrg/***********************************************************
2706f2543Smrg
3706f2543SmrgCopyright 1987, 1998  The Open Group
4706f2543Smrg
5706f2543SmrgPermission to use, copy, modify, distribute, and sell this software and its
6706f2543Smrgdocumentation for any purpose is hereby granted without fee, provided that
7706f2543Smrgthe above copyright notice appear in all copies and that both that
8706f2543Smrgcopyright notice and this permission notice appear in supporting
9706f2543Smrgdocumentation.
10706f2543Smrg
11706f2543SmrgThe above copyright notice and this permission notice shall be included in
12706f2543Smrgall copies or substantial portions of the Software.
13706f2543Smrg
14706f2543SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15706f2543SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16706f2543SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17706f2543SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18706f2543SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19706f2543SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20706f2543Smrg
21706f2543SmrgExcept as contained in this notice, the name of The Open Group shall not be
22706f2543Smrgused in advertising or otherwise to promote the sale, use or other dealings
23706f2543Smrgin this Software without prior written authorization from The Open Group.
24706f2543Smrg
25706f2543Smrg
26706f2543SmrgCopyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
27706f2543Smrg
28706f2543Smrg                        All Rights Reserved
29706f2543Smrg
30706f2543SmrgPermission to use, copy, modify, and distribute this software and its
31706f2543Smrgdocumentation for any purpose and without fee is hereby granted,
32706f2543Smrgprovided that the above copyright notice appear in all copies and that
33706f2543Smrgboth that copyright notice and this permission notice appear in
34706f2543Smrgsupporting documentation, and that the name of Digital not be
35706f2543Smrgused in advertising or publicity pertaining to distribution of the
36706f2543Smrgsoftware without specific, written prior permission.
37706f2543Smrg
38706f2543SmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39706f2543SmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40706f2543SmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41706f2543SmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42706f2543SmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43706f2543SmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
44706f2543SmrgSOFTWARE.
45706f2543Smrg
46706f2543Smrg******************************************************************/
47706f2543Smrg#ifdef HAVE_DIX_CONFIG_H
48706f2543Smrg#include <dix-config.h>
49706f2543Smrg#endif
50706f2543Smrg
51706f2543Smrg#include <X11/X.h>
52706f2543Smrg#include "gcstruct.h"
53706f2543Smrg#include "scrnintstr.h"
54706f2543Smrg#include "pixmapstr.h"
55706f2543Smrg#include "regionstr.h"
56706f2543Smrg#include "mi.h"
57706f2543Smrg#include "servermd.h"
58706f2543Smrg
59706f2543Smrg#define NPT 128
60706f2543Smrg
61706f2543Smrg/* These were stolen from mfb.  They don't really belong here. */
62706f2543Smrg#define LONG2CHARSSAMEORDER(x) ((MiBits)(x))
63706f2543Smrg#define LONG2CHARSDIFFORDER( x ) ( ( ( ( x ) & (MiBits)0x000000FF ) << 0x18 ) \
64706f2543Smrg                        | ( ( ( x ) & (MiBits)0x0000FF00 ) << 0x08 ) \
65706f2543Smrg                        | ( ( ( x ) & (MiBits)0x00FF0000 ) >> 0x08 ) \
66706f2543Smrg                        | ( ( ( x ) & (MiBits)0xFF000000 ) >> 0x18 ) )
67706f2543Smrg
68706f2543Smrg
69706f2543Smrg#define PGSZB	4
70706f2543Smrg#define PPW	(PGSZB<<3) /* assuming 8 bits per byte */
71706f2543Smrg#define PGSZ	PPW
72706f2543Smrg#define PLST	(PPW-1)
73706f2543Smrg#define PIM	PLST
74706f2543Smrg#define PWSH	5
75706f2543Smrg
76706f2543Smrg/* miPushPixels -- squeegees the fill style of pGC through pBitMap
77706f2543Smrg * into pDrawable.  pBitMap is a stencil (dx by dy of it is used, it may
78706f2543Smrg * be bigger) which is placed on the drawable at xOrg, yOrg.  Where a 1 bit
79706f2543Smrg * is set in the bitmap, the fill style is put onto the drawable using
80706f2543Smrg * the GC's logical function. The drawable is not changed where the bitmap
81706f2543Smrg * has a zero bit or outside the area covered by the stencil.
82706f2543Smrg
83706f2543SmrgWARNING:
84706f2543Smrg    this code works if the 1-bit deep pixmap format returned by GetSpans
85706f2543Smrgis the same as the format defined by the mfb code (i.e. 32-bit padding
86706f2543Smrgper scanline, scanline unit = 32 bits; later, this might mean
87706f2543Smrgbitsizeof(int) padding and sacnline unit == bitsizeof(int).)
88706f2543Smrg
89706f2543Smrg */
90706f2543Smrg
91706f2543Smrg/*
92706f2543Smrg * in order to have both (MSB_FIRST and LSB_FIRST) versions of this
93706f2543Smrg * in the server, we need to rename one of them
94706f2543Smrg */
95706f2543Smrgvoid
96706f2543SmrgmiPushPixels(GCPtr pGC, PixmapPtr pBitMap, DrawablePtr pDrawable,
97706f2543Smrg             int dx, int dy, int xOrg, int yOrg)
98706f2543Smrg{
99706f2543Smrg    int		h, dxDivPPW, ibEnd;
100706f2543Smrg    MiBits 	*pwLineStart;
101706f2543Smrg    MiBits	*pw, *pwEnd;
102706f2543Smrg    MiBits 	msk;
103706f2543Smrg    int 	ib, w;
104706f2543Smrg    int 	ipt;		/* index into above arrays */
105706f2543Smrg    Bool 	fInBox;
106706f2543Smrg    DDXPointRec	pt[NPT], ptThisLine;
107706f2543Smrg    int		width[NPT];
108706f2543Smrg#if 1
109706f2543Smrg    MiBits	startmask;
110706f2543Smrg    if (screenInfo.bitmapBitOrder == IMAGE_BYTE_ORDER)
111706f2543Smrg      if (screenInfo.bitmapBitOrder == LSBFirst)
112706f2543Smrg        startmask = (MiBits)(-1) ^
113706f2543Smrg            LONG2CHARSSAMEORDER((MiBits)(-1) << 1);
114706f2543Smrg      else
115706f2543Smrg        startmask = (MiBits)(-1) ^
116706f2543Smrg            LONG2CHARSSAMEORDER((MiBits)(-1) >> 1);
117706f2543Smrg    else
118706f2543Smrg      if (screenInfo.bitmapBitOrder == LSBFirst)
119706f2543Smrg        startmask = (MiBits)(-1) ^
120706f2543Smrg            LONG2CHARSDIFFORDER((MiBits)(-1) << 1);
121706f2543Smrg      else
122706f2543Smrg        startmask = (MiBits)(-1) ^
123706f2543Smrg            LONG2CHARSDIFFORDER((MiBits)(-1) >> 1);
124706f2543Smrg#endif
125706f2543Smrg
126706f2543Smrg    pwLineStart = malloc(BitmapBytePad(dx));
127706f2543Smrg    if (!pwLineStart)
128706f2543Smrg	return;
129706f2543Smrg    ipt = 0;
130706f2543Smrg    dxDivPPW = dx/PPW;
131706f2543Smrg
132706f2543Smrg    for(h = 0, ptThisLine.x = 0, ptThisLine.y = 0;
133706f2543Smrg	h < dy;
134706f2543Smrg	h++, ptThisLine.y++)
135706f2543Smrg    {
136706f2543Smrg
137706f2543Smrg	(*pBitMap->drawable.pScreen->GetSpans)((DrawablePtr)pBitMap, dx,
138706f2543Smrg			&ptThisLine, &dx, 1, (char *)pwLineStart);
139706f2543Smrg
140706f2543Smrg	pw = pwLineStart;
141706f2543Smrg	/* Process all words which are fully in the pixmap */
142706f2543Smrg
143706f2543Smrg	fInBox = FALSE;
144706f2543Smrg	pwEnd = pwLineStart + dxDivPPW;
145706f2543Smrg	while(pw  < pwEnd)
146706f2543Smrg	{
147706f2543Smrg	    w = *pw;
148706f2543Smrg#if 1
149706f2543Smrg	    msk = startmask;
150706f2543Smrg#else
151706f2543Smrg	    msk = (MiBits)(-1) ^ SCRRIGHT((MiBits)(-1), 1);
152706f2543Smrg#endif
153706f2543Smrg	    for(ib = 0; ib < PPW; ib++)
154706f2543Smrg	    {
155706f2543Smrg		if(w & msk)
156706f2543Smrg		{
157706f2543Smrg		    if(!fInBox)
158706f2543Smrg		    {
159706f2543Smrg			pt[ipt].x = ((pw - pwLineStart) << PWSH) + ib + xOrg;
160706f2543Smrg			pt[ipt].y = h + yOrg;
161706f2543Smrg			/* start new box */
162706f2543Smrg			fInBox = TRUE;
163706f2543Smrg		    }
164706f2543Smrg		}
165706f2543Smrg		else
166706f2543Smrg		{
167706f2543Smrg		    if(fInBox)
168706f2543Smrg		    {
169706f2543Smrg			width[ipt] = ((pw - pwLineStart) << PWSH) +
170706f2543Smrg				     ib + xOrg - pt[ipt].x;
171706f2543Smrg			if (++ipt >= NPT)
172706f2543Smrg			{
173706f2543Smrg			    (*pGC->ops->FillSpans)(pDrawable, pGC,
174706f2543Smrg					      NPT, pt, width, TRUE);
175706f2543Smrg			    ipt = 0;
176706f2543Smrg			}
177706f2543Smrg			/* end box */
178706f2543Smrg			fInBox = FALSE;
179706f2543Smrg		    }
180706f2543Smrg		}
181706f2543Smrg#if 1
182706f2543Smrg    		/* This is not quite right, but it'll do for now */
183706f2543Smrg		if (screenInfo.bitmapBitOrder == IMAGE_BYTE_ORDER)
184706f2543Smrg		  if (screenInfo.bitmapBitOrder == LSBFirst)
185706f2543Smrg		    msk = LONG2CHARSSAMEORDER(LONG2CHARSSAMEORDER(msk) << 1);
186706f2543Smrg		  else
187706f2543Smrg		    msk = LONG2CHARSSAMEORDER(LONG2CHARSSAMEORDER(msk) >> 1);
188706f2543Smrg		else
189706f2543Smrg		  if (screenInfo.bitmapBitOrder == LSBFirst)
190706f2543Smrg		    msk = LONG2CHARSDIFFORDER(LONG2CHARSDIFFORDER(msk) << 1);
191706f2543Smrg		  else
192706f2543Smrg		    msk = LONG2CHARSDIFFORDER(LONG2CHARSDIFFORDER(msk) >> 1);
193706f2543Smrg#else
194706f2543Smrg		msk = SCRRIGHT(msk, 1);
195706f2543Smrg#endif
196706f2543Smrg	    }
197706f2543Smrg	    pw++;
198706f2543Smrg	}
199706f2543Smrg	ibEnd = dx & PIM;
200706f2543Smrg	if(ibEnd)
201706f2543Smrg	{
202706f2543Smrg	    /* Process final partial word on line */
203706f2543Smrg	    w = *pw;
204706f2543Smrg#if 1
205706f2543Smrg	    msk = startmask;
206706f2543Smrg#else
207706f2543Smrg	    msk = (MiBits)(-1) ^ SCRRIGHT((MiBits)(-1), 1);
208706f2543Smrg#endif
209706f2543Smrg	    for(ib = 0; ib < ibEnd; ib++)
210706f2543Smrg	    {
211706f2543Smrg		if(w & msk)
212706f2543Smrg		{
213706f2543Smrg		    if(!fInBox)
214706f2543Smrg		    {
215706f2543Smrg			/* start new box */
216706f2543Smrg			pt[ipt].x = ((pw - pwLineStart) << PWSH) + ib + xOrg;
217706f2543Smrg			pt[ipt].y = h + yOrg;
218706f2543Smrg			fInBox = TRUE;
219706f2543Smrg		    }
220706f2543Smrg		}
221706f2543Smrg		else
222706f2543Smrg		{
223706f2543Smrg		    if(fInBox)
224706f2543Smrg		    {
225706f2543Smrg			/* end box */
226706f2543Smrg			width[ipt] = ((pw - pwLineStart) << PWSH) +
227706f2543Smrg				     ib + xOrg - pt[ipt].x;
228706f2543Smrg			if (++ipt >= NPT)
229706f2543Smrg			{
230706f2543Smrg			    (*pGC->ops->FillSpans)(pDrawable,
231706f2543Smrg					      pGC, NPT, pt, width, TRUE);
232706f2543Smrg			    ipt = 0;
233706f2543Smrg			}
234706f2543Smrg			fInBox = FALSE;
235706f2543Smrg		    }
236706f2543Smrg		}
237706f2543Smrg#if 1
238706f2543Smrg    		/* This is not quite right, but it'll do for now */
239706f2543Smrg		if (screenInfo.bitmapBitOrder == IMAGE_BYTE_ORDER)
240706f2543Smrg		  if (screenInfo.bitmapBitOrder == LSBFirst)
241706f2543Smrg		    msk = LONG2CHARSSAMEORDER(LONG2CHARSSAMEORDER(msk) << 1);
242706f2543Smrg		  else
243706f2543Smrg		    msk = LONG2CHARSSAMEORDER(LONG2CHARSSAMEORDER(msk) >> 1);
244706f2543Smrg		else
245706f2543Smrg		  if (screenInfo.bitmapBitOrder == LSBFirst)
246706f2543Smrg		    msk = LONG2CHARSDIFFORDER(LONG2CHARSDIFFORDER(msk) << 1);
247706f2543Smrg		  else
248706f2543Smrg		    msk = LONG2CHARSDIFFORDER(LONG2CHARSDIFFORDER(msk) >> 1);
249706f2543Smrg#else
250706f2543Smrg		msk = SCRRIGHT(msk, 1);
251706f2543Smrg#endif
252706f2543Smrg	    }
253706f2543Smrg	}
254706f2543Smrg	/* If scanline ended with last bit set, end the box */
255706f2543Smrg	if(fInBox)
256706f2543Smrg	{
257706f2543Smrg	    width[ipt] = dx + xOrg - pt[ipt].x;
258706f2543Smrg	    if (++ipt >= NPT)
259706f2543Smrg	    {
260706f2543Smrg		(*pGC->ops->FillSpans)(pDrawable, pGC, NPT, pt, width, TRUE);
261706f2543Smrg		ipt = 0;
262706f2543Smrg	    }
263706f2543Smrg	}
264706f2543Smrg    }
265706f2543Smrg    free(pwLineStart);
266706f2543Smrg    /* Flush any remaining spans */
267706f2543Smrg    if (ipt)
268706f2543Smrg    {
269706f2543Smrg	(*pGC->ops->FillSpans)(pDrawable, pGC, ipt, pt, width, TRUE);
270706f2543Smrg    }
271706f2543Smrg}
272