[gtk+/icon-shadow: 4/12] themingengine: use cairo image surfaces to render state effects



commit 55074fa60d26ded1dcfb5f3fb6e4566d7a16d4d3
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Jun 6 10:23:44 2011 -0400

    themingengine: use cairo image surfaces to render state effects
    
    This makes the code cleaner and allows this to be re-used in a
    pixbuf-less future.

 gtk/gtkthemingengine.c |   89 ++++++++++++++++++++++--------------------------
 1 files changed, 41 insertions(+), 48 deletions(-)
---
diff --git a/gtk/gtkthemingengine.c b/gtk/gtkthemingengine.c
index 275e3ae..b3e5d0e 100644
--- a/gtk/gtkthemingengine.c
+++ b/gtk/gtkthemingengine.c
@@ -3161,53 +3161,24 @@ lookup_icon_size (GtkThemingEngine *engine,
   return gtk_icon_size_lookup_for_settings (settings, size, width, height);
 }
 
-/* Kudos to the gnome-panel guys. */
 static void
-colorshift_pixbuf (GdkPixbuf *src,
-                   GdkPixbuf *dest,
-                   gint       shift)
-{
-  gint i, j;
-  gint width, height, has_alpha, src_rowstride, dest_rowstride;
-  guchar *target_pixels;
-  guchar *original_pixels;
-  guchar *pix_src;
-  guchar *pix_dest;
-  int val;
-  guchar r, g, b;
-
-  has_alpha       = gdk_pixbuf_get_has_alpha (src);
-  width           = gdk_pixbuf_get_width (src);
-  height          = gdk_pixbuf_get_height (src);
-  src_rowstride   = gdk_pixbuf_get_rowstride (src);
-  dest_rowstride  = gdk_pixbuf_get_rowstride (dest);
-  original_pixels = gdk_pixbuf_get_pixels (src);
-  target_pixels   = gdk_pixbuf_get_pixels (dest);
-
-  for (i = 0; i < height; i++)
-    {
-      pix_dest = target_pixels   + i * dest_rowstride;
-      pix_src  = original_pixels + i * src_rowstride;
+colorshift_source (cairo_t *cr,
+		   gdouble shift)
+{
+  cairo_pattern_t *source;
 
-      for (j = 0; j < width; j++)
-        {
-          r = *(pix_src++);
-          g = *(pix_src++);
-          b = *(pix_src++);
+  cairo_save (cr);
+  cairo_paint (cr);
 
-          val = r + shift;
-          *(pix_dest++) = CLAMP (val, 0, 255);
+  source = cairo_pattern_reference (cairo_get_source (cr));
 
-          val = g + shift;
-          *(pix_dest++) = CLAMP (val, 0, 255);
+  cairo_set_source_rgb (cr, shift, shift, shift);
+  cairo_set_operator (cr, CAIRO_OPERATOR_COLOR_DODGE);
 
-          val = b + shift;
-          *(pix_dest++) = CLAMP (val, 0, 255);
+  cairo_mask (cr, source);
 
-          if (has_alpha)
-            *(pix_dest++) = *(pix_src++);
-        }
-    }
+  cairo_pattern_destroy (source);
+  cairo_restore (cr);
 }
 
 static GdkPixbuf *
@@ -3221,6 +3192,8 @@ gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine    *engine,
   GtkStateFlags state;
   gint width = 1;
   gint height = 1;
+  cairo_t *cr;
+  cairo_surface_t *surface;
 
   base_pixbuf = gtk_icon_source_get_pixbuf (source);
   state = gtk_theming_engine_get_state (engine);
@@ -3248,16 +3221,36 @@ gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine    *engine,
     {
       if (state & GTK_STATE_FLAG_INSENSITIVE)
         {
-          stated = gdk_pixbuf_copy (scaled);
-          gdk_pixbuf_saturate_and_pixelate (scaled, stated,
-                                            0.8, TRUE);
-          g_object_unref (scaled);
+	  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+						gdk_pixbuf_get_width (scaled),
+						gdk_pixbuf_get_height (scaled));
+	  cr = cairo_create (surface);
+	  gdk_cairo_set_source_pixbuf (cr, scaled, 0, 0);
+	  cairo_paint_with_alpha (cr, 0.5);
+
+	  cairo_destroy (cr);
+
+	  g_object_unref (scaled);
+	  stated = gdk_pixbuf_get_from_surface (surface, 0, 0,
+						cairo_image_surface_get_width (surface),
+						cairo_image_surface_get_height (surface));
         }
       else if (state & GTK_STATE_FLAG_PRELIGHT)
         {
-          stated = gdk_pixbuf_copy (scaled);
-          colorshift_pixbuf (scaled, stated, 30);
-          g_object_unref (scaled);
+	  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+						gdk_pixbuf_get_width (scaled),
+						gdk_pixbuf_get_height (scaled));
+
+	  cr = cairo_create (surface);
+	  gdk_cairo_set_source_pixbuf (cr, scaled, 0, 0);
+	  colorshift_source (cr, 0.10);
+
+	  cairo_destroy (cr);
+
+	  g_object_unref (scaled);
+	  stated = gdk_pixbuf_get_from_surface (surface, 0, 0,
+						cairo_image_surface_get_width (surface),
+						cairo_image_surface_get_height (surface));
         }
       else
         stated = scaled;



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