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

« back to all changes in this revision

Viewing changes to ilbm/ilbmply1rct.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: xc/programs/Xserver/ilbm/ilbmply1rct.c,v 3.0 1996/08/18 01:54:02 dawes Exp $ */
 
2
/*
 
3
 * $XConsortium: ilbmply1rct.c,v 1.9 94/04/17 20:28:28 dpw Exp $
 
4
 *
 
5
Copyright (c) 1990  X Consortium
 
6
 
 
7
Permission is hereby granted, free of charge, to any person obtaining a copy
 
8
of this software and associated documentation files (the "Software"), to deal
 
9
in the Software without restriction, including without limitation the rights
 
10
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
11
copies of the Software, and to permit persons to whom the Software is
 
12
furnished to do so, subject to the following conditions:
 
13
 
 
14
The above copyright notice and this permission notice shall be included in
 
15
all copies or substantial portions of the Software.
 
16
 
 
17
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
18
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
19
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 
20
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
21
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
22
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
23
 
 
24
Except as contained in this notice, the name of the X Consortium shall not be
 
25
used in advertising or otherwise to promote the sale, use or other dealings
 
26
in this Software without prior written authorization from the X Consortium.
 
27
 *
 
28
 * Author:  Keith Packard, MIT X Consortium
 
29
 */
 
30
 
 
31
/* Modified jun 95 by Geert Uytterhoeven (Geert.Uytterhoeven@cs.kuleuven.ac.be)
 
32
   to use interleaved bitplanes instead of normal bitplanes */
 
33
 
 
34
#ifdef HAVE_DIX_CONFIG_H
 
35
#include <dix-config.h>
 
36
#endif
 
37
 
 
38
#include <X11/X.h>
 
39
 
 
40
#include "gcstruct.h"
 
41
#include "windowstr.h"
 
42
#include "pixmapstr.h"
 
43
#include "regionstr.h"
 
44
#include "scrnintstr.h"
 
45
#include "mistruct.h"
 
46
 
 
47
#include "ilbm.h"
 
48
#include "maskbits.h"
 
49
 
 
50
#if defined(mips) || defined(sparc)
 
51
#define GetHighWord(x) (((int)(x)) >> 16)
 
52
#else
 
53
#define GetHighWord(x) (((int)(x)) / 65536)
 
54
#endif
 
55
 
 
56
#if IMAGE_BYTE_ORDER == MSBFirst
 
57
#define intToCoord(i,x,y)       (((x) = GetHighWord(i)), ((y) = (int)((short) (i))))
 
58
#define coordToInt(x,y)         (((x) << 16) | (y))
 
59
#define intToX(i)                               (GetHighWord(i))
 
60
#define intToY(i)                               ((int)((short) i))
 
61
#else
 
62
#define intToCoord(i,x,y)       (((x) = (int)((short) (i))), ((y) = GetHighWord(i)))
 
63
#define coordToInt(x,y)         (((y) << 16) | (x))
 
64
#define intToX(i)                               ((int)((short) (i)))
 
65
#define intToY(i)                               (GetHighWord(i))
 
66
#endif
 
67
 
 
68
void
 
69
ilbmFillPolygonSolid (pDrawable, pGC, shape, mode, count, ptsIn)
 
70
        DrawablePtr pDrawable;
 
71
        GCPtr pGC;
 
72
        int shape;
 
73
        int mode;
 
74
        int count;
 
75
        DDXPointPtr ptsIn;
 
