From 431e0418e05125d103a811b106f777eef7fe2aa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberts=20Muktup=C4=81vels?= Date: Sat, 25 Feb 2017 19:09:29 +0200 Subject: libmetacity: fix gradients with one alpha value Commit 71d5decc42f3367bcbe2c4656356edd0f94d9feb ported gradient code from GdkPixbuf to cairo. Ported coded wrongly assumed that alpha values always match color stops. --- libmetacity/meta-gradient-spec.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/libmetacity/meta-gradient-spec.c b/libmetacity/meta-gradient-spec.c index cfb0f82e..79f1bd52 100644 --- a/libmetacity/meta-gradient-spec.c +++ b/libmetacity/meta-gradient-spec.c @@ -52,7 +52,7 @@ create_cairo_pattern_from_gradient_spec (const MetaGradientSpec *spec, if (n_colors == 0) return NULL; - if (alpha_spec != NULL) + if (alpha_spec != NULL && alpha_spec->n_alphas != 1) g_assert (n_colors == alpha_spec->n_alphas); if (spec->type == META_GRADIENT_HORIZONTAL) @@ -73,9 +73,18 @@ create_cairo_pattern_from_gradient_spec (const MetaGradientSpec *spec, meta_color_spec_render (tmp->data, context, &color); if (alpha_spec != NULL) - cairo_pattern_add_color_stop_rgba (pattern, i / (gfloat) (n_colors - 1), - color.red, color.green, color.blue, - alpha_spec->alphas[i] / 255.0); + { + gdouble alpha; + + if (alpha_spec->n_alphas == 1) + alpha = alpha_spec->alphas[0] / 255.0; + else + alpha = alpha_spec->alphas[i] / 255.0; + + cairo_pattern_add_color_stop_rgba (pattern, i / (gfloat) (n_colors - 1), + color.red, color.green, color.blue, + alpha); + } else cairo_pattern_add_color_stop_rgb (pattern, i / (gfloat) (n_colors - 1), color.red, color.green, color.blue); -- cgit v1.2.1