Rename GP_Context -> GP_Pixmap
[gfxprim.git] / libs / gfx / GP_HLine.gen.c.t
blobd2e212374f4623a0caed5f58997141950da1e374
1 @ include source.t
2 /*
3  * Horizontal line drawing
4  *
5  * Copyright (C) 2009-2011 Jiri "BlueBear" Dluhos
6  *                         <jiri.bluebear.dluhos@gmail.com>
7  * Copyright (C) 2009-2014 Cyril Hrubis <metan@ucw.cz>
8  */
10 #include "core/GP_GetPutPixel.gen.h"
11 #include "core/GP_WritePixel.h"
13 #include "gfx/GP_HLine.h"
15 @ # Explicit list of BPP that have optimized write pixel
16 @ have_writepixels = ['1BPP_LE', '1BPP_BE',
17 @                     '2BPP_LE', '2BPP_BE',
18 @                     '4BPP_LE', '4BPP_BE',
19 @                     '8BPP', '16BPP',
20 @                     '24BPP', '32BPP']
22 @ for ps in pixelsizes:
23 void GP_HLine_Raw_{{ ps.suffix }}(GP_Pixmap *pixmap, int x0, int x1, int y,
24                                GP_Pixel pixel)
26         /* draw always from left to right, swap coords if necessary */
27         if (x0 > x1)
28                 GP_SWAP(x0, x1);
30         /* return immediately if the line is completely out of surface */
31         if (y < 0 || y >= (int) pixmap->h || x1 < 0 || x0 >= (int) pixmap->w)
32                 return;
34         /* clip the line against surface boundaries */
35         x0 = GP_MAX(x0, 0);
36         x1 = GP_MIN(x1, (int) pixmap->w - 1);
38 @     if ps.suffix in have_writepixels:
39         size_t length = 1 + x1 - x0;
40         void *start = GP_PIXEL_ADDR(pixmap, x0, y);
42 @         if ps.needs_bit_endian():
43         unsigned int offset = GP_PIXEL_ADDR_OFFSET_{{ ps.suffix }}(x0);
45         GP_WritePixels_{{ ps.suffix }}(start, offset, length, pixel);
46 @         else:
47         GP_WritePixels_{{ ps.suffix }}(start, length, pixel);
48 @     else:
49         for (;x0 <= x1; x0++)
50                 GP_PutPixel_Raw_{{ ps.suffix }}(pixmap, x0, y, pixel);
51 @     end