Ticket #8699: blur.patch
File blur.patch, 7.1 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=kShading Dim165 inactive_dialog_shading=kShadingBlur 166 166 shading_dim_percent=50 167 shading_blur_rad=5 167 168 fontfile_normal="helvr12-l1.bdf" 168 169 fontfile_fixed_normal="courr12-l1.bdf" 169 170 cursor_hotspot_x=0 -
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 (_dialogShadingCallback && topDialog) 199 (this->*(_dialogShadingCallback))(); 207 200 208 201 memcpy(_dialog->screen.pixels, _screen.pixels, _screen.pitch*_screen.h); 209 202 … … 1096 1089 1097 1090 #define NO_EFFECT(x) ((x) & rowColor) 1098 1091 #define ALPHA_EFFECT(x) (getColorAlpha((x) & rowColor, *dst, alpha)) 1099 #define DARKEN_EFFECT(x) (calcDim Color((x) & rowColor))1092 #define DARKEN_EFFECT(x) (calcDimPixel((x) & rowColor)) 1100 1093 1101 1094 #define LEFT_RIGHT_OFFSET(x) (drawWidth-x-1) 1102 1095 #define NORMAL_OFFSET(x) (x) … … 1443 1436 } 1444 1437 break; 1445 1438 1439 case kShadingBlur: 1440 _blurRadValue = _evaluator->getVar("shading_blur_rad", -1); 1441 1442 if (_blurRadValue < 0) { 1443 _blurRadValue = 0; 1444 } else if (_blurRadValue > 100) { 1445 _blurRadValue = 100; 1446 } 1447 if (_blurRadValue != 0) { 1448 _dialogShadingCallback = &ThemeModern::calcBlurColor; 1449 } 1450 break; 1451 1446 1452 default: 1447 1453 warning("no valid 'inactive_dialog_shading' specified"); 1448 1454 } … … 1460 1466 1461 1467 #pragma mark - 1462 1468 1463 OverlayColor ThemeModern::calcLuminance(OverlayColor col) { 1469 void ThemeModern::calcLuminance() { 1470 OverlayColor *col = (OverlayColor*)_screen.pixels; 1464 1471 uint8 r, g, b; 1465 _system->colorToRGB(col, r, g, b);1466 1472 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 between 1470 // (and including) 0 and 221. 1471 uint lum = (r >> 2) + (g >> 1) + (b >> 3); 1472 1473 return _system->RGBToColor(lum, lum, lum); 1473 for (int y = 0; y < _screen.h; ++y) { 1474 for (int x = 0; x < _screen.w; ++x) { 1475 _system->colorToRGB(col[x], r, g, b); 1476 1477 // A better (but slower) formula to calculate the luminance would be: 1478 //uint lum = (byte)((0.299 * r + 0.587 * g + 0.114 * b) + 0.5); 1479 // Note that the approximation below will only produce values between 1480 // (and including) 0 and 221. 1481 uint lum = (r >> 2) + (g >> 1) + (b >> 3); 1482 1483 col[x] = _system->RGBToColor(lum, lum, lum); 1484 } 1485 col += _screen.w; 1486 } 1474 1487 } 1475 1488 1476 OverlayColor ThemeModern::calcDimColor(OverlayColor col) { 1489 void ThemeModern::calcDimColor() { 1490 OverlayColor *col = (OverlayColor*)_screen.pixels; 1491 for (int y = 0; y < _screen.h; ++y) { 1492 for (int x = 0; x < _screen.w; ++x) { 1493 col[x] = calcDimPixel(col[x]); 1494 } 1495 col += _screen.w; 1496 } 1497 } 1498 1499 OverlayColor ThemeModern::calcDimPixel(OverlayColor col) { 1477 1500 uint8 r, g, b; 1478 1501 _system->colorToRGB(col, r, g, b); 1479 1502 … … 1484 1507 return _system->RGBToColor(r, g, b); 1485 1508 } 1486 1509 1510 void ThemeModern::calcBlurColor() { 1511 int rad = _blurRadValue; 1512 1513 OverlayColor *col = (OverlayColor*)_screen.pixels; 1514 int32 acum_r, acum_g, acum_b; 1515 int count = 0; 1516 1517 // Convert the whole overlay to RGB (is there a more efficient way?) 1518 #define pixel(x,y) (rgb + (((x) + (y) * _screen.w) * 4)) 1519 uint8 *rgb = new uint8[_screen.w * _screen.h * 4]; 1520 for (int y = 0; y < _screen.h; y++) { 1521 for (int x = 0; x < _screen.w; x++) { 1522 uint8 r, g, b; 1523 _system->colorToRGB(col[x + y * _screen.w], r, g, b); 1524 1525 pixel(x,y)[0] = r; 1526 pixel(x,y)[1] = g; 1527 pixel(x,y)[2] = b; 1528 } 1529 } 1530 1531 1532 // Horizontal blur in place (using original_row for substractions) 1533 uint8 *original_row = new uint8[_screen.w * 4]; 1534 for (int y = 0; y < _screen.h; y++) { 1535 acum_r = acum_g = acum_b = 0; 1536 count = 0; 1537 1538 memcpy(original_row, rgb + y * _screen.w * 4, _screen.w * 4); 1539 1540 // Blur one line 1541 for (int x = -rad; x < _screen.w; x++) { 1542 if (x + rad < _screen.w) { 1543 count++; 1544 acum_r += pixel(x + rad, y)[0]; 1545 acum_g += pixel(x + rad, y)[1]; 1546 acum_b += pixel(x + rad, y)[2]; 1547 } 1548 if (x >= 0 && x < _screen.pitch) { 1549 pixel(x,y)[0] = acum_r / count; 1550 pixel(x,y)[1] = acum_g / count; 1551 pixel(x,y)[2] = acum_b / count; 1552 } 1553 if (x - rad >= 0) { 1554 count--; 1555 // We take it from the original row (current row is half blurred) 1556 acum_r -= original_row[(x - rad) * 4 + 0]; 1557 acum_g -= original_row[(x - rad) * 4 + 1]; 1558 acum_b -= original_row[(x - rad) * 4 + 2]; 1559 } 1560 } 1561 } 1562 delete [] original_row; 1563 1564 // Vertical blur with result to the overlay 1565 for (int x = 0; x < _screen.w; x++) { 1566 acum_r = acum_g = acum_b = 0; 1567 count = 0; 1568 1569 // Blur one column 1570 for (int y = -rad; y <= _screen.h + rad; y++) { 1571 if (y + rad < _screen.h) { 1572 count++; 1573 acum_r += pixel(x, y + rad)[0]; 1574 acum_g += pixel(x, y + rad)[1]; 1575 acum_b += pixel(x, y + rad)[2]; 1576 } 1577 if (y >= 0 && y < _screen.h) { 1578 col[x + y * _screen.w] = _system->RGBToColor(acum_r / count, acum_g / count, acum_b / count); 1579 } 1580 if (y - rad >= 0) { 1581 count--; 1582 acum_r -= pixel(x, y - rad)[0]; 1583 acum_g -= pixel(x, y - rad)[1]; 1584 acum_b -= pixel(x, y - rad)[2]; 1585 } 1586 } 1587 } 1588 1589 delete [] rgb; 1590 1591 #undef pixel 1592 } 1593 1487 1594 #pragma mark - 1488 1595 1489 1596 void ThemeModern::setUpCursor() { -
gui/theme.h
120 120 enum ShadingStyle { 121 121 kShadingNone, 122 122 kShadingDim, 123 kShadingLuminance 123 kShadingLuminance, 124 kShadingBlur 124 125 }; 125 126 126 127 virtual bool init() = 0; -
gui/eval.cpp
282 282 {"kShadingNone", Theme::kShadingNone}, 283 283 {"kShadingDim", Theme::kShadingDim}, 284 284 {"kShadingLuminance", Theme::kShadingLuminance}, 285 {"kShadingBlur", Theme::kShadingBlur}, 285 286 286 287 {"false", 0}, 287 288 {"true", 1}, -
gui/ThemeModern.h
211 211 212 212 private: 213 213 int _dimPercentValue; 214 typedef OverlayColor (ThemeModern::*InactiveDialogCallback)(OverlayColor col); 214 int _blurRadValue; 215 typedef void (ThemeModern::*InactiveDialogCallback)(); 215 216 InactiveDialogCallback _dialogShadingCallback; 216 217 217 OverlayColor calcLuminance(OverlayColor col); 218 OverlayColor calcDimColor(OverlayColor col); 218 void calcLuminance(); 219 void calcDimColor(); 220 void calcBlurColor(); 219 221 222 OverlayColor calcDimPixel(OverlayColor col); 223 220 224 bool _useCursor; 221 225 void setUpCursor(); 222 226 void createCursor();