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

@ -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 {

View file

@ -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 {

View file

@ -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 <QtCore/QBuffer>
#include <QtGui/QFontDatabase>
@ -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;
}
}

View file

@ -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);
};

View file

@ -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 {

View file

@ -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"

View file

@ -14,7 +14,6 @@ Copyright (C) 2017, Nicholas Guriev <guriev-ns@ya.ru>
#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"

View file

@ -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 {

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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 <tgcalls/VideoCaptureInterface.h>
#include <tgcalls/StaticThreads.h>

View file

@ -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"

View file

@ -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"

View file

@ -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.

View file

@ -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"

View file

@ -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 <QtCore/QTimer>

View file

@ -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 <QtCore/QBuffer>

View file

@ -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 {

View file

@ -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();

View file

@ -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 <QtGui/QGuiApplication>

View file

@ -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 <QtGui/QGuiApplication>

View file

@ -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 <QtCore/QBuffer>
#include <QtCore/QMimeType>

View file

@ -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 <QtCore/QBuffer>
#include <QtGui/QImageReader>
@ -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));
}
});
});

View file

@ -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);

View file

@ -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();
}

View file

@ -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 {

View file

@ -331,6 +331,15 @@ std::optional<WallPaper> 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();

View file

@ -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<StickersSet*> StickersSetThumbnailView::owner() const {
void StickersSetThumbnailView::set(
not_null<Main::Session*> 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 {

View file

@ -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 {

View file

@ -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()))) {

View file

@ -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"

View file

@ -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);

View file

@ -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"

View file

@ -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);

View file

@ -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);

View file

@ -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()) {

View file

@ -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*> image, int good) const;
void ensureDataMediaCreated() const;

View file

@ -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) {

View file

@ -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);
}

View file

@ -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 <QtCore/QJsonDocument>
#include <QtCore/QJsonArray>
@ -75,9 +74,12 @@ std::map<QString, QString> GetTexts(const ValueMap &map) {
}
QImage ReadImage(bytes::const_span buffer) {
return App::readImage(QByteArray::fromRawData(
reinterpret_cast<const char*>(buffer.data()),
buffer.size()));
return Images::Read({
.content = QByteArray::fromRawData(
reinterpret_cast<const char*>(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<const char*>(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;

View file

@ -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<ReadScanError, QByteArray> 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)) {

View file

@ -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;
}

View file

@ -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"

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;

View file

@ -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)

View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -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 <QtGui/QWindow>

@ -1 +1 @@
Subproject commit 0770df009db7928df1d0cad0900dc5110106d229
Subproject commit 2f9bda2cc7b8c94abe34f501b270df8533a7b141

@ -1 +1 @@
Subproject commit a2d1114a93c094f9b4919ddba06d42eca40a8655
Subproject commit 2bd63281b58d54aa129da78f05f0e6e73e5d63c9