Ticket #3771: preview.scale.patch

File preview.scale.patch, 7.6 KB (added by Bill <cizek@…>, 17 years ago)
  • mythtv/programs/mythfrontend/playbackbox.cpp

    diff -r -u -X diff.exclude myth.14030.0722a/mythtv/programs/mythfrontend/playbackbox.cpp myth.14030.0722b/mythtv/programs/mythfrontend/playbackbox.cpp
     
    571571    if (name.lower() == "program_info_del" && context == 1 && type == Delete)
    572572        drawInfoBounds = area;
    573573    if (name.lower() == "video")
     574    {
    574575        drawVideoBounds = area;
     576        QSize size = drawVideoBounds.size();
     577        drawVideoBoundsAspect = ((float)size.width()) / ((float)size.height());
     578        previewVideoAspect = drawVideoBoundsAspect;
     579    }
    575580    if (name.lower() == "group_info")
    576581        drawGroupBounds = area;       
    577582    if (name.lower() == "usage")
     
    10031008    {
    10041009        QPixmap temp = getPixmap(curitem);
    10051010        if (temp.width() > 0)
    1006             p->drawPixmap(drawVideoBounds.x(), drawVideoBounds.y(), temp);
     1011        {
     1012            if (temp.size() == drawVideoBounds.size())
     1013            {
     1014                p->drawPixmap(drawVideoBounds.x(), drawVideoBounds.y(), temp);
     1015            }
     1016            else
     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                   // The aspect ratio of the preview window is greater than that of the image
     1024                   // being displayed.  This can happen when trying to display a 4:3 image
     1025                   // in a 16:9 window.  We need to calculate the width of the image.
     1026                   size.setWidth( size.height() * vaspect );
     1027
     1028                } else if (vaspect > drawVideoBoundsAspect && vaspect > 0.0) {
     1029                   // The aspect ratio of the preview window is smaller than that of the image
     1030                   // being displayed.  This can happen when trying to display a 16:9 image
     1031                   // in a 4:3 window.  We need to calculate the height of the image.
     1032                   size.setHeight( size.width() / vaspect );
     1033                }
     1034
     1035                size.setHeight(((size.height() + 7) / 8) * 8);
     1036                size.setWidth( ((size.width()  + 7) / 8) * 8);
     1037
     1038                hoffset = (drawVideoBounds.width() - size.width()) / 2;
     1039                voffset = (drawVideoBounds.height() - size.height()) / 2;
     1040
     1041
     1042                if (hoffset > 0) {
     1043                    QSize barsize = drawVideoBounds.size();
     1044                    barsize.setWidth(hoffset);
     1045                    QPixmap qpm(barsize);
     1046                    qpm.fill(black);
     1047                    p->drawPixmap(drawVideoBounds.x(), drawVideoBounds.y(), qpm);
     1048                    p->drawPixmap(drawVideoBounds.x()+drawVideoBounds.width()-hoffset, drawVideoBounds.y(), qpm);
     1049                }
     1050                if (voffset > 0) {
     1051                    QSize barsize = drawVideoBounds.size();
     1052                    barsize.setHeight(voffset);
     1053                    QPixmap qpm(barsize);
     1054                    qpm.fill(black);
     1055                    p->drawPixmap(drawVideoBounds.x(), drawVideoBounds.y(), qpm);
     1056                    p->drawPixmap(drawVideoBounds.x(), drawVideoBounds.y()+drawVideoBounds.height()-(voffset-1), qpm);
     1057                }
     1058         
     1059                // Scale and draw the preview image
     1060                QImage previewImg = temp.convertToImage();
     1061                QImage previewImgScaled = previewImg.smoothScale (size.width(), size.height());
     1062
     1063                p->drawImage(drawVideoBounds.x() + hoffset, drawVideoBounds.y() + voffset, previewImgScaled);
     1064
     1065            }
     1066        }
    10071067    }
    10081068
    10091069    /* keep calling killPlayer() to handle nvp cleanup */
     
    10561116        previewVideoState = kStarting;
    10571117    }
    10581118
     1119    if (previewVideoState == kStarting)
     1120        previewVideoAspect = 0.0;
     1121
    10591122    if ((previewVideoState == kStarting) &&
    10601123        (!previewVideoStartTimerOn ||
    10611124         (previewVideoStartTimer.elapsed() > 500)))
     
    10971160        !playingSomething)
    10981161    {
    10991162        QSize size = drawVideoBounds.size();
    1100         float saspect = ((float)size.width()) / ((float)size.height());
     1163        int voffset = 0, hoffset = 0;
    11011164        float vaspect = previewVideoNVP->GetVideoAspect();
    1102         size.setHeight((int) ceil(size.height() * (saspect / vaspect)));
     1165
     1166        if ( drawVideoBoundsAspect > vaspect) {
     1167           // The aspect ratio of the preview window is greater than that of the image
     1168           // being displayed.  This can happen when trying to display a 4:3 image
     1169           // in a 16:9 window.  We need to calculate the width of the image.
     1170           size.setWidth( size.height() * vaspect );
     1171
     1172        } else if (vaspect > drawVideoBoundsAspect && vaspect > 0.0) {
     1173           // The aspect ratio of the preview window is smaller than that of the image
     1174           // being displayed.  This can happen when trying to display a 16:9 image
     1175           // in a 4:3 window.  We need to calculate the height of the image
     1176           size.setHeight( size.width() / vaspect );
     1177        }
     1178
    11031179        size.setHeight(((size.height() + 7) / 8) * 8);
    11041180        size.setWidth( ((size.width()  + 7) / 8) * 8);
     1181
     1182        hoffset = (drawVideoBounds.width() - size.width()) / 2;
     1183        voffset = (drawVideoBounds.height() - size.height()) / 2;
     1184
     1185        if (hoffset > 0 || voffset > 0) {
     1186            if (previewVideoAspect != vaspect) {
     1187                // If the Aspect ratio has changed draw the black bars either above and below the image,
     1188                // or on either side of the image.
     1189                previewVideoAspect = vaspect;
     1190
     1191                if (hoffset > 0) {
     1192                    QSize barsize = drawVideoBounds.size();
     1193                    barsize.setWidth(hoffset);
     1194                    QPixmap qpm(barsize);
     1195                    qpm.fill(black);
     1196                    p->drawPixmap(drawVideoBounds.x(), drawVideoBounds.y(), qpm);
     1197                    p->drawPixmap(drawVideoBounds.x()+drawVideoBounds.width()-hoffset, drawVideoBounds.y(), qpm);
     1198                }
     1199                if (voffset > 0) {
     1200                    QSize barsize = drawVideoBounds.size();
     1201                    barsize.setHeight(voffset);
     1202                    QPixmap qpm(barsize);
     1203                    qpm.fill(black);
     1204                    p->drawPixmap(drawVideoBounds.x(), drawVideoBounds.y(), qpm);
     1205                    p->drawPixmap(drawVideoBounds.x(), drawVideoBounds.y()+drawVideoBounds.height()-voffset, qpm);
     1206                }
     1207            }
     1208        }
     1209
    11051210        const QImage &img = previewVideoNVP->GetARGBFrame(size);
    1106         p->drawImage(drawVideoBounds.x(), drawVideoBounds.y(), img);
     1211        p->drawImage(drawVideoBounds.x() + hoffset, drawVideoBounds.y() + voffset, img);
    11071212    }
    11081213
    11091214    /* have we timed out waiting for nvp to start? */
  • mythtv/programs/mythfrontend/playbackbox.h

    Only in myth.14030.0722a/mythtv/programs/mythfrontend: playbackbox.cpp~
    diff -r -u -X diff.exclude myth.14030.0722a/mythtv/programs/mythfrontend/playbackbox.h myth.14030.0722b/mythtv/programs/mythfrontend/playbackbox.h
     
    365365    QRect               drawVideoBounds;
    366366    QRect               drawCurGroupBounds;
    367367
     368    // Aspect ratio cache for previews
     369    float               drawVideoBoundsAspect;
     370    float               previewVideoAspect;
     371
    368372    // Popup support //////////////////////////////////////////////////////////
    369373    // General popup support
    370374    MythPopupBox       *popup;