diff --git a/Telegram/SourceFiles/boxes/background_preview_box.cpp b/Telegram/SourceFiles/boxes/background_preview_box.cpp index a6136f4fc..d253e9397 100644 --- a/Telegram/SourceFiles/boxes/background_preview_box.cpp +++ b/Telegram/SourceFiles/boxes/background_preview_box.cpp @@ -379,15 +379,16 @@ QImage ColorizePattern(QImage image, QColor color) { QImage PrepareScaledFromFull( const QImage &image, - const std::vector &patternBackground, + bool isPattern, + const std::vector &background, int gradientRotation, float64 patternOpacity, Images::Option blur = Images::Option(0)) { auto result = PrepareScaledNonPattern(image, blur); - if (!patternBackground.empty()) { + if (isPattern) { result = Data::PreparePatternImage( std::move(result), - patternBackground, + background, gradientRotation, patternOpacity); } @@ -686,7 +687,8 @@ void BackgroundPreviewBox::setScaledFromThumb() { } auto scaled = PrepareScaledFromFull( thumbnail->original(), - patternBackgroundColors(), + _paper.isPattern(), + _paper.backgroundColors(), _paper.gradientRotation(), _paper.patternOpacity(), _paper.document() ? Images::Option::Blurred : Images::Option(0)); @@ -744,12 +746,6 @@ void BackgroundPreviewBox::updateServiceBg(const std::vector &bg) { QColor(red / count, green / count, blue / count)); } -std::vector BackgroundPreviewBox::patternBackgroundColors() const { - return _paper.isPattern() - ? _paper.backgroundColors() - : std::vector(); -} - void BackgroundPreviewBox::checkLoadedDocument() { const auto document = _paper.document(); if (!_full.isNull() @@ -765,17 +761,19 @@ void BackgroundPreviewBox::checkLoadedDocument() { crl::async([ this, image = std::move(image), - patternBackground = patternBackgroundColors(), + isPattern = _paper.isPattern(), + background = _paper.backgroundColors(), gradientRotation = _paper.gradientRotation(), patternOpacity = _paper.patternOpacity(), guard = _generating.make_guard() ]() mutable { auto scaled = PrepareScaledFromFull( image, - patternBackground, + isPattern, + background, gradientRotation, patternOpacity); - auto blurred = patternBackground.empty() + auto blurred = !isPattern ? PrepareScaledNonPattern( Data::PrepareBlurredBackground(image), Images::Option(0)) diff --git a/Telegram/SourceFiles/boxes/background_preview_box.h b/Telegram/SourceFiles/boxes/background_preview_box.h index 59d00a306..0a89934df 100644 --- a/Telegram/SourceFiles/boxes/background_preview_box.h +++ b/Telegram/SourceFiles/boxes/background_preview_box.h @@ -61,7 +61,6 @@ private: void setScaledFromThumb(); void setScaledFromImage(QImage &&image, QImage &&blurred); void updateServiceBg(const std::vector &bg); - std::vector patternBackgroundColors() const; void paintImage(Painter &p); void paintRadial(Painter &p); void paintTexts(Painter &p, crl::time ms); diff --git a/Telegram/SourceFiles/data/data_wall_paper.cpp b/Telegram/SourceFiles/data/data_wall_paper.cpp index d224f8529..02b1defab 100644 --- a/Telegram/SourceFiles/data/data_wall_paper.cpp +++ b/Telegram/SourceFiles/data/data_wall_paper.cpp @@ -466,9 +466,6 @@ std::optional WallPaper::Create( } }); } - if (result.isPattern() && result.backgroundColors().empty()) { - result._backgroundColors.push_back(DefaultBackgroundColor()); - } return result; } @@ -487,9 +484,6 @@ std::optional WallPaper::Create(const MTPDwallPaperNoFile &data) { } }); } - if (result.backgroundColors().empty()) { - result._backgroundColors.push_back(DefaultBackgroundColor()); - } return result; } @@ -622,9 +616,6 @@ std::optional WallPaper::FromSerialized( result._backgroundColors = std::move(backgroundColors); result._intensity = intensity; result._rotation = rotation; - if (result.isPattern() && result.backgroundColors().empty()) { - result._backgroundColors.push_back(DefaultBackgroundColor()); - } return result; } @@ -640,9 +631,6 @@ std::optional WallPaper::FromLegacySerialized( if (const auto color = ColorFromString(slug)) { result._backgroundColors.push_back(*color); } - if (result.isPattern() && result.backgroundColors().empty()) { - result._backgroundColors.push_back(DefaultBackgroundColor()); - } return result; } @@ -783,6 +771,9 @@ QImage GenerateDitheredGradient( } QImage GenerateDitheredGradient(const Data::WallPaper &paper) { + if (paper.backgroundColors().empty()) { + return GenerateDitheredGradient({ DefaultBackgroundColor() }, 0); + } return GenerateDitheredGradient( paper.backgroundColors(), paper.gradientRotation()); diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index f077cb1fe..ff663ba04 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -994,7 +994,7 @@ void MainMenu::refreshBackground() { fill, prepared.size()); - auto backgroundImage = !paper.backgroundColors().empty() + auto backgroundImage = paper.isPattern() ? Data::GenerateWallPaper( fill * cIntRetinaFactor(), paper.backgroundColors(),