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-2012 Jiri "BlueBear" Dluhos *
20 * <jiri.bluebear.dluhos@gmail.com> *
22 * Copyright (C) 2009-2013 Cyril Hrubis <metan@ucw.cz> *
24 *****************************************************************************/
28 {% block descr %}A filled circle drawing algorithm.{% endblock %}
32 #include "core/GP_GetPutPixel.h"
33 #include "core/GP_Transform.h"
34 #include "core/GP_FnPerBpp.h"
35 #include "gfx/GP_HLine.h"
36 #include "gfx/GP_Circle.h"
39 * A filled circle drawing algorithm.
41 * A filled circle is drawn in the same way as an unfilled one,
42 * in a top-down, line per line manner, except that we don't need to draw
43 * four points in each X step. Instead, we just iterate X
44 * until we accumulate enough Y changes to reach the next line,
45 * and then draw the full line. The top and bottom half are mirrored.
48 %% for ps in pixelsizes
50 static void GP_FillCircle_Raw_{{ ps.suffix }}(GP_Context *context,
51 GP_Coord xcenter, GP_Coord ycenter, GP_Size r, GP_Pixel pixel)
53 /* for r == 0, circle degenerates to a point */
55 GP_PutPixel_Raw_{{ ps.suffix }}(context, xcenter, ycenter, pixel);
60 for (x = 0, error = -r, y = r; y >= 0; y--) {
66 GP_HLine_Raw_{{ ps.suffix }}(context, xcenter-x+1, xcenter+x-1, ycenter-y, pixel);
67 GP_HLine_Raw_{{ ps.suffix }}(context, xcenter-x+1, xcenter+x-1, ycenter+y, pixel);
73 void GP_FillCircle_Raw(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
74 GP_Size r, GP_Pixel pixel)
76 GP_CHECK_CONTEXT(context);
78 GP_FN_PER_BPP_CONTEXT(GP_FillCircle_Raw, context, context,
79 xcenter, ycenter, r, pixel);
82 void GP_FillCircle(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
83 GP_Size r, GP_Pixel pixel)
85 GP_CHECK_CONTEXT(context);
87 GP_TRANSFORM_POINT(context, xcenter, ycenter);
89 GP_FillCircle_Raw(context, xcenter, ycenter, r, pixel);