A tiny amount of ifdef reduction.
[profile/ivi/pixman.git] / pixman / pixman-edge-imp.h
1 /*
2  * Copyright © 2004 Keith Packard
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation, and that the name of Keith Packard not be used in
9  * advertising or publicity pertaining to distribution of the software without
10  * specific, written prior permission.  Keith Packard makes no
11  * representations about the suitability of this software for any purpose.  It
12  * is provided "as is" without express or implied warranty.
13  *
14  * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16  * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20  * PERFORMANCE OF THIS SOFTWARE.
21  */
22
23 #ifndef rasterizeSpan
24 #endif
25
26 static void
27 rasterizeEdges (pixman_image_t  *image,
28                 pixman_edge_t   *l,
29                 pixman_edge_t   *r,
30                 pixman_fixed_t          t,
31                 pixman_fixed_t          b)
32 {
33     pixman_fixed_t  y = t;
34     uint32_t  *line;
35     uint32_t *buf = (image)->bits.bits;
36     int stride = (image)->bits.rowstride;
37     int width = (image)->bits.width;
38
39     line = buf + pixman_fixed_to_int (y) * stride;
40
41     for (;;)
42     {
43         pixman_fixed_t  lx;
44         pixman_fixed_t      rx;
45         int     lxi;
46         int rxi;
47
48         lx = l->x;
49         rx = r->x;
50 #if N_BITS == 1
51         /* For the non-antialiased case, round the coordinates up, in effect
52          * sampling the center of the pixel. (The AA case does a similar 
53          * adjustment in RenderSamplesX) */
54         lx += X_FRAC_FIRST(1);
55         rx += X_FRAC_FIRST(1);
56 #endif
57         /* clip X */
58         if (lx < 0)
59             lx = 0;
60         if (pixman_fixed_to_int (rx) >= width)
61 #if N_BITS == 1
62             rx = pixman_int_to_fixed (width);
63 #else
64             /* Use the last pixel of the scanline, covered 100%.
65              * We can't use the first pixel following the scanline,
66              * because accessing it could result in a buffer overrun.
67              */
68             rx = pixman_int_to_fixed (width) - 1;
69 #endif
70
71         /* Skip empty (or backwards) sections */
72         if (rx > lx)
73         {
74
75             /* Find pixel bounds for span */
76             lxi = pixman_fixed_to_int (lx);
77             rxi = pixman_fixed_to_int (rx);
78
79 #if N_BITS == 1
80             {
81                 uint32_t  *a = line;
82                 uint32_t  startmask;
83                 uint32_t  endmask;
84                 int         nmiddle;
85                 int         width = rxi - lxi;
86                 int         x = lxi;
87
88                 a += x >> FB_SHIFT;
89                 x &= FB_MASK;
90
91                 FbMaskBits (x, width, startmask, nmiddle, endmask);
92                     if (startmask) {
93                         WRITE(image, a, READ(image, a) | startmask);
94                         a++;
95                     }
96                     while (nmiddle--)
97                         WRITE(image, a++, FB_ALLONES);
98                     if (endmask)
99                         WRITE(image, a, READ(image, a) | endmask);
100             }
101 #else
102             {
103                 DefineAlpha(line,lxi);
104                 int         lxs;
105                 int     rxs;
106
107                 /* Sample coverage for edge pixels */
108                 lxs = RenderSamplesX (lx, N_BITS);
109                 rxs = RenderSamplesX (rx, N_BITS);
110
111                 /* Add coverage across row */
112                 if (lxi == rxi)
113                 {
114                     AddAlpha (rxs - lxs);
115                 }
116                 else
117                 {
118                     int xi;
119
120                     AddAlpha (N_X_FRAC(N_BITS) - lxs);
121                     StepAlpha;
122                     for (xi = lxi + 1; xi < rxi; xi++)
123                     {
124                         AddAlpha (N_X_FRAC(N_BITS));
125                         StepAlpha;
126                     }
127                     AddAlpha (rxs);
128                 }
129             }
130 #endif
131         }
132
133         if (y == b)
134             break;
135
136 #if N_BITS > 1
137         if (pixman_fixed_frac (y) != Y_FRAC_LAST(N_BITS))
138         {
139             RenderEdgeStepSmall (l);
140             RenderEdgeStepSmall (r);
141             y += STEP_Y_SMALL(N_BITS);
142         }
143         else
144 #endif
145         {
146             RenderEdgeStepBig (l);
147             RenderEdgeStepBig (r);
148             y += STEP_Y_BIG(N_BITS);
149             line += stride;
150         }
151     }
152 }
153
154 #undef rasterizeSpan