Ticket #3771: 031-preview.scale.patch

File 031-preview.scale.patch, 8.4 KB (added by Bill <cizek@…>, 16 years ago)

Updated patch

  • mythtv/programs/mythfrontend/playbackbox.cpp

    diff -r -u -X diff.exclude myth.14823.1109a/mythtv/programs/mythfrontend/playbackbox.cpp myth.14826.1109a/mythtv/programs/mythfrontend/playbackbox.cpp
     
    570570        drawInfoBounds = area;
    571571    if (name.lower() == "program_info_del" && context == 1 && type == Delete)
    572572        drawInfoBounds = area;
    573     if (name.lower() == "video")
     573    if (name.lower() == "video") {
    574574        drawVideoBounds = area;
     575        QSize size = drawVideoBounds.size();
     576        drawVideoBoundsAspect = ((float)size.width()) / ((float)size.height());
     577        previewVideoAspect = drawVideoBoundsAspect;
     578    }
    575579    if (name.lower() == "group_info")
    576580        drawGroupBounds = area;
    577581    if (name.lower() == "usage")
     
    10051009        QPixmap temp = getPixmap(curitem);
    10061010        if (temp.width() > 0)
    10071011        {
    1008             int pixmap_y = 0;
    1009 
    1010             if (temp.height() < drawVideoBounds.height())
    1011                 pixmap_y = drawVideoBounds.y() +
    1012                                 (drawVideoBounds.height() - temp.height())/2;
     1012            if (temp.size() == drawVideoBounds.size())
     1013            {
     1014                p->drawPixmap(drawVideoBounds.x(), drawVideoBounds.y(), temp);
     1015            }
    10131016            else
    1014                 pixmap_y = drawVideoBounds.y();
     1017            {
     1018                QSize size = drawVideoBounds.size();
     1019                int voffset = 0, hoffset = 0;
     1020                float vaspect = ((float) temp.width()) / ((float) temp.height());
     1021
     1022                if ( drawVideoBoundsAspect > vaspect)
     1023                {
     1024                   // The aspect ratio of the preview window is greater than that of the image
     1025                   // being displayed.  This can happen when trying to display a 4:3 image
     1026                   // in a 16:9 window.  We need to calculate the width of the image.
     1027                   size.setWidth( size.height() * vaspect );
     1028                }
     1029                else if (vaspect > drawVideoBoundsAspect && vaspect > 0.0)
     1030                {
     1031                   // The aspect ratio of the preview window is smaller than that of the image
     1032                   // being displayed.  This can happen when trying to display a 16:9 image
     1033                   // in a 4:3 window.  We need to calculate the height of the image.
     1034                   size.setHeight( size.width() / vaspect );
     1035                }
     1036
     1037                size.setHeight(((size.height() + 7) / 8) * 8);
     1038                size.setWidth( ((size.width()  + 7) / 8) * 8);
     1039
     1040                hoffset = (drawVideoBounds.width() - size.width()) / 2;
     1041                voffset = (drawVideoBounds.height() - size.height()) / 2;
     1042
     1043                if (hoffset > 0)
     1044                {
     1045                    QSize barsize = drawVideoBounds.size();
     1046                    barsize.setWidth(hoffset);
     1047                    QPixmap qpm(barsize);
     1048                    qpm.fill(black);
     1049                    p->drawPixmap(drawVideoBounds.x(), drawVideoBounds.y(), qpm);
     1050                    p->drawPixmap(drawVideoBounds.x()+drawVideoBounds.width()-hoffset, drawVideoBounds.y(), qpm);
     1051                }
     1052                if (voffset > 0)
     1053                {
     1054                    QSize barsize = drawVideoBounds.size();
     1055                    barsize.setHeight(voffset);
     1056                    QPixmap qpm(barsize);
     1057                    qpm.fill(black);
     1058                    p->drawPixmap(drawVideoBounds.x(), drawVideoBounds.y(), qpm);
     1059                    p->drawPixmap(drawVideoBounds.x(), drawVideoBounds.y()+drawVideoBounds.height()-(voffset-1), qpm);
     1060                }
     1061
     1062                // Scale and draw the preview image
     1063                QImage previewImg = temp.convertToImage();
     1064                QImage previewImgScaled = previewImg.smoothScale (size.width(), size.height());
    10151065
    1016             p->drawPixmap(drawVideoBounds.x(), pixmap_y, temp);
     1066                p->drawImage(drawVideoBounds.x() + hoffset, drawVideoBounds.y() + voffset, previewImgScaled);
     1067            }
    10171068        }
    10181069    }
    10191070
     
    10671118        previewVideoState = kStarting;
    10681119    }
    10691120
     1121    if (previewVideoState == kStarting)
     1122        previewVideoAspect = 0.0;
     1123
    10701124    if ((previewVideoState == kStarting) &&
    10711125        (!previewVideoStartTimerOn ||
    10721126         (previewVideoStartTimer.elapsed() > 500)))
     
    10791133        if (previewVideoNVP)
    10801134        {
    10811135            if (previewVideoNVP->IsPlaying())
    1082             {
    10831136                previewVideoState = kPlaying;
    1084                 erase(drawVideoBounds);
    1085             }
    10861137        }
    10871138        else
    10881139        {
     
    11111162        !playingSomething)
    11121163    {
    11131164        QSize size = drawVideoBounds.size();
    1114         float saspect = ((float)size.width() / (float)size.height())  / wmult;
     1165        int voffset = 0, hoffset = 0;
    11151166        float vaspect = previewVideoNVP->GetVideoAspect();
    1116         size.setHeight((int) ceil(size.height() * (saspect / vaspect) * hmult));
     1167
     1168        if ( drawVideoBoundsAspect > vaspect) {
     1169           // The aspect ratio of the preview window is greater than that of the image
     1170           // being displayed.  This can happen when trying to display a 4:3 image
     1171           // in a 16:9 window.  We need to calculate the width of the image.
     1172           size.setWidth( size.height() * vaspect );
     1173
     1174        } else if (vaspect > drawVideoBoundsAspect && vaspect > 0.0) {
     1175           // The aspect ratio of the preview window is smaller than that of the image
     1176           // being displayed.  This can happen when trying to display a 16:9 image
     1177           // in a 4:3 window.  We need to calculate the height of the image
     1178           size.setHeight( size.width() / vaspect );
     1179        }
     1180
    11171181        size.setHeight(((size.height() + 7) / 8) * 8);
    11181182        size.setWidth( ((size.width()  + 7) / 8) * 8);
    1119         const QImage &img = previewVideoNVP->GetARGBFrame(size);
    11201183
    1121         int video_y = 0;
     1184        hoffset = (drawVideoBounds.width() - size.width()) / 2;
     1185        voffset = (drawVideoBounds.height() - size.height()) / 2;
    11221186
    1123         if (img.height() < drawVideoBounds.height())
    1124             video_y = drawVideoBounds.y() +
    1125                             (drawVideoBounds.height() - img.height())/2;
    1126         else
    1127             video_y = drawVideoBounds.y();
     1187        if (hoffset > 0 || voffset > 0) {
     1188            if (previewVideoAspect != vaspect) {
     1189                // If the Aspect ratio has changed draw the black bars either above and below the image,
     1190                // or on either side of the image.
     1191                previewVideoAspect = vaspect;
     1192
     1193                if (hoffset > 0) {
     1194                    QSize barsize = drawVideoBounds.size();
     1195                    barsize.setWidth(hoffset);
     1196                    QPixmap qpm(barsize);
     1197                    qpm.fill(black);
     1198                    p->drawPixmap(drawVideoBounds.x(), drawVideoBounds.y(), qpm);
     1199                    p->drawPixmap(drawVideoBounds.x()+drawVideoBounds.width()-hoffset, drawVideoBounds.y(), qpm);
     1200                }
     1201                if (voffset > 0) {
     1202                    QSize barsize = drawVideoBounds.size();
     1203                    barsize.setHeight(voffset);
     1204                    QPixmap qpm(barsize);
     1205                    qpm.fill(black);
     1206                    p->drawPixmap(drawVideoBounds.x(), drawVideoBounds.y(), qpm);
     1207                    p->drawPixmap(drawVideoBounds.x(), drawVideoBounds.y()+drawVideoBounds.height()-voffset, qpm);
     1208                }
     1209            }
     1210        }
     1211
     1212        const QImage &img = previewVideoNVP->GetARGBFrame(size);
    11281213
    1129         p->drawImage(drawVideoBounds.x(), video_y, img);
     1214        p->drawImage(drawVideoBounds.x() + hoffset, drawVideoBounds.y() + voffset, img);
    11301215    }
    11311216
    11321217    /* have we timed out waiting for nvp to start? */
  • mythtv/programs/mythfrontend/playbackbox.h

    diff -r -u -X diff.exclude myth.14823.1109a/mythtv/programs/mythfrontend/playbackbox.h myth.14826.1109a/mythtv/programs/mythfrontend/playbackbox.h
     
    372372    QRect               drawCurGroupBounds;
    373373    QRect               drawSortOrderBounds;
    374374
     375    // Aspect ratio cache for previews
     376    float               drawVideoBoundsAspect;
     377    float               previewVideoAspect;
     378
    375379    // Popup support //////////////////////////////////////////////////////////
    376380    // General popup support
    377381    MythPopupBox       *popup;