Index: magnifier/zoom-region.c
===================================================================
RCS file: /cvs/gnome/gnome-mag/magnifier/zoom-region.c,v
retrieving revision 1.68
diff -u -p -r1.68 zoom-region.c
--- magnifier/zoom-region.c	9 Nov 2006 19:52:32 -0000	1.68
+++ magnifier/zoom-region.c	25 Nov 2006 19:54:33 -0000
@@ -1489,8 +1489,8 @@ zoom_region_process_pixbuf (ZoomRegion *
 
 	gboolean manipulate_contrast = FALSE;
 
-	if (zoom_region->contrast_r != 1 || zoom_region->contrast_g != 1 ||
-	    zoom_region->contrast_b != 1) {
+	if (zoom_region->contrast_r != 0 || zoom_region->contrast_g != 0 ||
+	    zoom_region->contrast_b != 0) {
 		manipulate_contrast = TRUE;
 	}
 
@@ -1498,19 +1498,30 @@ zoom_region_process_pixbuf (ZoomRegion *
 		return;
 
 #define CLAMP_UCHAR(v) (t = (v), CLAMP (t, 0, 255))
+#define CLAMP_LOW_MID(v) (t = (v), CLAMP (t, 0, 127))
+#define CLAMP_MID_HIGH(v) (t = (v), CLAMP (t, 127, 255))
 
 	for (j = 0; j < h; ++j) {
 		pixels_row = pixels;
 		for (i = 0; i < w; ++i) {
 			if (manipulate_contrast) {
-				// Set the RED contrast
-				pixels_row[0] = CLAMP_UCHAR (pixels_row[0] * zoom_region->contrast_r);
-
-				// Set the GREEN contrast
-				pixels_row[1] = CLAMP_UCHAR (pixels_row[1] * zoom_region->contrast_g);
-
-				// Set the BLUE contrast
-				pixels_row[2] = CLAMP_UCHAR (pixels_row[2] * zoom_region->contrast_b);
+				/* Set the RED contrast */
+				if (pixels_row[0] <= 127)
+					pixels_row[0] = CLAMP_LOW_MID (pixels_row[0] - zoom_region->contrast_r * 127);
+				else
+					pixels_row[0] = CLAMP_MID_HIGH (pixels_row[0] + zoom_region->contrast_r * 127);
+
+				/* Set the GREEN contrast */
+				if (pixels_row[1] <= 127)
+					pixels_row[1] = CLAMP_LOW_MID (pixels_row[1] - zoom_region->contrast_g * 127);
+				else
+					pixels_row[1] = CLAMP_MID_HIGH (pixels_row[1] + zoom_region->contrast_g * 127);
+
+				/* Set the BLUE contrast */
+				if (pixels_row[2] <= 127)
+					pixels_row[2] = CLAMP_LOW_MID (pixels_row[2] - zoom_region->contrast_b * 127);
+				else
+					pixels_row[2] = CLAMP_MID_HIGH (pixels_row[2] + zoom_region->contrast_b * 127);
 			}
 
 			if (zoom_region->invert) {
@@ -2292,6 +2303,7 @@ zoom_region_set_property (BonoboProperty
 {
 	ZoomRegion *zoom_region = user_data;
 	GNOME_Magnifier_RectBounds bounds;
+	gfloat t;
 
 #ifdef ZOOM_REGION_DEBUG
 	g_assert (zoom_region->alive);
@@ -2342,16 +2354,20 @@ zoom_region_set_property (BonoboProperty
 			g_object_unref (zoom_region->priv->source_drawable);
 		zoom_region_update_current (zoom_region);
 		break;
+#define CLAMP_B_C(v) (t = (v), CLAMP (t, -1, 1));
 	case ZOOM_REGION_CONTRASTR_PROP:
-		zoom_region->contrast_r = BONOBO_ARG_GET_FLOAT (arg);
+		zoom_region->contrast_r =
+			CLAMP_B_C (BONOBO_ARG_GET_FLOAT (arg));
 		zoom_region_update_current (zoom_region);
 		break;
 	case ZOOM_REGION_CONTRASTG_PROP:
-		zoom_region->contrast_g = BONOBO_ARG_GET_FLOAT (arg);
+		zoom_region->contrast_g =
+			CLAMP_B_C (BONOBO_ARG_GET_FLOAT (arg));
 		zoom_region_update_current (zoom_region);
 		break;
 	case ZOOM_REGION_CONTRASTB_PROP:
-		zoom_region->contrast_b = BONOBO_ARG_GET_FLOAT (arg);
+		zoom_region->contrast_b =
+			CLAMP_B_C (BONOBO_ARG_GET_FLOAT (arg));
 		zoom_region_update_current (zoom_region);
 		break;
 	case ZOOM_REGION_XSCALE_PROP:
@@ -2579,7 +2595,7 @@ impl_zoom_region_set_contrast (PortableS
 #endif
 	DBG (fprintf (stderr, "Set contrast: \t%f,%f %f\n", R, G, B));
 
-	/* if the contrast values are the same, this is a NOP */
+	/* if the contrast values are the same, this is a NOOP */
 	if (zoom_region->contrast_r == R &&
 	    zoom_region->contrast_g == G &&
 	    zoom_region->contrast_b == B)
@@ -2997,7 +3013,7 @@ zoom_region_properties_init (ZoomRegion 
 				 Bonobo_PROPERTY_WRITEABLE);
 
 	def = bonobo_arg_new (BONOBO_ARG_FLOAT);
-	BONOBO_ARG_SET_FLOAT (def, 1.0);
+	BONOBO_ARG_SET_FLOAT (def, 0.0);
 
 	bonobo_property_bag_add (zoom_region->properties,
 				 "red-contrast",
@@ -3010,7 +3026,7 @@ zoom_region_properties_init (ZoomRegion 
 	bonobo_arg_release (def);
 
 	def = bonobo_arg_new (BONOBO_ARG_FLOAT);
-	BONOBO_ARG_SET_FLOAT (def, 1.0);
+	BONOBO_ARG_SET_FLOAT (def, 0.0);
 
 	bonobo_property_bag_add (zoom_region->properties,
 				 "green-contrast",
@@ -3023,7 +3039,7 @@ zoom_region_properties_init (ZoomRegion 
 	bonobo_arg_release (def);
 
 	def = bonobo_arg_new (BONOBO_ARG_FLOAT);
-	BONOBO_ARG_SET_FLOAT (def, 1.0);
+	BONOBO_ARG_SET_FLOAT (def, 0.0);
 
 	bonobo_property_bag_add (zoom_region->properties,
 				 "blue-contrast",
@@ -3216,9 +3232,9 @@ zoom_region_init (ZoomRegion *zoom_regio
 	zoom_region_properties_init (zoom_region);
 	zoom_region->smooth_scroll_policy =
 		GNOME_Magnifier_ZoomRegion_SCROLL_SMOOTH;
-	zoom_region->contrast_r = 1.0;
-	zoom_region->contrast_g = 1.0;
-	zoom_region->contrast_b = 1.0;
+	zoom_region->contrast_r = 0.0;
+	zoom_region->contrast_g = 0.0;
+	zoom_region->contrast_b = 0.0;
 	zoom_region->invert = FALSE;
 	zoom_region->cache_source = FALSE;
 	zoom_region->border_size = 0;
