loaders: Add meta-data clear method and double type.
[gfxprim.git] / libs / gfx / GP_VLineAA.gen.c.t
blobe754d3e12f89f7f60d0c00a6fc1dea9f95bb006d
1 %% extends "base.c.t"
3 {% block descr %}Anti Aliased Vertical Line{% endblock %}
5 %% block body
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)
17         if (y1 < y0)
18                 GP_SWAP(y1, y0);
20         y0 -= GP_FP_1_2;
21         y1 += GP_FP_1_2;
22         x  -= GP_FP_1_2;
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) {
30                 //TODO          
31                 return;
32         }
34         /* Draw the starting and ending pixel */
35         uint8_t perc;
36         
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); 
42         
43         
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));
54         GP_Coord y;
55         
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);
59         }
62 %% endblock body