Go to the documentation of this file.
21 #include "../../SDL_internal.h"
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 = 0xFF; \
56 sr = DRAW_MUL(inva, sr) + r; \
57 sg = DRAW_MUL(inva, sg) + g; \
58 sb = DRAW_MUL(inva, sb) + b; \
59 sa = DRAW_MUL(inva, sa) + a; \
63 #define DRAW_SETPIXEL_ADD(getpixel, setpixel) \
65 unsigned sr, sg, sb, sa; (void) sa; \
67 sr += r; if (sr > 0xff) sr = 0xff; \
68 sg += g; if (sg > 0xff) sg = 0xff; \
69 sb += b; if (sb > 0xff) sb = 0xff; \
73 #define DRAW_SETPIXEL_MOD(getpixel, setpixel) \
75 unsigned sr, sg, sb, sa; (void) sa; \
77 sr = DRAW_MUL(sr, r); \
78 sg = DRAW_MUL(sg, g); \
79 sb = DRAW_MUL(sb, b); \
83 #define DRAW_SETPIXEL_MUL(getpixel, setpixel) \
85 unsigned sr, sg, sb, sa; sa = 0xFF; \
87 sr = DRAW_MUL(sr, r) + DRAW_MUL(inva, sr); if (sr > 0xff) sr = 0xff; \
88 sg = DRAW_MUL(sg, g) + DRAW_MUL(inva, sg); if (sg > 0xff) sg = 0xff; \
89 sb = DRAW_MUL(sb, b) + DRAW_MUL(inva, sb); if (sb > 0xff) sb = 0xff; \
90 sa = DRAW_MUL(sa, a) + DRAW_MUL(inva, sa); if (sa > 0xff) sa = 0xff; \
94 #define DRAW_SETPIXELXY(x, y, type, bpp, op) \
96 type *pixel = (type *)((Uint8 *)dst->pixels + (y) * dst->pitch \
105 #define DRAW_SETPIXEL_RGB555 \
106 DRAW_SETPIXEL(RGB555_FROM_RGB(*pixel, sr, sg, sb))
108 #define DRAW_SETPIXEL_BLEND_RGB555 \
109 DRAW_SETPIXEL_BLEND(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
110 RGB555_FROM_RGB(*pixel, sr, sg, sb))
112 #define DRAW_SETPIXEL_ADD_RGB555 \
113 DRAW_SETPIXEL_ADD(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
114 RGB555_FROM_RGB(*pixel, sr, sg, sb))
116 #define DRAW_SETPIXEL_MOD_RGB555 \
117 DRAW_SETPIXEL_MOD(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
118 RGB555_FROM_RGB(*pixel, sr, sg, sb))
120 #define DRAW_SETPIXEL_MUL_RGB555 \
121 DRAW_SETPIXEL_MUL(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
122 RGB555_FROM_RGB(*pixel, sr, sg, sb))
124 #define DRAW_SETPIXELXY_RGB555(x, y) \
125 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB555)
127 #define DRAW_SETPIXELXY_BLEND_RGB555(x, y) \
128 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB555)
130 #define DRAW_SETPIXELXY_ADD_RGB555(x, y) \
131 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB555)
133 #define DRAW_SETPIXELXY_MOD_RGB555(x, y) \
134 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MOD_RGB555)
136 #define DRAW_SETPIXELXY_MUL_RGB555(x, y) \
137 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MUL_RGB555)
143 #define DRAW_SETPIXEL_RGB565 \
144 DRAW_SETPIXEL(RGB565_FROM_RGB(*pixel, sr, sg, sb))
146 #define DRAW_SETPIXEL_BLEND_RGB565 \
147 DRAW_SETPIXEL_BLEND(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
148 RGB565_FROM_RGB(*pixel, sr, sg, sb))
150 #define DRAW_SETPIXEL_ADD_RGB565 \
151 DRAW_SETPIXEL_ADD(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
152 RGB565_FROM_RGB(*pixel, sr, sg, sb))
154 #define DRAW_SETPIXEL_MOD_RGB565 \
155 DRAW_SETPIXEL_MOD(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
156 RGB565_FROM_RGB(*pixel, sr, sg, sb))
158 #define DRAW_SETPIXEL_MUL_RGB565 \
159 DRAW_SETPIXEL_MUL(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
160 RGB565_FROM_RGB(*pixel, sr, sg, sb))
162 #define DRAW_SETPIXELXY_RGB565(x, y) \
163 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB565)
165 #define DRAW_SETPIXELXY_BLEND_RGB565(x, y) \
166 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB565)
168 #define DRAW_SETPIXELXY_ADD_RGB565(x, y) \
169 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB565)
171 #define DRAW_SETPIXELXY_MOD_RGB565(x, y) \
172 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MOD_RGB565)
174 #define DRAW_SETPIXELXY_MUL_RGB565(x, y) \
175 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MUL_RGB565)
181 #define DRAW_SETPIXEL_RGB888 \
182 DRAW_SETPIXEL(RGB888_FROM_RGB(*pixel, sr, sg, sb))
184 #define DRAW_SETPIXEL_BLEND_RGB888 \
185 DRAW_SETPIXEL_BLEND(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
186 RGB888_FROM_RGB(*pixel, sr, sg, sb))
188 #define DRAW_SETPIXEL_ADD_RGB888 \
189 DRAW_SETPIXEL_ADD(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
190 RGB888_FROM_RGB(*pixel, sr, sg, sb))
192 #define DRAW_SETPIXEL_MOD_RGB888 \
193 DRAW_SETPIXEL_MOD(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
194 RGB888_FROM_RGB(*pixel, sr, sg, sb))
196 #define DRAW_SETPIXEL_MUL_RGB888 \
197 DRAW_SETPIXEL_MUL(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
198 RGB888_FROM_RGB(*pixel, sr, sg, sb))
200 #define DRAW_SETPIXELXY_RGB888(x, y) \
201 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGB888)
203 #define DRAW_SETPIXELXY_BLEND_RGB888(x, y) \
204 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGB888)
206 #define DRAW_SETPIXELXY_ADD_RGB888(x, y) \
207 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGB888)
209 #define DRAW_SETPIXELXY_MOD_RGB888(x, y) \
210 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_RGB888)
212 #define DRAW_SETPIXELXY_MUL_RGB888(x, y) \
213 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MUL_RGB888)
219 #define DRAW_SETPIXEL_ARGB8888 \
220 DRAW_SETPIXEL(ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
222 #define DRAW_SETPIXEL_BLEND_ARGB8888 \
223 DRAW_SETPIXEL_BLEND(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
224 ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
226 #define DRAW_SETPIXEL_ADD_ARGB8888 \
227 DRAW_SETPIXEL_ADD(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
228 ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
230 #define DRAW_SETPIXEL_MOD_ARGB8888 \
231 DRAW_SETPIXEL_MOD(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
232 ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
234 #define DRAW_SETPIXEL_MUL_ARGB8888 \
235 DRAW_SETPIXEL_MUL(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
236 ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
238 #define DRAW_SETPIXELXY_ARGB8888(x, y) \
239 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ARGB8888)
241 #define DRAW_SETPIXELXY_BLEND_ARGB8888(x, y) \
242 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_ARGB8888)
244 #define DRAW_SETPIXELXY_ADD_ARGB8888(x, y) \
245 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_ARGB8888)
247 #define DRAW_SETPIXELXY_MOD_ARGB8888(x, y) \
248 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_ARGB8888)
250 #define DRAW_SETPIXELXY_MUL_ARGB8888(x, y) \
251 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MUL_ARGB8888)
257 #define DRAW_SETPIXEL_RGB \
258 DRAW_SETPIXEL(PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
260 #define DRAW_SETPIXEL_BLEND_RGB \
261 DRAW_SETPIXEL_BLEND(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \
262 PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
264 #define DRAW_SETPIXEL_ADD_RGB \
265 DRAW_SETPIXEL_ADD(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \
266 PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
268 #define DRAW_SETPIXEL_MOD_RGB \
269 DRAW_SETPIXEL_MOD(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \
270 PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
272 #define DRAW_SETPIXEL_MUL_RGB \
273 DRAW_SETPIXEL_MUL(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \
274 PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
276 #define DRAW_SETPIXELXY2_RGB(x, y) \
277 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB)
279 #define DRAW_SETPIXELXY4_RGB(x, y) \
280 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGB)
282 #define DRAW_SETPIXELXY2_BLEND_RGB(x, y) \
283 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB)
285 #define DRAW_SETPIXELXY4_BLEND_RGB(x, y) \
286 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGB)
288 #define DRAW_SETPIXELXY2_ADD_RGB(x, y) \
289 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB)
291 #define DRAW_SETPIXELXY4_ADD_RGB(x, y) \
292 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGB)
294 #define DRAW_SETPIXELXY2_MOD_RGB(x, y) \
295 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MOD_RGB)
297 #define DRAW_SETPIXELXY4_MOD_RGB(x, y) \
298 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_RGB)
300 #define DRAW_SETPIXELXY2_MUL_RGB(x, y) \
301 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MUL_RGB)
303 #define DRAW_SETPIXELXY4_MUL_RGB(x, y) \
304 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MUL_RGB)
311 #define DRAW_SETPIXEL_RGBA \
312 DRAW_SETPIXEL(PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
314 #define DRAW_SETPIXEL_BLEND_RGBA \
315 DRAW_SETPIXEL_BLEND(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \
316 PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
318 #define DRAW_SETPIXEL_ADD_RGBA \
319 DRAW_SETPIXEL_ADD(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \
320 PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
322 #define DRAW_SETPIXEL_MOD_RGBA \
323 DRAW_SETPIXEL_MOD(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \
324 PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
326 #define DRAW_SETPIXEL_MUL_RGBA \
327 DRAW_SETPIXEL_MUL(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \
328 PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
330 #define DRAW_SETPIXELXY4_RGBA(x, y) \
331 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGBA)
333 #define DRAW_SETPIXELXY4_BLEND_RGBA(x, y) \
334 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGBA)
336 #define DRAW_SETPIXELXY4_ADD_RGBA(x, y) \
337 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGBA)
339 #define DRAW_SETPIXELXY4_MOD_RGBA(x, y) \
340 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_RGBA)
342 #define DRAW_SETPIXELXY4_MUL_RGBA(x, y) \
343 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MUL_RGBA)
349 #define ABS(_x) ((_x) < 0 ? -(_x) : (_x))
352 #define HLINE(type, op, draw_end) \
355 int pitch = (dst->pitch / dst->format->BytesPerPixel); \
358 pixel = (type *)dst->pixels + y1 * pitch + x1; \
359 length = draw_end ? (x2-x1+1) : (x2-x1); \
361 pixel = (type *)dst->pixels + y1 * pitch + x2; \
365 length = draw_end ? (x1-x2+1) : (x1-x2); \
374 #define VLINE(type, op, draw_end) \
377 int pitch = (dst->pitch / dst->format->BytesPerPixel); \
380 pixel = (type *)dst->pixels + y1 * pitch + x1; \
381 length = draw_end ? (y2-y1+1) : (y2-y1); \
383 pixel = (type *)dst->pixels + y2 * pitch + x1; \
387 length = draw_end ? (y1-y2+1) : (y1-y2); \
396 #define DLINE(type, op, draw_end) \
399 int pitch = (dst->pitch / dst->format->BytesPerPixel); \
402 pixel = (type *)dst->pixels + y1 * pitch + x1; \
410 pixel = (type *)dst->pixels + y2 * pitch + x2; \
431 #define BLINE(x1, y1, x2, y2, op, draw_end) \
433 int i, deltax, deltay, numpixels; \
434 int d, dinc1, dinc2; \
435 int x, xinc1, xinc2; \
436 int y, yinc1, yinc2; \
438 deltax = ABS(x2 - x1); \
439 deltay = ABS(y2 - y1); \
441 if (deltax >= deltay) { \
442 numpixels = deltax + 1; \
443 d = (2 * deltay) - deltax; \
444 dinc1 = deltay * 2; \
445 dinc2 = (deltay - deltax) * 2; \
451 numpixels = deltay + 1; \
452 d = (2 * deltax) - deltay; \
453 dinc1 = deltax * 2; \
454 dinc2 = (deltax - deltay) * 2; \
476 for (i = 0; i < numpixels; ++i) { \
491 #define WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
493 Uint16 ErrorAdj, ErrorAcc; \
494 Uint16 ErrorAccTemp, Weighting; \
495 int DeltaX, DeltaY, Temp, XDir; \
496 unsigned r, g, b, a, inva; \
510 Temp = y1; y1 = y2; y2 = Temp; \
511 Temp = x1; x1 = x2; x2 = Temp; \
515 if ((DeltaX = x2 - x1) >= 0) { \
526 if (DeltaY > DeltaX) { \
530 ErrorAdj = ((unsigned long) DeltaX << 16) / (unsigned long) DeltaY; \
533 ErrorAccTemp = ErrorAcc; \
534 ErrorAcc += ErrorAdj; \
535 if (ErrorAcc <= ErrorAccTemp) { \
543 Weighting = ErrorAcc >> 8; \
545 a = DRAW_MUL(_a, (Weighting ^ 255)); \
546 r = DRAW_MUL(_r, a); \
547 g = DRAW_MUL(_g, a); \
548 b = DRAW_MUL(_b, a); \
553 a = DRAW_MUL(_a, Weighting); \
554 r = DRAW_MUL(_r, a); \
555 g = DRAW_MUL(_g, a); \
556 b = DRAW_MUL(_b, a); \
558 blend_op(x1 + XDir, y1); \
565 ErrorAdj = ((unsigned long) DeltaY << 16) / (unsigned long) DeltaX; \
568 ErrorAccTemp = ErrorAcc; \
569 ErrorAcc += ErrorAdj; \
570 if (ErrorAcc <= ErrorAccTemp) { \
578 Weighting = ErrorAcc >> 8; \
580 a = DRAW_MUL(_a, (Weighting ^ 255)); \
581 r = DRAW_MUL(_r, a); \
582 g = DRAW_MUL(_g, a); \
583 b = DRAW_MUL(_b, a); \
588 a = DRAW_MUL(_a, Weighting); \
589 r = DRAW_MUL(_r, a); \
590 g = DRAW_MUL(_g, a); \
591 b = DRAW_MUL(_b, a); \
593 blend_op(x1, y1 + 1); \
600 #define AALINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
601 WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end)
603 #define AALINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
604 BLINE(x1, y1, x2, y2, opaque_op, draw_end)
611 #define FILLRECT(type, op) \
613 int width = rect->w; \
614 int height = rect->h; \
615 int pitch = (dst->pitch / dst->format->BytesPerPixel); \
616 int skip = pitch - width; \
617 type *pixel = (type *)dst->pixels + rect->y * pitch + rect->x; \
619 { int n = (width+3)/4; \
620 switch (width & 3) { \
621 case 0: do { op; pixel++; \
622 case 3: op; pixel++; \
623 case 2: op; pixel++; \
624 case 1: op; pixel++; \
625 } while ( --n > 0 ); \