SimulPiscator / AirSane

Publish SANE scanners to MacOS, Android, and Windows via Apple AirScan.
GNU General Public License v3.0
243 stars 26 forks source link

"Stuttering" during scanning when using macOS system dialogs #87

Closed Swonkie closed 2 years ago

Swonkie commented 2 years ago

First, thanks a lot for creating AirSane - it made my scanner usable again πŸ‘ πŸ’›

I'm experiencing some minor issues though

Setup: AirSane runs on a RaspberryPi 3 (followed the instructions in the readme) Scanner is a Canon LiDE 100, connected by USB to the RaspberryPi Im scanning from a Mac (Monterey, 12.4) Using the web interface works perfectly from all devices in the network, including the Mac

Issues: When using any of the macOS system dialogs (Image Capture, Preview or "Open Scanner..." from system preferences)

Again, these issues do not happen when using the web interface. It would be fantastic if this could be fixed. Please let me know if you need further info.

SimulPiscator commented 2 years ago

The preview scan shows only the top half of the scan bed and stretches it vertically to fill the whole preview area - so I get a distorted image of the top half only. I can still scan a full page by selecting a paper format under "Size", and the resulting scan is fine.

This is weird. If it only happens for a custom paper size, what did you choose before selecting a pre-defined paper format?

Most of the time, the actual scanning process interrupts about 3 times per second and the scan takes much longer than it should. This happens most of the time but not always. It seems to depend on the DPI and color settings. My guess is that if the data rate is too high, the stuttering happens.

For me, this happens with a resolution of 2400dpi in the MacOS dialog. The Web Interface does not offer a resolution of 2400dpi for my scanner (a Canon LiDE60 with the genesys backend). I think this is an artifact of how the backend controls the scanner. If you want to test how your system behaves with larger data rates, you may enable the test backend in /etc/sane.d/dll.conf, which synthesizes a test image and is thus quite fast.

Testing with the scanimage program from the command line can tell you whether the observed effect is due to the backend or to AirSane. For me, a color scan at 2400dpi shows the behavior you observed even with scanimage.

Swonkie commented 2 years ago

This is weird. If it only happens for a custom paper size, what did you choose before selecting a pre-defined paper format?

The preview is done automatically when the scan dialog opens. At this point, I can't select anything yet. Only when the preview is finished, are the dialog options activated. In the beginning, "custom size" was selected and the dialog would automatically suggest a selection rectangle around the page content. Even though the rectangle was about the size of the whole preview area, the resulting scan would still show only the top half, distorted, just like the preview area shows. If I instead select a paper format which fills the scan bed (A4), the resulting scan is fine even though in the preview area the selection frame looked pretty much the same as in the first case.

SimulPiscator commented 2 years ago

Can you reproduce that or did it happen just once?

Swonkie commented 2 years ago

Can you reproduce that or did it happen just once?

I can reproduce it by selecting "Custom size" again. Even though the displayed dimensions in cm look correct (size of the whole scan bed), the resulting scan is still only the top half, distorted.

SimulPiscator commented 2 years ago

Unfortunately, I cannot reproduce this issue with my own scanner. You can help me debugging by running airsaned in debug mode, and post its output: sudo service airsaned stop cd /usr/local/src/AirSane-build (or wherever you built it) sudo -u saned ./airsaned --debug=true

Then, perform a scanning operation which will result in the distortion you reported. Thanks!

Swonkie commented 2 years ago

This is the debug output from a preview and then a scan, with distorted image of the top half of the page. I can't see anything suspicious. Maybe the "end of file" (sane_read(0x718121a8): End of file reached) is reached too soon and then "half the image data" is saved with the dimensions of the complete image?

