From 36fbdfb380310f04954dfd815ba047f7d8ac9dbc Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 29 May 2020 19:10:25 +0400 Subject: [PATCH] Simplify Image, remove ImageSource. --- Telegram/CMakeLists.txt | 2 - .../boxes/background_preview_box.cpp | 2 +- Telegram/SourceFiles/boxes/confirm_box.cpp | 1 - .../SourceFiles/boxes/edit_caption_box.cpp | 8 +- .../SourceFiles/boxes/sticker_set_box.cpp | 2 +- Telegram/SourceFiles/boxes/stickers_box.cpp | 2 +- Telegram/SourceFiles/calls/calls_panel.cpp | 11 +- Telegram/SourceFiles/calls/calls_panel.h | 2 +- .../chat_helpers/field_autocomplete.cpp | 2 +- .../chat_helpers/stickers_emoji_pack.cpp | 6 +- .../chat_helpers/stickers_list_widget.cpp | 7 +- .../SourceFiles/chat_helpers/stickers_set.cpp | 5 +- Telegram/SourceFiles/data/data_cloud_file.cpp | 9 +- Telegram/SourceFiles/data/data_cloud_file.h | 6 +- Telegram/SourceFiles/data/data_document.cpp | 1 - .../SourceFiles/data/data_document_media.cpp | 33 +-- .../SourceFiles/data/data_document_media.h | 2 +- .../SourceFiles/data/data_media_types.cpp | 1 - Telegram/SourceFiles/data/data_peer.cpp | 20 +- Telegram/SourceFiles/data/data_photo.cpp | 1 - .../SourceFiles/data/data_photo_media.cpp | 15 +- .../SourceFiles/data/data_reply_preview.cpp | 8 +- Telegram/SourceFiles/data/data_session.cpp | 7 +- Telegram/SourceFiles/data/data_wall_paper.h | 2 +- Telegram/SourceFiles/data/data_web_page.cpp | 1 - .../history/history_item_components.cpp | 2 +- .../SourceFiles/history/history_widget.cpp | 12 +- .../view/media/history_view_document.cpp | 4 +- .../history/view/media/history_view_gif.cpp | 21 +- .../view/media/history_view_large_emoji.cpp | 5 +- .../view/media/history_view_location.cpp | 2 +- .../history/view/media/history_view_photo.cpp | 18 +- .../view/media/history_view_sticker.cpp | 17 +- .../view/media/history_view_web_page.cpp | 6 +- .../inline_bot_layout_internal.cpp | 10 +- Telegram/SourceFiles/mainwidget.cpp | 4 +- .../media/view/media_view_group_thumbs.cpp | 3 +- .../media/view/media_view_overlay_widget.cpp | 9 +- .../SourceFiles/media/view/media_view_pip.cpp | 4 +- .../SourceFiles/overview/overview_layout.cpp | 35 +-- .../SourceFiles/platform/mac/mac_touchbar.mm | 1 - .../win/notifications_manager_win.cpp | 2 +- .../SourceFiles/settings/settings_chat.cpp | 4 +- Telegram/SourceFiles/ui/image/image.cpp | 255 +++++++----------- Telegram/SourceFiles/ui/image/image.h | 146 ++++------ Telegram/SourceFiles/ui/image/image_source.h | 31 --- .../window/notifications_utilities.cpp | 38 +-- .../window/notifications_utilities.h | 17 +- .../window/window_media_preview.cpp | 16 +- 49 files changed, 306 insertions(+), 512 deletions(-) delete mode 100644 Telegram/SourceFiles/ui/image/image_source.h diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 1db53bfdee..385c9e9a9f 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -935,8 +935,6 @@ PRIVATE ui/image/image_location.h ui/image/image_location_factory.cpp ui/image/image_location_factory.h - ui/image/image_source.cpp - ui/image/image_source.h ui/widgets/continuous_sliders.cpp ui/widgets/continuous_sliders.h ui/widgets/discrete_sliders.cpp diff --git a/Telegram/SourceFiles/boxes/background_preview_box.cpp b/Telegram/SourceFiles/boxes/background_preview_box.cpp index aef4698736..db5c71fc85 100644 --- a/Telegram/SourceFiles/boxes/background_preview_box.cpp +++ b/Telegram/SourceFiles/boxes/background_preview_box.cpp @@ -659,7 +659,7 @@ bool BackgroundPreviewBox::setScaledFromThumb() { : _media ? _media->thumbnail() : nullptr; - if (!thumbnail || !thumbnail->loaded()) { + if (!thumbnail) { return false; } else if (_paper.isPattern() && _paper.document() != nullptr) { return false; diff --git a/Telegram/SourceFiles/boxes/confirm_box.cpp b/Telegram/SourceFiles/boxes/confirm_box.cpp index 65581f5482..4f346f6336 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_box.cpp @@ -979,7 +979,6 @@ void ConfirmInviteBox::paintEvent(QPaintEvent *e) { (width() - st::confirmInvitePhotoSize) / 2, st::confirmInvitePhotoTop, image->pixCircled( - Data::FileOrigin(), st::confirmInvitePhotoSize, st::confirmInvitePhotoSize)); } diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index d3f85ffaa5..d308434cbc 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -132,7 +132,7 @@ EditCaptionBox::EditCaptionBox( | Images::Option::RoundedBottomLeft | Images::Option::RoundedBottomRight; _thumb = App::pixmapFromImageInPlace(Images::prepare( - image->pix(_msgId).toImage(), + image->original(), _thumbw * cIntRetinaFactor(), 0, options, @@ -180,7 +180,6 @@ EditCaptionBox::EditCaptionBox( const auto options = Images::Option::Smooth | Images::Option::Blurred; _thumb = image->pixNoCache( - _msgId, maxW * cIntRetinaFactor(), maxH * cIntRetinaFactor(), options, @@ -206,7 +205,6 @@ EditCaptionBox::EditCaptionBox( ? Images::Option::Blurred : Images::Option(0)); _thumb = use->pixNoCache( - _msgId, maxW * cIntRetinaFactor(), maxH * cIntRetinaFactor(), options, @@ -282,7 +280,7 @@ EditCaptionBox::EditCaptionBox( _thumbnailImageLoaded = _photoMedia ? (_photoMedia->image(Data::PhotoSize::Large) != nullptr) : _thumbnailImage - ? _thumbnailImage->loaded() + ? true : _documentMedia ? !_documentMedia->owner()->hasThumbnail() : true; @@ -299,7 +297,7 @@ EditCaptionBox::EditCaptionBox( && _documentMedia->owner()->hasThumbnail()) { _thumbnailImage = _documentMedia->thumbnail(); } - if (_thumbnailImage && _thumbnailImage->loaded()) { + if (_thumbnailImage) { _thumbnailImageLoaded = !_photoMedia || _photoMedia->image(PhotoSize::Large); if (_thumbnailImageLoaded) { diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.cpp b/Telegram/SourceFiles/boxes/sticker_set_box.cpp index 321f737d24..39c8b7264c 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.cpp +++ b/Telegram/SourceFiles/boxes/sticker_set_box.cpp @@ -665,7 +665,7 @@ void StickerSetBox::Inner::paintSticker( p.drawPixmapLeft( ppos, width(), - image->pix(document->stickerSetOrigin(), w, h)); + image->pix(w, h)); } } diff --git a/Telegram/SourceFiles/boxes/stickers_box.cpp b/Telegram/SourceFiles/boxes/stickers_box.cpp index 2d33d3f00b..7cf63db7ec 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.cpp +++ b/Telegram/SourceFiles/boxes/stickers_box.cpp @@ -940,7 +940,7 @@ void StickersBox::Inner::paintRowThumbnail( left + (st::contactsPhotoSize - row->pixw) / 2, st::contactsPadding.top() + (st::contactsPhotoSize - row->pixh) / 2, width(), - thumb->pix(origin, row->pixw, row->pixh)); + thumb->pix(row->pixw, row->pixh)); } else if (row->lottie->ready()) { const auto frame = row->lottie->frame(); const auto size = frame.size() / cIntRetinaFactor(); diff --git a/Telegram/SourceFiles/calls/calls_panel.cpp b/Telegram/SourceFiles/calls/calls_panel.cpp index 43bcd81dc6..049e6c46de 100644 --- a/Telegram/SourceFiles/calls/calls_panel.cpp +++ b/Telegram/SourceFiles/calls/calls_panel.cpp @@ -539,17 +539,13 @@ void Panel::refreshUserPhoto() { if (isNewBigPhoto) { _userPhotoId = _photo->owner()->id; _userPhotoFull = true; - createUserpicCache( - _photo->image(Data::PhotoSize::Large), - _user->userpicPhotoOrigin()); + createUserpicCache(_photo->image(Data::PhotoSize::Large)); } else if (_userPhoto.isNull()) { - createUserpicCache( - _userpic ? _userpic->image() : nullptr, - _user->userpicOrigin()); + createUserpicCache(_userpic ? _userpic->image() : nullptr); } } -void Panel::createUserpicCache(Image *image, Data::FileOrigin origin) { +void Panel::createUserpicCache(Image *image) { auto size = st::callWidth * cIntRetinaFactor(); auto options = _useTransparency ? (Images::Option::RoundedLarge | Images::Option::RoundedTopLeft | Images::Option::RoundedTopRight | Images::Option::Smooth) : Images::Option::None; if (image) { @@ -563,7 +559,6 @@ void Panel::createUserpicCache(Image *image, Data::FileOrigin origin) { width = size; } _userPhoto = image->pixNoCache( - origin, width, height, options, diff --git a/Telegram/SourceFiles/calls/calls_panel.h b/Telegram/SourceFiles/calls/calls_panel.h index ffa69a8443..a674cb66df 100644 --- a/Telegram/SourceFiles/calls/calls_panel.h +++ b/Telegram/SourceFiles/calls/calls_panel.h @@ -101,7 +101,7 @@ private: void processUserPhoto(); void refreshUserPhoto(); bool isGoodUserPhoto(PhotoData *photo); - void createUserpicCache(Image *image, Data::FileOrigin origin); + void createUserpicCache(Image *image); QRect signalBarsRect() const; void paintSignalBarsBg(Painter &p); diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp index f815a660e4..dbde3fd92f 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp @@ -685,7 +685,7 @@ void FieldAutocompleteInner::paintEvent(QPaintEvent *e) { } } else if (const auto image = media->getStickerSmall()) { QPoint ppos = pos + QPoint((st::stickerPanSize.width() - w) / 2, (st::stickerPanSize.height() - h) / 2); - p.drawPixmapLeft(ppos, width(), image->pix(document->stickerSetOrigin(), w, h)); + p.drawPixmapLeft(ppos, width(), image->pix(w, h)); } } } diff --git a/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.cpp b/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.cpp index 4654a2bddd..2b206ae70a 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.cpp @@ -11,7 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lottie/lottie_common.h" #include "ui/emoji_config.h" #include "ui/text/text_isolated_emoji.h" -#include "ui/image/image_source.h" +#include "ui/image/image.h" #include "main/main_session.h" #include "data/data_file_origin.h" #include "data/data_session.h" @@ -310,9 +310,7 @@ std::shared_ptr EmojiPack::image(EmojiPtr emoji) { if (const auto strong = i->second.lock()) { if (!strong->image) { strong->load = nullptr; - strong->image.emplace( - std::make_unique( - std::move(image))); + strong->image.emplace(std::move(image)); _session->downloaderTaskFinished().notify(); } } diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index dba484ed4f..c04e2b05d7 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -788,8 +788,8 @@ void StickersListWidget::Footer::paintSetIcon( || (!icon.lottie->ready() && !icon.savedFrame.isNull())) { const auto pixmap = !icon.savedFrame.isNull() ? icon.savedFrame - : (!icon.lottie && thumb && thumb->loaded()) - ? thumb->pix(origin, icon.pixw, icon.pixh) + : (!icon.lottie && thumb) + ? thumb->pix(icon.pixw, icon.pixh) : QPixmap(); if (pixmap.isNull()) { return; @@ -1866,9 +1866,8 @@ void StickersListWidget::paintSticker(Painter &p, Set &set, int y, int section, const auto image = media->getStickerSmall(); const auto pixmap = !sticker.savedFrame.isNull() ? sticker.savedFrame - : (image && image->loaded()) + : image ? image->pixSingle( - document->stickerSetOrigin(), w, h, w, diff --git a/Telegram/SourceFiles/chat_helpers/stickers_set.cpp b/Telegram/SourceFiles/chat_helpers/stickers_set.cpp index 6d74521570..c94e0c6d11 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_set.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_set.cpp @@ -11,7 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "data/data_file_origin.h" #include "storage/file_download.h" -#include "ui/image/image_source.h" +#include "ui/image/image.h" #include "app.h" namespace Stickers { @@ -30,8 +30,7 @@ void SetThumbnailView::set( if (image.isNull()) { _content = std::move(content); } else { - _image = std::make_unique( - std::make_unique(std::move(image))); + _image = std::make_unique(std::move(image)); } session->downloaderTaskFinished().notify(); } diff --git a/Telegram/SourceFiles/data/data_cloud_file.cpp b/Telegram/SourceFiles/data/data_cloud_file.cpp index 7ec7319dfe..7dcf88c8ba 100644 --- a/Telegram/SourceFiles/data/data_cloud_file.cpp +++ b/Telegram/SourceFiles/data/data_cloud_file.cpp @@ -11,7 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "storage/cache/storage_cache_database.h" #include "storage/file_download.h" -#include "ui/image/image_source.h" +#include "ui/image/image.h" #include "main/main_session.h" #include @@ -21,8 +21,7 @@ namespace Data { void CloudImageView::set( not_null session, QImage image) { - _image = std::make_unique( - std::make_unique(std::move(image))); + _image.emplace(std::move(image)); session->downloaderTaskFinished().notify(); } @@ -34,8 +33,8 @@ CloudImage::CloudImage( update(session, data); } -Image *CloudImageView::image() const { - return _image.get(); +Image *CloudImageView::image() { + return _image ? &*_image : nullptr; } void CloudImage::set( diff --git a/Telegram/SourceFiles/data/data_cloud_file.h b/Telegram/SourceFiles/data/data_cloud_file.h index fb5b187701..e295cd9ccb 100644 --- a/Telegram/SourceFiles/data/data_cloud_file.h +++ b/Telegram/SourceFiles/data/data_cloud_file.h @@ -8,10 +8,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "base/flags.h" +#include "ui/image/image.h" #include "ui/image/image_location.h" class FileLoader; -class Image; namespace Storage { namespace Cache { @@ -44,10 +44,10 @@ class CloudImageView final { public: void set(not_null session, QImage image); - [[nodiscard]] Image *image() const; + [[nodiscard]] Image *image(); private: - std::unique_ptr _image; + std::optional _image; }; diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index d2576d7e61..a9c63dfbc4 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -34,7 +34,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/cache/storage_cache_database.h" #include "boxes/confirm_box.h" #include "ui/image/image.h" -#include "ui/image/image_source.h" #include "ui/text/text_utilities.h" #include "base/base_file_utilities.h" #include "mainwindow.h" diff --git a/Telegram/SourceFiles/data/data_document_media.cpp b/Telegram/SourceFiles/data/data_document_media.cpp index 34b3f6ca6c..1f917b9de7 100644 --- a/Telegram/SourceFiles/data/data_document_media.cpp +++ b/Telegram/SourceFiles/data/data_document_media.cpp @@ -19,7 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history.h" #include "window/themes/window_theme_preview.h" #include "storage/file_download.h" -#include "ui/image/image_source.h" +#include "ui/image/image.h" #include "facades.h" #include "app.h" @@ -165,8 +165,7 @@ void DocumentMedia::setGoodThumbnail(QImage thumbnail) { if (!(_flags & Flag::GoodThumbnailWanted)) { return; } - _goodThumbnail = std::make_unique( - std::make_unique(std::move(thumbnail))); + _goodThumbnail = std::make_unique(std::move(thumbnail)); _owner->session().downloaderTaskFinished().notify(); } @@ -174,8 +173,7 @@ Image *DocumentMedia::thumbnailInline() const { if (!_inlineThumbnail) { auto image = Images::FromInlineBytes(_owner->inlineThumbnailBytes()); if (!image.isNull()) { - _inlineThumbnail = std::make_unique( - std::make_unique(std::move(image))); + _inlineThumbnail = std::make_unique(std::move(image)); } } return _inlineThumbnail.get(); @@ -200,8 +198,7 @@ QSize DocumentMedia::thumbnailSize() const { } void DocumentMedia::setThumbnail(QImage thumbnail) { - _thumbnail = std::make_unique( - std::make_unique(std::move(thumbnail))); + _thumbnail = std::make_unique(std::move(thumbnail)); _owner->session().downloaderTaskFinished().notify(); } @@ -232,7 +229,6 @@ void DocumentMedia::checkStickerLarge() { if (!data) { return; } - automaticLoad(_owner->stickerSetOrigin(), nullptr); if (data->animated || !loaded()) { return; @@ -240,13 +236,11 @@ void DocumentMedia::checkStickerLarge() { if (_bytes.isEmpty()) { const auto &loc = _owner->location(true); if (loc.accessEnable()) { - _sticker = std::make_unique( - std::make_unique(loc.name())); + _sticker = std::make_unique(loc.name()); loc.accessDisable(); } } else { - _sticker = std::make_unique( - std::make_unique(_bytes)); + _sticker = std::make_unique(_bytes); } } @@ -288,20 +282,16 @@ void DocumentMedia::automaticLoad( void DocumentMedia::collectLocalData(not_null local) { if (const auto image = local->_goodThumbnail.get()) { - _goodThumbnail = std::make_unique( - std::make_unique(image->original())); + _goodThumbnail = std::make_unique(image->original()); } if (const auto image = local->_inlineThumbnail.get()) { - _inlineThumbnail = std::make_unique( - std::make_unique(image->original())); + _inlineThumbnail = std::make_unique(image->original()); } if (const auto image = local->_thumbnail.get()) { - _thumbnail = std::make_unique( - std::make_unique(image->original())); + _thumbnail = std::make_unique(image->original()); } if (const auto image = local->_sticker.get()) { - _sticker = std::make_unique( - std::make_unique(image->original())); + _sticker = std::make_unique(image->original()); } _bytes = local->_bytes; _videoThumbnailBytes = local->_videoThumbnailBytes; @@ -373,8 +363,7 @@ void DocumentMedia::checkStickerLarge(not_null loader) { if (_owner->sticker() && !_sticker && !loader->imageData().isNull()) { - _sticker = std::make_unique( - std::make_unique(loader->imageData())); + _sticker = std::make_unique(loader->imageData()); } } diff --git a/Telegram/SourceFiles/data/data_document_media.h b/Telegram/SourceFiles/data/data_document_media.h index b153ce1a7c..d686a9573f 100644 --- a/Telegram/SourceFiles/data/data_document_media.h +++ b/Telegram/SourceFiles/data/data_document_media.h @@ -48,7 +48,7 @@ public: [[nodiscard]] not_null owner() const; void goodThumbnailWanted(); - [[nodiscard]] Image *goodThumbnail() const; // #TODO optimize QImage-wrap + [[nodiscard]] Image *goodThumbnail() const; void setGoodThumbnail(QImage thumbnail); [[nodiscard]] Image *thumbnailInline() const; diff --git a/Telegram/SourceFiles/data/data_media_types.cpp b/Telegram/SourceFiles/data/data_media_types.cpp index b4aeb88173..1b47c63dd5 100644 --- a/Telegram/SourceFiles/data/data_media_types.cpp +++ b/Telegram/SourceFiles/data/data_media_types.cpp @@ -25,7 +25,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/media/history_view_theme_document.h" #include "history/view/media/history_view_dice.h" #include "ui/image/image.h" -#include "ui/image/image_source.h" #include "ui/text_options.h" #include "ui/emoji_config.h" #include "storage/storage_shared_media.h" diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp index 370b12a7bd..5f4d3f50c4 100644 --- a/Telegram/SourceFiles/data/data_peer.cpp +++ b/Telegram/SourceFiles/data/data_peer.cpp @@ -28,7 +28,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwindow.h" #include "window/window_session_controller.h" #include "ui/image/image.h" -#include "ui/image/image_source.h" #include "ui/empty_userpic.h" #include "ui/text_options.h" #include "history/history.h" @@ -220,10 +219,9 @@ Image *PeerData::currentUserpic( _userpicEmpty = nullptr; } else if (isNotificationsUser()) { static auto result = Image( - std::make_unique( - Core::App().logoNoMargin().scaledToWidth( - kUserpicSize, - Qt::SmoothTransformation))); + Core::App().logoNoMargin().scaledToWidth( + kUserpicSize, + Qt::SmoothTransformation)); return &result; } return image; @@ -236,7 +234,7 @@ void PeerData::paintUserpic( int y, int size) const { if (const auto userpic = currentUserpic(view)) { - p.drawPixmap(x, y, userpic->pixCircled(userpicOrigin(), size, size)); + p.drawPixmap(x, y, userpic->pixCircled(size, size)); } else { ensureEmptyUserpic()->paint(p, x, y, x + size + x, size); } @@ -249,7 +247,7 @@ void PeerData::paintUserpicRounded( int y, int size) const { if (const auto userpic = currentUserpic(view)) { - p.drawPixmap(x, y, userpic->pixRounded(userpicOrigin(), size, size, ImageRoundRadius::Small)); + p.drawPixmap(x, y, userpic->pixRounded(size, size, ImageRoundRadius::Small)); } else { ensureEmptyUserpic()->paintRounded(p, x, y, x + size + x, size); } @@ -262,7 +260,7 @@ void PeerData::paintUserpicSquare( int y, int size) const { if (const auto userpic = currentUserpic(view)) { - p.drawPixmap(x, y, userpic->pix(userpicOrigin(), size, size)); + p.drawPixmap(x, y, userpic->pix(size, size)); } else { ensureEmptyUserpic()->paintSquare(p, x, y, x + size + x, size); } @@ -319,7 +317,7 @@ QPixmap PeerData::genUserpic( std::shared_ptr &view, int size) const { if (const auto userpic = currentUserpic(view)) { - return userpic->pixCircled(userpicOrigin(), size, size); + return userpic->pixCircled(size, size); } auto result = QImage(QSize(size, size) * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); result.setDevicePixelRatio(cRetinaFactor()); @@ -334,8 +332,8 @@ QPixmap PeerData::genUserpic( QPixmap PeerData::genUserpicRounded( std::shared_ptr &view, int size) const { - if (auto userpic = currentUserpic(view)) { - return userpic->pixRounded(userpicOrigin(), size, size, ImageRoundRadius::Small); + if (const auto userpic = currentUserpic(view)) { + return userpic->pixRounded(size, size, ImageRoundRadius::Small); } auto result = QImage(QSize(size, size) * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); result.setDevicePixelRatio(cRetinaFactor()); diff --git a/Telegram/SourceFiles/data/data_photo.cpp b/Telegram/SourceFiles/data/data_photo.cpp index fc73fe7440..2ccca68536 100644 --- a/Telegram/SourceFiles/data/data_photo.cpp +++ b/Telegram/SourceFiles/data/data_photo.cpp @@ -12,7 +12,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_reply_preview.h" #include "data/data_photo_media.h" #include "ui/image/image.h" -#include "ui/image/image_source.h" #include "main/main_session.h" #include "mainwidget.h" #include "storage/file_download.h" diff --git a/Telegram/SourceFiles/data/data_photo_media.cpp b/Telegram/SourceFiles/data/data_photo_media.cpp index 620874fea8..b794258274 100644 --- a/Telegram/SourceFiles/data/data_photo_media.cpp +++ b/Telegram/SourceFiles/data/data_photo_media.cpp @@ -15,7 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_item.h" #include "history/history.h" #include "storage/file_download.h" -#include "ui/image/image_source.h" +#include "ui/image/image.h" namespace Data { @@ -36,9 +36,7 @@ Image *PhotoMedia::thumbnailInline() const { if (!_inlineThumbnail) { auto image = Images::FromInlineBytes(_owner->inlineThumbnailBytes()); if (!image.isNull()) { - _inlineThumbnail = std::make_unique( - std::make_unique( - std::move(image))); + _inlineThumbnail = std::make_unique(std::move(image)); } } return _inlineThumbnail.get(); @@ -77,8 +75,7 @@ void PhotoMedia::set(PhotoSize size, QImage image) { Qt::KeepAspectRatio, Qt::SmoothTransformation); } - _images[index] = std::make_unique( - std::make_unique(std::move(image))); + _images[index] = std::make_unique(std::move(image)); _owner->session().downloaderTaskFinished().notify(); } @@ -112,13 +109,11 @@ void PhotoMedia::automaticLoad( void PhotoMedia::collectLocalData(not_null local) { if (const auto image = local->_inlineThumbnail.get()) { - _inlineThumbnail = std::make_unique( - std::make_unique(image->original())); + _inlineThumbnail = std::make_unique(image->original()); } for (auto i = 0; i != kPhotoSizeCount; ++i) { if (const auto image = local->_images[i].get()) { - _images[i] = std::make_unique( - std::make_unique(image->original())); + _images[i] = std::make_unique(image->original()); } } } diff --git a/Telegram/SourceFiles/data/data_reply_preview.cpp b/Telegram/SourceFiles/data/data_reply_preview.cpp index 0ec61e76c7..9603285068 100644 --- a/Telegram/SourceFiles/data/data_reply_preview.cpp +++ b/Telegram/SourceFiles/data/data_reply_preview.cpp @@ -13,7 +13,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_photo.h" #include "data/data_photo_media.h" #include "ui/image/image.h" -#include "ui/image/image_source.h" namespace Data { @@ -28,7 +27,7 @@ ReplyPreview::ReplyPreview(not_null photo) ReplyPreview::~ReplyPreview() = default; void ReplyPreview::prepare(not_null image, Images::Options options) { - if (image->isNull() || !image->loaded()) { + if (image->isNull()) { return; } int w = image->width(), h = image->height(); @@ -47,15 +46,12 @@ void ReplyPreview::prepare(not_null image, Images::Options options) { | options; auto outerSize = st::msgReplyBarSize.height(); auto bitmap = image->pixNoCache( - FileOrigin(), thumbSize.width(), thumbSize.height(), prepareOptions, outerSize, outerSize); - _image = std::make_unique( - std::make_unique( - bitmap.toImage())); + _image = std::make_unique(bitmap.toImage()); _good = ((options & Images::Option::Blurred) == 0); } diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 797eb12e99..dfb4db597e 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -16,7 +16,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/mime_type.h" // Core::IsMimeSticker #include "core/crash_reports.h" // CrashReports::SetAnnotation #include "ui/image/image.h" -#include "ui/image/image_source.h" // Images::ImageSource #include "ui/image/image_location_factory.h" // Images::FromPhotoSize #include "export/export_controller.h" #include "export/view/export_view_panel_controller.h" @@ -3822,8 +3821,7 @@ void Session::setWallpapers(const QVector &data, int32 hash) { _wallpapers.push_back(Data::Legacy1DefaultWallPaper()); _wallpapers.back().setLocalImageAsThumbnail(std::make_shared( - std::make_unique( - u":/gui/art/bg_initial.jpg"_q))); + u":/gui/art/bg_initial.jpg"_q)); for (const auto &paper : data) { if (const auto parsed = Data::WallPaper::Create(paper)) { _wallpapers.push_back(*parsed); @@ -3835,8 +3833,7 @@ void Session::setWallpapers(const QVector &data, int32 hash) { if (defaultFound == end(_wallpapers)) { _wallpapers.push_back(Data::DefaultWallPaper()); _wallpapers.back().setLocalImageAsThumbnail(std::make_shared( - std::make_unique( - u":/gui/arg/bg.jpg"_q))); + u":/gui/arg/bg.jpg"_q)); } } diff --git a/Telegram/SourceFiles/data/data_wall_paper.h b/Telegram/SourceFiles/data/data_wall_paper.h index 4af1c1fd1a..b1aa82fdfc 100644 --- a/Telegram/SourceFiles/data/data_wall_paper.h +++ b/Telegram/SourceFiles/data/data_wall_paper.h @@ -22,7 +22,7 @@ public: [[nodiscard]] WallPaperId id() const; [[nodiscard]] std::optional backgroundColor() const; [[nodiscard]] DocumentData *document() const; - [[nodiscard]] Image *localThumbnail() const; // #TODO optimize QImage-wrap + [[nodiscard]] Image *localThumbnail() const; [[nodiscard]] bool isPattern() const; [[nodiscard]] bool isDefault() const; [[nodiscard]] bool isCreator() const; diff --git a/Telegram/SourceFiles/data/data_web_page.cpp b/Telegram/SourceFiles/data/data_web_page.cpp index f5b68f3a14..4d0500ae25 100644 --- a/Telegram/SourceFiles/data/data_web_page.cpp +++ b/Telegram/SourceFiles/data/data_web_page.cpp @@ -14,7 +14,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_photo.h" #include "data/data_document.h" #include "ui/image/image.h" -#include "ui/image/image_source.h" #include "ui/text/text_entity.h" namespace { diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index b491226e47..fe6e57befa 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -341,7 +341,7 @@ void HistoryMessageReply::paint( auto to = style::rtlrect(x + st::msgReplyBarSkip, y + st::msgReplyPadding.top() + st::msgReplyBarPos.y(), st::msgReplyBarSize.height(), st::msgReplyBarSize.height(), w + 2 * x); auto previewWidth = image->width() / cIntRetinaFactor(); auto previewHeight = image->height() / cIntRetinaFactor(); - auto preview = image->pixSingle(replyToMsg->fullId(), previewWidth, previewHeight, to.width(), to.height(), ImageRoundRadius::Small, RectPart::AllCorners, selected ? &st::msgStickerOverlay : nullptr); + auto preview = image->pixSingle(previewWidth, previewHeight, to.width(), to.height(), ImageRoundRadius::Small, RectPart::AllCorners, selected ? &st::msgStickerOverlay : nullptr); p.drawPixmap(to.x(), to.y(), preview); } } diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 2b471eba89..7df52c2969 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -6764,7 +6764,7 @@ void HistoryWidget::drawField(Painter &p, const QRect &rect) { if (drawMsgText->media() && drawMsgText->media()->hasReplyPreview()) { if (const auto image = drawMsgText->media()->replyPreview()) { auto to = QRect(replyLeft, backy + st::msgReplyPadding.top(), st::msgReplyBarSize.height(), st::msgReplyBarSize.height()); - p.drawPixmap(to.x(), to.y(), image->pixSingle(drawMsgText->fullId(), image->width() / cIntRetinaFactor(), image->height() / cIntRetinaFactor(), to.width(), to.height(), ImageRoundRadius::Small)); + p.drawPixmap(to.x(), to.y(), image->pixSingle(image->width() / cIntRetinaFactor(), image->height() / cIntRetinaFactor(), to.width(), to.height(), ImageRoundRadius::Small)); } replyLeft += st::msgReplyBarSize.height() + st::msgReplyBarSkip - st::msgReplyBarSize.width() - st::msgReplyBarPos.x(); } @@ -6799,10 +6799,10 @@ void HistoryWidget::drawField(Painter &p, const QRect &rect) { if (preview) { auto to = QRect(forwardLeft, backy + st::msgReplyPadding.top(), st::msgReplyBarSize.height(), st::msgReplyBarSize.height()); if (preview->width() == preview->height()) { - p.drawPixmap(to.x(), to.y(), preview->pix(firstItem->fullId())); + p.drawPixmap(to.x(), to.y(), preview->pix()); } else { auto from = (preview->width() > preview->height()) ? QRect((preview->width() - preview->height()) / 2, 0, preview->height(), preview->height()) : QRect(0, (preview->height() - preview->width()) / 2, preview->width(), preview->width()); - p.drawPixmap(to, preview->pix(firstItem->fullId()), from); + p.drawPixmap(to, preview->pix(), from); } forwardLeft += st::msgReplyBarSize.height() + st::msgReplyBarSkip - st::msgReplyBarSize.width() - st::msgReplyBarPos.x(); } @@ -6824,10 +6824,10 @@ void HistoryWidget::drawField(Painter &p, const QRect &rect) { if (preview) { auto to = QRect(previewLeft, backy + st::msgReplyPadding.top(), st::msgReplyBarSize.height(), st::msgReplyBarSize.height()); if (preview->width() == preview->height()) { - p.drawPixmap(to.x(), to.y(), preview->pix(Data::FileOrigin())); + p.drawPixmap(to.x(), to.y(), preview->pix()); } else { auto from = (preview->width() > preview->height()) ? QRect((preview->width() - preview->height()) / 2, 0, preview->height(), preview->height()) : QRect(0, (preview->height() - preview->width()) / 2, preview->width(), preview->width()); - p.drawPixmap(to, preview->pix(Data::FileOrigin()), from); + p.drawPixmap(to, preview->pix(), from); } } previewLeft += st::msgReplyBarSize.height() + st::msgReplyBarSkip - st::msgReplyBarSize.width() - st::msgReplyBarPos.x(); @@ -6933,7 +6933,7 @@ void HistoryWidget::drawPinnedBar(Painter &p) { if (media && media->hasReplyPreview()) { if (const auto image = media->replyPreview()) { QRect to(left, top, st::msgReplyBarSize.height(), st::msgReplyBarSize.height()); - p.drawPixmap(to.x(), to.y(), image->pixSingle(_pinnedBar->msg->fullId(), image->width() / cIntRetinaFactor(), image->height() / cIntRetinaFactor(), to.width(), to.height(), ImageRoundRadius::Small)); + p.drawPixmap(to.x(), to.y(), image->pixSingle(image->width() / cIntRetinaFactor(), image->height() / cIntRetinaFactor(), to.width(), to.height(), ImageRoundRadius::Small)); } left += st::msgReplyBarSize.height() + st::msgReplyBarSkip - st::msgReplyBarSize.width() - st::msgReplyBarPos.x(); } diff --git a/Telegram/SourceFiles/history/view/media/history_view_document.cpp b/Telegram/SourceFiles/history/view/media/history_view_document.cpp index da10341e9c..3704744c89 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_document.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_document.cpp @@ -285,9 +285,9 @@ void Document::draw(Painter &p, const QRect &r, TextSelection selection, crl::ti QRect rthumb(style::rtlrect(st::msgFileThumbPadding.left(), st::msgFileThumbPadding.top() - topMinus, st::msgFileThumbSize, st::msgFileThumbSize, width())); QPixmap thumb; if (const auto normal = _dataMedia->thumbnail()) { - thumb = normal->pixSingle(_realParent->fullId(), thumbed->_thumbw, 0, st::msgFileThumbSize, st::msgFileThumbSize, roundRadius); + thumb = normal->pixSingle(thumbed->_thumbw, 0, st::msgFileThumbSize, st::msgFileThumbSize, roundRadius); } else if (const auto blurred = _dataMedia->thumbnailInline()) { - thumb = blurred->pixBlurredSingle(_realParent->fullId(), thumbed->_thumbw, 0, st::msgFileThumbSize, st::msgFileThumbSize, roundRadius); + thumb = blurred->pixBlurredSingle(thumbed->_thumbw, 0, st::msgFileThumbSize, st::msgFileThumbSize, roundRadius); } p.drawPixmap(rthumb.topLeft(), thumb); if (selected) { diff --git a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp index 7f03edc7ac..47a1b65821 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp @@ -26,7 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/media/history_view_media_common.h" #include "window/window_session_controller.h" #include "core/application.h" // Application::showDocument. -#include "ui/image/image_source.h" +#include "ui/image/image.h" #include "ui/grouped_layout.h" #include "data/data_session.h" #include "data/data_streaming.h" @@ -422,23 +422,23 @@ void Gif::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms } else { ensureDataMediaCreated(); if (const auto good = _dataMedia->goodThumbnail()) { - p.drawPixmap(rthumb.topLeft(), good->pixSingle({}, _thumbw, _thumbh, usew, painth, roundRadius, roundCorners)); + p.drawPixmap(rthumb.topLeft(), good->pixSingle(_thumbw, _thumbh, usew, painth, roundRadius, roundCorners)); } else { const auto normal = _dataMedia->thumbnail(); if (normal) { if (normal->width() >= kUseNonBlurredThreshold || normal->height() >= kUseNonBlurredThreshold) { - p.drawPixmap(rthumb.topLeft(), normal->pixSingle(_realParent->fullId(), _thumbw, _thumbh, usew, painth, roundRadius, roundCorners)); + p.drawPixmap(rthumb.topLeft(), normal->pixSingle(_thumbw, _thumbh, usew, painth, roundRadius, roundCorners)); } else { - p.drawPixmap(rthumb.topLeft(), normal->pixBlurredSingle(_realParent->fullId(), _thumbw, _thumbh, usew, painth, roundRadius, roundCorners)); + p.drawPixmap(rthumb.topLeft(), normal->pixBlurredSingle(_thumbw, _thumbh, usew, painth, roundRadius, roundCorners)); } } else { _data->loadThumbnail(_realParent->fullId()); validateVideoThumbnail(); if (_videoThumbnailFrame) { - p.drawPixmap(rthumb.topLeft(), _videoThumbnailFrame->pixSingle(_realParent->fullId(), _thumbw, _thumbh, usew, painth, roundRadius, roundCorners)); + p.drawPixmap(rthumb.topLeft(), _videoThumbnailFrame->pixSingle(_thumbw, _thumbh, usew, painth, roundRadius, roundCorners)); } else if (const auto blurred = _dataMedia->thumbnailInline()) { - p.drawPixmap(rthumb.topLeft(), blurred->pixBlurredSingle(_realParent->fullId(), _thumbw, _thumbh, usew, painth, roundRadius, roundCorners)); + p.drawPixmap(rthumb.topLeft(), blurred->pixBlurredSingle(_thumbw, _thumbh, usew, painth, roundRadius, roundCorners)); } else if (!isRound) { const auto roundTop = (roundCorners & RectPart::TopLeft); const auto roundBottom = (roundCorners & RectPart::BottomLeft); @@ -649,11 +649,9 @@ void Gif::validateVideoThumbnail() const { return; } auto info = ::Media::Clip::PrepareForSending(QString(), content); - _videoThumbnailFrame = std::make_unique( - std::make_unique( - (info.thumbnail.isNull() - ? Image::BlankMedia()->original() - : info.thumbnail))); + _videoThumbnailFrame = std::make_unique(info.thumbnail.isNull() + ? Image::BlankMedia()->original() + : info.thumbnail); } void Gif::drawCornerStatus(Painter &p, bool selected, QPoint position) const { @@ -1214,7 +1212,6 @@ void Gif::validateGroupedCache( *cacheKey = key; *cache = (image ? image : Image::BlankMedia().get())->pixNoCache( - _realParent->fullId(), pixWidth, pixHeight, options, diff --git a/Telegram/SourceFiles/history/view/media/history_view_large_emoji.cpp b/Telegram/SourceFiles/history/view/media/history_view_large_emoji.cpp index a251e301a6..cde50e11bf 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_large_emoji.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_large_emoji.cpp @@ -71,7 +71,6 @@ void LargeEmoji::draw(Painter &p, const QRect &r, bool selected) { const auto &padding = st::largeEmojiPadding; auto x = r.x() + (r.width() - _size.width()) / 2 + padding.left(); const auto y = r.y() + (r.height() - _size.height()) / 2 + padding.top(); - const auto o = Data::FileOrigin(); const auto skip = st::largeEmojiSkip - 2 * st::largeEmojiOutline; const auto size = EmojiImage::Size() / cIntRetinaFactor(); for (const auto &image : images) { @@ -80,8 +79,8 @@ void LargeEmoji::draw(Painter &p, const QRect &r, bool selected) { const auto h = size.height(); const auto &c = st::msgStickerOverlay; const auto pixmap = selected - ? prepared->pixColored(o, c, w, h) - : prepared->pix(o, w, h); + ? prepared->pixColored(c, w, h) + : prepared->pix(w, h); p.drawPixmap(x, y, pixmap); } else if (image->load) { image->load(); diff --git a/Telegram/SourceFiles/history/view/media/history_view_location.cpp b/Telegram/SourceFiles/history/view/media/history_view_location.cpp index 70f2b7b8ca..93080b1642 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_location.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_location.cpp @@ -180,7 +180,7 @@ void Location::draw(Painter &p, const QRect &r, TextSelection selection, crl::ti auto rthumb = QRect(paintx, painty, paintw, painth); ensureMediaCreated(); if (const auto thumbnail = _media->image()) { - const auto &pix = thumbnail->pixSingle({}, paintw, painth, paintw, painth, roundRadius, roundCorners); + const auto &pix = thumbnail->pixSingle(paintw, painth, paintw, painth, roundRadius, roundCorners); p.drawPixmap(rthumb.topLeft(), pix); } else { App::complexLocationRect(p, rthumb, roundRadius, roundCorners); diff --git a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp index 04bcc1d962..65dea9c18e 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp @@ -211,15 +211,15 @@ void Photo::draw(Painter &p, const QRect &r, TextSelection selection, crl::time if (_serviceWidth > 0) { const auto pix = [&] { if (const auto large = _dataMedia->image(PhotoSize::Large)) { - return large->pixCircled(_realParent->fullId(), _pixw, _pixh); + return large->pixCircled(_pixw, _pixh); } else if (const auto thumbnail = _dataMedia->image( PhotoSize::Thumbnail)) { - return thumbnail->pixBlurredCircled(_realParent->fullId(), _pixw, _pixh); + return thumbnail->pixBlurredCircled(_pixw, _pixh); } else if (const auto small = _dataMedia->image( PhotoSize::Small)) { - return small->pixBlurredCircled(_realParent->fullId(), _pixw, _pixh); + return small->pixBlurredCircled(_pixw, _pixh); } else if (const auto blurred = _dataMedia->thumbnailInline()) { - return blurred->pixBlurredCircled(_realParent->fullId(), _pixw, _pixh); + return blurred->pixBlurredCircled(_pixw, _pixh); } else { return QPixmap(); } @@ -243,15 +243,15 @@ void Photo::draw(Painter &p, const QRect &r, TextSelection selection, crl::time | ((isBubbleBottom() && _caption.isEmpty()) ? (RectPart::BottomLeft | RectPart::BottomRight) : RectPart::None)); const auto pix = [&] { if (const auto large = _dataMedia->image(PhotoSize::Large)) { - return large->pixSingle(_realParent->fullId(), _pixw, _pixh, paintw, painth, roundRadius, roundCorners); + return large->pixSingle(_pixw, _pixh, paintw, painth, roundRadius, roundCorners); } else if (const auto thumbnail = _dataMedia->image( PhotoSize::Thumbnail)) { - return thumbnail->pixBlurredSingle(_realParent->fullId(), _pixw, _pixh, paintw, painth, roundRadius, roundCorners); + return thumbnail->pixBlurredSingle(_pixw, _pixh, paintw, painth, roundRadius, roundCorners); } else if (const auto small = _dataMedia->image( PhotoSize::Small)) { - return small->pixBlurredSingle(_realParent->fullId(), _pixw, _pixh, paintw, painth, roundRadius, roundCorners); + return small->pixBlurredSingle(_pixw, _pixh, paintw, painth, roundRadius, roundCorners); } else if (const auto blurred = _dataMedia->thumbnailInline()) { - return blurred->pixBlurredSingle(_realParent->fullId(), _pixw, _pixh, paintw, painth, roundRadius, roundCorners); + return blurred->pixBlurredSingle(_pixw, _pixh, paintw, painth, roundRadius, roundCorners); } else { return QPixmap(); } @@ -577,7 +577,7 @@ void Photo::validateGroupedCache( : Image::BlankMedia().get(); *cacheKey = key; - *cache = image->pixNoCache(_realParent->fullId(), pixWidth, pixHeight, options, width, height); + *cache = image->pixNoCache(pixWidth, pixHeight, options, width, height); } TextForMimeData Photo::selectedText(TextSelection selection) const { diff --git a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp index b7dae0d88d..f80c4c2079 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp @@ -208,30 +208,29 @@ void Sticker::paintPixmap(Painter &p, const QRect &r, bool selected) { } QPixmap Sticker::paintedPixmap(bool selected) const { - const auto o = _parent->data()->fullId(); const auto w = _size.width(); const auto h = _size.height(); const auto &c = st::msgStickerOverlay; const auto good = _dataMedia->goodThumbnail(); if (const auto image = _dataMedia->getStickerLarge()) { return selected - ? image->pixColored(o, c, w, h) - : image->pix(o, w, h); + ? image->pixColored(c, w, h) + : image->pix(w, h); // // Inline thumbnails can't have alpha channel. // //} else if (const auto blurred = _data->thumbnailInline()) { // return selected - // ? blurred->pixBlurredColored(o, c, w, h) - // : blurred->pixBlurred(o, w, h); + // ? blurred->pixBlurredColored(c, w, h) + // : blurred->pixBlurred(w, h); } else if (good) { return selected - ? good->pixColored(o, c, w, h) - : good->pix(o, w, h); + ? good->pixColored(c, w, h) + : good->pix(w, h); } else if (const auto thumbnail = _dataMedia->thumbnail()) { return selected - ? thumbnail->pixBlurredColored(o, c, w, h) - : thumbnail->pixBlurred(o, w, h); + ? thumbnail->pixBlurredColored(c, w, h) + : thumbnail->pixBlurred(w, h); } return QPixmap(); } diff --git a/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp b/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp index 5135c3c486..e336dbe993 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp @@ -483,12 +483,12 @@ void WebPage::draw(Painter &p, const QRect &r, TextSelection selection, crl::tim } if (const auto thumbnail = _photoMedia->image( Data::PhotoSize::Thumbnail)) { - pix = thumbnail->pixSingle(contextId, pixw, pixh, pw, ph, ImageRoundRadius::Small); + pix = thumbnail->pixSingle(pixw, pixh, pw, ph, ImageRoundRadius::Small); } else if (const auto small = _photoMedia->image( Data::PhotoSize::Small)) { - pix = small->pixBlurredSingle(contextId, pixw, pixh, pw, ph, ImageRoundRadius::Small); + pix = small->pixBlurredSingle(pixw, pixh, pw, ph, ImageRoundRadius::Small); } else if (const auto blurred = _photoMedia->thumbnailInline()) { - pix = blurred->pixBlurredSingle(contextId, pixw, pixh, pw, ph, ImageRoundRadius::Small); + pix = blurred->pixBlurredSingle(pixw, pixh, pw, ph, ImageRoundRadius::Small); } p.drawPixmapLeft(padding.left() + paintw - pw, tshift, width(), pix); if (selected) { diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp index 122891308c..3617ac64d7 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp @@ -321,7 +321,6 @@ void Gif::validateThumbnail( } _thumbGood = good; _thumb = image->pixNoCache( - fileOrigin(), frame.width() * cIntRetinaFactor(), frame.height() * cIntRetinaFactor(), (Images::Option::Smooth @@ -554,7 +553,6 @@ void Sticker::prepareThumbnail() const { if (!_lottie && !_thumbLoaded && _dataMedia->loaded()) { const auto thumbSize = getThumbSize(); _thumb = sticker->pix( - document->stickerSetOrigin(), thumbSize.width(), thumbSize.height()); _thumbLoaded = true; @@ -653,7 +651,6 @@ void Photo::validateThumbnail( } const auto origin = fileOrigin(); _thumb = image->pixNoCache( - origin, frame.width() * cIntRetinaFactor(), frame.height() * cIntRetinaFactor(), Images::Option::Smooth | (good ? Images::Option(0) : Images::Option::Blurred), @@ -809,7 +806,7 @@ void Video::prepareThumbnail(QSize size) const { w = width; } } - _thumb = thumb->pixNoCache({}, w * cIntRetinaFactor(), h * cIntRetinaFactor(), Images::Option::Smooth, width, height); + _thumb = thumb->pixNoCache(w * cIntRetinaFactor(), h * cIntRetinaFactor(), Images::Option::Smooth, width, height); } } @@ -1139,7 +1136,7 @@ void Contact::prepareThumbnail(int width, int height) const { w = width; } } - _thumb = thumb->pixNoCache(origin, w * cIntRetinaFactor(), h * cIntRetinaFactor(), Images::Option::Smooth, width, height); + _thumb = thumb->pixNoCache(w * cIntRetinaFactor(), h * cIntRetinaFactor(), Images::Option::Smooth, width, height); } Article::Article( @@ -1291,7 +1288,7 @@ void Article::prepareThumbnail(int width, int height) const { w = width; } } - _thumb = thumb->pixNoCache(origin, w * cIntRetinaFactor(), h * cIntRetinaFactor(), Images::Option::Smooth, width, height); + _thumb = thumb->pixNoCache(w * cIntRetinaFactor(), h * cIntRetinaFactor(), Images::Option::Smooth, width, height); } Game::Game(not_null context, not_null result) @@ -1506,7 +1503,6 @@ void Game::validateThumbnail(Image *image, QSize size, bool good) const { } _thumbGood = good; _thumb = image->pixNoCache( - fileOrigin(), w * cIntRetinaFactor(), h * cIntRetinaFactor(), (Images::Option::Smooth diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index c98ce3c4a2..5393c034c6 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -34,7 +34,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/toast/toast.h" #include "ui/widgets/dropdown_menu.h" #include "ui/image/image.h" -#include "ui/image/image_source.h" #include "ui/focus_persister.h" #include "ui/resize_area.h" #include "ui/text_options.h" @@ -1354,8 +1353,7 @@ void MainWidget::setReadyChatBackground( if (image.isNull() && !background.document() - && background.localThumbnail() - && background.localThumbnail()->loaded()) { + && background.localThumbnail()) { image = background.localThumbnail()->original(); } diff --git a/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp b/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp index 461e0cb2d5..fc74966b45 100644 --- a/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp +++ b/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp @@ -248,7 +248,7 @@ void GroupThumbs::Thumb::validateImage() { const auto originalHeight = _image->height(); const auto takeWidth = originalWidth * st::mediaviewGroupWidthMax / pixSize.width(); - const auto original = _image->pixNoCache(_origin).toImage(); + const auto original = _image->original(); _full = App::pixmapFromImageInPlace(original.copy( (originalWidth - takeWidth) / 2, 0, @@ -261,7 +261,6 @@ void GroupThumbs::Thumb::validateImage() { Qt::SmoothTransformation)); } else { _full = _image->pixNoCache( - _origin, pixSize.width() * cIntRetinaFactor(), pixSize.height() * cIntRetinaFactor(), Images::Option::Smooth); diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index f8c4664bf0..b2234b6918 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -2014,10 +2014,9 @@ void OverlayWidget::displayDocument( if (_document) { if (_document->sticker()) { if (const auto image = _documentMedia->getStickerLarge()) { - _staticContent = image->pix(fileOrigin()); + _staticContent = image->pix(); } else if (const auto thumbnail = _documentMedia->thumbnail()) { _staticContent = thumbnail->pixBlurred( - fileOrigin(), _document->dimensions.width(), _document->dimensions.height()); } @@ -2235,7 +2234,6 @@ void OverlayWidget::initStreamingThumbnail() { : blurred ? blurred : Image::BlankMedia().get())->pixNoCache( - fileOrigin(), w, h, useGood ? goodOptions : options, @@ -2715,7 +2713,7 @@ void OverlayWidget::updatePlaybackState() { } void OverlayWidget::validatePhotoImage(Image *image, bool blurred) { - if (!image || !image->loaded()) { + if (!image) { return; } else if (!_staticContent.isNull() && (blurred || !_blurred)) { return; @@ -2723,7 +2721,6 @@ void OverlayWidget::validatePhotoImage(Image *image, bool blurred) { const auto use = flipSizeByRotation({ _width, _height }) * cIntRetinaFactor(); _staticContent = image->pixNoCache( - fileOrigin(), use.width(), use.height(), Images::Option::Smooth @@ -2842,7 +2839,7 @@ void OverlayWidget::paintEvent(QPaintEvent *e) { } } else if (const auto thumbnail = _documentMedia->thumbnail()) { int32 rf(cIntRetinaFactor()); - p.drawPixmap(_docIconRect.topLeft(), thumbnail->pix(fileOrigin(), _docThumbw), QRect(_docThumbx * rf, _docThumby * rf, st::mediaviewFileIconSize * rf, st::mediaviewFileIconSize * rf)); + p.drawPixmap(_docIconRect.topLeft(), thumbnail->pix(_docThumbw), QRect(_docThumbx * rf, _docThumby * rf, st::mediaviewFileIconSize * rf, st::mediaviewFileIconSize * rf)); } paintRadialLoading(p, radial, radialOpacity); diff --git a/Telegram/SourceFiles/media/view/media_view_pip.cpp b/Telegram/SourceFiles/media/view/media_view_pip.cpp index ed9ee3e3d1..fb8dd25aae 100644 --- a/Telegram/SourceFiles/media/view/media_view_pip.cpp +++ b/Telegram/SourceFiles/media/view/media_view_pip.cpp @@ -838,8 +838,7 @@ void Pip::setupPanel() { } const auto media = _data->activeMediaView(); const auto good = media ? media->goodThumbnail() : nullptr; - const auto useGood = (good && good->loaded()); - const auto original = useGood ? good->size() : _data->dimensions; + const auto original = good ? good->size() : _data->dimensions; return original.isEmpty() ? QSize(1, 1) : original; }(); _panel.setAspectRatio(FlipSizeByRotation(size, _rotation)); @@ -1427,7 +1426,6 @@ QImage Pip::videoFrame(const FrameRequest &request) const { : blurred ? blurred : Image::BlankMedia().get())->pixNoCache( - _contextId, request.resize.width(), request.resize.height(), options, diff --git a/Telegram/SourceFiles/overview/overview_layout.cpp b/Telegram/SourceFiles/overview/overview_layout.cpp index 439aaefa22..f456de3fea 100644 --- a/Telegram/SourceFiles/overview/overview_layout.cpp +++ b/Telegram/SourceFiles/overview/overview_layout.cpp @@ -439,8 +439,7 @@ void Video::paint(Painter &p, const QRect &clip, TextSelection selection, const const auto selected = (selection == FullSelection); const auto blurred = _dataMedia->thumbnailInline(); const auto thumbnail = _dataMedia->thumbnail(); - const auto goodLoaded = _dataMedia->goodThumbnail() - && _dataMedia->goodThumbnail()->loaded(); + const auto good = _dataMedia->goodThumbnail(); bool loaded = dataLoaded(), displayLoading = _data->displayLoading(); if (displayLoading) { @@ -453,12 +452,12 @@ void Video::paint(Painter &p, const QRect &clip, TextSelection selection, const const auto radial = isRadialAnimation(); const auto radialOpacity = radial ? _radial->opacity() : 0.; - if ((blurred || thumbnail || goodLoaded) + if ((blurred || thumbnail || good) && ((_pix.width() != _width * cIntRetinaFactor()) - || (_pixBlurred && (thumbnail || goodLoaded)))) { + || (_pixBlurred && (thumbnail || good)))) { auto size = _width * cIntRetinaFactor(); - auto img = goodLoaded - ? _dataMedia->goodThumbnail()->original() + auto img = good + ? good->original() : thumbnail ? thumbnail->original() : Images::prepareBlur(blurred->original()); @@ -474,7 +473,7 @@ void Video::paint(Painter &p, const QRect &clip, TextSelection selection, const img.setDevicePixelRatio(cRetinaFactor()); _pix = App::pixmapFromImageInPlace(std::move(img)); - _pixBlurred = !(thumbnail || goodLoaded); + _pixBlurred = !(thumbnail || good); } if (_pix.isNull()) { @@ -695,14 +694,8 @@ void Voice::paint(Painter &p, const QRect &clip, TextSelection selection, const p.setPen(Qt::NoPen); if (thumbnail || blurred) { const auto thumb = thumbnail - ? thumbnail->pixCircled( - parent()->fullId(), - inner.width(), - inner.height()) - : blurred->pixBlurredCircled( - parent()->fullId(), - inner.width(), - inner.height()); + ? thumbnail->pixCircled(inner.width(), inner.height()) + : blurred->pixBlurredCircled(inner.width(), inner.height()); p.drawPixmap(inner.topLeft(), thumb); } else if (_data->hasThumbnail()) { PainterHighQualityEnabler hq(p); @@ -1070,7 +1063,7 @@ void Document::paint(Painter &p, const QRect &clip, TextSelection selection, con ? Images::Option::None : Images::Option::Blurred); const auto image = thumbnail ? thumbnail : blurred; - _thumb = image->pixNoCache(parent()->fullId(), _thumbw * cIntRetinaFactor(), 0, options, _st.fileThumbSize, _st.fileThumbSize); + _thumb = image->pixNoCache(_thumbw * cIntRetinaFactor(), 0, options, _st.fileThumbSize, _st.fileThumbSize); } p.drawPixmap(rthumb.topLeft(), _thumb); } else { @@ -1628,13 +1621,13 @@ void Link::validateThumbnail() { using Data::PhotoSize; ensurePhotoMediaCreated(); if (const auto thumbnail = _photoMedia->image(PhotoSize::Thumbnail)) { - _thumbnail = thumbnail->pixSingle(parent()->fullId(), _pixw, _pixh, st::linksPhotoSize, st::linksPhotoSize, ImageRoundRadius::Small); + _thumbnail = thumbnail->pixSingle(_pixw, _pixh, st::linksPhotoSize, st::linksPhotoSize, ImageRoundRadius::Small); } else if (const auto large = _photoMedia->image(PhotoSize::Large)) { - _thumbnail = large->pixSingle(parent()->fullId(), _pixw, _pixh, st::linksPhotoSize, st::linksPhotoSize, ImageRoundRadius::Small); + _thumbnail = large->pixSingle(_pixw, _pixh, st::linksPhotoSize, st::linksPhotoSize, ImageRoundRadius::Small); } else if (const auto small = _photoMedia->image(PhotoSize::Small)) { - _thumbnail = small->pixSingle(parent()->fullId(), _pixw, _pixh, st::linksPhotoSize, st::linksPhotoSize, ImageRoundRadius::Small); + _thumbnail = small->pixSingle(_pixw, _pixh, st::linksPhotoSize, st::linksPhotoSize, ImageRoundRadius::Small); } else if (const auto blurred = _photoMedia->thumbnailInline()) { - _thumbnail = blurred->pixBlurredSingle(parent()->fullId(), _pixw, _pixh, st::linksPhotoSize, st::linksPhotoSize, ImageRoundRadius::Small); + _thumbnail = blurred->pixBlurredSingle(_pixw, _pixh, st::linksPhotoSize, st::linksPhotoSize, ImageRoundRadius::Small); } else { return; } @@ -1646,7 +1639,7 @@ void Link::validateThumbnail() { auto roundRadius = _page->document->isVideoMessage() ? ImageRoundRadius::Ellipse : ImageRoundRadius::Small; - _thumbnail = thumbnail->pixSingle(parent()->fullId(), _pixw, _pixh, st::linksPhotoSize, st::linksPhotoSize, roundRadius); + _thumbnail = thumbnail->pixSingle(_pixw, _pixh, st::linksPhotoSize, st::linksPhotoSize, roundRadius); _documentMedia = nullptr; delegate()->unregisterHeavyItem(this); } diff --git a/Telegram/SourceFiles/platform/mac/mac_touchbar.mm b/Telegram/SourceFiles/platform/mac/mac_touchbar.mm index 0ddb2ea349..5b9888f216 100644 --- a/Telegram/SourceFiles/platform/mac/mac_touchbar.mm +++ b/Telegram/SourceFiles/platform/mac/mac_touchbar.mm @@ -709,7 +709,6 @@ void AppendEmojiPacks(std::vector &to) { .scaled(kCircleDiameter, kCircleDiameter, Qt::KeepAspectRatio); _imageView.image = [qt_mac_create_nsimage( _image->pixSingle( - fileOrigin, size.width(), size.height(), kCircleDiameter, diff --git a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp index 285781264c..56110739e1 100644 --- a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp +++ b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp @@ -482,7 +482,7 @@ bool Manager::Private::showNotification( const auto key = hideNameAndPhoto ? InMemoryKey() : peer->userpicUniqueKey(view); - const auto userpicPath = _cachedUserpics.get(key, peer); + const auto userpicPath = _cachedUserpics.get(key, peer, view); const auto userpicPathWide = QDir::toNativeSeparators(userpicPath).toStdWString(); hr = SetImageSrc(userpicPathWide.c_str(), toastXml.Get()); diff --git a/Telegram/SourceFiles/settings/settings_chat.cpp b/Telegram/SourceFiles/settings/settings_chat.cpp index 8c72a50f10..33abb39480 100644 --- a/Telegram/SourceFiles/settings/settings_chat.cpp +++ b/Telegram/SourceFiles/settings/settings_chat.cpp @@ -27,7 +27,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/radial_animation.h" #include "ui/toast/toast.h" #include "ui/image/image.h" -#include "ui/image/image_source.h" #include "lang/lang_keys.h" #include "window/themes/window_theme.h" #include "window/themes/window_themes_embedded.h" @@ -439,7 +438,6 @@ void BackgroundRow::paintEvent(QPaintEvent *e) { p.drawPixmap(0, 0, _background); } else { const auto &pix = backThumb->pixBlurred( - Data::FileOrigin(), st::settingsBackgroundThumb); const auto factor = cIntRetinaFactor(); p.drawPixmap( @@ -630,7 +628,7 @@ void ChooseFromFile( } auto local = Data::CustomWallPaper(); local.setLocalImageAsThumbnail(std::make_shared( - std::make_unique(std::move(image)))); + std::move(image))); Ui::show(Box(session, local)); }); FileDialog::GetOpenPath( diff --git a/Telegram/SourceFiles/ui/image/image.cpp b/Telegram/SourceFiles/ui/image/image.cpp index 5b2f37f69d..24c1e46ee2 100644 --- a/Telegram/SourceFiles/ui/image/image.cpp +++ b/Telegram/SourceFiles/ui/image/image.cpp @@ -7,10 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "ui/image/image.h" -#include "ui/image/image_source.h" #include "storage/cache/storage_cache_database.h" #include "data/data_session.h" -#include "data/data_file_origin.h" #include "chat_helpers/stickers.h" #include "main/main_session.h" #include "app.h" @@ -20,16 +18,27 @@ using namespace Images; namespace Images { namespace { -uint64 PixKey(int width, int height, Options options) { +[[nodiscard]] uint64 PixKey(int width, int height, Options options) { return static_cast(width) | (static_cast(height) << 24) | (static_cast(options) << 48); } -uint64 SinglePixKey(Options options) { +[[nodiscard]] uint64 SinglePixKey(Options options) { return PixKey(0, 0, options); } +[[nodiscard]] QByteArray ReadContent(const QString &path) { + auto file = QFile(path); + const auto good = (file.size() <= App::kImageSizeLimit) + && file.open(QIODevice::ReadOnly); + return good ? file.readAll() : QByteArray(); +} + +[[nodiscard]] QImage ReadImage(const QByteArray &content) { + return App::readImage(content, nullptr, false, nullptr); +} + } // namespace QByteArray ExpandInlineBytes(const QByteArray &bytes) { @@ -97,14 +106,17 @@ QSize GetSizeForDocument(const QVector &attributes) { } // namespace Images -Image::Image(std::unique_ptr &&source) -: _source(std::move(source)) { +Image::Image(const QString &path) : Image(ReadContent(path)) { } -Image::~Image() = default; +Image::Image(const QByteArray &content) : Image(ReadImage(content)) { +} + +Image::Image(QImage &&data) : _data(std::move(data)) { +} not_null Image::Empty() { - static auto result = [] { + static auto result = Image([] { const auto factor = cIntRetinaFactor(); auto data = QImage( factor, @@ -112,13 +124,13 @@ not_null Image::Empty() { QImage::Format_ARGB32_Premultiplied); data.fill(Qt::transparent); data.setDevicePixelRatio(cRetinaFactor()); - return Image(std::make_unique(std::move(data))); - }(); + return data; + }()); return &result; } not_null Image::BlankMedia() { - static auto result = [] { + static auto result = Image([] { const auto factor = cIntRetinaFactor(); auto data = QImage( factor, @@ -126,21 +138,16 @@ not_null Image::BlankMedia() { QImage::Format_ARGB32_Premultiplied); data.fill(Qt::black); data.setDevicePixelRatio(cRetinaFactor()); - return Image(std::make_unique(std::move(data))); - }(); + return data; + }()); return &result; } -bool Image::isNull() const { - return (this == Empty()); +QImage Image::original() const { + return _data; } -const QPixmap &Image::pix( - Data::FileOrigin origin, - int32 w, - int32 h) const { - checkSource(); - +const QPixmap &Image::pix(int w, int h) const { if (w <= 0 || !width() || !height()) { w = width(); } else { @@ -149,23 +156,20 @@ const QPixmap &Image::pix( } auto options = Option::Smooth | Option::None; auto k = PixKey(w, h, options); - auto i = _sizesCache.constFind(k); - if (i == _sizesCache.cend()) { - auto p = pixNoCache(origin, w, h, options); + auto i = _cache.find(k); + if (i == _cache.cend()) { + auto p = pixNoCache(w, h, options); p.setDevicePixelRatio(cRetinaFactor()); - i = _sizesCache.insert(k, p); + i = _cache.emplace(k, p).first; } - return i.value(); + return i->second; } const QPixmap &Image::pixRounded( - Data::FileOrigin origin, - int32 w, - int32 h, + int w, + int h, ImageRoundRadius radius, RectParts corners) const { - checkSource(); - if (w <= 0 || !width() || !height()) { w = width(); } else { @@ -187,21 +191,16 @@ const QPixmap &Image::pixRounded( options |= Option::Circled | cornerOptions(corners); } auto k = PixKey(w, h, options); - auto i = _sizesCache.constFind(k); - if (i == _sizesCache.cend()) { - auto p = pixNoCache(origin, w, h, options); + auto i = _cache.find(k); + if (i == _cache.cend()) { + auto p = pixNoCache(w, h, options); p.setDevicePixelRatio(cRetinaFactor()); - i = _sizesCache.insert(k, p); + i = _cache.emplace(k, p).first; } - return i.value(); + return i->second; } -const QPixmap &Image::pixCircled( - Data::FileOrigin origin, - int32 w, - int32 h) const { - checkSource(); - +const QPixmap &Image::pixCircled(int w, int h) const { if (w <= 0 || !width() || !height()) { w = width(); } else { @@ -210,21 +209,16 @@ const QPixmap &Image::pixCircled( } auto options = Option::Smooth | Option::Circled; auto k = PixKey(w, h, options); - auto i = _sizesCache.constFind(k); - if (i == _sizesCache.cend()) { - auto p = pixNoCache(origin, w, h, options); + auto i = _cache.find(k); + if (i == _cache.cend()) { + auto p = pixNoCache(w, h, options); p.setDevicePixelRatio(cRetinaFactor()); - i = _sizesCache.insert(k, p); + i = _cache.emplace(k, p).first; } - return i.value(); + return i->second; } -const QPixmap &Image::pixBlurredCircled( - Data::FileOrigin origin, - int32 w, - int32 h) const { - checkSource(); - +const QPixmap &Image::pixBlurredCircled(int w, int h) const { if (w <= 0 || !width() || !height()) { w = width(); } else { @@ -233,21 +227,16 @@ const QPixmap &Image::pixBlurredCircled( } auto options = Option::Smooth | Option::Circled | Option::Blurred; auto k = PixKey(w, h, options); - auto i = _sizesCache.constFind(k); - if (i == _sizesCache.cend()) { - auto p = pixNoCache(origin, w, h, options); + auto i = _cache.find(k); + if (i == _cache.cend()) { + auto p = pixNoCache(w, h, options); p.setDevicePixelRatio(cRetinaFactor()); - i = _sizesCache.insert(k, p); + i = _cache.emplace(k, p).first; } - return i.value(); + return i->second; } -const QPixmap &Image::pixBlurred( - Data::FileOrigin origin, - int32 w, - int32 h) const { - checkSource(); - +const QPixmap &Image::pixBlurred(int w, int h) const { if (w <= 0 || !width() || !height()) { w = width() * cIntRetinaFactor(); } else { @@ -256,22 +245,16 @@ const QPixmap &Image::pixBlurred( } auto options = Option::Smooth | Option::Blurred; auto k = PixKey(w, h, options); - auto i = _sizesCache.constFind(k); - if (i == _sizesCache.cend()) { - auto p = pixNoCache(origin, w, h, options); + auto i = _cache.find(k); + if (i == _cache.cend()) { + auto p = pixNoCache(w, h, options); p.setDevicePixelRatio(cRetinaFactor()); - i = _sizesCache.insert(k, p); + i = _cache.emplace(k, p).first; } - return i.value(); + return i->second; } -const QPixmap &Image::pixColored( - Data::FileOrigin origin, - style::color add, - int32 w, - int32 h) const { - checkSource(); - +const QPixmap &Image::pixColored(style::color add, int w, int h) const { if (w <= 0 || !width() || !height()) { w = width() * cIntRetinaFactor(); } else { @@ -280,22 +263,19 @@ const QPixmap &Image::pixColored( } auto options = Option::Smooth | Option::Colored; auto k = PixKey(w, h, options); - auto i = _sizesCache.constFind(k); - if (i == _sizesCache.cend()) { - auto p = pixColoredNoCache(origin, add, w, h, true); + auto i = _cache.find(k); + if (i == _cache.cend()) { + auto p = pixColoredNoCache(add, w, h, true); p.setDevicePixelRatio(cRetinaFactor()); - i = _sizesCache.insert(k, p); + i = _cache.emplace(k, p).first; } - return i.value(); + return i->second; } const QPixmap &Image::pixBlurredColored( - Data::FileOrigin origin, style::color add, - int32 w, - int32 h) const { - checkSource(); - + int w, + int h) const { if (w <= 0 || !width() || !height()) { w = width() * cIntRetinaFactor(); } else { @@ -304,26 +284,23 @@ const QPixmap &Image::pixBlurredColored( } auto options = Option::Blurred | Option::Smooth | Option::Colored; auto k = PixKey(w, h, options); - auto i = _sizesCache.constFind(k); - if (i == _sizesCache.cend()) { - auto p = pixBlurredColoredNoCache(origin, add, w, h); + auto i = _cache.find(k); + if (i == _cache.cend()) { + auto p = pixBlurredColoredNoCache(add, w, h); p.setDevicePixelRatio(cRetinaFactor()); - i = _sizesCache.insert(k, p); + i = _cache.emplace(k, p).first; } - return i.value(); + return i->second; } const QPixmap &Image::pixSingle( - Data::FileOrigin origin, - int32 w, - int32 h, - int32 outerw, - int32 outerh, + int w, + int h, + int outerw, + int outerh, ImageRoundRadius radius, RectParts corners, const style::color *colored) const { - checkSource(); - if (w <= 0 || !width() || !height()) { w = width() * cIntRetinaFactor(); } else { @@ -350,25 +327,22 @@ const QPixmap &Image::pixSingle( } auto k = SinglePixKey(options); - auto i = _sizesCache.constFind(k); - if (i == _sizesCache.cend() || i->width() != (outerw * cIntRetinaFactor()) || i->height() != (outerh * cIntRetinaFactor())) { - auto p = pixNoCache(origin, w, h, options, outerw, outerh, colored); + auto i = _cache.find(k); + if (i == _cache.cend() || i->second.width() != (outerw * cIntRetinaFactor()) || i->second.height() != (outerh * cIntRetinaFactor())) { + auto p = pixNoCache(w, h, options, outerw, outerh, colored); p.setDevicePixelRatio(cRetinaFactor()); - i = _sizesCache.insert(k, p); + i = _cache.emplace(k, p).first; } - return i.value(); + return i->second; } const QPixmap &Image::pixBlurredSingle( - Data::FileOrigin origin, - int32 w, - int32 h, - int32 outerw, - int32 outerh, + int w, + int h, + int outerw, + int outerh, ImageRoundRadius radius, RectParts corners) const { - checkSource(); - if (w <= 0 || !width() || !height()) { w = width() * cIntRetinaFactor(); } else { @@ -392,30 +366,27 @@ const QPixmap &Image::pixBlurredSingle( } auto k = SinglePixKey(options); - auto i = _sizesCache.constFind(k); - if (i == _sizesCache.cend() || i->width() != (outerw * cIntRetinaFactor()) || i->height() != (outerh * cIntRetinaFactor())) { - auto p = pixNoCache(origin, w, h, options, outerw, outerh); + auto i = _cache.find(k); + if (i == _cache.cend() || i->second.width() != (outerw * cIntRetinaFactor()) || i->second.height() != (outerh * cIntRetinaFactor())) { + auto p = pixNoCache(w, h, options, outerw, outerh); p.setDevicePixelRatio(cRetinaFactor()); - i = _sizesCache.insert(k, p); + i = _cache.emplace(k, p).first; } - return i.value(); + return i->second; } QPixmap Image::pixNoCache( - Data::FileOrigin origin, int w, int h, Options options, int outerw, int outerh, const style::color *colored) const { - checkSource(); - if (_data.isNull()) { if (h <= 0 && height() > 0) { h = qRound(width() * w / float64(height())); } - return Empty()->pixNoCache(origin, w, h, options, outerw, outerh); + return Empty()->pixNoCache(w, h, options, outerw, outerh); } if (isNull() && outerw > 0 && outerh > 0) { @@ -462,15 +433,12 @@ QPixmap Image::pixNoCache( } QPixmap Image::pixColoredNoCache( - Data::FileOrigin origin, style::color add, - int32 w, - int32 h, + int w, + int h, bool smooth) const { - checkSource(); - if (_data.isNull()) { - return Empty()->pix(origin); + return Empty()->pix(); } auto img = _data; @@ -484,14 +452,11 @@ QPixmap Image::pixColoredNoCache( } QPixmap Image::pixBlurredColoredNoCache( - Data::FileOrigin origin, style::color add, - int32 w, - int32 h) const { - checkSource(); - + int w, + int h) const { if (_data.isNull()) { - return Empty()->pix(origin); + return Empty()->pix(); } auto img = prepareBlur(_data); @@ -503,31 +468,3 @@ QPixmap Image::pixBlurredColoredNoCache( return App::pixmapFromImageInPlace(prepareColored(add, img)); } - -QImage Image::original() const { - checkSource(); - return _data; -} - -void Image::load() { - if (!loaded()) { - _source->load(); - } -} - -bool Image::loaded() const { - checkSource(); - return !_data.isNull(); -} - -void Image::checkSource() const { - auto data = _source->takeLoaded(); - if (_data.isNull() && !data.isNull()) { - invalidateSizeCache(); - _data = std::move(data); - } -} - -void Image::invalidateSizeCache() const { - _sizesCache.clear(); -} diff --git a/Telegram/SourceFiles/ui/image/image.h b/Telegram/SourceFiles/ui/image/image.h index 340ddab3b9..16bba2b1b4 100644 --- a/Telegram/SourceFiles/ui/image/image.h +++ b/Telegram/SourceFiles/ui/image/image.h @@ -9,8 +9,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/image/image_prepare.h" -class HistoryItem; - namespace Images { [[nodiscard]] QByteArray ExpandInlineBytes(const QByteArray &bytes); @@ -19,125 +17,81 @@ namespace Images { [[nodiscard]] QSize GetSizeForDocument( const QVector &attributes); -class Source { -public: - Source() = default; - Source(const Source &other) = delete; - Source(Source &&other) = delete; - Source &operator=(const Source &other) = delete; - Source &operator=(Source &&other) = delete; - virtual ~Source() = default; - - virtual void load() = 0; - virtual QImage takeLoaded() = 0; - - virtual int width() = 0; - virtual int height() = 0; - -}; - } // namespace Images class Image final { public: - explicit Image(std::unique_ptr &&source); + explicit Image(const QString &path); + explicit Image(const QByteArray &content); + explicit Image(QImage &&data); - static not_null Empty(); // 1x1 transparent - static not_null BlankMedia(); // 1x1 black + [[nodiscard]] static not_null Empty(); // 1x1 transparent + [[nodiscard]] static not_null BlankMedia(); // 1x1 black - QImage original() const; + [[nodiscard]] int width() const { + return _data.width(); + } + [[nodiscard]] int height() const { + return _data.height(); + } + [[nodiscard]] QSize size() const { + return { width(), height() }; + } - const QPixmap &pix( - Data::FileOrigin origin, - int32 w = 0, - int32 h = 0) const; - const QPixmap &pixRounded( - Data::FileOrigin origin, - int32 w = 0, - int32 h = 0, + [[nodiscard]] bool isNull() const { + return (this == Empty()); + } + + [[nodiscard]] QImage original() const; + + [[nodiscard]] const QPixmap &pix(int w = 0, int h = 0) const; + [[nodiscard]] const QPixmap &pixRounded( + int w = 0, + int h = 0, ImageRoundRadius radius = ImageRoundRadius::None, RectParts corners = RectPart::AllCorners) const; - const QPixmap &pixBlurred( - Data::FileOrigin origin, - int32 w = 0, - int32 h = 0) const; - const QPixmap &pixColored( - Data::FileOrigin origin, + [[nodiscard]] const QPixmap &pixBlurred(int w = 0, int h = 0) const; + [[nodiscard]] const QPixmap &pixColored(style::color add, int w = 0, int h = 0) const; + [[nodiscard]] const QPixmap &pixBlurredColored( style::color add, - int32 w = 0, - int32 h = 0) const; - const QPixmap &pixBlurredColored( - Data::FileOrigin origin, - style::color add, - int32 w = 0, - int32 h = 0) const; - const QPixmap &pixSingle( - Data::FileOrigin origin, - int32 w, - int32 h, - int32 outerw, - int32 outerh, + int w = 0, + int h = 0) const; + [[nodiscard]] const QPixmap &pixSingle( + int w, + int h, + int outerw, + int outerh, ImageRoundRadius radius, RectParts corners = RectPart::AllCorners, const style::color *colored = nullptr) const; - const QPixmap &pixBlurredSingle( - Data::FileOrigin origin, - int32 w, - int32 h, - int32 outerw, - int32 outerh, + [[nodiscard]] const QPixmap &pixBlurredSingle( + int w, + int h, + int outerw, + int outerh, ImageRoundRadius radius, RectParts corners = RectPart::AllCorners) const; - const QPixmap &pixCircled( - Data::FileOrigin origin, - int32 w = 0, - int32 h = 0) const; - const QPixmap &pixBlurredCircled( - Data::FileOrigin origin, - int32 w = 0, - int32 h = 0) const; - QPixmap pixNoCache( - Data::FileOrigin origin, + [[nodiscard]] const QPixmap &pixCircled(int w = 0, int h = 0) const; + [[nodiscard]] const QPixmap &pixBlurredCircled(int w = 0, int h = 0) const; + [[nodiscard]] QPixmap pixNoCache( int w = 0, int h = 0, Images::Options options = 0, int outerw = -1, int outerh = -1, const style::color *colored = nullptr) const; - QPixmap pixColoredNoCache( - Data::FileOrigin origin, + [[nodiscard]] QPixmap pixColoredNoCache( style::color add, - int32 w = 0, - int32 h = 0, + int w = 0, + int h = 0, bool smooth = false) const; - QPixmap pixBlurredColoredNoCache( - Data::FileOrigin origin, + [[nodiscard]] QPixmap pixBlurredColoredNoCache( style::color add, - int32 w, - int32 h = 0) const; - - int width() const { - return _source->width(); - } - int height() const { - return _source->height(); - } - QSize size() const { - return { width(), height() }; - } - void load(); - - bool loaded() const; - bool isNull() const; - - ~Image(); + int w, + int h = 0) const; private: - void checkSource() const; - void invalidateSizeCache() const; - - std::unique_ptr _source; - mutable QMap _sizesCache; - mutable QImage _data; + const QImage _data; + mutable base::flat_map _cache; }; diff --git a/Telegram/SourceFiles/ui/image/image_source.h b/Telegram/SourceFiles/ui/image/image_source.h deleted file mode 100644 index b17ac9465f..0000000000 --- a/Telegram/SourceFiles/ui/image/image_source.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -This file is part of Telegram Desktop, -the official desktop application for the Telegram messaging service. - -For license and copyright information please follow this link: -https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL -*/ -#pragma once - -#include "ui/image/image.h" - -namespace Images { - -class ImageSource : public Source { -public: - explicit ImageSource(const QString &path); - explicit ImageSource(const QByteArray &content); - explicit ImageSource(QImage &&data); - - void load() override; - QImage takeLoaded() override; - - int width() override; - int height() override; - -private: - QImage _data; - -}; - -} // namespace Images diff --git a/Telegram/SourceFiles/window/notifications_utilities.cpp b/Telegram/SourceFiles/window/notifications_utilities.cpp index d32e72ee68..0bc77640a5 100644 --- a/Telegram/SourceFiles/window/notifications_utilities.cpp +++ b/Telegram/SourceFiles/window/notifications_utilities.cpp @@ -24,11 +24,26 @@ constexpr int kNotifyDeletePhotoAfterMs = 60000; CachedUserpics::CachedUserpics(Type type) : _type(type) -, _clearTimer([=] { onClear(); }) { +, _clearTimer([=] { clear(); }) { QDir().mkpath(cWorkingDir() + qsl("tdata/temp")); } -QString CachedUserpics::get(const InMemoryKey &key, PeerData *peer) { +CachedUserpics::~CachedUserpics() { + if (_someSavedFlag) { + crl::time result = 0; + for (const auto &item : std::as_const(_images)) { + QFile(item.path).remove(); + } + + // This works about 1200ms on Windows for a folder with one image O_o + // psDeleteDir(cWorkingDir() + qsl("tdata/temp")); + } +} + +QString CachedUserpics::get( + const InMemoryKey &key, + not_null peer, + std::shared_ptr &view) { auto ms = crl::now(); auto i = _images.find(key); if (i != _images.cend()) { @@ -46,16 +61,15 @@ QString CachedUserpics::get(const InMemoryKey &key, PeerData *peer) { } v.path = cWorkingDir() + qsl("tdata/temp/") + QString::number(rand_value(), 16) + qsl(".png"); if (key.first || key.second) { - auto userpic = std::shared_ptr(); // #TODO optimize userpic if (peer->isSelf()) { const auto method = (_type == Type::Rounded) ? Ui::EmptyUserpic::GenerateSavedMessagesRounded : Ui::EmptyUserpic::GenerateSavedMessages; method(st::notifyMacPhotoSize).save(v.path, "PNG"); } else if (_type == Type::Rounded) { - peer->saveUserpicRounded(userpic, v.path, st::notifyMacPhotoSize); + peer->saveUserpicRounded(view, v.path, st::notifyMacPhotoSize); } else { - peer->saveUserpic(userpic, v.path, st::notifyMacPhotoSize); + peer->saveUserpic(view, v.path, st::notifyMacPhotoSize); } } else { Core::App().logoNoMargin().save(v.path, "PNG"); @@ -98,7 +112,7 @@ void CachedUserpics::clearInMs(int ms) { _clearTimer.callOnce(ms); } -void CachedUserpics::onClear() { +void CachedUserpics::clear() { auto ms = crl::now(); auto minuntil = clear(ms); if (minuntil) { @@ -106,17 +120,5 @@ void CachedUserpics::onClear() { } } -CachedUserpics::~CachedUserpics() { - if (_someSavedFlag) { - crl::time result = 0; - for (const auto &item : std::as_const(_images)) { - QFile(item.path).remove(); - } - -// This works about 1200ms on Windows for a folder with one image O_o -// psDeleteDir(cWorkingDir() + qsl("tdata/temp")); - } -} - } // namespace Notifications } // namespace Window diff --git a/Telegram/SourceFiles/window/notifications_utilities.h b/Telegram/SourceFiles/window/notifications_utilities.h index eede77d5b7..3215049399 100644 --- a/Telegram/SourceFiles/window/notifications_utilities.h +++ b/Telegram/SourceFiles/window/notifications_utilities.h @@ -10,27 +10,30 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/notifications_manager.h" #include "base/timer.h" +namespace Data { +class CloudImageView; +} // namespace Data + namespace Window { namespace Notifications { class CachedUserpics : public QObject { - Q_OBJECT - public: enum class Type { Rounded, Circled, }; + CachedUserpics(Type type); - - QString get(const InMemoryKey &key, PeerData *peer); - ~CachedUserpics(); -private slots: - void onClear(); + [[nodiscard]] QString get( + const InMemoryKey &key, + not_null peer, + std::shared_ptr &view); private: + void clear(); void clearInMs(int ms); crl::time clear(crl::time ms); diff --git a/Telegram/SourceFiles/window/window_media_preview.cpp b/Telegram/SourceFiles/window/window_media_preview.cpp index 3e2197558b..4ed7bf3a12 100644 --- a/Telegram/SourceFiles/window/window_media_preview.cpp +++ b/Telegram/SourceFiles/window/window_media_preview.cpp @@ -265,13 +265,13 @@ QPixmap MediaPreviewWidget::currentImage() const { return QPixmap(); } else if (const auto image = _documentMedia->getStickerLarge()) { QSize s = currentDimensions(); - _cache = image->pix(_origin, s.width(), s.height()); + _cache = image->pix(s.width(), s.height()); _cacheStatus = CacheLoaded; } else if (_cacheStatus != CacheThumbLoaded && _document->hasThumbnail() && _documentMedia->thumbnail()) { QSize s = currentDimensions(); - _cache = _documentMedia->thumbnail()->pixBlurred(_origin, s.width(), s.height()); + _cache = _documentMedia->thumbnail()->pixBlurred(s.width(), s.height()); _cacheStatus = CacheThumbLoaded; } } @@ -290,10 +290,10 @@ QPixmap MediaPreviewWidget::currentImage() const { QSize s = currentDimensions(); const auto thumbnail = _documentMedia->thumbnail(); if (thumbnail) { - _cache = thumbnail->pixBlurred(_origin, s.width(), s.height()); + _cache = thumbnail->pixBlurred(s.width(), s.height()); _cacheStatus = CacheThumbLoaded; } else if (const auto blurred = _documentMedia->thumbnailInline()) { - _cache = blurred->pixBlurred(_origin, s.width(), s.height()); + _cache = blurred->pixBlurred(s.width(), s.height()); _cacheStatus = CacheThumbLoaded; } } @@ -302,7 +302,7 @@ QPixmap MediaPreviewWidget::currentImage() const { if (_cacheStatus != CacheLoaded) { if (_photoMedia->loaded()) { QSize s = currentDimensions(); - _cache = _photoMedia->image(Data::PhotoSize::Large)->pix(_origin, s.width(), s.height()); + _cache = _photoMedia->image(Data::PhotoSize::Large)->pix(s.width(), s.height()); _cacheStatus = CacheLoaded; } else { _photo->load(_origin); @@ -310,14 +310,14 @@ QPixmap MediaPreviewWidget::currentImage() const { QSize s = currentDimensions(); if (const auto thumbnail = _photoMedia->image( Data::PhotoSize::Thumbnail)) { - _cache = thumbnail->pixBlurred(_origin, s.width(), s.height()); + _cache = thumbnail->pixBlurred(s.width(), s.height()); _cacheStatus = CacheThumbLoaded; } else if (const auto small = _photoMedia->image( Data::PhotoSize::Small)) { - _cache = small->pixBlurred(_origin, s.width(), s.height()); + _cache = small->pixBlurred(s.width(), s.height()); _cacheStatus = CacheThumbLoaded; } else if (const auto blurred = _photoMedia->thumbnailInline()) { - _cache = blurred->pixBlurred(_origin, s.width(), s.height()); + _cache = blurred->pixBlurred(s.width(), s.height()); _cacheStatus = CacheThumbLoaded; } else { _photoMedia->wanted(Data::PhotoSize::Small, _origin);