3 * A filled circle drawing algorithm.
5 * Copyright (C) 2009-2012 Jiri "BlueBear" Dluhos
6 * <jiri.bluebear.dluhos@gmail.com>
7 * Copyright (C) 2009-2014 Cyril Hrubis <metan@ucw.cz>
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.
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.
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 */
32 GP_PutPixel_Raw_{{ ps.suffix }}(pixmap, xcenter, ycenter, pixel);
37 for (x = 0, error = -r, y = r; y >= 0; y--) {
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);
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);