Commit 95766459 authored by Nate Graham's avatar Nate Graham
Browse files

Adjust wallpaper accent calculation to increase contrast and vibrancy

Right now, the calculation prefers the image's dominant color, which is
likely to be a color from the background. As a result, it often returns
a color that is very dark or muted, especially with wallpapers based on
night landscaped or space. The darkness is especially problematic when
using a dark color scheme, where it causes contrast issues. It also has
the effect of making the selection highlight on the desktop hard to see
since by definition, its color will be very similar to the most common
color in the wallpaper.

This commit adjusts the wallpaper accent color calculation as follows:

1. Consider a narrower range of lightness values acceptable; now the
   lightness has to be at least 0.4, and it can't be darker than 0.75.
   This fixes most of the contrast issues.
2. Try the wallpaper's highlight color before the dominant color. This
   tends to pick the color in the wallpaper that is most likely to draw
   the user's attention, even if it's not the most common color. It also
   tends to be a richer and brighter color compared to the dominant
   color, so the extracted accent color is more likly to be bright and
   pretty rather than dark and muted.
3. If the highlight color or dominant color isn't within the specified
   lightness range, lighten or darken it and try again. This makes the
   algorithm work harder to try to give you a color based on the
   highlight color or the dominant color and avoid falling back to the
   average color, which is highly likely to return a drab, muted color.

BUG: 457861
FIXED-IN: 5.26
parent 0b90d030
Pipeline #222700 passed with stage
in 6 minutes and 6 seconds
......@@ -76,25 +76,37 @@ Item {
target: desktop
property: "accentColor"
value: {
// First try the highlight color
if (isCandidateColor(imageColors.highlight)) {
return imageColors.highlight
}
// If it was too light or dark, adjust lightness a bit and try again
if (lightness(imageColors.highlight) >= 0.75) {
return Qt.darker(imageColors.highlight, 1.20);
} else {
return Qt.lighter(imageColors.highlight, 1.20);
}
// If it's still is too light or too dark, try the dominant color
if (isCandidateColor(imageColors.dominant)) {
return imageColors.dominant;
}
// If the color is too light or too dark, use highlight instead
if (isCandidateColor(imageColors.highlight)) {
return imageColors.highlight
// As before, adjust lightness a bit and try again
if (lightness(imageColors.dominant) >= 0.75) {
return Qt.darker(imageColors.dominant, 1.20);
} else {
return Qt.lighter(imageColors.dominant, 1.20);
}
// Neither is suitable, check average color.
// Neither is suitable; use the average color
if (isCandidateColor(imageColors.average)) {
return imageColors.average;
}
// Adjust the lightness of the average color
if (lightness(imageColors.average) >= 0.8) {
return Qt.darker(imageColors.average, 1.25);
// Adjust lightness and return one of them
if (lightness(imageColors.average) >= 0.75) {
return Qt.darker(imageColors.average, 1.20);
} else {
return Qt.lighter(imageColors.average, 1.25);
return Qt.lighter(imageColors.average, 1.20);
}
}
......@@ -113,7 +125,7 @@ Item {
*/
function isCandidateColor(color) {
const l = lightness(color);
return l > 0.2 && l < 0.8;
return l > 0.4 && l < 0.75;
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment