| 4588 | static QSize calc_preview_size(const QSize &bounds, const QSize &imageSize) |
| 4589 | { |
| 4590 | if ((bounds.width() == imageSize.width()) && (imageSize.height() <= bounds.height())) |
| 4591 | return imageSize; |
| 4592 | |
| 4593 | float blackholeaspect = ((float)bounds.width()) / ((float)bounds.height()); |
| 4594 | float videoaspect = ((float)imageSize.width()) / ((float)imageSize.height()); |
| 4595 | float scaleratio = 1.0f; |
| 4596 | int previewwidth = bounds.width(); |
| 4597 | int previewheight = bounds.height(); |
| 4598 | |
| 4599 | // Calculate new height or width according to relative aspect ratio |
| 4600 | if ((int)((blackholeaspect + 0.05f) * 10) > (int)((videoaspect + 0.05f) * 10)) |
| 4601 | { |
| 4602 | scaleratio = (videoaspect / blackholeaspect); |
| 4603 | previewwidth = (int)(previewwidth * scaleratio); |
| 4604 | } |
| 4605 | else if ((int)((blackholeaspect + 0.05f) * 10) < (int)((videoaspect + 0.05f) * 10)) |
| 4606 | { |
| 4607 | scaleratio = (blackholeaspect / videoaspect); |
| 4608 | previewheight = (int)(previewheight * scaleratio); |
| 4609 | } |
| 4610 | |
| 4611 | // Ensure preview width/height are multiples of 8 to match |
| 4612 | // the preview video |
| 4613 | //previewwidth = ((previewwidth + 7) / 8) * 8; |
| 4614 | //previewheight = ((previewheight + 7) / 8) * 8; |
| 4615 | |
| 4616 | return QSize(previewwidth, previewheight); |
| 4617 | } |
| 4618 | |
4719 | | float blackholeaspect = ((float)blackholeBounds.width()) |
4720 | | / ((float)blackholeBounds.height()); |
4721 | | float videoaspect = ((float)image->width()) |
4722 | | / ((float)image->height()); |
4723 | | |
4724 | | float scaleratio = 1; |
4725 | | int previewwidth = blackholeBounds.width(); |
4726 | | int previewheight = blackholeBounds.height(); |
4727 | | |
4728 | | // Calculate new height or width according to relative aspect ratio |
4729 | | if ((int)((blackholeaspect + 0.05) * 10) > (int)((videoaspect + 0.05) * 10)) |
4730 | | { |
4731 | | scaleratio = (videoaspect / blackholeaspect); |
4732 | | previewwidth = (int)(previewwidth * scaleratio); |
4733 | | } |
4734 | | else if ((int)((blackholeaspect + 0.05) * 10) < (int)((videoaspect + 0.05) * 10)) |
4735 | | { |
4736 | | scaleratio = (blackholeaspect / videoaspect); |
4737 | | previewheight = (int)(previewheight * scaleratio); |
4738 | | } |
4739 | | |
4740 | | // Ensure preview width/height are multiples of 8 to match |
4741 | | // the preview video |
4742 | | //previewwidth = ((previewwidth + 7) / 8) * 8; |
4743 | | //previewheight = ((previewheight + 7) / 8) * 8; |
4744 | | |
4745 | | QImage tmp2 = image->smoothScale(previewwidth, previewheight); |
4746 | | previewPixmap->convertFromImage(tmp2); |
| 4759 | VERBOSE(VB_IMPORTANT, "previewPixmap 3"); |
| 4760 | previewPixmap->convertFromImage(*image); |