diff src/pixbuf_util.c @ 82:a4c1b7014e6e

Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net> * image.c, typedefs.h: Add ALTER_DESATURATE alteration type. * img-view.c, layout_image.c, layout_util.c, menu.c: Allow to grayscale the display of current image with [Shift]+[G] kyboard shortcut and 'adjust' submenu item. * pixbuf_util.[ch] (pixbuf_desaturate_rect): Implement grayscale function.
author gqview
date Thu, 19 Oct 2006 19:27:20 +0000
parents 6281cc38e5ca
children d063f97503b7
line wrap: on
line diff
--- a/src/pixbuf_util.c	Thu Oct 19 13:38:52 2006 +0000
+++ b/src/pixbuf_util.c	Thu Oct 19 19:27:20 2006 +0000
@@ -1177,3 +1177,50 @@
 }
 
 
+/*
+ *-----------------------------------------------------------------------------
+ * pixbuf color alterations
+ *-----------------------------------------------------------------------------
+ */
+
+void pixbuf_desaturate_rect(GdkPixbuf *pb,
+			    gint x, gint y, gint w, gint h)
+{
+	gint p_alpha;
+	gint pw, ph, prs;
+	guchar *p_pix;
+	guchar *pp;
+	gint i, j;
+
+	if (!pb) return;
+
+	pw = gdk_pixbuf_get_width(pb);
+	ph = gdk_pixbuf_get_height(pb);
+
+	if (x < 0 || x + w > pw) return;
+	if (y < 0 || y + h > ph) return;
+
+	p_alpha = gdk_pixbuf_get_has_alpha(pb);
+	prs = gdk_pixbuf_get_rowstride(pb);
+	p_pix = gdk_pixbuf_get_pixels(pb);
+
+        for (i = 0; i < h; i++)
+		{
+		pp = p_pix + (y + i) * prs + (x * (p_alpha ? 4 : 3));
+		for (j = 0; j < w; j++)
+			{
+			guint8 grey;
+
+			grey = (pp[0] + pp[1] + pp[2]) / 3;
+			*pp = grey;
+			pp++;
+			*pp = grey;
+			pp++;
+			*pp = grey;
+			pp++;
+			if (p_alpha) pp++;
+			}
+		}
+}
+
+