mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Filter out patterns without background colors.
This commit is contained in:
parent
7a06eccaec
commit
2abcb51dda
4 changed files with 15 additions and 27 deletions
|
@ -379,15 +379,16 @@ QImage ColorizePattern(QImage image, QColor color) {
|
||||||
|
|
||||||
QImage PrepareScaledFromFull(
|
QImage PrepareScaledFromFull(
|
||||||
const QImage &image,
|
const QImage &image,
|
||||||
const std::vector<QColor> &patternBackground,
|
bool isPattern,
|
||||||
|
const std::vector<QColor> &background,
|
||||||
int gradientRotation,
|
int gradientRotation,
|
||||||
float64 patternOpacity,
|
float64 patternOpacity,
|
||||||
Images::Option blur = Images::Option(0)) {
|
Images::Option blur = Images::Option(0)) {
|
||||||
auto result = PrepareScaledNonPattern(image, blur);
|
auto result = PrepareScaledNonPattern(image, blur);
|
||||||
if (!patternBackground.empty()) {
|
if (isPattern) {
|
||||||
result = Data::PreparePatternImage(
|
result = Data::PreparePatternImage(
|
||||||
std::move(result),
|
std::move(result),
|
||||||
patternBackground,
|
background,
|
||||||
gradientRotation,
|
gradientRotation,
|
||||||
patternOpacity);
|
patternOpacity);
|
||||||
}
|
}
|
||||||
|
@ -686,7 +687,8 @@ void BackgroundPreviewBox::setScaledFromThumb() {
|
||||||
}
|
}
|
||||||
auto scaled = PrepareScaledFromFull(
|
auto scaled = PrepareScaledFromFull(
|
||||||
thumbnail->original(),
|
thumbnail->original(),
|
||||||
patternBackgroundColors(),
|
_paper.isPattern(),
|
||||||
|
_paper.backgroundColors(),
|
||||||
_paper.gradientRotation(),
|
_paper.gradientRotation(),
|
||||||
_paper.patternOpacity(),
|
_paper.patternOpacity(),
|
||||||
_paper.document() ? Images::Option::Blurred : Images::Option(0));
|
_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));
|
QColor(red / count, green / count, blue / count));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<QColor> BackgroundPreviewBox::patternBackgroundColors() const {
|
|
||||||
return _paper.isPattern()
|
|
||||||
? _paper.backgroundColors()
|
|
||||||
: std::vector<QColor>();
|
|
||||||
}
|
|
||||||
|
|
||||||
void BackgroundPreviewBox::checkLoadedDocument() {
|
void BackgroundPreviewBox::checkLoadedDocument() {
|
||||||
const auto document = _paper.document();
|
const auto document = _paper.document();
|
||||||
if (!_full.isNull()
|
if (!_full.isNull()
|
||||||
|
@ -765,17 +761,19 @@ void BackgroundPreviewBox::checkLoadedDocument() {
|
||||||
crl::async([
|
crl::async([
|
||||||
this,
|
this,
|
||||||
image = std::move(image),
|
image = std::move(image),
|
||||||
patternBackground = patternBackgroundColors(),
|
isPattern = _paper.isPattern(),
|
||||||
|
background = _paper.backgroundColors(),
|
||||||
gradientRotation = _paper.gradientRotation(),
|
gradientRotation = _paper.gradientRotation(),
|
||||||
patternOpacity = _paper.patternOpacity(),
|
patternOpacity = _paper.patternOpacity(),
|
||||||
guard = _generating.make_guard()
|
guard = _generating.make_guard()
|
||||||
]() mutable {
|
]() mutable {
|
||||||
auto scaled = PrepareScaledFromFull(
|
auto scaled = PrepareScaledFromFull(
|
||||||
image,
|
image,
|
||||||
patternBackground,
|
isPattern,
|
||||||
|
background,
|
||||||
gradientRotation,
|
gradientRotation,
|
||||||
patternOpacity);
|
patternOpacity);
|
||||||
auto blurred = patternBackground.empty()
|
auto blurred = !isPattern
|
||||||
? PrepareScaledNonPattern(
|
? PrepareScaledNonPattern(
|
||||||
Data::PrepareBlurredBackground(image),
|
Data::PrepareBlurredBackground(image),
|
||||||
Images::Option(0))
|
Images::Option(0))
|
||||||
|
|
|
@ -61,7 +61,6 @@ private:
|
||||||
void setScaledFromThumb();
|
void setScaledFromThumb();
|
||||||
void setScaledFromImage(QImage &&image, QImage &&blurred);
|
void setScaledFromImage(QImage &&image, QImage &&blurred);
|
||||||
void updateServiceBg(const std::vector<QColor> &bg);
|
void updateServiceBg(const std::vector<QColor> &bg);
|
||||||
std::vector<QColor> patternBackgroundColors() const;
|
|
||||||
void paintImage(Painter &p);
|
void paintImage(Painter &p);
|
||||||
void paintRadial(Painter &p);
|
void paintRadial(Painter &p);
|
||||||
void paintTexts(Painter &p, crl::time ms);
|
void paintTexts(Painter &p, crl::time ms);
|
||||||
|
|
|
@ -466,9 +466,6 @@ std::optional<WallPaper> WallPaper::Create(
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (result.isPattern() && result.backgroundColors().empty()) {
|
|
||||||
result._backgroundColors.push_back(DefaultBackgroundColor());
|
|
||||||
}
|
|
||||||
return result;
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -622,9 +616,6 @@ std::optional<WallPaper> WallPaper::FromSerialized(
|
||||||
result._backgroundColors = std::move(backgroundColors);
|
result._backgroundColors = std::move(backgroundColors);
|
||||||
result._intensity = intensity;
|
result._intensity = intensity;
|
||||||
result._rotation = rotation;
|
result._rotation = rotation;
|
||||||
if (result.isPattern() && result.backgroundColors().empty()) {
|
|
||||||
result._backgroundColors.push_back(DefaultBackgroundColor());
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -640,9 +631,6 @@ std::optional<WallPaper> WallPaper::FromLegacySerialized(
|
||||||
if (const auto color = ColorFromString(slug)) {
|
if (const auto color = ColorFromString(slug)) {
|
||||||
result._backgroundColors.push_back(*color);
|
result._backgroundColors.push_back(*color);
|
||||||
}
|
}
|
||||||
if (result.isPattern() && result.backgroundColors().empty()) {
|
|
||||||
result._backgroundColors.push_back(DefaultBackgroundColor());
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -783,6 +771,9 @@ QImage GenerateDitheredGradient(
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage GenerateDitheredGradient(const Data::WallPaper &paper) {
|
QImage GenerateDitheredGradient(const Data::WallPaper &paper) {
|
||||||
|
if (paper.backgroundColors().empty()) {
|
||||||
|
return GenerateDitheredGradient({ DefaultBackgroundColor() }, 0);
|
||||||
|
}
|
||||||
return GenerateDitheredGradient(
|
return GenerateDitheredGradient(
|
||||||
paper.backgroundColors(),
|
paper.backgroundColors(),
|
||||||
paper.gradientRotation());
|
paper.gradientRotation());
|
||||||
|
|
|
@ -994,7 +994,7 @@ void MainMenu::refreshBackground() {
|
||||||
fill,
|
fill,
|
||||||
prepared.size());
|
prepared.size());
|
||||||
|
|
||||||
auto backgroundImage = !paper.backgroundColors().empty()
|
auto backgroundImage = paper.isPattern()
|
||||||
? Data::GenerateWallPaper(
|
? Data::GenerateWallPaper(
|
||||||
fill * cIntRetinaFactor(),
|
fill * cIntRetinaFactor(),
|
||||||
paper.backgroundColors(),
|
paper.backgroundColors(),
|
||||||
|
|
Loading…
Add table
Reference in a new issue