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-2010 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 ellipse drawing algorithm.{% endblock %}
32 #include "core/GP_GetPutPixel.h"
33 #include "core/GP_FnPerBpp.h"
34 #include "gfx/GP_HLine.h"
35 #include "gfx/GP_VLine.h"
36 #include "gfx/GP_Ellipse.h"
39 * A filled ellipse drawing algorithm.
41 * The algorithm is exactly the same as with GP_Ellipse() except that
42 * we draw a line between each two points at each side of the X axis;
43 * therefore, we don't need to draw any points during iterations of X,
44 * we just iterate X until Y reaches next line, and then draw the full line.
47 %% for ps in pixelsizes
49 static void GP_FillEllipse_Raw_{{ ps.suffix }}(GP_Context *context, GP_Coord xcenter,
50 GP_Coord ycenter, GP_Size a, GP_Size b, GP_Pixel pixel)
52 /* Precompute quadratic terms. */
56 /* Handle special case */
58 GP_VLine_Raw_{{ ps.suffix }}(context, xcenter, ycenter - b, ycenter + b, pixel);
63 for (x = 0, error = -b2*a, y = b; y >= 0; y--) {
65 error += b2 * (2*x + 1);
68 error += a2 * (-2*y + 1);
70 /* Draw two horizontal lines reflected across Y. */
71 GP_HLine_Raw_{{ ps.suffix }}(context, xcenter-x+1, xcenter+x-1, ycenter-y, pixel);
72 GP_HLine_Raw_{{ ps.suffix }}(context, xcenter-x+1, xcenter+x-1, ycenter+y, pixel);
78 void GP_FillEllipse_Raw(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
79 GP_Size a, GP_Size b, GP_Pixel pixel)
81 GP_CHECK_CONTEXT(context);
83 GP_FN_PER_BPP_CONTEXT(GP_FillEllipse_Raw, context, context,
84 xcenter, ycenter, a, b, pixel);
87 void GP_FillEllipse(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
88 GP_Size a, GP_Size b, GP_Pixel pixel)
90 GP_CHECK_CONTEXT(context);
92 GP_TRANSFORM_POINT(context, xcenter, ycenter);
93 GP_TRANSFORM_SWAP(context, a, b);
95 GP_FillEllipse_Raw(context, xcenter, ycenter, a, b, pixel);