Ticket #8699: blur.patch

File blur.patch, 7.1 KB (added by jvprat, 17 years ago)
  • gui/themes/modern.ini

     
    162162shadow_right_width=4
    163163shadow_top_height=2
    164164shadow_bottom_height=4
    165 inactive_dialog_shading=kShadingDim
     165inactive_dialog_shading=kShadingBlur
    166166shading_dim_percent=50
     167shading_blur_rad=5
    167168fontfile_normal="helvr12-l1.bdf"
    168169fontfile_fixed_normal="courr12-l1.bdf"
    169170cursor_hotspot_x=0
  • gui/ThemeModern.cpp

     
    195195                _dialog->screen.create(_screen.w, _screen.h, sizeof(OverlayColor));
    196196        }
    197197       
    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))();
    207200       
    208201        memcpy(_dialog->screen.pixels, _screen.pixels, _screen.pitch*_screen.h);
    209202       
     
    10961089
    10971090#define NO_EFFECT(x) ((x) & rowColor)
    10981091#define ALPHA_EFFECT(x) (getColorAlpha((x) & rowColor, *dst, alpha))
    1099 #define DARKEN_EFFECT(x) (calcDimColor((x) & rowColor))
     1092#define DARKEN_EFFECT(x) (calcDimPixel((x) & rowColor))
    11001093
    11011094#define LEFT_RIGHT_OFFSET(x) (drawWidth-x-1)
    11021095#define NORMAL_OFFSET(x) (x)
     
    14431436                }
    14441437                break;
    14451438
     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
    14461452        default:
    14471453                        warning("no valid 'inactive_dialog_shading' specified");
    14481454        }
     
    14601466
    14611467#pragma mark -
    14621468
    1463 OverlayColor ThemeModern::calcLuminance(OverlayColor col) {
     1469void ThemeModern::calcLuminance() {
     1470        OverlayColor *col = (OverlayColor*)_screen.pixels;
    14641471        uint8 r, g, b;
    1465         _system->colorToRGB(col, r, g, b);
    14661472
    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        }
    14741487}
    14751488
    1476 OverlayColor ThemeModern::calcDimColor(OverlayColor col) {
     1489void 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
     1499OverlayColor ThemeModern::calcDimPixel(OverlayColor col) {
    14771500        uint8 r, g, b;
    14781501        _system->colorToRGB(col, r, g, b);
    14791502       
     
    14841507        return _system->RGBToColor(r, g, b);
    14851508}
    14861509
     1510void 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
    14871594#pragma mark -
    14881595
    14891596void ThemeModern::setUpCursor() {
  • gui/theme.h

     
    120120        enum ShadingStyle {
    121121                kShadingNone,
    122122                kShadingDim,
    123                 kShadingLuminance
     123                kShadingLuminance,
     124                kShadingBlur
    124125        };
    125126
    126127        virtual bool init() = 0;
  • gui/eval.cpp

     
    282282        {"kShadingNone", Theme::kShadingNone},
    283283        {"kShadingDim", Theme::kShadingDim},
    284284        {"kShadingLuminance", Theme::kShadingLuminance},
     285        {"kShadingBlur", Theme::kShadingBlur},
    285286
    286287        {"false", 0},
    287288        {"true", 1},
  • gui/ThemeModern.h

     
    211211
    212212private:
    213213        int _dimPercentValue;
    214         typedef OverlayColor (ThemeModern::*InactiveDialogCallback)(OverlayColor col); 
     214        int _blurRadValue;
     215        typedef void (ThemeModern::*InactiveDialogCallback)();
    215216        InactiveDialogCallback _dialogShadingCallback;
    216217       
    217         OverlayColor calcLuminance(OverlayColor col);
    218         OverlayColor calcDimColor(OverlayColor col);
     218        void calcLuminance();
     219        void calcDimColor();
     220        void calcBlurColor();
    219221
     222        OverlayColor calcDimPixel(OverlayColor col);
     223
    220224        bool _useCursor;
    221225        void setUpCursor();
    222226        void createCursor();