All pastes #773960 Raw Edit

Preview Image Scaling

public text v1 · immutable
#773960 ·published 2007-11-14 21:51 UTC
rendered paste body
Index: mythtv/programs/mythfrontend/playbackbox.cpp
===================================================================
--- mythtv/programs/mythfrontend/playbackbox.cpp	(revision 14863)
+++ mythtv/programs/mythfrontend/playbackbox.cpp	(working copy)
@@ -238,7 +238,8 @@
       drawTotalBounds(0, 0, size().width(), size().height()),
       drawListBounds(0, 0, 0, 0),       drawInfoBounds(0, 0, 0, 0),
       drawGroupBounds(0, 0, 0, 0),      drawUsageBounds(0, 0, 0, 0),
-      drawVideoBounds(0, 0, 0, 0),      drawCurGroupBounds(0, 0, 0, 0),
+      drawVideoBounds(0, 0, 0, 0),      blackholeBounds(0, 0, 0, 0),
+      drawCurGroupBounds(0, 0, 0, 0),
       // General popup support
       popup(NULL),                      expectingPopup(false),
       // Recording Group popup support
@@ -516,7 +517,7 @@
             kKilled :  kKilling;
 
         /* NOTE: need unlock/process/lock here because we need
-           to allow updateVideo() to run to handle changes in
+           to allow drawVideo() to run to handle changes in
            previewVideoStates */
         qApp->unlock();
         qApp->processEvents();
@@ -572,7 +573,10 @@
     if (name.lower() == "program_info_del" && context == 1 && type == Delete)
         drawInfoBounds = area;
     if (name.lower() == "video")
+    {
         drawVideoBounds = area;
+        blackholeBounds = area;
+    }
     if (name.lower() == "group_info")
         drawGroupBounds = area;
     if (name.lower() == "usage")
@@ -689,11 +693,16 @@
         updateUsage(&p);
     }
 
-    if (r.intersects(drawVideoBounds))
+    if (r.intersects(drawVideoBounds) && !paintSkipUpdate)
     {
         updateVideo(&p);
     }
 
+    if (r.intersects(blackholeBounds))
+    {
+        drawVideo(&p);
+    }
+
     paintSkipCount--;
     if (paintSkipCount < 0)
     {
@@ -986,6 +995,30 @@
 
 void PlaybackBox::updateVideo(QPainter *p)
 {
+    if (!(previewVideoEnabled && previewPixmapEnabled))
+    {
+        return;
+    }
+
+    LayerSet *container = NULL;
+    container = theme->GetSet("video");
+    UIBlackHoleType *blackhole = NULL;
+    blackhole = (UIBlackHoleType *)container->GetType("video_blackhole");
+    if (blackhole)
+    {
+        blackholeBounds = blackhole->getScreenArea();
+        QPixmap pix(drawVideoBounds.size());
+        pix.fill(this, drawVideoBounds.topLeft());
+        QPainter tmp(&pix);
+        container->Draw(&tmp, 1, 1);
+        tmp.end();
+        p->drawPixmap(drawVideoBounds.topLeft(), pix);
+    }
+}
+
+void PlaybackBox::drawVideo(QPainter *p)
+{
+
     if (playbackVideoContainer)
     {
         m_player->DrawUnusedRects(false);
@@ -1007,14 +1040,23 @@
         if (temp.width() > 0)
         {
             int pixmap_y = 0;
+            int pixmap_x = 0;
 
-            if (temp.height() < drawVideoBounds.height())
-                pixmap_y = drawVideoBounds.y() + 
-                                (drawVideoBounds.height() - temp.height())/2;
+            // Centre preview in the y axis
+            if (temp.height() < blackholeBounds.height())
+                pixmap_y = blackholeBounds.y() + 
+                                (blackholeBounds.height() - temp.height()) / 2;
             else
-                pixmap_y = drawVideoBounds.y();
+                pixmap_y = blackholeBounds.y();
 
-            p->drawPixmap(drawVideoBounds.x(), pixmap_y, temp);
+            // Centre preview in the x axis
+            if (temp.width() < blackholeBounds.width())
+                pixmap_x = blackholeBounds.x() + 
+                                (blackholeBounds.width() - temp.width()) / 2;
+            else
+                pixmap_x = blackholeBounds.x();
+
+            p->drawPixmap(pixmap_x, pixmap_y, temp);
         }
     }
 
@@ -1082,7 +1124,7 @@
             if (previewVideoNVP->IsPlaying())
             {
                 previewVideoState = kPlaying;
-                erase(drawVideoBounds);
+                erase(blackholeBounds);
             }
         }
         else
@@ -1111,7 +1153,7 @@
     if ((previewVideoState == kPlaying) && previewVideoNVP->IsPlaying() &&
         !playingSomething)
     {
-        QSize size = drawVideoBounds.size();
+        QSize size = blackholeBounds.size();
         float saspect = ((float)size.width() / (float)size.height())  / wmult;
         float vaspect = previewVideoNVP->GetVideoAspect();
         size.setHeight((int) ceil(size.height() * (saspect / vaspect) * hmult));
@@ -1120,14 +1162,23 @@
         const QImage &img = previewVideoNVP->GetARGBFrame(size);
 
         int video_y = 0;
+        int video_x = 0;
 
-        if (img.height() < drawVideoBounds.height())
-            video_y = drawVideoBounds.y() + 
-                            (drawVideoBounds.height() - img.height())/2;
+        // Centre video in the y axis
+        if (img.height() < blackholeBounds.height())
+            video_y = blackholeBounds.y() + 
+                            (blackholeBounds.height() - img.height()) / 2;
         else
-            video_y = drawVideoBounds.y();
+            video_y = blackholeBounds.y();
 
-        p->drawImage(drawVideoBounds.x(), video_y, img);
+        // Centre video in the x axis
+        if (img.width() < blackholeBounds.width())
+            video_x = blackholeBounds.x() + 
+                            (blackholeBounds.width() - img.width()) / 2;
+        else
+            video_x = blackholeBounds.x();
+
+        p->drawImage(blackholeBounds.x(), video_y, img);
     }
 
     /* have we timed out waiting for nvp to start? */
@@ -3921,7 +3972,7 @@
         return;
 
     if (previewVideoEnabled)
-        update(drawVideoBounds);
+        update(blackholeBounds);
 }
 
 void PlaybackBox::processNetworkControlCommands(void)
