Rename GP_Context -> GP_Pixmap
[gfxprim.git] / libs / gfx / GP_FillEllipse.gen.c.t
blob3a86fcfa5e2f0db9985f15c48da7e48bd95762db
1 @ include source.t
2 /*
3  * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos
4  *                         <jiri.bluebear.dluhos@gmail.com>
5  * Copyright (C) 2009-2014 Cyril Hrubis <metan@ucw.cz>
6  */
8 #include "core/GP_GetPutPixel.h"
9 #include "core/GP_FnPerBpp.h"
10 #include "gfx/GP_HLine.h"
11 #include "gfx/GP_VLine.h"
12 #include "gfx/GP_Ellipse.h"
15  * A filled ellipse drawing algorithm.
16  *
17  * The algorithm is exactly the same as with GP_Ellipse() except that
18  * we draw a line between each two points at each side of the X axis;
19  * therefore, we don't need to draw any points during iterations of X,
20  * we just iterate X until Y reaches next line, and then draw the full line.
21  */
23 @ for ps in pixelsizes:
25 static void GP_FillEllipse_Raw_{{ ps.suffix }}(GP_Pixmap *pixmap, GP_Coord xcenter,
26                 GP_Coord ycenter, GP_Size a, GP_Size b, GP_Pixel pixel)
28         /* Precompute quadratic terms. */
29         int a2 = a*a;
30         int b2 = b*b;
32         /* Handle special case */
33         if (a == 0) {
34                 GP_VLine_Raw_{{ ps.suffix }}(pixmap, xcenter, ycenter - b, ycenter + b, pixel);
35                 return;
36         }
38         int x, y, error;
39         for (x = 0, error = -b2*a, y = b; y >= 0; y--) {
40                 while (error < 0) {
41                         error += b2 * (2*x + 1);
42                         x++;
43                 }
44                 error += a2 * (-2*y + 1);
46                 /* Draw two horizontal lines reflected across Y. */
47                 GP_HLine_Raw_{{ ps.suffix }}(pixmap, xcenter-x+1, xcenter+x-1, ycenter-y, pixel);
48                 GP_HLine_Raw_{{ ps.suffix }}(pixmap, xcenter-x+1, xcenter+x-1, ycenter+y, pixel);
49         }
52 @ end
54 void GP_FillEllipse_Raw(GP_Pixmap *pixmap, GP_Coord xcenter, GP_Coord ycenter,
55                         GP_Size a, GP_Size b, GP_Pixel pixel)
57         GP_CHECK_PIXMAP(pixmap);
59         GP_FN_PER_BPP_PIXMAP(GP_FillEllipse_Raw, pixmap, pixmap,
60                               xcenter, ycenter, a, b, pixel);
63 void GP_FillEllipse(GP_Pixmap *pixmap, GP_Coord xcenter, GP_Coord ycenter,
64                     GP_Size a, GP_Size b, GP_Pixel pixel)
66         GP_CHECK_PIXMAP(pixmap);
68         GP_TRANSFORM_POINT(pixmap, xcenter, ycenter);
69         GP_TRANSFORM_SWAP(pixmap, a, b);
71         GP_FillEllipse_Raw(pixmap, xcenter, ycenter, a, b, pixel);