diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index 28af6957f..bedf44e92 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -80,7 +80,17 @@ EditCaptionBox::EditCaptionBox( _photoMedia = photo->createMediaView(); _photoMedia->wanted(PhotoSize::Large, _msgId); image = _photoMedia->image(PhotoSize::Large); + if (!image) { + image = _photoMedia->image(PhotoSize::Thumbnail); + if (!image) { + image = _photoMedia->image(PhotoSize::Small); + if (!image) { + image = _photoMedia->thumbnailInline(); + } + } + } dimensions = _photoMedia->size(PhotoSize::Large); + _photo = true; } else if (const auto document = media->document()) { _documentMedia = document->createMediaView(); _documentMedia->thumbnailWanted(_msgId); @@ -183,14 +193,23 @@ EditCaptionBox::EditCaptionBox( maxH = dimensions.height(); _thumbnailImage = image; _refreshThumbnail = [=] { - if (!_thumbnailImage) { - return; - } - _thumb = _thumbnailImage->pixNoCache( + const auto photo = _photoMedia + ? _photoMedia->image(Data::PhotoSize::Large) + : nullptr; + const auto use = photo + ? photo + : _thumbnailImage + ? _thumbnailImage + : Image::BlankMedia().get(); + const auto options = Images::Option::Smooth + | ((_photoMedia && !photo) + ? Images::Option::Blurred + : Images::Option(0)); + _thumb = use->pixNoCache( _msgId, maxW * cIntRetinaFactor(), maxH * cIntRetinaFactor(), - Images::Option::Smooth, + options, maxW, maxH); }; @@ -260,10 +279,10 @@ EditCaptionBox::EditCaptionBox( } Assert(_animated || _photo || _doc); - _thumbnailImageLoaded = _thumbnailImage + _thumbnailImageLoaded = _photoMedia + ? _photoMedia->image(Data::PhotoSize::Large) + : _thumbnailImage ? _thumbnailImage->loaded() - : _photoMedia - ? false : _documentMedia ? !_documentMedia->owner()->hasThumbnail() : true; @@ -271,7 +290,9 @@ EditCaptionBox::EditCaptionBox( subscribe(_controller->session().downloaderTaskFinished(), [=] { if (_thumbnailImageLoaded) { return; - } else if (!_thumbnailImage && _photoMedia) { + } else if (!_thumbnailImage + && _photoMedia + && _photoMedia->image(PhotoSize::Large)) { _thumbnailImage = _photoMedia->image(PhotoSize::Large); } else if (!_thumbnailImage && _documentMedia @@ -279,9 +300,12 @@ EditCaptionBox::EditCaptionBox( _thumbnailImage = _documentMedia->thumbnail(); } if (_thumbnailImage && _thumbnailImage->loaded()) { - _thumbnailImageLoaded = true; - _refreshThumbnail(); - update(); + _thumbnailImageLoaded = !_photoMedia + || _photoMedia->image(PhotoSize::Large); + if (_thumbnailImageLoaded) { + _refreshThumbnail(); + update(); + } } }); } diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp index 274367fca..71d25fdf1 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp @@ -1125,7 +1125,6 @@ TextState Contact::getState( } void Contact::prepareThumbnail(int width, int height) const { - // #TODO optimize use photo / document thumbnail as well const auto thumb = getResultThumb(); if (!thumb) { if (_thumb.width() != width * cIntRetinaFactor() || _thumb.height() != height * cIntRetinaFactor()) { @@ -1215,7 +1214,6 @@ void Article::paint(Painter &p, const QRect &clip, const PaintContext *context) prepareThumbnail(st::inlineThumbSize, st::inlineThumbSize); QRect rthumb(style::rtlrect(0, st::inlineRowMargin, st::inlineThumbSize, st::inlineThumbSize, _width)); if (_thumb.isNull()) { - // #TODO optimize use photo / document thumbnail as well const auto thumb = getResultThumb(); if (!thumb && !_thumbLetter.isEmpty()) { int32 index = (_thumbLetter.at(0).unicode() % 4); @@ -1281,7 +1279,6 @@ TextState Article::getState( } void Article::prepareThumbnail(int width, int height) const { - // #TODO optimize use photo / document thumbnail as well const auto thumb = getResultThumb(); if (!thumb) { if (_thumb.width() != width * cIntRetinaFactor() || _thumb.height() != height * cIntRetinaFactor()) { diff --git a/Telegram/SourceFiles/storage/localimageloader.cpp b/Telegram/SourceFiles/storage/localimageloader.cpp index b134dc7ba..5ed687d79 100644 --- a/Telegram/SourceFiles/storage/localimageloader.cpp +++ b/Telegram/SourceFiles/storage/localimageloader.cpp @@ -853,10 +853,6 @@ void FileLoadTask::process() { } else if (isAnimation) { attributes.push_back(MTP_documentAttributeAnimated()); } else if (_type != SendMediaType::File) { - auto thumb = (w > 100 || h > 100) ? fullimage.scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation) : fullimage; - photoThumbs.emplace('s', thumb); - photoSizes.push_back(MTP_photoSize(MTP_string("s"), MTP_fileLocationToBeDeprecated(MTP_long(0), MTP_int(0)), MTP_int(thumb.width()), MTP_int(thumb.height()), MTP_int(0))); - auto medium = (w > 320 || h > 320) ? fullimage.scaled(320, 320, Qt::KeepAspectRatio, Qt::SmoothTransformation) : fullimage; photoThumbs.emplace('m', medium); photoSizes.push_back(MTP_photoSize(MTP_string("m"), MTP_fileLocationToBeDeprecated(MTP_long(0), MTP_int(0)), MTP_int(medium.width()), MTP_int(medium.height()), MTP_int(0))); diff --git a/Telegram/SourceFiles/ui/image/image_location.h b/Telegram/SourceFiles/ui/image/image_location.h index a0421c684..dd57520d3 100644 --- a/Telegram/SourceFiles/ui/image/image_location.h +++ b/Telegram/SourceFiles/ui/image/image_location.h @@ -378,6 +378,8 @@ struct PlainUrlLocation { }; struct InMemoryLocation { + ~InMemoryLocation() = default; + QByteArray bytes; friend inline bool operator==(