@@ -4257,7 +4308,7 @@
         }
 
         // ask for repaint
-        update(drawVideoBounds);
+        update(blackholeBounds);
     }
     qApp->unlock();
 }
@@ -4408,20 +4459,34 @@
     {
         previewPixmap = new QPixmap();
 
-        if (drawVideoBounds.width() != image->width())
+        if (blackholeBounds.width() != image->width())
         {
-            VERBOSE(VB_IMPORTANT, QString("%1 %2 x %3").arg(drawVideoBounds.width())
-                                                     .arg(image->width())
-                                                     .arg(image->height()));
+            float blackholeaspect = ((float)blackholeBounds.width())
+                                    / ((float)blackholeBounds.height());
+            float videoaspect = ((float)image->width())
+                                    / ((float)image->height());
 
-            float scaleratio = ((float)drawVideoBounds.width() / wmult)
-                                    / (float)image->width();
-            int previewwidth = (int)drawVideoBounds.width();
-            int previewheight = (int)(image->height() * scaleratio * hmult);
+            float scaleratio = 1;
+            int previewwidth = blackholeBounds.width();
+            int previewheight = blackholeBounds.height();
 
-            VERBOSE(VB_IMPORTANT, QString("%1 x %2").arg(previewwidth)
-                                                     .arg(previewheight));
+            // Calculate new height orwidth according to relative aspect ratio
+            if (blackholeaspect > videoaspect)
+            {
+                scaleratio = (videoaspect / blackholeaspect) / hmult;
+                previewwidth = (int)(previewwidth * scaleratio * wmult);
+            }
+            else if (blackholeaspect < videoaspect)
+            {
+                scaleratio = (blackholeaspect / videoaspect) / wmult;
+                previewheight = (int)(previewheight * scaleratio * hmult);
+            }
 
+            // Ensure preview width/height are multiples of 8 to match
+            // the preview video
+            //previewwidth = ((previewwidth + 7) / 8) * 8;
+            //previewheight = ((previewheight + 7) / 8) * 8;
+
             QImage tmp2 = image->smoothScale(previewwidth, previewheight);
             previewPixmap->convertFromImage(tmp2);
         }
@@ -4433,8 +4498,8 @@
 
     if (!previewPixmap)
     {
-        previewPixmap = new QPixmap((int)(drawVideoBounds.width()),
-                                    (int)(drawVideoBounds.height()));
+        previewPixmap = new QPixmap((int)(blackholeBounds.width()),
+                                    (int)(blackholeBounds.height()));
         previewPixmap->fill(black);
     }
 
Index: mythtv/programs/mythfrontend/playbackbox.h
===================================================================
--- mythtv/programs/mythfrontend/playbackbox.h	(revision 14863)
+++ mythtv/programs/mythfrontend/playbackbox.h	(working copy)
@@ -298,6 +298,7 @@
     void grayOut(QPainter *);
     void updateBackground(void);
     void updateVideo(QPainter *);
+    void drawVideo(QPainter *);
     void updateShowTitles(QPainter *);
     void updateInfo(QPainter *);
     void updateUsage(QPainter *);
@@ -367,6 +368,7 @@
     QRect               drawGroupBounds;
     QRect               drawUsageBounds;
     QRect               drawVideoBounds;
+    QRect               blackholeBounds;
     QRect               drawCurGroupBounds;
 
     // Popup support //////////////////////////////////////////////////////////