2
/***********************************************************
4
Copyright (c) 1987 X Consortium
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:
13
The above copyright notice and this permission notice shall be included in
14
all copies or substantial portions of the Software.
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.
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.
28
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
32
Permission to use, copy, modify, and distribute this software and its
33
documentation for any purpose and without fee is hereby granted,
34
provided that the above copyright notice appear in all copies and that
35
both that copyright notice and this permission notice appear in
36
supporting documentation, and that the name of Digital not be
37
used in advertising or publicity pertaining to distribution of the
38
software without specific, written prior permission.
40
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
41
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
42
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
43
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
44
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
45
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
48
******************************************************************/
49
/* $XConsortium: ilbmclip.c,v 5.6 94/04/17 20:28:19 dpw Exp $ */
51
/* Modified jun 95 by Geert Uytterhoeven (Geert.Uytterhoeven@cs.kuleuven.ac.be)
52
to use interleaved bitplanes instead of normal bitplanes */
54
#ifdef HAVE_DIX_CONFIG_H
55
#include <dix-config.h>
59
#include "miscstruct.h"
60
#include "pixmapstr.h"
61
#include "scrnintstr.h"
62
#include "regionstr.h"
67
#define ADDRECT(reg,r,fr,rx1,ry1,rx2,ry2) \
68
if (((rx1) < (rx2)) && ((ry1) < (ry2)) && \
69
(!((reg)->data->numRects && \
70
((r-1)->y1 == (ry1)) && \
71
((r-1)->y2 == (ry2)) && \
72
((r-1)->x1 <= (rx1)) && \
73
((r-1)->x2 >= (rx2))))) { \
74
if ((reg)->data->numRects == (reg)->data->size) { \
75
miRectAlloc(reg, 1); \
76
fr = REGION_BOXPTR(reg); \
77
r = fr + (reg)->data->numRects; \
83
(reg)->data->numRects++; \
84
if (r->x1 < (reg)->extents.x1) \
85
(reg)->extents.x1 = r->x1; \
86
if (r->x2 > (reg)->extents.x2) \
87
(reg)->extents.x2 = r->x2; \
91
/* Convert bitmap clip mask into clipping region.
92
* First, goes through each line and makes boxes by noting the transitions
93
* from 0 to 1 and 1 to 0.
94
* Then it coalesces the current line with the previous if they have boxes
95
* at the same X coordinates.
98
ilbmPixmapToRegion(pPix)
101
register RegionPtr pReg;
102
register PixelType *pw, w;
104
int width, h, base, rx1, crects;
105
PixelType *pwLineEnd;
106
int irectPrevStart, irectLineStart;
107
register BoxPtr prectO, prectN;
108
BoxPtr FirstRect, rects, prectLineStart;
110
register PixelType mask0 = mask[0];
114
pReg = REGION_CREATE(pPix->drawable.pScreen, NULL, 1);
117
FirstRect = REGION_BOXPTR(pReg);
120
pwLine = (PixelType *)pPix->devPrivate.ptr;
121
nWidth = pPix->devKind/PGSZB;
123
width = pPix->drawable.width;
124
pReg->extents.x1 = width - 1;
125
pReg->extents.x2 = 0;
127
for (h = 0; h < pPix->drawable.height; h++) {
130
irectLineStart = rects - FirstRect;
131
/* If the Screen left most bit of the word is set, we're starting in
138
/* Process all words which are fully in the pixmap */
139
pwLineEnd = pw + (width >> PWSH);
140
for (base = 0; pw < pwLineEnd; base += PPW) {
149
for (ib = 0; ib < PPW; ib++) {
150
/* If the Screen left most bit of the word is set, we're
161
ADDRECT(pReg, rects, FirstRect, rx1, h, base + ib, h + 1);
165
/* Shift the word VISUALLY left one. */
170
/* Process final partial word on line */
172
for (ib = 0; ib < (width & PIM); ib++) {
173
/* If the Screen left most bit of the word is set, we're
184
ADDRECT(pReg, rects, FirstRect,
185
rx1, h, base + ib, h + 1);
189
/* Shift the word VISUALLY left one. */
193
/* If scanline ended with last bit set, end the box */
195
ADDRECT(pReg, rects, FirstRect,
196
rx1, h, base + (width & PIM), h + 1);
198
/* if all rectangles on this line have the same x-coords as
199
* those on the previous line, then add 1 to all the previous y2s and
200
* throw away all the rectangles from this line
203
if (irectPrevStart != -1) {
204
crects = irectLineStart - irectPrevStart;
205
if (crects == ((rects - FirstRect) - irectLineStart)) {
206
prectO = FirstRect + irectPrevStart;
207
prectN = prectLineStart = FirstRect + irectLineStart;
209
while (prectO < prectLineStart) {
210
if ((prectO->x1 != prectN->x1) || (prectO->x2 != prectN->x2)) {
218
prectO = FirstRect + irectPrevStart;
219
while (prectO < prectLineStart) {
224
pReg->data->numRects -= crects;
229
irectPrevStart = irectLineStart;
231
if (!pReg->data->numRects)
232
pReg->extents.x1 = pReg->extents.x2 = 0;
234
pReg->extents.y1 = REGION_BOXPTR(pReg)->y1;
235
pReg->extents.y2 = REGION_END(pReg)->y2;
236
if (pReg->data->numRects == 1) {
238
pReg->data = (RegDataPtr)NULL;
242
if (!miValidRegion(pReg))
243
FatalError("Assertion failed file %s, line %d: expr\n", __FILE__, __LINE__);