Go to the documentation of this file.
23 #include "../../video/SDL_blit.h"
29 #define DRAW_MUL(_a, _b) (((unsigned)(_a)*(_b))/255)
31 #define DRAW_FASTSETPIXEL(type) \
34 #define DRAW_FASTSETPIXEL1 DRAW_FASTSETPIXEL(Uint8)
35 #define DRAW_FASTSETPIXEL2 DRAW_FASTSETPIXEL(Uint16)
36 #define DRAW_FASTSETPIXEL4 DRAW_FASTSETPIXEL(Uint32)
38 #define DRAW_FASTSETPIXELXY(x, y, type, bpp, color) \
39 *(type *)((Uint8 *)dst->pixels + (y) * dst->pitch \
40 + (x) * bpp) = (type) color
42 #define DRAW_FASTSETPIXELXY1(x, y) DRAW_FASTSETPIXELXY(x, y, Uint8, 1, color)
43 #define DRAW_FASTSETPIXELXY2(x, y) DRAW_FASTSETPIXELXY(x, y, Uint16, 2, color)
44 #define DRAW_FASTSETPIXELXY4(x, y) DRAW_FASTSETPIXELXY(x, y, Uint32, 4, color)
46 #define DRAW_SETPIXEL(setpixel) \
48 unsigned sr = r, sg = g, sb = b, sa = a; (void) sa; \
52 #define DRAW_SETPIXEL_BLEND(getpixel, setpixel) \
54 unsigned sr, sg, sb, sa; (void) sa; \
56 sr = DRAW_MUL(inva, sr) + r; \
57 sg = DRAW_MUL(inva, sg) + g; \
58 sb = DRAW_MUL(inva, sb) + b; \
62 #define DRAW_SETPIXEL_ADD(getpixel, setpixel) \
64 unsigned sr, sg, sb, sa; (void) sa; \
66 sr += r; if (sr > 0xff) sr = 0xff; \
67 sg += g; if (sg > 0xff) sg = 0xff; \
68 sb += b; if (sb > 0xff) sb = 0xff; \
72 #define DRAW_SETPIXEL_MOD(getpixel, setpixel) \
74 unsigned sr, sg, sb, sa; (void) sa; \
76 sr = DRAW_MUL(sr, r); \
77 sg = DRAW_MUL(sg, g); \
78 sb = DRAW_MUL(sb, b); \
82 #define DRAW_SETPIXELXY(x, y, type, bpp, op) \
84 type *pixel = (type *)((Uint8 *)dst->pixels + (y) * dst->pitch \
93 #define DRAW_SETPIXEL_RGB555 \
94 DRAW_SETPIXEL(RGB555_FROM_RGB(*pixel, sr, sg, sb))
96 #define DRAW_SETPIXEL_BLEND_RGB555 \
97 DRAW_SETPIXEL_BLEND(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
98 RGB555_FROM_RGB(*pixel, sr, sg, sb))
100 #define DRAW_SETPIXEL_ADD_RGB555 \
101 DRAW_SETPIXEL_ADD(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
102 RGB555_FROM_RGB(*pixel, sr, sg, sb))
104 #define DRAW_SETPIXEL_MOD_RGB555 \
105 DRAW_SETPIXEL_MOD(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
106 RGB555_FROM_RGB(*pixel, sr, sg, sb))
108 #define DRAW_SETPIXELXY_RGB555(x, y) \
109 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB555)
111 #define DRAW_SETPIXELXY_BLEND_RGB555(x, y) \
112 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB555)
114 #define DRAW_SETPIXELXY_ADD_RGB555(x, y) \
115 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB555)
117 #define DRAW_SETPIXELXY_MOD_RGB555(x, y) \
118 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MOD_RGB555)
124 #define DRAW_SETPIXEL_RGB565 \
125 DRAW_SETPIXEL(RGB565_FROM_RGB(*pixel, sr, sg, sb))
127 #define DRAW_SETPIXEL_BLEND_RGB565 \
128 DRAW_SETPIXEL_BLEND(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
129 RGB565_FROM_RGB(*pixel, sr, sg, sb))
131 #define DRAW_SETPIXEL_ADD_RGB565 \
132 DRAW_SETPIXEL_ADD(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
133 RGB565_FROM_RGB(*pixel, sr, sg, sb))
135 #define DRAW_SETPIXEL_MOD_RGB565 \
136 DRAW_SETPIXEL_MOD(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
137 RGB565_FROM_RGB(*pixel, sr, sg, sb))
139 #define DRAW_SETPIXELXY_RGB565(x, y) \
140 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB565)
142 #define DRAW_SETPIXELXY_BLEND_RGB565(x, y) \
143 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB565)
145 #define DRAW_SETPIXELXY_ADD_RGB565(x, y) \
146 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB565)
148 #define DRAW_SETPIXELXY_MOD_RGB565(x, y) \
149 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MOD_RGB565)
155 #define DRAW_SETPIXEL_RGB888 \
156 DRAW_SETPIXEL(RGB888_FROM_RGB(*pixel, sr, sg, sb))
158 #define DRAW_SETPIXEL_BLEND_RGB888 \
159 DRAW_SETPIXEL_BLEND(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
160 RGB888_FROM_RGB(*pixel, sr, sg, sb))
162 #define DRAW_SETPIXEL_ADD_RGB888 \
163 DRAW_SETPIXEL_ADD(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
164 RGB888_FROM_RGB(*pixel, sr, sg, sb))
166 #define DRAW_SETPIXEL_MOD_RGB888 \
167 DRAW_SETPIXEL_MOD(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
168 RGB888_FROM_RGB(*pixel, sr, sg, sb))
170 #define DRAW_SETPIXELXY_RGB888(x, y) \
171 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGB888)
173 #define DRAW_SETPIXELXY_BLEND_RGB888(x, y) \
174 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGB888)
176 #define DRAW_SETPIXELXY_ADD_RGB888(x, y) \
177 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGB888)
179 #define DRAW_SETPIXELXY_MOD_RGB888(x, y) \
180 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_RGB888)
186 #define DRAW_SETPIXEL_ARGB8888 \
187 DRAW_SETPIXEL(ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
189 #define DRAW_SETPIXEL_BLEND_ARGB8888 \
190 DRAW_SETPIXEL_BLEND(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
191 ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
193 #define DRAW_SETPIXEL_ADD_ARGB8888 \
194 DRAW_SETPIXEL_ADD(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
195 ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
197 #define DRAW_SETPIXEL_MOD_ARGB8888 \
198 DRAW_SETPIXEL_MOD(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
199 ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
201 #define DRAW_SETPIXELXY_ARGB8888(x, y) \
202 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ARGB8888)
204 #define DRAW_SETPIXELXY_BLEND_ARGB8888(x, y) \
205 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_ARGB8888)
207 #define DRAW_SETPIXELXY_ADD_ARGB8888(x, y) \
208 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_ARGB8888)
210 #define DRAW_SETPIXELXY_MOD_ARGB8888(x, y) \
211 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_ARGB8888)
217 #define DRAW_SETPIXEL_RGB \
218 DRAW_SETPIXEL(PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
220 #define DRAW_SETPIXEL_BLEND_RGB \
221 DRAW_SETPIXEL_BLEND(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \
222 PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
224 #define DRAW_SETPIXEL_ADD_RGB \
225 DRAW_SETPIXEL_ADD(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \
226 PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
228 #define DRAW_SETPIXEL_MOD_RGB \
229 DRAW_SETPIXEL_MOD(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \
230 PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
232 #define DRAW_SETPIXELXY2_RGB(x, y) \
233 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB)
235 #define DRAW_SETPIXELXY4_RGB(x, y) \
236 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGB)
238 #define DRAW_SETPIXELXY2_BLEND_RGB(x, y) \
239 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB)
241 #define DRAW_SETPIXELXY4_BLEND_RGB(x, y) \
242 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGB)
244 #define DRAW_SETPIXELXY2_ADD_RGB(x, y) \
245 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB)
247 #define DRAW_SETPIXELXY4_ADD_RGB(x, y) \
248 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGB)
250 #define DRAW_SETPIXELXY2_MOD_RGB(x, y) \
251 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MOD_RGB)
253 #define DRAW_SETPIXELXY4_MOD_RGB(x, y) \
254 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_RGB)
261 #define DRAW_SETPIXEL_RGBA \
262 DRAW_SETPIXEL(PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
264 #define DRAW_SETPIXEL_BLEND_RGBA \
265 DRAW_SETPIXEL_BLEND(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \
266 PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
268 #define DRAW_SETPIXEL_ADD_RGBA \
269 DRAW_SETPIXEL_ADD(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \
270 PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
272 #define DRAW_SETPIXEL_MOD_RGBA \
273 DRAW_SETPIXEL_MOD(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \
274 PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
276 #define DRAW_SETPIXELXY4_RGBA(x, y) \
277 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGBA)
279 #define DRAW_SETPIXELXY4_BLEND_RGBA(x, y) \
280 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGBA)
282 #define DRAW_SETPIXELXY4_ADD_RGBA(x, y) \
283 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGBA)
285 #define DRAW_SETPIXELXY4_MOD_RGBA(x, y) \
286 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_RGBA)
292 #define ABS(_x) ((_x) < 0 ? -(_x) : (_x))
295 #define HLINE(type, op, draw_end) \
298 int pitch = (dst->pitch / dst->format->BytesPerPixel); \
301 pixel = (type *)dst->pixels + y1 * pitch + x1; \
302 length = draw_end ? (x2-x1+1) : (x2-x1); \
304 pixel = (type *)dst->pixels + y1 * pitch + x2; \
308 length = draw_end ? (x1-x2+1) : (x1-x2); \
317 #define VLINE(type, op, draw_end) \
320 int pitch = (dst->pitch / dst->format->BytesPerPixel); \
323 pixel = (type *)dst->pixels + y1 * pitch + x1; \
324 length = draw_end ? (y2-y1+1) : (y2-y1); \
326 pixel = (type *)dst->pixels + y2 * pitch + x1; \
330 length = draw_end ? (y1-y2+1) : (y1-y2); \
339 #define DLINE(type, op, draw_end) \
342 int pitch = (dst->pitch / dst->format->BytesPerPixel); \
345 pixel = (type *)dst->pixels + y1 * pitch + x1; \
353 pixel = (type *)dst->pixels + y2 * pitch + x2; \
374 #define BLINE(x1, y1, x2, y2, op, draw_end) \
376 int i, deltax, deltay, numpixels; \
377 int d, dinc1, dinc2; \
378 int x, xinc1, xinc2; \
379 int y, yinc1, yinc2; \
381 deltax = ABS(x2 - x1); \
382 deltay = ABS(y2 - y1); \
384 if (deltax >= deltay) { \
385 numpixels = deltax + 1; \
386 d = (2 * deltay) - deltax; \
387 dinc1 = deltay * 2; \
388 dinc2 = (deltay - deltax) * 2; \
394 numpixels = deltay + 1; \
395 d = (2 * deltax) - deltay; \
396 dinc1 = deltax * 2; \
397 dinc2 = (deltax - deltay) * 2; \
419 for (i = 0; i < numpixels; ++i) { \
434 #define WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
436 Uint16 ErrorAdj, ErrorAcc; \
437 Uint16 ErrorAccTemp, Weighting; \
438 int DeltaX, DeltaY, Temp, XDir; \
439 unsigned r, g, b, a, inva; \
453 Temp = y1; y1 = y2; y2 = Temp; \
454 Temp = x1; x1 = x2; x2 = Temp; \
458 if ((DeltaX = x2 - x1) >= 0) { \
469 if (DeltaY > DeltaX) { \
473 ErrorAdj = ((unsigned long) DeltaX << 16) / (unsigned long) DeltaY; \
476 ErrorAccTemp = ErrorAcc; \
477 ErrorAcc += ErrorAdj; \
478 if (ErrorAcc <= ErrorAccTemp) { \
486 Weighting = ErrorAcc >> 8; \
488 a = DRAW_MUL(_a, (Weighting ^ 255)); \
489 r = DRAW_MUL(_r, a); \
490 g = DRAW_MUL(_g, a); \
491 b = DRAW_MUL(_b, a); \
496 a = DRAW_MUL(_a, Weighting); \
497 r = DRAW_MUL(_r, a); \
498 g = DRAW_MUL(_g, a); \
499 b = DRAW_MUL(_b, a); \
501 blend_op(x1 + XDir, y1); \
508 ErrorAdj = ((unsigned long) DeltaY << 16) / (unsigned long) DeltaX; \
511 ErrorAccTemp = ErrorAcc; \
512 ErrorAcc += ErrorAdj; \
513 if (ErrorAcc <= ErrorAccTemp) { \
521 Weighting = ErrorAcc >> 8; \
523 a = DRAW_MUL(_a, (Weighting ^ 255)); \
524 r = DRAW_MUL(_r, a); \
525 g = DRAW_MUL(_g, a); \
526 b = DRAW_MUL(_b, a); \
531 a = DRAW_MUL(_a, Weighting); \
532 r = DRAW_MUL(_r, a); \
533 g = DRAW_MUL(_g, a); \
534 b = DRAW_MUL(_b, a); \
536 blend_op(x1, y1 + 1); \
543 #define AALINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
544 WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end)
546 #define AALINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
547 BLINE(x1, y1, x2, y2, opaque_op, draw_end)
554 #define FILLRECT(type, op) \
556 int width = rect->w; \
557 int height = rect->h; \
558 int pitch = (dst->pitch / dst->format->BytesPerPixel); \
559 int skip = pitch - width; \
560 type *pixel = (type *)dst->pixels + rect->y * pitch + rect->x; \
562 { int n = (width+3)/4; \
563 switch (width & 3) { \
564 case 0: do { op; pixel++; \
565 case 3: op; pixel++; \
566 case 2: op; pixel++; \
567 case 1: op; pixel++; \
568 } while ( --n > 0 ); \