Skip to content

Commit 5544bc2

Browse files
committed
ColorInformation: Support dimmed background
1 parent 8f8d250 commit 5544bc2

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

background/Background.vala

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,18 @@ public interface Gala.Background.Background : Object, Gdk.Paintable {
6161
}
6262

6363
public Utils.ColorInformation? get_color_information (int height) {
64-
return texture.get_color_information (height);
64+
var info = texture.get_color_information (height);
65+
if (info == null) {
66+
return null;
67+
}
68+
69+
info.average_red *= 0.55;
70+
info.average_green *= 0.55;
71+
info.average_blue *= 0.55;
72+
info.mean_luminance *= 0.55;
73+
info.luminance_variance *= 0.55;
74+
75+
return info;
6576
}
6677

6778
public void snapshot (Gdk.Snapshot gdk_snapshot, double width, double height) {

background/Utils.vala

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Copyright 2024 elementary, Inc. (https://elementary.io)
3+
* SPDX-License-Identifier: GPL-3.0-or-later
4+
*/
5+
16
namespace Gala.Background.Utils {
27
private const double SATURATION_WEIGHT = 1.5;
38
private const double WEIGHT_THRESHOLD = 1.0;
@@ -12,18 +17,15 @@ namespace Gala.Background.Utils {
1217
}
1318

1419
public static ColorInformation? get_background_color_information (Gdk.Texture texture, int panel_height) {
15-
int x_start = 0;
16-
int y_start = 0;
17-
1820
int width = texture.width;
1921
int height = int.min (texture.height, panel_height);
2022

2123
if (width <= 0 || height <= 0) {
22-
warning ("Got invalid rectangle: %i, %i, %i, %i".printf (x_start, y_start, width, height));
24+
warning ("Got invalid rectangle: %i, %i".printf (width, height));
2325
return null;
2426
}
2527

26-
double mean_acutance = 0, variance = 0, mean = 0, r_total = 0, g_total = 0, b_total = 0;
28+
double mean_acutance, variance, mean, r_total, g_total, b_total = 0;
2729

2830
var texture_width = texture.width;
2931
var texture_height = texture.height;
@@ -45,13 +47,13 @@ namespace Gala.Background.Utils {
4547
* plank's lib/Drawing/DrawingService.vala average_color()
4648
* http://bazaar.launchpad.net/~docky-core/plank/trunk/view/head:/lib/Drawing/DrawingService.vala
4749
*/
48-
for (int y = y_start; y < (y_start + height); y++) {
49-
for (int x = x_start; x < (x_start + width); x++) {
50+
for (int y = 0; y < height; y++) {
51+
for (int x = 0; x < width; x++) {
5052
int i = (y * (int)texture_width * 4) + (x * 4);
5153

52-
uint8 b = pixels[i];
53-
uint8 g = pixels[i + 1];
54-
uint8 r = pixels[i + 2];
54+
uint8 r = pixels[i + 1];
55+
uint8 g = pixels[i + 2];
56+
uint8 b = pixels[i + 3];
5557

5658
pixel = (0.3 * r + 0.59 * g + 0.11 * b) ;
5759

@@ -79,8 +81,8 @@ namespace Gala.Background.Utils {
7981
}
8082
}
8183

82-
for (int y = y_start + 1; y < (y_start + height) - 1; y++) {
83-
for (int x = x_start + 1; x < (x_start + width) - 1; x++) {
84+
for (int y = 1; y < height - 1; y++) {
85+
for (int x = 1; x < width - 1; x++) {
8486
var acutance =
8587
(pixel_lums[y * width + x] * 4) -
8688
(

0 commit comments

Comments
 (0)