[Xfce4-commits] <ristretto:master> Apply the brightness setting in the wallpaper-manager preview window.

Stephan Arts noreply at xfce.org
Sun Nov 6 10:26:06 CET 2011


Updating branch refs/heads/master
         to 6c88ad70e96c6d6e4fc72077b882d1dcfd67a065 (commit)
       from e5c4bcc47caa7773c84d13a8f47f62476236e1b2 (commit)

commit 6c88ad70e96c6d6e4fc72077b882d1dcfd67a065
Author: Stephan Arts <stephan at xfce.org>
Date:   Sun Nov 6 10:21:42 2011 +0100

    Apply the brightness setting in the wallpaper-manager preview window.

 src/xfce_wallpaper_manager.c |  113 ++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 108 insertions(+), 5 deletions(-)

diff --git a/src/xfce_wallpaper_manager.c b/src/xfce_wallpaper_manager.c
index e1b2799..1f12d3a 100644
--- a/src/xfce_wallpaper_manager.c
+++ b/src/xfce_wallpaper_manager.c
@@ -14,6 +14,9 @@
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *  The adjust-brightness code is written by
+ *  Brian Tarricone <bjt23 at cornell.edu>, originally written for xfdesktop.
  */
 
 #include <config.h>
@@ -26,6 +29,9 @@
 #include <libxfce4util/libxfce4util.h>
 #include <gio/gio.h>
 
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gdk-pixbuf/gdk-pixdata.h>
+
 #include <libexif/exif-data.h>
 
 #include "util.h"
@@ -54,6 +60,11 @@ rstto_xfce_wallpaper_manager_dispose (GObject *object);
 static void
 rstto_xfce_wallpaper_manager_finalize (GObject *object);
 
+static GdkPixbuf *
+adjust_brightness (
+        GdkPixbuf *src,
+        gint amount );
+
 static void
 cb_style_combo_changed (
         GtkComboBox *style_combo,
@@ -113,6 +124,7 @@ rstto_xfce_wallpaper_manager_configure_dialog_run (
     manager->priv->file = file;
     GdkPixbuf *monitor_pixbuf = NULL;
     gdouble saturation = gtk_adjustment_get_value (GTK_ADJUSTMENT(manager->priv->saturation_adjustment));
+    gdouble brightness = gtk_adjustment_get_value (GTK_ADJUSTMENT(manager->priv->brightness_adjustment));
 
     if (manager->priv->pixbuf)
     {
@@ -129,12 +141,18 @@ rstto_xfce_wallpaper_manager_configure_dialog_run (
     {
         monitor_pixbuf = gdk_pixbuf_copy (manager->priv->pixbuf);
         gdk_pixbuf_saturate_and_pixelate (
+                monitor_pixbuf,
+                monitor_pixbuf,
+                saturation,
+                FALSE);
+        monitor_pixbuf = adjust_brightness (
             monitor_pixbuf,
-            monitor_pixbuf,
-            saturation,
-            FALSE);
+            (gint)brightness);
     }
 
+    /* The monitor-chooser adds a reference to the pixbuf,
+     * so we should unref this pixbuf at a later time.
+     */
     rstto_monitor_chooser_set_pixbuf (
             RSTTO_MONITOR_CHOOSER(manager->priv->monitor_chooser),
             manager->priv->monitor,
@@ -661,9 +679,32 @@ cb_monitor_chooser_changed (
 static void
 cb_brightness_adjustment_value_changed (
         GtkAdjustment *adjustment,
-        RsttoXfceWallpaperManager *man)
+        RsttoXfceWallpaperManager *manager)
 {
+    GdkPixbuf *monitor_pixbuf = NULL;
+    gdouble saturation = gtk_adjustment_get_value (GTK_ADJUSTMENT(manager->priv->saturation_adjustment));
+    gdouble brightness = gtk_adjustment_get_value (GTK_ADJUSTMENT(manager->priv->brightness_adjustment));
+
+    if (manager->priv->pixbuf)
+    {
+        monitor_pixbuf = gdk_pixbuf_copy (manager->priv->pixbuf);
+        gdk_pixbuf_saturate_and_pixelate (
+            monitor_pixbuf,
+            monitor_pixbuf,
+            saturation,
+            FALSE);
+        monitor_pixbuf = adjust_brightness (
+            monitor_pixbuf,
+            (gint)brightness);
+    }
+
+    rstto_monitor_chooser_set_pixbuf (
+            RSTTO_MONITOR_CHOOSER(manager->priv->monitor_chooser),
+            manager->priv->monitor,
+            monitor_pixbuf,
+            NULL);
 
+    g_object_unref (monitor_pixbuf);
 }
 
 static void
@@ -672,7 +713,8 @@ cb_saturation_adjustment_value_changed (
         RsttoXfceWallpaperManager *manager)
 {
     GdkPixbuf *monitor_pixbuf = NULL;
-    gdouble saturation = gtk_adjustment_get_value (adjustment);
+    gdouble saturation = gtk_adjustment_get_value (GTK_ADJUSTMENT(manager->priv->saturation_adjustment));
+    gdouble brightness = gtk_adjustment_get_value (GTK_ADJUSTMENT(manager->priv->brightness_adjustment));
 
     if (manager->priv->pixbuf)
     {
@@ -682,6 +724,9 @@ cb_saturation_adjustment_value_changed (
             monitor_pixbuf,
             saturation,
             FALSE);
+        monitor_pixbuf = adjust_brightness (
+            monitor_pixbuf,
+            (gint)brightness);
     }
 
     rstto_monitor_chooser_set_pixbuf (
@@ -692,3 +737,61 @@ cb_saturation_adjustment_value_changed (
 
     g_object_unref (monitor_pixbuf);
 }
+
+/** adjust_brightness:
+ * @src: Source Pixbuf
+ * @amount: Amount of brightness to be adjusted, a positive value means
+ * increased brightness, a negative value means decreased brightness.
+ *
+ * The contents of this function are copied from xfdesktop, written by 
+ * Brian Tarricone
+ */
+static GdkPixbuf *
+adjust_brightness (
+        GdkPixbuf *src,
+        gint amount )
+{
+    GdkPixbuf *newpix;
+    GdkPixdata pdata;
+    gboolean has_alpha = FALSE;
+    gint i, len;
+    GError *err = NULL;
+    
+    g_return_val_if_fail(src != NULL, NULL);
+    if(amount == 0)
+    {
+        return src;
+    }
+    
+    gdk_pixdata_from_pixbuf(&pdata, src, FALSE);
+    has_alpha = (pdata.pixdata_type & GDK_PIXDATA_COLOR_TYPE_RGBA);
+    if(pdata.length < 1)
+        len = pdata.width * pdata.height * (has_alpha?4:3);
+    else
+        len = pdata.length - GDK_PIXDATA_HEADER_LENGTH;
+    
+    for(i = 0; i < len; i++) {
+        gshort scaled;
+        
+        if(has_alpha && (i+1)%4)
+            continue;
+        
+        scaled = pdata.pixel_data[i] + amount;
+        if(scaled > 255)
+            scaled = 255;
+        if(scaled < 0)
+            scaled = 0;
+        pdata.pixel_data[i] = scaled;
+    }
+    
+    newpix = gdk_pixbuf_from_pixdata(&pdata, TRUE, &err);
+    if(!newpix) {
+        g_warning("%s: Unable to modify image brightness: %s", PACKAGE,
+                err->message);
+        g_error_free(err);
+        return src;
+    }
+    g_object_unref(G_OBJECT(src));
+    
+    return newpix;
+}


More information about the Xfce4-commits mailing list