[sane-devel] A couple of backend API questions

Henning Meier-Geinitz henning@meier-geinitz.de
Tue, 2 Oct 2001 23:05:15 +0200


Hi,

On Tue, Oct 02, 2001 at 12:58:02PM +1000, Dmitri Katchalov wrote:
> 1) Does SANE support non-square pixel resolutions? My device (which is
> basically a fax machine)
> supports 200x100 (Standard), 200x200 (Fine) and 200x400 (Super Fine)
> modes. How do I set
> the "resolution" attribute?

Look at include/sane/saneopts.h: "resolution" and "resolution-y"
should be the correct options.

Another way is to ensure "square" resolutions by increasing the lower
resolution in the backend (e.g. doubling each pixel for 100-->200
dpi). That's what I do in the Mustek backend. Depends on what you want
to do with the images after the scan.

> 2) Timing of SANE_read. Once the scan operation is started the device
> spits data at pretty much
> constant rate. I haven't yet found a way to flow-control it. If the
> front-end does not call read() on time
> buffer overrun is likely to occur and the data will be lost. Unlike
> other scanners this one is a
> multi-function device, it can do several things at the same time and the
> comms channel is shared
> with printer and fax so if I don't poll it fast enough it will affect
> printing and faxing as well.

That's bad. If you really can't stop the device you can fork a reader
process in the backend and read the data into a big buffer to be sure
that the time between two sane_reads isn't too long. However, if the
buffer isn't large enough for the complete scan, it can overflow
nevertheless, e.g. if the scan is done over the net and there are
network problems.

> 3) The device has paper end detector. If the document is physically
> shorter than A4 the number
> of scan lines returned may be less than requested. Is it OK to return
> EOF in this case or do I need
> to pad the image with blank lines?

There is the special value of -1 for params.lines which means "I don't
know how much lines. Read until EOF". As far as I know this isn't
supported very well by the frontends. The idea of this was to support
hand scanners. I'm not sure if the standard allows to just send EOF if
there is no data and what the frontends do in this case.

> 4) SANE_cancel. I'm having some problems implementing its asynchronous
> behaviour.
> My device needs to be closed gracefully otherwise I will have problems
> opening it next time.
> This involves sending a "shut up" command to the device and getting a
> response back.
> When the manual says "asynchronously" I take it can be either from a
> different thread or a signal
> handler. AFAIK there are only a few things you can do from within signal
> handler and waiting
> for a packet is not one of them. I don't think you can even call free()
> safely in this context.

I'm not sure about the signal handler thing. scanimage calls
sane_cancel in an sigint handler. E.g. the mustek backend uses things
like gettimeofday, kill, waitpid, send and wait for SCSI commands
and similar things in sane_cancel. It seems to work.

Bye,
  Henning