gnome-scan r529 - in trunk: . modules



Author: bersace
Date: Wed Feb 27 17:06:21 2008
New Revision: 529
URL: http://svn.gnome.org/viewvc/gnome-scan?rev=529&view=rev

Log:
Fixed rotation.


Modified:
   trunk/ChangeLog
   trunk/modules/gsane-meta-param.c
   trunk/modules/gsane-meta-param.h

Modified: trunk/modules/gsane-meta-param.c
==============================================================================
--- trunk/modules/gsane-meta-param.c	(original)
+++ trunk/modules/gsane-meta-param.c	Wed Feb 27 17:06:21 2008
@@ -24,8 +24,16 @@
 #include <gtk/gtk.h>
 #include <gnome-scan-plugin.h>
 #include <gnome-scan-preview-plugin-area.h>
+#include <gnome-scan-types.h>
+#include <gnome-scan-utils.h>
 #include "gsane-meta-param.h"
 
+/**
+ * GSANE_DEFINE_META_PARAM:
+ * @opts: the swallowed sane options
+ * @params: the generated params ?
+ *
+ **/
 #define	GSANE_DEFINE_META_PARAM(Name, name, opts, params)				\
 	static void	meta_param_##name##_class_init (MetaParamClass *klass);	\
 	static void	meta_param_##name##_init (MetaParam *mp);				\
@@ -180,7 +188,9 @@
 
 /* AREA */
 /* TODO : handle paper-width,paper-height */
-GSANE_DEFINE_META_PARAM(PaperSize, paper_size, "tl-x,tl-y,br-x,br-y,page-format,paper-size", "paper-size,orig,orientation");
+GSANE_DEFINE_META_PARAM(PaperSize, paper_size,
+						"tl-x,tl-y,br-x,br-y,page-format,paper-size",
+						"paper-size,orig,page-orientation");
 
 static void
 meta_param_paper_size_init (MetaParam *mp)
@@ -249,6 +259,10 @@
 	spec = GS_PARAM_SPEC_RANGE (mpps->br_y);
 	set_int (spec->default_value, deft.height);
 	deft.height-= deft.y;
+	
+	mpps->area.width = rect.width;
+	mpps->area.height = rect.height;
+	
 #undef set_int
 
 	/* note: decomposing area in three options orientation, origin and paper-size
@@ -284,7 +298,7 @@
 		GTK_PAPER_NAME_LEGAL,
 		"iso_dl",
 		"om_small-photo",
-		NULL
+		NULL /* what else ? */
 	};
 	GSList *enumeration = NULL;
 
@@ -302,6 +316,11 @@
 	w-=x;
 	h-=y;
 	
+	mpps->roi.x = x;
+	mpps->roi.y = y;
+	mpps->roi.width = w;
+	mpps->roi.height = h;
+	
 #undef get_opt
 
 	g_value_unset (integer);
