~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to ilbm/ilbmclip.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XFree86$ */
 
2
/***********************************************************
 
3
 
 
4
Copyright (c) 1987  X Consortium
 
5
 
 
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:
 
12
 
 
13
The above copyright notice and this permission notice shall be included in
 
14
all copies or substantial portions of the Software.
 
15
 
 
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.
 
22
 
 
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.
 
26
 
 
27
 
 
28
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
 
29
 
 
30
                        All Rights Reserved
 
31
 
 
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.
 
39
 
 
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
 
46
SOFTWARE.
 
47
 
 
48
******************************************************************/
 
49
/* $XConsortium: ilbmclip.c,v 5.6 94/04/17 20:28:19 dpw Exp $ */
 
50
 
 
51
/* Modified jun 95 by Geert Uytterhoeven (Geert.Uytterhoeven@cs.kuleuven.ac.be)
 
52
   to use interleaved bitplanes instead of normal bitplanes */
 
53
 
 
54
#ifdef HAVE_DIX_CONFIG_H
 
55
#include <dix-config.h>
 
56
#endif
 
57
 
 
58
#include <X11/X.h>
 
59
#include "miscstruct.h"
 
60
#include "pixmapstr.h"
 
61
#include "scrnintstr.h"
 
62
#include "regionstr.h"
 
63
#include "gc.h"
 
64
#include "maskbits.h"
 
65
#include "mi.h"
 
66
 
 
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; \
 
78
        } \
 
79
        r->x1 = (rx1); \
 
80
        r->y1 = (ry1); \
 
81
        r->x2 = (rx2); \
 
82
        r->y2 = (ry2); \
 
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; \
 
88
        r++; \
 
89
}
 
90
 
 
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.
 
96
 */
 
97
RegionPtr
 
98
ilbmPixmapToRegion(pPix)
 
99
        PixmapPtr pPix;
 
