fix cairo's a1-traps-sample test
[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 #if N_BITS == 1
49         /* For the non-antialiased case, round the coordinates up, in effect
50          * sampling the center of the pixel. (The AA case does a similar 
51          * adjustment in RenderSamplesX) */
52         lx = l->x + X_FRAC_FIRST(1);
53         rx = r->x + X_FRAC_FIRST(1);
54 #else
55         lx = l->x;
56         rx = r->x;
57 #endif
58         /* clip X */
59         if (lx < 0)
60             lx = 0;
61         if (pixman_fixed_to_int (rx) >= width)
62             rx = pixman_int_to_fixed (width);
63
64         /* Skip empty (or backwards) sections */
65         if (rx > lx)
66         {
67
68             /* Find pixel bounds for span */
69             lxi = pixman_fixed_to_int (lx);
70             rxi = pixman_fixed_to_int (rx);
71
72 #if N_BITS == 1
73             {
74                 uint32_t  *a = line;
75                 uint32_t  startmask;
76                 uint32_t  endmask;
77                 int         nmiddle;
78                 int         width = rxi - lxi;
79                 int         x = lxi;
80
81                 a += x >> FB_SHIFT;
82                 x &= FB_MASK;
83
84                 FbMaskBits (x, width, startmask, nmiddle, endmask);
85                     if (startmask) {
86                         WRITE(image, a, READ(image, a) | startmask);
87                         a++;
88                     }
89                     while (nmiddle--)
90                         WRITE(image, a++, FB_ALLONES);
91                     if (endmask)
92                         WRITE(image, a, READ(image, a) | endmask);
93             }
94 #else
95             {
96                 DefineAlpha(line,lxi);
97                 int         lxs;
98                 int     rxs;
99
100                 /* Sample coverage for edge pixels */
101                 lxs = RenderSamplesX (lx, N_BITS);
102                 rxs = RenderSamplesX (rx, N_BITS);
103
104                 /* Add coverage across row */
105                 if (lxi == rxi)
106                 {
107                     AddAlpha (rxs - lxs);
108                 }
109                 else
110                 {
111                     int xi;
112
113                     AddAlpha (N_X_FRAC(N_BITS) - lxs);
114                     StepAlpha;
115                     for (xi = lxi + 1; xi < rxi; xi++)
116                     {
117                         AddAlpha (N_X_FRAC(N_BITS));
118                         StepAlpha;
119                     }
120                     /* Do not add in a 0 alpha here. This check is necessary
121                      * to avoid a buffer overrun when rx is exactly on a pixel
122                      * boundary.
123                      */
124                     if (rxs != 0)
125                         AddAlpha (rxs);
126                 }
127             }
128 #endif
129         }
130
131         if (y == b)
132             break;
133
134 #if N_BITS > 1
135         if (pixman_fixed_frac (y) != Y_FRAC_LAST(N_BITS))
136         {
137             RenderEdgeStepSmall (l);
138             RenderEdgeStepSmall (r);
139             y += STEP_Y_SMALL(N_BITS);
140         }
141         else
142 #endif
143         {
144             RenderEdgeStepBig (l);
145             RenderEdgeStepBig (r);
146             y += STEP_Y_BIG(N_BITS);
147             line += stride;
148         }
149     }
150 }
151
152 #undef rasterizeSpan