|
Packit |
030a23 |
/*
|
|
Packit |
030a23 |
* Copyright © 2004 Keith Packard
|
|
Packit |
030a23 |
*
|
|
Packit |
030a23 |
* Permission to use, copy, modify, distribute, and sell this software and its
|
|
Packit |
030a23 |
* documentation for any purpose is hereby granted without fee, provided that
|
|
Packit |
030a23 |
* the above copyright notice appear in all copies and that both that
|
|
Packit |
030a23 |
* copyright notice and this permission notice appear in supporting
|
|
Packit |
030a23 |
* documentation, and that the name of Keith Packard not be used in
|
|
Packit |
030a23 |
* advertising or publicity pertaining to distribution of the software without
|
|
Packit |
030a23 |
* specific, written prior permission. Keith Packard makes no
|
|
Packit |
030a23 |
* representations about the suitability of this software for any purpose. It
|
|
Packit |
030a23 |
* is provided "as is" without express or implied warranty.
|
|
Packit |
030a23 |
*
|
|
Packit |
030a23 |
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
Packit |
030a23 |
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
|
Packit |
030a23 |
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
|
Packit |
030a23 |
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
Packit |
030a23 |
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
Packit |
030a23 |
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
Packit |
030a23 |
* PERFORMANCE OF THIS SOFTWARE.
|
|
Packit |
030a23 |
*/
|
|
Packit |
030a23 |
|
|
Packit |
030a23 |
#ifndef rasterize_span
|
|
Packit |
030a23 |
#endif
|
|
Packit |
030a23 |
|
|
Packit |
030a23 |
static void
|
|
Packit |
030a23 |
RASTERIZE_EDGES (pixman_image_t *image,
|
|
Packit |
030a23 |
pixman_edge_t *l,
|
|
Packit |
030a23 |
pixman_edge_t *r,
|
|
Packit |
030a23 |
pixman_fixed_t t,
|
|
Packit |
030a23 |
pixman_fixed_t b)
|
|
Packit |
030a23 |
{
|
|
Packit |
030a23 |
pixman_fixed_t y = t;
|
|
Packit |
030a23 |
uint32_t *line;
|
|
Packit |
030a23 |
uint32_t *buf = (image)->bits.bits;
|
|
Packit |
030a23 |
int stride = (image)->bits.rowstride;
|
|
Packit |
030a23 |
int width = (image)->bits.width;
|
|
Packit |
030a23 |
|
|
Packit |
030a23 |
line = buf + pixman_fixed_to_int (y) * stride;
|
|
Packit |
030a23 |
|
|
Packit |
030a23 |
for (;;)
|
|
Packit |
030a23 |
{
|
|
Packit |
030a23 |
pixman_fixed_t lx;
|
|
Packit |
030a23 |
pixman_fixed_t rx;
|
|
Packit |
030a23 |
int lxi;
|
|
Packit |
030a23 |
int rxi;
|
|
Packit |
030a23 |
|
|
Packit |
030a23 |
lx = l->x;
|
|
Packit |
030a23 |
rx = r->x;
|
|
Packit |
030a23 |
#if N_BITS == 1
|
|
Packit |
030a23 |
/* For the non-antialiased case, round the coordinates up, in effect
|
|
Packit |
030a23 |
* sampling just slightly to the left of the pixel. This is so that
|
|
Packit |
030a23 |
* when the sample point lies exactly on the line, we round towards
|
|
Packit |
030a23 |
* north-west.
|
|
Packit |
030a23 |
*
|
|
Packit |
030a23 |
* (The AA case does a similar adjustment in RENDER_SAMPLES_X)
|
|
Packit |
030a23 |
*/
|
|
Packit |
030a23 |
lx += X_FRAC_FIRST(1) - pixman_fixed_e;
|
|
Packit |
030a23 |
rx += X_FRAC_FIRST(1) - pixman_fixed_e;
|
|
Packit |
030a23 |
#endif
|
|
Packit |
030a23 |
/* clip X */
|
|
Packit |
030a23 |
if (lx < 0)
|
|
Packit |
030a23 |
lx = 0;
|
|
Packit |
030a23 |
if (pixman_fixed_to_int (rx) >= width)
|
|
Packit |
030a23 |
#if N_BITS == 1
|
|
Packit |
030a23 |
rx = pixman_int_to_fixed (width);
|
|
Packit |
030a23 |
#else
|
|
Packit |
030a23 |
/* Use the last pixel of the scanline, covered 100%.
|
|
Packit |
030a23 |
* We can't use the first pixel following the scanline,
|
|
Packit |
030a23 |
* because accessing it could result in a buffer overrun.
|
|
Packit |
030a23 |
*/
|
|
Packit |
030a23 |
rx = pixman_int_to_fixed (width) - 1;
|
|
Packit |
030a23 |
#endif
|
|
Packit |
030a23 |
|
|
Packit |
030a23 |
/* Skip empty (or backwards) sections */
|
|
Packit |
030a23 |
if (rx > lx)
|
|
Packit |
030a23 |
{
|
|
Packit |
030a23 |
|
|
Packit |
030a23 |
/* Find pixel bounds for span */
|
|
Packit |
030a23 |
lxi = pixman_fixed_to_int (lx);
|
|
Packit |
030a23 |
rxi = pixman_fixed_to_int (rx);
|
|
Packit |
030a23 |
|
|
Packit |
030a23 |
#if N_BITS == 1
|
|
Packit |
030a23 |
{
|
|
Packit |
030a23 |
|
|
Packit |
030a23 |
#define LEFT_MASK(x) \
|
|
Packit |
030a23 |
(((x) & 0x1f) ? \
|
|
Packit |
030a23 |
SCREEN_SHIFT_RIGHT (0xffffffff, (x) & 0x1f) : 0)
|
|
Packit |
030a23 |
#define RIGHT_MASK(x) \
|
|
Packit |
030a23 |
(((32 - (x)) & 0x1f) ? \
|
|
Packit |
030a23 |
SCREEN_SHIFT_LEFT (0xffffffff, (32 - (x)) & 0x1f) : 0)
|
|
Packit |
030a23 |
|
|
Packit |
030a23 |
#define MASK_BITS(x,w,l,n,r) { \
|
|
Packit |
030a23 |
n = (w); \
|
|
Packit |
030a23 |
r = RIGHT_MASK ((x) + n); \
|
|
Packit |
030a23 |
l = LEFT_MASK (x); \
|
|
Packit |
030a23 |
if (l) { \
|
|
Packit |
030a23 |
n -= 32 - ((x) & 0x1f); \
|
|
Packit |
030a23 |
if (n < 0) { \
|
|
Packit |
030a23 |
n = 0; \
|
|
Packit |
030a23 |
l &= r; \
|
|
Packit |
030a23 |
r = 0; \
|
|
Packit |
030a23 |
} \
|
|
Packit |
030a23 |
} \
|
|
Packit |
030a23 |
n >>= 5; \
|
|
Packit |
030a23 |
}
|
|
Packit |
030a23 |
|
|
Packit |
030a23 |
uint32_t *a = line;
|
|
Packit |
030a23 |
uint32_t startmask;
|
|
Packit |
030a23 |
uint32_t endmask;
|
|
Packit |
030a23 |
int nmiddle;
|
|
Packit |
030a23 |
int width = rxi - lxi;
|
|
Packit |
030a23 |
int x = lxi;
|
|
Packit |
030a23 |
|
|
Packit |
030a23 |
a += x >> 5;
|
|
Packit |
030a23 |
x &= 0x1f;
|
|
Packit |
030a23 |
|
|
Packit |
030a23 |
MASK_BITS (x, width, startmask, nmiddle, endmask);
|
|
Packit |
030a23 |
|
|
Packit |
030a23 |
if (startmask) {
|
|
Packit |
030a23 |
WRITE(image, a, READ(image, a) | startmask);
|
|
Packit |
030a23 |
a++;
|
|
Packit |
030a23 |
}
|
|
Packit |
030a23 |
while (nmiddle--)
|
|
Packit |
030a23 |
WRITE(image, a++, 0xffffffff);
|
|
Packit |
030a23 |
if (endmask)
|
|
Packit |
030a23 |
WRITE(image, a, READ(image, a) | endmask);
|
|
Packit |
030a23 |
}
|
|
Packit |
030a23 |
#else
|
|
Packit |
030a23 |
{
|
|
Packit |
030a23 |
DEFINE_ALPHA(line,lxi);
|
|
Packit |
030a23 |
int lxs;
|
|
Packit |
030a23 |
int rxs;
|
|
Packit |
030a23 |
|
|
Packit |
030a23 |
/* Sample coverage for edge pixels */
|
|
Packit |
030a23 |
lxs = RENDER_SAMPLES_X (lx, N_BITS);
|
|
Packit |
030a23 |
rxs = RENDER_SAMPLES_X (rx, N_BITS);
|
|
Packit |
030a23 |
|
|
Packit |
030a23 |
/* Add coverage across row */
|
|
Packit |
030a23 |
if (lxi == rxi)
|
|
Packit |
030a23 |
{
|
|
Packit |
030a23 |
ADD_ALPHA (rxs - lxs);
|
|
Packit |
030a23 |
}
|
|
Packit |
030a23 |
else
|
|
Packit |
030a23 |
{
|
|
Packit |
030a23 |
int xi;
|
|
Packit |
030a23 |
|
|
Packit |
030a23 |
ADD_ALPHA (N_X_FRAC(N_BITS) - lxs);
|
|
Packit |
030a23 |
STEP_ALPHA;
|
|
Packit |
030a23 |
for (xi = lxi + 1; xi < rxi; xi++)
|
|
Packit |
030a23 |
{
|
|
Packit |
030a23 |
ADD_ALPHA (N_X_FRAC(N_BITS));
|
|
Packit |
030a23 |
STEP_ALPHA;
|
|
Packit |
030a23 |
}
|
|
Packit |
030a23 |
ADD_ALPHA (rxs);
|
|
Packit |
030a23 |
}
|
|
Packit |
030a23 |
}
|
|
Packit |
030a23 |
#endif
|
|
Packit |
030a23 |
}
|
|
Packit |
030a23 |
|
|
Packit |
030a23 |
if (y == b)
|
|
Packit |
030a23 |
break;
|
|
Packit |
030a23 |
|
|
Packit |
030a23 |
#if N_BITS > 1
|
|
Packit |
030a23 |
if (pixman_fixed_frac (y) != Y_FRAC_LAST(N_BITS))
|
|
Packit |
030a23 |
{
|
|
Packit |
030a23 |
RENDER_EDGE_STEP_SMALL (l);
|
|
Packit |
030a23 |
RENDER_EDGE_STEP_SMALL (r);
|
|
Packit |
030a23 |
y += STEP_Y_SMALL(N_BITS);
|
|
Packit |
030a23 |
}
|
|
Packit |
030a23 |
else
|
|
Packit |
030a23 |
#endif
|
|
Packit |
030a23 |
{
|
|
Packit |
030a23 |
RENDER_EDGE_STEP_BIG (l);
|
|
Packit |
030a23 |
RENDER_EDGE_STEP_BIG (r);
|
|
Packit |
030a23 |
y += STEP_Y_BIG(N_BITS);
|
|
Packit |
030a23 |
line += stride;
|
|
Packit |
030a23 |
}
|
|
Packit |
030a23 |
}
|
|
Packit |
030a23 |
}
|
|
Packit |
030a23 |
|
|
Packit |
030a23 |
#undef rasterize_span
|