[sane-devel] scanimage bug?

Henning Meier-Geinitz henning@meier-geinitz.de
Sat, 27 Apr 2002 23:13:06 +0200


Hi,

On Sat, Apr 27, 2002 at 06:27:37PM +0100, Major A wrote:
> I'm quite sure the "-1" is correct. If I have a scanner that has, say,
> 1000 pixels in one direction, I can specify 0...999 for both the left
> and right boundaries, but the width ranges from 1 to 1000. At least
> that's how scanimage works: if I specify a left of 0 and a width of
> 999 (the maximum given by scanimage -h), it passes a left of 0 and a
> right of 998 to the scanner.

I see. I don't like counting starting by 0 :-)
This seems to be only relevant for SANE_TYPE_INT. What about this one:

Index: frontend/scanimage.c
===================================================================
RCS file: /cvsroot/external/sane/sane-backends/frontend/scanimage.c,v
retrieving revision 1.25
diff -u -u -r1.25 scanimage.c
--- scanimage.c	2002/04/27 09:40:21	1.25
+++ scanimage.c	2002/04/27 21:03:30
@@ -390,8 +390,13 @@
 	case SANE_CONSTRAINT_RANGE:
 	  if (opt->type == SANE_TYPE_INT)
 	    {
-	      printf ("%d..%d",
-		      opt->constraint.range->min, opt->constraint.range->max);
+	      if (opt_num == window[0] || opt_num == window[1])
+		/* width and height */
+		printf ("%d..%d", opt->constraint.range->min,
+			opt->constraint.range->max + 1);
+	      else
+		printf ("%d..%d", opt->constraint.range->min,
+			opt->constraint.range->max);
 	      print_unit (opt->unit);
 	      if (opt->size > (SANE_Int) sizeof (SANE_Word))
 		fputs (",...", stdout);
@@ -457,7 +462,10 @@
 	      break;
 
 	    case SANE_TYPE_INT:
-	      printf ("%d", *(SANE_Int *) val);
+	      if (opt_num == window[0] || opt_num == window[1])
+		printf ("%d", (*(SANE_Int *) val) + 1);
+	      else
+		printf ("%d", *(SANE_Int *) val);
 	      break;
 
 	    case SANE_TYPE_FIXED:


It fixes only the range.max value and doesn't try to force 1 for
range.min. In reality, this should be something like:

range.min = 1;
range.max = br_x.range.max - tl_x.range.min + 1;

Correct? Can be more difficult if range.quant != 1 ...

I haven't tried if setting these options is ok.

Printing the options values seems to have another problem: The "real" option
value of -x and -y (br-x and br-y) is printed, not the width. You can
see this if you specify a value other than 0 for tl-x or tl-y:

    -l 0..200pel (in steps of 1) [5]
            Top-left x position of scan area.
    -t 0..200pel (in steps of 1) [7]
            Top-left y position of scan area.
    -x 0..201pel (in steps of 1) [81]
            Width of scan-area.
    -y 0..201pel (in steps of 1) [101]
            Height of scan-area.
						
br-x is 80 (not 85), br-y is 100 (not 107).

Bye,
  Henning