|
MythTV
0.26-pre
|
00001 #include <QPainter> 00002 00003 #include "mythuiimage.h" 00004 #include "mythpainter.h" 00005 00006 #include "bdringbuffer.h" 00007 #include "bdoverlayscreen.h" 00008 00009 #define LOC QString("BDScreen: ") 00010 00011 BDOverlayScreen::BDOverlayScreen(MythPlayer *player, const QString &name) 00012 : MythScreenType((MythScreenType*)NULL, name), 00013 m_player(player), m_overlayArea(QRect()) 00014 { 00015 } 00016 00017 BDOverlayScreen::~BDOverlayScreen() 00018 { 00019 LOG(VB_PLAYBACK, LOG_DEBUG, LOC + "dtor"); 00020 m_overlayMap.clear(); 00021 } 00022 00023 void BDOverlayScreen::DisplayBDOverlay(BDOverlay *overlay) 00024 { 00025 if (!overlay || !m_player) 00026 return; 00027 00028 if (!overlay->m_data) 00029 { 00030 m_overlayArea = overlay->m_position; 00031 SetArea(MythRect(m_overlayArea)); 00032 DeleteAllChildren(); 00033 m_overlayMap.clear(); 00034 SetRedraw(); 00035 LOG(VB_PLAYBACK, LOG_INFO, LOC + 00036 QString("Initialised Size: %1x%2 (%3+%4) Plane: %5 Pts: %6") 00037 .arg(overlay->m_position.width()) 00038 .arg(overlay->m_position.height()) 00039 .arg(overlay->m_position.left()) 00040 .arg(overlay->m_position.top()) 00041 .arg(overlay->m_plane) 00042 .arg(overlay->m_pts)); 00043 BDOverlay::DeleteOverlay(overlay); 00044 return; 00045 } 00046 00047 if (!m_overlayArea.isValid()) 00048 { 00049 LOG(VB_GENERAL, LOG_ERR, LOC + 00050 "Error: Overlay image submitted before initialisation."); 00051 } 00052 00053 VideoOutput *vo = m_player->GetVideoOutput(); 00054 if (!vo) 00055 return; 00056 00057 QRect rect = overlay->m_position; 00058 QString hash = QString("%1+%2+%3x%4") 00059 .arg(rect.left()).arg(rect.top()) 00060 .arg(rect.width()).arg(rect.height()); 00061 00062 // remove if we already have this overlay 00063 if (m_overlayMap.contains(hash)) 00064 { 00065 LOG(VB_PLAYBACK, LOG_DEBUG, LOC + QString("Removing %1 (%2 left)") 00066 .arg(hash).arg(m_overlayMap.size())); 00067 MythUIImage *old = m_overlayMap.take(hash); 00068 DeleteChild(old); 00069 } 00070 00071 // convert the overlay palette to ARGB 00072 uint32_t *origpalette = (uint32_t *)(overlay->m_palette); 00073 QVector<unsigned int> palette; 00074 for (int i = 0; i < 256; i++) 00075 { 00076 int y = (origpalette[i] >> 0) & 0xff; 00077 int cr = (origpalette[i] >> 8) & 0xff; 00078 int cb = (origpalette[i] >> 16) & 0xff; 00079 int a = (origpalette[i] >> 24) & 0xff; 00080 int r = int(y + 1.4022 * (cr - 128)); 00081 int b = int(y + 1.7710 * (cb - 128)); 00082 int g = int(1.7047 * y - (0.1952 * b) - (0.5647 * r)); 00083 if (r < 0) r = 0; 00084 if (g < 0) g = 0; 00085 if (b < 0) b = 0; 00086 if (r > 0xff) r = 0xff; 00087 if (g > 0xff) g = 0xff; 00088 if (b > 0xff) b = 0xff; 00089 palette.push_back((a << 24) | (r << 16) | (g << 8) | b); 00090 } 00091 00092 // convert the image to QImage 00093 QImage img(rect.size(), QImage::Format_Indexed8); 00094 memcpy(img.bits(), overlay->m_data, rect.width() * rect.height()); 00095 img.setColorTable(palette); 00096 img.convertToFormat(QImage::Format_ARGB32); 00097 00098 // add to screen 00099 QRect scaled = vo->GetImageRect(rect); 00100 if (scaled.size() != rect.size()) 00101 { 00102 img = img.scaled(scaled.width(), scaled.height(), 00103 Qt::IgnoreAspectRatio, Qt::SmoothTransformation); 00104 } 00105 00106 MythPainter *osd_painter = vo->GetOSDPainter(); 00107 MythImage* image = NULL; 00108 if (osd_painter) 00109 image = osd_painter->GetFormatImage(); 00110 00111 if (image) 00112 { 00113 image->Assign(img); 00114 MythUIImage *uiimage = new MythUIImage(this, "bdoverlay"); 00115 if (uiimage) 00116 { 00117 uiimage->SetImage(image); 00118 uiimage->SetArea(MythRect(scaled)); 00119 m_overlayMap.insert(hash, uiimage); 00120 LOG(VB_PLAYBACK, LOG_DEBUG, LOC + QString("Added %1 (%2 tot)") 00121 .arg(hash).arg(m_overlayMap.size())); 00122 } 00123 } 00124 00125 SetRedraw(); 00126 BDOverlay::DeleteOverlay(overlay); 00127 }
1.7.6.1