76
{
 
77
        ilbmPrivGCPtr   devPriv;
 
78
        int nlwidth;
 
79
        PixelType *addrl, *addr;
 
80
        int maxy;
 
81
        int origin;
 
82
        register int vertex1, vertex2;
 
83
        int c;
 
84
        BoxPtr extents;
 
85
        int clip;
 
86
        int y;
 
87
        int *vertex1p, *vertex2p;
 
88
        int *endp;
 
89
        int x1, x2;
 
90
        int dx1, dx2;
 
91
        int dy1, dy2;
 
92
        int e1, e2;
 
93
        int step1, step2;
 
94
        int sign1, sign2;
 
95
        int h;
 
96
        int l, r;
 
97
        PixelType mask, bits = ~((PixelType)0);
 
98
        int nmiddle;
 
99
        register unsigned char *rrops;
 
100
        register int n;
 
101
        register int d;
 
102
        int auxDst;
 
103
        int depthDst;
 
104
        register PixelType *pdst;
 
105
 
 
106
        devPriv = (ilbmPrivGC *)(pGC->devPrivates[ilbmGCPrivateIndex].ptr);
 
107
 
 
108
        if (mode == CoordModePrevious || shape != Convex ||
 
109
                REGION_NUM_RECTS(pGC->pCompositeClip) != 1) {
 
110
                miFillPolygon (pDrawable, pGC, shape, mode, count, ptsIn);
 
111
                return;
 
112
        }
 
113
        origin = *((int *) &pDrawable->x);
 
114
        origin -= (origin & 0x8000) << 1;
 
115
        extents = &pGC->pCompositeClip->extents;
 
116
        vertex1 = *((int *) &extents->x1) - origin;
 
117
        vertex2 = *((int *) &extents->x2) - origin - 0x00010001;
 
118
        clip = 0;
 
119
        y = 32767;
 
120
        maxy = 0;
 
121
        vertex2p = (int *) ptsIn;
 
122
        endp = vertex2p + count;
 
123
        while (count--) {
 
124
                c = *vertex2p;
 
125
                clip |= (c - vertex1) | (vertex2 - c);
 
126
                c = intToY(c);
 
127
                if (c < y) {
 
128
                        y = c;
 
129
                        vertex1p = vertex2p;
 
130
                }
 
131
                vertex2p++;
 
132
                if (c > maxy)
 
133
                        maxy = c;
 
134
        }
 
135
        if (y == maxy)
 
136
                return;
 
137
 
 
138
        if (clip & 0x80008000) {
 
139
                miFillPolygon (pDrawable, pGC, shape, mode, vertex2p - (int *) ptsIn, ptsIn);
 
140
                return;
 
141
        }
 
142
 
 
143
        ilbmGetPixelWidthAuxDepthAndPointer(pDrawable, nlwidth, auxDst, depthDst,
 
144
                                                                                                        addrl);
 
145
        rrops = devPriv->rrops;
 
146
        addrl = ilbmScanlineDelta(addrl, y + pDrawable->y, auxDst);
 
147
        origin = intToX(origin);
 
148
        vertex2p = vertex1p;
 
149
        vertex2 = vertex1 = *vertex2p++;
 
150
        if (vertex2p == endp)
 
151
                vertex2p = (int *) ptsIn;
 
152
#define Setup(c,x,vertex,dx,dy,e,sign,step) {\
 
153
        x = intToX(vertex); \
 
154
        if (dy = intToY(c) - y) { \
 
155
                dx = intToX(c) - x; \
 
156
                step = 0; \
 
157
                if (dx >= 0) { \
 
158
                        e = 0; \
 
159
                        sign = 1; \
 
160
                        if (dx >= dy) {\
 
161
                                step = dx / dy; \
 
162
                                dx = dx % dy; \
 
163
                        } \
 
164
                } else { \
 
165
                        e = 1 - dy; \
 
166
                        sign = -1; \
 
167
                        dx = -dx; \
 
168
                        if (dx >= dy) { \
 
169
                                step = - (dx / dy); \
 
170
                                dx = dx % dy; \
 
171
                        } \
 
172
                } \
 
173
        } \
 
174
        x += origin; \
 
175
        vertex = c; \
 
176
}
 
177
 
 
178
#define Step(x,dx,dy,e,sign,step) {\
 
179
        x += step; \
 
180
        if ((e += dx) > 0) { \
 
181
                x += sign; \
 
182
                e -= dy; \
 
183
        } \
 
184
}
 
