Ticket #8611: 32bit.patch
File 32bit.patch, 41.0 KB (added by , 17 years ago) |
---|
-
backends/platform/sdl/graphics.cpp
145 145 bool OSystem_SDL::setGraphicsMode(int mode) { 146 146 Common::StackLock lock(_graphicsMutex); 147 147 148 bool needHotSwap = false; 148 149 int newScaleFactor = 1; 149 150 ScalerProc *newScalerProc; 150 151 … … 211 212 _transactionDetails.normal1xScaler = (mode == GFX_NORMAL); 212 213 213 214 _mode = mode; 215 216 #ifndef DISABLE_HQ_SCALERS 217 // Hotswapping (to change the color depth) when switching to and from HQ-scalers 218 if (_scalerProc != newScalerProc) { 219 if (((newScalerProc == HQ2x) || (newScalerProc == HQ3x)) && 220 (_curBytesPerPixel == 4)) 221 needHotSwap = true; 222 if (((_scalerProc == HQ2x) || (_scalerProc == HQ3x)) && 223 (_bytesPerPixel > 2)) 224 needHotSwap = true; 225 } 226 #endif 227 214 228 _scalerProc = newScalerProc; 215 229 216 230 if (_transactionMode == kTransactionActive) { … … 230 244 // NOTE: This should not be executed at transaction commit 231 245 // Otherwise there is some unsolicited setGraphicsMode() call 232 246 // which should be properly removed 233 if ( newScaleFactor != _scaleFactor) {247 if ((newScaleFactor != _scaleFactor) || needHotSwap) { 234 248 assert(_transactionMode != kTransactionCommit); 235 249 236 250 _scaleFactor = newScaleFactor; … … 337 351 error("allocating _screen failed"); 338 352 339 353 // 340 // C reate the surface that contains the scaled graphics in 16 bit mode354 // Check whether to use 32 or 16 bit colors 341 355 // 342 356 343 _hwscreen = SDL_SetVideoMode(hwW, hwH, 16, 357 if ((_bytesPerPixel > 2) && (_scalerProc != HQ2x) && (_scalerProc != HQ3x)) 358 _curBytesPerPixel = 4; 359 else 360 _curBytesPerPixel = 2; 361 362 // 363 // Create the surface that contains the scaled graphics in 32/16 bit mode 364 // 365 366 _hwscreen = SDL_SetVideoMode(hwW, hwH, _curBytesPerPixel * 8, 344 367 _fullscreen ? (SDL_FULLSCREEN|SDL_SWSURFACE) : SDL_SWSURFACE 345 368 ); 346 369 if (_hwscreen == NULL) { … … 369 392 // 370 393 371 394 // Distinguish 555 and 565 mode 372 if (_hwscreen->format->Rmask == 0x7C00) 373 InitScalers(555); 374 else 375 InitScalers(565); 395 if (_curBytesPerPixel == 2) { 396 _Rmask = _hwscreen->format->Rmask; 397 _Gmask = _hwscreen->format->Gmask; 398 _Bmask = _hwscreen->format->Bmask; 399 _Amask = _hwscreen->format->Amask; 400 if (_Rmask == 0x7C00) 401 InitScalers(555); 402 else 403 InitScalers(565); 404 } else { 405 _Rmask = 0xF800; 406 _Gmask = 0x07E0; 407 _Bmask = 0x001F; 408 _Amask = 0x0000; 409 InitScalers(8888); 410 } 376 411 377 412 // Need some extra bytes around when using 2xSaI 378 413 _tmpscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, _screenWidth + 3, _screenHeight + 3, 379 16,414 _curBytesPerPixel * 8, 380 415 _hwscreen->format->Rmask, 381 416 _hwscreen->format->Gmask, 382 417 _hwscreen->format->Bmask, … … 386 421 error("allocating _tmpscreen failed"); 387 422 388 423 _overlayscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, _overlayWidth, _overlayHeight, 389 16, 390 _hwscreen->format->Rmask, 391 _hwscreen->format->Gmask, 392 _hwscreen->format->Bmask, 393 _hwscreen->format->Amask); 424 16, _Rmask, _Gmask, _Bmask, _Amask); 394 425 395 426 if (_overlayscreen == NULL) 396 427 error("allocating _overlayscreen failed"); 397 428 398 429 _tmpscreen2 = SDL_CreateRGBSurface(SDL_SWSURFACE, _overlayWidth + 3, _overlayHeight + 3, 399 16, 430 16, _Rmask, _Gmask, _Bmask, _Amask); 431 432 if (_tmpscreen2 == NULL) 433 error("allocating _tmpscreen2 failed"); 434 435 _tmpscreen3 = SDL_CreateRGBSurface(SDL_SWSURFACE, _screenWidth + 3, _screenHeight + 3, 436 16, _Rmask, _Gmask, _Bmask, _Amask); 437 438 if (_tmpscreen3 == NULL) 439 error("allocating _tmpscreen3 failed"); 440 441 _tmpscreen4 = SDL_CreateRGBSurface(SDL_SWSURFACE, _overlayWidth + 3, _overlayHeight + 3, 442 _curBytesPerPixel * 8, 400 443 _hwscreen->format->Rmask, 401 444 _hwscreen->format->Gmask, 402 445 _hwscreen->format->Bmask, 403 446 _hwscreen->format->Amask); 404 447 405 if (_tmpscreen 2== NULL)406 error("allocating _tmpscreen 2failed");448 if (_tmpscreen4 == NULL) 449 error("allocating _tmpscreen4 failed"); 407 450 408 451 #ifdef USE_OSD 409 452 _osdSurface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, 410 453 _hwscreen->w, 411 454 _hwscreen->h, 412 16, 413 _hwscreen->format->Rmask, 414 _hwscreen->format->Gmask, 415 _hwscreen->format->Bmask, 416 _hwscreen->format->Amask); 455 16, _Rmask, _Gmask, _Bmask, _Amask); 417 456 if (_osdSurface == NULL) 418 457 error("allocating _osdSurface failed"); 419 458 SDL_SetColorKey(_osdSurface, SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, kOSDColorKey); … … 447 486 _tmpscreen2 = NULL; 448 487 } 449 488 489 if (_tmpscreen3) { 490 SDL_FreeSurface(_tmpscreen3); 491 _tmpscreen3 = NULL; 492 } 493 494 if (_tmpscreen4) { 495 SDL_FreeSurface(_tmpscreen4); 496 _tmpscreen4 = NULL; 497 } 498 450 499 if (_overlayscreen) { 451 500 SDL_FreeSurface(_overlayscreen); 452 501 _overlayscreen = NULL; … … 474 523 475 524 SDL_FreeSurface(_tmpscreen); 476 525 SDL_FreeSurface(_tmpscreen2); 526 SDL_FreeSurface(_tmpscreen3); 527 SDL_FreeSurface(_tmpscreen4); 477 528 478 529 #ifdef USE_OSD 479 530 // Release the OSD surface … … 578 629 scale1 = _scaleFactor; 579 630 } else { 580 631 origSurf = _overlayscreen; 581 srcSurf = _tmpscreen 2;632 srcSurf = _tmpscreen4; 582 633 width = _overlayWidth; 583 634 height = _overlayHeight; 584 635 scalerProc = Normal1x; … … 646 697 dst_y = real2Aspect(dst_y); 647 698 648 699 assert(scalerProc != NULL); 649 scalerProc((byte *)srcSurf->pixels + (r->x * 2 + 2) + (r->y + 1) * srcPitch, srcPitch, 650 (byte *)_hwscreen->pixels + rx1 * 2 + dst_y * dstPitch, dstPitch, r->w, dst_h); 700 scalerProc((byte *)srcSurf->pixels + 701 (r->x * _curBytesPerPixel + _bytesPerPixel) + 702 (r->y + 1) * srcPitch, srcPitch, 703 (byte *)_hwscreen->pixels + 704 rx1 * _curBytesPerPixel + 705 dst_y * dstPitch, dstPitch, 706 r->w, dst_h, _curBytesPerPixel); 651 707 } 652 708 653 709 r->x = rx1; … … 657 713 658 714 #ifndef DISABLE_SCALERS 659 715 if (_adjustAspectRatio && orig_dst_y < height && !_overlayVisible) 660 r->h = stretch200To240((uint8 *) _hwscreen->pixels, dstPitch, r->w, r->h, r->x, r->y, orig_dst_y * scale1 );716 r->h = stretch200To240((uint8 *) _hwscreen->pixels, dstPitch, r->w, r->h, r->x, r->y, orig_dst_y * scale1, _curBytesPerPixel); 661 717 #endif 662 718 } 663 719 SDL_UnlockSurface(srcSurf); … … 1157 1213 dst.x = dst.y = 1; 1158 1214 src.w = dst.w = _screenWidth; 1159 1215 src.h = dst.h = _screenHeight; 1160 if (SDL_BlitSurface(_screen, &src, _tmpscreen , &dst) != 0)1216 if (SDL_BlitSurface(_screen, &src, _tmpscreen3, &dst) != 0) 1161 1217 error("SDL_BlitSurface failed: %s", SDL_GetError()); 1162 1218 1163 SDL_LockSurface(_tmpscreen );1219 SDL_LockSurface(_tmpscreen3); 1164 1220 SDL_LockSurface(_overlayscreen); 1165 _scalerProc((byte *)(_tmpscreen ->pixels) + _tmpscreen->pitch + 2, _tmpscreen->pitch,1221 _scalerProc((byte *)(_tmpscreen3->pixels) + _tmpscreen3->pitch + 2, _tmpscreen3->pitch, 1166 1222 (byte *)_overlayscreen->pixels, _overlayscreen->pitch, _screenWidth, _screenHeight); 1167 1223 1168 1224 #ifndef DISABLE_SCALERS 1169 1225 if (_adjustAspectRatio) 1170 1226 stretch200To240((uint8 *)_overlayscreen->pixels, _overlayscreen->pitch, 1171 _overlayWidth, _screenHeight * _scaleFactor, 0, 0, 0 );1227 _overlayWidth, _screenHeight * _scaleFactor, 0, 0, 0, 2); 1172 1228 #endif 1173 SDL_UnlockSurface(_tmpscreen );1229 SDL_UnlockSurface(_tmpscreen3); 1174 1230 SDL_UnlockSurface(_overlayscreen); 1175 1231 1176 1232 _forceFull = true; … … 1317 1373 _mouseOrigSurface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, 1318 1374 _mouseCurState.w + 2, 1319 1375 _mouseCurState.h + 2, 1320 16, 1321 _hwscreen->format->Rmask, 1322 _hwscreen->format->Gmask, 1323 _hwscreen->format->Bmask, 1324 _hwscreen->format->Amask); 1376 16, _Rmask, _Gmask, _Bmask, _Amask); 1325 1377 1326 1378 if (_mouseOrigSurface == NULL) 1327 1379 error("allocating _mouseOrigSurface failed"); … … 1438 1490 _mouseSurface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, 1439 1491 _mouseCurState.rW, 1440 1492 _mouseCurState.rH, 1441 16, 1442 _hwscreen->format->Rmask, 1443 _hwscreen->format->Gmask, 1444 _hwscreen->format->Bmask, 1445 _hwscreen->format->Amask); 1493 16, _Rmask, _Gmask, _Bmask, _Amask); 1446 1494 1447 1495 if (_mouseSurface == NULL) 1448 1496 error("allocating _mouseSurface failed"); -
backends/platform/sdl/sdl.cpp
142 142 error("Could not initialize SDL: %s", SDL_GetError()); 143 143 } 144 144 145 _bytesPerPixel = SDL_GetVideoInfo()->vfmt->BytesPerPixel; 145 146 _graphicsMutex = createMutex(); 146 147 147 148 SDL_ShowCursor(SDL_DISABLE); -
backends/platform/sdl/sdl-common.h
221 221 // temporary screen (for scalers) 222 222 SDL_Surface *_tmpscreen; 223 223 SDL_Surface *_tmpscreen2; 224 SDL_Surface *_tmpscreen3; 225 SDL_Surface *_tmpscreen4; 224 226 225 227 // overlay 226 228 SDL_Surface *_overlayscreen; 227 229 int _overlayWidth, _overlayHeight; 228 230 bool _overlayVisible; 229 231 232 // color depth 233 uint8 _bytesPerPixel; 234 uint8 _curBytesPerPixel; 235 uint32 _Rmask; 236 uint32 _Gmask; 237 uint32 _Bmask; 238 uint32 _Amask; 239 230 240 // Audio 231 241 int _samplesPerSec; 232 242 -
graphics/scaler.cpp
107 107 InitLUT<ColorMasks<555> >(); 108 108 if (gBitFormat == 565) 109 109 InitLUT<ColorMasks<565> >(); 110 // Use 565-format for 16 bit surfaces in 32 bit mode 111 if (gBitFormat == 8888) 112 InitLUT<ColorMasks<565> >(); 110 113 #endif 111 114 } 112 115 … … 116 119 * source to the destionation. 117 120 */ 118 121 void Normal1x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, 119 int width, int height ) {122 int width, int height, uint8 bytesPerPixel) { 120 123 while (height--) { 121 memcpy(dstPtr, srcPtr, 2* width);124 memcpy(dstPtr, srcPtr, bytesPerPixel * width); 122 125 srcPtr += srcPitch; 123 126 dstPtr += dstPitch; 124 127 } … … 129 132 * Trivial nearest-neighbour 2x scaler. 130 133 */ 131 134 void Normal2x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, 132 int width, int height ) {135 int width, int height, uint8 bytesPerPixel) { 133 136 uint8 *r; 137 const uint8 *s; 134 138 135 139 assert(((long)dstPtr & 3) == 0); 140 width *= bytesPerPixel; 136 141 while (height--) { 137 142 r = dstPtr; 138 for (int i = 0; i < width; ++i, r += 4) { 139 uint32 color = *(((const uint16 *)srcPtr) + i); 140 141 color |= color << 16; 142 143 *(uint32 *)(r) = color; 144 *(uint32 *)(r + dstPitch) = color; 143 for (int i = 0; i < width; i += bytesPerPixel, r += (bytesPerPixel * 2)) { 144 s = srcPtr + i; 145 memcpy(r, s, bytesPerPixel); 146 memcpy(r + bytesPerPixel, s, bytesPerPixel); 147 memcpy(r + dstPitch, s, bytesPerPixel); 148 memcpy(r + dstPitch + bytesPerPixel, s, bytesPerPixel); 145 149 } 146 150 srcPtr += srcPitch; 147 151 dstPtr += dstPitch << 1; … … 152 156 * Trivial nearest-neighbour 3x scaler. 153 157 */ 154 158 void Normal3x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, 155 int width, int height ) {159 int width, int height, uint8 bytesPerPixel) { 156 160 uint8 *r; 161 const uint8 *s; 157 162 const uint32 dstPitch2 = dstPitch * 2; 158 163 const uint32 dstPitch3 = dstPitch * 3; 159 164 160 165 assert(((long)dstPtr & 1) == 0); 166 width *= bytesPerPixel; 161 167 while (height--) { 162 168 r = dstPtr; 163 for (int i = 0; i < width; ++i, r += 6) { 164 uint16 color = *(((const uint16 *)srcPtr) + i); 165 166 *(uint16 *)(r + 0) = color; 167 *(uint16 *)(r + 2) = color; 168 *(uint16 *)(r + 4) = color; 169 *(uint16 *)(r + 0 + dstPitch) = color; 170 *(uint16 *)(r + 2 + dstPitch) = color; 171 *(uint16 *)(r + 4 + dstPitch) = color; 172 *(uint16 *)(r + 0 + dstPitch2) = color; 173 *(uint16 *)(r + 2 + dstPitch2) = color; 174 *(uint16 *)(r + 4 + dstPitch2) = color; 169 for (int i = 0; i < width; i += bytesPerPixel, r += (bytesPerPixel * 3)) { 170 s = srcPtr + i; 171 memcpy(r, s, bytesPerPixel); 172 memcpy(r + bytesPerPixel, s, bytesPerPixel); 173 memcpy(r + bytesPerPixel * 2, s, bytesPerPixel); 174 memcpy(r + dstPitch, s, bytesPerPixel); 175 memcpy(r + dstPitch + bytesPerPixel, s, bytesPerPixel); 176 memcpy(r + dstPitch + bytesPerPixel * 2, s, bytesPerPixel); 177 memcpy(r + dstPitch2, s, bytesPerPixel); 178 memcpy(r + dstPitch2 + bytesPerPixel, s, bytesPerPixel); 179 memcpy(r + dstPitch2 + bytesPerPixel * 2, s, bytesPerPixel); 175 180 } 176 181 srcPtr += srcPitch; 177 182 dstPtr += dstPitch3; … … 184 189 /** 185 190 * Trivial nearest-neighbour 1.5x scaler. 186 191 */ 187 template<int bitFormat >188 void Normal1o5xTemplate(const uint8 *srcPtr, uint32 srcPitch, uint8*dstPtr, uint32 dstPitch,192 template<int bitFormat, typename T> 193 void Normal1o5xTemplate(const T *srcPtr, uint32 srcPitch, T *dstPtr, uint32 dstPitch, 189 194 int width, int height) { 190 uint8 *r; 195 dstPitch /= sizeof(T); 196 srcPitch /= sizeof(T); 197 198 T *r; 191 199 const uint32 dstPitch2 = dstPitch * 2; 192 200 const uint32 dstPitch3 = dstPitch * 3; 193 201 const uint32 srcPitch2 = srcPitch * 2; … … 195 203 assert(((long)dstPtr & 1) == 0); 196 204 while (height > 0) { 197 205 r = dstPtr; 198 for (int i = 0; i < width; i += 2, r += 6) {199 uint16 color0 = *(((const uint16 *)srcPtr)+ i);200 uint16 color1 = *(((const uint16 *)srcPtr)+ i + 1);201 uint16 color2 = *(((const uint16 *)(srcPtr + srcPitch))+ i);202 uint16 color3 = *(((const uint16 *)(srcPtr + srcPitch))+ i + 1);206 for (int i = 0; i < width; i += 1, r += 3) { 207 T color0 = *(srcPtr + i); 208 T color1 = *(srcPtr + i + 1); 209 T color2 = *(srcPtr + srcPitch + i); 210 T color3 = *(srcPtr + srcPitch + i + 1); 203 211 204 *( uint16 *)(r + 0) = color0;205 *( uint16 *)(r + 2) = interpolate32_1_1(color0, color1);206 *( uint16 *)(r + 4) = color1;207 *( uint16 *)(r + 0 + dstPitch) = interpolate32_1_1(color0, color2);208 *( uint16 *)(r + 2+ dstPitch) = interpolate32_1_1_1_1(color0, color1, color2, color3);209 *( uint16 *)(r + 4+ dstPitch) = interpolate32_1_1(color1, color3);210 *( uint16 *)(r + 0 + dstPitch2) = color2;211 *( uint16 *)(r + 2+ dstPitch2) = interpolate32_1_1(color2, color3);212 *( uint16 *)(r + 4+ dstPitch2) = color3;212 *(r + 0) = color0; 213 *(r + 1) = interpolate32_1_1(color0, color1); 214 *(r + 2) = color1; 215 *(r + 0 + dstPitch) = interpolate32_1_1(color0, color2); 216 *(r + 1 + dstPitch) = interpolate32_1_1_1_1(color0, color1, color2, color3); 217 *(r + 2 + dstPitch) = interpolate32_1_1(color1, color3); 218 *(r + 0 + dstPitch2) = color2; 219 *(r + 1 + dstPitch2) = interpolate32_1_1(color2, color3); 220 *(r + 2 + dstPitch2) = color3; 213 221 } 214 222 srcPtr += srcPitch2; 215 223 dstPtr += dstPitch3; … … 223 231 * See also http://scale2x.sourceforge.net 224 232 */ 225 233 void AdvMame2x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, 226 int width, int height ) {227 scale(2, dstPtr, dstPitch, srcPtr - srcPitch, srcPitch, 2, width, height);234 int width, int height, uint8 bytesPerPixel) { 235 scale(2, dstPtr, dstPitch, srcPtr - srcPitch, srcPitch, bytesPerPixel, width, height); 228 236 } 229 237 230 238 /** … … 232 240 * See also http://scale2x.sourceforge.net 233 241 */ 234 242 void AdvMame3x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, 235 int width, int height ) {236 scale(3, dstPtr, dstPitch, srcPtr - srcPitch, srcPitch, 2, width, height);243 int width, int height, uint8 bytesPerPixel) { 244 scale(3, dstPtr, dstPitch, srcPtr - srcPitch, srcPitch, bytesPerPixel, width, height); 237 245 } 238 246 239 template<int bitFormat >240 void TV2xTemplate(const uint8 *srcPtr, uint32 srcPitch, uint8*dstPtr, uint32 dstPitch,247 template<int bitFormat, typename T> 248 void TV2xTemplate(const T *srcPtr, uint32 srcPitch, T *dstPtr, uint32 dstPitch, 241 249 int width, int height) { 242 const uint32 nextlineSrc = srcPitch / sizeof(uint16);243 const uint16 *p = (const uint16 *)srcPtr;250 dstPitch /= sizeof(T); 251 srcPitch /= sizeof(T); 244 252 245 const uint32 nextlineDst = dstPitch / sizeof(uint16);246 uint16 *q = (uint16 *)dstPtr;247 248 253 while (height--) { 249 254 for (int i = 0, j = 0; i < width; ++i, j += 2) { 250 uint16 p1 = *(p+ i);255 T p1 = *(srcPtr + i); 251 256 uint32 pi; 252 257 253 258 pi = (((p1 & redblueMask) * 7) >> 3) & redblueMask; 254 259 pi |= (((p1 & greenMask) * 7) >> 3) & greenMask; 255 260 256 *( q+ j) = p1;257 *( q+ j + 1) = p1;258 *( q + j + nextlineDst) = (uint16)pi;259 *( q + j + nextlineDst + 1) = (uint16)pi;261 *(dstPtr + j) = p1; 262 *(dstPtr + j + 1) = p1; 263 *(dstPtr + j + dstPitch) = (T)pi; 264 *(dstPtr + j + dstPitch + 1) = (T)pi; 260 265 } 261 p += nextlineSrc;262 q += nextlineDst<< 1;266 srcPtr += srcPitch; 267 dstPtr += dstPitch << 1; 263 268 } 264 269 } 265 270 MAKE_WRAPPER(TV2x) … … 277 282 0x1CE7, 0x0000, 0x1CE7, 0x0000 278 283 }; 279 284 280 static inline uint16 DOT_16(const uint16 *dotmatrix, uint16 c, int j, int i) { 285 static const uint32 dotmatrix_8888[16] = { 286 0x00003F00, 0x0000003F, 0x001F0000, 0x00000000, 287 0x001F3F3F, 0x00000000, 0x001F3F3F, 0x00000000, 288 0x001F0000, 0x00000000, 0x00003F00, 0x0000003F, 289 0x001F3F3F, 0x00000000, 0x001F3F3F, 0x00000000 290 }; 291 292 template<typename T> 293 static inline T DOT(const T *dotmatrix, T c, int j, int i) { 281 294 return c - ((c >> 2) & *(dotmatrix + ((j & 3) << 2) + (i & 3))); 282 295 } 283 296 … … 287 300 // a way that also works together with aspect-ratio correction is left as an 288 301 // exercise for the reader.) 289 302 303 template<typename T> 304 void DotMatrix(const T *srcPtr, uint32 srcPitch, T *dstPtr, uint32 dstPitch, 305 int width, int height, const T *dotmatrix) { 306 dstPitch /= sizeof(T); 307 srcPitch /= sizeof(T); 308 309 for (int j = 0, jj = 0; j < height; ++j, jj += 2) { 310 for (int i = 0, ii = 0; i < width; ++i, ii += 2) { 311 T c = *(srcPtr + i); 312 *(dstPtr + ii) = DOT(dotmatrix, c, jj, ii); 313 *(dstPtr + ii + 1) = DOT(dotmatrix, c, jj, ii + 1); 314 *(dstPtr + ii + dstPitch) = DOT(dotmatrix, c, jj + 1, ii); 315 *(dstPtr + ii + dstPitch + 1) = DOT(dotmatrix, c, jj + 1, ii + 1); 316 } 317 srcPtr += srcPitch; 318 dstPtr += dstPitch << 1; 319 } 320 } 321 290 322 void DotMatrix(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, 291 int width, int height) { 292 293 const uint16 *dotmatrix; 323 int width, int height, uint8 bytesPerPixel) { 294 324 if (gBitFormat == 565) { 295 dotmatrix = dotmatrix_565;325 DotMatrix((uint16*) srcPtr, srcPitch, (uint16*) dstPtr, dstPitch, width, height, dotmatrix_565); 296 326 } else if (gBitFormat == 555) { 297 dotmatrix = dotmatrix_555; 327 DotMatrix((uint16*) srcPtr, srcPitch, (uint16*) dstPtr, dstPitch, width, height, dotmatrix_555); 328 } else if (gBitFormat == 8888) { 329 if (bytesPerPixel == 4) 330 DotMatrix((uint32*) srcPtr, srcPitch, (uint32*) dstPtr, dstPitch, width, height, dotmatrix_8888); 331 else 332 DotMatrix((uint16*) srcPtr, srcPitch, (uint16*) dstPtr, dstPitch, width, height, dotmatrix_565); 298 333 } else { 299 334 error("Unknown bit format %d", gBitFormat); 300 335 } 301 302 const uint32 nextlineSrc = srcPitch / sizeof(uint16);303 const uint16 *p = (const uint16 *)srcPtr;304 305 const uint32 nextlineDst = dstPitch / sizeof(uint16);306 uint16 *q = (uint16 *)dstPtr;307 308 for (int j = 0, jj = 0; j < height; ++j, jj += 2) {309 for (int i = 0, ii = 0; i < width; ++i, ii += 2) {310 uint16 c = *(p + i);311 *(q + ii) = DOT_16(dotmatrix, c, jj, ii);312 *(q + ii + 1) = DOT_16(dotmatrix, c, jj, ii + 1);313 *(q + ii + nextlineDst) = DOT_16(dotmatrix, c, jj + 1, ii);314 *(q + ii + nextlineDst + 1) = DOT_16(dotmatrix, c, jj + 1, ii + 1);315 }316 p += nextlineSrc;317 q += nextlineDst << 1;318 }319 336 } 320 337 321 338 #endif -
graphics/scaler.h
29 29 extern void InitScalers(uint32 BitFormat); 30 30 31 31 typedef void ScalerProc(const uint8 *srcPtr, uint32 srcPitch, 32 uint8 *dstPtr, uint32 dstPitch, int width, int height );32 uint8 *dstPtr, uint32 dstPitch, int width, int height, uint8 bytesPerPixel = 2); 33 33 34 34 #define DECLARE_SCALER(x) \ 35 35 extern void x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, \ 36 uint32 dstPitch, int width, int height )36 uint32 dstPitch, int width, int height, uint8 bytesPerPixel = 2) 37 37 38 38 DECLARE_SCALER(_2xSaI); 39 39 DECLARE_SCALER(Super2xSaI); … … 62 62 63 63 extern void makeRectStretchable(int &x, int &y, int &w, int &h); 64 64 65 extern int stretch200To240(uint8 *buf, uint32 pitch, int width, int height, int srcX, int srcY, int origSrcY );65 extern int stretch200To240(uint8 *buf, uint32 pitch, int width, int height, int srcX, int srcY, int origSrcY, uint8 bytesPerPixel = 2); 66 66 67 67 // creates a 160x100 thumbnail for 320x200 games 68 68 // and 160x120 thumbnail for 320x240 and 640x480 games -
graphics/colormasks.h
172 172 template<> 173 173 struct ColorMasks<888> { 174 174 enum { 175 highBits = 0x00FEFEFE, 176 lowBits = 0x00010101, 177 qhighBits = 0x00FCFCFC, 178 qlowBits = 0x00030303, 175 179 kBytesPerPixel = 4, 176 180 177 181 kAlphaBits = 0, … … 196 200 template<> 197 201 struct ColorMasks<8888> { 198 202 enum { 203 highBits = 0xFEFEFEFE, 204 lowBits = 0x01010101, 205 qhighBits = 0xFCFCFCFC, 206 qlowBits = 0x03030303, 199 207 kBytesPerPixel = 4, 200 208 201 209 kAlphaBits = 8, -
graphics/scaler/intern.h
46 46 static inline uint32 interpolate32_1_1(uint32 A, uint32 B) { 47 47 return (((A & highBits) >> 1) + ((B & highBits) >> 1) + (A & B & lowBits)); 48 48 } 49 /** 50 * Interpolate two 32 bit pixels with equal weights 1. 51 */ 52 template<> 53 static inline uint32 interpolate32_1_1<8888>(uint32 A, uint32 B) { 54 return ((A & 0xFEFEFEFE) >> 1) + ((B & 0xFEFEFEFE) >> 1) + (A & B & 0x01010101); 55 } 49 56 50 57 /** 51 58 * Interpolate two 16 bit pixel *pairs* at once with weights 3 resp. 1. … … 60 67 y &= qlowBits; 61 68 return x + y; 62 69 } 70 /** 71 * Interpolate two 32 bit pixels with weights 3 resp. 1. 72 */ 73 template<> 74 static inline uint32 interpolate32_3_1<8888>(uint32 A, uint32 B) { 75 register uint32 x = ((A & 0xFCFCFCFC) >> 2) * 3 + ((B & 0xFCFCFCFC) >> 2); 76 register uint32 y = ((A & 0x03030303) * 3 + (B & 0x03030303)) >> 2; 63 77 78 y &= 0x03030303; 79 return x + y; 80 } 81 82 64 83 /** 65 84 * Interpolate four 16 bit pixel pairs at once with equal weights 1. 66 85 * In particular, A and B can contain two pixels/each in the upper … … 74 93 y &= qlowBits; 75 94 return x + y; 76 95 } 96 /** 97 * Interpolate four 32 bit pixels with equal weights 1. 98 */ 99 template<> 100 static inline uint32 interpolate32_1_1_1_1<8888>(uint32 A, uint32 B, uint32 C, uint32 D) { 101 register uint32 x = ((A & 0xFCFCFCFC) >> 2) + ((B & 0xFCFCFCFC) >> 2) + 102 ((C & 0xFCFCFCFC) >> 2) + ((D & 0xFCFCFCFC) >> 2); 103 register uint32 y = ((A & 0x03030303) + (B & 0x03030303) + 104 (C & 0x03030303) + (D & 0x03030303)) >> 2; 77 105 106 y &= 0x03030303; 107 return x + y; 108 } 78 109 110 79 111 /** 80 112 * Interpolate two 16 bit pixels with the weights specified in the template 81 113 * parameters. Used by the hq scaler family. 82 114 * @note w1 and w2 must sum up to 2, 4, 8 or 16. 83 115 */ 84 116 template<int bitFormat, int w1, int w2> 85 static inline uint 16 interpolate16_2(uint16 p1, uint16p2) {117 static inline uint32 interpolate16_2(uint32 p1, uint32 p2) { 86 118 return ((((p1 & redblueMask) * w1 + (p2 & redblueMask) * w2) / (w1 + w2)) & redblueMask) | 87 119 ((((p1 & greenMask) * w1 + (p2 & greenMask) * w2) / (w1 + w2)) & greenMask); 88 120 } 121 /** 122 * Interpolate two 32 bit pixels with the weights specified in the template 123 * parameters. Used by the hq scaler family. 124 * @note w1 and w2 must sum up to 2, 4, 8 or 16. 125 */ 126 template<> 127 static inline uint32 interpolate16_2<8888, 1, 1>(uint32 p1, uint32 p2) { 128 return ((((p1 & 0xFF00FF) * 1 + (p2 & 0xFF00FF) * 1) / (1 + 1)) & 0xFF00FF) | 129 ((((p1 & 0x00FF00) * 1 + (p2 & 0x00FF00) * 1) / (1 + 1)) & 0x00FF00); 130 } 131 template<> 132 static inline uint32 interpolate16_2<8888, 3, 1>(uint32 p1, uint32 p2) { 133 return ((((p1 & 0xFF00FF) * 3 + (p2 & 0xFF00FF) * 1) / (3 + 1)) & 0xFF00FF) | 134 ((((p1 & 0x00FF00) * 3 + (p2 & 0x00FF00) * 1) / (3 + 1)) & 0x00FF00); 135 } 89 136 137 90 138 /** 91 139 * Interpolate three 16 bit pixels with the weights specified in the template 92 140 * parameters. Used by the hq scaler family. 93 141 * @note w1, w2 and w3 must sum up to 2, 4, 8 or 16. 94 142 */ 95 143 template<int bitFormat, int w1, int w2, int w3> 96 static inline uint 16 interpolate16_3(uint16 p1, uint16 p2, uint16p3) {144 static inline uint32 interpolate16_3(uint32 p1, uint32 p2, uint32 p3) { 97 145 return ((((p1 & redblueMask) * w1 + (p2 & redblueMask) * w2 + (p3 & redblueMask) * w3) / (w1 + w2 + w3)) & redblueMask) | 98 146 ((((p1 & greenMask) * w1 + (p2 & greenMask) * w2 + (p3 & greenMask) * w3) / (w1 + w2 + w3)) & greenMask); 99 147 } 148 /** 149 * Interpolate three 32 bit pixels with the weights specified in the template 150 * parameters. Used by the hq scaler family. 151 */ 152 template<> 153 static inline uint32 interpolate16_3<8888, 6, 1, 1>(uint32 p1, uint32 p2, uint32 p3) { 154 return ((((p1 & 0xFF00FF) * 6 + (p2 & 0xFF00FF) * 1 + (p3 & 0xFF00FF) * 1) / (6 + 1 + 1)) & 0xFF00FF) | 155 ((((p1 & 0x00FF00) * 6 + (p2 & 0x00FF00) * 1 + (p3 & 0x00FF00) * 1) / (6 + 1 + 1)) & 0x00FF00); 156 } 100 157 101 158 102 159 /** … … 146 203 147 204 /** Auxiliary macro to simplify creating those template function wrappers. */ 148 205 #define MAKE_WRAPPER(FUNC) \ 149 void FUNC(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) { \ 150 if (gBitFormat == 565) \ 151 FUNC ## Template<565>(srcPtr, srcPitch, dstPtr, dstPitch, width, height); \ 206 void FUNC(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height, uint8 bytesPerPixel) { \ 207 if (gBitFormat == 8888) { \ 208 if (bytesPerPixel == 4) \ 209 FUNC ## Template<8888>((uint32*) srcPtr, srcPitch, (uint32*) dstPtr, dstPitch, width, height); \ 210 else \ 211 FUNC ## Template<565>((uint16*) srcPtr, srcPitch, (uint16*) dstPtr, dstPitch, width, height); \ 212 } \ 213 else if (gBitFormat == 565) \ 214 FUNC ## Template<565>((uint16*) srcPtr, srcPitch, (uint16*) dstPtr, dstPitch, width, height); \ 152 215 else \ 153 FUNC ## Template<555>( srcPtr, srcPitch,dstPtr, dstPitch, width, height); \216 FUNC ## Template<555>((uint16*) srcPtr, srcPitch, (uint16*) dstPtr, dstPitch, width, height); \ 154 217 } 155 218 156 /** Specifies the currently active 16bit pixel format, 555 or 565. */ 219 220 /** Specifies the currently active pixel format, 555, 565 or 8888. */ 157 221 extern int gBitFormat; 158 222 159 223 #endif -
graphics/scaler/aspect.cpp
34 34 35 35 #if ASPECT_MODE == kSlowAndPerfectAspectMode 36 36 37 template<int bitFormat, int scale >38 static inline uint16 interpolate5(uint16 A, uint16B) {39 uint16 r = (uint16)(((A & redblueMask & 0xFF00) * scale + (B & redblueMask & 0xFF00) * (5 - scale)) / 5);40 uint16 g = (uint16)(((A & greenMask) * scale + (B & greenMask) * (5 - scale)) / 5);41 uint16 b = (uint16)(((A & redblueMask & 0x00FF) * scale + (B & redblueMask & 0x00FF) * (5 - scale)) / 5);37 template<int bitFormat, int scale, typename T> 38 static inline T interpolate5(T A, T B) { 39 T r = (T)(((A & redblueMask & 0xFF00) * scale + (B & redblueMask & 0xFF00) * (5 - scale)) / 5); 40 T g = (T)(((A & greenMask) * scale + (B & greenMask) * (5 - scale)) / 5); 41 T b = (T)(((A & redblueMask & 0x00FF) * scale + (B & redblueMask & 0x00FF) * (5 - scale)) / 5); 42 42 43 return ( uint16)((r & redblueMask & 0xFF00) | (g & greenMask) | (b & redblueMask & 0x00FF));43 return (T)((r & redblueMask & 0xFF00) | (g & greenMask) | (b & redblueMask & 0x00FF)); 44 44 } 45 template<> 46 static inline uint32 interpolate5<8888, 1>(uint32 A, uint32 B) { 47 uint32 r = (uint32)(((A & 0xFF00FF & 0xFFFF0000) * 1 + (B & 0xFF00FF & 0xFFFF0000) * (5 - 1)) / 5); 48 uint32 g = (uint32)(((A & 0x00FF00) * 1 + (B & 0x00FF00) * (5 - 1)) / 5); 49 uint32 b = (uint32)(((A & 0xFF00FF & 0x0000FFFF) * 1 + (B & 0xFF00FF & 0x0000FFFF) * (5 - 1)) / 5); 45 50 51 return (uint32)((r & 0xFF00FF & 0xFFFF0000) | (g & 0x00FF00) | (b & 0xFF00FF & 0x0000FFFF)); 52 } 53 template<> 54 static inline uint32 interpolate5<8888, 2>(uint32 A, uint32 B) { 55 uint32 r = (uint32)(((A & 0xFF00FF & 0xFFFF0000) * 2 + (B & 0xFF00FF & 0xFFFF0000) * (5 - 2)) / 5); 56 uint32 g = (uint32)(((A & 0x00FF00) * 2 + (B & 0x00FF00) * (5 - 2)) / 5); 57 uint32 b = (uint32)(((A & 0xFF00FF & 0x0000FFFF) * 2 + (B & 0xFF00FF & 0x0000FFFF) * (5 - 2)) / 5); 46 58 47 template<int bitFormat, int scale> 48 static inline void interpolate5Line(uint16 *dst, const uint16 *srcA, const uint16 *srcB, int width) { 59 return (uint32)((r & 0xFF00FF & 0xFFFF0000) | (g & 0x00FF00) | (b & 0xFF00FF & 0x0000FFFF)); 60 } 61 62 63 template<int bitFormat, int scale, typename T> 64 static inline void interpolate5Line(T *dst, const T *srcA, const T *srcB, int width) { 49 65 // Accurate but slightly slower code 50 66 while (width--) { 51 67 *dst++ = interpolate5<bitFormat, scale>(*srcA++, *srcB++); … … 55 71 56 72 #if ASPECT_MODE == kFastAndNiceAspectMode 57 73 58 template<int bitFormat, int scale >59 static inline void interpolate5Line( uint16 *dst, const uint16 *srcA, const uint16*srcB, int width) {74 template<int bitFormat, int scale, typename T> 75 static inline void interpolate5Line(T *dst, const T *srcA, const T *srcB, int width) { 60 76 // For efficiency reasons we blit two pixels at a time, so it is important 61 77 // that makeRectStretchable() guarantees that the width is even and that 62 78 // the rect starts on a well-aligned address. (Even where unaligned memory … … 84 100 } 85 101 } 86 102 } 103 template<> 104 static inline void interpolate5Line<8888, 1>(uint32 *dst, const uint32 *srcA, const uint32 *srcB, int width) { 105 while (width--) 106 *dst++ = interpolate32_3_1<8888>(*srcB++, *srcA++); 107 } 108 template<> 109 static inline void interpolate5Line<8888, 2>(uint32 *dst, const uint32 *srcA, const uint32 *srcB, int width) { 110 while (width--) 111 *dst++ = interpolate32_1_1<8888>(*srcB++, *srcA++); 112 } 87 113 #endif 88 114 89 115 void makeRectStretchable(int &x, int &y, int &w, int &h) { … … 131 157 * srcY + height - 1, and it should be stretched to Y coordinates srcY 132 158 * through real2Aspect(srcY + height - 1). 133 159 */ 134 template<int bitFormat> 135 int stretch200To240(uint8 *buf, uint32 pitch, int width, int height, int srcX, int srcY, int origSrcY) { 160 template<int bitFormat, typename T> 161 int stretch200To240(T *buf, uint32 pitch, int width, int height, int srcX, int srcY, int origSrcY) { 162 pitch /= sizeof(T); 163 136 164 int maxDstY = real2Aspect(origSrcY + height - 1); 137 165 int y; 138 const uint8 *startSrcPtr = buf + srcX * 2+ (srcY - origSrcY) * pitch;139 uint8 *dstPtr = buf + srcX * 2+ maxDstY * pitch;166 const T *startSrcPtr = buf + srcX + (srcY - origSrcY) * pitch; 167 T *dstPtr = buf + srcX + maxDstY * pitch; 140 168 141 169 for (y = maxDstY; y >= srcY; y--) { 142 const uint8*srcPtr = startSrcPtr + aspect2Real(y) * pitch;170 const T *srcPtr = startSrcPtr + aspect2Real(y) * pitch; 143 171 144 172 #if ASPECT_MODE == kVeryFastAndUglyAspectMode 145 173 if (srcPtr == dstPtr) 146 174 break; 147 memcpy(dstPtr, srcPtr, width * 2);175 memcpy(dstPtr, srcPtr, width * sizeof(T)); 148 176 #else 149 177 // Bilinear filter 150 178 switch (y % 6) { 151 179 case 0: 152 180 case 5: 153 181 if (srcPtr != dstPtr) 154 memcpy(dstPtr, srcPtr, width * 2);182 memcpy(dstPtr, srcPtr, width * sizeof(T)); 155 183 break; 156 184 case 1: 157 interpolate5Line<bitFormat, 1>( (uint16 *)dstPtr, (const uint16 *)(srcPtr - pitch), (const uint16 *)srcPtr, width);185 interpolate5Line<bitFormat, 1>(dstPtr, srcPtr - pitch, srcPtr, width); 158 186 break; 159 187 case 2: 160 interpolate5Line<bitFormat, 2>( (uint16 *)dstPtr, (const uint16 *)(srcPtr - pitch), (const uint16 *)srcPtr, width);188 interpolate5Line<bitFormat, 2>(dstPtr, srcPtr - pitch, srcPtr, width); 161 189 break; 162 190 case 3: 163 interpolate5Line<bitFormat, 2>( (uint16 *)dstPtr, (const uint16 *)srcPtr, (const uint16 *)(srcPtr - pitch), width);191 interpolate5Line<bitFormat, 2>(dstPtr, srcPtr, srcPtr - pitch, width); 164 192 break; 165 193 case 4: 166 interpolate5Line<bitFormat, 1>( (uint16 *)dstPtr, (const uint16 *)srcPtr, (const uint16 *)(srcPtr - pitch), width);194 interpolate5Line<bitFormat, 1>(dstPtr, srcPtr, srcPtr - pitch, width); 167 195 break; 168 196 } 169 197 #endif … … 173 201 return 1 + maxDstY - srcY; 174 202 } 175 203 176 int stretch200To240(uint8 *buf, uint32 pitch, int width, int height, int srcX, int srcY, int origSrcY) { 177 if (gBitFormat == 565) 178 return stretch200To240<565>(buf, pitch, width, height, srcX, srcY, origSrcY); 204 int stretch200To240(uint8 *buf, uint32 pitch, int width, int height, int srcX, int srcY, int origSrcY, uint8 bytesPerPixel) { 205 if (gBitFormat == 8888) { 206 if (bytesPerPixel == 4) 207 return stretch200To240<8888>((uint32*) buf, pitch, width, height, srcX, srcY, origSrcY); 208 else 209 return stretch200To240<565>((uint16*) buf, pitch, width, height, srcX, srcY, origSrcY); 210 } 211 else if (gBitFormat == 565) 212 return stretch200To240<565>((uint16*) buf, pitch, width, height, srcX, srcY, origSrcY); 179 213 else // gBitFormat == 555 180 return stretch200To240<555>( buf, pitch, width, height, srcX, srcY, origSrcY);214 return stretch200To240<555>((uint16*) buf, pitch, width, height, srcX, srcY, origSrcY); 181 215 } 182 216 -
graphics/scaler/hq2x.cpp
36 36 37 37 } 38 38 39 void HQ2x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height ) {39 void HQ2x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height, uint8 bytesPerPixel) { 40 40 hq2x_16(srcPtr, dstPtr, width, height, srcPitch, dstPitch); 41 41 } 42 42 … … 110 110 #undef bitFormat 111 111 112 112 113 void HQ2x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height ) {113 void HQ2x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height, uint8 bytesPerPixel) { 114 114 if (gBitFormat == 565) 115 115 HQ2x_565(srcPtr, srcPitch, dstPtr, dstPitch, width, height); 116 116 else -
graphics/scaler/hq3x.cpp
37 37 38 38 } 39 39 40 void HQ3x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height ) {40 void HQ3x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height, uint8 bytesPerPixel) { 41 41 hq3x_16(srcPtr, dstPtr, width, height, srcPitch, dstPitch); 42 42 } 43 43 … … 113 113 #undef bitFormat 114 114 115 115 116 void HQ3x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height ) {116 void HQ3x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height, uint8 bytesPerPixel) { 117 117 if (gBitFormat == 565) 118 118 HQ3x_565(srcPtr, srcPitch, dstPtr, dstPitch, width, height); 119 119 else -
graphics/scaler/2xsai.cpp
49 49 #define interpolate_6_1_1 interpolate16_3<bitFormat, 6, 1, 1> 50 50 #define interpolate_1_1_1_1 interpolate32_1_1_1_1<bitFormat> 51 51 52 template<int bitFormat> 53 void Super2xSaITemplate(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) { 54 const uint16 *bP; 55 uint16 *dP; 56 const uint32 nextlineSrc = srcPitch >> 1; 52 template<int bitFormat, typename T> 53 void Super2xSaITemplate(const T *srcPtr, uint32 srcPitch, T *dstPtr, uint32 dstPitch, int width, int height) { 54 const T *bP; 55 T *dP; 57 56 57 dstPitch /= sizeof(T); 58 srcPitch /= sizeof(T); 59 58 60 while (height--) { 59 bP = (const uint16*)srcPtr;60 dP = ( uint16*)dstPtr;61 bP = (const T *)srcPtr; 62 dP = (T *)dstPtr; 61 63 62 64 for (int i = 0; i < width; ++i) { 63 65 uint32 color4, color5, color6; … … 72 74 // 1 2 3 S1 73 75 // A1 A2 74 76 75 colorB0 = *(bP - nextlineSrc- 1);76 colorB1 = *(bP - nextlineSrc);77 colorB2 = *(bP - nextlineSrc+ 1);78 colorB3 = *(bP - nextlineSrc+ 2);77 colorB0 = *(bP - srcPitch - 1); 78 colorB1 = *(bP - srcPitch); 79 colorB2 = *(bP - srcPitch + 1); 80 colorB3 = *(bP - srcPitch + 2); 79 81 80 82 color4 = *(bP - 1); 81 83 color5 = *(bP); 82 84 color6 = *(bP + 1); 83 85 colorS2 = *(bP + 2); 84 86 85 color1 = *(bP + nextlineSrc- 1);86 color2 = *(bP + nextlineSrc);87 color3 = *(bP + nextlineSrc+ 1);88 colorS1 = *(bP + nextlineSrc+ 2);87 color1 = *(bP + srcPitch - 1); 88 color2 = *(bP + srcPitch); 89 color3 = *(bP + srcPitch + 1); 90 colorS1 = *(bP + srcPitch + 2); 89 91 90 colorA0 = *(bP + 2 * nextlineSrc- 1);91 colorA1 = *(bP + 2 * nextlineSrc);92 colorA2 = *(bP + 2 * nextlineSrc+ 1);93 colorA3 = *(bP + 2 * nextlineSrc+ 2);92 colorA0 = *(bP + 2 * srcPitch - 1); 93 colorA1 = *(bP + 2 * srcPitch); 94 colorA2 = *(bP + 2 * srcPitch + 1); 95 colorA3 = *(bP + 2 * srcPitch + 2); 94 96 95 97 //-------------------------------------- 96 98 if (color2 == color6 && color5 != color3) { … … 142 144 else 143 145 product1a = color5; 144 146 145 *(dP + 0) = ( uint16) product1a;146 *(dP + 1) = ( uint16) product1b;147 *(dP + dstPitch /2 + 0) = (uint16) product2a;148 *(dP + dstPitch /2 + 1) = (uint16) product2b;147 *(dP + 0) = (T) product1a; 148 *(dP + 1) = (T) product1b; 149 *(dP + dstPitch + 0) = (T) product2a; 150 *(dP + dstPitch + 1) = (T) product2b; 149 151 150 152 bP += 1; 151 153 dP += 2; … … 158 160 159 161 MAKE_WRAPPER(Super2xSaI) 160 162 161 template<int bitFormat> 162 void SuperEagleTemplate(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) { 163 const uint16 *bP; 164 uint16 *dP; 165 const uint32 nextlineSrc = srcPitch >> 1; 163 template<int bitFormat, typename T> 164 void SuperEagleTemplate(const T *srcPtr, uint32 srcPitch, T *dstPtr, uint32 dstPitch, int width, int height) { 165 const T *bP; 166 T *dP; 166 167 168 dstPitch /= sizeof(T); 169 srcPitch /= sizeof(T); 170 167 171 while (height--) { 168 bP = (const uint16*)srcPtr;169 dP = ( uint16*)dstPtr;172 bP = (const T *)srcPtr; 173 dP = (T *)dstPtr; 170 174 for (int i = 0; i < width; ++i) { 171 175 uint32 color4, color5, color6; 172 176 uint32 color1, color2, color3; 173 177 uint32 colorA1, colorA2, colorB1, colorB2, colorS1, colorS2; 174 178 uint32 product1a, product1b, product2a, product2b; 175 179 176 colorB1 = *(bP - nextlineSrc);177 colorB2 = *(bP - nextlineSrc+ 1);180 colorB1 = *(bP - srcPitch); 181 colorB2 = *(bP - srcPitch + 1); 178 182 179 183 color4 = *(bP - 1); 180 184 color5 = *(bP); 181 185 color6 = *(bP + 1); 182 186 colorS2 = *(bP + 2); 183 187 184 color1 = *(bP + nextlineSrc- 1);185 color2 = *(bP + nextlineSrc);186 color3 = *(bP + nextlineSrc+ 1);187 colorS1 = *(bP + nextlineSrc+ 2);188 color1 = *(bP + srcPitch - 1); 189 color2 = *(bP + srcPitch); 190 color3 = *(bP + srcPitch + 1); 191 colorS1 = *(bP + srcPitch + 2); 188 192 189 colorA1 = *(bP + 2 * nextlineSrc);190 colorA2 = *(bP + 2 * nextlineSrc+ 1);193 colorA1 = *(bP + 2 * srcPitch); 194 colorA2 = *(bP + 2 * srcPitch + 1); 191 195 192 196 // -------------------------------------- 193 197 if (color5 != color3) { … … 247 251 } 248 252 } 249 253 250 *(dP + 0) = ( uint16) product1a;251 *(dP + 1) = ( uint16) product1b;252 *(dP + dstPitch /2 + 0) = (uint16) product2a;253 *(dP + dstPitch /2 + 1) = (uint16) product2b;254 *(dP + 0) = (T) product1a; 255 *(dP + 1) = (T) product1b; 256 *(dP + dstPitch + 0) = (T) product2a; 257 *(dP + dstPitch + 1) = (T) product2b; 254 258 255 259 bP += 1; 256 260 dP += 2; … … 263 267 264 268 MAKE_WRAPPER(SuperEagle) 265 269 266 template<int bitFormat> 267 void _2xSaITemplate(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) { 268 const uint16 *bP; 269 uint16 *dP; 270 const uint32 nextlineSrc = srcPitch >> 1; 270 template<int bitFormat, typename T> 271 void _2xSaITemplate(const T *srcPtr, uint32 srcPitch, T *dstPtr, uint32 dstPitch, int width, int height) { 272 const T *bP; 273 T *dP; 271 274 275 dstPitch /= sizeof(T); 276 srcPitch /= sizeof(T); 277 272 278 while (height--) { 273 bP = (const uint16*)srcPtr;274 dP = ( uint16*)dstPtr;279 bP = (const T *)srcPtr; 280 dP = (T *)dstPtr; 275 281 276 282 for (int i = 0; i < width; ++i) { 277 283 … … 285 291 // G|A B|K 286 292 // H|C D|L 287 293 // M|N O|P 288 colorI = *(bP - nextlineSrc- 1);289 colorE = *(bP - nextlineSrc);290 colorF = *(bP - nextlineSrc+ 1);291 colorJ = *(bP - nextlineSrc+ 2);294 colorI = *(bP - srcPitch - 1); 295 colorE = *(bP - srcPitch); 296 colorF = *(bP - srcPitch + 1); 297 colorJ = *(bP - srcPitch + 2); 292 298 293 299 colorG = *(bP - 1); 294 300 colorA = *(bP); 295 301 colorB = *(bP + 1); 296 302 colorK = *(bP + 2); 297 303 298 colorH = *(bP + nextlineSrc- 1);299 colorC = *(bP + nextlineSrc);300 colorD = *(bP + nextlineSrc+ 1);301 colorL = *(bP + nextlineSrc+ 2);304 colorH = *(bP + srcPitch - 1); 305 colorC = *(bP + srcPitch); 306 colorD = *(bP + srcPitch + 1); 307 colorL = *(bP + srcPitch + 2); 302 308 303 colorM = *(bP + 2 * nextlineSrc- 1);304 colorN = *(bP + 2 * nextlineSrc);305 colorO = *(bP + 2 * nextlineSrc+ 1);306 colorP = *(bP + 2 * nextlineSrc+ 2);309 colorM = *(bP + 2 * srcPitch - 1); 310 colorN = *(bP + 2 * srcPitch); 311 colorO = *(bP + 2 * srcPitch + 1); 312 colorP = *(bP + 2 * srcPitch + 2); 307 313 308 314 if ((colorA == colorD) && (colorB != colorC)) { 309 315 if (((colorA == colorE) && (colorB == colorL)) || … … 383 389 } 384 390 } 385 391 386 *(dP + 0) = ( uint16) colorA;387 *(dP + 1) = ( uint16) product;388 *(dP + dstPitch /2 + 0) = (uint16) product1;389 *(dP + dstPitch /2 + 1) = (uint16) product2;392 *(dP + 0) = (T) colorA; 393 *(dP + 1) = (T) product; 394 *(dP + dstPitch + 0) = (T) product1; 395 *(dP + dstPitch + 1) = (T) product2; 390 396 391 397 bP += 1; 392 398 dP += 2;