changeset 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 0ef72a64930b
children 4a0091c0c231
files ChangeLog TODO src/image.c src/img-view.c src/layout_image.c src/layout_util.c src/menu.c src/pixbuf_util.c src/pixbuf_util.h src/typedefs.h
diffstat 10 files changed, 103 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Oct 19 13:38:52 2006 +0000
+++ b/ChangeLog	Thu Oct 19 19:27:20 2006 +0000
@@ -1,3 +1,12 @@
+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.
+
 Thu Oct 19 09:35:18 2006  John Ellis  <johne@verizon.net>
 
 	* layout.[ch] (layout_new_with_geometry): New function to create a
--- a/TODO	Thu Oct 19 13:38:52 2006 +0000
+++ b/TODO	Thu Oct 19 19:27:20 2006 +0000
@@ -90,6 +90,7 @@
    > xvpics is now hidden option.
    > Holding down shift will now scroll more when panning with mouse.
    > add --geometry command line option
+   > add [shift]+G grayscale alteration
 
    > add blurb about moving images between collections with shift+drag
 
@@ -107,6 +108,12 @@
 
  > do not lose slideshow when reworking window layout.
 
+ > fix printing of transparent images to not use black for transparency (white or user settable).
+
+ > add [control]+G to display as greyscale
+
+ > fix comment field in keywords bar to a height of 2 or 3 text lines.
+
  > add toolbar to: (UPDATE: these toolbars may not make it into 1.6)
    > find dupes window (with button to open dialog to add new files/folders)
    > collection window
--- a/src/image.c	Thu Oct 19 13:38:52 2006 +0000
+++ b/src/image.c	Thu Oct 19 19:27:20 2006 +0000
@@ -206,6 +206,11 @@
 			new = pixbuf_copy_mirror(pr->pixbuf, FALSE, TRUE);
 			y = pr->height - y;
 			break;
+		case ALTER_DESATURATE:
+			pixbuf_desaturate_rect(pr->pixbuf,
+					       0, 0,  pr->image_width, pr->image_height);
+			image_area_changed(imd, 0, 0, pr->image_width, pr->image_height);
+			break;
 		case ALTER_NONE:
 		default:
 			return;
--- a/src/img-view.c	Thu Oct 19 13:38:52 2006 +0000
+++ b/src/img-view.c	Thu Oct 19 19:27:20 2006 +0000
@@ -413,7 +413,10 @@
 			image_zoom_set_fill_geometry(imd, TRUE);
 			break;
 		case 'R': case 'r':
-			image_reload(imd);
+			if (!event->state & GDK_SHIFT_MASK)
+				{
+				image_reload(imd);
+				}
 			break;
 		case 'S': case 's':
 			if (vw->ss)
@@ -552,6 +555,10 @@
 				image_alter(imd, ALTER_FLIP);
 				stop_signal = TRUE;
 				break;
+			case 'G': case 'g':
+				image_alter(imd, ALTER_DESATURATE);
+				stop_signal = TRUE;
+				break;
 			default:
 				break;
 			}
--- a/src/layout_image.c	Thu Oct 19 13:38:52 2006 +0000
+++ b/src/layout_image.c	Thu Oct 19 19:27:20 2006 +0000
@@ -203,7 +203,10 @@
 			stop_signal = TRUE;
 			break;
 		case 'R': case 'r':
-			layout_refresh(lw);
+			if (!(event->state & GDK_SHIFT_MASK))
+				{
+				layout_refresh(lw);
+				}
 			break;
 		case 'S': case 's':
 			layout_image_slideshow_toggle(lw);
@@ -305,6 +308,10 @@
 				layout_image_alter(lw, ALTER_FLIP);
 				stop_signal = TRUE;
 				break;
+			case 'G': case 'g':
+				layout_image_alter(lw, ALTER_DESATURATE);
+				stop_signal = TRUE;
+				break;
 			default:
 				break;
 			}
--- a/src/layout_util.c	Thu Oct 19 13:38:52 2006 +0000
+++ b/src/layout_util.c	Thu Oct 19 19:27:20 2006 +0000
@@ -383,6 +383,13 @@
 	layout_image_alter(lw, ALTER_FLIP);
 }
 
