3 {% block descr %}Anti Aliased Vertical Line{% endblock %}
7 #include "core/GP_Context.h"
8 #include "core/GP_MixPixels.h"
9 #include "core/GP_FixedPoint.h"
10 #include "core/GP_GammaCorrection.h"
12 #define FP_TO_PERC(a) (GP_FP_ROUND_TO_INT((a) * 255))
14 void GP_VLineAA_Raw(GP_Context *context, GP_Coord x, GP_Coord y0,
15 GP_Coord y1, GP_Pixel pixel)
24 GP_Coord int_y0 = GP_FP_TO_INT(y0);
25 GP_Coord int_y1 = GP_FP_TO_INT(y1);
26 GP_Coord int_x = GP_FP_TO_INT(x);
28 /* Line is shorter than two pixels */
29 if (int_y0 == int_y1) {
34 /* Draw the starting and ending pixel */
37 perc = FP_TO_PERC(GP_FP_MUL(GP_FP_RFRAC(x), GP_FP_RFRAC(y0)));
38 GP_MixPixel_Raw_Clipped(context, int_x, int_y0, pixel, perc);
40 perc = FP_TO_PERC(GP_FP_MUL(GP_FP_FRAC(x), GP_FP_RFRAC(y0)));
41 GP_MixPixel_Raw_Clipped(context, int_x+1, int_y0, pixel, perc);
44 perc = FP_TO_PERC(GP_FP_MUL(GP_FP_RFRAC(x), GP_FP_FRAC(y1)));
45 GP_MixPixel_Raw_Clipped(context, int_x, int_y1, pixel, perc);
47 perc = FP_TO_PERC(GP_FP_MUL(GP_FP_FRAC(x), GP_FP_FRAC(y1)));
48 GP_MixPixel_Raw_Clipped(context, int_x+1, int_y1, pixel, perc);
50 /* Draw the middle pixels */
51 uint8_t up = FP_TO_PERC(GP_FP_RFRAC(x));
52 uint8_t lp = FP_TO_PERC(GP_FP_FRAC(x));
56 for (y = int_y0 + 1; y < int_y1; y++) {
57 GP_MixPixel_Raw_Clipped(context, int_x, y, pixel, up);
58 GP_MixPixel_Raw_Clipped(context, int_x+1, y, pixel, lp);