Skip to content

Commit

Permalink
Improve handling of Bluray overlays (and add support for ARGB overlays).
Browse files Browse the repository at this point in the history
There's still some room for improvement:
1. The display PTS is not used (overlays are shown immediately)
2. Separate PG and IG planes are supported but not currently composited before displaying.
3. It may be possible to optimize memory usage by keeping track of the individual (smaller) wipe/draw operations and then painting them to a larger overlay 'canvas' when needed.
4. No doubt more stuff I haven't found yet.

N.B. ARGB overlays are only available when BD-J support is enabled (by passing '--enable-bdjava' to configure).
  • Loading branch information
peper03 committed Dec 20, 2016
1 parent ae7b3a0 commit 20926ad
Show file tree
Hide file tree
Showing 4 changed files with 291 additions and 144 deletions.
76 changes: 5 additions & 71 deletions mythtv/libs/libmythtv/Bluray/bdoverlayscreen.cpp
Expand Up @@ -10,92 +10,29 @@

BDOverlayScreen::BDOverlayScreen(MythPlayer *player, const QString &name)
: MythScreenType((MythScreenType*)NULL, name),
m_player(player), m_overlayArea(QRect())
m_player(player)
{
}

BDOverlayScreen::~BDOverlayScreen()
{
LOG(VB_PLAYBACK, LOG_DEBUG, LOC + "dtor");
m_overlayMap.clear();
}

void BDOverlayScreen::DisplayBDOverlay(BDOverlay *overlay)
{
if (!overlay || !m_player)
return;

if (!overlay->m_data)
{
m_overlayArea = overlay->m_position;
SetArea(MythRect(m_overlayArea));
DeleteAllChildren();
m_overlayMap.clear();
SetRedraw();
LOG(VB_PLAYBACK, LOG_INFO, LOC +
QString("Initialised Size: %1x%2 (%3+%4) Plane: %5 Pts: %6")
.arg(overlay->m_position.width())
.arg(overlay->m_position.height())
.arg(overlay->m_position.left())
.arg(overlay->m_position.top())
.arg(overlay->m_plane)
.arg(overlay->m_pts));

delete overlay;
overlay = NULL;
return;
}

if (!m_overlayArea.isValid())
{
LOG(VB_GENERAL, LOG_ERR, LOC +
"Error: Overlay image submitted before initialisation.");
}
MythRect rect(overlay->x, overlay->y, overlay->image.width(), overlay->image.height());
SetArea(rect);
DeleteAllChildren();

VideoOutput *vo = m_player->GetVideoOutput();
if (!vo)
return;

QRect rect = overlay->m_position;
QString hash = QString("%1+%2+%3x%4")
.arg(rect.left()).arg(rect.top())
.arg(rect.width()).arg(rect.height());

// remove if we already have this overlay
if (m_overlayMap.contains(hash))
{
LOG(VB_PLAYBACK, LOG_DEBUG, LOC + QString("Removing %1 (%2 left)")
.arg(hash).arg(m_overlayMap.size()));
MythUIImage *old = m_overlayMap.take(hash);
DeleteChild(old);
}

// convert the overlay palette to ARGB
uint32_t *origpalette = (uint32_t *)(overlay->m_palette);
QVector<unsigned int> palette;
for (int i = 0; i < 256; i++)
{
int y = (origpalette[i] >> 0) & 0xff;
int cr = (origpalette[i] >> 8) & 0xff;
int cb = (origpalette[i] >> 16) & 0xff;
int a = (origpalette[i] >> 24) & 0xff;
int r = int(y + 1.4022 * (cr - 128));
int b = int(y + 1.7710 * (cb - 128));
int g = int(1.7047 * y - (0.1952 * b) - (0.5647 * r));
if (r < 0) r = 0;
if (g < 0) g = 0;
if (b < 0) b = 0;
if (r > 0xff) r = 0xff;
if (g > 0xff) g = 0xff;
if (b > 0xff) b = 0xff;
palette.push_back((a << 24) | (r << 16) | (g << 8) | b);
}

// convert the image to QImage
QImage img(rect.size(), QImage::Format_Indexed8);
memcpy(img.bits(), overlay->m_data, rect.width() * rect.height());
img.setColorTable(palette);
img.convertToFormat(QImage::Format_ARGB32);
QImage& img = overlay->image;

// add to screen
QRect scaled = vo->GetImageRect(rect);
Expand All @@ -118,9 +55,6 @@ void BDOverlayScreen::DisplayBDOverlay(BDOverlay *overlay)
{
uiimage->SetImage(image);
uiimage->SetArea(MythRect(scaled));
m_overlayMap.insert(hash, uiimage);
LOG(VB_PLAYBACK, LOG_DEBUG, LOC + QString("Added %1 (%2 tot)")
.arg(hash).arg(m_overlayMap.size()));
}
image->DecrRef();
}
Expand Down
2 changes: 0 additions & 2 deletions mythtv/libs/libmythtv/Bluray/bdoverlayscreen.h
Expand Up @@ -16,8 +16,6 @@ class BDOverlayScreen : public MythScreenType

private:
MythPlayer *m_player;
QRect m_overlayArea;
QMap<QString,MythUIImage*> m_overlayMap;
};

#endif // BDOVERLAYSCREEN_H

0 comments on commit 20926ad

Please sign in to comment.