[metacity] gradient: avoid a forward declaration



commit 102400137f3aef9e1be1b311f7cba1c72c70b5b1
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sun Jan 17 12:20:53 2016 +0200

    gradient: avoid a forward declaration

 src/ui/gradient.c |  425 +++++++++++++++++++++++++----------------------------
 1 files changed, 198 insertions(+), 227 deletions(-)
---
diff --git a/src/ui/gradient.c b/src/ui/gradient.c
index 3006f6d..f9354d8 100644
--- a/src/ui/gradient.c
+++ b/src/ui/gradient.c
@@ -27,35 +27,6 @@
 #include "util.h"
 #include <string.h>
 
-/* This is all Alfredo's and Dan's usual very nice WindowMaker code,
- * slightly GTK-ized
- */
-static GdkPixbuf* meta_gradient_create_horizontal       (int             width,
-                                                         int             height,
-                                                         const GdkRGBA  *from,
-                                                         const GdkRGBA  *to);
-static GdkPixbuf* meta_gradient_create_vertical         (int             width,
-                                                         int             height,
-                                                         const GdkRGBA  *from,
-                                                         const GdkRGBA  *to);
-static GdkPixbuf* meta_gradient_create_diagonal         (int             width,
-                                                         int             height,
-                                                         const GdkRGBA  *from,
-                                                         const GdkRGBA  *to);
-static GdkPixbuf* meta_gradient_create_multi_horizontal (int             width,
-                                                         int             height,
-                                                         const GdkRGBA  *colors,
-                                                         int             count);
-static GdkPixbuf* meta_gradient_create_multi_vertical   (int             width,
-                                                         int             height,
-                                                         const GdkRGBA  *colors,
-                                                         int             count);
-static GdkPixbuf* meta_gradient_create_multi_diagonal   (int             width,
-                                                         int             height,
-                                                         const GdkRGBA  *colors,
-                                                         int             count);
-
-
 /* Used as the destroy notification function for gdk_pixbuf_new() */
 static void
 free_buffer (guchar *pixels, gpointer data)
@@ -85,204 +56,6 @@ blank_pixbuf (int width, int height)
                                    free_buffer, NULL);
 }
 
