loaders: PNG: Handle gamma on 16bpp conversion
[gfxprim.git] / libs / gfx / GP_VLineAA.gen.c.t
blob22c220d65f1c955a2104c168f9f7e74bd6b99045
1 /*****************************************************************************
2  * This file is part of gfxprim library.                                     *
3  *                                                                           *
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.        *
8  *                                                                           *
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.                           *
13  *                                                                           *
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                                               *
18  *                                                                           *
19  * Copyright (C) 2009-2013 Cyril Hrubis <metan@ucw.cz>                       *
20  *                                                                           *
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)
35         if (y1 < y0)
36                 GP_SWAP(y1, y0);
38         y0 -= GP_FP_1_2;
39         y1 += GP_FP_1_2;
40         x  -= GP_FP_1_2;
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) {
48                 //TODO
49                 return;
50         }
52         /* Draw the starting and ending pixel */
53         uint8_t perc;
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));
71         GP_Coord y;
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);
76         }