mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-23 09:37:08 +02:00
parent
7c537cd787
commit
84288112fc
13 changed files with 67 additions and 27 deletions
|
@ -451,7 +451,8 @@ void EditCaptionBox::setupPhotoEditorEventHandler() {
|
||||||
&file.information->media);
|
&file.information->media);
|
||||||
|
|
||||||
image->modifications = mods;
|
image->modifications = mods;
|
||||||
Storage::UpdateImageDetails(file, previewWidth);
|
const auto sideLimit = PhotoSideLimit();
|
||||||
|
Storage::UpdateImageDetails(file, previewWidth, sideLimit);
|
||||||
rebuildPreview();
|
rebuildPreview();
|
||||||
};
|
};
|
||||||
const auto fileImage = std::make_shared<Image>(*large);
|
const auto fileImage = std::make_shared<Image>(*large);
|
||||||
|
|
|
@ -348,8 +348,9 @@ void SendFilesBox::enqueueNextPrepare() {
|
||||||
_list.filesToProcess.pop_front();
|
_list.filesToProcess.pop_front();
|
||||||
const auto weak = Ui::MakeWeak(this);
|
const auto weak = Ui::MakeWeak(this);
|
||||||
_preparing = true;
|
_preparing = true;
|
||||||
crl::async([weak, file = std::move(file)]() mutable {
|
const auto sideLimit = PhotoSideLimit(); // Get on main thread.
|
||||||
Storage::PrepareDetails(file, st::sendMediaPreviewSize);
|
crl::async([weak, sideLimit, file = std::move(file)]() mutable {
|
||||||
|
Storage::PrepareDetails(file, st::sendMediaPreviewSize, sideLimit);
|
||||||
crl::on_main([weak, file = std::move(file)]() mutable {
|
crl::on_main([weak, file = std::move(file)]() mutable {
|
||||||
if (weak) {
|
if (weak) {
|
||||||
weak->addPreparedAsyncFile(std::move(file));
|
weak->addPreparedAsyncFile(std::move(file));
|
||||||
|
|
|
@ -23,7 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr auto kPhotoSideLimit = 1280;
|
constexpr auto kPhotoSideLimit = 2560;
|
||||||
|
|
||||||
using Data::PhotoMedia;
|
using Data::PhotoMedia;
|
||||||
using Data::PhotoSize;
|
using Data::PhotoSize;
|
||||||
|
|
|
@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/boxes/confirm_box.h" // InformBox
|
#include "ui/boxes/confirm_box.h" // InformBox
|
||||||
#include "editor/editor_layer_widget.h"
|
#include "editor/editor_layer_widget.h"
|
||||||
#include "editor/photo_editor.h"
|
#include "editor/photo_editor.h"
|
||||||
|
#include "storage/localimageloader.h"
|
||||||
#include "storage/storage_media_prepare.h"
|
#include "storage/storage_media_prepare.h"
|
||||||
#include "ui/chat/attach/attach_prepare.h"
|
#include "ui/chat/attach/attach_prepare.h"
|
||||||
#include "window/window_controller.h"
|
#include "window/window_controller.h"
|
||||||
|
@ -42,10 +43,11 @@ void OpenWithPreparedFile(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto sideLimit = PhotoSideLimit();
|
||||||
auto callback = [=, done = std::move(doneCallback)](
|
auto callback = [=, done = std::move(doneCallback)](
|
||||||
const PhotoModifications &mods) {
|
const PhotoModifications &mods) {
|
||||||
image->modifications = mods;
|
image->modifications = mods;
|
||||||
Storage::UpdateImageDetails(*file, previewWidth);
|
Storage::UpdateImageDetails(*file, previewWidth, sideLimit);
|
||||||
{
|
{
|
||||||
using namespace Ui;
|
using namespace Ui;
|
||||||
const auto size = file->preview.size();
|
const auto size = file->preview.size();
|
||||||
|
|
|
@ -27,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
#include "window/window_controller.h"
|
#include "window/window_controller.h"
|
||||||
#include "settings/settings_common.h"
|
#include "settings/settings_common.h"
|
||||||
|
#include "storage/localimageloader.h"
|
||||||
#include "styles/style_settings.h"
|
#include "styles/style_settings.h"
|
||||||
#include "styles/style_layers.h"
|
#include "styles/style_layers.h"
|
||||||
|
|
||||||
|
@ -142,6 +143,7 @@ void SetupExperimental(
|
||||||
addToggle(Ui::GL::kOptionAllowLinuxNvidiaOpenGL);
|
addToggle(Ui::GL::kOptionAllowLinuxNvidiaOpenGL);
|
||||||
addToggle(Ui::kOptionUseSmallMsgBubbleRadius);
|
addToggle(Ui::kOptionUseSmallMsgBubbleRadius);
|
||||||
addToggle(Media::Player::kOptionDisableAutoplayNext);
|
addToggle(Media::Player::kOptionDisableAutoplayNext);
|
||||||
|
addToggle(kOptionSendLargePhotos);
|
||||||
addToggle(Settings::kOptionMonoSettingsIcons);
|
addToggle(Settings::kOptionMonoSettingsIcons);
|
||||||
addToggle(Webview::kOptionWebviewDebugEnabled);
|
addToggle(Webview::kOptionWebviewDebugEnabled);
|
||||||
addToggle(kOptionAutoScrollInactiveChat);
|
addToggle(kOptionAutoScrollInactiveChat);
|
||||||
|
|
|
@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
#include "core/file_utilities.h"
|
#include "core/file_utilities.h"
|
||||||
#include "core/mime_type.h"
|
#include "core/mime_type.h"
|
||||||
|
#include "base/options.h"
|
||||||
#include "base/unixtime.h"
|
#include "base/unixtime.h"
|
||||||
#include "base/random.h"
|
#include "base/random.h"
|
||||||
#include "editor/scene/scene_item_sticker.h"
|
#include "editor/scene/scene_item_sticker.h"
|
||||||
|
@ -49,6 +50,13 @@ constexpr auto kRecompressAfterBpp = 4;
|
||||||
|
|
||||||
using Ui::ValidateThumbDimensions;
|
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 {
|
struct PreparedFileThumbnail {
|
||||||
uint64 id = 0;
|
uint64 id = 0;
|
||||||
QString name;
|
QString name;
|
||||||
|
@ -191,8 +199,22 @@ struct PreparedFileThumbnail {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] int PhotoSideLimit(bool large) {
|
||||||
|
return large ? 2560 : 1280;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] int PhotoSideLimitAtomic() {
|
||||||
|
return PhotoSideLimit(SendLargePhotosAtomic.load());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
const char kOptionSendLargePhotos[] = "send-large-photos";
|
||||||
|
|
||||||
|
int PhotoSideLimit() {
|
||||||
|
return PhotoSideLimit(SendLargePhotos.value());
|
||||||
|
}
|
||||||
|
|
||||||
SendMediaPrepare::SendMediaPrepare(
|
SendMediaPrepare::SendMediaPrepare(
|
||||||
const QString &file,
|
const QString &file,
|
||||||
const PeerId &peer,
|
const PeerId &peer,
|
||||||
|
@ -518,7 +540,6 @@ void FileLoadResult::setThumbData(const QByteArray &thumbdata) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FileLoadTask::FileLoadTask(
|
FileLoadTask::FileLoadTask(
|
||||||
not_null<Main::Session*> session,
|
not_null<Main::Session*> session,
|
||||||
const QString &filepath,
|
const QString &filepath,
|
||||||
|
@ -543,6 +564,8 @@ FileLoadTask::FileLoadTask(
|
||||||
Expects(to.options.scheduled
|
Expects(to.options.scheduled
|
||||||
|| !to.replaceMediaOf
|
|| !to.replaceMediaOf
|
||||||
|| IsServerMsgId(to.replaceMediaOf));
|
|| IsServerMsgId(to.replaceMediaOf));
|
||||||
|
|
||||||
|
SendLargePhotosAtomic = SendLargePhotos.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
FileLoadTask::FileLoadTask(
|
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;
|
auto medium = (w > 320 || h > 320) ? fullimage.scaled(320, 320, Qt::KeepAspectRatio, Qt::SmoothTransformation) : fullimage;
|
||||||
|
|
||||||
const auto downscaled = (w > 1280 || h > 1280);
|
const auto limit = PhotoSideLimitAtomic();
|
||||||
auto full = downscaled ? fullimage.scaled(1280, 1280, Qt::KeepAspectRatio, Qt::SmoothTransformation) : fullimage;
|
const auto downscaled = (w > limit || h > limit);
|
||||||
|
auto full = downscaled ? fullimage.scaled(limit, limit, Qt::KeepAspectRatio, Qt::SmoothTransformation) : fullimage;
|
||||||
if (downscaled) {
|
if (downscaled) {
|
||||||
fullimagebytes = fullimageformat = QByteArray();
|
fullimagebytes = fullimageformat = QByteArray();
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,10 @@ constexpr auto kFileSizeLimit = 2'000 * int64(1024 * 1024);
|
||||||
// Load files up to 4'000 MB.
|
// Load files up to 4'000 MB.
|
||||||
constexpr auto kFileSizePremiumLimit = 4'000 * int64(1024 * 1024);
|
constexpr auto kFileSizePremiumLimit = 4'000 * int64(1024 * 1024);
|
||||||
|
|
||||||
|
extern const char kOptionSendLargePhotos[];
|
||||||
|
|
||||||
|
[[nodiscard]] int PhotoSideLimit();
|
||||||
|
|
||||||
enum class SendMediaType {
|
enum class SendMediaType {
|
||||||
Photo,
|
Photo,
|
||||||
Audio,
|
Audio,
|
||||||
|
|
|
@ -47,13 +47,10 @@ bool ValidVideoForAlbum(const PreparedFileInformation::Video &video) {
|
||||||
return Ui::ValidateThumbDimensions(width, height);
|
return Ui::ValidateThumbDimensions(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize PrepareShownDimensions(const QImage &preview) {
|
QSize PrepareShownDimensions(const QImage &preview, int sideLimit) {
|
||||||
constexpr auto kMaxWidth = 1280;
|
|
||||||
constexpr auto kMaxHeight = 1280;
|
|
||||||
|
|
||||||
const auto result = preview.size();
|
const auto result = preview.size();
|
||||||
return (result.width() > kMaxWidth || result.height() > kMaxHeight)
|
return (result.width() > sideLimit || result.height() > sideLimit)
|
||||||
? result.scaled(kMaxWidth, kMaxHeight, Qt::KeepAspectRatio)
|
? result.scaled(sideLimit, sideLimit, Qt::KeepAspectRatio)
|
||||||
: result;
|
: result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,10 +60,11 @@ void PrepareDetailsInParallel(PreparedList &result, int previewWidth) {
|
||||||
if (result.files.empty()) {
|
if (result.files.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const auto sideLimit = PhotoSideLimit(); // Get on main thread.
|
||||||
QSemaphore semaphore;
|
QSemaphore semaphore;
|
||||||
for (auto &file : result.files) {
|
for (auto &file : result.files) {
|
||||||
crl::async([=, &semaphore, &file] {
|
crl::async([=, &semaphore, &file] {
|
||||||
PrepareDetails(file, previewWidth);
|
PrepareDetails(file, previewWidth, sideLimit);
|
||||||
semaphore.release();
|
semaphore.release();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -272,7 +270,7 @@ std::optional<PreparedList> PreparedFileFromFilesDialog(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrepareDetails(PreparedFile &file, int previewWidth) {
|
void PrepareDetails(PreparedFile &file, int previewWidth, int sideLimit) {
|
||||||
if (!file.path.isEmpty()) {
|
if (!file.path.isEmpty()) {
|
||||||
file.information = FileLoadTask::ReadMediaInformation(
|
file.information = FileLoadTask::ReadMediaInformation(
|
||||||
file.path,
|
file.path,
|
||||||
|
@ -293,7 +291,7 @@ void PrepareDetails(PreparedFile &file, int previewWidth) {
|
||||||
&file.information->media)) {
|
&file.information->media)) {
|
||||||
Assert(!image->data.isNull());
|
Assert(!image->data.isNull());
|
||||||
if (ValidPhotoForAlbum(*image, file.information->filemime)) {
|
if (ValidPhotoForAlbum(*image, file.information->filemime)) {
|
||||||
UpdateImageDetails(file, previewWidth);
|
UpdateImageDetails(file, previewWidth, sideLimit);
|
||||||
file.type = PreparedFile::Type::Photo;
|
file.type = PreparedFile::Type::Photo;
|
||||||
} else if (image->animated) {
|
} else if (image->animated) {
|
||||||
file.type = PreparedFile::Type::None;
|
file.type = PreparedFile::Type::None;
|
||||||
|
@ -303,7 +301,10 @@ void PrepareDetails(PreparedFile &file, int previewWidth) {
|
||||||
if (ValidVideoForAlbum(*video)) {
|
if (ValidVideoForAlbum(*video)) {
|
||||||
auto blurred = Images::Blur(
|
auto blurred = Images::Blur(
|
||||||
Images::Opaque(base::duplicate(video->thumbnail)));
|
Images::Opaque(base::duplicate(video->thumbnail)));
|
||||||
file.shownDimensions = PrepareShownDimensions(video->thumbnail);
|
file.originalDimensions = video->thumbnail.size();
|
||||||
|
file.shownDimensions = PrepareShownDimensions(
|
||||||
|
video->thumbnail,
|
||||||
|
sideLimit);
|
||||||
file.preview = std::move(blurred).scaledToWidth(
|
file.preview = std::move(blurred).scaledToWidth(
|
||||||
previewWidth * cIntRetinaFactor(),
|
previewWidth * cIntRetinaFactor(),
|
||||||
Qt::SmoothTransformation);
|
Qt::SmoothTransformation);
|
||||||
|
@ -316,7 +317,10 @@ void PrepareDetails(PreparedFile &file, int previewWidth) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateImageDetails(PreparedFile &file, int previewWidth) {
|
void UpdateImageDetails(
|
||||||
|
PreparedFile &file,
|
||||||
|
int previewWidth,
|
||||||
|
int sideLimit) {
|
||||||
const auto image = std::get_if<Image>(&file.information->media);
|
const auto image = std::get_if<Image>(&file.information->media);
|
||||||
if (!image) {
|
if (!image) {
|
||||||
return;
|
return;
|
||||||
|
@ -326,7 +330,8 @@ void UpdateImageDetails(PreparedFile &file, int previewWidth) {
|
||||||
? Editor::ImageModified(image->data, image->modifications)
|
? Editor::ImageModified(image->data, image->modifications)
|
||||||
: image->data;
|
: image->data;
|
||||||
Assert(!preview.isNull());
|
Assert(!preview.isNull());
|
||||||
file.shownDimensions = PrepareShownDimensions(preview);
|
file.originalDimensions = preview.size();
|
||||||
|
file.shownDimensions = PrepareShownDimensions(preview, sideLimit);
|
||||||
const auto toWidth = std::min(
|
const auto toWidth = std::min(
|
||||||
previewWidth,
|
previewWidth,
|
||||||
style::ConvertScale(preview.width())
|
style::ConvertScale(preview.width())
|
||||||
|
|
|
@ -51,8 +51,11 @@ enum class MimeDataState {
|
||||||
QImage &&image,
|
QImage &&image,
|
||||||
QByteArray &&content,
|
QByteArray &&content,
|
||||||
int previewWidth);
|
int previewWidth);
|
||||||
void PrepareDetails(Ui::PreparedFile &file, int previewWidth);
|
void PrepareDetails(Ui::PreparedFile &file, int previewWidth, int sideLimit);
|
||||||
void UpdateImageDetails(Ui::PreparedFile &file, int previewWidth);
|
void UpdateImageDetails(
|
||||||
|
Ui::PreparedFile &file,
|
||||||
|
int previewWidth,
|
||||||
|
int sideLimit);
|
||||||
|
|
||||||
bool ApplyModifications(Ui::PreparedList &list);
|
bool ApplyModifications(Ui::PreparedList &list);
|
||||||
|
|
||||||
|
|
|
@ -81,8 +81,7 @@ AlbumThumbnail::AlbumThumbnail(
|
||||||
const auto filepath = file.path;
|
const auto filepath = file.path;
|
||||||
if (filepath.isEmpty()) {
|
if (filepath.isEmpty()) {
|
||||||
_name = "image.png";
|
_name = "image.png";
|
||||||
_status = FormatImageSizeText(_fullPreview.size()
|
_status = FormatImageSizeText(file.originalDimensions);
|
||||||
/ _fullPreview.devicePixelRatio());
|
|
||||||
} else {
|
} else {
|
||||||
auto fileinfo = QFileInfo(filepath);
|
auto fileinfo = QFileInfo(filepath);
|
||||||
_name = fileinfo.fileName();
|
_name = fileinfo.fileName();
|
||||||
|
|
|
@ -103,7 +103,6 @@ void ItemSingleFilePreview::preparePreview(not_null<DocumentData*> document) {
|
||||||
|
|
||||||
data.name = Text::FormatSongName(filename, songTitle, songPerformer)
|
data.name = Text::FormatSongName(filename, songTitle, songPerformer)
|
||||||
.string();
|
.string();
|
||||||
data.statusText = FormatSizeText(document->size);
|
|
||||||
} else {
|
} else {
|
||||||
data.name = document->filename();
|
data.name = document->filename();
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,6 +80,7 @@ struct PreparedFile {
|
||||||
std::unique_ptr<Ui::PreparedFileInformation> information;
|
std::unique_ptr<Ui::PreparedFileInformation> information;
|
||||||
QImage preview;
|
QImage preview;
|
||||||
QSize shownDimensions;
|
QSize shownDimensions;
|
||||||
|
QSize originalDimensions;
|
||||||
Type type = Type::File;
|
Type type = Type::File;
|
||||||
bool spoiler = false;
|
bool spoiler = false;
|
||||||
};
|
};
|
||||||
|
|
|
@ -41,8 +41,7 @@ void SingleFilePreview::preparePreview(const PreparedFile &file) {
|
||||||
if (filepath.isEmpty()) {
|
if (filepath.isEmpty()) {
|
||||||
auto filename = "image.png";
|
auto filename = "image.png";
|
||||||
data.name = filename;
|
data.name = filename;
|
||||||
data.statusText = FormatImageSizeText(preview.size()
|
data.statusText = FormatImageSizeText(file.originalDimensions);
|
||||||
/ preview.devicePixelRatio());
|
|
||||||
data.fileIsImage = true;
|
data.fileIsImage = true;
|
||||||
} else {
|
} else {
|
||||||
auto fileinfo = QFileInfo(filepath);
|
auto fileinfo = QFileInfo(filepath);
|
||||||
|
|
Loading…
Add table
Reference in a new issue