185
        for (;;) {
 
186
                if (y == intToY(vertex1)) {
 
187
                        do {
 
188
                                if (vertex1p == (int *) ptsIn)
 
189
                                vertex1p = endp;
 
190
                                c = *--vertex1p;
 
191
                                Setup (c,x1,vertex1,dx1,dy1,e1,sign1,step1)
 
192
                        } while (y >= intToY(vertex1));
 
193
                        h = dy1;
 
194
                } else {
 
195
                        Step(x1,dx1,dy1,e1,sign1,step1)
 
196
                        h = intToY(vertex1) - y;
 
197
                }
 
198
                if (y == intToY(vertex2)) {
 
199
                        do {
 
200
                                c = *vertex2p++;
 
201
                                if (vertex2p == endp)
 
202
                                vertex2p = (int *) ptsIn;
 
203
                                Setup (c,x2,vertex2,dx2,dy2,e2,sign2,step2)
 
204
                        } while (y >= intToY(vertex2));
 
205
                        if (dy2 < h)
 
206
                                h = dy2;
 
207
                } else {
 
208
                        Step(x2,dx2,dy2,e2,sign2,step2)
 
209
                        if ((c = (intToY(vertex2) - y)) < h)
 
210
                                h = c;
 
211
                }
 
212
                /* fill spans for this segment */
 
213
                y += h;
 
214
                for (;;) {
 
215
                        l = x1;
 
216
                        r = x2;
 
217
                        nmiddle = x2 - x1;
 
218
                        if (nmiddle < 0) {
 
219
                                nmiddle = -nmiddle;
 
220
                                l = x2;
 
221
                                r = x1;
 
222
                        }
 
223
                        c = l & PIM;
 
224
                        l -= c;
 
225
                        l = l >> PWSH;
 
226
                        addr = addrl + l;
 
227
                        if (c + nmiddle < PPW) {
 
228
                                mask = SCRRIGHT (bits,c) ^ SCRRIGHT (bits,c+nmiddle);
 
229
                                for (pdst = addr, d = 0; d < depthDst; d++, pdst += nlwidth) {  /* @@@ NEXT PLANE @@@ */
 
230
                                        switch (rrops[d]) {
 
231
                                                case RROP_BLACK:
 
232
                                                        *pdst &= ~mask;
 
233
                                                        break;
 
234
                                                case RROP_WHITE:
 
235
                                                        *pdst |= mask;
 
236
                                                        break;
 
237
                                                case RROP_INVERT:
 
238
                                                        *pdst ^= mask;
 
239
                                                        break;
 
240
                                                case RROP_NOP:
 
241
                                                        break;
 
242
                                        }
 
243
                                }
 
244
                        } else {
 
245
                                if (c) {
 
246
                                        mask = SCRRIGHT(bits, c);
 
247
                                        for (pdst = addr, d = 0; d < depthDst; d++, pdst += nlwidth) {  /* @@@ NEXT PLANE @@@ */
 
248
                                                switch (rrops[d]) {
 
249
                                                        case RROP_BLACK:
 
250
                                                                *pdst &= ~mask;
 
251
                                                                break;
 
252
                                                        case RROP_WHITE:
 
253
                                                                *pdst |= mask;
 
254
                                                                break;
 
255
                                                        case RROP_INVERT:
 
256
                                                                *pdst ^= mask;
 
257
                                                                break;
 
258
                                                        case RROP_NOP:
 
259
                                                                break;
 
260
                                                }
 
261
                                        }
 
262
                                        nmiddle += c - PPW;
 
263
                                        addr++;
 
264
                                }
 
265
                                nmiddle >>= PWSH;
 
266
                                mask = ~SCRRIGHT(bits, r & PIM);
 
267
 
 
268
                                for (d = 0; d < depthDst; d++, addr += nlwidth) {       /* @@@ NEXT PLANE @@@ */
 
269
                                        n = nmiddle;
 
270
                                        pdst = addr;
 
271
 
 
272
                                        switch (rrops[d]) {
 
273
                                                case RROP_BLACK:
 
274
                                                        Duff (n, *pdst++ = 0;)
 
275
                                                        if (mask)
 
276
                                                                *pdst &= ~mask;
 
277
                                                        break;
 
278
                                                case RROP_WHITE:
 
279
                                                        Duff (n, *pdst++ = ~0;);
 
280
                                                        if (mask)
 
281
                                                                *pdst |= mask;
 
282
                                                        break;
 
283
                                                case RROP_INVERT:
 
284
                                                        Duff (n, *pdst++ ^= ~0;);
 
285
                                                        if (mask)
 
286
                                                                *pdst ^= mask;
 
287
                                                        break;
 
288
                                                case RROP_NOP:
 
289
                                                        break;
 
290
                                        }
 
291
                                }
 
292
                        }
 
293
                        if (!--h)
 
294
                                break;
 
295
                        ilbmScanlineInc(addrl, auxDst);
 
296
                        Step(x1,dx1,dy1,e1,sign1,step1)
 
297
                        Step(x2,dx2,dy2,e2,sign2,step2)
 
298
                }
 
299
                if (y == maxy)
 
300
                        break;
 
301
                ilbmScanlineInc(addrl, auxDst);
 
302
        }
 
303
}