GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_hline.gen.h
1// SPDX-License-Identifier: GPL-2.1-or-later
2/*
3 * gp_hline.gen.h
4 *
5 * GENERATED on 2025 10 03 20:51:36 from gp_hline.gen.h.t
6 *
7 * DO NOT MODIFY THIS FILE DIRECTLY!
8 */
9/*
10 * Horizontal line drawing
11 *
12 * Copyright (C) 2009-2011 Jiri "BlueBear" Dluhos
13 * <jiri.bluebear.dluhos@gmail.com>
14 * Copyright (C) 2009-2014 Cyril Hrubis <metan@ucw.cz>
15 */
16
17#ifndef GFX_GP_HLINE_GEN_H__
18#define GFX_GP_HLINE_GEN_H__
19
22
23static inline void gp_hline_raw_1BPP_DB(gp_pixmap *pixmap, int x0, int x1, int y,
24 gp_pixel pixel)
25{
26 /* draw always from left to right, swap coords if necessary */
27 if (x0 > x1)
28 GP_SWAP(x0, x1);
29
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;
33
34 /* clip the line against surface boundaries */
35 x0 = GP_MAX(x0, 0);
36 x1 = GP_MIN(x1, (gp_coord) pixmap->w - 1);
37
38 size_t length = 1 + x1 - x0;
39 void *start = GP_PIXEL_ADDR_1BPP_DB(pixmap, x0, y);
40
41 unsigned int offset = GP_PIXEL_ADDR_OFFSET_1BPP_DB(pixmap, x0);
42 gp_write_pixels_1BPP_DB(start, offset, y, length, pixel);
43}
44
45static inline void gp_hline_raw_1BPP_UB(gp_pixmap *pixmap, int x0, int x1, int y,
46 gp_pixel pixel)
47{
48 /* draw always from left to right, swap coords if necessary */
49 if (x0 > x1)
50 GP_SWAP(x0, x1);
51
52 /* return immediately if the line is completely out of surface */
53 if (y < 0 || y >= (int) pixmap->h || x1 < 0 || x0 >= (int) pixmap->w)
54 return;
55
56 /* clip the line against surface boundaries */
57 x0 = GP_MAX(x0, 0);
58 x1 = GP_MIN(x1, (gp_coord) pixmap->w - 1);
59
60 size_t length = 1 + x1 - x0;
61 void *start = GP_PIXEL_ADDR_1BPP_UB(pixmap, x0, y);
62
63 unsigned int offset = GP_PIXEL_ADDR_OFFSET_1BPP_UB(pixmap, x0);
64 gp_write_pixels_1BPP_UB(start, offset, y, length, pixel);
65}
66
67static inline void gp_hline_raw_2BPP_DB(gp_pixmap *pixmap, int x0, int x1, int y,
68 gp_pixel pixel)
69{
70 /* draw always from left to right, swap coords if necessary */
71 if (x0 > x1)
72 GP_SWAP(x0, x1);
73
74 /* return immediately if the line is completely out of surface */
75 if (y < 0 || y >= (int) pixmap->h || x1 < 0 || x0 >= (int) pixmap->w)
76 return;
77
78 /* clip the line against surface boundaries */
79 x0 = GP_MAX(x0, 0);
80 x1 = GP_MIN(x1, (gp_coord) pixmap->w - 1);
81
82 size_t length = 1 + x1 - x0;
83 void *start = GP_PIXEL_ADDR_2BPP_DB(pixmap, x0, y);
84
85 unsigned int offset = GP_PIXEL_ADDR_OFFSET_2BPP_DB(pixmap, x0);
86 gp_write_pixels_2BPP_DB(start, offset, length, pixel);
87}
88
89static inline void gp_hline_raw_2BPP_UB(gp_pixmap *pixmap, int x0, int x1, int y,
90 gp_pixel pixel)
91{
92 /* draw always from left to right, swap coords if necessary */
93 if (x0 > x1)
94 GP_SWAP(x0, x1);
95
96 /* return immediately if the line is completely out of surface */
97 if (y < 0 || y >= (int) pixmap->h || x1 < 0 || x0 >= (int) pixmap->w)
98 return;
99
100 /* clip the line against surface boundaries */
101 x0 = GP_MAX(x0, 0);
102 x1 = GP_MIN(x1, (gp_coord) pixmap->w - 1);
103
104 size_t length = 1 + x1 - x0;
105 void *start = GP_PIXEL_ADDR_2BPP_UB(pixmap, x0, y);
106
107 unsigned int offset = GP_PIXEL_ADDR_OFFSET_2BPP_UB(pixmap, x0);
108 gp_write_pixels_2BPP_UB(start, offset, length, pixel);
109}
110
111static inline void gp_hline_raw_4BPP_DB(gp_pixmap *pixmap, int x0, int x1, int y,
112 gp_pixel pixel)
113{
114 /* draw always from left to right, swap coords if necessary */
115 if (x0 > x1)
116 GP_SWAP(x0, x1);
117
118 /* return immediately if the line is completely out of surface */
119 if (y < 0 || y >= (int) pixmap->h || x1 < 0 || x0 >= (int) pixmap->w)
120 return;
121
122 /* clip the line against surface boundaries */
123 x0 = GP_MAX(x0, 0);
124 x1 = GP_MIN(x1, (gp_coord) pixmap->w - 1);
125
126 size_t length = 1 + x1 - x0;
127 void *start = GP_PIXEL_ADDR_4BPP_DB(pixmap, x0, y);
128
129 unsigned int offset = GP_PIXEL_ADDR_OFFSET_4BPP_DB(pixmap, x0);
130 gp_write_pixels_4BPP_DB(start, offset, length, pixel);
131}
132
133static inline void gp_hline_raw_4BPP_UB(gp_pixmap *pixmap, int x0, int x1, int y,
134 gp_pixel pixel)
135{
136 /* draw always from left to right, swap coords if necessary */
137 if (x0 > x1)
138 GP_SWAP(x0, x1);
139
140 /* return immediately if the line is completely out of surface */
141 if (y < 0 || y >= (int) pixmap->h || x1 < 0 || x0 >= (int) pixmap->w)
142 return;
143
144 /* clip the line against surface boundaries */
145 x0 = GP_MAX(x0, 0);
146 x1 = GP_MIN(x1, (gp_coord) pixmap->w - 1);
147
148 size_t length = 1 + x1 - x0;
149 void *start = GP_PIXEL_ADDR_4BPP_UB(pixmap, x0, y);
150
151 unsigned int offset = GP_PIXEL_ADDR_OFFSET_4BPP_UB(pixmap, x0);
152 gp_write_pixels_4BPP_UB(start, offset, length, pixel);
153}
154
155static inline void gp_hline_raw_8BPP(gp_pixmap *pixmap, int x0, int x1, int y,
156 gp_pixel pixel)
157{
158 /* draw always from left to right, swap coords if necessary */
159 if (x0 > x1)
160 GP_SWAP(x0, x1);
161
162 /* return immediately if the line is completely out of surface */
163 if (y < 0 || y >= (int) pixmap->h || x1 < 0 || x0 >= (int) pixmap->w)
164 return;
165
166 /* clip the line against surface boundaries */
167 x0 = GP_MAX(x0, 0);
168 x1 = GP_MIN(x1, (gp_coord) pixmap->w - 1);
169
170 size_t length = 1 + x1 - x0;
171 void *start = GP_PIXEL_ADDR_8BPP(pixmap, x0, y);
172
173 gp_write_pixels_8BPP(start, length, pixel);
174}
175
176static inline void gp_hline_raw_16BPP(gp_pixmap *pixmap, int x0, int x1, int y,
177 gp_pixel pixel)
178{
179 /* draw always from left to right, swap coords if necessary */
180 if (x0 > x1)
181 GP_SWAP(x0, x1);
182
183 /* return immediately if the line is completely out of surface */
184 if (y < 0 || y >= (int) pixmap->h || x1 < 0 || x0 >= (int) pixmap->w)
185 return;
186
187 /* clip the line against surface boundaries */
188 x0 = GP_MAX(x0, 0);
189 x1 = GP_MIN(x1, (gp_coord) pixmap->w - 1);
190
191 size_t length = 1 + x1 - x0;
192 void *start = GP_PIXEL_ADDR_16BPP(pixmap, x0, y);
193
194 gp_write_pixels_16BPP(start, length, pixel);
195}
196
197static inline void gp_hline_raw_16BPP_BE(gp_pixmap *pixmap, int x0, int x1, int y,
198 gp_pixel pixel)
199{
200 /* draw always from left to right, swap coords if necessary */
201 if (x0 > x1)
202 GP_SWAP(x0, x1);
203
204 /* return immediately if the line is completely out of surface */
205 if (y < 0 || y >= (int) pixmap->h || x1 < 0 || x0 >= (int) pixmap->w)
206 return;
207
208 /* clip the line against surface boundaries */
209 x0 = GP_MAX(x0, 0);
210 x1 = GP_MIN(x1, (gp_coord) pixmap->w - 1);
211
212 size_t length = 1 + x1 - x0;
213 void *start = GP_PIXEL_ADDR_16BPP_BE(pixmap, x0, y);
214
215 gp_write_pixels_16BPP_BE(start, length, pixel);
216}
217
218static inline void gp_hline_raw_24BPP(gp_pixmap *pixmap, int x0, int x1, int y,
219 gp_pixel pixel)
220{
221 /* draw always from left to right, swap coords if necessary */
222 if (x0 > x1)
223 GP_SWAP(x0, x1);
224
225 /* return immediately if the line is completely out of surface */
226 if (y < 0 || y >= (int) pixmap->h || x1 < 0 || x0 >= (int) pixmap->w)
227 return;
228
229 /* clip the line against surface boundaries */
230 x0 = GP_MAX(x0, 0);
231 x1 = GP_MIN(x1, (gp_coord) pixmap->w - 1);
232
233 size_t length = 1 + x1 - x0;
234 void *start = GP_PIXEL_ADDR_24BPP(pixmap, x0, y);
235
236 gp_write_pixels_24BPP(start, length, pixel);
237}
238
239static inline void gp_hline_raw_32BPP(gp_pixmap *pixmap, int x0, int x1, int y,
240 gp_pixel pixel)
241{
242 /* draw always from left to right, swap coords if necessary */
243 if (x0 > x1)
244 GP_SWAP(x0, x1);
245
246 /* return immediately if the line is completely out of surface */
247 if (y < 0 || y >= (int) pixmap->h || x1 < 0 || x0 >= (int) pixmap->w)
248 return;
249
250 /* clip the line against surface boundaries */
251 x0 = GP_MAX(x0, 0);
252 x1 = GP_MIN(x1, (gp_coord) pixmap->w - 1);
253
254 size_t length = 1 + x1 - x0;
255 void *start = GP_PIXEL_ADDR_32BPP(pixmap, x0, y);
256
257 gp_write_pixels_32BPP(start, length, pixel);
258}
259
260static inline void gp_hline_raw_18BPP_DB(gp_pixmap *pixmap, int x0, int x1, int y,
261 gp_pixel pixel)
262{
263 /* draw always from left to right, swap coords if necessary */
264 if (x0 > x1)
265 GP_SWAP(x0, x1);
266
267 /* return immediately if the line is completely out of surface */
268 if (y < 0 || y >= (int) pixmap->h || x1 < 0 || x0 >= (int) pixmap->w)
269 return;
270
271 /* clip the line against surface boundaries */
272 x0 = GP_MAX(x0, 0);
273 x1 = GP_MIN(x1, (gp_coord) pixmap->w - 1);
274
275 for (;x0 <= x1; x0++)
276 gp_putpixel_raw_18BPP_DB(pixmap, x0, y, pixel);
277}
278
279#endif /* GFX_GP_HLINE_GEN_H__ */
#define GP_SWAP(a, b)
Swaps a and b.
Definition gp_common.h:148
#define GP_MAX(a, b)
Returns a maximum of the two numbers.
Definition gp_common.h:59
#define GP_MIN(a, b)
Returns a minimum of the two numbers.
Definition gp_common.h:31
uint32_t gp_pixel
Pixel integer value.
Definition gp_types.h:33
int gp_coord
Integer type for coordinates i.e. x, y, ...
Definition gp_types.h:19
Generated macros and function to access pixels.
static void gp_putpixel_raw_18BPP_DB(gp_pixmap *c, gp_coord x, gp_coord y, gp_pixel p)
gp_putpixel for 18BPP_DB
#define GP_PIXEL_ADDR_OFFSET_4BPP_DB(pixmap, x)
A macro to get pixel offset in pixels.
#define GP_PIXEL_ADDR_OFFSET_2BPP_DB(pixmap, x)
A macro to get pixel offset in pixels.
#define GP_PIXEL_ADDR_OFFSET_4BPP_UB(pixmap, x)
A macro to get pixel offset in pixels.
#define GP_PIXEL_ADDR_OFFSET_1BPP_DB(pixmap, x)
A macro to get pixel offset in pixels.
#define GP_PIXEL_ADDR_1BPP_UB(pixmap, x, y)
A macro to get address of a starting byte for a pixel in a 1BPP_UB pixmap.
#define GP_PIXEL_ADDR_2BPP_UB(pixmap, x, y)
A macro to get address of a starting byte for a pixel in a 2BPP_UB pixmap.
#define GP_PIXEL_ADDR_OFFSET_1BPP_UB(pixmap, x)
A macro to get pixel offset in pixels.
#define GP_PIXEL_ADDR_OFFSET_2BPP_UB(pixmap, x)
A macro to get pixel offset in pixels.
#define GP_PIXEL_ADDR_4BPP_DB(pixmap, x, y)
A macro to get address of a starting byte for a pixel in a 4BPP_DB pixmap.
#define GP_PIXEL_ADDR_24BPP(pixmap, x, y)
A macro to get address of a starting byte for a pixel in a 24BPP pixmap.
#define GP_PIXEL_ADDR_4BPP_UB(pixmap, x, y)
A macro to get address of a starting byte for a pixel in a 4BPP_UB pixmap.
#define GP_PIXEL_ADDR_1BPP_DB(pixmap, x, y)
A macro to get address of a starting byte for a pixel in a 1BPP_DB pixmap.
#define GP_PIXEL_ADDR_8BPP(pixmap, x, y)
A macro to get address of a starting byte for a pixel in a 8BPP pixmap.
#define GP_PIXEL_ADDR_32BPP(pixmap, x, y)
A macro to get address of a starting byte for a pixel in a 32BPP pixmap.
#define GP_PIXEL_ADDR_2BPP_DB(pixmap, x, y)
A macro to get address of a starting byte for a pixel in a 2BPP_DB pixmap.
#define GP_PIXEL_ADDR_16BPP_BE(pixmap, x, y)
A macro to get address of a starting byte for a pixel in a 16BPP_BE pixmap.
#define GP_PIXEL_ADDR_16BPP(pixmap, x, y)
A macro to get address of a starting byte for a pixel in a 16BPP pixmap.
Optimized functions to write a row of pixels.
void gp_write_pixels_8BPP(void *start, size_t cnt, unsigned int val)
Optimized function to draw a row of 8BPP pixels.
void gp_write_pixels_4BPP_UB(void *start, uint8_t off, size_t cnt, unsigned int val)
Optimized function to draw a row of 4BPP_UB pixels.
void gp_write_pixels_4BPP_DB(void *start, uint8_t off, size_t cnt, unsigned int val)
Optimized function to draw a row of 4BPP_DB pixels.
void gp_write_pixels_2BPP_DB(void *start, uint8_t off, size_t cnt, unsigned int val)
Optimized function to draw a row of 2BPP_DB pixels.
void gp_write_pixels_16BPP_BE(void *start, size_t cnt, unsigned int val)
Optimized function to draw a row of 16BPP_BE pixels.
void gp_write_pixels_32BPP(void *start, size_t cnt, unsigned int val)
Optimized function to draw a row of 32BPP pixels.
void gp_write_pixels_1BPP_DB(void *start, uint8_t off, uint8_t y_off, size_t cnt, unsigned int val)
Optimized function to draw a row of 1BPP_DB pixels.
void gp_write_pixels_16BPP(void *start, size_t cnt, unsigned int val)
Optimized function to draw a row of 16BPP pixels.
void gp_write_pixels_24BPP(void *start, size_t cnt, unsigned int val)
Optimized function to draw a row of 24BPP pixels.
void gp_write_pixels_1BPP_UB(void *start, uint8_t off, uint8_t y_off, size_t cnt, unsigned int val)
Optimized function to draw a row of 1BPP_UB pixels.
void gp_write_pixels_2BPP_UB(void *start, uint8_t off, size_t cnt, unsigned int val)
Optimized function to draw a row of 2BPP_UB pixels.
A pixmap buffer.
Definition gp_pixmap.h:33
uint32_t h
Pixmap height in pixels.
Definition gp_pixmap.h:46
uint32_t w
Pixmap width in pixels.
Definition gp_pixmap.h:44