[ocrfeeder] Prevent exceptions when setting scan mode and resolution
- From: Joaquim Rocha <jrocha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ocrfeeder] Prevent exceptions when setting scan mode and resolution
- Date: Wed, 22 Jan 2020 22:28:31 +0000 (UTC)
commit 873af2169e1fde039cbf3e53db9b386189afb92b
Author: scx <scx mail gmail com>
Date: Mon Jan 6 21:02:41 2020 +0100
Prevent exceptions when setting scan mode and resolution
Invalid scanner options lead to an unrecoverable error:
Error scanning page
We want to set the mode as color and resolution as 300 DPI if possible,
but the setting unsupported values was resulting in an non-caught
exception.
Some scanners don't support the Resolution parameter at all.
Supported modes may be vary across different scanners.
Not all of them support the "Color" mode.
For example, some of them support "Color24" or "Color48" instead.
This patch fixes that by simply catching the exceptions, using the
default values in that case.
src/ocrfeeder/util/lib.py | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
---
diff --git a/src/ocrfeeder/util/lib.py b/src/ocrfeeder/util/lib.py
index f3f72b4..f408743 100644
--- a/src/ocrfeeder/util/lib.py
+++ b/src/ocrfeeder/util/lib.py
@@ -160,8 +160,18 @@ def obtainScanners():
def scan(device):
try:
scandev = sane.open(device)
- scandev.mode = 'color'
- scandev.resolution = 300
+ try:
+ scandev.mode = 'Color24'
+ except:
+ debug('Unable to set scanner mode to "Color24".')
+ try:
+ scandev.mode = 'Color'
+ except:
+ debug('Unable to set scanner mode to "Color". Using default.')
+ try:
+ scandev.resolution = 300
+ except:
+ debug('Unable to set scanner resolution to 300 DPI. Using default.')
result = scandev.scan()
filename = tempfile.mktemp(suffix='.png')
result.save(filename, 'PNG')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]