[simple-scan] If brightness and contrast option is found, then always set it, even if it is zero



commit 0cf15de86d4f4a6a7f0e83f6370e69e476a535fe
Author: Bartosz Kosiorek <gang65 poczta onet pl>
Date:   Fri Dec 6 22:39:26 2019 +0100

    If brightness and contrast option is found, then always set it, even if it is zero
    
    Without this patch, the brightness and contrast are set only if it is different
    than zero. It cause error, in following situation:
    
    - Change brightness/contrast to value different than zero
    - Start scanning. Notice that brightness/contrast has changed
    - Change brightness/contrast to zero
    - Without patch, brightness/contrast was not changed to zero
    
    Current patch fixes that issue, and it's always set brightness/contrast.

 src/scanner.vala | 46 ++++++++++++++++++++--------------------------
 1 file changed, 20 insertions(+), 26 deletions(-)
---
diff --git a/src/scanner.vala b/src/scanner.vala
index 81c1415..0971ca7 100644
--- a/src/scanner.vala
+++ b/src/scanner.vala
@@ -1146,40 +1146,34 @@ public class Scanner : Object
             option = get_option_by_name (handle, Sane.NAME_BRIGHTNESS, out index);
             if (option != null)
             {
-                if (job.brightness != 0)
+                if (option.type == Sane.ValueType.FIXED)
                 {
-                    if (option.type == Sane.ValueType.FIXED)
-                    {
-                        var brightness = scale_fixed (-100, 100, option, job.brightness);
-                        set_fixed_option (handle, option, index, brightness, null);
-                    }
-                    else if (option.type == Sane.ValueType.INT)
-                    {
-                        var brightness = scale_int (-100, 100, option, job.brightness);
-                        set_int_option (handle, option, index, brightness, null);
-                    }
-                    else
-                        warning ("Unable to set brightness, please file a bug");
+                    var brightness = scale_fixed (-100, 100, option, job.brightness);
+                    set_fixed_option (handle, option, index, brightness, null);
                 }
+                else if (option.type == Sane.ValueType.INT)
+                {
+                    var brightness = scale_int (-100, 100, option, job.brightness);
+                    set_int_option (handle, option, index, brightness, null);
+                }
+                else
+                    warning ("Unable to set brightness, please file a bug");
             }
             option = get_option_by_name (handle, Sane.NAME_CONTRAST, out index);
             if (option != null)
             {
-                if (job.contrast != 0)
+                if (option.type == Sane.ValueType.FIXED)
                 {
-                    if (option.type == Sane.ValueType.FIXED)
-                    {
-                        var contrast = scale_fixed (-100, 100, option, job.contrast);
-                        set_fixed_option (handle, option, index, contrast, null);
-                    }
-                    else if (option.type == Sane.ValueType.INT)
-                    {
-                        var contrast = scale_int (-100, 100, option, job.contrast);
-                        set_int_option (handle, option, index, contrast, null);
-                    }
-                    else
-                        warning ("Unable to set contrast, please file a bug");
+                    var contrast = scale_fixed (-100, 100, option, job.contrast);
+                    set_fixed_option (handle, option, index, contrast, null);
                 }
+                else if (option.type == Sane.ValueType.INT)
+                {
+                    var contrast = scale_int (-100, 100, option, job.contrast);
+                    set_int_option (handle, option, index, contrast, null);
+                }
+                else
+                    warning ("Unable to set contrast, please file a bug");
             }
 
             /* Test scanner options (hoping will not effect other scanners...) */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]