Rename GP_Context -> GP_Pixmap
[gfxprim.git] / libs / gfx / GP_FillCircle.gen.c.t
blob48ac950102135e6c24e69b76d3ce7c64effbbb35
1 @ include source.t
2 /*
3  * A filled circle drawing algorithm.
4  *
5  * Copyright (C) 2009-2012 Jiri "BlueBear" Dluhos
6  *                         <jiri.bluebear.dluhos@gmail.com>
7  * Copyright (C) 2009-2014 Cyril Hrubis <metan@ucw.cz>
8  */
10 #include "core/GP_GetPutPixel.h"
11 #include "core/GP_Transform.h"
12 #include "core/GP_FnPerBpp.h"
13 #include "gfx/GP_HLine.h"
14 #include "gfx/GP_Circle.h"
17  * A filled circle drawing algorithm.
18  *
19  * A filled circle is drawn in the same way as an unfilled one,
20  * in a top-down, line per line manner, except that we don't need to draw
21  * four points in each X step. Instead, we just iterate X
22  * until we accumulate enough Y changes to reach the next line,
23  * and then draw the full line. The top and bottom half are mirrored.
24  */
25 @ for ps in pixelsizes:
27 static void GP_FillCircle_Raw_{{ ps.suffix }}(GP_Pixmap *pixmap,
28         GP_Coord xcenter, GP_Coord ycenter, GP_Size r, GP_Pixel pixel)
30         /* for r == 0, circle degenerates to a point */
31         if (r == 0) {
32                 GP_PutPixel_Raw_{{ ps.suffix }}(pixmap, xcenter, ycenter, pixel);
33                 return;
34         }
36         int x, y, error;
37         for (x = 0, error = -r, y = r; y >= 0; y--) {
38                 while (error < 0) {
39                         error += 2*x + 1;
40                         x++;
41                 }
42                 error += -2*y + 1;
43                 GP_HLine_Raw_{{ ps.suffix }}(pixmap, xcenter-x+1, xcenter+x-1, ycenter-y, pixel);
44                 GP_HLine_Raw_{{ ps.suffix }}(pixmap, xcenter-x+1, xcenter+x-1, ycenter+y, pixel);
45         }
48 @ end
50 void GP_FillCircle_Raw(GP_Pixmap *pixmap, GP_Coord xcenter, GP_Coord ycenter,
51                        GP_Size r, GP_Pixel pixel)
53         GP_CHECK_PIXMAP(pixmap);
55         GP_FN_PER_BPP_PIXMAP(GP_FillCircle_Raw, pixmap, pixmap,
56                               xcenter, ycenter, r, pixel);
59 void GP_FillCircle(GP_Pixmap *pixmap, GP_Coord xcenter, GP_Coord ycenter,
60                    GP_Size r, GP_Pixel pixel)
62         GP_CHECK_PIXMAP(pixmap);
64         GP_TRANSFORM_POINT(pixmap, xcenter, ycenter);
66         GP_FillCircle_Raw(pixmap, xcenter, ycenter, r, pixel);