backends: Add support for timers to backends.
[gfxprim/pasky.git] / libs / gfx / GP_HLine.gen.c.t
blob72f1555754e284dd448449b617a775cbb55964cf
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-2011 Jiri "BlueBear" Dluhos                            *
20  *                         <jiri.bluebear.dluhos@gmail.com>                  *
21  *                                                                           *
22  * Copyright (C) 2009-2012 Cyril Hrubis <metan@ucw.cz>                       *
23  *                                                                           *
24  *****************************************************************************/
26 %% extends "base.c.t"
28 {% block descr %}Horizontal line drawing{% endblock %}
30 %% block body
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',
39                            '2BPP_LE', '2BPP_BE',
40                            '4BPP_LE', '4BPP_BE',
41                            '8BPP', '16BPP',
42                            '24BPP', '32BPP']
44 %% for ps in pixelsizes
46 void GP_HLine_Raw_{{ ps.suffix }}(GP_Context *context, int x0, int x1, int y,
47                                GP_Pixel pixel)
49         /* draw always from left to right, swap coords if necessary */
50         if (x0 > x1)
51                 GP_SWAP(x0, x1);
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)
55                 return;
57         /* clip the line against surface boundaries */
58         x0 = GP_MAX(x0, 0);
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);
69 %%   else
70         GP_WritePixels_{{ ps.suffix }}(start, length, pixel);
71 %%   endif
73 %%  else
74         for (;x0 <= x1; x0++)
75                 GP_PutPixel_Raw_{{ ps.suffix }}(context, x0, y, pixel);
76 %%  endif
79 %% endfor
80 %% endblock body