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:
@@ -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 {
|
||||
|
Reference in New Issue
Block a user