Use always the same sizes for group layout.

For the floating point precision to matter less in the album layout
decisions use always full image sizes for layout
when sending an album and when displaying it.

Fixes #5049.
This commit is contained in:
John Preston 2018-08-04 16:48:15 +03:00
parent 7bd289ed0f
commit 90f6642d33
4 changed files with 22 additions and 5 deletions

View File

@ -993,7 +993,7 @@ auto SendFilesBox::AlbumPreview::generateOrderedLayout() const
auto sizes = ranges::view::all(
_order
) | ranges::view::transform([&](int index) {
return _list.files[index].preview.size() / cIntRetinaFactor();
return _list.files[index].shownDimensions;
}) | ranges::to_vector;
auto layout = Ui::LayoutMediaGroup(

View File

@ -545,8 +545,8 @@ TextState HistoryPhoto::textState(QPoint point, StateRequest request) const {
}
QSize HistoryPhoto::sizeForGrouping() const {
const auto width = convertScale(_data->full->width());
const auto height = convertScale(_data->full->height());
const auto width = _data->full->width();
const auto height = _data->full->height();
return { std::max(width, 1), std::max(height, 1) };
}
@ -992,8 +992,12 @@ TextState HistoryVideo::textState(QPoint point, StateRequest request) const {
}
QSize HistoryVideo::sizeForGrouping() const {
const auto width = convertScale(_data->thumb->width());
const auto height = convertScale(_data->thumb->height());
const auto width = _data->dimensions.isEmpty()
? _data->thumb->width()
: _data->dimensions.width();
const auto height = _data->dimensions.isEmpty()
? _data->thumb->height()
: _data->dimensions.height();
return { std::max(width, 1), std::max(height, 1) };
}

View File

@ -41,6 +41,16 @@ bool ValidVideoForAlbum(const FileMediaInformation::Video &video) {
return ValidateThumbDimensions(width, height);
}
QSize PrepareShownDimensions(const QImage &preview) {
constexpr auto kMaxWidth = 1280;
constexpr auto kMaxHeight = 1280;
const auto result = preview.size();
return (result.width() > kMaxWidth || result.height() > kMaxHeight)
? result.scaled(kMaxWidth, kMaxHeight, Qt::KeepAspectRatio)
: result;
}
bool PrepareAlbumMediaIsWaiting(
QSemaphore &semaphore,
PreparedFile &file,
@ -69,6 +79,7 @@ bool PrepareAlbumMediaIsWaiting(
if (const auto image = base::get_if<Image>(
&file.information->media)) {
if (ValidPhotoForAlbum(*image)) {
file.shownDimensions = PrepareShownDimensions(image->data);
file.preview = Images::prepareOpaque(image->data.scaledToWidth(
std::min(previewWidth, convertScale(image->data.width()))
* cIntRetinaFactor(),
@ -80,6 +91,7 @@ bool PrepareAlbumMediaIsWaiting(
&file.information->media)) {
if (ValidVideoForAlbum(*video)) {
auto blurred = Images::prepareBlur(Images::prepareOpaque(video->thumbnail));
file.shownDimensions = PrepareShownDimensions(video->thumbnail);
file.preview = std::move(blurred).scaledToWidth(
previewWidth * cIntRetinaFactor(),
Qt::SmoothTransformation);

View File

@ -37,6 +37,7 @@ struct PreparedFile {
QString mime;
std::unique_ptr<FileMediaInformation> information;
QImage preview;
QSize shownDimensions;
AlbumType type = AlbumType::None;
};