diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index 5f6d8b128..31f3c93c0 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -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( diff --git a/Telegram/SourceFiles/history/history_media_types.cpp b/Telegram/SourceFiles/history/history_media_types.cpp index 942fcf9b3..23c658b22 100644 --- a/Telegram/SourceFiles/history/history_media_types.cpp +++ b/Telegram/SourceFiles/history/history_media_types.cpp @@ -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) }; } diff --git a/Telegram/SourceFiles/storage/storage_media_prepare.cpp b/Telegram/SourceFiles/storage/storage_media_prepare.cpp index 389f7d03e..4568c6edb 100644 --- a/Telegram/SourceFiles/storage/storage_media_prepare.cpp +++ b/Telegram/SourceFiles/storage/storage_media_prepare.cpp @@ -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( &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); diff --git a/Telegram/SourceFiles/storage/storage_media_prepare.h b/Telegram/SourceFiles/storage/storage_media_prepare.h index 20b31d6c6..7a5683169 100644 --- a/Telegram/SourceFiles/storage/storage_media_prepare.h +++ b/Telegram/SourceFiles/storage/storage_media_prepare.h @@ -37,6 +37,7 @@ struct PreparedFile { QString mime; std::unique_ptr information; QImage preview; + QSize shownDimensions; AlbumType type = AlbumType::None; };