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-2011 Jiri "BlueBear" Dluhos *
20 * <jiri.bluebear.dluhos@gmail.com> *
22 * Copyright (C) 2009-2012 Cyril Hrubis <metan@ucw.cz> *
24 *****************************************************************************/
28 {% block descr %}Horizontal line drawing{% endblock %}
32 #include "core/GP_GetPutPixel.gen.h"
33 #include "core/GP_WritePixel.h"
35 #include "gfx/GP_HLine.h"
37 {# Explicit list of BPP that have optimized write pixel #}
38 %% set have_writepixels = ['1BPP_LE', '1BPP_BE',
44 %% for ps in pixelsizes
46 void GP_HLine_Raw_{{ ps.suffix }}(GP_Context *context, int x0, int x1, int y,
49 /* draw always from left to right, swap coords if necessary */
53 /* return immediately if the line is completely out of surface */
54 if (y < 0 || y >= (int) context->h || x1 < 0 || x0 >= (int) context->w)
57 /* clip the line against surface boundaries */
59 x1 = GP_MIN(x1, (int) context->w - 1);
61 %% if ps.suffix in have_writepixels
62 size_t length = 1 + x1 - x0;
63 void *start = GP_PIXEL_ADDR(context, x0, y);
65 %% if ps.needs_bit_endian()
66 unsigned int offset = GP_PIXEL_ADDR_OFFSET_{{ ps.suffix }}(x0);
68 GP_WritePixels_{{ ps.suffix }}(start, offset, length, pixel);
70 GP_WritePixels_{{ ps.suffix }}(start, length, pixel);
75 GP_PutPixel_Raw_{{ ps.suffix }}(context, x0, y, pixel);