[metacity] libmetacity: fix gradients with one alpha value



commit 431e0418e05125d103a811b106f777eef7fe2aa7
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sat Feb 25 19:09:29 2017 +0200

    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 files changed, 13 insertions(+), 4 deletions(-)
---
diff --git a/libmetacity/meta-gradient-spec.c b/libmetacity/meta-gradient-spec.c
index cfb0f82..79f1bd5 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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]