[gpointing-device-settings] Unified the process of creating grayscale pixbuf.



commit 7f89eb93207307a9600aa0d5eb9e35bff8ba1748
Author: Hiroyuki Ikezoe <poincare ikezoe net>
Date:   Mon Mar 15 19:22:08 2010 +0900

    Unified the process of creating grayscale pixbuf.

 src/gpds-grayed-desktop.c |   23 +----------------------
 src/gpds-main-window.c    |   34 +---------------------------------
 src/gpds-utils.c          |   32 ++++++++++++++++++++++++++++++++
 src/gpds-utils.h          |    3 ++-
 4 files changed, 36 insertions(+), 56 deletions(-)
---
diff --git a/src/gpds-grayed-desktop.c b/src/gpds-grayed-desktop.c
index 6df0799..eca04fb 100644
--- a/src/gpds-grayed-desktop.c
+++ b/src/gpds-grayed-desktop.c
@@ -90,9 +90,6 @@ create_grayscaled_background (void)
     GdkWindow *root;
     GdkPixbuf *pixbuf;
     gint width, height;
-    guchar *pixels;
-    int rowstride, n_channels;
-    int x, y;
 
     root = gdk_get_default_root_window();
     gdk_drawable_get_size(root, &width, &height);
@@ -103,25 +100,7 @@ create_grayscaled_background (void)
                                           0, 0,
                                           width, height);
 
-    pixels = gdk_pixbuf_get_pixels(pixbuf);
-    rowstride = gdk_pixbuf_get_rowstride(pixbuf);
-    n_channels = gdk_pixbuf_get_n_channels(pixbuf);
-
-    for (y = 0; y < height; y++) {
-        for (x = 0; x < width * n_channels; x += n_channels) {
-            guchar grayscale;
-            guchar *p;
-
-            p = pixels + y * rowstride + x;
-            grayscale = (p[0] * 11 + p[1] * 16 + p[2] * 5) / 32;
-            p[0] = grayscale;
-            p[1] = grayscale;
-            p[2] = grayscale;
-            p[3] = 1;
-        }
-    }
-
-    return pixbuf;
+    return gpds_convert_to_grayscaled_pixbuf(pixbuf);
 }
 
 static void
diff --git a/src/gpds-main-window.c b/src/gpds-main-window.c
index 76375b8..dea7331 100644
--- a/src/gpds-main-window.c
+++ b/src/gpds-main-window.c
@@ -478,38 +478,6 @@ grab_pointer (GpdsMainWindow *window)
     return TRUE;
 }
 
-static GdkPixbuf *
-convert_to_grayscaled_pixbuf (GdkPixbuf *src)
-{
-    GdkPixbuf *dest;
-    gint width, height;
-    guchar *pixels;
-    int rowstride, n_channels;
-    int x, y;
-
-    dest = gdk_pixbuf_copy(src);
-    width = gdk_pixbuf_get_width(dest);
-    height = gdk_pixbuf_get_height(dest);
-    rowstride = gdk_pixbuf_get_rowstride(dest);
-    n_channels = gdk_pixbuf_get_n_channels(dest);
-    pixels = gdk_pixbuf_get_pixels(dest);
-
-    for (y = 0; y < height; y++) {
-        for (x = 0; x < width * n_channels; x += n_channels) {
-            guchar grayscale;
-            guchar *p;
-
-            p = pixels + y * rowstride + x;
-            grayscale = (p[0] * 11 + p[1] * 16 + p[2] * 5) / 32;
-            p[0] = grayscale;
-            p[1] = grayscale;
-            p[2] = grayscale;
-        }
-    }
-
-    return dest;
-}
-
 static gboolean
 set_grayscaled_pixbuf (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
 {
@@ -523,7 +491,7 @@ set_grayscaled_pixbuf (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter
     gtk_tree_model_get(model, iter,
                        ORIGINAL_ICON_COLUMN, &pixbuf,
                        -1);
-    gray = convert_to_grayscaled_pixbuf(pixbuf);
+    gray = gpds_convert_to_grayscaled_pixbuf(pixbuf);
 
     gtk_list_store_set(GTK_LIST_STORE(model), iter,
                        ICON_COLUMN, gray,
diff --git a/src/gpds-utils.c b/src/gpds-utils.c
index b90ed64..e2e12be 100644
--- a/src/gpds-utils.c
+++ b/src/gpds-utils.c
@@ -41,6 +41,38 @@ gpds_get_icon_file_directory (void)
     return dir ? dir : GPDS_ICONDIR;
 }
 
+GdkPixbuf *
+gpds_convert_to_grayscaled_pixbuf (GdkPixbuf *src)
+{
+    GdkPixbuf *dest;
+    gint width, height;
+    guchar *pixels;
+    int rowstride, n_channels;
+    int x, y;
+
+    dest = gdk_pixbuf_copy(src);
+    width = gdk_pixbuf_get_width(dest);
+    height = gdk_pixbuf_get_height(dest);
+    rowstride = gdk_pixbuf_get_rowstride(dest);
+    n_channels = gdk_pixbuf_get_n_channels(dest);
+    pixels = gdk_pixbuf_get_pixels(dest);
+
+    for (y = 0; y < height; y++) {
+        for (x = 0; x < width * n_channels; x += n_channels) {
+            guchar grayscale;
+            guchar *p;
+
+            p = pixels + y * rowstride + x;
+            grayscale = (p[0] * 11 + p[1] * 16 + p[2] * 5) / 32;
+            p[0] = grayscale;
+            p[1] = grayscale;
+            p[2] = grayscale;
+        }
+    }
+
+    return dest;
+}
+
 /*
 vi:ts=4:nowrap:ai:expandtab:sw=4
 */
diff --git a/src/gpds-utils.h b/src/gpds-utils.h
index 042cec6..894be0e 100644
--- a/src/gpds-utils.h
+++ b/src/gpds-utils.h
@@ -20,12 +20,13 @@
 #ifndef __GPDS_UTILS_H__
 #define __GPDS_UTILS_H__
 
-#include <glib.h>
+#include <gtk/gtk.h>
 
 G_BEGIN_DECLS
 
 const gchar *gpds_get_ui_file_directory (void);
 const gchar *gpds_get_icon_file_directory (void);
+GdkPixbuf   *gpds_convert_to_grayscaled_pixbuf (GdkPixbuf *src);
 
 G_END_DECLS
 



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