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