|
|
@@ -17,114 +17,116 @@ |
|
|
|
* aline_template.c: antialiased (Wu) line rendering template |
|
|
|
*/ |
|
|
|
|
|
|
|
float x1 = s->x1, y1 = s->y1, x2 = s->x2, y2 = s->y2; |
|
|
|
float g, xd, yd, xgap, xend, yend, xf, yf, val1, val2; |
|
|
|
int x, y, ix1, ix2, iy1, iy2; |
|
|
|
float x1 = s->x1, y1 = s->y1, x2 = s->x2, y2 = s->y2; |
|
|
|
float g, xd, yd, xgap, xend, yend, xf, yf, val1, val2; |
|
|
|
int x, y, ix1, ix2, iy1, iy2; |
|
|
|
|
|
|
|
xd = x2 - x1; |
|
|
|
yd = y2 - y1; |
|
|
|
xd = x2 - x1; |
|
|
|
yd = y2 - y1; |
|
|
|
|
|
|
|
/* "Horizontal" line (X greater than Y)*/ |
|
|
|
if (fabsf(xd) > fabsf(yd)) { |
|
|
|
if (x1 > x2) |
|
|
|
/* "Horizontal" line (X greater than Y)*/ |
|
|
|
if (fabsf(xd) > fabsf(yd)) |
|
|
|
{ |
|
|
|
float tmp; |
|
|
|
tmp = x1; x1 = x2; x2 = tmp; |
|
|
|
tmp = y1; y1 = y2; y2 = tmp; |
|
|
|
xd = (x2-x1); |
|
|
|
yd = (y2-y1); |
|
|
|
} |
|
|
|
g = yd/xd; |
|
|
|
|
|
|
|
xend = truncf(x1+0.5); |
|
|
|
yend = y1 + g*(xend-x1); |
|
|
|
xgap = fractinvf(x1+0.5); |
|
|
|
ix1 = (int)xend; |
|
|
|
iy1 = (int)yend; |
|
|
|
val1 = fractinvf(yend)*xgap; |
|
|
|
val2 = fractf(yend)*xgap; |
|
|
|
|
|
|
|
PLOT(ix1, iy1, val1); |
|
|
|
PLOT(ix1, (iy1+1)<y1?(iy1+1):iy1, val2); |
|
|
|
|
|
|
|
yf = yend+g; |
|
|
|
xend = truncf(x2+0.5); |
|
|
|
yend = y2 + g*(xend-x2); |
|
|
|
xgap = fractinvf(x2-0.5); |
|
|
|
ix2 = (int)xend; |
|
|
|
iy2 = (int)yend; |
|
|
|
val1 = fractinvf(yend)*xgap; |
|
|
|
val2 = fractf(yend)*xgap; |
|
|
|
|
|
|
|
PLOT(ix2, iy2, val1); |
|
|
|
PLOT(ix2, iy2+1<y2?iy2+1:iy2, val2); |
|
|
|
|
|
|
|
for (x = (ix1+1); x < ix2; x++) |
|
|
|
if (x1 > x2) |
|
|
|
{ |
|
|
|
float tmp; |
|
|
|
tmp = x1; x1 = x2; x2 = tmp; |
|
|
|
tmp = y1; y1 = y2; y2 = tmp; |
|
|
|
xd = (x2-x1); |
|
|
|
yd = (y2-y1); |
|
|
|
} |
|
|
|
g = yd/xd; |
|
|
|
|
|
|
|
xend = truncf(x1+0.5); |
|
|
|
yend = y1 + g*(xend-x1); |
|
|
|
xgap = fractinvf(x1+0.5); |
|
|
|
ix1 = (int)xend; |
|
|
|
iy1 = (int)yend; |
|
|
|
val1 = fractinvf(yend)*xgap; |
|
|
|
val2 = fractf(yend)*xgap; |
|
|
|
|
|
|
|
PLOT(ix1, iy1, val1); |
|
|
|
PLOT(ix1, (iy1+1)<y1?(iy1+1):iy1, val2); |
|
|
|
|
|
|
|
yf = yend+g; |
|
|
|
xend = truncf(x2+0.5); |
|
|
|
yend = y2 + g*(xend-x2); |
|
|
|
xgap = fractinvf(x2-0.5); |
|
|
|
ix2 = (int)xend; |
|
|
|
iy2 = (int)yend; |
|
|
|
val1 = fractinvf(yend)*xgap; |
|
|
|
val2 = fractf(yend)*xgap; |
|
|
|
|
|
|
|
PLOT(ix2, iy2, val1); |
|
|
|
PLOT(ix2, iy2+1<y2?iy2+1:iy2, val2); |
|
|
|
|
|
|
|
for (x = (ix1+1); x < ix2; x++) |
|
|
|
{ |
|
|
|
float focus; |
|
|
|
|
|
|
|
val1 = fractinvf(yf); |
|
|
|
val2 = fractf(yf); |
|
|
|
focus = (1.0 - fabsf(val1-val2)); |
|
|
|
val1 += 0.3*focus; |
|
|
|
val2 += 0.3*focus; |
|
|
|
|
|
|
|
PLOT(x, yf, val1); |
|
|
|
PLOT(x, (yf+1)<y1?(yf+1):yf, val2); |
|
|
|
|
|
|
|
yf = yf + g; |
|
|
|
} |
|
|
|
} |
|
|
|
/* "Vertical" line (Y greater than X)*/ |
|
|
|
else |
|
|
|
{ |
|
|
|
float focus; |
|
|
|
|
|
|
|
val1 = fractinvf(yf); |
|
|
|
val2 = fractf(yf); |
|
|
|
focus = (1.0 - fabsf(val1-val2)); |
|
|
|
val1 += 0.3*focus; |
|
|
|
val2 += 0.3*focus; |
|
|
|
|
|
|
|
PLOT(x, yf, val1); |
|
|
|
PLOT(x, (yf+1)<y1?(yf+1):yf, val2); |
|
|
|
|
|
|
|
yf = yf + g; |
|
|
|
} |
|
|
|
} |
|
|
|
/* "Vertical" line (Y greater than X)*/ |
|
|
|
else { |
|
|
|
if (x1 > x2) |
|
|
|
{ |
|
|
|
float tmp; |
|
|
|
tmp = x1; x1 = x2; x2 = tmp; |
|
|
|
tmp = y1; y1 = y2; y2 = tmp; |
|
|
|
xd = (x2-x1); |
|
|
|
yd = (y2-y1); |
|
|
|
} |
|
|
|
|
|
|
|
g = xd/yd; |
|
|
|
|
|
|
|
xend = truncf(x1+0.5); |
|
|
|
yend = y1 + g*(xend-x1); |
|
|
|
xgap = fractf(x1+0.5); |
|
|
|
ix1 = (int)xend; |
|
|
|
iy1 = (int)yend; |
|
|
|
val1 = fractinvf(yend)*xgap; |
|
|
|
val2 = fractf(yend)*xgap; |
|
|
|
|
|
|
|
PLOT(ix1, iy1, val1); |
|
|
|
PLOT(ix1, (iy1+1)<y1?(iy1+1):iy1, val2); |
|
|
|
|
|
|
|
xf = xend + g; |
|
|
|
|
|
|
|
xend = truncf(x2+0.5); |
|
|
|
yend = y2 + g*(xend-x2); |
|
|
|
xgap = fractinvf(x2-0.5); |
|
|
|
ix2 = (int)xend; |
|
|
|
iy2 = (int)yend; |
|
|
|
val1 = fractinvf(yend)*xgap; |
|
|
|
val2 = fractf(yend)*xgap; |
|
|
|
|
|
|
|
PLOT(ix2, iy2, val1); |
|
|
|
PLOT(ix2, (iy2+1)<y2?(iy2+1):iy2, val2); |
|
|
|
|
|
|
|
|
|
|
|
for (y = (iy1+1); y < iy2; y++) |
|
|
|
{ |
|
|
|
float focus; |
|
|
|
int vx = xf; |
|
|
|
val1 = fractinvf(xf); |
|
|
|
val2 = fractf(xf); |
|
|
|
focus = (1.0 - fabsf(val1-val2)); |
|
|
|
val1 += 0.3*focus; |
|
|
|
val2 += 0.3*focus; |
|
|
|
PLOT(vx, y, val1); |
|
|
|
vx++; |
|
|
|
PLOT(vx, y, val2); |
|
|
|
xf = xf + g; |
|
|
|
} |
|
|
|
} |
|
|
|
if (x1 > x2) |
|
|
|
{ |
|
|
|
float tmp; |
|
|
|
tmp = x1; x1 = x2; x2 = tmp; |
|
|
|
tmp = y1; y1 = y2; y2 = tmp; |
|
|
|
xd = (x2-x1); |
|
|
|
yd = (y2-y1); |
|
|
|
} |
|
|
|
|
|
|
|
g = xd/yd; |
|
|
|
|
|
|
|
xend = truncf(x1+0.5); |
|
|
|
yend = y1 + g*(xend-x1); |
|
|
|
xgap = fractf(x1+0.5); |
|
|
|
ix1 = (int)xend; |
|
|
|
iy1 = (int)yend; |
|
|
|
val1 = fractinvf(yend)*xgap; |
|
|
|
val2 = fractf(yend)*xgap; |
|
|
|
|
|
|
|
PLOT(ix1, iy1, val1); |
|
|
|
PLOT(ix1, (iy1+1)<y1?(iy1+1):iy1, val2); |
|
|
|
|
|
|
|
xf = xend + g; |
|
|
|
|
|
|
|
xend = truncf(x2+0.5); |
|
|
|
yend = y2 + g*(xend-x2); |
|
|
|
xgap = fractinvf(x2-0.5); |
|
|
|
ix2 = (int)xend; |
|
|
|
iy2 = (int)yend; |
|
|
|
val1 = fractinvf(yend)*xgap; |
|
|
|
val2 = fractf(yend)*xgap; |
|
|
|
|
|
|
|
PLOT(ix2, iy2, val1); |
|
|
|
PLOT(ix2, (iy2+1)<y2?(iy2+1):iy2, val2); |
|
|
|
|
|
|
|
|
|
|
|
for (y = (iy1+1); y < iy2; y++) |
|
|
|
{ |
|
|
|
float focus; |
|
|
|
int vx = xf; |
|
|
|
val1 = fractinvf(xf); |
|
|
|
val2 = fractf(xf); |
|
|
|
focus = (1.0 - fabsf(val1-val2)); |
|
|
|
val1 += 0.3*focus; |
|
|
|
val2 += 0.3*focus; |
|
|
|
PLOT(vx, y, val1); |
|
|
|
vx++; |
|
|
|
PLOT(vx, y, val2); |
|
|
|
xf = xf + g; |
|
|
|
} |
|
|
|
} |