Provide GenerateLinearGradient with several colors.
This commit is contained in:
parent
af1429cb87
commit
db1b4b65c7
4 changed files with 40 additions and 4 deletions
|
|
@ -821,7 +821,17 @@ QImage BlurLargeImage(QImage image, int radius) {
|
||||||
return QImage();
|
return QImage();
|
||||||
} else if (colors.size() > 2) {
|
} else if (colors.size() > 2) {
|
||||||
return GenerateComplexGradient(size, colors, rotation, progress);
|
return GenerateComplexGradient(size, colors, rotation, progress);
|
||||||
|
} else {
|
||||||
|
return GenerateLinearGradient(size, colors, rotation);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QImage GenerateLinearGradient(
|
||||||
|
QSize size,
|
||||||
|
const std::vector<QColor> &colors,
|
||||||
|
int rotation) {
|
||||||
|
Expects(!colors.empty());
|
||||||
|
|
||||||
auto result = QImage(size, QImage::Format_RGB32);
|
auto result = QImage(size, QImage::Format_RGB32);
|
||||||
if (colors.size() == 1) {
|
if (colors.size() == 1) {
|
||||||
result.fill(colors.front());
|
result.fill(colors.front());
|
||||||
|
|
@ -846,10 +856,21 @@ QImage BlurLargeImage(QImage image, int radius) {
|
||||||
Unexpected("Rotation value in GenerateDitheredGradient.");
|
Unexpected("Rotation value in GenerateDitheredGradient.");
|
||||||
}();
|
}();
|
||||||
auto gradient = QLinearGradient(start, finalStop);
|
auto gradient = QLinearGradient(start, finalStop);
|
||||||
gradient.setStops(QGradientStops{
|
|
||||||
{ 0.0, colors[0] },
|
if (colors.size() == 2) {
|
||||||
{ 1.0, colors[1] }
|
gradient.setStops(QGradientStops{
|
||||||
});
|
{ 0.0, colors[0] },
|
||||||
|
{ 1.0, colors[1] }
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
auto stops = QGradientStops();
|
||||||
|
const auto step = 1. / (colors.size() - 1);
|
||||||
|
auto point = 0.;
|
||||||
|
for (const auto color : colors) {
|
||||||
|
stops.append({ point, color });
|
||||||
|
point += step;
|
||||||
|
}
|
||||||
|
}
|
||||||
p.fillRect(QRect(QPoint(), size), QBrush(std::move(gradient)));
|
p.fillRect(QRect(QPoint(), size), QBrush(std::move(gradient)));
|
||||||
p.end();
|
p.end();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,11 @@ namespace Images {
|
||||||
int rotation = 0,
|
int rotation = 0,
|
||||||
float progress = 1.f);
|
float progress = 1.f);
|
||||||
|
|
||||||
|
[[nodiscard]] QImage GenerateLinearGradient(
|
||||||
|
QSize size,
|
||||||
|
const std::vector<QColor> &colors,
|
||||||
|
int rotation = 0);
|
||||||
|
|
||||||
[[nodiscard]] const std::array<QImage, 4> &CornersMask(
|
[[nodiscard]] const std::array<QImage, 4> &CornersMask(
|
||||||
ImageRoundRadius radius);
|
ImageRoundRadius radius);
|
||||||
[[nodiscard]] std::array<QImage, 4> PrepareCorners(
|
[[nodiscard]] std::array<QImage, 4> PrepareCorners(
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,15 @@ palette::SetResult palette::setColor(QLatin1String name, uchar r, uchar g, uchar
|
||||||
return duplicate ? SetResult::Duplicate : SetResult::Ok;
|
return duplicate ? SetResult::Duplicate : SetResult::Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
palette::SetResult palette::setColor(QLatin1String name, const QColor &color) {
|
||||||
|
auto r = 0;
|
||||||
|
auto g = 0;
|
||||||
|
auto b = 0;
|
||||||
|
auto a = 0;
|
||||||
|
color.getRgb(&r, &g, &b, &a);
|
||||||
|
return setColor(name, uchar(r), uchar(g), uchar(b), uchar(a));
|
||||||
|
}
|
||||||
|
|
||||||
palette::SetResult palette::setColor(QLatin1String name, QLatin1String from) {
|
palette::SetResult palette::setColor(QLatin1String name, QLatin1String from) {
|
||||||
const auto nameIndex = internal::GetPaletteIndex(name);
|
const auto nameIndex = internal::GetPaletteIndex(name);
|
||||||
if (nameIndex < 0) {
|
if (nameIndex < 0) {
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ public:
|
||||||
Duplicate,
|
Duplicate,
|
||||||
};
|
};
|
||||||
SetResult setColor(QLatin1String name, uchar r, uchar g, uchar b, uchar a);
|
SetResult setColor(QLatin1String name, uchar r, uchar g, uchar b, uchar a);
|
||||||
|
SetResult setColor(QLatin1String name, const QColor &color);
|
||||||
SetResult setColor(QLatin1String name, QLatin1String from);
|
SetResult setColor(QLatin1String name, QLatin1String from);
|
||||||
void reset(const colorizer &with);
|
void reset(const colorizer &with);
|
||||||
void reset();
|
void reset();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue