[simple-scan/revert-647d3dea] Revert "Improve quality of the Text scans."



commit 9811a23915f7ff2076a89f073808ae0bc7d709d3
Author: Bartosz <gang65 poczta onet pl>
Date:   Fri May 8 07:57:56 2020 +0000

    Revert "Improve quality of the Text scans."
    
    This reverts commit 647d3deaeb890e652c48cc7bb25db318b275c314

 src/app-window.vala |  3 ++-
 src/scanner.vala    | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 1 deletion(-)
---
diff --git a/src/app-window.vala b/src/app-window.vala
index 4ef2d6c..7e3579c 100644
--- a/src/app-window.vala
+++ b/src/app-window.vala
@@ -970,13 +970,14 @@ public class AppWindow : Gtk.ApplicationWindow
         {
             options.scan_mode = ScanMode.GRAY;
             options.dpi = preferences_dialog.get_text_dpi ();
+            options.depth = 2;
         }
         else
         {
             options.scan_mode = ScanMode.COLOR;
             options.dpi = preferences_dialog.get_photo_dpi ();
+            options.depth = 8;
         }
-        options.depth = 8;
         preferences_dialog.get_paper_size (out options.paper_width, out options.paper_height);
         options.brightness = brightness;
         options.contrast = contrast;
diff --git a/src/scanner.vala b/src/scanner.vala
index 23a44fc..c8f37ac 100644
--- a/src/scanner.vala
+++ b/src/scanner.vala
@@ -1336,6 +1336,10 @@ public class Scanner : Object
         info.width = parameters.pixels_per_line;
         info.height = parameters.lines;
         info.depth = parameters.depth;
+        /* Reduce bit depth if requested lower than received */
+        // FIXME: This a hack and only works on 8 bit gray to 2 bit gray
+        if (parameters.depth == 8 && parameters.format == Sane.Frame.GRAY && job.depth == 2 && job.scan_mode 
== ScanMode.GRAY)
+            info.depth = job.depth;
         info.n_channels = parameters.format == Sane.Frame.GRAY ? 1 : 3;
         info.dpi = job.dpi; // FIXME: This is the requested DPI, not the actual DPI
         info.device = current_device;
@@ -1475,6 +1479,56 @@ public class Scanner : Object
                 n_used++;
             }
 
+            /* Reduce bit depth if requested lower than received */
+            // FIXME: This a hack and only works on 8 bit gray to 2 bit gray
+            if (parameters.depth == 8 && parameters.format == Sane.Frame.GRAY &&
+                job.depth == 2 && job.scan_mode == ScanMode.GRAY)
+            {
+                uchar block = 0;
+                var write_offset = 0;
+                var block_shift = 6;
+                for (var i = 0; i < line.n_lines; i++)
+                {
+                    var offset = i * line.data_length;
+                    for (var x = 0; x < line.width; x++)
+                    {
+                         var p = line.data[offset + x];
+
+                         uchar sample;
+                         if (p >= 192)
+                             sample = 3;
+                         else if (p >= 128)
+                             sample = 2;
+                         else if (p >= 64)
+                             sample = 1;
+                         else
+                             sample = 0;
+
+                         block |= sample << block_shift;
+                         if (block_shift == 0)
+                         {
+                             line.data[write_offset] = block;
+                             write_offset++;
+                             block = 0;
+                             block_shift = 6;
+                         }
+                         else
+                             block_shift -= 2;
+                    }
+
+                    /* Finish each line on a byte boundary */
+                    if (block_shift != 6)
+                    {
+                        line.data[write_offset] = block;
+                        write_offset++;
+                        block = 0;
+                        block_shift = 6;
+                    }
+                }
+
+                line.data_length = (line.width * 2 + 7) / 8;
+            }
+
             notify_event (new NotifyGotLine (job.id, line));
         }
     }


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