1 /*****************************************************************************
2 * This file is part of gfxprim library. *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
19 * Copyright (C) 2009-2013 Cyril Hrubis <metan@ucw.cz> *
21 *****************************************************************************/
23 /* Anti Aliased Vertical Line */
25 #include "core/GP_Pixmap.h"
26 #include "core/GP_MixPixels.h"
27 #include "core/GP_FixedPoint.h"
28 #include "core/GP_GammaCorrection.h"
30 #define FP_TO_PERC(a) (GP_FP_ROUND_TO_INT((a) * 255))
32 void GP_VLineAA_Raw(GP_Pixmap *pixmap, GP_Coord x, GP_Coord y0,
33 GP_Coord y1, GP_Pixel pixel)
42 GP_Coord int_y0 = GP_FP_TO_INT(y0);
43 GP_Coord int_y1 = GP_FP_TO_INT(y1);
44 GP_Coord int_x = GP_FP_TO_INT(x);
46 /* Line is shorter than two pixels */
47 if (int_y0 == int_y1) {
52 /* Draw the starting and ending pixel */
55 perc = FP_TO_PERC(GP_FP_MUL(GP_FP_RFRAC(x), GP_FP_RFRAC(y0)));
56 GP_MixPixel_Raw_Clipped(pixmap, int_x, int_y0, pixel, perc);
58 perc = FP_TO_PERC(GP_FP_MUL(GP_FP_FRAC(x), GP_FP_RFRAC(y0)));
59 GP_MixPixel_Raw_Clipped(pixmap, int_x+1, int_y0, pixel, perc);
61 perc = FP_TO_PERC(GP_FP_MUL(GP_FP_RFRAC(x), GP_FP_FRAC(y1)));
62 GP_MixPixel_Raw_Clipped(pixmap, int_x, int_y1, pixel, perc);
64 perc = FP_TO_PERC(GP_FP_MUL(GP_FP_FRAC(x), GP_FP_FRAC(y1)));
65 GP_MixPixel_Raw_Clipped(pixmap, int_x+1, int_y1, pixel, perc);
67 /* Draw the middle pixels */
68 uint8_t up = FP_TO_PERC(GP_FP_RFRAC(x));
69 uint8_t lp = FP_TO_PERC(GP_FP_FRAC(x));
73 for (y = int_y0 + 1; y < int_y1; y++) {
74 GP_MixPixel_Raw_Clipped(pixmap, int_x, y, pixel, up);
75 GP_MixPixel_Raw_Clipped(pixmap, int_x+1, y, pixel, lp);