Rename GP_Context -> GP_Pixmap
[gfxprim.git] / libs / gfx / algo / FillRing.algo.h
blob0673cfd85f92cd8217126d835aa6022ed0d53d77
1 /*****************************************************************************
2 * This file is part of gfxprim library. *
3 * *
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. *
8 * *
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. *
13 * *
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 *
18 * *
19 * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
20 * <jiri.bluebear.dluhos@gmail.com> *
21 * *
22 * Copyright (C) 2009-2012 Cyril Hrubis <metan@ucw.cz> *
23 * *
24 *****************************************************************************/
27 * A filled ring drawing algorithm.
31 * This macro defines a filled circle drawing function.
32 * Arguments:
33 * PIXMAP_T - user-defined type of drawing pixmap (passed to HLINE)
34 * PIXVAL_T - user-defined pixel value type (passed to HLINE)
35 * HLINE - horizontal line drawing function f(pixmap, x0, x1, y, pixval)
36 * FN_NAME - name of the function to be defined
38 #define DEF_FILLRING_FN(FN_NAME, PIXMAP_T, PIXVAL_T, HLINE) \
39 static void FN_NAME(PIXMAP_T pixmap, int xcenter, int ycenter, \
40 unsigned int r1, unsigned int r2, PIXVAL_T pixval) \
41 { \
42 int outer_r = (int) GP_MAX(r1, r2); \
43 int inner_r = (int) GP_MIN(r1, r2); \
44 int outer_x = 0; \
45 int inner_x = 0; \
46 int y; \
47 int outer_error = -outer_r; \
48 int inner_error = -inner_r; \
49 for (y = outer_r; y >= 0; y--) { \
51 while (outer_error < 0) { \
52 outer_error += 2*outer_x + 1; \
53 outer_x++; \
54 } \
55 outer_error += -2*y + 1; \
57 if (y < inner_r && y > -inner_r) { \
58 while (inner_error < 0) { \
59 inner_error += 2*inner_x + 1; \
60 inner_x++; \
61 } \
62 inner_error += -2*y + 1; \
64 HLINE(pixmap, xcenter - outer_x + 1, xcenter - inner_x, ycenter - y, pixval); \
65 HLINE(pixmap, xcenter + inner_x, xcenter + outer_x - 1, ycenter - y, pixval); \
66 HLINE(pixmap, xcenter - outer_x + 1, xcenter - inner_x, ycenter + y, pixval); \
67 HLINE(pixmap, xcenter + inner_x, xcenter + outer_x - 1, ycenter + y, pixval); \
68 } else { \
69 HLINE(pixmap, xcenter - outer_x + 1, xcenter + outer_x - 1, ycenter-y, pixval); \
70 HLINE(pixmap, xcenter - outer_x + 1, xcenter + outer_x - 1, ycenter+y, pixval); \
71 } \
72 } \