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-2010 Cyril Hrubis <metan@ucw.cz> *
24 *****************************************************************************/
26 /* A vertical line drawing algorithm. */
28 /* Ensures that coordinates are in correct order, and clips them.
29 * Exits immediately if the line is completely clipped out.
31 #define ORDER_AND_CLIP_COORDS do { \
32 if (y0 > y1) GP_SWAP(y0, y1); \
33 if (x < (int) context->clip_w_min \
34 || x > (int) context->clip_w_max \
35 || y1 < (int) context->clip_h_min \
36 || y0 > (int) context->clip_h_max) { \
39 y0 = GP_MAX(y0, (int) context->clip_h_min); \
40 y1 = GP_MIN(y1, (int) context->clip_h_max); \
44 * This macro defines a horizontal line drawing function.
46 * CONTEXT_T - user-defined type of drawing context (passed to PUTPIXEL)
47 * PIXVAL_T - user-defined pixel value type (passed to PUTPIXEL)
48 * PIXEL_ADDRESS - a function that returns a pointer to a pixel in memory,
49 * in form f(context, y, x)
50 * WRITE_PIXELS - a function that fills a linear block with pixel value,
51 * in form f(start, length, pixel)
52 * FN_NAME - name of the function to be defined
54 #define DEF_VLINE_FN(FN_NAME, CONTEXT_T, PIXEL_T, PUT_PIXEL) \
55 void FN_NAME(CONTEXT_T context, int x, int y0, int y1, PIXEL_T pixel) \
57 ORDER_AND_CLIP_COORDS; \
60 for (y = y0; y <= y1; y++) \
61 PUT_PIXEL(context, x, y, pixel); \