100
{
 
101
        register RegionPtr pReg;
 
102
        register PixelType *pw, w;
 
103
        register int ib;
 
104
        int width, h, base, rx1, crects;
 
105
        PixelType *pwLineEnd;
 
106
        int irectPrevStart, irectLineStart;
 
107
        register BoxPtr prectO, prectN;
 
108
        BoxPtr FirstRect, rects, prectLineStart;
 
109
        Bool fInBox, fSame;
 
110
        register PixelType mask0 = mask[0];
 
111
        PixelType *pwLine;
 
112
        int nWidth;
 
113
 
 
114
        pReg = REGION_CREATE(pPix->drawable.pScreen, NULL, 1);
 
115
        if (!pReg)
 
116
                return(NullRegion);
 
117
        FirstRect = REGION_BOXPTR(pReg);
 
118
        rects = FirstRect;
 
119
 
 
120
        pwLine = (PixelType *)pPix->devPrivate.ptr;
 
121
        nWidth = pPix->devKind/PGSZB;
 
122
 
 
123
        width = pPix->drawable.width;
 
124
        pReg->extents.x1 = width - 1;
 
125
        pReg->extents.x2 = 0;
 
126
        irectPrevStart = -1;
 
127
        for (h = 0; h < pPix->drawable.height; h++) {
 
128
                pw = pwLine;
 
129
                pwLine += nWidth;
 
130
                irectLineStart = rects - FirstRect;
 
131
                /* If the Screen left most bit of the word is set, we're starting in
 
132
                 * a box */
 
133
                if (*pw & mask0) {
 
134
                        fInBox = TRUE;
 
135
                        rx1 = 0;
 
136
                } else
 
137
                        fInBox = FALSE;
 
138
                /* Process all words which are fully in the pixmap */
 
139
                pwLineEnd = pw + (width >> PWSH);
 
140
                for (base = 0; pw < pwLineEnd; base += PPW) {
 
141
                        w = *pw++;
 
142
                        if (fInBox) {
 
143
                                if (!~w)
 
144
                                        continue;
 
145
                        } else {
 
146
                                if (!w)
 
147
                                        continue;
 
148
                        }
 
149
                        for (ib = 0; ib < PPW; ib++) {
 
150
                                /* If the Screen left most bit of the word is set, we're
 
151
                                 * starting a box */
 
152
                                if (w & mask0) {
 
153
                                        if (!fInBox) {
 
154
                                                rx1 = base + ib;
 
155
                                                /* start new box */
 
156
                                                fInBox = TRUE;
 
157
                                        }
 
158
                                } else {
 
159
                                        if (fInBox) {
 
160
                                                /* end box */
 
161
                                                ADDRECT(pReg, rects, FirstRect, rx1, h, base + ib, h + 1);
 
162
                                                fInBox = FALSE;
 
163
                                        }
 
164
                                }
 
165
                                /* Shift the word VISUALLY left one. */
 
166
                                w = SCRLEFT(w, 1);
 
167
                        }
 
168
                }
 
169
                if (width & PIM) {
 
170
                        /* Process final partial word on line */
 
171
                        w = *pw++;
 
172
                        for (ib = 0; ib < (width & PIM); ib++) {
 
173
                                /* If the Screen left most bit of the word is set, we're
 
174
                                 * starting a box */
 
175
                                if (w & mask0) {
 
176
                                        if (!fInBox) {
 
177
                                                rx1 = base + ib;
 
178
                                                /* start new box */
 
179
                                                fInBox = TRUE;
 
180
                                        }
 
181
                                } else {
 
182
                                        if (fInBox) {
 
183
                                                /* end box */
 
184
                                                ADDRECT(pReg, rects, FirstRect,
 
185
                                                                rx1, h, base + ib, h + 1);
 
186
                                                fInBox = FALSE;
 
187
                                        }
 
188
                                }
 
189
                                /* Shift the word VISUALLY left one. */
 
190
                                w = SCRLEFT(w, 1);
 
191
                        }
 
192
                }
 
193
                /* If scanline ended with last bit set, end the box */
 
194
                if (fInBox) {
 
195
                        ADDRECT(pReg, rects, FirstRect,
 
196
                                        rx1, h, base + (width & PIM), h + 1);
 
197
                }
 
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
 
201
                 */
 
202
                fSame = FALSE;
 
203
                if (irectPrevStart != -1) {
 
204
                        crects = irectLineStart - irectPrevStart;
 
205
                        if (crects == ((rects - FirstRect) - irectLineStart)) {
 
206
                                prectO = FirstRect + irectPrevStart;
 
207
                                prectN = prectLineStart = FirstRect + irectLineStart;
 
208
                                fSame = TRUE;
 
209
                                while (prectO < prectLineStart) {
 
210
                                        if ((prectO->x1 != prectN->x1) || (prectO->x2 != prectN->x2)) {
 
211
                                                  fSame = FALSE;
 
212
                                                  break;
 
213
                                        }
 
214
                                        prectO++;
 
215
                                        prectN++;
 
216
                                }
 
217
                                if (fSame) {
 
218
                                        prectO = FirstRect + irectPrevStart;
 
219
                                        while (prectO < prectLineStart) {
 
220
                                                prectO->y2 += 1;
 
221
                                                prectO++;
 
222
                                        }
 
223
                                        rects -= crects;
 
224
                                        pReg->data->numRects -= crects;
 
225
                                }
 
226
                        }
 
227
                }
 
228
                if (!fSame)
 
229
                        irectPrevStart = irectLineStart;
 
230
        }
 
231
        if (!pReg->data->numRects)
 
232
                pReg->extents.x1 = pReg->extents.x2 = 0;
 
233
        else {
 
234
                pReg->extents.y1 = REGION_BOXPTR(pReg)->y1;
 
235
                pReg->extents.y2 = REGION_END(pReg)->y2;
 
236
                if (pReg->data->numRects == 1) {
 
237
                        xfree(pReg->data);
 
238
                        pReg->data = (RegDataPtr)NULL;
 
239
                }
 
240
        }
 
241
#ifdef DEBUG
 
242
        if (!miValidRegion(pReg))
 
243
                FatalError("Assertion failed file %s, line %d: expr\n", __FILE__, __LINE__);
 
244
#endif
 
245
        return(pReg);
 
246
}