2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Store replyPreview in unique_ptr<Image>.

This commit is contained in:
John Preston
2018-11-09 19:03:38 +04:00
parent 147079ce2a
commit 2b95b96fa3
8 changed files with 69 additions and 69 deletions

View File

@@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_session.h"
#include "ui/image/image.h"
#include "ui/image/image_source.h"
#include "mainwidget.h"
#include "history/history_media_types.h"
#include "auth_session.h"
@@ -108,42 +109,39 @@ void PhotoData::unload() {
//thumb->unload();
medium->unload();
full->unload();
if (!replyPreview->isNull()) {
// Should be std::unique_ptr<Image>.
delete replyPreview.get();
replyPreview = ImagePtr();
}
_replyPreview = nullptr;
}
ImagePtr PhotoData::makeReplyPreview(Data::FileOrigin origin) {
if (replyPreview->isNull() && !thumb->isNull()) {
Image *PhotoData::getReplyPreview(Data::FileOrigin origin) {
if (!_replyPreview && !thumb->isNull()) {
const auto previewFromImage = [&](const ImagePtr &image) {
if (!image->loaded()) {
image->load(origin);
return ImagePtr();
return std::unique_ptr<Image>();
}
int w = image->width(), h = image->height();
if (w <= 0) w = 1;
if (h <= 0) h = 1;
return Images::Create(
return std::make_unique<Image>(
std::make_unique<Images::ImageSource>(
(w > h
? image->pix(
origin,
w * st::msgReplyBarSize.height() / h,
st::msgReplyBarSize.height())
: image->pix(origin, st::msgReplyBarSize.height())
).toImage(),
"PNG");
).toImage(),
"PNG"));
};
if (thumb->isDelayedStorageImage()
&& !full->isNull()
&& !full->isDelayedStorageImage()) {
replyPreview = previewFromImage(full);
_replyPreview = previewFromImage(full);
} else {
replyPreview = previewFromImage(thumb);
_replyPreview = previewFromImage(thumb);
}
}
return replyPreview;
return _replyPreview.get();
}
MTPInputPhoto PhotoData::mtpInput() const {