From c79cd0b692616ccf15fb88ea46a01aef17a77503 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 11 Aug 2021 18:40:17 +0300 Subject: [PATCH] Use Images::Read instead of App::readImage. --- Telegram/SourceFiles/api/api_sending.cpp | 1 - Telegram/SourceFiles/apiwrap.cpp | 2 +- Telegram/SourceFiles/app.cpp | 93 ------------------- Telegram/SourceFiles/app.h | 9 -- Telegram/SourceFiles/boxes/abstract_box.cpp | 1 - Telegram/SourceFiles/boxes/confirm_box.cpp | 1 - .../SourceFiles/boxes/mute_settings_box.cpp | 1 - .../boxes/peers/add_participants_box.cpp | 1 - .../boxes/peers/edit_peer_info_box.cpp | 1 - .../boxes/peers/edit_peer_permissions_box.cpp | 1 - Telegram/SourceFiles/boxes/send_files_box.cpp | 1 - Telegram/SourceFiles/boxes/url_auth_box.cpp | 1 - .../calls/calls_box_controller.cpp | 1 - Telegram/SourceFiles/calls/calls_instance.cpp | 2 +- Telegram/SourceFiles/calls/calls_panel.cpp | 1 - Telegram/SourceFiles/calls/calls_top_bar.cpp | 1 - .../calls/group/calls_group_panel.cpp | 1 - .../chat_helpers/gifs_list_widget.cpp | 1 - .../chat_helpers/gifs_list_widget.h | 1 - .../chat_helpers/stickers_emoji_pack.cpp | 1 - .../SourceFiles/chat_helpers/tabbed_panel.cpp | 1 - Telegram/SourceFiles/core/application.cpp | 7 +- .../SourceFiles/core/click_handler_types.cpp | 1 - .../SourceFiles/core/local_url_handlers.cpp | 1 - Telegram/SourceFiles/data/data_document.cpp | 1 - .../SourceFiles/data/data_document_media.cpp | 7 +- .../data/data_document_resolver.cpp | 22 ++--- .../SourceFiles/data/data_media_types.cpp | 3 +- Telegram/SourceFiles/data/data_photo.cpp | 1 - Telegram/SourceFiles/data/data_wall_paper.cpp | 9 ++ .../data/stickers/data_stickers_set.cpp | 3 +- .../SourceFiles/dialogs/dialogs_entry.cpp | 1 - .../editor/photo_editor_layer_widget.cpp | 9 +- .../SourceFiles/history/history_message.cpp | 1 - .../SourceFiles/history/history_widget.cpp | 13 +-- .../view/history_view_pinned_section.cpp | 1 - .../view/history_view_replies_section.cpp | 13 +-- .../view/history_view_scheduled_section.cpp | 14 +-- .../media/history_view_theme_document.cpp | 25 +++-- .../view/media/history_view_theme_document.h | 1 + .../SourceFiles/media/audio/media_audio.cpp | 16 ++-- .../media/view/media_view_overlay_widget.cpp | 40 ++++---- .../passport/passport_form_controller.cpp | 14 +-- .../passport/passport_panel_edit_scans.cpp | 11 ++- .../SourceFiles/settings/settings_chat.cpp | 9 +- .../settings/settings_information.cpp | 1 - .../SourceFiles/storage/file_download.cpp | 19 ++-- .../SourceFiles/storage/localimageloader.cpp | 25 +++-- .../storage/storage_media_prepare.cpp | 3 +- Telegram/SourceFiles/ui/image/image.cpp | 20 +--- .../window/themes/window_theme.cpp | 6 +- .../window/themes/window_theme_editor.cpp | 7 +- .../window/themes/window_theme_editor_box.cpp | 16 ++-- .../SourceFiles/window/window_controller.cpp | 1 - Telegram/lib_lottie | 2 +- Telegram/lib_ui | 2 +- 56 files changed, 155 insertions(+), 293 deletions(-) diff --git a/Telegram/SourceFiles/api/api_sending.cpp b/Telegram/SourceFiles/api/api_sending.cpp index 4816c1ffa..52a041a64 100644 --- a/Telegram/SourceFiles/api/api_sending.cpp +++ b/Telegram/SourceFiles/api/api_sending.cpp @@ -32,7 +32,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/file_upload.h" #include "mainwidget.h" #include "apiwrap.h" -#include "app.h" namespace Api { namespace { diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 1cda6e6d8..a3904d74f 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -80,7 +80,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/storage_media_prepare.h" #include "storage/storage_account.h" #include "facades.h" -#include "app.h" +#include "app.h" // App::quitting namespace { diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index 167360a97..b96161ef8 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -7,44 +7,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "app.h" -#include "lang/lang_keys.h" -#include "boxes/confirm_box.h" -#include "data/data_channel.h" -#include "data/data_chat.h" -#include "data/data_user.h" -#include "data/data_abstract_structure.h" -#include "data/data_media_types.h" -#include "data/data_session.h" -#include "data/data_document.h" -#include "history/history.h" -#include "history/history_location_manager.h" -#include "history/history_item_components.h" #include "history/view/history_view_element.h" -#include "media/audio/media_audio.h" -#include "ui/image/image.h" -#include "ui/cached_round_corners.h" -#include "inline_bots/inline_bot_layout_item.h" -#include "core/crash_reports.h" #include "core/update_checker.h" #include "core/sandbox.h" #include "core/application.h" -#include "window/notifications_manager.h" -#include "window/window_controller.h" -#include "platform/platform_notifications_manager.h" -#include "storage/file_upload.h" -#include "storage/localstorage.h" -#include "storage/storage_facade.h" -#include "storage/storage_shared_media.h" #include "mainwindow.h" -#include "mainwidget.h" -#include "apiwrap.h" -#include "main/main_session.h" -#include "styles/style_boxes.h" -#include "styles/style_overview.h" -#include "styles/style_media_view.h" -#include "styles/style_chat_helpers.h" -#include "styles/style_chat.h" -#include "styles/style_layers.h" #include #include @@ -65,15 +32,6 @@ HistoryView::Element *hoveredItem = nullptr, namespace App { - void initMedia() { - Ui::StartCachedCorners(); - } - - void deinitMedia() { - Ui::FinishCachedCorners(); - Data::clearGlobalStructures(); - } - void hoveredItem(HistoryView::Element *item) { ::hoveredItem = item; } @@ -164,55 +122,4 @@ namespace App { App::quit(); } - QImage readImage(QByteArray data, QByteArray *format, bool opaque, bool *animated) { - if (data.isEmpty()) { - return QImage(); - } - QByteArray tmpFormat; - QImage result; - QBuffer buffer(&data); - if (!format) { - format = &tmpFormat; - } - { - QImageReader reader(&buffer, *format); - reader.setAutoTransform(true); - if (animated) *animated = reader.supportsAnimation() && reader.imageCount() > 1; - if (!reader.canRead()) { - return QImage(); - } - const auto imageSize = reader.size(); - if (imageSize.width() * imageSize.height() > kImageAreaLimit) { - return QImage(); - } - QByteArray fmt = reader.format(); - if (!fmt.isEmpty()) *format = fmt; - if (!reader.read(&result)) { - return QImage(); - } - fmt = reader.format(); - if (!fmt.isEmpty()) *format = fmt; - } - buffer.seek(0); - auto fmt = QString::fromUtf8(*format).toLower(); - if (opaque) { - result = Images::prepareOpaque(std::move(result)); - } - return result; - } - - QImage readImage(const QString &file, QByteArray *format, bool opaque, bool *animated, QByteArray *content) { - QFile f(file); - if (f.size() > kImageSizeLimit || !f.open(QIODevice::ReadOnly)) { - if (animated) *animated = false; - return QImage(); - } - auto imageBytes = f.readAll(); - auto result = readImage(imageBytes, format, opaque, animated); - if (content && !result.isNull()) { - *content = imageBytes; - } - return result; - } - } diff --git a/Telegram/SourceFiles/app.h b/Telegram/SourceFiles/app.h index 6e581251b..65b111b6a 100644 --- a/Telegram/SourceFiles/app.h +++ b/Telegram/SourceFiles/app.h @@ -7,8 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include "data/data_types.h" - namespace HistoryView { class Element; } // namespace HistoryView @@ -26,9 +24,6 @@ namespace App { HistoryView::Element *mousedItem(); void clearMousedItems(); - void initMedia(); - void deinitMedia(); - enum LaunchState { Launched = 0, QuitRequested = 1, @@ -40,8 +35,4 @@ namespace App { void setLaunchState(LaunchState state); void restart(); - constexpr auto kImageSizeLimit = 64 * 1024 * 1024; // Open images up to 64mb jpg/png/gif - QImage readImage(QByteArray data, QByteArray *format = nullptr, bool opaque = true, bool *animated = nullptr); - QImage readImage(const QString &file, QByteArray *format = nullptr, bool opaque = true, bool *animated = nullptr, QByteArray *content = 0); - }; diff --git a/Telegram/SourceFiles/boxes/abstract_box.cpp b/Telegram/SourceFiles/boxes/abstract_box.cpp index d9d7b7761..e1dfb1cad 100644 --- a/Telegram/SourceFiles/boxes/abstract_box.cpp +++ b/Telegram/SourceFiles/boxes/abstract_box.cpp @@ -9,7 +9,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwidget.h" #include "mainwindow.h" -#include "app.h" namespace Ui { namespace internal { diff --git a/Telegram/SourceFiles/boxes/confirm_box.cpp b/Telegram/SourceFiles/boxes/confirm_box.cpp index 0e291b9b6..02ef67afe 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_box.cpp @@ -41,7 +41,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "mtproto/mtproto_config.h" #include "facades.h" // Ui::showChatsList -#include "app.h" #include "styles/style_layers.h" #include "styles/style_boxes.h" diff --git a/Telegram/SourceFiles/boxes/mute_settings_box.cpp b/Telegram/SourceFiles/boxes/mute_settings_box.cpp index 7fd659c9b..be5137f9a 100644 --- a/Telegram/SourceFiles/boxes/mute_settings_box.cpp +++ b/Telegram/SourceFiles/boxes/mute_settings_box.cpp @@ -14,7 +14,6 @@ Copyright (C) 2017, Nicholas Guriev #include "ui/special_buttons.h" #include "ui/widgets/checkbox.h" #include "ui/widgets/labels.h" -#include "app.h" #include "styles/style_layers.h" #include "styles/style_boxes.h" diff --git a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp index 52d90ca79..2222c232d 100644 --- a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp @@ -30,7 +30,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/profile/info_profile_icon.h" #include "apiwrap.h" #include "facades.h" // Ui::showPeerHistory -#include "app.h" #include "styles/style_boxes.h" namespace { diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp index 286512410..5b80bd8c3 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -47,7 +47,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/wrap/vertical_layout.h" #include "window/window_session_controller.h" #include "info/profile/info_profile_icon.h" -#include "app.h" #include "apiwrap.h" #include "api/api_invite_links.h" #include "facades.h" diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp index 2d4b67ee2..183d988b6 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp @@ -27,7 +27,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "mainwindow.h" #include "apiwrap.h" -#include "app.h" #include "styles/style_layers.h" #include "styles/style_boxes.h" #include "styles/style_info.h" diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index 5007b911a..283f6f1d0 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -52,7 +52,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/application.h" #include "core/core_settings.h" #include "facades.h" // App::LambdaDelayed. -#include "app.h" #include "styles/style_chat.h" #include "styles/style_layers.h" #include "styles/style_boxes.h" diff --git a/Telegram/SourceFiles/boxes/url_auth_box.cpp b/Telegram/SourceFiles/boxes/url_auth_box.cpp index d77e8bd35..84584acdf 100644 --- a/Telegram/SourceFiles/boxes/url_auth_box.cpp +++ b/Telegram/SourceFiles/boxes/url_auth_box.cpp @@ -19,7 +19,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "main/main_session.h" #include "apiwrap.h" -#include "app.h" #include "styles/style_layers.h" #include "styles/style_boxes.h" diff --git a/Telegram/SourceFiles/calls/calls_box_controller.cpp b/Telegram/SourceFiles/calls/calls_box_controller.cpp index b3bd55597..beba2eb45 100644 --- a/Telegram/SourceFiles/calls/calls_box_controller.cpp +++ b/Telegram/SourceFiles/calls/calls_box_controller.cpp @@ -26,7 +26,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/confirm_box.h" #include "base/unixtime.h" #include "api/api_updates.h" -#include "app.h" #include "apiwrap.h" #include "styles/style_layers.h" // st::boxLabel. #include "styles/style_calls.h" diff --git a/Telegram/SourceFiles/calls/calls_instance.cpp b/Telegram/SourceFiles/calls/calls_instance.cpp index d14b12ebc..5939e6f10 100644 --- a/Telegram/SourceFiles/calls/calls_instance.cpp +++ b/Telegram/SourceFiles/calls/calls_instance.cpp @@ -34,7 +34,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwidget.h" #include "mtproto/mtproto_config.h" #include "boxes/rate_call_box.h" -#include "app.h" +#include "app.h" // App::quitting #include #include diff --git a/Telegram/SourceFiles/calls/calls_panel.cpp b/Telegram/SourceFiles/calls/calls_panel.cpp index f66ede2c8..3dd75c45a 100644 --- a/Telegram/SourceFiles/calls/calls_panel.cpp +++ b/Telegram/SourceFiles/calls/calls_panel.cpp @@ -45,7 +45,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/platform_specific.h" #include "base/platform/base_platform_info.h" #include "window/main_window.h" -#include "app.h" #include "webrtc/webrtc_video_track.h" #include "webrtc/webrtc_media_devices.h" #include "styles/style_calls.h" diff --git a/Telegram/SourceFiles/calls/calls_top_bar.cpp b/Telegram/SourceFiles/calls/calls_top_bar.cpp index 451ddf1a8..ca5499a10 100644 --- a/Telegram/SourceFiles/calls/calls_top_bar.cpp +++ b/Telegram/SourceFiles/calls/calls_top_bar.cpp @@ -32,7 +32,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "boxes/abstract_box.h" #include "base/timer.h" -#include "app.h" #include "styles/style_calls.h" #include "styles/style_chat.h" // style::GroupCallUserpics #include "styles/style_layers.h" diff --git a/Telegram/SourceFiles/calls/group/calls_group_panel.cpp b/Telegram/SourceFiles/calls/group/calls_group_panel.cpp index 6a5a1a2f9..1cc67c2a0 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_panel.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_panel.cpp @@ -48,7 +48,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/unixtime.h" #include "base/qt_signal_producer.h" #include "base/timer_rpl.h" -#include "app.h" #include "apiwrap.h" // api().kickParticipant. #include "webrtc/webrtc_video_track.h" #include "webrtc/webrtc_media_devices.h" // UniqueDesktopCaptureSource. diff --git a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp index dd4bc60fe..dfe99608f 100644 --- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp @@ -33,7 +33,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "window/window_session_controller.h" #include "history/view/history_view_cursor_state.h" -#include "app.h" #include "storage/storage_account.h" // Account::writeSavedGifs #include "styles/style_chat_helpers.h" diff --git a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h index fe83d2630..b03485b32 100644 --- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h @@ -11,7 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/timer.h" #include "inline_bots/inline_bot_layout_item.h" #include "layout/layout_mosaic.h" -#include "app.h" #include diff --git a/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.cpp b/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.cpp index 490f09bfc..3ee265c3d 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.cpp @@ -21,7 +21,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/application.h" #include "base/call_delayed.h" #include "apiwrap.h" -#include "app.h" #include "styles/style_chat.h" #include diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp index f39f357c4..a2ceaff77 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp @@ -14,7 +14,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/window_session_controller.h" #include "mainwindow.h" #include "core/application.h" -#include "app.h" #include "styles/style_chat_helpers.h" namespace ChatHelpers { diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index 005b9260f..603f2fb34 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "core/application.h" +#include "data/data_abstract_structure.h" #include "data/data_photo.h" #include "data/data_document.h" #include "data/data_session.h" @@ -64,6 +65,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text/text_options.h" #include "ui/emoji_config.h" #include "ui/effects/animations.h" +#include "ui/cached_round_corners.h" #include "storage/serialize_common.h" #include "storage/storage_domain.h" #include "storage/storage_databases.h" @@ -172,7 +174,8 @@ Application::~Application() { Ui::Emoji::Clear(); Media::Clip::Finish(); - App::deinitMedia(); + Ui::FinishCachedCorners(); + Data::clearGlobalStructures(); Window::Theme::Uninitialize(); @@ -217,6 +220,7 @@ void Application::run() { style::startManager(cScale()); Ui::InitTextOptions(); + Ui::StartCachedCorners(); Ui::Emoji::Init(); startEmojiImageLoader(); startSystemDarkModeViewer(); @@ -262,7 +266,6 @@ void Application::run() { // Depend on activeWindow() for now :( startShortcuts(); - App::initMedia(); startDomain(); _window->widget()->show(); diff --git a/Telegram/SourceFiles/core/click_handler_types.cpp b/Telegram/SourceFiles/core/click_handler_types.cpp index e15f9b5a3..ab693cd66 100644 --- a/Telegram/SourceFiles/core/click_handler_types.cpp +++ b/Telegram/SourceFiles/core/click_handler_types.cpp @@ -23,7 +23,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "window/window_session_controller.h" #include "facades.h" -#include "app.h" #include diff --git a/Telegram/SourceFiles/core/local_url_handlers.cpp b/Telegram/SourceFiles/core/local_url_handlers.cpp index f8148f91a..7dd99957f 100644 --- a/Telegram/SourceFiles/core/local_url_handlers.cpp +++ b/Telegram/SourceFiles/core/local_url_handlers.cpp @@ -40,7 +40,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "main/main_session_settings.h" #include "apiwrap.h" -#include "app.h" #include diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index 75c8fb691..c3ab56529 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -45,7 +45,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwindow.h" #include "core/application.h" #include "lottie/lottie_animation.h" -#include "app.h" #include #include diff --git a/Telegram/SourceFiles/data/data_document_media.cpp b/Telegram/SourceFiles/data/data_document_media.cpp index e0d9acfe0..736fdb2c1 100644 --- a/Telegram/SourceFiles/data/data_document_media.cpp +++ b/Telegram/SourceFiles/data/data_document_media.cpp @@ -24,7 +24,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/application.h" #include "storage/file_download.h" #include "ui/image/image.h" -#include "app.h" #include #include @@ -464,11 +463,11 @@ void DocumentMedia::ReadOrGenerateThumbnail( }); } else if (active) { crl::async([=] { - const auto image = App::readImage(value, nullptr, false); - crl::on_main(guard, [=] { + auto image = Images::Read({ .content = value }).image; + crl::on_main(guard, [=, image = std::move(image)]() mutable { document->setGoodThumbnailChecked(true); if (const auto active = document->activeMediaView()) { - active->setGoodThumbnail(image); + active->setGoodThumbnail(std::move(image)); } }); }); diff --git a/Telegram/SourceFiles/data/data_document_resolver.cpp b/Telegram/SourceFiles/data/data_document_resolver.cpp index 8452af7fd..12aae4be3 100644 --- a/Telegram/SourceFiles/data/data_document_resolver.cpp +++ b/Telegram/SourceFiles/data/data_document_resolver.cpp @@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "data/data_document_resolver.h" -#include "app.h" #include "facades.h" #include "base/platform/base_platform_info.h" #include "boxes/confirm_box.h" @@ -186,22 +185,15 @@ base::binary_guard ReadImageAsync( guard = result.make_guard(), callback = std::move(done) ]() mutable { - auto format = QByteArray(); - if (bytes.isEmpty()) { - QFile f(path); - if (f.size() <= App::kImageSizeLimit - && f.open(QIODevice::ReadOnly)) { - bytes = f.readAll(); - } - } - auto image = bytes.isEmpty() - ? QImage() - : App::readImage(bytes, &format, false, nullptr); + auto read = Images::Read({ + .path = path, + .content = bytes, + }); if (postprocess) { - image = postprocess(std::move(image)); + read.image = postprocess(std::move(read.image)); } crl::on_main(std::move(guard), [ - image = std::move(image), + image = std::move(read.image), callback = std::move(callback) ]() mutable { callback(std::move(image)); @@ -231,7 +223,7 @@ void ResolveDocument( const auto media = document->createMediaView(); const auto openImageInApp = [&] { - if (document->size >= App::kImageSizeLimit) { + if (document->size >= Images::kReadBytesLimit) { return false; } const auto &location = document->location(true); diff --git a/Telegram/SourceFiles/data/data_media_types.cpp b/Telegram/SourceFiles/data/data_media_types.cpp index 8b8201879..1863fc288 100644 --- a/Telegram/SourceFiles/data/data_media_types.cpp +++ b/Telegram/SourceFiles/data/data_media_types.cpp @@ -1007,7 +1007,8 @@ WebPageData *MediaWebPage::webpage() const { bool MediaWebPage::hasReplyPreview() const { if (const auto document = MediaWebPage::document()) { - return document->hasThumbnail() && !document->isPatternWallPaper(); + return document->hasThumbnail() + && !document->isPatternWallPaper(); } else if (const auto photo = MediaWebPage::photo()) { return !photo->isNull(); } diff --git a/Telegram/SourceFiles/data/data_photo.cpp b/Telegram/SourceFiles/data/data_photo.cpp index f93d6fb67..045d0ec91 100644 --- a/Telegram/SourceFiles/data/data_photo.cpp +++ b/Telegram/SourceFiles/data/data_photo.cpp @@ -19,7 +19,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/file_download.h" #include "core/application.h" #include "facades.h" -#include "app.h" namespace { diff --git a/Telegram/SourceFiles/data/data_wall_paper.cpp b/Telegram/SourceFiles/data/data_wall_paper.cpp index f7e6d203d..e9724eabc 100644 --- a/Telegram/SourceFiles/data/data_wall_paper.cpp +++ b/Telegram/SourceFiles/data/data_wall_paper.cpp @@ -331,6 +331,15 @@ std::optional WallPaper::Create( if (!document->checkWallPaperProperties()) { return std::nullopt; } + const auto unsupported = data.vsettings() + && data.vsettings()->match([&](const MTPDwallPaperSettings &data) { + return data.vsecond_background_color() + || data.vthird_background_color() + || data.vfourth_background_color(); // #TODO themes gradients + }); + if (unsupported) { + return std::nullopt; + } auto result = WallPaper(data.vid().v); result._accessHash = data.vaccess_hash().v; result._ownerId = session->userId(); diff --git a/Telegram/SourceFiles/data/stickers/data_stickers_set.cpp b/Telegram/SourceFiles/data/stickers/data_stickers_set.cpp index 7198161f1..fbabbf524 100644 --- a/Telegram/SourceFiles/data/stickers/data_stickers_set.cpp +++ b/Telegram/SourceFiles/data/stickers/data_stickers_set.cpp @@ -12,7 +12,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_file_origin.h" #include "storage/file_download.h" #include "ui/image/image.h" -#include "app.h" namespace Data { @@ -28,7 +27,7 @@ not_null StickersSetThumbnailView::owner() const { void StickersSetThumbnailView::set( not_null session, QByteArray content) { - auto image = App::readImage(content, nullptr, false); + auto image = Images::Read({ .content = content }).image; if (image.isNull()) { _content = std::move(content); } else { diff --git a/Telegram/SourceFiles/dialogs/dialogs_entry.cpp b/Telegram/SourceFiles/dialogs/dialogs_entry.cpp index c34feb978..dff0aa1ac 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_entry.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_entry.cpp @@ -18,7 +18,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session_settings.h" #include "history/history_item.h" #include "history/history.h" -#include "app.h" #include "styles/style_dialogs.h" // st::dialogsTextWidthMin namespace Dialogs { diff --git a/Telegram/SourceFiles/editor/photo_editor_layer_widget.cpp b/Telegram/SourceFiles/editor/photo_editor_layer_widget.cpp index 8bb077673..9100631bf 100644 --- a/Telegram/SourceFiles/editor/photo_editor_layer_widget.cpp +++ b/Telegram/SourceFiles/editor/photo_editor_layer_widget.cpp @@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "editor/photo_editor_layer_widget.h" -#include "app.h" // readImage #include "boxes/confirm_box.h" // InformBox #include "editor/photo_editor.h" #include "storage/storage_media_prepare.h" @@ -80,9 +79,11 @@ void PrepareProfilePhoto( return; } - auto image = result.remoteContent.isEmpty() - ? App::readImage(result.paths.front()) - : App::readImage(result.remoteContent); + auto image = Images::Read({ + .path = result.paths.isEmpty() ? QString() : result.paths.front(), + .content = result.remoteContent, + .forceOpaque = true, + }).image; if (image.isNull() || (image.width() > (10 * image.height())) || (image.height() > (10 * image.width()))) { diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 8e78290b1..082705d50 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -45,7 +45,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_channel.h" #include "data/data_user.h" #include "data/data_histories.h" -#include "app.h" #include "styles/style_dialogs.h" #include "styles/style_widgets.h" #include "styles/style_chat.h" diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index a82ee13ee..d32f05f8a 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -3541,15 +3541,12 @@ void HistoryWidget::chooseAttach() { } if (!result.remoteContent.isEmpty()) { - auto animated = false; - auto image = App::readImage( - result.remoteContent, - nullptr, - false, - &animated); - if (!image.isNull() && !animated) { + auto read = Images::Read({ + .content = result.remoteContent, + }); + if (!read.image.isNull() && !read.animated) { confirmSendingFiles( - std::move(image), + std::move(read.image), std::move(result.remoteContent)); } else { uploadFile(result.remoteContent, SendMediaType::File); diff --git a/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp b/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp index d2d70c890..32548d4c4 100644 --- a/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp @@ -44,7 +44,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/platform_specific.h" #include "lang/lang_keys.h" #include "facades.h" -#include "app.h" #include "styles/style_chat.h" #include "styles/style_window.h" #include "styles/style_info.h" diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index e40e1629c..a0cff1001 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -58,7 +58,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/platform_specific.h" #include "lang/lang_keys.h" #include "facades.h" -#include "app.h" #include "styles/style_chat.h" #include "styles/style_window.h" #include "styles/style_info.h" @@ -559,14 +558,12 @@ void RepliesWidget::chooseAttach() { if (!result.remoteContent.isEmpty()) { auto animated = false; - auto image = App::readImage( - result.remoteContent, - nullptr, - false, - &animated); - if (!image.isNull() && !animated) { + auto read = Images::Read({ + .content = result.remoteContent, + }); + if (!read.image.isNull() && !read.animated) { confirmSendingFiles( - std::move(image), + std::move(read.image), std::move(result.remoteContent)); } else { uploadFile(result.remoteContent, SendMediaType::File); diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index d7ffa049e..a15735f77 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -51,7 +51,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/platform_specific.h" #include "lang/lang_keys.h" #include "facades.h" -#include "app.h" #include "styles/style_chat.h" #include "styles/style_window.h" #include "styles/style_info.h" @@ -298,15 +297,12 @@ void ScheduledWidget::chooseAttach() { } if (!result.remoteContent.isEmpty()) { - auto animated = false; - auto image = App::readImage( - result.remoteContent, - nullptr, - false, - &animated); - if (!image.isNull() && !animated) { + auto read = Images::Read({ + .content = result.remoteContent, + }); + if (!read.image.isNull() && !read.animated) { confirmSendingFiles( - std::move(image), + std::move(read.image), std::move(result.remoteContent)); } else { uploadFile(result.remoteContent, SendMediaType::File); diff --git a/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp b/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp index f670d25ac..a46cf9871 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp @@ -197,23 +197,32 @@ void ThemeDocument::ensureDataMediaCreated() const { return; } _dataMedia = _data->createMediaView(); - _dataMedia->goodThumbnailWanted(); + if (checkGoodThumbnail()) { + _dataMedia->goodThumbnailWanted(); + } _dataMedia->thumbnailWanted(_realParent->fullId()); _parent->history()->owner().registerHeavyViewPart(_parent); } +bool ThemeDocument::checkGoodThumbnail() const { + return !_data->hasThumbnail() || !_data->isPatternWallPaper(); +} + void ThemeDocument::validateThumbnail() const { - if (_thumbnailGood > 0) { - return; - } - ensureDataMediaCreated(); - if (const auto good = _dataMedia->goodThumbnail()) { - prepareThumbnailFrom(good, 1); - return; + if (checkGoodThumbnail()) { + if (_thumbnailGood > 0) { + return; + } + ensureDataMediaCreated(); + if (const auto good = _dataMedia->goodThumbnail()) { + prepareThumbnailFrom(good, 1); + return; + } } if (_thumbnailGood >= 0) { return; } + ensureDataMediaCreated(); if (const auto normal = _dataMedia->thumbnail()) { prepareThumbnailFrom(normal, 0); } else if (_thumbnail.isNull()) { diff --git a/Telegram/SourceFiles/history/view/media/history_view_theme_document.h b/Telegram/SourceFiles/history/view/media/history_view_theme_document.h index e0c9427ee..66d36e161 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_theme_document.h +++ b/Telegram/SourceFiles/history/view/media/history_view_theme_document.h @@ -61,6 +61,7 @@ private: QSize countCurrentSize(int newWidth) override; void fillPatternFieldsFrom(const QString &url); + [[nodiscard]] bool checkGoodThumbnail() const; void validateThumbnail() const; void prepareThumbnailFrom(not_null image, int good) const; void ensureDataMediaCreated() const; diff --git a/Telegram/SourceFiles/media/audio/media_audio.cpp b/Telegram/SourceFiles/media/audio/media_audio.cpp index f4d31f590..ef34eb3c0 100644 --- a/Telegram/SourceFiles/media/audio/media_audio.cpp +++ b/Telegram/SourceFiles/media/audio/media_audio.cpp @@ -1614,16 +1614,14 @@ public: const auto coverBytes = QByteArray( (const char*)packet.data, packet.size); - auto format = QByteArray(); - auto animated = false; - _cover = App::readImage( - coverBytes, - &format, - true, - &animated); - if (!_cover.isNull()) { + auto read = Images::Read({ + .content = coverBytes, + .forceOpaque = true, + }); + if (!read.image.isNull()) { + _cover = std::move(read.image); _coverBytes = coverBytes; - _coverFormat = format; + _coverFormat = read.format; } } } else if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index ecca71f79..b81ca7d49 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -70,7 +70,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/storage_account.h" #include "calls/calls_instance.h" #include "facades.h" -#include "app.h" #include "styles/style_media_view.h" #include "styles/style_chat.h" @@ -149,24 +148,16 @@ QWidget *PipDelegate::pipParentWidget() { : result; } -[[nodiscard]] QImage PrepareStaticImage(QImage image) { - if (image.width() > kMaxDisplayImageSize - || image.height() > kMaxDisplayImageSize) { - image = image.scaled( +[[nodiscard]] QImage PrepareStaticImage(Images::ReadArgs &&args) { + auto read = Images::Read(std::move(args)); + return (read.image.width() > kMaxDisplayImageSize + || read.image.height() > kMaxDisplayImageSize) + ? read.image.scaled( kMaxDisplayImageSize, kMaxDisplayImageSize, Qt::KeepAspectRatio, - Qt::SmoothTransformation); - } - return image; -} - -[[nodiscard]] QImage PrepareStaticImage(const QString &path) { - return PrepareStaticImage(App::readImage(path, nullptr, false)); -} - -[[nodiscard]] QImage PrepareStaticImage(const QByteArray &bytes) { - return PrepareStaticImage(App::readImage(bytes, nullptr, false)); + Qt::SmoothTransformation) + : read.image; } [[nodiscard]] bool IsSemitransparent(const QImage &image) { @@ -1181,7 +1172,8 @@ bool OverlayWidget::radialAnimationCallback(crl::time now) { } const auto ready = _document && _documentMedia->loaded(); const auto streamVideo = ready && _documentMedia->canBePlayed(); - const auto tryOpenImage = ready && (_document->size < App::kImageSizeLimit); + const auto tryOpenImage = ready + && (_document->size < Images::kReadBytesLimit); if (ready && ((tryOpenImage && !_radial.animating()) || streamVideo)) { _streamingStartPaused = false; if (streamVideo) { @@ -2415,14 +2407,16 @@ void OverlayWidget::displayDocument( _document->saveFromDataSilent(); auto &location = _document->location(true); if (location.accessEnable()) { - const auto &path = location.name(); - if (QImageReader(path).canRead()) { - setStaticContent(PrepareStaticImage(path)); + setStaticContent(PrepareStaticImage({ + .path = location.name(), + })); + if (!_staticContent.isNull()) { _touchbarDisplay.fire(TouchBarItemType::Photo); } - } else if (!_documentMedia->bytes().isEmpty()) { - setStaticContent( - PrepareStaticImage(_documentMedia->bytes())); + } else { + setStaticContent(PrepareStaticImage({ + .content = _documentMedia->bytes(), + })); if (!_staticContent.isNull()) { _touchbarDisplay.fire(TouchBarItemType::Photo); } diff --git a/Telegram/SourceFiles/passport/passport_form_controller.cpp b/Telegram/SourceFiles/passport/passport_form_controller.cpp index 336ef62fe..b48942325 100644 --- a/Telegram/SourceFiles/passport/passport_form_controller.cpp +++ b/Telegram/SourceFiles/passport/passport_form_controller.cpp @@ -29,7 +29,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/localstorage.h" #include "storage/file_upload.h" #include "storage/file_download_mtproto.h" -#include "app.h" #include #include @@ -75,9 +74,12 @@ std::map GetTexts(const ValueMap &map) { } QImage ReadImage(bytes::const_span buffer) { - return App::readImage(QByteArray::fromRawData( - reinterpret_cast(buffer.data()), - buffer.size())); + return Images::Read({ + .content = QByteArray::fromRawData( + reinterpret_cast(buffer.data()), + buffer.size()), + .forceOpaque = true, + }).image; } Value::Type ConvertType(const MTPSecureValueType &type) { @@ -1777,9 +1779,7 @@ void FormController::fileLoadDone(FileKey key, const QByteArray &bytes) { return; } file->downloadOffset = file->size; - file->image = App::readImage(QByteArray::fromRawData( - reinterpret_cast(decrypted.data()), - decrypted.size())); + file->image = ReadImage(gsl::make_span(decrypted)); if (const auto fileInEdit = findEditFile(key)) { fileInEdit->fields.image = file->image; fileInEdit->fields.downloadOffset = file->downloadOffset; diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_scans.cpp b/Telegram/SourceFiles/passport/passport_panel_edit_scans.cpp index 783677957..ed291b552 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_scans.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_edit_scans.cpp @@ -18,12 +18,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/chat/attach/attach_prepare.h" #include "ui/text/text_utilities.h" // Ui::Text::ToUpper #include "ui/text/text_options.h" +#include "ui/image/image_prepare.h" #include "core/file_utilities.h" #include "lang/lang_keys.h" #include "boxes/abstract_box.h" #include "storage/storage_media_prepare.h" #include "storage/file_upload.h" // For Storage::kUseBigFilesFrom. -#include "app.h" #include "styles/style_layers.h" #include "styles/style_passport.h" @@ -39,7 +39,12 @@ constexpr auto kJpegQuality = 89; static_assert(kMaxSize <= Storage::kUseBigFilesFrom); std::variant ProcessImage(QByteArray &&bytes) { - auto image = App::readImage(base::take(bytes)); + auto read = Images::Read({ + .content = base::take(bytes), + .forceOpaque = true, + }); + + auto &image = read.image; if (image.isNull()) { return ReadScanError::CantReadImage; } else if (!Ui::ValidateThumbDimensions(image.width(), image.height())) { @@ -858,7 +863,7 @@ void EditScans::ChooseScan( auto content = [&] { QFile f(file); - if (f.size() > App::kImageSizeLimit) { + if (f.size() > Images::kReadBytesLimit) { guardedError(ReadScanError::FileTooLarge); return QByteArray(); } else if (!f.open(QIODevice::ReadOnly)) { diff --git a/Telegram/SourceFiles/settings/settings_chat.cpp b/Telegram/SourceFiles/settings/settings_chat.cpp index f2428b818..29690be5f 100644 --- a/Telegram/SourceFiles/settings/settings_chat.cpp +++ b/Telegram/SourceFiles/settings/settings_chat.cpp @@ -55,7 +55,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwidget.h" #include "mainwindow.h" #include "facades.h" -#include "app.h" #include "styles/style_settings.h" #include "styles/style_layers.h" @@ -626,9 +625,11 @@ void ChooseFromFile( } } - auto image = result.remoteContent.isEmpty() - ? App::readImage(result.paths.front()) - : App::readImage(result.remoteContent); + auto image = Images::Read({ + .path = result.paths.isEmpty() ? QString() : result.paths.front(), + .content = result.remoteContent, + .forceOpaque = true, + }).image; if (image.isNull() || image.width() <= 0 || image.height() <= 0) { return; } diff --git a/Telegram/SourceFiles/settings/settings_information.cpp b/Telegram/SourceFiles/settings/settings_information.cpp index d672ef56e..394420934 100644 --- a/Telegram/SourceFiles/settings/settings_information.cpp +++ b/Telegram/SourceFiles/settings/settings_information.cpp @@ -32,7 +32,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "apiwrap.h" #include "core/file_utilities.h" #include "base/call_delayed.h" -#include "app.h" #include "styles/style_layers.h" #include "styles/style_settings.h" diff --git a/Telegram/SourceFiles/storage/file_download.cpp b/Telegram/SourceFiles/storage/file_download.cpp index 2a2e9cb59..65e685f62 100644 --- a/Telegram/SourceFiles/storage/file_download.cpp +++ b/Telegram/SourceFiles/storage/file_download.cpp @@ -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), {}, {}); } diff --git a/Telegram/SourceFiles/storage/localimageloader.cpp b/Telegram/SourceFiles/storage/localimageloader.cpp index bec5601e5..c20ecfacd 100644 --- a/Telegram/SourceFiles/storage/localimageloader.cpp +++ b/Telegram/SourceFiles/storage/localimageloader.cpp @@ -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 #include @@ -642,25 +641,25 @@ bool FileLoadTask::CheckForImage( const QString &filepath, const QByteArray &content, std::unique_ptr &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( diff --git a/Telegram/SourceFiles/storage/storage_media_prepare.cpp b/Telegram/SourceFiles/storage/storage_media_prepare.cpp index e33e84fc7..859885272 100644 --- a/Telegram/SourceFiles/storage/storage_media_prepare.cpp +++ b/Telegram/SourceFiles/storage/storage_media_prepare.cpp @@ -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 #include @@ -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; diff --git a/Telegram/SourceFiles/ui/image/image.cpp b/Telegram/SourceFiles/ui/image/image.cpp index 342a12f88..ab1c6664b 100644 --- a/Telegram/SourceFiles/ui/image/image.cpp +++ b/Telegram/SourceFiles/ui/image/image.cpp @@ -11,7 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "main/main_session.h" #include "ui/ui_utility.h" -#include "app.h" using namespace Images; @@ -28,17 +27,6 @@ namespace { return PixKey(0, 0, options); } -[[nodiscard]] QByteArray ReadContent(const QString &path) { - auto file = QFile(path); - const auto good = (file.size() <= App::kImageSizeLimit) - && file.open(QIODevice::ReadOnly); - return good ? file.readAll() : QByteArray(); -} - -[[nodiscard]] QImage ReadImage(const QByteArray &content) { - return App::readImage(content, nullptr, false, nullptr); -} - } // namespace QByteArray ExpandInlineBytes(const QByteArray &bytes) { @@ -91,7 +79,7 @@ QByteArray ExpandInlineBytes(const QByteArray &bytes) { } QImage FromInlineBytes(const QByteArray &bytes) { - return App::readImage(ExpandInlineBytes(bytes)); + return Read({ .content = ExpandInlineBytes(bytes) }).image; } // Thanks TDLib for code. @@ -297,10 +285,12 @@ QPainterPath PathFromInlineBytes(const QByteArray &bytes) { } // namespace Images -Image::Image(const QString &path) : Image(ReadContent(path)) { +Image::Image(const QString &path) +: Image(Read({ .path = path }).image) { } -Image::Image(const QByteArray &content) : Image(ReadImage(content)) { +Image::Image(const QByteArray &content) +: Image(Read({ .content = content }).image) { } Image::Image(QImage &&data) diff --git a/Telegram/SourceFiles/window/themes/window_theme.cpp b/Telegram/SourceFiles/window/themes/window_theme.cpp index 4f5af4269..2413f8c8d 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme.cpp @@ -31,7 +31,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/confirm_box.h" #include "boxes/background_box.h" #include "core/application.h" -#include "app.h" #include "styles/style_widgets.h" #include "styles/style_chat.h" @@ -323,7 +322,10 @@ bool LoadTheme( LOG(("Theme Error: bad background image size in the theme file.")); return false; } - auto background = App::readImage(backgroundContent); + auto background = Images::Read({ + .content = backgroundContent, + .forceOpaque = true, + }).image; if (background.isNull()) { LOG(("Theme Error: could not read background image in the theme file.")); return false; diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor.cpp b/Telegram/SourceFiles/window/themes/window_theme_editor.cpp index b556b2a03..e2cf864ca 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_editor.cpp @@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/multi_select.h" #include "ui/widgets/dropdown_menu.h" #include "ui/toast/toast.h" +#include "ui/image/image_prepare.h" #include "ui/ui_utility.h" #include "base/parse_helper.h" #include "base/zlib_help.h" @@ -31,7 +32,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/edit_color_box.h" #include "lang/lang_keys.h" #include "facades.h" -#include "app.h" #include "styles/style_window.h" #include "styles/style_dialogs.h" #include "styles/style_layers.h" @@ -789,7 +789,10 @@ void Editor::importTheme() { _inner->applyNewPalette(parsed.palette); _inner->recreateRows(); updateControlsGeometry(); - auto image = App::readImage(parsed.background); + auto image = Images::Read({ + .content = parsed.background, + .forceOpaque = true, + }).image; if (!image.isNull() && !image.size().isEmpty()) { Background()->set(Data::CustomWallPaper(), std::move(image)); Background()->setTile(parsed.tiled); diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp b/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp index 7d42c0e6d..7e901b1aa 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp @@ -40,7 +40,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/file_upload.h" #include "mainwindow.h" #include "apiwrap.h" -#include "app.h" #include "styles/style_widgets.h" #include "styles/style_window.h" #include "styles/style_settings.h" @@ -186,15 +185,14 @@ void BackgroundSelector::chooseBackgroundFromFile() { } } if (!content.isEmpty()) { - auto format = QByteArray(); - auto image = App::readImage(content, &format); - if (!image.isNull() - && (format == "jpeg" - || format == "jpg" - || format == "png")) { - _background = image; + auto read = Images::Read({ .content = content }); + if (!read.image.isNull() + && (read.format == "jpeg" + || read.format == "jpg" + || read.format == "png")) { + _background = std::move(read.image); _parsed.background = content; - _parsed.isPng = (format == "png"); + _parsed.isPng = (read.format == "png"); const auto phrase = _parsed.isPng ? tr::lng_theme_editor_read_from_png : tr::lng_theme_editor_read_from_jpg; diff --git a/Telegram/SourceFiles/window/window_controller.cpp b/Telegram/SourceFiles/window/window_controller.cpp index 2bd1e7849..bde206d3e 100644 --- a/Telegram/SourceFiles/window/window_controller.cpp +++ b/Telegram/SourceFiles/window/window_controller.cpp @@ -33,7 +33,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwindow.h" #include "apiwrap.h" // ApiWrap::acceptTerms. #include "facades.h" -#include "app.h" #include "styles/style_layers.h" #include diff --git a/Telegram/lib_lottie b/Telegram/lib_lottie index 0770df009..2f9bda2cc 160000 --- a/Telegram/lib_lottie +++ b/Telegram/lib_lottie @@ -1 +1 @@ -Subproject commit 0770df009db7928df1d0cad0900dc5110106d229 +Subproject commit 2f9bda2cc7b8c94abe34f501b270df8533a7b141 diff --git a/Telegram/lib_ui b/Telegram/lib_ui index a2d1114a9..2bd63281b 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit a2d1114a93c094f9b4919ddba06d42eca40a8655 +Subproject commit 2bd63281b58d54aa129da78f05f0e6e73e5d63c9