summaryrefslogtreecommitdiff
path: root/libmate-desktop
diff options
context:
space:
mode:
authorraveit65 <[email protected]>2016-06-18 18:53:21 +0200
committerraveit65 <[email protected]>2016-07-02 10:26:46 +0200
commit90d0a924f844d5dde9a687ee872c26d5e3237687 (patch)
treeb1d4ec5eab4471e79098252904b24ea3305ab734 /libmate-desktop
parentc0f4ab4692744ab08f4f38880e78db0bfdc4d02f (diff)
downloadmate-desktop-90d0a924f844d5dde9a687ee872c26d5e3237687.tar.bz2
mate-desktop-90d0a924f844d5dde9a687ee872c26d5e3237687.tar.xz
GTK+-3 mate-bg: have pixbuf_average_value return GdkRGBA
Now that we have a proper type for RGBA values, we should use it (instead of packing the four components into a uint32). https://bugzilla.gnome.org/show_bug.cgi?id=671750 taken from: https://git.gnome.org/browse/gnome-desktop/commit/?h=gnome-3-4&id=0f60413
Diffstat (limited to 'libmate-desktop')
-rw-r--r--libmate-desktop/mate-bg.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/libmate-desktop/mate-bg.c b/libmate-desktop/mate-bg.c
index 24c0776..d53510f 100644
--- a/libmate-desktop/mate-bg.c
+++ b/libmate-desktop/mate-bg.c
@@ -148,7 +148,12 @@ static GdkPixmap *make_root_pixmap (GdkWindow *window,
gint height);
/* Pixbuf utils */
+#if GTK_CHECK_VERSION (3, 0, 0)
+static void pixbuf_average_value (GdkPixbuf *pixbuf,
+ GdkRGBA *result);
+#else
static guint32 pixbuf_average_value (GdkPixbuf *pixbuf);
+#endif
static GdkPixbuf *pixbuf_scale_to_fit (GdkPixbuf *src,
int max_width,
int max_height);
@@ -1299,11 +1304,21 @@ mate_bg_is_dark (MateBG *bg,
}
pixbuf = get_pixbuf_for_size (bg, -1, width, height);
if (pixbuf) {
+#if GTK_CHECK_VERSION (3, 0, 0)
+ GdkRGBA argb;
+
+ pixbuf_average_value (pixbuf, &argb);
+ guchar a = argb.alpha * 0xff;
+ guchar r = argb.red * 0xff;
+ guchar g = argb.green * 0xff;
+ guchar b = argb.blue * 0xff;
+#else
guint32 argb = pixbuf_average_value (pixbuf);
guchar a = (argb >> 24) & 0xff;
guchar r = (argb >> 16) & 0xff;
guchar g = (argb >> 8) & 0xff;
guchar b = (argb >> 0) & 0xff;
+#endif
color.red = (color.red * (0xFF - a) + r * 0x101 * a) / 0xFF;
color.green = (color.green * (0xFF - a) + g * 0x101 * a) / 0xFF;
@@ -2554,8 +2569,14 @@ clear_cache (MateBG *bg)
}
/* Pixbuf utilities */
+#if GTK_CHECK_VERSION (3, 0, 0)
+static void
+pixbuf_average_value (GdkPixbuf *pixbuf,
+ GdkRGBA *result)
+#else
static guint32
pixbuf_average_value (GdkPixbuf *pixbuf)
+#endif
{
guint64 a_total, r_total, g_total, b_total;
guint row, column;
@@ -2564,6 +2585,9 @@ pixbuf_average_value (GdkPixbuf *pixbuf)
int r, g, b, a;
guint64 dividend;
guint width, height;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ gdouble dd;
+#endif
width = gdk_pixbuf_get_width (pixbuf);
height = gdk_pixbuf_get_height (pixbuf);
@@ -2609,11 +2633,20 @@ pixbuf_average_value (GdkPixbuf *pixbuf)
dividend = height * width;
a_total = dividend * 0xFF;
}
+#if GTK_CHECK_VERSION (3, 0, 0)
+
+ dd = dividend * 0xFF;
+ result->alpha = a_total / dd;
+ result->red = r_total / dd;
+ result->green = g_total / dd;
+ result->blue = b_total / dd;
+#else
return ((a_total + dividend / 2) / dividend) << 24
| ((r_total + dividend / 2) / dividend) << 16
| ((g_total + dividend / 2) / dividend) << 8
| ((b_total + dividend / 2) / dividend);
+#endif
}
static GdkPixbuf *