python-pillow / Sane

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

sane-genesys scanner ysize=-1 leads to PIL MemoryError #4

Closed wiredfool closed 9 years ago

wiredfool commented 9 years ago

Transferred from https://github.com/python-pillow/Pillow/issues/1052

from @hanishkvc

Hi,

I am trying to use python-sane to access a Sane supported Scanner which uses the sane-genesys backend (from the device name), also sane-genesys man page matchs it Ambir PS665.

After init,open,start on doing snap, it fails with a MemoryError in PIL Image. On debugging it further found that basically get_parameters returns a size of (318,-1). And Because of this ysize of -1, PIL Image fails and inturn snap() fails.

As I am not much of a python expert and equally new to sane, for now I have modified sane.py snap code to check if ysize is -1 and then change it to xsize*3. But you all will have a better idea of calculating ysize, maybe using geometry info (I am assuming) or so. So please look at fixing this issue in python-sane by checking if xsize,ysize are valid or not and inturn mapping to some saner calculated value.

manisandro commented 9 years ago

-1 is returned when the driver cannot anticipate the number of lines returned (see section 4.3.8 of http://www.sane-project.org/html/doc012.html). This needs to be handled by dynamically resizing the image as necessary in snap. I'll look at this as soon as I find a moment.

manisandro commented 9 years ago

@hanishkvc Could you please try the overhauled module here https://github.com/manisandro/Sane ?

manisandro commented 9 years ago

Fixed in 2.8.0.