1
/* $XFree86: xc/programs/Xserver/mfb/mfbclip.c,v 1.5 2001/12/14 20:00:05 dawes Exp $ */
2
/***********************************************************
4
Copyright 1987, 1998 The Open Group
6
Permission to use, copy, modify, distribute, and sell this software and its
7
documentation for any purpose is hereby granted without fee, provided that
8
the above copyright notice appear in all copies and that both that
9
copyright notice and this permission notice appear in supporting
12
The above copyright notice and this permission notice shall be included in
13
all copies or substantial portions of the Software.
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
Except as contained in this notice, the name of The Open Group shall not be
23
used in advertising or otherwise to promote the sale, use or other dealings
24
in this Software without prior written authorization from The Open Group.
27
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
31
Permission to use, copy, modify, and distribute this software and its
32
documentation for any purpose and without fee is hereby granted,
33
provided that the above copyright notice appear in all copies and that
34
both that copyright notice and this permission notice appear in
35
supporting documentation, and that the name of Digital not be
36
used in advertising or publicity pertaining to distribution of the
37
software without specific, written prior permission.
39
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
40
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
41
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
47
******************************************************************/
48
/* $Xorg: mfbclip.c,v 1.4 2001/02/09 02:05:18 xorgcvs Exp $ */
49
#ifdef HAVE_DIX_CONFIG_H
50
#include <dix-config.h>
54
#include "regionstr.h"
55
#include "pixmapstr.h"
56
#include "scrnintstr.h"
57
#include "regionstr.h"
63
#define ADDRECT(reg,r,fr,rx1,ry1,rx2,ry2) \
64
if (((rx1) < (rx2)) && ((ry1) < (ry2)) && \
65
(!((reg)->data->numRects && \
66
((r-1)->y1 == (ry1)) && \
67
((r-1)->y2 == (ry2)) && \
68
((r-1)->x1 <= (rx1)) && \
69
((r-1)->x2 >= (rx2))))) \
71
if ((reg)->data->numRects == (reg)->data->size) \
73
miRectAlloc(reg, 1); \
74
fr = REGION_BOXPTR(reg); \
75
r = fr + (reg)->data->numRects; \
81
(reg)->data->numRects++; \
82
if(r->x1 < (reg)->extents.x1) \
83
(reg)->extents.x1 = r->x1; \
84
if(r->x2 > (reg)->extents.x2) \
85
(reg)->extents.x2 = r->x2; \
89
/* Convert bitmap clip mask into clipping region.
90
* First, goes through each line and makes boxes by noting the transitions
91
* from 0 to 1 and 1 to 0.
92
* Then it coalesces the current line with the previous if they have boxes
93
* at the same X coordinates.
96
mfbPixmapToRegion(pPix)
99
register RegionPtr pReg;
100
register PixelType *pw, w;
102
int width, h, base, rx1 = 0, crects;
103
PixelType *pwLineEnd;
104
int irectPrevStart, irectLineStart;
105
register BoxPtr prectO, prectN;
106
BoxPtr FirstRect, rects, prectLineStart;
108
register PixelType mask0 = mask[0];
112
pReg = REGION_CREATE(pPix->drawable.pScreen, NULL, 1);
115
FirstRect = REGION_BOXPTR(pReg);
118
pwLine = (PixelType *) pPix->devPrivate.ptr;
119
nWidth = pPix->devKind / PGSZB;
121
width = pPix->drawable.width;
122
pReg->extents.x1 = width - 1;
123
pReg->extents.x2 = 0;
125
for(h = 0; h < pPix->drawable.height; h++)
129
irectLineStart = rects - FirstRect;
130
/* If the Screen left most bit of the word is set, we're starting in
139
/* Process all words which are fully in the pixmap */
140
pwLineEnd = pw + (width >> PWSH);
141
for (base = 0; pw < pwLineEnd; base += PPW)
154
for(ib = 0; ib < PPW; ib++)
156
/* If the Screen left most bit of the word is set, we're
172
ADDRECT(pReg, rects, FirstRect,
173
rx1, h, base + ib, h + 1);
177
/* Shift the word VISUALLY left one. */
183
/* Process final partial word on line */
185
for(ib = 0; ib < (width & PIM); ib++)
187
/* If the Screen left most bit of the word is set, we're
203
ADDRECT(pReg, rects, FirstRect,
204
rx1, h, base + ib, h + 1);
208
/* Shift the word VISUALLY left one. */
212
/* If scanline ended with last bit set, end the box */
215
ADDRECT(pReg, rects, FirstRect,
216
rx1, h, base + (width & PIM), h + 1);
218
/* if all rectangles on this line have the same x-coords as
219
* those on the previous line, then add 1 to all the previous y2s and
220
* throw away all the rectangles from this line
223
if(irectPrevStart != -1)
225
crects = irectLineStart - irectPrevStart;
226
if(crects == ((rects - FirstRect) - irectLineStart))
228
prectO = FirstRect + irectPrevStart;
229
prectN = prectLineStart = FirstRect + irectLineStart;
231
while(prectO < prectLineStart)
233
if((prectO->x1 != prectN->x1) || (prectO->x2 != prectN->x2))
243
prectO = FirstRect + irectPrevStart;
244
while(prectO < prectLineStart)
250
pReg->data->numRects -= crects;
255
irectPrevStart = irectLineStart;
257
if (!pReg->data->numRects)
258
pReg->extents.x1 = pReg->extents.x2 = 0;
261
pReg->extents.y1 = REGION_BOXPTR(pReg)->y1;
262
pReg->extents.y2 = REGION_END(pReg)->y2;
263
if (pReg->data->numRects == 1)
266
pReg->data = (RegDataPtr)NULL;
270
if (!miValidRegion(pReg))
271
FatalError("Assertion failed file %s, line %d: expr\n", __FILE__, __LINE__);
276
mfbPixmapToRegionProc *
277
mfbPixmapToRegionWeak(void)
279
return mfbPixmapToRegion;