1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "scumm/he/intern_he.h"
#include "scumm/he/wiz_he.h"
#include "scumm/he/moonbase/moonbase.h"
namespace Scumm {
enum MoonbaseDistortionTypes {
kMDTEdgeReflectionClipped = 0,
kMDTNotClipped = 1,
kMDTSpecializedNotClipped = 2
};
#define T14_MMX_REQUIRED (0x8000)
#define T14_NOP (0x0000)
#define T14_COPY (0x0001)
#define T14_CHEAP_50_50 (0x0002)
#define T14_PREMULTIPLIED_5050 (0x0003)
#define T14_MMX_COPY (0x0004 | T14_MMX_REQUIRED)
#define T14_MMX_CHEAP_50_50 (0x0005 | T14_MMX_REQUIRED)
#define T14_MMX_PREMULTIPLIED_5050 (0x0006 | T14_MMX_REQUIRED)
#define T14_MMX_ADDITIVE (0x0007 | T14_MMX_REQUIRED)
#define T14_MMX_SUBTRACTIVE (0x0008 | T14_MMX_REQUIRED)
#define T14_MMX_CONSTANT_ALPHA (0x0009 | T14_MMX_REQUIRED)
#define T14_MMX_SILHOUETTE_DARKEN (0x000A | T14_MMX_REQUIRED)
#define T14_MMX_SILHOUETTE_BRIGHTEN (0x000B | T14_MMX_REQUIRED)
#define T14_MMX_PREMUL_ALPHA_COPY (0x000C | T14_MMX_REQUIRED)
#define SIZE_OF_BPTLLC_VALIDATION_HEADER 8
#define BPTLLC_CURRENT_DATA_REVISION 2
#define BPTLLC_CURRENT_REVISION_MASK 0x000000FF
#define BPTLLC_ID_T14_TYPE (uint32)(0x12340100 | (BPTLLC_CURRENT_DATA_REVISION))
#define BPTLLC_ID_RAW_555_DISTORT_TYPE (uint32)(0x12340800 | (BPTLLC_CURRENT_DATA_REVISION))
#define BPTLLC_ID_TRLE_555_DISTORT_TYPE (uint32)(0x12340900 | (BPTLLC_CURRENT_DATA_REVISION))
#define MOONBASE_HANDLE_SKIP_PIXELS_STEP() { \
/* Decompress bytes to do simple clipping... */ \
while (skipAmount > 0) { \
if ((runCount = *dataStream++) & 1) { \
/* Handle the transparent color... */ \
runCount >>= 1; \
if (runCount > skipAmount) { \
runCount -= skipAmount; \
goto DoTransparentRun; \
} else { \
skipAmount -= runCount; \
} \
} else if (runCount & 2) { \
/* Handle a run of color... */ \
runCount = (runCount >> 2) + 1; \
if (runCount > skipAmount) { \
runCount -= skipAmount; \
goto WriteRunData; \
} else { \
skipAmount -= runCount; \
dataStream += sizeof(WizRawPixel16); \
} \
} else { \
/* Handle a literal run of pixels... */ \
runCount = (runCount >> 2) + 1; \
if (runCount > skipAmount) { \
runCount -= skipAmount; \
dataStream += (skipAmount * sizeof(WizRawPixel16)); \
goto WriteLiteralData; \
} else { \
skipAmount -= runCount; \
dataStream += (runCount * sizeof(WizRawPixel16)); \
} \
} \
} \
}
#define MOONBASE_HANDLE_RUN_DECOMPRESS_STEP(_TransparentCode_, _RunCode_, _LiteralCode_) { \
while (decompAmount > 0) { \
runCount = *dataStream++; \
if (runCount & 1) { /* xxxxxxx1 */ \
runCount >>= 1; \
DoTransparentRun: \
decompAmount -= runCount; \
_TransparentCode_ \
} else if (runCount & 2) { /* xxxxxx10 */ \
runCount = (runCount >> 2) + 1; \
WriteRunData: \
decompAmount -= runCount; \
if (decompAmount < 0) { \
runCount += decompAmount; \
} \
_RunCode_ \
dataStream += sizeof(WizRawPixel16); \
} else { /* xxxxxx00 */ \
runCount = (runCount >> 2) + 1; \
WriteLiteralData: \
decompAmount -= runCount; \
if (decompAmount < 0) { \
runCount += decompAmount; \
} \
_LiteralCode_ \
dataStream += (runCount * sizeof(WizRawPixel16)); \
} \
} \
}
static bool canMoonbaseDrawWizType(int compressionType) {
return (kWCTTRLE16Bpp == compressionType) ||
(kWCTComposite == compressionType) ||
(kWCTDataBlockDependent == compressionType);
}
static bool getMoonbaseWizSizeAndType(ScummEngine_v71he *vm, WizImage *wizPtr, int state, int32 &sizeX, int32 &sizeY, int32 &compType) {
byte *workPtr = vm->findWrappedBlock(MKTAG('W', 'I', 'Z', 'H'), wizPtr->data, state, false);
if (!workPtr) {
sizeX = 0;
sizeY = 0;
compType = 0;
return false;
}
compType = READ_LE_UINT32(workPtr + 0);
sizeX = READ_LE_UINT32(workPtr + 4);
sizeY = READ_LE_UINT32(workPtr + 8);
return true;
}
bool Wiz::drawMoonbaseLayeredWiz(
byte *dstBitmapData, int dstWidth, int dstHeight, int dstPitch,
int dstFormat, int dstBpp, byte *wizImageData,
int x, const int y, int state, int clipX1, int clipY1, int clipX2, int clipY2,
uint32 flags, uint32 conditionBits, byte *ptr8BppToXBppClut, byte *altSourceBuffer) {
WizImage wiz;
wiz.data = wizImageData;
wiz.dataSize = READ_BE_UINT32(wiz.data + 4);
// Check to see if this is a valid compression type...
byte *data = _vm->findWrappedBlock(MKTAG('W', 'I', 'Z', 'H'), wiz.data, state, false);
assert(data);
int stateCompressionType = READ_LE_UINT32(data);
if (!canMoonbaseDrawWizType(stateCompressionType)) {
return false;
}
// Make sure we can map the multitype bitmap to a rawbitmap...
WizRawBitmap mappedRawbitmap;
mappedRawbitmap.data = (WizRawPixel16 *)dstBitmapData;
mappedRawbitmap.width = dstWidth;
mappedRawbitmap.height = dstHeight;
mappedRawbitmap.dataSize = (mappedRawbitmap.width * sizeof(WizRawPixel16)) * mappedRawbitmap.height;
if (dstPitch != (int)(mappedRawbitmap.width * sizeof(WizRawPixel16))) {
return false;
}
Common::Rect clipRect;
// We are not directly assigning the rectangle values
// in the constructor: the game can (and will!) assign
// values which will trigger the "invalid rectangle" assertion...
clipRect.left = clipX1;
clipRect.top = clipY1;
clipRect.right = clipX2;
clipRect.bottom = clipY2;
// Dispatch to the image renderer...
drawMoonbaseImageEx(&mappedRawbitmap, &wiz, x, y, state, &clipRect, flags, nullptr, conditionBits, (WizRawPixel16 *)ptr8BppToXBppClut, altSourceBuffer);
// Assume if we're here that we did something...
return true;
}
void Wiz::drawMoonbaseImageEx(
WizRawBitmap *bitmapPtr, WizImage *wizPtr, int x, int y, int state,
Common::Rect *clipRectPtr, int32 flags, Common::Rect *optionalSrcRect,
uint32 conditionBits, WizRawPixel16 *ptr8BppToXBppClut, byte *altSourceBuffer) {
WizMoonbaseCompressedImage fakedHeader;
int32 stateCompressionType;
WizRawBitmap fakedBitmap;
Common::Rect src, dstRect;
int32 sizeX, sizeY;
if (getMoonbaseWizSizeAndType(((ScummEngine_v71he *)_vm), wizPtr, state, sizeX, sizeY, stateCompressionType)) {
if (stateCompressionType == kWCTDataBlockDependent) {
// Find the data block
byte *compressedDataPtr = _vm->findWrappedBlock(MKTAG('W', 'I', 'Z', 'D'), wizPtr->data, state, false);
// If we have data (assume it's T14 for now...)
if (compressedDataPtr) {
Common::Rect clippingRect;
Common::Rect *targetClippingRect;
if (clipRectPtr) {
clippingRect.left = clipRectPtr->left;
clippingRect.top = clipRectPtr->top;
clippingRect.right = (clipRectPtr->right + 1);
clippingRect.bottom = (clipRectPtr->bottom + 1);
targetClippingRect = &clippingRect;
} else {
targetClippingRect = nullptr;
}
// Convert incoming condition bits to ROP's and params
int rawROP = (conditionBits & kWMSBRopMask);
int nROPParam = ((conditionBits & kWMSBReservedBits) >> kWMSBRopParamRShift);
conditionBits &= ~kWMSBReservedBits;
int nROP = T14_NOP;
switch (rawROP) {
default:
case 1: // MMX copy
nROP = T14_MMX_PREMUL_ALPHA_COPY;
break;
case 2: // additive
nROP = T14_MMX_ADDITIVE;
break;
case 3: // subtractive
nROP = T14_MMX_SUBTRACTIVE;
break;
case 4: // over all alpha
nROP = T14_MMX_CONSTANT_ALPHA;
break;
case 5: // MMX cheap 50:50 copy
nROP = T14_MMX_CHEAP_50_50;
break;
case 6: // NON MMX copy
nROP = T14_COPY;
break;
case 7: // NON MMX copy
nROP = T14_CHEAP_50_50;
break;
}
// Finally dispatch to the T14 handler
dispatchBlitRGB555((byte *)bitmapPtr->data, bitmapPtr->width, bitmapPtr->height,
(bitmapPtr->width * sizeof(WizRawPixel16)), targetClippingRect,
compressedDataPtr, x, y, nROP, nROPParam, altSourceBuffer);
}
} else {
byte *wizdBlockPtr = _vm->findWrappedBlock(MKTAG('W', 'I', 'Z', 'D'), wizPtr->data, state, false);
if (wizdBlockPtr) {
wizdBlockPtr -= _vm->_resourceHeaderSize;
// Fake up the compressed image header
fakedHeader.data = wizdBlockPtr + _vm->_resourceHeaderSize;
fakedHeader.transparentColor = 5;
fakedHeader.width = sizeX;
fakedHeader.height = sizeY;
fakedHeader.size = READ_BE_UINT32(wizdBlockPtr + 4);
fakedHeader.type = 0x100; // COMPRESSION_TYPE_SRLE
// Clip the rects passed in...
makeSizedRect(&src, sizeX, sizeY);
if (optionalSrcRect) {
if (!findRectOverlap(&src, optionalSrcRect)) {
return;
}
}
// Get down to business and draw the image...
switch (stateCompressionType) {
case kWCTNone:
break; // Explicitly unhandled
case kWCTTRLE:
if (ptr8BppToXBppClut) {
error("Wiz::drawMoonbaseImageEx(): unimplemented development path trleFLIPDecompress8BppToXBpp()!");
}
break;
case kWCTNone16Bpp:
if (getRawMoonbaseBitmapInfoForState(&fakedBitmap, wizPtr, state)) {
makeSizedRectAt(&dstRect, x, y, getRectWidth(&src), getRectHeight(&src));
if (flags & kWRFHFlip) {
swapRectX(&dstRect);
}
if (flags & kWRFVFlip) {
swapRectY(&dstRect);
}
// How should transparency be managed?
rawMoonbaseBitmapBlit(bitmapPtr, &dstRect, &fakedBitmap, &src);
}
break;
case kWCTComposite:
handleCompositeDrawMoonbaseImage(
bitmapPtr, wizPtr, wizdBlockPtr, x, y, &src, clipRectPtr, flags,
conditionBits, sizeX, sizeY, ptr8BppToXBppClut, altSourceBuffer);
break;
case kWCTTRLE16Bpp:
trleFLIPDecompressMoonbaseImage(bitmapPtr, &fakedHeader, x, y, &src, clipRectPtr, flags);
break;
default:
break;
}
}
}
}
}
bool Wiz::getRawMoonbaseBitmapInfoForState(WizRawBitmap *bitmapPtr, WizImage *wizPtr, int state) {
byte *workPtr;
int32 sizeX, sizeY, compType;
bool wizValid = getMoonbaseWizSizeAndType(_vm, wizPtr, state, sizeX, sizeY, compType);
// Make sure this is a raw image...
if (compType != kWCTNone16Bpp) {
return false;
}
// Make sure that the Wiz is valid...
if (!wizValid) {
return false;
}
// Get the data block for the state...
workPtr = _vm->findWrappedBlock(MKTAG('W', 'I', 'Z', 'H'), wizPtr->data, state, false);
if (!workPtr) {
return false;
}
// Build the bitmap struct for this state...
bitmapPtr->data = (WizRawPixel16 *)workPtr;
bitmapPtr->dataSize = sizeX * sizeY;
bitmapPtr->width = sizeX;
bitmapPtr->height = sizeY;
return true;
}
void Wiz::rawMoonbaseBitmapBlit(WizRawBitmap *dstBitmap, Common::Rect *dstRectPtr, WizRawBitmap *srcBitmap, Common::Rect *srcRectPtr) {
Common::Rect clipRect, dstRect, srcRect;
int x, cw, dw, sw, ch, dxm, dym, ca;
WizRawPixel16 *s;
WizRawPixel16 *d;
dstRect = *dstRectPtr;
srcRect = *srcRectPtr;
makeSizedRect(&clipRect, dstBitmap->width, dstBitmap->height);
if (findRectOverlap(&dstRect, &clipRect)) {
// Adjust the source coords to the clipped dest coords...
dxm = (srcRect.left <= srcRect.right) ? 1 : -1;
dym = (srcRect.top <= srcRect.bottom) ? 1 : -1;
moveRect(&srcRect, (dstRect.left - dstRectPtr->left) * dxm, (dstRect.top - dstRectPtr->top) * dym);
// Common calcs...
dw = dstBitmap->width;
sw = srcBitmap->width;
cw = getRectWidth(&dstRect);
ch = getRectHeight(&dstRect);
d = dstBitmap->data + (((dstBitmap)->width * (dstRect.top) + (dstRect.left)));
s = srcBitmap->data + (((srcBitmap)->width * (srcRect.top) + (srcRect.left)));
ca = cw * sizeof(WizRawPixel16);
// Going up or down?
if (srcRect.top > srcRect.bottom) {
sw = -sw;
}
// Left or right?
if (srcRect.left <= srcRect.right) {
while (--ch >= 0) {
for (x = 0; x < ca; x++) {
d[x] = FROM_LE_16(s[x]);
}
d += dw;
s += sw;
}
} else {
dw -= cw;
sw += cw;
while (--ch >= 0) {
for (x = cw; --x >= 0;) {
*d++ = FROM_LE_16(*s--);
}
d += dw;
s += sw;
}
}
}
}
static void trleFLIPMoonbaseBackwardsPixelCopy(WizRawPixel16 *dstPtr, WizRawPixel16 *srcPtr, int size) {
while (size-- > 0) {
*dstPtr-- = FROM_LE_16(*srcPtr++);
}
}
static void trleFLIPDecompressMoonbaseLineForward(Wiz *wiz, WizRawPixel16 *destPtr, byte *dataStream, int skipAmount, int decompAmount, byte *extraPtr) {
int runCount;
// Decompress bytes to do simple clipping...
MOONBASE_HANDLE_SKIP_PIXELS_STEP();
// Really decompress to the dest buffer...
MOONBASE_HANDLE_RUN_DECOMPRESS_STEP(
{
destPtr += runCount;
},
{
wiz->rawPixelMemset(destPtr, FROM_LE_16(*((uint16 *)dataStream)), runCount);
destPtr += runCount;
},
{
for (int i = 0; i < runCount; i++) {
destPtr[i] = FROM_LE_16(((WizRawPixel16 *)dataStream)[i]);
}
destPtr += runCount;
}
);
}
static void trleFLIPDecompressMoonbaseLineBackward(Wiz *wiz, WizRawPixel16 *destPtr, byte *dataStream, int skipAmount, int decompAmount, byte *extraPtr) {
int runCount;
// Decompress bytes to do simple clipping...
MOONBASE_HANDLE_SKIP_PIXELS_STEP();
// Really decompress to the dest buffer...
MOONBASE_HANDLE_RUN_DECOMPRESS_STEP(
{
destPtr -= runCount;
},
{
destPtr -= runCount;
wiz->rawPixelMemset(destPtr + 1, FROM_LE_16(*((uint16 *)dataStream)), runCount);
},
{
trleFLIPMoonbaseBackwardsPixelCopy(destPtr, (WizRawPixel16 *)dataStream, runCount);
destPtr -= runCount;
}
);
}
void Wiz::trleFLIPDecompressMoonbaseImage(
WizRawBitmap *bitmapPtr, WizMoonbaseCompressedImage *imagePtr, int destX, int destY,
Common::Rect *sourceCoords, Common::Rect *clipRectPtr, int32 flags) {
Common::Rect sourceRect, destRect, clipRect, workRect, inSourceRect;
int width, height, bufferWidth, bufferHeight;
// Lame ass general setup...
bufferWidth = bitmapPtr->width;
bufferHeight = bitmapPtr->height;
if (!sourceCoords) {
width = imagePtr->width;
height = imagePtr->height;
makeSizedRect(&sourceRect, width, height);
} else {
width = getRectWidth(sourceCoords);
height = getRectHeight(sourceCoords);
sourceRect = *sourceCoords;
}
inSourceRect = sourceRect;
makeSizedRectAt(&destRect, destX, destY, width, height);
// Custom clip rect...
if (clipRectPtr) {
clipRect = *clipRectPtr;
makeSizedRect(&workRect, bufferWidth, bufferHeight);
if (!findRectOverlap(&clipRect, &workRect)) {
return;
}
} else {
makeSizedRect(&clipRect, bufferWidth, bufferHeight);
}
// Clip the source & dest coords to the clipping rectangle...
clipRectCoords(&sourceRect, &destRect, &clipRect);
if (destRect.right < destRect.left) {
return;
}
if (destRect.bottom < destRect.top) {
return;
}
if (sourceRect.right < sourceRect.left) {
return;
}
if (sourceRect.bottom < sourceRect.top) {
return;
}
// Handle the flip coords source adjustment...
bool useForwardFunction = true;
if (flags & kWRFHFlip) {
useForwardFunction = false;
horzFlipAlignWithRect(&sourceRect, &inSourceRect);
swapRectX(&destRect);
}
if (flags & kWRFVFlip) {
vertFlipAlignWithRect(&sourceRect, &inSourceRect);
swapRectY(&destRect);
}
// Call the primitive image renderer...
if (useForwardFunction) {
trleFLIPDecompMoonbaseImageHull(
bitmapPtr->data, bufferWidth, &destRect, imagePtr->data,
&sourceRect, nullptr, trleFLIPDecompressMoonbaseLineForward);
} else {
trleFLIPDecompMoonbaseImageHull(
bitmapPtr->data, bufferWidth, &destRect, imagePtr->data,
&sourceRect, nullptr, trleFLIPDecompressMoonbaseLineBackward);
}
}
void Wiz::trleFLIPDecompMoonbaseImageHull(
WizRawPixel16 *bufferPtr, int bufferWidth, Common::Rect *destRect, byte *compData, Common::Rect *sourceRect, byte *extraPtr,
void (*functionPtr)(Wiz *wiz, WizRawPixel *destPtr, byte *dataStream, int skipAmount, int decompAmount, byte *extraPtr)) {
int decompWidth, decompHeight, counter, x1, lineSize;
// General setup...
x1 = sourceRect->left;
decompWidth = sourceRect->right - sourceRect->left + 1;
decompHeight = sourceRect->bottom - sourceRect->top + 1;
// Quickly skip down to the lines to be compressed & dest position...
bufferPtr += bufferWidth * destRect->top + destRect->left;
for (counter = sourceRect->top; counter > 0; counter--) {
compData += READ_LE_UINT16(compData) + 2;
}
// Flip the dest offset if vertical flipping...
if (destRect->top > destRect->bottom) {
bufferWidth = -bufferWidth;
}
// Decompress all the lines that are visible...
while (decompHeight-- > 0) {
lineSize = READ_LE_UINT16(compData);
if (lineSize != 0) {
(*functionPtr)(this, bufferPtr, compData + 2, x1, decompWidth, extraPtr);
compData += lineSize + 2;
bufferPtr += bufferWidth;
} else {
// Handle a completely transparent line!
compData += 2;
bufferPtr += bufferWidth;
}
}
}
bool Wiz::moonbaseLayeredWizHitTest(int32 *outValue, int32 *optionalOutActualValue, byte *globPtr, int state, int x, int y, int32 flags, uint32 conditionBits) {
WizImage wiz;
wiz.data = globPtr;
wiz.dataSize = READ_BE_UINT32(wiz.data + 4);
// Check to see if this is a compression type we like
byte *data = _vm->findWrappedBlock(MKTAG('W', 'I', 'Z', 'H'), wiz.data, state, false);
assert(data);
int stateCompressionType = READ_LE_UINT32(data);
if (!canMoonbaseDrawWizType(stateCompressionType)) {
return false;
}
// Use the layered renderer to do hit-tests, so that all compression
// types supported by the U32 are supported...
int32 chroma = ~0;
int32 pixel = chroma;
drawMoonbaseLayeredWiz((byte *)&pixel, 1, 1, sizeof(WizRawPixel16), 555, 16,
globPtr, -x, -y, state, 0, 0, 0, 0, flags, conditionBits, 0, 0);
if (chroma != pixel) {
*outValue = 1;
} else {
*outValue = 0;
}
if (optionalOutActualValue) {
*optionalOutActualValue = (int32)((uint16)pixel);
}
return true;
}
void Wiz::handleCompositeDrawMoonbaseImage(
WizRawBitmap *bitmapPtr, WizImage *wizPtr, byte *compositeInfoBlockPtr,
int x, int y, Common::Rect *srcRect, Common::Rect *clipRect,
int32 flags, uint32 conditionBits, int32 outerSizeX, int32 outerSizeY,
WizRawPixel16 *ptr8BppToXBppClut, byte *altSourceBuffer) {
int layerCount, xPos, yPos, subState, cmdSize;
uint32 layerConditionBits, layerCmdDataBits;
uint32 subConditionBits, drawFlags;
WizImage nestedMultiStateWiz;
byte *nestedBlockHeader;
byte *nestedWizHeader;
byte *cmdPtr;
uint32 conditionType;
int32 stateSizeX = 0, stateSizeY = 0;
// Get the nested block...
nestedBlockHeader = _vm->heFindResource(MKTAG('N', 'E', 'S', 'T'), wizPtr->data);
if (!nestedBlockHeader) {
return;
}
// Get the real nested wiz...
nestedWizHeader = _vm->heFindResource(MKTAG('M', 'U', 'L', 'T'), nestedBlockHeader);
if (!nestedWizHeader) {
return;
}
// Build a fake wiz header...
nestedMultiStateWiz.data = nestedWizHeader;
nestedMultiStateWiz.dataSize = READ_BE_UINT32(nestedWizHeader + 4);
// Process the composite command block...
compositeInfoBlockPtr += _vm->_resourceHeaderSize;
// Get the number of layers in this command block...
layerCount = READ_LE_UINT16(compositeInfoBlockPtr);
compositeInfoBlockPtr += 2;
// Deal with the moonbase 'system' bits...
int32 defaultSubConditionBits = (conditionBits & kWMSBReservedBits);
conditionBits &= ~kWMSBReservedBits;
// Process each layer...
for (int layerCounter = 0; layerCounter < layerCount; layerCounter++) {
// Get the command and move down by the cmd size
cmdSize = READ_LE_UINT16(compositeInfoBlockPtr);
cmdPtr = compositeInfoBlockPtr + 2;
compositeInfoBlockPtr += (cmdSize + 2);
// Get the cmd flags
layerCmdDataBits = READ_LE_UINT32(cmdPtr);
cmdPtr += 4;
// Check for condition bits
if (layerCmdDataBits & kWCFConditionBits) {
layerConditionBits = READ_LE_UINT32(cmdPtr);
cmdPtr += 4;
// Check to see if the layer overrides the default system bits
subConditionBits = (layerConditionBits & kWMSBReservedBits);
layerConditionBits &= ~kWMSBReservedBits;
if (subConditionBits == 0) {
subConditionBits = defaultSubConditionBits;
}
// Get the condition bits and strip them from the bits...
conditionType = (layerConditionBits & kWSPCCTBits);
layerConditionBits &= ~kWSPCCTBits;
// Perform the actual compare for the bits...
switch (conditionType) {
default:
case kWSPCCTOr:
if (!(layerConditionBits & conditionBits)) {
continue;
}
break;
case kWSPCCTAnd:
if (layerConditionBits != (layerConditionBits & conditionBits)) {
continue;
}
break;
case kWSPCCTNot:
if (layerConditionBits & conditionBits) {
continue;
}
break;
}
} else {
subConditionBits = defaultSubConditionBits;
}
// Get the sub state
if (layerCmdDataBits & kWCFSubState) {
subState = READ_LE_UINT16(cmdPtr);
cmdPtr += 2;
} else {
subState = 0;
}
// Get the X delta
if (layerCmdDataBits & kWCFXDelta) {
xPos = (int16)READ_LE_UINT16(cmdPtr);
cmdPtr += 2;
} else {
xPos = 0;
}
// Get the Y delta
if (layerCmdDataBits & kWCFYDelta) {
yPos = (int16)READ_LE_UINT16(cmdPtr);
cmdPtr += 2;
} else {
yPos = 0;
}
// Get the drawing flags
if (layerCmdDataBits & kWCFDrawFlags) {
drawFlags = READ_LE_UINT32(cmdPtr);
cmdPtr += 4;
} else {
drawFlags = flags;
}
// Based on the drawing flags adjust the blit position
if (drawFlags & (kWRFHFlip | kWRFVFlip)) {
int32 compressionType = 0;
if (!getMoonbaseWizSizeAndType(_vm, &nestedMultiStateWiz, subState, stateSizeX, stateSizeY, compressionType)) {
return;
}
}
if (drawFlags & kWRFHFlip) {
xPos = (outerSizeX - (xPos + stateSizeX));
}
if (drawFlags & kWRFVFlip) {
yPos = (outerSizeY - (yPos + stateSizeY));
}
// Are there any sub condition bits?
if (layerCmdDataBits & kWCFSubConditionBits) {
subConditionBits = READ_LE_UINT32(cmdPtr);
cmdPtr += 4;
}
// Finally do the actual command...
drawMoonbaseImageEx(
bitmapPtr, &nestedMultiStateWiz, (x + xPos), (y + yPos), subState, clipRect,
drawFlags, nullptr, subConditionBits, ptr8BppToXBppClut, altSourceBuffer);
}
}
void Wiz::dispatchBlitRGB555(
byte *bufferData, int bufferWidth, int bufferHeight, int bufferPitch,
Common::Rect *optionalClippingRect, byte *compressedDataStream,
int x, int y, int nROP, int nROPParam, byte *altSourceBuffer) {
if (compressedDataStream) {
uint32 id = READ_LE_UINT32(compressedDataStream);
if (id == BPTLLC_ID_T14_TYPE) {
blitT14CodecImage(
bufferData, bufferWidth, bufferHeight, bufferPitch, optionalClippingRect, compressedDataStream, x, y, nROP, nROPParam);
} else if (id == BPTLLC_ID_RAW_555_DISTORT_TYPE) {
blitDistortion(
bufferData, bufferWidth, bufferHeight, bufferPitch, optionalClippingRect, compressedDataStream, x, y, altSourceBuffer);
} else if (id == BPTLLC_ID_TRLE_555_DISTORT_TYPE) {
error("Unimplemented development path!");
}
}
}
void Wiz::blitT14CodecImage(byte *dst, int dstw, int dsth, int dstPitch, const Common::Rect *clipBox, byte *wizd, int x, int y, int rawROP, int paramROP) {
bool premulAlpha = false;
if (rawROP == T14_MMX_PREMUL_ALPHA_COPY)
premulAlpha = true;
Common::Rect clippedDstRect(dstw, dsth);
if (clipBox) {
Common::Rect clip(clipBox->left, clipBox->top, clipBox->right, clipBox->bottom);
if (clippedDstRect.intersects(clip)) {
clippedDstRect.clip(clip);
} else {
return;
}
}
int width = READ_LE_UINT16(wizd + 0x8 + 0);
int height = READ_LE_UINT16(wizd + 0x8 + 2);
Common::Rect srcLimitsRect(width, height);
Common::Rect dstOperation(x, y, x + width, y + height);
if (!clippedDstRect.intersects(dstOperation))
return;
Common::Rect clippedRect = clippedDstRect.findIntersectingRect(dstOperation);
int cx = clippedRect.right - clippedRect.left;
int cy = clippedRect.bottom - clippedRect.top;
int sx = ((clippedRect.left - x) + srcLimitsRect.left);
int sy = ((clippedRect.top - y) + srcLimitsRect.top);
dst += clippedRect.top * dstPitch + clippedRect.left * 2;
int headerSize = READ_LE_UINT32(wizd + 0x4);
uint8 *dataPointer = wizd + 0x8 + headerSize;
for (int i = 0; i < sy; i++) {
uint16 lineSize = READ_LE_UINT16(dataPointer + 0);
dataPointer += lineSize;
}
for (int i = 0; i < cy; i++) {
uint16 lineSize = READ_LE_UINT16(dataPointer + 0);
uint8 *singlesOffset = READ_LE_UINT16(dataPointer + 2) + dataPointer;
uint8 *quadsOffset = READ_LE_UINT16(dataPointer + 4) + dataPointer;
int pixels = 0;
byte *dst1 = dst;
byte *codes = dataPointer + 6;
while (1) {
int code = *codes - 2;
codes++;
if (code <= 0) { // quad or single
uint8 *src;
int cnt;
if (code == 0) { // quad
src = quadsOffset;
quadsOffset += 8;
cnt = 4; // 4 pixels
} else { // single
src = singlesOffset;
singlesOffset += 2;
cnt = 1;
}
for (int c = 0; c < cnt; c++) {
if (pixels >= sx) {
if (rawROP == T14_MMX_PREMUL_ALPHA_COPY) { // MMX_PREMUL_ALPHA_COPY
WRITE_UINT16(dst1, READ_LE_UINT16(src));
} else if (rawROP == T14_MMX_ADDITIVE) { // MMX_ADDITIVE
uint16 color = READ_LE_UINT16(src);
uint16 orig = READ_UINT16(dst1);
uint32 r = MIN<uint32>(0x7c00, (orig & 0x7c00) + (color & 0x7c00));
uint32 g = MIN<uint32>(0x03e0, (orig & 0x03e0) + (color & 0x03e0));
uint32 b = MIN<uint32>(0x001f, (orig & 0x001f) + (color & 0x001f));
WRITE_UINT16(dst1, (r | g | b));
} else if (rawROP == T14_MMX_CHEAP_50_50) { // MMX_CHEAP_50_50
uint16 color = (READ_LE_UINT16(src) >> 1) & 0x3DEF;
uint16 orig = (READ_UINT16(dst1) >> 1) & 0x3DEF;
WRITE_UINT16(dst1, (color + orig));
}
dst1 += 2;
}
src += 2;
pixels++;
if (pixels >= cx + sx)
break;
}
} else { // skip
if ((code & 1) == 0) {
code >>= 1;
for (int j = 0; j < code; j++) {
if (pixels >= sx)
dst1 += 2;
pixels++;
if (pixels >= cx + sx)
break;
}
} else { // special case
if (pixels >= sx) {
int alpha = code >> 1;
uint16 color = READ_LE_UINT16(singlesOffset);
uint32 orig = READ_UINT16(dst1);
if (!premulAlpha) {
WRITE_UINT16(dst1, color); // ENABLE_PREMUL_ALPHA = 0
} else {
if (alpha > 32) {
alpha -= 32;
uint32 oR = orig & 0x7c00;
uint32 oG = orig & 0x03e0;
uint32 oB = orig & 0x1f;
uint32 dR = ((((color & 0x7c00) - oR) * alpha) >> 5) + oR;
uint32 dG = ((((color & 0x3e0) - oG) * alpha) >> 5) + oG;
uint32 dB = ((((color & 0x1f) - oB) * alpha) >> 5) + oB;
WRITE_UINT16(dst1, (dR & 0x7c00) | (dG & 0x3e0) | (dB & 0x1f));
} else {
uint32 pix = ((orig << 16) | orig) & 0x3e07c1f;
pix = (((pix * alpha) & 0xffffffff) >> 5) & 0x3e07c1f;
pix = ((pix >> 16) + pix + color) & 0xffff;
WRITE_UINT16(dst1, pix);
}
}
dst1 += 2;
}
singlesOffset += 2;
pixels++;
}
}
if (pixels >= cx + sx)
break;
}
dataPointer += lineSize;
dst += dstPitch;
}
}
void Wiz::blitDistortion(
byte *bufferData, int bufferWidth, int bufferHeight, int bufferPitch,
Common::Rect *optionalClippingRect, byte *compressedDataStream,
int x, int y, byte *altSourceBuffer) {
int format = 555;
int bpp = 16;
int distortionFormat = 555;
int distortionBpp = 16;
// Setup the source pointer...
byte *sourcePixels = (altSourceBuffer) ? altSourceBuffer : bufferData;
// Clip the optional clipping rect to the dest bitmap limits...
Common::Rect dstLimitsRect(0, 0, bufferWidth, bufferHeight);
Common::Rect clippedDstRect;
if (optionalClippingRect) {
if (!dstLimitsRect.intersects(*optionalClippingRect)) {
return;
}
clippedDstRect = dstLimitsRect;
clippedDstRect.clip(*optionalClippingRect);
} else {
clippedDstRect = dstLimitsRect;
}
// Get the source operation size...
int w = READ_LE_UINT16(compressedDataStream + SIZE_OF_BPTLLC_VALIDATION_HEADER + 0);
int h = READ_LE_UINT16(compressedDataStream + SIZE_OF_BPTLLC_VALIDATION_HEADER + 2);
Common::Rect srcLimitsRect(0, 0, w, h);
Common::Rect clippedSrcRect = srcLimitsRect;
// Perform a simple clipping operation to detect if we have to bail out early...
Common::Rect dstOperation(x, y,
x + (clippedSrcRect.right - clippedSrcRect.left),
y + (clippedSrcRect.bottom - clippedSrcRect.top));
Common::Rect clippedRect;
if (!clippedDstRect.intersects(dstOperation)) {
return;
}
clippedRect = clippedDstRect;
clippedRect.clip(dstOperation);
// Get the important header information...
int subBlockCount = READ_LE_UINT16(compressedDataStream + SIZE_OF_BPTLLC_VALIDATION_HEADER + 4);
byte *subBlockStream = compressedDataStream + SIZE_OF_BPTLLC_VALIDATION_HEADER + READ_LE_UINT32(compressedDataStream + 4);
// Get our clip rect information...
int cx1 = clippedDstRect.left;
int cy1 = clippedDstRect.top;
int cx2 = clippedDstRect.right - 1;
int cy2 = clippedDstRect.bottom - 1;
// Process each sub-block...
for (int i = 0; i < subBlockCount; i++) {
// Read the sub-block header...
byte *blockData = subBlockStream;
uint32 blockSize = READ_LE_UINT32(blockData); blockData += 4;
subBlockStream += blockSize;
int xOffset = READ_LE_UINT16(blockData); blockData += 2;
int yOffset = READ_LE_UINT16(blockData); blockData += 2;
int width = READ_LE_UINT16(blockData); blockData += 2;
int height = READ_LE_UINT16(blockData); blockData += 2;
int lReach = READ_LE_UINT16(blockData); blockData += 2;
int rReach = READ_LE_UINT16(blockData); blockData += 2;
int tReach = READ_LE_UINT16(blockData); blockData += 2;
int bReach = READ_LE_UINT16(blockData); blockData += 2;
int distortionPitch = ((width * distortionBpp + 7) / 8);
// Check for special case...
if ((width == 0) && (height == 0)) {
continue;
}
// Call the blitter for the sub block...
blitUncompressedDistortionBitmap(
bufferData, bufferWidth, bufferHeight, bufferPitch, format, bpp,
sourcePixels, bufferWidth, bufferHeight, bufferPitch, format, bpp,
blockData, width, height, distortionPitch, distortionFormat, distortionBpp,
(x + xOffset), (y + yOffset), (x + xOffset), (y + yOffset),
lReach, rReach, tReach, bReach,
cx1, cy1, cx2, cy2, cx1, cy1, cx2, cy2
);
}
}
void Wiz::blitUncompressedDistortionBitmap(
byte *dstBitmapData, int dstWidth, int dstHeight, int dstPitch, int dstFormat, int dstBpp,
byte *srcBitmapData, int srcWidth, int srcHeight, int srcPitch, int srcFormat, int srcBpp,
byte *distortionBitmapData, int distortionWidth, int distortionHeight, int distortionPitch, int distortionFormat, int distortionBpp,
int dstX, int dstY, int srcX, int srcY, int lReach, int rReach, int tReach, int bReach,
int srcClipX1, int srcClipY1, int srcClipX2, int srcClipY2,
int dstClipX1, int dstClipY1, int dstClipX2, int dstClipY2) {
MoonbaseDistortionInfo distInfo;
int gMax = ((1 << 5) - 1);
int bMax = ((1 << 5) - 1);
int xSignedAdjust = -(gMax / 2);
int ySignedAdjust = -(bMax / 2);
Graphics::Surface mappedDstBitmap;
mappedDstBitmap.init(dstWidth, dstHeight, dstPitch, dstBitmapData, Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0));
Graphics::Surface mappedSrcBitmap;
mappedSrcBitmap.init(srcWidth, srcHeight, srcPitch, srcBitmapData, Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0));
Graphics::Surface mappedDistortionBitmap;
mappedDistortionBitmap.init(distortionWidth, distortionHeight, distortionPitch, distortionBitmapData, Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0));
Common::Rect srcClipRect(srcClipX1, srcClipY1, srcClipX2, srcClipY2);
Common::Rect dstClipRect(dstClipX1, dstClipY1, dstClipX2, dstClipY2);
Common::Rect srcReach((srcX - lReach), (srcY - tReach), (srcX + rReach), (srcY + bReach));
Common::Rect srcLimits(mappedSrcBitmap.w, mappedSrcBitmap.h);
if (!findRectOverlap(&srcLimits, &srcClipRect)) {
return;
}
if (!srcReach.intersects(srcLimits)) {
return;
}
if (srcReach.contains(srcLimits)) {
if (mappedSrcBitmap.pitch == 1280) {
distInfo.baseX = 0;
distInfo.baseY = 0;
distInfo.srcPitch = mappedSrcBitmap.pitch;
distInfo.clipRect = nullptr;
distInfo.srcData = (byte *)mappedSrcBitmap.getBasePtr(
(dstX - srcX) + xSignedAdjust, (dstY - srcY) + ySignedAdjust);
distortionBlitCore(&mappedDstBitmap, dstX, dstY, &mappedDistortionBitmap, 0, &dstClipRect, kMDTSpecializedNotClipped, &distInfo);
} else {
distInfo.baseX = (dstX - srcX) + xSignedAdjust;
distInfo.baseY = (dstY - srcY) + ySignedAdjust;
distInfo.srcPitch = mappedSrcBitmap.pitch;
distInfo.clipRect = nullptr;
distInfo.srcData = (byte *)mappedSrcBitmap.getBasePtr(0, 0);
distortionBlitCore(&mappedDstBitmap, dstX, dstY, &mappedDistortionBitmap, 0, &dstClipRect, kMDTNotClipped, &distInfo);
}
} else {
distInfo.baseX = (dstX - srcX) + xSignedAdjust;
distInfo.baseY = (dstY - srcY) + ySignedAdjust;
distInfo.srcPitch = mappedSrcBitmap.pitch;
distInfo.clipRect = &srcLimits;
distInfo.srcData = (byte *)mappedSrcBitmap.getBasePtr(0, 0);
distortionBlitCore(&mappedDstBitmap, dstX, dstY, &mappedDistortionBitmap, 0, &dstClipRect, kMDTEdgeReflectionClipped, &distInfo);
}
}
static void distortionGetCoordinates(int s, int &x, int &y) {
int G_Mask = (((1 << 5) - 1) << 5);
int B_Mask = (((1 << 5) - 1) << 0);
int G_LShift = 5;
int B_LShift = 0;
x = (s & G_Mask) >> G_LShift;
y = (s & B_Mask) >> B_LShift;
}
static void distortionTransferOp(int transferOp, MoonbaseDistortionInfo *mdi, uint16 *d, uint16 *s, int dx, int dy) {
int xx, yy, sx, sy;
switch (transferOp) {
case kMDTEdgeReflectionClipped:
// Get the 'coordinates' from the color channels...
distortionGetCoordinates(READ_LE_UINT16(s), xx, yy);
// Find the read X location
sx = mdi->baseX + dx + xx;
if (sx < mdi->clipRect->left) {
sx -= (mdi->clipRect->left - sx);
}
if (sx > mdi->clipRect->right) {
sx -= (sx - mdi->clipRect->right);
}
// Cap the coordinates just incase it's a really tight src clip...
sx = MAX<int>(mdi->clipRect->left, MIN<int>(sx, mdi->clipRect->right));
// Find the read Y location...
sy = mdi->baseY + dy + yy;
if (sy < mdi->clipRect->top) {
sy -= (mdi->clipRect->top - sy);
}
if (sy > mdi->clipRect->bottom) {
sy -= (sy - mdi->clipRect->bottom);
}
// Cap the coordinates just in case it's a really tight src clip...
sy = MAX<int>(mdi->clipRect->top, MIN<int>(sy, mdi->clipRect->bottom));
// Transfer the pixel...
*d = *((uint16 *)(mdi->srcData + sy * mdi->srcPitch + sx * sizeof(uint16)));
break;
case kMDTNotClipped:
// Get the 'coordinates' from the color channels...
distortionGetCoordinates(READ_BE_UINT16(s), xx, yy);
// Find the read X location...
sx = mdi->baseX + dx + xx;
// Find the read Y location...
sy = mdi->baseY + dy + yy;
// Transfer the pixel...
*d = *((uint16 *)(mdi->srcData + sy * mdi->srcPitch + sx * sizeof(uint16)));
break;
case kMDTSpecializedNotClipped:
// Get the 'coordinates' from the color channels...
distortionGetCoordinates(READ_BE_UINT16(s), xx, yy);
// Transfer the source pixel...
*d = *((uint16 *)(mdi->srcData + ((dy + yy) * 640 * sizeof(uint16)) + ((dx + xx) * sizeof(uint16))));
break;
default:
error("distortionTransferOp(): Invalid transfer operation %d", transferOp);
}
}
void Wiz::distortionBlitCore(
Graphics::Surface *dstBitmap, int x, int y, Graphics::Surface *srcBitmap,
Common::Rect *optionalSrcRectPtr, Common::Rect *optionalclipRectPtr, int transferOp, MoonbaseDistortionInfo *mdi) {
// Clip the clip rect if one with the dest bitmap limits...
Common::Rect clipRect;
makeSizedRect(&clipRect, dstBitmap->w, dstBitmap->h);
if (optionalclipRectPtr) {
if (!findRectOverlap(&clipRect, optionalclipRectPtr))
return;
}
// Clip the source coords to the source bitmap limits...
Common::Rect srcRect;
makeSizedRect(&srcRect, srcBitmap->w, srcBitmap->h);
if (optionalSrcRectPtr) {
if (!findRectOverlap(&srcRect, optionalSrcRectPtr))
return;
}
// Build/clip the dest rect...
Common::Rect dstRect;
makeSizedRectAt(&dstRect, x, y, getRectWidth(&srcRect), getRectHeight(&srcRect));
if (!findRectOverlap(&dstRect, &clipRect))
return;
// Adjust the source coords to the clipped dest coords...
moveRect(&srcRect, (dstRect.left - x), (dstRect.top - y));
// Calc the source pointer/get the source stride...
byte *srcPtr = (byte *)srcBitmap->getBasePtr(srcRect.left, srcRect.top);
int sStride = srcBitmap->pitch;
// Calc the destination pointer / get the destination stride...
byte *dstPtr = (byte *)dstBitmap->getBasePtr(dstRect.left, dstRect.top);
int dStride = dstBitmap->pitch;
// Setup operation amounts...
int cw = getRectWidth(&dstRect);
int ch = getRectHeight(&dstRect);
// Left or right?
int idx = dstRect.left;
int dy = dstRect.top;
while (--ch >= 0) {
// Get the working pointers and step the line pointers...
uint16 *d = (uint16 *)dstPtr;
uint16 *s = (uint16 *)srcPtr;
// Transfer the pixels...
int dx = idx;
for (int i = cw; --i >= 0;) {
distortionTransferOp(transferOp, mdi, d, s, dx, dy);
++d;
++s;
++dx;
}
// Move the line pointers...
dstPtr += dStride;
srcPtr += sStride;
++dy;
}
}
} // End of namespace Scumm
|