-/**
- * meta_gradient_create_simple:
- * @width: Width in pixels
- * @height: Height in pixels
- * @from: Starting color
- * @to: Ending color
- * @style: Gradient style
- *
- * Returns: (transfer full): A new linear gradient
- */
-GdkPixbuf*
-meta_gradient_create_simple (int              width,
-                             int              height,
-                             const GdkRGBA   *from,
-                             const GdkRGBA   *to,
-                             MetaGradientType style)
-{
-  switch (style)
-    {
-    case META_GRADIENT_HORIZONTAL:
-      return meta_gradient_create_horizontal (width, height,
-                                              from, to);
-    case META_GRADIENT_VERTICAL:
-      return meta_gradient_create_vertical (width, height,
-                                            from, to);
-
-    case META_GRADIENT_DIAGONAL:
-      return meta_gradient_create_diagonal (width, height,
-                                            from, to);
-    case META_GRADIENT_LAST:
-      break;
-
-    default:
-      break;
-    }
-  g_assert_not_reached ();
-  return NULL;
-}
-
-/**
- * meta_gradient_create_multi:
- * @width: Width in pixels
- * @height: Height in pixels
- * @colors: (array length=n_colors): Array of colors
- * @n_colors: Number of colors
- * @style: Gradient style
- *
- * Returns: (transfer full): A new multi-step linear gradient
- */
-GdkPixbuf*
-meta_gradient_create_multi (int              width,
-                            int              height,
-                            const GdkRGBA   *colors,
-                            int              n_colors,
-                            MetaGradientType style)
-{
-
-  if (n_colors > 2)
-    {
-      switch (style)
-        {
-        case META_GRADIENT_HORIZONTAL:
-          return meta_gradient_create_multi_horizontal (width, height, colors, n_colors);
-        case META_GRADIENT_VERTICAL:
-          return meta_gradient_create_multi_vertical (width, height, colors, n_colors);
-        case META_GRADIENT_DIAGONAL:
-          return meta_gradient_create_multi_diagonal (width, height, colors, n_colors);
-        case META_GRADIENT_LAST:
-          g_assert_not_reached ();
-          break;
-        default:
-          g_assert_not_reached ();
-          break;
-        }
-    }
-  else if (n_colors > 1)
-    {
-      return meta_gradient_create_simple (width, height, &colors[0], &colors[1],
-                                          style);
-    }
-  else if (n_colors > 0)
-    {
-      return meta_gradient_create_simple (width, height, &colors[0], &colors[0],
-                                          style);
-    }
-  g_assert_not_reached ();
-  return NULL;
-}
-
-/**
- * meta_gradient_create_interwoven: (skip)
- * @width: Width in pixels
- * @height: Height in pixels
- * @colors1: Array of colors
- * @thickness1: Thickness
- * @colors2: Array of colors
- * @thickness2: Thickness
- *
- * Interwoven essentially means we have two vertical gradients,
- * cut into horizontal strips of the given thickness, and then the strips
- * are alternated. I'm not sure what it's good for, just copied since
- * WindowMaker had it.
- */
-GdkPixbuf*
-meta_gradient_create_interwoven (int            width,
-                                 int            height,
-                                 const GdkRGBA  colors1[2],
-                                 int            thickness1,
-                                 const GdkRGBA  colors2[2],
-                                 int            thickness2)
-{
-
-  int i, j, k, l, ll;
-  long r1, g1, b1, a1, dr1, dg1, db1, da1;
-  long r2, g2, b2, a2, dr2, dg2, db2, da2;
-  GdkPixbuf *pixbuf;
-  unsigned char *ptr;
-  unsigned char *pixels;
-  int rowstride;
-
-  pixbuf = blank_pixbuf (width, height);
-  if (pixbuf == NULL)
-    return NULL;
-
-  pixels = gdk_pixbuf_get_pixels (pixbuf);
-  rowstride = gdk_pixbuf_get_rowstride (pixbuf);
-
-  r1 = (long)(colors1[0].red*0xffffff);
-  g1 = (long)(colors1[0].green*0xffffff);
-  b1 = (long)(colors1[0].blue*0xffffff);
-  a1 = (long)(colors1[0].alpha*0xffffff);
-
-  r2 = (long)(colors2[0].red*0xffffff);
-  g2 = (long)(colors2[0].green*0xffffff);
-  b2 = (long)(colors2[0].blue*0xffffff);
-  a2 = (long)(colors2[0].alpha*0xffffff);
-
-  dr1 = ((colors1[1].red-colors1[0].red)*0xffffff)/(int)height;
-  dg1 = ((colors1[1].green-colors1[0].green)*0xffffff)/(int)height;
-  db1 = ((colors1[1].blue-colors1[0].blue)*0xffffff)/(int)height;
-  da1 = ((colors1[1].alpha-colors1[0].alpha)*0xffffff)/(int)height;
-
-  dr2 = ((colors2[1].red-colors2[0].red)*0xffffff)/(int)height;
-  dg2 = ((colors2[1].green-colors2[0].green)*0xffffff)/(int)height;
-  db2 = ((colors2[1].blue-colors2[0].blue)*0xffffff)/(int)height;
-  da2 = ((colors2[1].alpha-colors2[0].alpha)*0xffffff)/(int)height;
-
-  for (i=0,k=0,l=0,ll=thickness1; i<height; i++)
-    {
-      ptr = pixels + i * rowstride;
-
-      if (k == 0)
-        {
-          ptr[0] = (unsigned char) (r1>>16);
-          ptr[1] = (unsigned char) (g1>>16);
-          ptr[2] = (unsigned char) (b1>>16);
-          ptr[3] = (unsigned char) (a1>>16);
-        }
-      else
-        {
-          ptr[0] = (unsigned char) (r2>>16);
-          ptr[1] = (unsigned char) (g2>>16);
-          ptr[2] = (unsigned char) (b2>>16);
-          ptr[3] = (unsigned char) (a2>>16);
-        }
-
-      for (j=1; j <= width/2; j *= 2)
-        memcpy (&(ptr[j*4]), ptr, j*4);
-      memcpy (&(ptr[j*4]), ptr, (width - j)*4);
-
-      if (++l == ll)
-        {
-          if (k == 0)
-            {
-              k = 1;
-              ll = thickness2;
-            }
-          else
-            {
-              k = 0;
-              ll = thickness1;
-            }
-          l = 0;
-        }
-      r1+=dr1;
-      g1+=dg1;
-      b1+=db1;
-      a1+=da1;
-
-      r2+=dr2;
-      g2+=dg2;
-      b2+=db2;
-      a2+=da2;
-    }
-
-  return pixbuf;
-}
-
 /*
  *----------------------------------------------------------------------
  * meta_gradient_create_horizontal--
@@ -876,6 +649,204 @@ meta_gradient_add_alpha_horizontal (GdkPixbuf           *pixbuf,
   g_free (gradient);
 }
 
+/**
+ * meta_gradient_create_simple:
+ * @width: Width in pixels
+ * @height: Height in pixels
+ * @from: Starting color
+ * @to: Ending color
+ * @style: Gradient style
+ *
+ * Returns: (transfer full): A new linear gradient
+ */
+GdkPixbuf*
+meta_gradient_create_simple (int              width,
+                             int              height,
+                             const GdkRGBA   *from,
+                             const GdkRGBA   *to,
+                             MetaGradientType style)
+{
+  switch (style)
+    {
+    case META_GRADIENT_HORIZONTAL:
+      return meta_gradient_create_horizontal (width, height,
+                                              from, to);
+    case META_GRADIENT_VERTICAL:
+      return meta_gradient_create_vertical (width, height,
+                                            from, to);
+
+    case META_GRADIENT_DIAGONAL:
+      return meta_gradient_create_diagonal (width, height,
+                                            from, to);
+    case META_GRADIENT_LAST:
+      break;
+
+    default:
+      break;
+    }
+  g_assert_not_reached ();
+  return NULL;
+}
+
+/**
+ * meta_gradient_create_multi:
+ * @width: Width in pixels
+ * @height: Height in pixels
+ * @colors: (array length=n_colors): Array of colors
+ * @n_colors: Number of colors
+ * @style: Gradient style
+ *
+ * Returns: (transfer full): A new multi-step linear gradient
+ */
+GdkPixbuf*
+meta_gradient_create_multi (int              width,
+                            int              height,
+                            const GdkRGBA   *colors,
+                            int              n_colors,
+                            MetaGradientType style)
+{
+
+  if (n_colors > 2)
+    {
+      switch (style)
+        {
+        case META_GRADIENT_HORIZONTAL:
+          return meta_gradient_create_multi_horizontal (width, height, colors, n_colors);
+        case META_GRADIENT_VERTICAL:
+          return meta_gradient_create_multi_vertical (width, height, colors, n_colors);
+        case META_GRADIENT_DIAGONAL:
+          return meta_gradient_create_multi_diagonal (width, height, colors, n_colors);
+        case META_GRADIENT_LAST:
+          g_assert_not_reached ();
+          break;
+        default:
+          g_assert_not_reached ();
+          break;
+        }
+    }
+  else if (n_colors > 1)
+    {
+      return meta_gradient_create_simple (width, height, &colors[0], &colors[1],
+                                          style);
+    }
+  else if (n_colors > 0)
+    {
+      return meta_gradient_create_simple (width, height, &colors[0], &colors[0],
+                                          style);
+    }
+  g_assert_not_reached ();
+  return NULL;
+}
+
+/**
+ * meta_gradient_create_interwoven: (skip)
+ * @width: Width in pixels
+ * @height: Height in pixels
+ * @colors1: Array of colors
+ * @thickness1: Thickness
+ * @colors2: Array of colors
+ * @thickness2: Thickness
+ *
+ * Interwoven essentially means we have two vertical gradients,
+ * cut into horizontal strips of the given thickness, and then the strips
+ * are alternated. I'm not sure what it's good for, just copied since
+ * WindowMaker had it.
+ */
+GdkPixbuf*
+meta_gradient_create_interwoven (int            width,
+                                 int            height,
+                                 const GdkRGBA  colors1[2],
+                                 int            thickness1,
+                                 const GdkRGBA  colors2[2],
+                                 int            thickness2)
+{
+
+  int i, j, k, l, ll;
+  long r1, g1, b1, a1, dr1, dg1, db1, da1;
+  long r2, g2, b2, a2, dr2, dg2, db2, da2;
+  GdkPixbuf *pixbuf;
+  unsigned char *ptr;
+  unsigned char *pixels;
+  int rowstride;
+
+  pixbuf = blank_pixbuf (width, height);
+  if (pixbuf == NULL)
+    return NULL;
+
+  pixels = gdk_pixbuf_get_pixels (pixbuf);
+  rowstride = gdk_pixbuf_get_rowstride (pixbuf);
+
+  r1 = (long)(colors1[0].red*0xffffff);
+  g1 = (long)(colors1[0].green*0xffffff);
+  b1 = (long)(colors1[0].blue*0xffffff);
+  a1 = (long)(colors1[0].alpha*0xffffff);
+
+  r2 = (long)(colors2[0].red*0xffffff);
+  g2 = (long)(colors2[0].green*0xffffff);
+  b2 = (long)(colors2[0].blue*0xffffff);
+  a2 = (long)(colors2[0].alpha*0xffffff);
+
+  dr1 = ((colors1[1].red-colors1[0].red)*0xffffff)/(int)height;
+  dg1 = ((colors1[1].green-colors1[0].green)*0xffffff)/(int)height;
+  db1 = ((colors1[1].blue-colors1[0].blue)*0xffffff)/(int)height;
+  da1 = ((colors1[1].alpha-colors1[0].alpha)*0xffffff)/(int)height;
+
+  dr2 = ((colors2[1].red-colors2[0].red)*0xffffff)/(int)height;
+  dg2 = ((colors2[1].green-colors2[0].green)*0xffffff)/(int)height;
+  db2 = ((colors2[1].blue-colors2[0].blue)*0xffffff)/(int)height;
+  da2 = ((colors2[1].alpha-colors2[0].alpha)*0xffffff)/(int)height;
+
+  for (i=0,k=0,l=0,ll=thickness1; i<height; i++)
+    {
+      ptr = pixels + i * rowstride;
+
+      if (k == 0)
+        {
+          ptr[0] = (unsigned char) (r1>>16);
+          ptr[1] = (unsigned char) (g1>>16);
+          ptr[2] = (unsigned char) (b1>>16);
+          ptr[3] = (unsigned char) (a1>>16);
+        }
+      else
+        {
+          ptr[0] = (unsigned char) (r2>>16);
+          ptr[1] = (unsigned char) (g2>>16);
+          ptr[2] = (unsigned char) (b2>>16);
+          ptr[3] = (unsigned char) (a2>>16);
+        }
+
+      for (j=1; j <= width/2; j *= 2)
+        memcpy (&(ptr[j*4]), ptr, j*4);
+      memcpy (&(ptr[j*4]), ptr, (width - j)*4);
+
+      if (++l == ll)
+        {
+          if (k == 0)
+            {
+              k = 1;
+              ll = thickness2;
+            }
+          else
+            {
+              k = 0;
+              ll = thickness1;
+            }
+          l = 0;
+        }
+      r1+=dr1;
+      g1+=dg1;
+      b1+=db1;
+      a1+=da1;
+
+      r2+=dr2;
+      g2+=dg2;
+      b2+=db2;
+      a2+=da2;
+    }
+
+  return pixbuf;
+}
+
 void
 meta_gradient_add_alpha (GdkPixbuf       *pixbuf,
                          const guchar    *alphas,


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