Ticket #8699: blur-mix.patch
File blur-mix.patch, 9.7 KB (added by , 17 years ago) |
---|
-
gui/themes/modern.ini
162 162 shadow_right_width=4 163 163 shadow_top_height=2 164 164 shadow_bottom_height=4 165 inactive_dialog_shading=kShadingDim 166 shading_dim_percent=50 165 shading_luminance_percent=30 166 shading_dim_percent=10 167 shading_blur_rad=2 167 168 fontfile_normal="helvr12-l1.bdf" 168 169 fontfile_fixed_normal="courr12-l1.bdf" 169 170 cursor_hotspot_x=0 … … 610 611 launcher_logo.visible=true 611 612 612 613 # Override extras 613 inactive_dialog_shading=kShadingNone 614 shading_luminance_percent=0 615 shading_dim_percent=0 616 shading_blur_rad=0 614 617 615 618 # Override browser 616 619 def_buttonWidth=90 -
gui/ThemeModern.cpp
195 195 _dialog->screen.create(_screen.w, _screen.h, sizeof(OverlayColor)); 196 196 } 197 197 198 if (_dialogShadingCallback && topDialog) { 199 OverlayColor *col = (OverlayColor*)_screen.pixels; 200 for (int y = 0; y < _screen.h; ++y) { 201 for (int x = 0; x < _screen.w; ++x) { 202 col[x] = (this->*(_dialogShadingCallback))(col[x]); 203 } 204 col += _screen.w; 205 } 206 } 198 if (_dialogShading && topDialog) 199 dialogShading(); 207 200 208 201 memcpy(_dialog->screen.pixels, _screen.pixels, _screen.pitch*_screen.h); 209 202 210 if ( (_dialogShadingCallback)&& topDialog)203 if (_dialogShading && topDialog) 211 204 addDirtyRect(Common::Rect(0, 0, _screen.w, _screen.h), false, false); 212 205 } 213 206 … … 1123 1116 blitSurface(NORMAL_OFFSET, NO_EFFECT); 1124 1117 } 1125 1118 } else if (alpha < 0 && alpha >= -256) { 1126 int backUp = _ dimPercentValue;1127 _ dimPercentValue= 256 * (100 - (-alpha)) / 100;1119 int backUp = _shadingDimPercent; 1120 _shadingDimPercent = 256 * (100 - (-alpha)) / 100; 1128 1121 1129 1122 if (leftRight) { 1130 1123 blitSurface(LEFT_RIGHT_OFFSET, DARKEN_EFFECT); … … 1132 1125 blitSurface(NORMAL_OFFSET, DARKEN_EFFECT); 1133 1126 } 1134 1127 1135 _ dimPercentValue= backUp;1128 _shadingDimPercent = backUp; 1136 1129 } else { 1137 1130 if (leftRight) { 1138 1131 blitSurface(LEFT_RIGHT_OFFSET, ALPHA_EFFECT); … … 1416 1409 _cursorTargetScale = _evaluator->getVar("cursor_targetScale", 1); 1417 1410 1418 1411 // inactive dialog shading stuff 1419 1420 ShadingStyle shading = (ShadingStyle)_evaluator->getVar("inactive_dialog_shading", kShadingNone); 1412 _shadingLuminancePercent = _evaluator->getVar("shading_luminance_percent", -1); 1413 if (_shadingLuminancePercent < 0) { 1414 _shadingLuminancePercent = 0; 1415 } else if (_shadingLuminancePercent > 100) { 1416 _shadingLuminancePercent = 100; 1417 } 1418 _shadingLuminancePercent = 256 * _shadingLuminancePercent / 100; 1421 1419 1422 switch (shading) { 1423 case kShadingNone: 1424 _dialogShadingCallback = 0; 1425 break; 1420 _shadingDimPercent = _evaluator->getVar("shading_dim_percent", -1); 1421 if (_shadingDimPercent < 0) { 1422 _shadingDimPercent = 0; 1423 } else if (_shadingDimPercent > 100) { 1424 _shadingDimPercent = 100; 1425 } 1426 _shadingDimPercent = 256 * (100 - _shadingDimPercent) / 100; 1426 1427 1427 case kShadingLuminance: 1428 _dialogShadingCallback = &ThemeModern::calcLuminance; 1429 break; 1430 1431 case kShadingDim: 1432 _dimPercentValue = _evaluator->getVar("shading_dim_percent", -1); 1433 1434 if (_dimPercentValue < 0) { 1435 _dimPercentValue = 0; 1436 } else if (_dimPercentValue > 100) { 1437 _dimPercentValue = 100; 1438 } 1439 1440 if (_dimPercentValue != 0) { 1441 _dimPercentValue = 256 * (100 - _dimPercentValue) / 100; 1442 _dialogShadingCallback = &ThemeModern::calcDimColor; 1443 } 1444 break; 1445 1446 default: 1447 warning("no valid 'inactive_dialog_shading' specified"); 1428 _shadingBlurRad = _evaluator->getVar("shading_blur_rad", -1); 1429 if (_shadingBlurRad < 0) { 1430 _shadingBlurRad = 0; 1431 } else if (_shadingBlurRad > 100) { 1432 _shadingBlurRad = 100; 1448 1433 } 1434 _dialogShading = _shadingLuminancePercent || _shadingDimPercent < 256 || _shadingBlurRad; 1449 1435 1450 1436 setupFonts(); 1451 1437 … … 1460 1446 1461 1447 #pragma mark - 1462 1448 1463 OverlayColor ThemeModern::calcLuminance(OverlayColor col) {1464 uint8 r, g, b;1465 _system->colorToRGB(col, r, g, b);1466 1467 // A better (but slower) formula to calculate the luminance would be:1468 //uint lum = (byte)((0.299 * r + 0.587 * g + 0.114 * b) + 0.5);1469 // Note that the approximation below will only produce values between1470 // (and including) 0 and 221.1471 uint lum = (r >> 2) + (g >> 1) + (b >> 3);1472 1473 return _system->RGBToColor(lum, lum, lum);1474 }1475 1476 1449 OverlayColor ThemeModern::calcDimColor(OverlayColor col) { 1477 1450 uint8 r, g, b; 1478 1451 _system->colorToRGB(col, r, g, b); 1479 1452 1480 r = r * _ dimPercentValue>> 8;1481 g = g * _ dimPercentValue>> 8;1482 b = b * _ dimPercentValue>> 8;1453 r = r * _shadingDimPercent >> 8; 1454 g = g * _shadingDimPercent >> 8; 1455 b = b * _shadingDimPercent >> 8; 1483 1456 1484 1457 return _system->RGBToColor(r, g, b); 1485 1458 } 1486 1459 1460 void ThemeModern::dialogShading() { 1461 OverlayColor *col = (OverlayColor*)_screen.pixels; 1462 1463 // Convert the whole overlay to RGB (is there a more efficient way?) 1464 #define pixel(x,y) (rgb + (((x) + (y) * _screen.w) * 4)) 1465 uint8 *rgb = new uint8[_screen.w * _screen.h * 4]; 1466 for (int y = 0; y < _screen.h; y++) { 1467 for (int x = 0; x < _screen.w; x++) { 1468 uint8 r, g, b; 1469 _system->colorToRGB(col[x + y * _screen.w], r, g, b); 1470 1471 // Luminance 1472 if (_shadingLuminancePercent > 0) { 1473 // A better (but slower) formula to calculate the luminance would be: 1474 //uint lum = (byte)((0.299 * r + 0.587 * g + 0.114 * b) + 0.5); 1475 // Note that the approximation below will only produce values between 1476 // (and including) 0 and 221. 1477 uint lum = (r >> 2) + (g >> 1) + (b >> 3); 1478 lum *= _shadingLuminancePercent; 1479 lum >>= 8; 1480 r = lum + (r * (256 - _shadingLuminancePercent) >> 8); 1481 g = lum + (g * (256 - _shadingLuminancePercent) >> 8); 1482 b = lum + (b * (256 - _shadingLuminancePercent) >> 8); 1483 } 1484 1485 // Dimming 1486 if (_shadingDimPercent < 256) { 1487 r = r * _shadingDimPercent >> 8; 1488 g = g * _shadingDimPercent >> 8; 1489 b = b * _shadingDimPercent >> 8; 1490 } 1491 1492 pixel(x,y)[0] = r; 1493 pixel(x,y)[1] = g; 1494 pixel(x,y)[2] = b; 1495 } 1496 } 1497 1498 1499 int32 acum_r, acum_g, acum_b; 1500 int count = 0; 1501 1502 // If we don't want to blur, we skip the horizontal blur. The vertical one 1503 // actually writes back to the overlay surface. 1504 if (_shadingBlurRad) { 1505 // Horizontal blur in place (using original_row for substractions) 1506 uint8 *original_row = new uint8[_screen.w * 4]; 1507 for (int y = 0; y < _screen.h; y++) { 1508 acum_r = acum_g = acum_b = 0; 1509 count = 0; 1510 1511 memcpy(original_row, rgb + y * _screen.w * 4, _screen.w * 4); 1512 1513 // Blur one line 1514 for (int x = -_shadingBlurRad; x < _screen.w; x++) { 1515 // Add the new pixel in the window 1516 if (x + _shadingBlurRad < _screen.w) { 1517 count++; 1518 acum_r += pixel(x + _shadingBlurRad, y)[0]; 1519 acum_g += pixel(x + _shadingBlurRad, y)[1]; 1520 acum_b += pixel(x + _shadingBlurRad, y)[2]; 1521 } 1522 // Calculate the central pixel 1523 if (x >= 0 && x < _screen.pitch) { 1524 pixel(x,y)[0] = acum_r / count; 1525 pixel(x,y)[1] = acum_g / count; 1526 pixel(x,y)[2] = acum_b / count; 1527 } 1528 // Delete the old pixel in the window 1529 if (x - _shadingBlurRad >= 0) { 1530 count--; 1531 // We take it from the original row (current row is half blurred) 1532 acum_r -= original_row[(x - _shadingBlurRad) * 4 + 0]; 1533 acum_g -= original_row[(x - _shadingBlurRad) * 4 + 1]; 1534 acum_b -= original_row[(x - _shadingBlurRad) * 4 + 2]; 1535 } 1536 } 1537 } 1538 delete [] original_row; 1539 } 1540 1541 // Vertical blur with result to the overlay 1542 for (int x = 0; x < _screen.w; x++) { 1543 acum_r = acum_g = acum_b = 0; 1544 count = 0; 1545 1546 // Blur one column 1547 for (int y = -_shadingBlurRad; y <= _screen.h + _shadingBlurRad; y++) { 1548 // Add the new pixel in the window 1549 if (y + _shadingBlurRad < _screen.h) { 1550 count++; 1551 acum_r += pixel(x, y + _shadingBlurRad)[0]; 1552 acum_g += pixel(x, y + _shadingBlurRad)[1]; 1553 acum_b += pixel(x, y + _shadingBlurRad)[2]; 1554 } 1555 // Calculate the central pixel (and draw it back to the overlay) 1556 if (y >= 0 && y < _screen.h) { 1557 col[x + y * _screen.w] = _system->RGBToColor(acum_r / count, acum_g / count, acum_b / count); 1558 } 1559 // Delete the old pixel in the window 1560 if (y - _shadingBlurRad >= 0) { 1561 count--; 1562 acum_r -= pixel(x, y - _shadingBlurRad)[0]; 1563 acum_g -= pixel(x, y - _shadingBlurRad)[1]; 1564 acum_b -= pixel(x, y - _shadingBlurRad)[2]; 1565 } 1566 } 1567 } 1568 1569 delete [] rgb; 1570 1571 #undef pixel 1572 } 1573 1487 1574 #pragma mark - 1488 1575 1489 1576 void ThemeModern::setUpCursor() { -
gui/theme.h
117 117 kFontStyleMax 118 118 }; 119 119 120 enum ShadingStyle {121 kShadingNone,122 kShadingDim,123 kShadingLuminance124 };125 126 120 virtual bool init() = 0; 127 121 virtual void deinit() = 0; 128 122 -
gui/eval.cpp
279 279 {"kFontStyleFixedNormal", Theme::kFontStyleFixedNormal}, 280 280 {"kFontStyleFixedItalic", Theme::kFontStyleFixedItalic}, 281 281 282 {"kShadingNone", Theme::kShadingNone},283 {"kShadingDim", Theme::kShadingDim},284 {"kShadingLuminance", Theme::kShadingLuminance},285 286 282 {"false", 0}, 287 283 {"true", 1}, 288 284 {NULL, 0} -
gui/ThemeModern.h
210 210 }; 211 211 212 212 private: 213 int _dimPercentValue; 214 typedef OverlayColor (ThemeModern::*InactiveDialogCallback)(OverlayColor col); 215 InactiveDialogCallback _dialogShadingCallback; 213 int _shadingLuminancePercent; 214 int _shadingDimPercent; 215 int _shadingBlurRad; 216 bool _dialogShading; 216 217 217 OverlayColor calcLuminance(OverlayColor col); 218 void dialogShading(); 219 218 220 OverlayColor calcDimColor(OverlayColor col); 219 221 220 222 bool _useCursor;