Ticket #8792: float-scaler-fixed.patch
File float-scaler-fixed.patch, 12.5 KB (added by , 16 years ago) |
---|
-
common/scummsys.h
441 441 typedef unsigned short uint16; 442 442 typedef signed short int16; 443 443 444 444 445 #ifdef SCUMMVM_USE_LONG_INT 445 446 typedef unsigned long uint32; 446 447 typedef signed long int32; … … 453 454 #endif 454 455 455 456 457 #ifndef DISABLE_FLOAT_SCALER 458 typedef float scale_t; 459 #else 460 typedef int scale_t; 461 #endif 456 462 457 463 // 458 464 // Overlay color type (FIXME: shouldn't be declared here) -
graphics/scaler.cpp
320 320 } 321 321 } 322 322 323 #ifndef DISABLE_FLOAT_SCALER 324 325 float gScale; 326 void UserScaler(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, 327 int width, int height) { 328 329 float scale = gScale; 330 if (scale <= 0.0f || scale > 3.0f) 331 scale = 1.0f; 332 333 for (int y = 0; y < height; y++) { 334 for (int x = 0; x < width; x++) { 335 int xMin, yMin; 336 uint16 pixel = *((uint16 *)(srcPtr + srcPitch * y) + x); 337 // calculate the point where this pixel would be on a scalar coordinate system 338 xMin = x * scale; 339 yMin = y * scale; 340 341 #define DESTOF(a, b, c) do { *(uint16 *)((dstPtr + (dstPitch * (b)) + (a)*2)) = pixel; } while (0) 342 DESTOF(xMin, yMin, pixel); 343 if (scale > 1.0) { 344 DESTOF(xMin + 1, yMin, pixel); 345 DESTOF(xMin, yMin + 1, pixel); 346 DESTOF(xMin + 1, yMin + 1, pixel); 347 if (scale > 2.0 && x < width - 1 && y < height - 1) { 348 DESTOF(xMin + 2, yMin, pixel); 349 DESTOF(xMin + 2, yMin + 1, pixel); 350 DESTOF(xMin + 2, yMin + 2, pixel); 351 DESTOF(xMin + 1, yMin + 2, pixel); 352 DESTOF(xMin, yMin + 2, pixel); 353 } 354 } 355 } 356 } 357 } 358 #endif // DISABLE_FLOAT_SCALER 359 323 360 #endif -
graphics/scaler.h
48 48 DECLARE_SCALER(Normal1o5x); 49 49 DECLARE_SCALER(TV2x); 50 50 DECLARE_SCALER(DotMatrix); 51 DECLARE_SCALER(UserScaler); 51 52 52 53 #ifndef DISABLE_HQ_SCALERS 53 54 DECLARE_SCALER(HQ2x); -
backends/platform/sdl/graphics.cpp
30 30 #include "graphics/scaler.h" 31 31 #include "graphics/surface.h" 32 32 33 #ifndef DISABLE_FLOAT_SCALER 34 #include "common/config-manager.h" 35 #include "common/singleton.h" 36 extern float gScale; // from scaler.cpp 37 #endif 38 33 39 static const OSystem::GraphicsMode s_supportedGraphicsModes[] = { 34 40 {"1x", "Normal (no scaling)", GFX_NORMAL}, 35 41 {"2x", "2x", GFX_DOUBLESIZE}, … … 45 51 #endif 46 52 {"tv2x", "TV2x", GFX_TV2X}, 47 53 {"dotmatrix", "DotMatrix", GFX_DOTMATRIX}, 54 {"user", "User defined float scaling", GFX_FLOAT}, 48 55 {0, 0, 0} 49 56 }; 50 57 … … 70 77 { GFX_NORMAL, GFX_SUPER2XSAI, -1, -1 }, 71 78 { GFX_NORMAL, GFX_SUPEREAGLE, -1, -1 }, 72 79 { GFX_NORMAL, GFX_TV2X, -1, -1 }, 73 { GFX_NORMAL, GFX_DOTMATRIX, -1, -1 } 80 { GFX_NORMAL, GFX_DOTMATRIX, -1, -1 }, 81 { GFX_NORMAL, GFX_FLOAT, -1, -1 } 74 82 }; 75 83 76 84 #ifndef DISABLE_SCALERS … … 147 155 bool OSystem_SDL::setGraphicsMode(int mode) { 148 156 Common::StackLock lock(_graphicsMutex); 149 157 150 int newScaleFactor = 1;158 scale_t newScaleFactor = 1; 151 159 ScalerProc *newScalerProc; 160 #ifndef DISABLE_FLOAT_SCALER 161 float f; 162 Common::String s; 163 #endif 152 164 153 165 switch(mode) { 154 166 case GFX_NORMAL: … … 203 215 newScaleFactor = 2; 204 216 newScalerProc = DotMatrix; 205 217 break; 218 #ifndef DISABLE_FLOAT_SCALER 219 case GFX_FLOAT: 220 s = Common::Singleton<Common::ConfigManager>::instance().get("gfx_scale"); 221 f = atof(s.c_str()); 222 if (f > 0.0f && f <= 3.0f) { 223 newScaleFactor = f; 224 gScale = f; 225 } else { 226 newScaleFactor = 1.0f; 227 gScale = 1.0f; 228 } 229 newScalerProc = UserScaler; 230 break; 231 #endif // DISABLE_FLOAT_SCALER 206 232 #endif // DISABLE_SCALERS 207 233 208 234 default: … … 314 340 int hwW, hwH; 315 341 316 342 #ifndef __MAEMO__ 317 _overlayWidth = _screenWidth * _scaleFactor;318 _overlayHeight = _screenHeight * _scaleFactor;343 _overlayWidth = (int)(_screenWidth * _scaleFactor); 344 _overlayHeight = (int)(_screenHeight * _scaleFactor); 319 345 320 346 if (_screenHeight != 200 && _screenHeight != 400) 321 347 _adjustAspectRatio = false; … … 323 349 if (_adjustAspectRatio) 324 350 _overlayHeight = real2Aspect(_overlayHeight); 325 351 326 hwW = _screenWidth * _scaleFactor;352 hwW = (int)(_screenWidth * _scaleFactor); 327 353 hwH = effectiveScreenHeight(); 328 354 #else 329 355 hwW = _overlayWidth; … … 421 447 #endif 422 448 423 449 // keyboard cursor control, some other better place for it? 424 _km.x_max = _screenWidth * _scaleFactor - 1;450 _km.x_max = (int)(_screenWidth * _scaleFactor - 1); 425 451 _km.y_max = effectiveScreenHeight() - 1; 426 452 _km.delay_time = 25; 427 453 _km.last_time = 0; … … 517 543 SDL_Surface *srcSurf, *origSurf; 518 544 int height, width; 519 545 ScalerProc *scalerProc; 520 int scale1;546 scale_t scale1; 521 547 522 548 #if defined (DEBUG) && ! defined(_WIN32_WCE) // definitions not available for non-DEBUG here. (needed this to compile in SYMBIAN32 & linux?) 523 549 assert(_hwscreen != NULL); … … 526 552 527 553 // If the shake position changed, fill the dirty area with blackness 528 554 if (_currentShakePos != _newShakePos) { 529 SDL_Rect blackrect = {0, 0, _screenWidth * _scaleFactor, _newShakePos * _scaleFactor};555 SDL_Rect blackrect = {0, 0, (int)(_screenWidth * _scaleFactor), (int)(_newShakePos * _scaleFactor)}; 530 556 531 557 if (_adjustAspectRatio && !_overlayVisible) 532 558 blackrect.h = real2Aspect(blackrect.h - 1) + 1; … … 624 650 register int dst_y = r->y + _currentShakePos; 625 651 register int dst_h = 0; 626 652 register int orig_dst_y = 0; 627 register int rx1 = r->x * scale1;653 register int rx1 = (int)(r->x * scale1); 628 654 629 655 if (dst_y < height) { 630 656 dst_h = r->h; … … 632 658 dst_h = height - dst_y; 633 659 634 660 orig_dst_y = dst_y; 635 dst_y = dst_y * scale1;661 dst_y = (int)(dst_y * scale1); 636 662 637 663 if (_adjustAspectRatio && !_overlayVisible) 638 664 dst_y = real2Aspect(dst_y); … … 644 670 645 671 r->x = rx1; 646 672 r->y = dst_y; 647 r->w = r->w * scale1;648 r->h = dst_h * scale1;673 r->w = (int)(r->w * scale1); 674 r->h = (int)(dst_h * scale1); 649 675 650 676 #ifndef DISABLE_SCALERS 651 677 if (_adjustAspectRatio && orig_dst_y < height && !_overlayVisible) 652 r->h = stretch200To240((uint8 *) _hwscreen->pixels, dstPitch, r->w, r->h, r->x, r->y, orig_dst_y * scale1);678 r->h = stretch200To240((uint8 *) _hwscreen->pixels, dstPitch, r->w, r->h, r->x, r->y, (int)(orig_dst_y * scale1)); 653 679 #endif 654 680 } 655 681 SDL_UnlockSurface(srcSurf); … … 1093 1119 1094 1120 // Since resolution could change, put mouse to adjusted position 1095 1121 // Fixes bug #1349059 1096 x = _mouseCurState.x * _scaleFactor;1122 x = (int)(_mouseCurState.x * _scaleFactor); 1097 1123 if (_adjustAspectRatio) 1098 y = real2Aspect(_mouseCurState.y) * _scaleFactor;1124 y = (int)(real2Aspect(_mouseCurState.y) * _scaleFactor); 1099 1125 else 1100 y = _mouseCurState.y * _scaleFactor;1126 y = (int)(_mouseCurState.y * _scaleFactor); 1101 1127 1102 1128 warpMouse(x, y); 1103 1129 … … 1116 1142 1117 1143 // Since resolution could change, put mouse to adjusted position 1118 1144 // Fixes bug #1349059 1119 x = _mouseCurState.x / _scaleFactor;1120 y = _mouseCurState.y / _scaleFactor;1145 x = (int)(_mouseCurState.x / _scaleFactor); 1146 y = (int)(_mouseCurState.y / _scaleFactor); 1121 1147 if (_adjustAspectRatio) 1122 1148 y = aspect2Real(y); 1123 1149 … … 1153 1179 #ifndef DISABLE_SCALERS 1154 1180 if (_adjustAspectRatio) 1155 1181 stretch200To240((uint8 *)_overlayscreen->pixels, _overlayscreen->pitch, 1156 _overlayWidth, _screenHeight * _scaleFactor, 0, 0, 0);1182 _overlayWidth, (int)(_screenHeight * _scaleFactor), 0, 0, 0); 1157 1183 #endif 1158 1184 SDL_UnlockSurface(_tmpscreen); 1159 1185 SDL_UnlockSurface(_overlayscreen); … … 1265 1291 1266 1292 if (_mouseCurState.x != x || _mouseCurState.y != y) { 1267 1293 if (!_overlayVisible) 1268 SDL_WarpMouse( x * _scaleFactor, y1 * _scaleFactor);1294 SDL_WarpMouse((int)(x * _scaleFactor), (int)(y1 * _scaleFactor)); 1269 1295 else 1270 1296 SDL_WarpMouse(x, y1); 1271 1297 … … 1381 1407 1382 1408 // The virtual dimensions may be larger than the original. 1383 1409 1384 _mouseCurState.vW = w * _cursorTargetScale / _scaleFactor;1385 _mouseCurState.vH = h * _cursorTargetScale / _scaleFactor;1386 _mouseCurState.vHotX = _mouseCurState.hotX * _cursorTargetScale /1387 _scaleFactor ;1388 _mouseCurState.vHotY = _mouseCurState.hotY * _cursorTargetScale /1389 _scaleFactor ;1410 _mouseCurState.vW = (int)(w * _cursorTargetScale / _scaleFactor); 1411 _mouseCurState.vH = (int)(h * _cursorTargetScale / _scaleFactor); 1412 _mouseCurState.vHotX = (int)(_mouseCurState.hotX * _cursorTargetScale / 1413 _scaleFactor); 1414 _mouseCurState.vHotY = (int)(_mouseCurState.hotY * _cursorTargetScale / 1415 _scaleFactor); 1390 1416 } else { 1391 1417 // The cursor target scale is smaller than the scale at which 1392 1418 // the rest of the screen is drawn. We scale up the cursor 1393 1419 // image to make it appear correct. 1394 1420 1395 rW = w * _scaleFactor / _cursorTargetScale;1396 rH = h * _scaleFactor / _cursorTargetScale;1397 _mouseCurState.rHotX = _mouseCurState.hotX * _scaleFactor /1398 _cursorTargetScale ;1399 _mouseCurState.rHotY = _mouseCurState.hotY * _scaleFactor /1400 _cursorTargetScale ;1421 rW = (int)(w * _scaleFactor / _cursorTargetScale); 1422 rH = (int)(h * _scaleFactor / _cursorTargetScale); 1423 _mouseCurState.rHotX = (int)(_mouseCurState.hotX * _scaleFactor / 1424 _cursorTargetScale); 1425 _mouseCurState.rHotY = (int)(_mouseCurState.hotY * _scaleFactor / 1426 _cursorTargetScale); 1401 1427 1402 1428 // The virtual dimensions will be the same as the original. 1403 1429 … … 1446 1472 // the game. This only works well with the non-blurring scalers so we 1447 1473 // actually only use the 1x, 1.5x, 2x and AdvMame scalers. 1448 1474 1449 if (_cursorTargetScale == 1 && (_mode == GFX_DOUBLESIZE || _mode == GFX_TRIPLESIZE)) 1475 if (_cursorTargetScale == 1 && (_mode == GFX_DOUBLESIZE || _mode == GFX_TRIPLESIZE) || 1476 _mode == GFX_FLOAT) 1450 1477 scalerProc = _scalerProc; 1451 1478 else 1452 scalerProc = scalersMagn[ _cursorTargetScale - 1][_scaleFactor - 1];1479 scalerProc = scalersMagn[(int)_cursorTargetScale - 1][(int)_scaleFactor - 1]; 1453 1480 1454 1481 scalerProc((byte *)_mouseOrigSurface->pixels + _mouseOrigSurface->pitch + 2, 1455 1482 _mouseOrigSurface->pitch, (byte *)_mouseSurface->pixels, _mouseSurface->pitch, … … 1514 1541 } 1515 1542 1516 1543 SDL_Rect dst; 1517 int scale;1544 scale_t scale; 1518 1545 int width, height; 1519 1546 int hotX, hotY; 1520 1547 … … 1557 1584 if (_adjustAspectRatio && !_overlayVisible) 1558 1585 dst.y = real2Aspect(dst.y); 1559 1586 1560 dst.x = scale * dst.x - _mouseCurState.rHotX;1561 dst.y = scale * dst.y - _mouseCurState.rHotY;1587 dst.x = (int)(scale * dst.x - _mouseCurState.rHotX); 1588 dst.y = (int)(scale * dst.y - _mouseCurState.rHotY); 1562 1589 dst.w = _mouseCurState.rW; 1563 1590 dst.h = _mouseCurState.rH; 1564 1591 … … 1690 1717 } 1691 1718 1692 1719 int newMode = -1; 1693 int factor = _scaleFactor - 1;1720 int factor = (int)(_scaleFactor - 1); 1694 1721 1695 1722 // Increase/decrease the scale factor 1696 1723 if (key.keysym.sym == SDLK_EQUALS || key.keysym.sym == SDLK_PLUS || key.keysym.sym == SDLK_MINUS || -
backends/platform/sdl/events.cpp
77 77 78 78 // Adjust for the screen scaling 79 79 if (!_overlayVisible) { 80 event.mouse.x /= _scaleFactor;81 event.mouse.y /= _scaleFactor;80 event.mouse.x = (int)(event.mouse.x / _scaleFactor); 81 event.mouse.y = (int)(event.mouse.y / _scaleFactor); 82 82 if (_adjustAspectRatio) 83 83 event.mouse.y = aspect2Real(event.mouse.y); 84 84 } -
backends/platform/sdl/sdl.h
64 64 GFX_HQ2X = 8, 65 65 GFX_HQ3X = 9, 66 66 GFX_TV2X = 10, 67 GFX_DOTMATRIX = 11 67 GFX_DOTMATRIX = 11, 68 GFX_FLOAT = 12 68 69 }; 69 70 70 71 … … 270 271 bool _forceFull; 271 272 ScalerProc *_scalerProc; 272 273 int _scalerType; 273 int _scaleFactor;274 scale_t _scaleFactor; 274 275 int _mode; 275 276 int _transactionMode; 276 277 bool _fullscreen; … … 339 340 SDL_Rect _mouseBackup; 340 341 MousePos _mouseCurState; 341 342 byte _mouseKeyColor; 342 int _cursorTargetScale;343 scale_t _cursorTargetScale; 343 344 bool _cursorPaletteDisabled; 344 345 SDL_Surface *_mouseOrigSurface; 345 346 SDL_Surface *_mouseSurface; … … 402 403 virtual bool saveScreenshot(const char *filename); // overloaded by CE backend 403 404 404 405 int effectiveScreenHeight() const { 405 return ( _adjustAspectRatio ? real2Aspect(_screenHeight) : _screenHeight)406 * _scaleFactor ;406 return (int)((_adjustAspectRatio ? real2Aspect(_screenHeight) : _screenHeight) 407 * _scaleFactor); 407 408 } 408 409 409 410 void setupIcon();