python-pillow / Sane

Python interface to the SANE scanner and frame grabber
Other
54 stars 19 forks source link

provide progress while scanning #21

Closed bodograumann closed 5 years ago

bodograumann commented 8 years ago

It would be nice if while scanning there was an indication of the progress. In scanimage this is done like this:

  hundred_percent = parm.bytes_per_line * parm.lines 
    * ((parm.format == SANE_FRAME_RGB || parm.format == SANE_FRAME_GRAY) ? 1:3);

  while (1)
    {
      double progr;
      status = sane_read (device, buffer, buffer_size, &len);
      total_bytes += (SANE_Word) len;
      progr = ((total_bytes * 100.) / (double) hundred_percent);
      if (progr > 100.)
        progr = 100.;
      if (progress)
        fprintf (stderr, "Progress: %3.1f%%\r", progr);

Of course in python-sane the progress should be exposed through an API. Maybe something like this:

def display_progress(progr):
    print("\x1b[1F\x1b[2KProgress: %3.1f%%" % (progr * 100))

sane.init()
scanner = sane.open(sane.get_devices()[0][0])
scanner.scan(progress = display_progress)
manisandro commented 8 years ago

This is a valid idea. Do you want to have a go at implementing it?

bodograumann commented 8 years ago

The python C-API is not my area of expertise, but I could certainly try. I won’t be angry though, if somebody more knowledgeable beat me to it ;-)

manisandro commented 8 years ago

Currently I don't have that much time, so if you feel like it, give it a try :)

manisandro commented 5 years ago

Should be done with 921151fb1be722db9731d7eaad16e334e0e685e4