@@ -310,8 +329,7 @@
 	enumeration = g_slist_append (enumeration,
 								  gtk_paper_size_new_custom ("manual",
 															 _("Manual"),
-															 w,
-															 h,
+															 w, h,
 															 GTK_UNIT_MM)); /* what if w and h are not mm, but e.g. pixel ? */
 	enumeration = g_slist_append (enumeration,
 								  gtk_paper_size_new_custom ("maximal",
@@ -336,40 +354,106 @@
 	g_param_spec_set_qdata (pspec, GSANE_META_PARAM_QUARK, mp);
 	gnome_scan_plugin_params_add (GNOME_SCAN_PLUGIN (mp->gss), pspec);
 
-
 	return TRUE;
 }
 
+GdkRectangle*
+gs_rectange_rotate(GdkRectangle *r,
+				   GdkRectangle *a,
+				   guint angle)
+{
+	GdkRectangle *res = g_memdup(r, sizeof(GdkRectangle));
+	angle%= 360;
+	
+	switch (angle)
+	{
+		case 0:
+			break;
+		case 270:
+			res->width = r->height;
+			res->height = r->width;
+			res->x = r->y;
+			res->y = a->width - r->x - r->width;
+			break;
+		case 180:
+			res->x = a->width - r->x - r->width;
+			res->y = a->height - r->y - r->height;
+			break;
+		case 90:
+			res->width = r->height;
+			res->height = r->width;
+			res->y = r->x;
+			res->x = a->height - r->y - r->height;
+			break;
+		default:
+			g_warning("%s: %i degree rotation is not supported",
+					  __FUNCTION__, angle);
+			break;
+	}
+	return res;
+}
 static SANE_Int
-meta_param_paper_size_set_value			(MetaParam *mp, GParamSpec *spec, GValue *value)
+mpps_set_roi(MetaParam *mp)
 {
-	MetaParamPaperSize *mpps = GSANE_META_PARAM_PAPER_SIZE (mp);
+	MetaParamPaperSize *mpps = GSANE_META_PARAM_PAPER_SIZE(mp);
 	SANE_Int i = 0;
-	gint x, y, w, h;
-	
 	/* setup translator for integer/double handling */
-	GValue *integer = g_new0 (GValue, 1);
+	GValue *real = g_new0 (GValue, 1);
 	GValue *trans = g_new0 (GValue, 1);
 	GValue *v;
-	g_value_init (integer, G_TYPE_INT);
+	g_value_init (real, G_TYPE_DOUBLE);
 	g_value_init (trans, G_PARAM_SPEC_VALUE_TYPE (mpps->tl_x));
 	g_param_value_set_default (mpps->tl_x, trans);
+	GSRectangle *r, *u; /* rotation, unit */
+	guint unit = gs_param_spec_get_unit (mpps->tl_x);
 	
-	const gchar*name = g_param_spec_get_name (spec);
 	
-#define set_opt(opt,val)	g_value_set_int(integer,(val));			\
-	g_value_transform(integer, trans);								\
+#define set_opt(opt,val)	g_value_set_double(real,(val));			\
+	g_value_transform(real, trans);								\
 	i=i|gsane_scanner_option_set_value (mp->gss, mpps->opt, trans)
 
 #define get_opt(opt,var)	v=gsane_scanner_option_get_value (mp->gss, mpps->opt); \
-	g_value_transform(v,integer);										\
+	g_value_transform(v,real);										\
 	g_free(v);															\
-	var = g_value_get_int(integer);
+	var = g_value_get_double(real);
+	
+	r = gs_rectangle_rotate (&mpps->roi, &mpps->area, mpps->rotation);
+	u = gs_rectangle_convert_from_mm (r, unit, mpps->resolution);
+	g_free(r);
+	
+	set_opt(tl_x, u->x);
+	set_opt(tl_y, u->y);
+	set_opt(br_x, u->x + u->width);
+	set_opt(br_y, u->y + u->height);
+	
+	g_free(u);  
+	
+	g_value_unset (trans);
+	g_free (trans);
+		
+#undef set_opt
+#undef get_opt	
+	return i;
+}
+
+static SANE_Int
+meta_param_paper_size_set_value (MetaParam *mp,
+								 GParamSpec *spec,
+								 GValue *value)
+{
+	MetaParamPaperSize *mpps = GSANE_META_PARAM_PAPER_SIZE (mp);
+	gint w, h;
+	guint unit;
 
+	const gchar*name = g_param_spec_get_name (spec);
+	mpps->rotation = gnome_scan_settings_get_int (mp->settings,
+												  "rotation");
+	mpps->resolution = gnome_scan_settings_get_double (mp->settings,
+													   "resolution");
+	
 	/* paper-size */
 	if (g_str_equal (name, "paper-size")) {
 		mpps->ps = g_value_get_boxed (value);
-		guint unit;
 		
 		switch (gs_param_spec_get_unit (mpps->tl_x)) {
 		case GS_UNIT_MM:
@@ -382,10 +466,6 @@
 			break;
 		}
 
-		/* take offset in account */
-		get_opt(tl_x, x);
-		get_opt(tl_y, y);
-
 		switch (mpps->po) {
 		case GTK_PAGE_ORIENTATION_LANDSCAPE:
 		case GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE:
@@ -399,37 +479,20 @@
 			h = gtk_paper_size_get_height (mpps->ps, unit);
 			break;
 		}
-			
-		set_opt(br_x, x+w);
-		set_opt(br_y, y+h);
+		
+		mpps->roi.width = w;
+		mpps->roi.height = h;
 	}
-	else if (g_str_equal (name, "origin")) {
+	else if (g_str_equal (name, "origin")) {		
 		mpps->origin = g_value_get_pointer (value);
-
-		/* offset the current area */
-
-		get_opt(tl_x, x);
-		get_opt(tl_y, y);
-		get_opt(br_x, w);
-		get_opt(br_y, h);
-		w-=x;
-		h-=y;
-
-		set_opt(tl_x, mpps->origin->x);
-		set_opt(tl_y, mpps->origin->y);
-		set_opt(br_x, mpps->origin->x+w);
-		set_opt(br_y, mpps->origin->y+h);
+		mpps->roi.x = mpps->origin->x;
+		mpps->roi.y = mpps->origin->y;
 	}
 	else if (g_str_equal (name, "page-orientation")) {
 		mpps->po = g_value_get_enum (value);
 		gint t;
-
-		get_opt(tl_x, x);
-		get_opt(tl_y, y);
-		get_opt(br_x, w);
-		w-=x;
-		get_opt(br_y, h);
-		h-=y;
+		w = mpps->roi.width;
+		h = mpps->roi.height;
 		switch (mpps->po) {
 		case GTK_PAGE_ORIENTATION_PORTRAIT:
 		case GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT:
@@ -448,23 +511,18 @@
 			}		
 			break;
 		}
-
-		set_opt (br_x, x+w);
-		set_opt (br_y, y+h);
+		mpps->roi.width = w;
+		mpps->roi.height= h;
 	}
-#undef set_opt
-#undef get_opt
 
-	g_value_unset (trans);
-	g_free (trans);
-	
-	return i;
+	return 	mpps_set_roi(mp);
 }
 
 static GValue*
 meta_param_paper_size_get_value			(MetaParam *mp, GParamSpec *spec)
 {
-	g_warning ("%s not yet implemented", __FUNCTION__);
+	/* TODO: implement get value : convert SANE value to origin, papersize,
+	 and orientation */
 	return NULL;
 }
 

Modified: trunk/modules/gsane-meta-param.h
==============================================================================
--- trunk/modules/gsane-meta-param.h	(original)
+++ trunk/modules/gsane-meta-param.h	Wed Feb 27 17:06:21 2008
@@ -113,7 +113,12 @@
 	/* values */
 	GtkPaperSize		*ps;
 	GtkPageOrientation	po;
-	GdkPoint			*origin;
+	GSPoint				*origin;
+	
+	guint			rotation;
+	gdouble			resolution;
+	GSRectangle		roi;
+	GSRectangle		area;
 };
 
 GType		meta_param_paper_size_get_type	(void) G_GNUC_CONST;



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