git commit: 64f6283 (branch master, rev 233)
build date: 2022-06-21T15:33:21Z
start time is 230.457
reading device options from '/etc/airsane/options.conf'
enumerating local devices...
sane_init(nullptr, nullptr)
sane_get_devices() ...
... sane_get_devices() -> SANE_Status Success
sane_exit()
found: genesys:libusb:001:004 (Canon LiDE 100)
stable unique name: genesys:Canon LiDE 100:1
uuid: fe67b27a-354e-5155-b6c9-38382c3caf49
sane_init(nullptr, nullptr)
sane_open(genesys:libusb:001:004) -> 0x735645b8
/etc/airsane/options.conf: regex 'genesys:.*' matches device name 'genesys:libusb:001:004'
[source] := "Flatbed"
sane_close(0x735645b8)
sane_exit()
published as 'Canon LiDE 100'
end time is 230.997
startup took 0.540665 secconds
listening on 127.0.0.1:8090
listening on 192.168.1.76:8090
listening on [::1]:8090
listening on [2001:1711:fa4f:280:6028:14a6:1ec0:ad57]:8090
listening on [2001:1711:fa4f:280:e9a8:8b90:4ca0:f81]:8090
listening on [fdaa:bbcc:ddee:0:bddc:6f99:ff10:4108]:8090
listening on [fe80::5b88:3abf:c709:b452]:8090
document format requested: image/jpeg
document format used: image/png
job kind: single
using color gamma of 1
sane_init(nullptr, nullptr)
sane_open(genesys:libusb:001:004) -> 0x71819278
[source] := "Flatbed"
[depth] := 8 -> reload options
[mode] := "Color" -> reload options
[resolution] := 75dpi
[tl-x] := 0mm
[tl-y] := 0mm
[br-x] := 216mm
[br-y] := 299mm
sane_start(0x71819278) with options:
[br-x] = 216mm
[br-y] = 299mm
[brightness] = 0
[buttons] = 
[calibration-file] = ""
[clear-calibration] = 
[contrast] = 0
[copy] = 0
[custom-gamma] = 0
[depth] = 8
[email] = 0
[enhancement] = 
[expiration-time] = 60
[extras-group] = 
[file] = 0
[force-calibration] = 
[geometry] = 
[ignore-internal-offsets] = 
[lamp-off-scan] = 0
[lamp-off-time] = 15
[mode] = "Color"
[preview] = 0
[resolution] = 75dpi
[scan] = 0
[scanmode-group] = 
[sensors] = 
[source] = "Flatbed"
[tl-x] = 0mm
[tl-y] = 0mm
sane_read(0x71819278): End of file reached
images completed: 1
sane_cancel(0x71819278)
sane_cancel(0x71819278)
sane_close(0x71819278)
sane_exit()
document format requested: image/jpeg
document format used: image/png
job kind: single
using color gamma of 1
sane_init(nullptr, nullptr)
sane_open(genesys:libusb:001:004) -> 0x718121a8
[source] := "Flatbed"
[depth] := 8 -> reload options
[mode] := "Color" -> reload options
[resolution] := 75dpi
[tl-x] := 0mm
[tl-y] := 0mm
[br-x] := 210mm
[br-y] := 297mm
sane_start(0x718121a8) with options:
[br-x] = 210mm
[br-y] = 297mm
[brightness] = 0
[buttons] = 
[calibration-file] = ""
[clear-calibration] = 
[contrast] = 0
[copy] = 0
[custom-gamma] = 0
[depth] = 8
[email] = 0
[enhancement] = 
[expiration-time] = 60
[extras-group] = 
[file] = 0
[force-calibration] = 
[geometry] = 
[ignore-internal-offsets] = 
[lamp-off-scan] = 0
[lamp-off-time] = 15
[mode] = "Color"
[preview] = 0
[resolution] = 75dpi
[scan] = 0
[scanmode-group] = 
[sensors] = 
[source] = "Flatbed"
[tl-x] = 0mm
[tl-y] = 0mm
sane_read(0x718121a8): End of file reached
images completed: 1
sane_cancel(0x718121a8)
sane_cancel(0x718121a8)
sane_close(0x718121a8)
sane_exit()
SimulPiscator commented 2 years ago

Thanks for the debug output. I agree that it does not look suspicious. To double check, could you use the scanimage command line program from the raspberry pi command line, and see whether the scan is correct? sudo -u saned scanimage --format png --resolution=75 --tl-x=0 --tl-y=0 --width=216 --height=299 > test.png

Swonkie commented 2 years ago

That results in a distorted scan.

SimulPiscator commented 2 years ago

It seems then that the issue is related to the genesys scanner backend, not to AirSane. I found a bug report for the genesys backend that mentions an issue such as you are experiencing: https://gitlab.com/sane-project/backends/-/issues/549

You might try updating to a newer version of the SANE backends package, e.g. by installing from source: https://gitlab.com/sane-project/backends/-/blob/master/README

Swonkie commented 2 years ago

You're right. Apparently I didn't experiment enough with the settings and came to a wrong conclusion. Not the custom size triggers this bug, but simply the DPI settings below 200dpi - and the preview is always low resolution. Thanks for figuring this out. I'll see if I can update the SANE backend.