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_SETPIXELXY(x, y, type, bpp, op) \ 85 type *pixel = (type *)((Uint8 *)dst->pixels + (y) * dst->pitch \ 94 #define DRAW_SETPIXEL_RGB555 \ 95 DRAW_SETPIXEL(RGB555_FROM_RGB(*pixel, sr, sg, sb)) 97 #define DRAW_SETPIXEL_BLEND_RGB555 \ 98 DRAW_SETPIXEL_BLEND(RGB_FROM_RGB555(*pixel, sr, sg, sb), \ 99 RGB555_FROM_RGB(*pixel, sr, sg, sb)) 101 #define DRAW_SETPIXEL_ADD_RGB555 \ 102 DRAW_SETPIXEL_ADD(RGB_FROM_RGB555(*pixel, sr, sg, sb), \ 103 RGB555_FROM_RGB(*pixel, sr, sg, sb)) 105 #define DRAW_SETPIXEL_MOD_RGB555 \ 106 DRAW_SETPIXEL_MOD(RGB_FROM_RGB555(*pixel, sr, sg, sb), \ 107 RGB555_FROM_RGB(*pixel, sr, sg, sb)) 109 #define DRAW_SETPIXELXY_RGB555(x, y) \ 110 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB555) 112 #define DRAW_SETPIXELXY_BLEND_RGB555(x, y) \ 113 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB555) 115 #define DRAW_SETPIXELXY_ADD_RGB555(x, y) \ 116 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB555) 118 #define DRAW_SETPIXELXY_MOD_RGB555(x, y) \ 119 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MOD_RGB555) 125 #define DRAW_SETPIXEL_RGB565 \ 126 DRAW_SETPIXEL(RGB565_FROM_RGB(*pixel, sr, sg, sb)) 128 #define DRAW_SETPIXEL_BLEND_RGB565 \ 129 DRAW_SETPIXEL_BLEND(RGB_FROM_RGB565(*pixel, sr, sg, sb), \ 130 RGB565_FROM_RGB(*pixel, sr, sg, sb)) 132 #define DRAW_SETPIXEL_ADD_RGB565 \ 133 DRAW_SETPIXEL_ADD(RGB_FROM_RGB565(*pixel, sr, sg, sb), \ 134 RGB565_FROM_RGB(*pixel, sr, sg, sb)) 136 #define DRAW_SETPIXEL_MOD_RGB565 \ 137 DRAW_SETPIXEL_MOD(RGB_FROM_RGB565(*pixel, sr, sg, sb), \ 138 RGB565_FROM_RGB(*pixel, sr, sg, sb)) 140 #define DRAW_SETPIXELXY_RGB565(x, y) \ 141 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB565) 143 #define DRAW_SETPIXELXY_BLEND_RGB565(x, y) \ 144 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB565) 146 #define DRAW_SETPIXELXY_ADD_RGB565(x, y) \ 147 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB565) 149 #define DRAW_SETPIXELXY_MOD_RGB565(x, y) \ 150 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MOD_RGB565) 156 #define DRAW_SETPIXEL_RGB888 \ 157 DRAW_SETPIXEL(RGB888_FROM_RGB(*pixel, sr, sg, sb)) 159 #define DRAW_SETPIXEL_BLEND_RGB888 \ 160 DRAW_SETPIXEL_BLEND(RGB_FROM_RGB888(*pixel, sr, sg, sb), \ 161 RGB888_FROM_RGB(*pixel, sr, sg, sb)) 163 #define DRAW_SETPIXEL_ADD_RGB888 \ 164 DRAW_SETPIXEL_ADD(RGB_FROM_RGB888(*pixel, sr, sg, sb), \ 165 RGB888_FROM_RGB(*pixel, sr, sg, sb)) 167 #define DRAW_SETPIXEL_MOD_RGB888 \ 168 DRAW_SETPIXEL_MOD(RGB_FROM_RGB888(*pixel, sr, sg, sb), \ 169 RGB888_FROM_RGB(*pixel, sr, sg, sb)) 171 #define DRAW_SETPIXELXY_RGB888(x, y) \ 172 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGB888) 174 #define DRAW_SETPIXELXY_BLEND_RGB888(x, y) \ 175 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGB888) 177 #define DRAW_SETPIXELXY_ADD_RGB888(x, y) \ 178 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGB888) 180 #define DRAW_SETPIXELXY_MOD_RGB888(x, y) \ 181 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_RGB888) 187 #define DRAW_SETPIXEL_ARGB8888 \ 188 DRAW_SETPIXEL(ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa)) 190 #define DRAW_SETPIXEL_BLEND_ARGB8888 \ 191 DRAW_SETPIXEL_BLEND(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \ 192 ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa)) 194 #define DRAW_SETPIXEL_ADD_ARGB8888 \ 195 DRAW_SETPIXEL_ADD(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \ 196 ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa)) 198 #define DRAW_SETPIXEL_MOD_ARGB8888 \ 199 DRAW_SETPIXEL_MOD(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \ 200 ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa)) 202 #define DRAW_SETPIXELXY_ARGB8888(x, y) \ 203 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ARGB8888) 205 #define DRAW_SETPIXELXY_BLEND_ARGB8888(x, y) \ 206 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_ARGB8888) 208 #define DRAW_SETPIXELXY_ADD_ARGB8888(x, y) \ 209 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_ARGB8888) 211 #define DRAW_SETPIXELXY_MOD_ARGB8888(x, y) \ 212 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_ARGB8888) 218 #define DRAW_SETPIXEL_RGB \ 219 DRAW_SETPIXEL(PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb)) 221 #define DRAW_SETPIXEL_BLEND_RGB \ 222 DRAW_SETPIXEL_BLEND(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \ 223 PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb)) 225 #define DRAW_SETPIXEL_ADD_RGB \ 226 DRAW_SETPIXEL_ADD(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \ 227 PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb)) 229 #define DRAW_SETPIXEL_MOD_RGB \ 230 DRAW_SETPIXEL_MOD(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \ 231 PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb)) 233 #define DRAW_SETPIXELXY2_RGB(x, y) \ 234 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB) 236 #define DRAW_SETPIXELXY4_RGB(x, y) \ 237 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGB) 239 #define DRAW_SETPIXELXY2_BLEND_RGB(x, y) \ 240 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB) 242 #define DRAW_SETPIXELXY4_BLEND_RGB(x, y) \ 243 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGB) 245 #define DRAW_SETPIXELXY2_ADD_RGB(x, y) \ 246 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB) 248 #define DRAW_SETPIXELXY4_ADD_RGB(x, y) \ 249 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGB) 251 #define DRAW_SETPIXELXY2_MOD_RGB(x, y) \ 252 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MOD_RGB) 254 #define DRAW_SETPIXELXY4_MOD_RGB(x, y) \ 255 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_RGB) 262 #define DRAW_SETPIXEL_RGBA \ 263 DRAW_SETPIXEL(PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa)) 265 #define DRAW_SETPIXEL_BLEND_RGBA \ 266 DRAW_SETPIXEL_BLEND(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \ 267 PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa)) 269 #define DRAW_SETPIXEL_ADD_RGBA \ 270 DRAW_SETPIXEL_ADD(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \ 271 PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa)) 273 #define DRAW_SETPIXEL_MOD_RGBA \ 274 DRAW_SETPIXEL_MOD(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \ 275 PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa)) 277 #define DRAW_SETPIXELXY4_RGBA(x, y) \ 278 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGBA) 280 #define DRAW_SETPIXELXY4_BLEND_RGBA(x, y) \ 281 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGBA) 283 #define DRAW_SETPIXELXY4_ADD_RGBA(x, y) \ 284 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGBA) 286 #define DRAW_SETPIXELXY4_MOD_RGBA(x, y) \ 287 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_RGBA) 293 #define ABS(_x) ((_x) < 0 ? -(_x) : (_x)) 296 #define HLINE(type, op, draw_end) \ 299 int pitch = (dst->pitch / dst->format->BytesPerPixel); \ 302 pixel = (type *)dst->pixels + y1 * pitch + x1; \ 303 length = draw_end ? (x2-x1+1) : (x2-x1); \ 305 pixel = (type *)dst->pixels + y1 * pitch + x2; \ 309 length = draw_end ? (x1-x2+1) : (x1-x2); \ 318 #define VLINE(type, op, draw_end) \ 321 int pitch = (dst->pitch / dst->format->BytesPerPixel); \ 324 pixel = (type *)dst->pixels + y1 * pitch + x1; \ 325 length = draw_end ? (y2-y1+1) : (y2-y1); \ 327 pixel = (type *)dst->pixels + y2 * pitch + x1; \ 331 length = draw_end ? (y1-y2+1) : (y1-y2); \ 340 #define DLINE(type, op, draw_end) \ 343 int pitch = (dst->pitch / dst->format->BytesPerPixel); \ 346 pixel = (type *)dst->pixels + y1 * pitch + x1; \ 354 pixel = (type *)dst->pixels + y2 * pitch + x2; \ 375 #define BLINE(x1, y1, x2, y2, op, draw_end) \ 377 int i, deltax, deltay, numpixels; \ 378 int d, dinc1, dinc2; \ 379 int x, xinc1, xinc2; \ 380 int y, yinc1, yinc2; \ 382 deltax = ABS(x2 - x1); \ 383 deltay = ABS(y2 - y1); \ 385 if (deltax >= deltay) { \ 386 numpixels = deltax + 1; \ 387 d = (2 * deltay) - deltax; \ 388 dinc1 = deltay * 2; \ 389 dinc2 = (deltay - deltax) * 2; \ 395 numpixels = deltay + 1; \ 396 d = (2 * deltax) - deltay; \ 397 dinc1 = deltax * 2; \ 398 dinc2 = (deltax - deltay) * 2; \ 420 for (i = 0; i < numpixels; ++i) { \ 435 #define WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \ 437 Uint16 ErrorAdj, ErrorAcc; \ 438 Uint16 ErrorAccTemp, Weighting; \ 439 int DeltaX, DeltaY, Temp, XDir; \ 440 unsigned r, g, b, a, inva; \ 454 Temp = y1; y1 = y2; y2 = Temp; \ 455 Temp = x1; x1 = x2; x2 = Temp; \ 459 if ((DeltaX = x2 - x1) >= 0) { \ 470 if (DeltaY > DeltaX) { \ 474 ErrorAdj = ((unsigned long) DeltaX << 16) / (unsigned long) DeltaY; \ 477 ErrorAccTemp = ErrorAcc; \ 478 ErrorAcc += ErrorAdj; \ 479 if (ErrorAcc <= ErrorAccTemp) { \ 487 Weighting = ErrorAcc >> 8; \ 489 a = DRAW_MUL(_a, (Weighting ^ 255)); \ 490 r = DRAW_MUL(_r, a); \ 491 g = DRAW_MUL(_g, a); \ 492 b = DRAW_MUL(_b, a); \ 497 a = DRAW_MUL(_a, Weighting); \ 498 r = DRAW_MUL(_r, a); \ 499 g = DRAW_MUL(_g, a); \ 500 b = DRAW_MUL(_b, a); \ 502 blend_op(x1 + XDir, y1); \ 509 ErrorAdj = ((unsigned long) DeltaY << 16) / (unsigned long) DeltaX; \ 512 ErrorAccTemp = ErrorAcc; \ 513 ErrorAcc += ErrorAdj; \ 514 if (ErrorAcc <= ErrorAccTemp) { \ 522 Weighting = ErrorAcc >> 8; \ 524 a = DRAW_MUL(_a, (Weighting ^ 255)); \ 525 r = DRAW_MUL(_r, a); \ 526 g = DRAW_MUL(_g, a); \ 527 b = DRAW_MUL(_b, a); \ 532 a = DRAW_MUL(_a, Weighting); \ 533 r = DRAW_MUL(_r, a); \ 534 g = DRAW_MUL(_g, a); \ 535 b = DRAW_MUL(_b, a); \ 537 blend_op(x1, y1 + 1); \ 544 #define AALINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \ 545 WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) 547 #define AALINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \ 548 BLINE(x1, y1, x2, y2, opaque_op, draw_end) 555 #define FILLRECT(type, op) \ 557 int width = rect->w; \ 558 int height = rect->h; \ 559 int pitch = (dst->pitch / dst->format->BytesPerPixel); \ 560 int skip = pitch - width; \ 561 type *pixel = (type *)dst->pixels + rect->y * pitch + rect->x; \ 563 { int n = (width+3)/4; \ 564 switch (width & 3) { \ 565 case 0: do { op; pixel++; \ 566 case 3: op; pixel++; \ 567 case 2: op; pixel++; \ 568 case 1: op; pixel++; \ 569 } while ( --n > 0 ); \