Atlas - SDL_blit_0.c
Home / ext / SDL / src / video Lines: 1 | Size: 32668 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2025 Sam Lantinga <[email protected]> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21#include "SDL_internal.h" 22 23#ifdef SDL_HAVE_BLIT_0 24 25#include "SDL_surface_c.h" 26 27// Functions to blit from bitmaps to other surfaces 28 29SDL_FORCE_INLINE void BlitBto1(SDL_BlitInfo *info, const Uint32 srcbpp) 30{ 31 const Uint32 mask = (1 << srcbpp) - 1; 32 const Uint32 align = (8 / srcbpp) - 1; 33 34 int c; 35 int width, height; 36 Uint8 *src, *map, *dst; 37 int srcskip, dstskip; 38 39 // Set up some basic variables 40 width = info->dst_w; 41 height = info->dst_h; 42 src = info->src; 43 srcskip = info->src_skip; 44 dst = info->dst; 45 dstskip = info->dst_skip; 46 map = info->table; 47 48 width += info->leading_skip; 49 50 if (srcbpp == 4) 51 srcskip += width - (width + 1) / 2; 52 else if (srcbpp == 2) 53 srcskip += width - (width + 3) / 4; 54 else if (srcbpp == 1) 55 srcskip += width - (width + 7) / 8; 56 57 if (map) { 58 if (SDL_PIXELORDER(info->src_fmt->format) == SDL_BITMAPORDER_4321) { 59 while (height--) { 60 Uint8 byte = 0, bit; 61 for (c = 0; c < info->leading_skip; ++c) { 62 if (!(c & align)) { 63 byte = *src++; 64 } 65 byte >>= srcbpp; 66 } 67 for (; c < width; ++c) { 68 if (!(c & align)) { 69 byte = *src++; 70 } 71 bit = (byte & mask); 72 if (1) { 73 *dst = map[bit]; 74 } 75 dst++; 76 byte >>= srcbpp; 77 } 78 src += srcskip; 79 dst += dstskip; 80 } 81 } else { 82 while (height--) { 83 Uint8 byte = 0, bit; 84 for (c = 0; c < info->leading_skip; ++c) { 85 if (!(c & align)) { 86 byte = *src++; 87 } 88 byte <<= srcbpp; 89 } 90 for (; c < width; ++c) { 91 if (!(c & align)) { 92 byte = *src++; 93 } 94 bit = (byte >> (8 - srcbpp)) & mask; 95 if (1) { 96 *dst = map[bit]; 97 } 98 dst++; 99 byte <<= srcbpp; 100 } 101 src += srcskip; 102 dst += dstskip; 103 } 104 } 105 } else { 106 if (SDL_PIXELORDER(info->src_fmt->format) == SDL_BITMAPORDER_4321) { 107 while (height--) { 108 Uint8 byte = 0, bit; 109 for (c = 0; c < info->leading_skip; ++c) { 110 if (!(c & align)) { 111 byte = *src++; 112 } 113 byte >>= srcbpp; 114 } 115 for (; c < width; ++c) { 116 if (!(c & align)) { 117 byte = *src++; 118 } 119 bit = (byte & mask); 120 if (1) { 121 *dst = bit; 122 } 123 dst++; 124 byte >>= srcbpp; 125 } 126 src += srcskip; 127 dst += dstskip; 128 } 129 } else { 130 while (height--) { 131 Uint8 byte = 0, bit; 132 for (c = 0; c < info->leading_skip; ++c) { 133 if (!(c & align)) { 134 byte = *src++; 135 } 136 byte <<= srcbpp; 137 } 138 for (; c < width; ++c) { 139 if (!(c & align)) { 140 byte = *src++; 141 } 142 bit = (byte >> (8 - srcbpp)) & mask; 143 if (1) { 144 *dst = bit; 145 } 146 dst++; 147 byte <<= srcbpp; 148 } 149 src += srcskip; 150 dst += dstskip; 151 } 152 } 153 } 154} 155 156SDL_FORCE_INLINE void BlitBto2(SDL_BlitInfo *info, const Uint32 srcbpp) 157{ 158 const Uint32 mask = (1 << srcbpp) - 1; 159 const Uint32 align = (8 / srcbpp) - 1; 160 161 int c; 162 int width, height; 163 Uint8 *src; 164 Uint16 *map, *dst; 165 int srcskip, dstskip; 166 167 // Set up some basic variables 168 width = info->dst_w; 169 height = info->dst_h; 170 src = info->src; 171 srcskip = info->src_skip; 172 dst = (Uint16 *)info->dst; 173 dstskip = info->dst_skip / 2; 174 map = (Uint16 *)info->table; 175 176 width += info->leading_skip; 177 178 if (srcbpp == 4) 179 srcskip += width - (width + 1) / 2; 180 else if (srcbpp == 2) 181 srcskip += width - (width + 3) / 4; 182 else if (srcbpp == 1) 183 srcskip += width - (width + 7) / 8; 184 185 if (SDL_PIXELORDER(info->src_fmt->format) == SDL_BITMAPORDER_4321) { 186 while (height--) { 187 Uint8 byte = 0, bit; 188 for (c = 0; c < info->leading_skip; ++c) { 189 if (!(c & align)) { 190 byte = *src++; 191 } 192 byte >>= srcbpp; 193 } 194 for (; c < width; ++c) { 195 if (!(c & align)) { 196 byte = *src++; 197 } 198 bit = (byte & mask); 199 if (1) { 200 *dst = map[bit]; 201 } 202 byte >>= srcbpp; 203 dst++; 204 } 205 src += srcskip; 206 dst += dstskip; 207 } 208 } else { 209 while (height--) { 210 Uint8 byte = 0, bit; 211 for (c = 0; c < info->leading_skip; ++c) { 212 if (!(c & align)) { 213 byte = *src++; 214 } 215 byte <<= srcbpp; 216 } 217 for (; c < width; ++c) { 218 if (!(c & align)) { 219 byte = *src++; 220 } 221 bit = (byte >> (8 - srcbpp)) & mask; 222 if (1) { 223 *dst = map[bit]; 224 } 225 byte <<= srcbpp; 226 dst++; 227 } 228 src += srcskip; 229 dst += dstskip; 230 } 231 } 232} 233 234SDL_FORCE_INLINE void BlitBto3(SDL_BlitInfo *info, const Uint32 srcbpp) 235{ 236 const Uint32 mask = (1 << srcbpp) - 1; 237 const Uint32 align = (8 / srcbpp) - 1; 238 239 int c, o; 240 int width, height; 241 Uint8 *src, *map, *dst; 242 int srcskip, dstskip; 243 244 // Set up some basic variables 245 width = info->dst_w; 246 height = info->dst_h; 247 src = info->src; 248 srcskip = info->src_skip; 249 dst = info->dst; 250 dstskip = info->dst_skip; 251 map = info->table; 252 253 width += info->leading_skip; 254 255 if (srcbpp == 4) 256 srcskip += width - (width + 1) / 2; 257 else if (srcbpp == 2) 258 srcskip += width - (width + 3) / 4; 259 else if (srcbpp == 1) 260 srcskip += width - (width + 7) / 8; 261 262 if (SDL_PIXELORDER(info->src_fmt->format) == SDL_BITMAPORDER_4321) { 263 while (height--) { 264 Uint8 byte = 0, bit; 265 for (c = 0; c < info->leading_skip; ++c) { 266 if (!(c & align)) { 267 byte = *src++; 268 } 269 byte >>= srcbpp; 270 } 271 for (; c < width; ++c) { 272 if (!(c & align)) { 273 byte = *src++; 274 } 275 bit = (byte & mask); 276 if (1) { 277 o = bit * 4; 278 dst[0] = map[o++]; 279 dst[1] = map[o++]; 280 dst[2] = map[o++]; 281 } 282 byte >>= srcbpp; 283 dst += 3; 284 } 285 src += srcskip; 286 dst += dstskip; 287 } 288 } else { 289 while (height--) { 290 Uint8 byte = 0, bit; 291 for (c = 0; c < info->leading_skip; ++c) { 292 if (!(c & align)) { 293 byte = *src++; 294 } 295 byte <<= srcbpp; 296 } 297 for (; c < width; ++c) { 298 if (!(c & align)) { 299 byte = *src++; 300 } 301 bit = (byte >> (8 - srcbpp)) & mask; 302 if (1) { 303 o = bit * 4; 304 dst[0] = map[o++]; 305 dst[1] = map[o++]; 306 dst[2] = map[o++]; 307 } 308 byte <<= srcbpp; 309 dst += 3; 310 } 311 src += srcskip; 312 dst += dstskip; 313 } 314 } 315} 316 317SDL_FORCE_INLINE void BlitBto4(SDL_BlitInfo *info, const Uint32 srcbpp) 318{ 319 const Uint32 mask = (1 << srcbpp) - 1; 320 const Uint32 align = (8 / srcbpp) - 1; 321 322 int width, height; 323 Uint8 *src; 324 Uint32 *map, *dst; 325 int srcskip, dstskip; 326 int c; 327 328 // Set up some basic variables 329 width = info->dst_w; 330 height = info->dst_h; 331 src = info->src; 332 srcskip = info->src_skip; 333 dst = (Uint32 *)info->dst; 334 dstskip = info->dst_skip / 4; 335 map = (Uint32 *)info->table; 336 337 width += info->leading_skip; 338 339 if (srcbpp == 4) 340 srcskip += width - (width + 1) / 2; 341 else if (srcbpp == 2) 342 srcskip += width - (width + 3) / 4; 343 else if (srcbpp == 1) 344 srcskip += width - (width + 7) / 8; 345 346 if (SDL_PIXELORDER(info->src_fmt->format) == SDL_BITMAPORDER_4321) { 347 while (height--) { 348 Uint8 byte = 0, bit; 349 for (c = 0; c < info->leading_skip; ++c) { 350 if (!(c & align)) { 351 byte = *src++; 352 } 353 byte >>= srcbpp; 354 } 355 for (; c < width; ++c) { 356 if (!(c & align)) { 357 byte = *src++; 358 } 359 bit = (byte & mask); 360 if (1) { 361 *dst = map[bit]; 362 } 363 byte >>= srcbpp; 364 dst++; 365 } 366 src += srcskip; 367 dst += dstskip; 368 } 369 } else { 370 while (height--) { 371 Uint8 byte = 0, bit; 372 for (c = 0; c < info->leading_skip; ++c) { 373 if (!(c & align)) { 374 byte = *src++; 375 } 376 byte <<= srcbpp; 377 } 378 for (; c < width; ++c) { 379 if (!(c & align)) { 380 byte = *src++; 381 } 382 bit = (byte >> (8 - srcbpp)) & mask; 383 if (1) { 384 *dst = map[bit]; 385 } 386 byte <<= srcbpp; 387 dst++; 388 } 389 src += srcskip; 390 dst += dstskip; 391 } 392 } 393} 394 395SDL_FORCE_INLINE void BlitBto1Key(SDL_BlitInfo *info, const Uint32 srcbpp) 396{ 397 const Uint32 mask = (1 << srcbpp) - 1; 398 const Uint32 align = (8 / srcbpp) - 1; 399 400 int width = info->dst_w; 401 int height = info->dst_h; 402 Uint8 *src = info->src; 403 Uint8 *dst = info->dst; 404 int srcskip = info->src_skip; 405 int dstskip = info->dst_skip; 406 Uint32 ckey = info->colorkey; 407 Uint8 *palmap = info->table; 408 int c; 409 410 width += info->leading_skip; 411 412 if (srcbpp == 4) 413 srcskip += width - (width + 1) / 2; 414 else if (srcbpp == 2) 415 srcskip += width - (width + 3) / 4; 416 else if (srcbpp == 1) 417 srcskip += width - (width + 7) / 8; 418 419 if (palmap) { 420 if (SDL_PIXELORDER(info->src_fmt->format) == SDL_BITMAPORDER_4321) { 421 while (height--) { 422 Uint8 byte = 0, bit; 423 for (c = 0; c < info->leading_skip; ++c) { 424 if (!(c & align)) { 425 byte = *src++; 426 } 427 byte >>= srcbpp; 428 } 429 for (; c < width; ++c) { 430 if (!(c & align)) { 431 byte = *src++; 432 } 433 bit = (byte & mask); 434 if (bit != ckey) { 435 *dst = palmap[bit]; 436 } 437 dst++; 438 byte >>= srcbpp; 439 } 440 src += srcskip; 441 dst += dstskip; 442 } 443 } else { 444 while (height--) { 445 Uint8 byte = 0, bit; 446 for (c = 0; c < info->leading_skip; ++c) { 447 if (!(c & align)) { 448 byte = *src++; 449 } 450 byte <<= srcbpp; 451 } 452 for (; c < width; ++c) { 453 if (!(c & align)) { 454 byte = *src++; 455 } 456 bit = (byte >> (8 - srcbpp)) & mask; 457 if (bit != ckey) { 458 *dst = palmap[bit]; 459 } 460 dst++; 461 byte <<= srcbpp; 462 } 463 src += srcskip; 464 dst += dstskip; 465 } 466 } 467 } else { 468 if (SDL_PIXELORDER(info->src_fmt->format) == SDL_BITMAPORDER_4321) { 469 while (height--) { 470 Uint8 byte = 0, bit; 471 for (c = 0; c < info->leading_skip; ++c) { 472 if (!(c & align)) { 473 byte = *src++; 474 } 475 byte >>= srcbpp; 476 } 477 for (; c < width; ++c) { 478 if (!(c & align)) { 479 byte = *src++; 480 } 481 bit = (byte & mask); 482 if (bit != ckey) { 483 *dst = bit; 484 } 485 dst++; 486 byte >>= srcbpp; 487 } 488 src += srcskip; 489 dst += dstskip; 490 } 491 } else { 492 while (height--) { 493 Uint8 byte = 0, bit; 494 for (c = 0; c < info->leading_skip; ++c) { 495 if (!(c & align)) { 496 byte = *src++; 497 } 498 byte <<= srcbpp; 499 } 500 for (; c < width; ++c) { 501 if (!(c & align)) { 502 byte = *src++; 503 } 504 bit = (byte >> (8 - srcbpp)) & mask; 505 if (bit != ckey) { 506 *dst = bit; 507 } 508 dst++; 509 byte <<= srcbpp; 510 } 511 src += srcskip; 512 dst += dstskip; 513 } 514 } 515 } 516} 517 518SDL_FORCE_INLINE void BlitBto2Key(SDL_BlitInfo *info, const Uint32 srcbpp) 519{ 520 const Uint32 mask = (1 << srcbpp) - 1; 521 const Uint32 align = (8 / srcbpp) - 1; 522 523 int width = info->dst_w; 524 int height = info->dst_h; 525 Uint8 *src = info->src; 526 Uint16 *dstp = (Uint16 *)info->dst; 527 int srcskip = info->src_skip; 528 int dstskip = info->dst_skip; 529 Uint32 ckey = info->colorkey; 530 Uint8 *palmap = info->table; 531 int c; 532 533 width += info->leading_skip; 534 535 if (srcbpp == 4) 536 srcskip += width - (width + 1) / 2; 537 else if (srcbpp == 2) 538 srcskip += width - (width + 3) / 4; 539 else if (srcbpp == 1) 540 srcskip += width - (width + 7) / 8; 541 dstskip /= 2; 542 543 if (SDL_PIXELORDER(info->src_fmt->format) == SDL_BITMAPORDER_4321) { 544 while (height--) { 545 Uint8 byte = 0, bit; 546 for (c = 0; c < info->leading_skip; ++c) { 547 if (!(c & align)) { 548 byte = *src++; 549 } 550 byte >>= srcbpp; 551 } 552 for (; c < width; ++c) { 553 if (!(c & align)) { 554 byte = *src++; 555 } 556 bit = (byte & mask); 557 if (bit != ckey) { 558 *dstp = ((Uint16 *)palmap)[bit]; 559 } 560 byte >>= srcbpp; 561 dstp++; 562 } 563 src += srcskip; 564 dstp += dstskip; 565 } 566 } else { 567 while (height--) { 568 Uint8 byte = 0, bit; 569 for (c = 0; c < info->leading_skip; ++c) { 570 if (!(c & align)) { 571 byte = *src++; 572 } 573 byte <<= srcbpp; 574 } 575 for (; c < width; ++c) { 576 if (!(c & align)) { 577 byte = *src++; 578 } 579 bit = (byte >> (8 - srcbpp)) & mask; 580 if (bit != ckey) { 581 *dstp = ((Uint16 *)palmap)[bit]; 582 } 583 byte <<= srcbpp; 584 dstp++; 585 } 586 src += srcskip; 587 dstp += dstskip; 588 } 589 } 590} 591 592SDL_FORCE_INLINE void BlitBto3Key(SDL_BlitInfo *info, const Uint32 srcbpp) 593{ 594 const Uint32 mask = (1 << srcbpp) - 1; 595 const Uint32 align = (8 / srcbpp) - 1; 596 597 int width = info->dst_w; 598 int height = info->dst_h; 599 Uint8 *src = info->src; 600 Uint8 *dst = info->dst; 601 int srcskip = info->src_skip; 602 int dstskip = info->dst_skip; 603 Uint32 ckey = info->colorkey; 604 Uint8 *palmap = info->table; 605 int c; 606 607 width += info->leading_skip; 608 609 if (srcbpp == 4) 610 srcskip += width - (width + 1) / 2; 611 else if (srcbpp == 2) 612 srcskip += width - (width + 3) / 4; 613 else if (srcbpp == 1) 614 srcskip += width - (width + 7) / 8; 615 616 if (SDL_PIXELORDER(info->src_fmt->format) == SDL_BITMAPORDER_4321) { 617 while (height--) { 618 Uint8 byte = 0, bit; 619 for (c = 0; c < info->leading_skip; ++c) { 620 if (!(c & align)) { 621 byte = *src++; 622 } 623 byte >>= srcbpp; 624 } 625 for (; c < width; ++c) { 626 if (!(c & align)) { 627 byte = *src++; 628 } 629 bit = (byte & mask); 630 if (bit != ckey) { 631 SDL_memcpy(dst, &palmap[bit * 4], 3); 632 } 633 byte >>= srcbpp; 634 dst += 3; 635 } 636 src += srcskip; 637 dst += dstskip; 638 } 639 } else { 640 while (height--) { 641 Uint8 byte = 0, bit; 642 for (c = 0; c < info->leading_skip; ++c) { 643 if (!(c & align)) { 644 byte = *src++; 645 } 646 byte <<= srcbpp; 647 } 648 for (; c < width; ++c) { 649 if (!(c & align)) { 650 byte = *src++; 651 } 652 bit = (byte >> (8 - srcbpp)) & mask; 653 if (bit != ckey) { 654 SDL_memcpy(dst, &palmap[bit * 4], 3); 655 } 656 byte <<= srcbpp; 657 dst += 3; 658 } 659 src += srcskip; 660 dst += dstskip; 661 } 662 } 663} 664 665SDL_FORCE_INLINE void BlitBto4Key(SDL_BlitInfo *info, const Uint32 srcbpp) 666{ 667 const Uint32 mask = (1 << srcbpp) - 1; 668 const Uint32 align = (8 / srcbpp) - 1; 669 670 int width = info->dst_w; 671 int height = info->dst_h; 672 Uint8 *src = info->src; 673 Uint32 *dstp = (Uint32 *)info->dst; 674 int srcskip = info->src_skip; 675 int dstskip = info->dst_skip; 676 Uint32 ckey = info->colorkey; 677 Uint8 *palmap = info->table; 678 int c; 679 680 width += info->leading_skip; 681 682 if (srcbpp == 4) 683 srcskip += width - (width + 1) / 2; 684 else if (srcbpp == 2) 685 srcskip += width - (width + 3) / 4; 686 else if (srcbpp == 1) 687 srcskip += width - (width + 7) / 8; 688 dstskip /= 4; 689 690 if (SDL_PIXELORDER(info->src_fmt->format) == SDL_BITMAPORDER_4321) { 691 while (height--) { 692 Uint8 byte = 0, bit; 693 for (c = 0; c < info->leading_skip; ++c) { 694 if (!(c & align)) { 695 byte = *src++; 696 } 697 byte >>= srcbpp; 698 } 699 for (; c < width; ++c) { 700 if (!(c & align)) { 701 byte = *src++; 702 } 703 bit = (byte & mask); 704 if (bit != ckey) { 705 *dstp = ((Uint32 *)palmap)[bit]; 706 } 707 byte >>= srcbpp; 708 dstp++; 709 } 710 src += srcskip; 711 dstp += dstskip; 712 } 713 } else { 714 while (height--) { 715 Uint8 byte = 0, bit; 716 for (c = 0; c < info->leading_skip; ++c) { 717 if (!(c & align)) { 718 byte = *src++; 719 } 720 byte <<= srcbpp; 721 } 722 for (; c < width; ++c) { 723 if (!(c & align)) { 724 byte = *src++; 725 } 726 bit = (byte >> (8 - srcbpp)) & mask; 727 if (bit != ckey) { 728 *dstp = ((Uint32 *)palmap)[bit]; 729 } 730 byte <<= srcbpp; 731 dstp++; 732 } 733 src += srcskip; 734 dstp += dstskip; 735 } 736 } 737} 738 739static void BlitBtoNAlpha(SDL_BlitInfo *info) 740{ 741 int width = info->dst_w; 742 int height = info->dst_h; 743 Uint8 *src = info->src; 744 Uint8 *dst = info->dst; 745 int srcskip = info->src_skip; 746 int dstskip = info->dst_skip; 747 const SDL_Color *srcpal = info->src_pal->colors; 748 const SDL_PixelFormatDetails *srcfmt = info->src_fmt; 749 const SDL_PixelFormatDetails *dstfmt = info->dst_fmt; 750 int srcbpp, dstbpp; 751 int c; 752 Uint32 pixelvalue, mask, align; 753 unsigned sR, sG, sB; 754 unsigned dR, dG, dB, dA; 755 const unsigned A = info->a; 756 757 width += info->leading_skip; 758 759 srcbpp = srcfmt->bytes_per_pixel; 760 dstbpp = dstfmt->bytes_per_pixel; 761 if (srcbpp == 4) 762 srcskip += width - (width + 1) / 2; 763 else if (srcbpp == 2) 764 srcskip += width - (width + 3) / 4; 765 else if (srcbpp == 1) 766 srcskip += width - (width + 7) / 8; 767 mask = (1 << srcbpp) - 1; 768 align = (8 / srcbpp) - 1; 769 770 if (SDL_PIXELORDER(info->src_fmt->format) == SDL_BITMAPORDER_4321) { 771 while (height--) { 772 Uint8 byte = 0, bit; 773 for (c = 0; c < info->leading_skip; ++c) { 774 if (!(c & align)) { 775 byte = *src++; 776 } 777 byte >>= srcbpp; 778 } 779 for (; c < width; ++c) { 780 if (!(c & align)) { 781 byte = *src++; 782 } 783 bit = (byte & mask); 784 if (1) { 785 sR = srcpal[bit].r; 786 sG = srcpal[bit].g; 787 sB = srcpal[bit].b; 788 DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixelvalue, dR, dG, dB, dA); 789 ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA); 790 ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA); 791 } 792 byte >>= srcbpp; 793 dst += dstbpp; 794 } 795 src += srcskip; 796 dst += dstskip; 797 } 798 } else { 799 while (height--) { 800 Uint8 byte = 0, bit; 801 for (c = 0; c < info->leading_skip; ++c) { 802 if (!(c & align)) { 803 byte = *src++; 804 } 805 byte <<= srcbpp; 806 } 807 for (; c < width; ++c) { 808 if (!(c & align)) { 809 byte = *src++; 810 } 811 bit = (byte >> (8 - srcbpp)) & mask; 812 if (1) { 813 sR = srcpal[bit].r; 814 sG = srcpal[bit].g; 815 sB = srcpal[bit].b; 816 DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixelvalue, dR, dG, dB, dA); 817 ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA); 818 ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA); 819 } 820 byte <<= srcbpp; 821 dst += dstbpp; 822 } 823 src += srcskip; 824 dst += dstskip; 825 } 826 } 827} 828 829static void BlitBtoNAlphaKey(SDL_BlitInfo *info) 830{ 831 int width = info->dst_w; 832 int height = info->dst_h; 833 Uint8 *src = info->src; 834 Uint8 *dst = info->dst; 835 int srcskip = info->src_skip; 836 int dstskip = info->dst_skip; 837 const SDL_PixelFormatDetails *srcfmt = info->src_fmt; 838 const SDL_PixelFormatDetails *dstfmt = info->dst_fmt; 839 const SDL_Color *srcpal = info->src_pal->colors; 840 int srcbpp, dstbpp; 841 int c; 842 Uint32 pixelvalue, mask, align; 843 unsigned sR, sG, sB; 844 unsigned dR, dG, dB, dA; 845 const unsigned A = info->a; 846 Uint32 ckey = info->colorkey; 847 848 width += info->leading_skip; 849 850 srcbpp = srcfmt->bytes_per_pixel; 851 dstbpp = dstfmt->bytes_per_pixel; 852 if (srcbpp == 4) 853 srcskip += width - (width + 1) / 2; 854 else if (srcbpp == 2) 855 srcskip += width - (width + 3) / 4; 856 else if (srcbpp == 1) 857 srcskip += width - (width + 7) / 8; 858 mask = (1 << srcbpp) - 1; 859 align = (8 / srcbpp) - 1; 860 861 if (SDL_PIXELORDER(info->src_fmt->format) == SDL_BITMAPORDER_4321) { 862 while (height--) { 863 Uint8 byte = 0, bit; 864 for (c = 0; c < info->leading_skip; ++c) { 865 if (!(c & align)) { 866 byte = *src++; 867 } 868 byte >>= srcbpp; 869 } 870 for (; c < width; ++c) { 871 if (!(c & align)) { 872 byte = *src++; 873 } 874 bit = (byte & mask); 875 if (bit != ckey) { 876 sR = srcpal[bit].r; 877 sG = srcpal[bit].g; 878 sB = srcpal[bit].b; 879 DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixelvalue, dR, dG, dB, dA); 880 ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA); 881 ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA); 882 } 883 byte >>= srcbpp; 884 dst += dstbpp; 885 } 886 src += srcskip; 887 dst += dstskip; 888 } 889 } else { 890 while (height--) { 891 Uint8 byte = 0, bit; 892 for (c = 0; c < info->leading_skip; ++c) { 893 if (!(c & align)) { 894 byte = *src++; 895 } 896 byte <<= srcbpp; 897 } 898 for (; c < width; ++c) { 899 if (!(c & align)) { 900 byte = *src++; 901 } 902 bit = (byte >> (8 - srcbpp)) & mask; 903 if (bit != ckey) { 904 sR = srcpal[bit].r; 905 sG = srcpal[bit].g; 906 sB = srcpal[bit].b; 907 DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixelvalue, dR, dG, dB, dA); 908 ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA); 909 ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA); 910 } 911 byte <<= srcbpp; 912 dst += dstbpp; 913 } 914 src += srcskip; 915 dst += dstskip; 916 } 917 } 918} 919 920 921 922static void Blit1bto1(SDL_BlitInfo *info) { 923 BlitBto1(info, 1); 924} 925 926static void Blit1bto2(SDL_BlitInfo *info) { 927 BlitBto2(info, 1); 928} 929 930static void Blit1bto3(SDL_BlitInfo *info) { 931 BlitBto3(info, 1); 932} 933 934static void Blit1bto4(SDL_BlitInfo *info) { 935 BlitBto4(info, 1); 936} 937 938static const SDL_BlitFunc bitmap_blit_1b[] = { 939 (SDL_BlitFunc)NULL, Blit1bto1, Blit1bto2, Blit1bto3, Blit1bto4 940}; 941 942static void Blit1bto1Key(SDL_BlitInfo *info) { 943 BlitBto1Key(info, 1); 944} 945 946static void Blit1bto2Key(SDL_BlitInfo *info) { 947 BlitBto2Key(info, 1); 948} 949 950static void Blit1bto3Key(SDL_BlitInfo *info) { 951 BlitBto3Key(info, 1); 952} 953 954static void Blit1bto4Key(SDL_BlitInfo *info) { 955 BlitBto4Key(info, 1); 956} 957 958static const SDL_BlitFunc colorkey_blit_1b[] = { 959 (SDL_BlitFunc)NULL, Blit1bto1Key, Blit1bto2Key, Blit1bto3Key, Blit1bto4Key 960}; 961 962 963 964static void Blit2bto1(SDL_BlitInfo *info) { 965 BlitBto1(info, 2); 966} 967 968static void Blit2bto2(SDL_BlitInfo *info) { 969 BlitBto2(info, 2); 970} 971 972static void Blit2bto3(SDL_BlitInfo *info) { 973 BlitBto3(info, 2); 974} 975 976static void Blit2bto4(SDL_BlitInfo *info) { 977 BlitBto4(info, 2); 978} 979 980static const SDL_BlitFunc bitmap_blit_2b[] = { 981 (SDL_BlitFunc)NULL, Blit2bto1, Blit2bto2, Blit2bto3, Blit2bto4 982}; 983 984static void Blit2bto1Key(SDL_BlitInfo *info) { 985 BlitBto1Key(info, 2); 986} 987 988static void Blit2bto2Key(SDL_BlitInfo *info) { 989 BlitBto2Key(info, 2); 990} 991 992static void Blit2bto3Key(SDL_BlitInfo *info) { 993 BlitBto3Key(info, 2); 994} 995 996static void Blit2bto4Key(SDL_BlitInfo *info) { 997 BlitBto4Key(info, 2); 998} 999 1000static const SDL_BlitFunc colorkey_blit_2b[] = { 1001 (SDL_BlitFunc)NULL, Blit2bto1Key, Blit2bto2Key, Blit2bto3Key, Blit2bto4Key 1002}; 1003 1004 1005 1006static void Blit4bto1(SDL_BlitInfo *info) { 1007 BlitBto1(info, 4); 1008} 1009 1010static void Blit4bto2(SDL_BlitInfo *info) { 1011 BlitBto2(info, 4); 1012} 1013 1014static void Blit4bto3(SDL_BlitInfo *info) { 1015 BlitBto3(info, 4); 1016} 1017 1018static void Blit4bto4(SDL_BlitInfo *info) { 1019 BlitBto4(info, 4); 1020} 1021 1022static const SDL_BlitFunc bitmap_blit_4b[] = { 1023 (SDL_BlitFunc)NULL, Blit4bto1, Blit4bto2, Blit4bto3, Blit4bto4 1024}; 1025 1026static void Blit4bto1Key(SDL_BlitInfo *info) { 1027 BlitBto1Key(info, 4); 1028} 1029 1030static void Blit4bto2Key(SDL_BlitInfo *info) { 1031 BlitBto2Key(info, 4); 1032} 1033 1034static void Blit4bto3Key(SDL_BlitInfo *info) { 1035 BlitBto3Key(info, 4); 1036} 1037 1038static void Blit4bto4Key(SDL_BlitInfo *info) { 1039 BlitBto4Key(info, 4); 1040} 1041 1042static const SDL_BlitFunc colorkey_blit_4b[] = { 1043 (SDL_BlitFunc)NULL, Blit4bto1Key, Blit4bto2Key, Blit4bto3Key, Blit4bto4Key 1044}; 1045 1046 1047 1048SDL_BlitFunc SDL_CalculateBlit0(SDL_Surface *surface) 1049{ 1050 int which; 1051 1052 if (SDL_BITSPERPIXEL(surface->map.info.dst_fmt->format) < 8) { 1053 which = 0; 1054 } else { 1055 which = SDL_BYTESPERPIXEL(surface->map.info.dst_fmt->format); 1056 } 1057 1058 if (SDL_PIXELTYPE(surface->format) == SDL_PIXELTYPE_INDEX1) { 1059 switch (surface->map.info.flags & ~SDL_COPY_RLE_MASK) { 1060 case 0: 1061 if (which < SDL_arraysize(bitmap_blit_1b)) { 1062 return bitmap_blit_1b[which]; 1063 } 1064 break; 1065 1066 case SDL_COPY_COLORKEY: 1067 if (which < SDL_arraysize(colorkey_blit_1b)) { 1068 return colorkey_blit_1b[which]; 1069 } 1070 break; 1071 1072 case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: 1073 return which >= 2 ? BlitBtoNAlpha : (SDL_BlitFunc)NULL; 1074 1075 case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: 1076 return which >= 2 ? BlitBtoNAlphaKey : (SDL_BlitFunc)NULL; 1077 } 1078 return NULL; 1079 } 1080 1081 if (SDL_PIXELTYPE(surface->format) == SDL_PIXELTYPE_INDEX2) { 1082 switch (surface->map.info.flags & ~SDL_COPY_RLE_MASK) { 1083 case 0: 1084 if (which < SDL_arraysize(bitmap_blit_2b)) { 1085 return bitmap_blit_2b[which]; 1086 } 1087 break; 1088 1089 case SDL_COPY_COLORKEY: 1090 if (which < SDL_arraysize(colorkey_blit_2b)) { 1091 return colorkey_blit_2b[which]; 1092 } 1093 break; 1094 1095 case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: 1096 return which >= 2 ? BlitBtoNAlpha : (SDL_BlitFunc)NULL; 1097 1098 case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: 1099 return which >= 2 ? BlitBtoNAlphaKey : (SDL_BlitFunc)NULL; 1100 } 1101 return NULL; 1102 } 1103 1104 if (SDL_PIXELTYPE(surface->format) == SDL_PIXELTYPE_INDEX4) { 1105 switch (surface->map.info.flags & ~SDL_COPY_RLE_MASK) { 1106 case 0: 1107 if (which < SDL_arraysize(bitmap_blit_4b)) { 1108 return bitmap_blit_4b[which]; 1109 } 1110 break; 1111 1112 case SDL_COPY_COLORKEY: 1113 if (which < SDL_arraysize(colorkey_blit_4b)) { 1114 return colorkey_blit_4b[which]; 1115 } 1116 break; 1117 1118 case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: 1119 return which >= 2 ? BlitBtoNAlpha : (SDL_BlitFunc)NULL; 1120 1121 case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: 1122 return which >= 2 ? BlitBtoNAlphaKey : (SDL_BlitFunc)NULL; 1123 } 1124 return NULL; 1125 } 1126 1127 return NULL; 1128} 1129 1130#endif // SDL_HAVE_BLIT_0 1131[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.