Ticket #9860: dvdmenubuttons.patch

File dvdmenubuttons.patch, 9.0 KB (added by linux@…, 14 years ago)

patch series for DVD menu button highlighting

  • mythtv/libs/libmythtv/dvdringbuffer.cpp

    From 3e5a9542d9c820d805f8ec6c853af5b730c6864f Mon Sep 17 00:00:00 2001
    From: Martin Kittel <linux@martin-kittel.de>
    Date: Wed, 22 Jun 2011 19:35:08 +0200
    Subject: [PATCH 1/4] DVD menu button: fix height of button subtitle area
    
    In the current version of libavcodec the height is calculated simply as
    y2-y1. However this is not symmetric with the way the width is calculated.
    Now we do it just as for the width which is the same way it is done in
    xine.
    ---
     mythtv/libs/libmythtv/dvdringbuffer.cpp |    2 +-
     1 files changed, 1 insertions(+), 1 deletions(-)
    
    diff --git a/mythtv/libs/libmythtv/dvdringbuffer.cpp b/mythtv/libs/libmythtv/dvdringbuffer.cpp
    index 1c1cf4f..a904488 100644
    a b bool DVDRingBuffer::DecodeSubtitles(AVSubtitle *sub, int *gotSubtitles, 
    13881388            w = x2 - x1 + 1;
    13891389            if (w < 0)
    13901390                w = 0;
    1391             h = y2 - y1 + 2;
     1391            h = y2 - y1 + 1;
    13921392            if (h < 0)
    13931393                h = 0;
    13941394            if (w > 0 && h > 0)
  • mythtv/libs/libmythtv/subtitlescreen.cpp

    -- 
    1.7.5.3
    
    From ae2491adcd0c16e5c4bb96bad5a70a9a1f065ae9 Mon Sep 17 00:00:00 2001
    From: Martin Kittel <linux@martin-kittel.de>
    Date: Wed, 22 Jun 2011 19:41:29 +0200
    Subject: [PATCH 2/4] DVD menu buttons: use QImage constructor with
     bytesPerLine parameter
    
    I do not know why adding this is necessary. Most of the time the old
    constructor was working fine. On one of my DVDs however the button
    graphics were always corrupted. Using the constructor with the
    bytesPerLine parameter solved the issue.
    ---
     mythtv/libs/libmythtv/subtitlescreen.cpp |    2 +-
     1 files changed, 1 insertions(+), 1 deletions(-)
    
    diff --git a/mythtv/libs/libmythtv/subtitlescreen.cpp b/mythtv/libs/libmythtv/subtitlescreen.cpp
    index 60b90e2..d144d6f 100644
    a b void SubtitleScreen::DisplayDVDButton(AVSubtitle* dvdButton, QRect &buttonPos) 
    533533    uint h = hl_button->h;
    534534    uint w = hl_button->w;
    535535    QRect rect = QRect(hl_button->x, hl_button->y, w, h);
    536     QImage bg_image(hl_button->pict.data[0], w, h, QImage::Format_Indexed8);
     536    QImage bg_image(hl_button->pict.data[0], w, h, w, QImage::Format_Indexed8);
    537537    uint32_t *bgpalette = (uint32_t *)(hl_button->pict.data[1]);
    538538
    539539    bool blank = true;
  • mythtv/libs/libmythtv/dvdringbuffer.cpp

    -- 
    1.7.5.3
    
    From c10689ba96cd57eded2f24d4eca454c3c54b4ce7 Mon Sep 17 00:00:00 2001
    From: Martin Kittel <linux@martin-kittel.de>
    Date: Wed, 22 Jun 2011 19:58:32 +0200
    Subject: [PATCH 3/4] DVD menu buttons: fix button position handling
    
    The current implementation did not handle menu buttons correctly whenever
    the background subtitle position was not in the upper left corner.
    Now button positions are taken as supplied by dvdnav and the foreground
    button content is copied from the background subtitle taking the offset
    into account.
    
    Also, a heuristic check for valid button coordinates in
    DVDRingBuffer::GetMenuSubtitle has been removed. It turns out that even if
    the button coordinates look fishy the end result turns out fine (and with
    the check in place the buttons would never get painted).
    ---
     mythtv/libs/libmythtv/dvdringbuffer.cpp  |   15 +++------------
     mythtv/libs/libmythtv/subtitlescreen.cpp |    7 ++++---
     2 files changed, 7 insertions(+), 15 deletions(-)
    
    diff --git a/mythtv/libs/libmythtv/dvdringbuffer.cpp b/mythtv/libs/libmythtv/dvdringbuffer.cpp
    index a904488..88f3e93 100644
    a b AVSubtitle *DVDRingBuffer::GetMenuSubtitle(uint &version) 
    12451245    // this is unlocked by ReleaseMenuButton
    12461246    m_menuBtnLock.lock();
    12471247
    1248     if ((m_menuBuflength > 4) && m_buttonExists && (NumMenuButtons() > 0) &&
    1249         (m_dvdMenuButton.rects[0]->h >= m_hl_button.height()) &&
    1250         (m_dvdMenuButton.rects[0]->w >= m_hl_button.width()))
     1248    if ((m_menuBuflength > 4) && m_buttonExists && (NumMenuButtons() > 0))
    12511249    {
    12521250        version = m_buttonVersion;
    12531251        return &(m_dvdMenuButton);
    QRect DVDRingBuffer::GetButtonCoords(void) 
    12701268    if (!m_buttonExists)
    12711269        return rect;
    12721270
    1273     int x1, y1;
    1274     int x = 0; int y = 0;
    1275     x1 = m_dvdMenuButton.rects[0]->x;
    1276     y1 = m_dvdMenuButton.rects[0]->y;
    1277     if (m_hl_button.x() > x1)
    1278         x = m_hl_button.x() - x1;
    1279     if (m_hl_button.y() > y1)
    1280         y  = m_hl_button.y() - y1;
    1281     rect.setRect(x, y, m_hl_button.width(), m_hl_button.height());
     1271    rect.setRect(m_hl_button.x(), m_hl_button.y(), m_hl_button.width(),
     1272            m_hl_button.height());
    12821273
    12831274    return rect;
    12841275}
  • mythtv/libs/libmythtv/subtitlescreen.cpp

    diff --git a/mythtv/libs/libmythtv/subtitlescreen.cpp b/mythtv/libs/libmythtv/subtitlescreen.cpp
    index d144d6f..8a726d0 100644
    a b void SubtitleScreen::DisplayDVDButton(AVSubtitle* dvdButton, QRect &buttonPos) 
    560560        VERBOSE(VB_PLAYBACK, LOC + "Added DVD button background");
    561561    }
    562562
    563     QImage fg_image = bg_image.copy(buttonPos);
     563    // copy button region of background image
     564    QRect fg_rect(buttonPos.translated(-hl_button->x, -hl_button->y));
     565    QImage fg_image = bg_image.copy(fg_rect);
    564566    QVector<unsigned int> fg_palette;
    565567    uint32_t *fgpalette = (uint32_t *)(dvdButton->rects[1]->pict.data[1]);
    566568    if (fgpalette)
    void SubtitleScreen::DisplayDVDButton(AVSubtitle* dvdButton, QRect &buttonPos) 
    571573    }
    572574
    573575    // scale highlight image to match OSD size, if required
    574     QRect button = buttonPos.adjusted(0, 2, 0, 0);
    575576    fg_image = fg_image.convertToFormat(QImage::Format_ARGB32);
    576     AddScaledImage(fg_image, button);
     577    AddScaledImage(fg_image, buttonPos);
    577578}
    578579
    579580void SubtitleScreen::DisplayCC608Subtitles(void)
  • mythtv/libs/libmythtv/subtitlescreen.cpp

    -- 
    1.7.5.3
    
    From f6fcc5526a595e730d8285f0fc16d8d64be80f8b Mon Sep 17 00:00:00 2001
    From: Martin Kittel <linux@martin-kittel.de>
    Date: Wed, 22 Jun 2011 20:33:20 +0200
    Subject: [PATCH 4/4] DVD menu buttons: set highlight color in background
     image
    
    Instead of painting the subtitle background picture and the foreground
    button on top of it, the foreground color should be set in the background
    picture directly. Otherwise button effects such as a greyed out area
    becoming transparent will not work.
    This behavior also matches what is described here
    http://www.mpucoder.com/guides/menu1.html.
    ---
     mythtv/libs/libmythtv/subtitlescreen.cpp |   47 +++++++++++++----------------
     1 files changed, 21 insertions(+), 26 deletions(-)
    
    diff --git a/mythtv/libs/libmythtv/subtitlescreen.cpp b/mythtv/libs/libmythtv/subtitlescreen.cpp
    index 8a726d0..aa787f4 100644
    a b void SubtitleScreen::DisplayDVDButton(AVSubtitle* dvdButton, QRect &buttonPos) 
    536536    QImage bg_image(hl_button->pict.data[0], w, h, w, QImage::Format_Indexed8);
    537537    uint32_t *bgpalette = (uint32_t *)(hl_button->pict.data[1]);
    538538
    539     bool blank = true;
    540     for (uint x = 0; (x < w) && bgpalette; x++)
    541     {
    542         for (uint y = 0; y < h; y++)
    543         {
    544             if (qAlpha(bgpalette[bg_image.pixelIndex(x, y)]) > 0)
    545             {
    546                 blank = false;
    547                 break;
    548             }
    549         }
    550     }
    551 
    552     if (!blank)
    553     {
    554         QVector<unsigned int> bg_palette;
    555         for (int i = 0; i < AVPALETTE_COUNT; i++)
    556             bg_palette.push_back(bgpalette[i]);
    557         bg_image.setColorTable(bg_palette);
    558         bg_image = bg_image.convertToFormat(QImage::Format_ARGB32);
    559         AddScaledImage(bg_image, rect);
    560         VERBOSE(VB_PLAYBACK, LOC + "Added DVD button background");
    561     }
     539    QVector<unsigned int> bg_palette;
     540    for (int i = 0; i < AVPALETTE_COUNT; i++)
     541        bg_palette.push_back(bgpalette[i]);
     542    bg_image.setColorTable(bg_palette);
    562543
    563544    // copy button region of background image
    564     QRect fg_rect(buttonPos.translated(-hl_button->x, -hl_button->y));
     545    const QRect fg_rect(buttonPos.translated(-hl_button->x, -hl_button->y));
    565546    QImage fg_image = bg_image.copy(fg_rect);
    566547    QVector<unsigned int> fg_palette;
    567548    uint32_t *fgpalette = (uint32_t *)(dvdButton->rects[1]->pict.data[1]);
    void SubtitleScreen::DisplayDVDButton(AVSubtitle* dvdButton, QRect &buttonPos) 
    572553        fg_image.setColorTable(fg_palette);
    573554    }
    574555
    575     // scale highlight image to match OSD size, if required
     556    bg_image = bg_image.convertToFormat(QImage::Format_ARGB32);
    576557    fg_image = fg_image.convertToFormat(QImage::Format_ARGB32);
    577     AddScaledImage(fg_image, buttonPos);
     558
     559    // set pixel of highlight area to highlight color
     560    for (int x=fg_rect.x(); x < fg_rect.x()+fg_rect.width(); ++x)
     561    {
     562        if ((x < 0) || (x > hl_button->w))
     563            continue;
     564        for (int y=fg_rect.y(); y < fg_rect.y()+fg_rect.height(); ++y)
     565        {
     566            if ((y < 0) || (y > hl_button->h))
     567                continue;
     568            bg_image.setPixel(x, y, fg_image.pixel(x-fg_rect.x(),y-fg_rect.y()));
     569        }
     570    }
     571
     572    AddScaledImage(bg_image, rect);
    578573}
    579574
    580575void SubtitleScreen::DisplayCC608Subtitles(void)