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

Use Images::Read instead of App::readImage.

This commit is contained in:
John Preston
2021-08-11 18:40:17 +03:00
parent b150ab8ef5
commit c79cd0b692
56 changed files with 155 additions and 293 deletions

View File

@@ -23,7 +23,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/crash_reports.h"
#include "base/bytes.h"
#include "base/openssl_help.h"
#include "app.h"
namespace {
@@ -163,11 +162,10 @@ void FileLoader::readImage(int progressiveSizeLimit) const {
const auto buffer = progressiveSizeLimit
? QByteArray::fromRawData(_data.data(), progressiveSizeLimit)
: _data;
auto format = QByteArray();
auto image = App::readImage(buffer, &format, false);
if (!image.isNull()) {
_imageData = std::move(image);
_imageFormat = format;
auto read = Images::Read({ .content = buffer });
if (!read.image.isNull()) {
_imageData = std::move(read.image);
_imageFormat = read.format;
}
}
@@ -290,13 +288,12 @@ void FileLoader::loadLocal(const Storage::Cache::Key &key) {
value = std::move(value),
done = std::move(callback)
]() mutable {
auto format = QByteArray();
auto image = App::readImage(value, &format, false);
if (!image.isNull()) {
auto read = Images::Read({ .content = value });
if (!read.image.isNull()) {
done(
std::move(value),
std::move(image),
std::move(format));
std::move(read.image),
std::move(read.format));
} else {
done(std::move(value), {}, {});
}

View File

@@ -31,7 +31,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mainwidget.h"
#include "mainwindow.h"
#include "main/main_session.h"
#include "app.h"
#include <QtCore/QBuffer>
#include <QtGui/QImageWriter>
@@ -642,25 +641,25 @@ bool FileLoadTask::CheckForImage(
const QString &filepath,
const QByteArray &content,
std::unique_ptr<Ui::PreparedFileInformation> &result) {
auto animated = false;
auto image = [&] {
auto read = [&] {
if (filepath.endsWith(qstr(".tgs"), Qt::CaseInsensitive)) {
auto image = Lottie::ReadThumbnail(
Lottie::ReadContent(content, filepath));
if (!image.isNull()) {
animated = true;
const auto success = !image.isNull();
if (success) {
result->filemime = qstr("application/x-tgsticker");
}
return image;
return Images::ReadResult{
.image = std::move(image),
.animated = success,
};
}
if (!content.isEmpty()) {
return App::readImage(content, nullptr, false, &animated);
} else if (!filepath.isEmpty()) {
return App::readImage(filepath, nullptr, false, &animated);
}
return QImage();
return Images::Read({
.path = filepath,
.content = content,
});
}();
return FillImageInformation(std::move(image), animated, result);
return FillImageInformation(std::move(read.image), read.animated, result);
}
bool FileLoadTask::FillImageInformation(

View File

@@ -14,7 +14,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/image/image_prepare.h"
#include "ui/chat/attach/attach_extensions.h"
#include "ui/chat/attach/attach_prepare.h"
#include "app.h"
#include <QtCore/QSemaphore>
#include <QtCore/QMimeData>
@@ -164,7 +163,7 @@ MimeDataState ComputeMimeDataState(const QMimeData *data) {
if (filesize > kFileSizeLimit) {
return MimeDataState::None;
} else if (allAreSmallImages) {
if (filesize > App::kImageSizeLimit) {
if (filesize > Images::kReadBytesLimit) {
allAreSmallImages = false;
} else if (!HasExtensionFrom(file, imageExtensions)) {
allAreSmallImages = false;