2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Allow sending photos larger 1280 (experimental).

Improves #6520.
This commit is contained in:
John Preston
2023-01-02 14:25:44 +04:00
parent 7c537cd787
commit 84288112fc
13 changed files with 67 additions and 27 deletions

View File

@@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_user.h"
#include "core/file_utilities.h"
#include "core/mime_type.h"
#include "base/options.h"
#include "base/unixtime.h"
#include "base/random.h"
#include "editor/scene/scene_item_sticker.h"
@@ -49,6 +50,13 @@ constexpr auto kRecompressAfterBpp = 4;
using Ui::ValidateThumbDimensions;
base::options::toggle SendLargePhotos({
.id = kOptionSendLargePhotos,
.name = "Send large photos",
.description = "Increase the side limit on compressed images to 2560px.",
});
std::atomic<bool> SendLargePhotosAtomic/* = false*/;
struct PreparedFileThumbnail {
uint64 id = 0;
QString name;
@@ -191,8 +199,22 @@ struct PreparedFileThumbnail {
return result;
}
[[nodiscard]] int PhotoSideLimit(bool large) {
return large ? 2560 : 1280;
}
[[nodiscard]] int PhotoSideLimitAtomic() {
return PhotoSideLimit(SendLargePhotosAtomic.load());
}
} // namespace
const char kOptionSendLargePhotos[] = "send-large-photos";
int PhotoSideLimit() {
return PhotoSideLimit(SendLargePhotos.value());
}
SendMediaPrepare::SendMediaPrepare(
const QString &file,
const PeerId &peer,
@@ -518,7 +540,6 @@ void FileLoadResult::setThumbData(const QByteArray &thumbdata) {
}
}
FileLoadTask::FileLoadTask(
not_null<Main::Session*> session,
const QString &filepath,
@@ -543,6 +564,8 @@ FileLoadTask::FileLoadTask(
Expects(to.options.scheduled
|| !to.replaceMediaOf
|| IsServerMsgId(to.replaceMediaOf));
SendLargePhotosAtomic = SendLargePhotos.value();
}
FileLoadTask::FileLoadTask(
@@ -942,8 +965,9 @@ void FileLoadTask::process(Args &&args) {
}
auto medium = (w > 320 || h > 320) ? fullimage.scaled(320, 320, Qt::KeepAspectRatio, Qt::SmoothTransformation) : fullimage;
const auto downscaled = (w > 1280 || h > 1280);
auto full = downscaled ? fullimage.scaled(1280, 1280, Qt::KeepAspectRatio, Qt::SmoothTransformation) : fullimage;
const auto limit = PhotoSideLimitAtomic();
const auto downscaled = (w > limit || h > limit);
auto full = downscaled ? fullimage.scaled(limit, limit, Qt::KeepAspectRatio, Qt::SmoothTransformation) : fullimage;
if (downscaled) {
fullimagebytes = fullimageformat = QByteArray();
}