+static void layout_menu_alter_desaturate_cb(GtkAction *action, gpointer data)
+{
+	LayoutWindow *lw = data;
+
+	layout_image_alter(lw, ALTER_DESATURATE);
+}
+
 static void layout_menu_info_cb(GtkAction *action, gpointer data)
 {
 	LayoutWindow *lw = data;
@@ -776,6 +783,7 @@
   { "Rotate180",	NULL,		N_("Rotate 1_80"),	"<shift>R",	NULL,	CB(layout_menu_alter_180_cb) },
   { "Mirror",		NULL,		N_("_Mirror"),		"<shift>M",	NULL,	CB(layout_menu_alter_mirror_cb) },
   { "Flip",		NULL,		N_("_Flip"),		"<shift>F",	NULL,	CB(layout_menu_alter_flip_cb) },
+  { "Grayscale",	NULL,		N_("_Grayscale"),	"<shift>G",	NULL,	CB(layout_menu_alter_desaturate_cb) },
   { "Properties",GTK_STOCK_PROPERTIES,	N_("_Properties"),	"<control>P",	NULL,	CB(layout_menu_info_cb) },
   { "SelectAll",	NULL,		N_("Select _all"),	"<control>A",	NULL,	CB(layout_menu_select_all_cb) },
   { "SelectNone",	NULL,		N_("Select _none"), "<control><shift>A",NULL,	CB(layout_menu_unselect_all_cb) },
@@ -857,6 +865,7 @@
 "        <menuitem action='Rotate180'/>"
 "        <menuitem action='Mirror'/>"
 "        <menuitem action='Flip'/>"
+"        <menuitem action='Grayscale'/>"
 "      </menu>"
 "      <menuitem action='Properties'/>"
 "      <separator/>"
--- a/src/menu.c	Thu Oct 19 13:38:52 2006 +0000
+++ b/src/menu.c	Thu Oct 19 19:27:20 2006 +0000
@@ -205,6 +205,9 @@
 		case ALTER_FLIP:
 			return _("_Flip");
 			break;
+		case ALTER_DESATURATE:
+			return _("_Grayscale");
+			break;
 		default:
 			break;
 		}
@@ -240,6 +243,7 @@
 	submenu_add_alter_item(submenu, func, ALTER_ROTATE_180, accel_group, 'R', GDK_SHIFT_MASK);
 	submenu_add_alter_item(submenu, func, ALTER_MIRROR, accel_group, 'M', GDK_SHIFT_MASK);
 	submenu_add_alter_item(submenu, func, ALTER_FLIP, accel_group, 'F', GDK_SHIFT_MASK);
+	submenu_add_alter_item(submenu, func, ALTER_DESATURATE, accel_group, 'G', GDK_SHIFT_MASK);
 
 	if (menu)
 		{
--- 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++;
+			}
+		}
+}
+
+
--- a/src/pixbuf_util.h	Thu Oct 19 13:38:52 2006 +0000
+++ b/src/pixbuf_util.h	Thu Oct 19 19:27:20 2006 +0000
@@ -77,6 +77,10 @@
 			gint x, gint y, gint w, gint h, gint border,
 			guint8 r, guint8 g, guint8 b, guint8 a);
 
+void pixbuf_desaturate_rect(GdkPixbuf *pb,
+			    gint x, gint y, gint w, gint h);
+
+
 /* clipping utils */
 
 gint util_clip_region(gint x, gint y, gint w, gint h,
--- a/src/typedefs.h	Thu Oct 19 13:38:52 2006 +0000
+++ b/src/typedefs.h	Thu Oct 19 19:27:20 2006 +0000
@@ -29,7 +29,8 @@
 	ALTER_ROTATE_90_CC,	/* counterclockwise */
 	ALTER_ROTATE_180,
 	ALTER_MIRROR,
-	ALTER_FLIP
+	ALTER_FLIP,
+	ALTER_DESATURATE
 } AlterType;
 
 typedef enum {