Filter out patterns without background colors.

This commit is contained in:
John Preston 2021-08-16 17:14:34 +03:00
parent 7a06eccaec
commit 2abcb51dda
4 changed files with 15 additions and 27 deletions

View file

@ -379,15 +379,16 @@ QImage ColorizePattern(QImage image, QColor color) {
QImage PrepareScaledFromFull(
const QImage &image,
const std::vector<QColor> &patternBackground,
bool isPattern,
const std::vector<QColor> &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<QColor> &bg) {
QColor(red / count, green / count, blue / count));
}
std::vector<QColor> BackgroundPreviewBox::patternBackgroundColors() const {
return _paper.isPattern()
? _paper.backgroundColors()
: std::vector<QColor>();
}
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))

View file

@ -61,7 +61,6 @@ private:
void setScaledFromThumb();
void setScaledFromImage(QImage &&image, QImage &&blurred);
void updateServiceBg(const std::vector<QColor> &bg);
std::vector<QColor> patternBackgroundColors() const;
void paintImage(Painter &p);
void paintRadial(Painter &p);
void paintTexts(Painter &p, crl::time ms);

View file

@ -466,9 +466,6 @@ std::optional<WallPaper> WallPaper::Create(
}
});
}
if (result.isPattern() && result.backgroundColors().empty()) {
result._backgroundColors.push_back(DefaultBackgroundColor());
}
return result;
}
@ -487,9 +484,6 @@ std::optional<WallPaper> WallPaper::Create(const MTPDwallPaperNoFile &data) {
}
});
}
if (result.backgroundColors().empty()) {
result._backgroundColors.push_back(DefaultBackgroundColor());
}
return result;
}
@ -622,9 +616,6 @@ std::optional<WallPaper> 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> 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());

View file

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