3 * Horizontal line drawing
5 * Copyright (C) 2009-2011 Jiri "BlueBear" Dluhos
6 * <jiri.bluebear.dluhos@gmail.com>
7 * Copyright (C) 2009-2014 Cyril Hrubis <metan@ucw.cz>
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',
22 @ for ps in pixelsizes:
23 void GP_HLine_Raw_{{ ps.suffix }}(GP_Pixmap *pixmap, int x0, int x1, int y,
26 /* draw always from left to right, swap coords if necessary */
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)
34 /* clip the line against surface boundaries */
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);
47 GP_WritePixels_{{ ps.suffix }}(start, length, pixel);
50 GP_PutPixel_Raw_{{ ps.suffix }}(pixmap, x0, y, pixel);