[sane-devel] duplexing question

jazz_johnson at verizon.net jazz_johnson at verizon.net
Wed Oct 31 18:30:54 UTC 2007


I looked over the fujitsu backend and see why it must buffer the RGB frames
which are not returned sorted by page side.
For my hs2p backend, I only have one GRAY frame, the first window of which
is the image data for the 1st side, and the 2nd window for the 2nd side.
So all I need is a boolean flag scanner->another_page in sane_start to tell
sane_start to reset the bytes-to-read counter to a full page.

sane_start()
{
  if (s->another_side)
  {
      /* Number of bytes to read for one side of sheet */
      s->bytes_to_read = s->params.bytes_per_line * s->params.lines;
      DBG (1, "SIDE#2 %d pixels per line, %d bytes, %d lines high, dpi=%d\n", 
           s->params.pixels_per_line, s->params.bytes_per_line,
           s->params.lines, (int) s->val[OPT_Y_RESOLUTION].w);
      s->scanning     = SANE_TRUE;
      s->cancelled    = SANE_FALSE;
      s->another_side = SANE_FALSE; /* This is side 2, so no more sides */
      DBG (11, "<< sane_start\n");
      return (SANE_STATUS_GOOD);
  }
  /* else this is the first page, and we need to initialize the scanner's options and set_window paramters*/
  if (using_duplex) s->another_side = SANE_TRUE;
  <...>
}

sane_read(){
  if (s->bytes_to_read == 0) {  /* We've reached the end of one side of sheet */
      if(!s->another_side){
         do_cancel (s);   /* We're done scanning */
         return (SANE_STATUS_EOF);
      }else{
         /* let frontend call sane_start again to reset bytes_to_read */
         DBG (11, "<< sane_read: getting another side\n");
	 return(SANE_STATUS_EOF);
      }
  }
  /* else continue reading:  */
  nread = max_len;
  if (nread > s->bytes_to_read) nread = s->bytes_to_read;
  status = read_data (s->fd, buf, &nread);
 <...>
}


This requires the front end to make two calls to sane_start for each duplex page scanned.
In Xsane, the user must click on "SCAN" button twice, or set the "Number of Pages to Scan" 
counter to 2. Then the first time the user clicks the SCAN button, the scanner will feed one 
page through the ADF and scan both sides at that time. The frontend will then read the 
first side's data and save that as out.0001.pnm and then on the second sane_start it 
will simply continue reading image data for side 2 from the scanner's memory, 
and then save that as out.0002.pnm.

Seems slightly awkward, unless there's a way to have the OPT_DUPLEX option somehow
automatically set the "Number of Pages to Scan" counter. Have I misunderstood something, 
or is this how the other backends duplex with Xsane?

Thanks.



More information about the sane-devel mailing list