Additional device-specific settings for scanner

It would be great if it is possible to set additional options for the scanner in paperwork.
Rationale: I’m using an ADF scanner (Fujitsu ScanSnap iX100)

  1. it returns a pagesize of 215 x 859 mm, i.e. A4 paper width and almost 1 m long. This can be solved by the calibrate option, but it saves the large original (~ 3 MB per scan) and takes a long time to process
  2. The black/white levels are low, so that the image looks like a photograph of the paper, not a clean scan

Both problems can be alleviated by setting scanner options for SANE. Here is a patch which allows to do that from the config file

diff --git a/paperwork-backend/src/paperwork_backend/docscan/libinsane.py b/paperwork-backend/src/paperwork_backend/docscan/libinsane.py
index 16f016b8..fb60d058 100644
--- a/paperwork-backend/src/paperwork_backend/docscan/libinsane.py
+++ b/paperwork-backend/src/paperwork_backend/docscan/libinsane.py
@@ -207,6 +207,19 @@ class Source(object):
                     )
                     # will try to scan anyway
 
+            extrasettings = self.core.call_success("config_get", "scanner_extra_settings")
+
+            for (setting, value) in extrasettings.items():
+                if setting in opts:
+                    try:
+                        opts[setting].set_value(value)
+                    except Exception as exc:
+                        LOGGER.warning(
+                            "Failed to set scan setting " + setting + "=" + str(value), exc_info=exc
+                        )
+                else:
+                    LOGGER.warning("No such scanner setting: " + setting)
+
             imgs = self._scan(scan_id, resolution, max_pages, close_on_end)
             return (self, scan_id, imgs)
 
@@ -613,11 +626,17 @@ class Plugin(openpaperwork_core.PluginBase):
                 "config_build_simple", "scanner",
                 "mode", lambda: "Color"
             ),
+            'scanner_extra_settings': self.core.call_success(
+                "config_build_simple", "scanner",
+                "extrasettings", lambda: {}
+            ),
+
         }
         for (k, setting) in settings.items():
             self.core.call_all(
                 "config_register", k, setting
             )
+        # self.core.call_success("config_put", "scanner_extra_settings", {'brightness' : 20, 'contrast' : 20})
 
     def chkdeps(self, out: dict):
         if not GI_AVAILABLE:

With this line in my config file, both problems are completely alleviated:

extrasettings = dict:brightness=int:20;contrast=int:20;page-height=float:279.364;page-width=float:210

I couldn’t manage to add the GUI settings for a good solution, though (inquiring libinsane for all options, creating buttons etc.), that was over the top of my head.

Hello,

I’m going to add your patch on the branch testing (future Paperwork 2.2.0) and to develop. But next time, can you submit it through a merge request please ?

Paperwork credits (“about”) are generated based on Git history. Since I’m the one adding your patch to the Git repository, you won’t get credit for it.

Regarding the GUI, I won’t add such option. However something that could be done is to add to Libinsane a list of predefined default setting values for specific scanner models.

1 Like

Thank you for adding the patch, that makes my life easier! I don’t mind the credit.