summaryrefslogtreecommitdiff
path: root/cd/src/sim/sim_linepolyfill.c
diff options
context:
space:
mode:
authorNicolas "Pixel" Noble <pixel@nobis-crew.org>2010-09-09 01:48:52 +0200
committerNicolas "Pixel" Noble <pixel@nobis-crew.org>2010-09-09 01:50:25 +0200
commite9a184546b18cf3b796bd560561f312934004c54 (patch)
treeaa785af9a8d03f8ce276c9e9ecec78397005ec22 /cd/src/sim/sim_linepolyfill.c
parent92efe73791d0998536042bfab5a1babc67d168c7 (diff)
Upgrading to CD 5.4 - and cleaning up.
Diffstat (limited to 'cd/src/sim/sim_linepolyfill.c')
-rwxr-xr-xcd/src/sim/sim_linepolyfill.c98
1 files changed, 78 insertions, 20 deletions
diff --git a/cd/src/sim/sim_linepolyfill.c b/cd/src/sim/sim_linepolyfill.c
index 2454a00..f73b26f 100755
--- a/cd/src/sim/sim_linepolyfill.c
+++ b/cd/src/sim/sim_linepolyfill.c
@@ -712,13 +712,67 @@ void simLineThick(cdCanvas* canvas, int x1, int y1, int x2, int y2)
cdCanvasLineStyle(canvas, style);
}
+void simfLineThick(cdCanvas* canvas, double x1, double y1, double x2, double y2)
+{
+ const int interior = canvas->interior_style;
+ const int width = canvas->line_width;
+ const int style = canvas->line_style;
+
+ const double dx = x2-x1;
+ const double dy = y2-y1;
+
+ const double len = hypot(dx,dy);
+
+ const double dnx = dx/len;
+ const double dny = dy/len;
+
+ const double w1 = width/2.0;
+ const double w2 = width-w1;
+
+ const double n1x = w1*dny;
+ const double n1y = -w1*dnx;
+
+ const double n2x = -w2*dny;
+ const double n2y = w2*dnx;
+
+ const double p1x = x1 + n1x;
+ const double p1y = y1 + n1y;
+ const double p2x = x1 + n2x;
+ const double p2y = y1 + n2y;
+ const double p3x = p2x + dx;
+ const double p3y = p2y + dy;
+ const double p4x = p1x + dx;
+ const double p4y = p1y + dy;
+
+ cdPoint poly[4];
+
+ cdCanvasLineWidth(canvas, 1);
+ cdCanvasInteriorStyle(canvas, CD_SOLID);
+ cdCanvasLineStyle(canvas, CD_CONTINUOUS);
+
+ poly[0].x = _cdRound(p1x);
+ poly[0].y = _cdRound(p1y);
+ poly[1].x = _cdRound(p2x);
+ poly[1].y = _cdRound(p2y);
+ poly[2].x = _cdRound(p3x);
+ poly[2].y = _cdRound(p3y);
+ poly[3].x = _cdRound(p4x);
+ poly[3].y = _cdRound(p4y);
+
+ simPolyFill(canvas->simulation, poly, 4);
+
+ cdCanvasLineWidth(canvas, width);
+ cdCanvasInteriorStyle(canvas, interior);
+ cdCanvasLineStyle(canvas, style);
+}
+
void simLineThin(cdCanvas* canvas, int x1, int y1, int x2, int y2)
{
unsigned short ErrorInc, ErrorAcc;
unsigned short ErrorAccTemp, Weighting;
int DeltaX, DeltaY, XDir;
long aa_fgcolor;
- unsigned char alpha = cdAlpha(canvas->foreground), aa_alpha;
+ unsigned char alpha = cdAlpha(canvas->foreground), aa_alpha1, aa_alpha2;
int no_antialias = !(canvas->simulation->antialias);
unsigned short int ls;
long fgcolor = canvas->foreground;
@@ -840,11 +894,12 @@ void simLineThin(cdCanvas* canvas, int x1, int y1, int x2, int y2)
weighting for the paired pixel.
Combine the Weighting with the existing alpha,
When Weighting is zero alpha must be fully preserved. */
- aa_alpha = (unsigned char)(((255-Weighting) * alpha) / 255);
+ aa_alpha1 = (unsigned char)(((255-Weighting) * alpha) / 255);
+ aa_alpha2 = (unsigned char)((Weighting * alpha) / 255);
- aa_fgcolor = cdEncodeAlpha(fgcolor, aa_alpha);
+ aa_fgcolor = cdEncodeAlpha(fgcolor, aa_alpha1);
_cdLineDrawPixel(canvas, x1, y1, ls, aa_fgcolor);
- aa_fgcolor = cdEncodeAlpha(fgcolor, 255-aa_alpha);
+ aa_fgcolor = cdEncodeAlpha(fgcolor, aa_alpha2);
_cdLineDrawPixel(canvas, x1 + XDir, y1, ls, aa_fgcolor);
ls = simRotateLineStyle(ls);
}
@@ -891,11 +946,12 @@ void simLineThin(cdCanvas* canvas, int x1, int y1, int x2, int y2)
weighting for the paired pixel.
Combine the Weighting with the existing alpha,
When Weighting is zero alpha must be fully preserved. */
- aa_alpha = (unsigned char)(((255-Weighting) * alpha) / 255);
+ aa_alpha1 = (unsigned char)(((255-Weighting) * alpha) / 255);
+ aa_alpha2 = (unsigned char)((Weighting * alpha) / 255);
- aa_fgcolor = cdEncodeAlpha(fgcolor, aa_alpha);
+ aa_fgcolor = cdEncodeAlpha(fgcolor, aa_alpha1);
_cdLineDrawPixel(canvas, x1, y1, ls, aa_fgcolor);
- aa_fgcolor = cdEncodeAlpha(fgcolor, 255-aa_alpha);
+ aa_fgcolor = cdEncodeAlpha(fgcolor, aa_alpha2);
_cdLineDrawPixel(canvas, x1, y1+1, ls, aa_fgcolor);
ls = simRotateLineStyle(ls);
}
@@ -914,7 +970,7 @@ void simfLineThin(cdCanvas* canvas, double x1, double y1, double x2, double y2,
{
double DeltaX, DeltaY, a, b;
long aa_fgcolor;
- unsigned char alpha = cdAlpha(canvas->foreground), aa_alpha;
+ unsigned char alpha = cdAlpha(canvas->foreground), aa_alpha1, aa_alpha2;
int no_antialias = !(canvas->simulation->antialias);
int yi, xi, update_a = 1, update_b = 1;
unsigned short int ls;
@@ -975,11 +1031,12 @@ void simfLineThin(cdCanvas* canvas, double x1, double y1, double x2, double y2,
/* Combine the Weighting with the existing alpha,
When Weighting is zero alpha must be fully preserved. */
- aa_alpha = (unsigned char)((1.0-(x - xi)) * alpha);
+ aa_alpha1 = (unsigned char)((1.0-(x - xi)) * alpha);
+ aa_alpha2 = (unsigned char)((x - xi) * alpha);
if (no_antialias)
{
- if (aa_alpha > 128)
+ if (aa_alpha1 > 128)
_cdLineDrawPixel(canvas, xi, yi, ls, fgcolor)
else
_cdLineDrawPixel(canvas, xi+1, yi, ls, fgcolor)
@@ -999,7 +1056,7 @@ void simfLineThin(cdCanvas* canvas, double x1, double y1, double x2, double y2,
if ((xi != *last_xi_a || yi != *last_yi_a) &&
(xi != *last_xi_b || yi != *last_yi_b))
{
- aa_fgcolor = cdEncodeAlpha(fgcolor, aa_alpha);
+ aa_fgcolor = cdEncodeAlpha(fgcolor, aa_alpha1);
_cdLineDrawPixel(canvas, xi, yi, ls, aa_fgcolor);
if (yi == yi_last) /* one pixel only */
@@ -1009,7 +1066,7 @@ void simfLineThin(cdCanvas* canvas, double x1, double y1, double x2, double y2,
if ((xi+1 != *last_xi_a || yi != *last_yi_a) &&
(xi+1 != *last_xi_b || yi != *last_yi_b))
{
- aa_fgcolor = cdEncodeAlpha(fgcolor, 255-aa_alpha);
+ aa_fgcolor = cdEncodeAlpha(fgcolor, aa_alpha2);
_cdLineDrawPixel(canvas, xi+1, yi, ls, aa_fgcolor);
if (yi == yi_last) /* one pixel only */
@@ -1018,9 +1075,9 @@ void simfLineThin(cdCanvas* canvas, double x1, double y1, double x2, double y2,
}
else
{
- aa_fgcolor = cdEncodeAlpha(fgcolor, aa_alpha);
+ aa_fgcolor = cdEncodeAlpha(fgcolor, aa_alpha1);
_cdLineDrawPixel(canvas, xi, yi, ls, aa_fgcolor);
- aa_fgcolor = cdEncodeAlpha(fgcolor, 255-aa_alpha);
+ aa_fgcolor = cdEncodeAlpha(fgcolor, aa_alpha2);
_cdLineDrawPixel(canvas, xi+1, yi, ls, aa_fgcolor);
}
}
@@ -1061,11 +1118,12 @@ void simfLineThin(cdCanvas* canvas, double x1, double y1, double x2, double y2,
/* Combine the Weighting with the existing alpha,
When Weighting is zero alpha must be fully preserved. */
- aa_alpha = (unsigned char)((1.0-(y - yi)) * alpha);
+ aa_alpha1 = (unsigned char)((1.0-(y - yi)) * alpha);
+ aa_alpha2 = (unsigned char)((y - yi) * alpha);
if (no_antialias)
{
- if (aa_alpha > 128)
+ if (aa_alpha1 > 128)
_cdLineDrawPixel(canvas, xi, yi, ls, fgcolor)
else
_cdLineDrawPixel(canvas, xi, yi+1, ls, fgcolor)
@@ -1085,7 +1143,7 @@ void simfLineThin(cdCanvas* canvas, double x1, double y1, double x2, double y2,
if ((xi != *last_xi_a || yi != *last_yi_a) &&
(xi != *last_xi_b || yi != *last_yi_b))
{
- aa_fgcolor = cdEncodeAlpha(fgcolor, aa_alpha);
+ aa_fgcolor = cdEncodeAlpha(fgcolor, aa_alpha1);
_cdLineDrawPixel(canvas, xi, yi, ls, aa_fgcolor);
if (xi == xi_last) /* one pixel only */
@@ -1095,7 +1153,7 @@ void simfLineThin(cdCanvas* canvas, double x1, double y1, double x2, double y2,
if ((xi != *last_xi_a || yi+1 != *last_yi_a) &&
(xi != *last_xi_b || yi+1 != *last_yi_b))
{
- aa_fgcolor = cdEncodeAlpha(fgcolor, 255-aa_alpha);
+ aa_fgcolor = cdEncodeAlpha(fgcolor, aa_alpha2);
_cdLineDrawPixel(canvas, xi, yi+1, ls, aa_fgcolor);
if (xi == xi_last) /* one pixel only */
@@ -1104,9 +1162,9 @@ void simfLineThin(cdCanvas* canvas, double x1, double y1, double x2, double y2,
}
else
{
- aa_fgcolor = cdEncodeAlpha(fgcolor, aa_alpha);
+ aa_fgcolor = cdEncodeAlpha(fgcolor, aa_alpha1);
_cdLineDrawPixel(canvas, xi, yi, ls, aa_fgcolor);
- aa_fgcolor = cdEncodeAlpha(fgcolor, 255-aa_alpha);
+ aa_fgcolor = cdEncodeAlpha(fgcolor, aa_alpha2);
_cdLineDrawPixel(canvas, xi, yi+1, ls, aa_fgcolor);
}
}