2 * Copyright © 2004 Keith Packard
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.
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.
27 rasterizeEdges (pixman_image_t *image,
35 uint32_t *buf = (image)->bits.bits;
36 int stride = (image)->bits.rowstride;
37 int width = (image)->bits.width;
39 line = buf + pixman_fixed_to_int (y) * stride;
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);
60 if (pixman_fixed_to_int (rx) >= width)
62 rx = pixman_int_to_fixed (width);
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.
68 rx = pixman_int_to_fixed (width) - 1;
71 /* Skip empty (or backwards) sections */
75 /* Find pixel bounds for span */
76 lxi = pixman_fixed_to_int (lx);
77 rxi = pixman_fixed_to_int (rx);
82 #ifdef WORDS_BIGENDIAN
83 # define FbScrLeft(x,n) ((x) << (n))
84 # define FbScrRight(x,n) ((x) >> (n))
86 # define FbScrLeft(x,n) ((x) >> (n))
87 # define FbScrRight(x,n) ((x) << (n))
90 #define FbLeftMask(x) \
92 FbScrRight (0xffffffff, (x) & 0x1f) : 0)
93 #define FbRightMask(x) \
94 (((32 - (x)) & 0x1f) ? \
95 FbScrLeft (0xffffffff, (32 - (x)) & 0x1f) : 0)
97 #define FbMaskBits(x,w,l,n,r) { \
99 r = FbRightMask ((x) + n); \
100 l = FbLeftMask (x); \
102 n -= 32 - ((x) & 0x1f); \
116 int width = rxi - lxi;
122 FbMaskBits (x, width, startmask, nmiddle, endmask);
125 WRITE(image, a, READ(image, a) | startmask);
129 WRITE(image, a++, 0xffffffff);
131 WRITE(image, a, READ(image, a) | endmask);
135 DefineAlpha(line,lxi);
139 /* Sample coverage for edge pixels */
140 lxs = RenderSamplesX (lx, N_BITS);
141 rxs = RenderSamplesX (rx, N_BITS);
143 /* Add coverage across row */
146 AddAlpha (rxs - lxs);
152 AddAlpha (N_X_FRAC(N_BITS) - lxs);
154 for (xi = lxi + 1; xi < rxi; xi++)
156 AddAlpha (N_X_FRAC(N_BITS));
169 if (pixman_fixed_frac (y) != Y_FRAC_LAST(N_BITS))
171 RenderEdgeStepSmall (l);
172 RenderEdgeStepSmall (r);
173 y += STEP_Y_SMALL(N_BITS);
178 RenderEdgeStepBig (l);
179 RenderEdgeStepBig (r);
180 y += STEP_Y_BIG(N_BITS);