| 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 | } |
| 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 | |
| | 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 | |